Add new command "maint print core-file-backed-mappings"
[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
6d2ebf8b 560@node Sample Session
c906108c
SS
561@chapter A Sample @value{GDBN} Session
562
563You can use this manual at your leisure to read all about @value{GDBN}.
564However, a handful of commands are enough to get started using the
565debugger. This chapter illustrates those commands.
566
567@iftex
568In this sample session, we emphasize user input like this: @b{input},
569to make it easier to pick out from the surrounding output.
570@end iftex
571
572@c FIXME: this example may not be appropriate for some configs, where
573@c FIXME...primary interest is in remote use.
574
575One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
576processor) exhibits the following bug: sometimes, when we change its
577quote strings from the default, the commands used to capture one macro
578definition within another stop working. In the following short @code{m4}
579session, we define a macro @code{foo} which expands to @code{0000}; we
580then use the @code{m4} built-in @code{defn} to define @code{bar} as the
581same thing. However, when we change the open quote string to
582@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
583procedure fails to define a new synonym @code{baz}:
584
585@smallexample
586$ @b{cd gnu/m4}
587$ @b{./m4}
588@b{define(foo,0000)}
589
590@b{foo}
5910000
592@b{define(bar,defn(`foo'))}
593
594@b{bar}
5950000
596@b{changequote(<QUOTE>,<UNQUOTE>)}
597
598@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
599@b{baz}
c8aa23ab 600@b{Ctrl-d}
c906108c
SS
601m4: End of input: 0: fatal error: EOF in string
602@end smallexample
603
604@noindent
605Let us use @value{GDBN} to try to see what is going on.
606
c906108c
SS
607@smallexample
608$ @b{@value{GDBP} m4}
609@c FIXME: this falsifies the exact text played out, to permit smallbook
610@c FIXME... format to come out better.
611@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 612 of it under certain conditions; type "show copying" to see
c906108c 613 the conditions.
5d161b24 614There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
615 for details.
616
617@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
618(@value{GDBP})
619@end smallexample
c906108c
SS
620
621@noindent
622@value{GDBN} reads only enough symbol data to know where to find the
623rest when needed; as a result, the first prompt comes up very quickly.
624We now tell @value{GDBN} to use a narrower display width than usual, so
625that examples fit in this manual.
626
627@smallexample
628(@value{GDBP}) @b{set width 70}
629@end smallexample
630
631@noindent
632We need to see how the @code{m4} built-in @code{changequote} works.
633Having looked at the source, we know the relevant subroutine is
634@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
635@code{break} command.
636
637@smallexample
638(@value{GDBP}) @b{break m4_changequote}
639Breakpoint 1 at 0x62f4: file builtin.c, line 879.
640@end smallexample
641
642@noindent
643Using the @code{run} command, we start @code{m4} running under @value{GDBN}
644control; as long as control does not reach the @code{m4_changequote}
645subroutine, the program runs as usual:
646
647@smallexample
648(@value{GDBP}) @b{run}
649Starting program: /work/Editorial/gdb/gnu/m4/m4
650@b{define(foo,0000)}
651
652@b{foo}
6530000
654@end smallexample
655
656@noindent
657To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
658suspends execution of @code{m4}, displaying information about the
659context where it stops.
660
661@smallexample
662@b{changequote(<QUOTE>,<UNQUOTE>)}
663
5d161b24 664Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
665 at builtin.c:879
666879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
667@end smallexample
668
669@noindent
670Now we use the command @code{n} (@code{next}) to advance execution to
671the next line of the current function.
672
673@smallexample
674(@value{GDBP}) @b{n}
675882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
676 : nil,
677@end smallexample
678
679@noindent
680@code{set_quotes} looks like a promising subroutine. We can go into it
681by using the command @code{s} (@code{step}) instead of @code{next}.
682@code{step} goes to the next line to be executed in @emph{any}
683subroutine, so it steps into @code{set_quotes}.
684
685@smallexample
686(@value{GDBP}) @b{s}
687set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
688 at input.c:530
689530 if (lquote != def_lquote)
690@end smallexample
691
692@noindent
693The display that shows the subroutine where @code{m4} is now
694suspended (and its arguments) is called a stack frame display. It
695shows a summary of the stack. We can use the @code{backtrace}
696command (which can also be spelled @code{bt}), to see where we are
697in the stack as a whole: the @code{backtrace} command displays a
698stack frame for each active subroutine.
699
700@smallexample
701(@value{GDBP}) @b{bt}
702#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
703 at input.c:530
5d161b24 704#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
705 at builtin.c:882
706#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
707#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
708 at macro.c:71
709#4 0x79dc in expand_input () at macro.c:40
710#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
711@end smallexample
712
713@noindent
714We step through a few more lines to see what happens. The first two
715times, we can use @samp{s}; the next two times we use @code{n} to avoid
716falling into the @code{xstrdup} subroutine.
717
718@smallexample
719(@value{GDBP}) @b{s}
7200x3b5c 532 if (rquote != def_rquote)
721(@value{GDBP}) @b{s}
7220x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
723def_lquote : xstrdup(lq);
724(@value{GDBP}) @b{n}
725536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
726 : xstrdup(rq);
727(@value{GDBP}) @b{n}
728538 len_lquote = strlen(rquote);
729@end smallexample
730
731@noindent
732The last line displayed looks a little odd; we can examine the variables
733@code{lquote} and @code{rquote} to see if they are in fact the new left
734and right quotes we specified. We use the command @code{p}
735(@code{print}) to see their values.
736
737@smallexample
738(@value{GDBP}) @b{p lquote}
739$1 = 0x35d40 "<QUOTE>"
740(@value{GDBP}) @b{p rquote}
741$2 = 0x35d50 "<UNQUOTE>"
742@end smallexample
743
744@noindent
745@code{lquote} and @code{rquote} are indeed the new left and right quotes.
746To look at some context, we can display ten lines of source
747surrounding the current line with the @code{l} (@code{list}) command.
748
749@smallexample
750(@value{GDBP}) @b{l}
751533 xfree(rquote);
752534
753535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
754 : xstrdup (lq);
755536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
756 : xstrdup (rq);
757537
758538 len_lquote = strlen(rquote);
759539 len_rquote = strlen(lquote);
760540 @}
761541
762542 void
763@end smallexample
764
765@noindent
766Let us step past the two lines that set @code{len_lquote} and
767@code{len_rquote}, and then examine the values of those variables.
768
769@smallexample
770(@value{GDBP}) @b{n}
771539 len_rquote = strlen(lquote);
772(@value{GDBP}) @b{n}
773540 @}
774(@value{GDBP}) @b{p len_lquote}
775$3 = 9
776(@value{GDBP}) @b{p len_rquote}
777$4 = 7
778@end smallexample
779
780@noindent
781That certainly looks wrong, assuming @code{len_lquote} and
782@code{len_rquote} are meant to be the lengths of @code{lquote} and
783@code{rquote} respectively. We can set them to better values using
784the @code{p} command, since it can print the value of
785any expression---and that expression can include subroutine calls and
786assignments.
787
788@smallexample
789(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
790$5 = 7
791(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
792$6 = 9
793@end smallexample
794
795@noindent
796Is that enough to fix the problem of using the new quotes with the
797@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
798executing with the @code{c} (@code{continue}) command, and then try the
799example that caused trouble initially:
800
801@smallexample
802(@value{GDBP}) @b{c}
803Continuing.
804
805@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
806
807baz
8080000
809@end smallexample
810
811@noindent
812Success! The new quotes now work just as well as the default ones. The
813problem seems to have been just the two typos defining the wrong
814lengths. We allow @code{m4} exit by giving it an EOF as input:
815
816@smallexample
c8aa23ab 817@b{Ctrl-d}
c906108c
SS
818Program exited normally.
819@end smallexample
820
821@noindent
822The message @samp{Program exited normally.} is from @value{GDBN}; it
823indicates @code{m4} has finished executing. We can end our @value{GDBN}
824session with the @value{GDBN} @code{quit} command.
825
826@smallexample
827(@value{GDBP}) @b{quit}
828@end smallexample
c906108c 829
6d2ebf8b 830@node Invocation
c906108c
SS
831@chapter Getting In and Out of @value{GDBN}
832
833This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 834The essentials are:
c906108c 835@itemize @bullet
5d161b24 836@item
53a5351d 837type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 838@item
c8aa23ab 839type @kbd{quit} or @kbd{Ctrl-d} to exit.
c906108c
SS
840@end itemize
841
842@menu
843* Invoking GDB:: How to start @value{GDBN}
844* Quitting GDB:: How to quit @value{GDBN}
845* Shell Commands:: How to use shell commands inside @value{GDBN}
79a6e687 846* Logging Output:: How to log @value{GDBN}'s output to a file
c906108c
SS
847@end menu
848
6d2ebf8b 849@node Invoking GDB
c906108c
SS
850@section Invoking @value{GDBN}
851
c906108c
SS
852Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
853@value{GDBN} reads commands from the terminal until you tell it to exit.
854
855You can also run @code{@value{GDBP}} with a variety of arguments and options,
856to specify more of your debugging environment at the outset.
857
c906108c
SS
858The command-line options described here are designed
859to cover a variety of situations; in some environments, some of these
5d161b24 860options may effectively be unavailable.
c906108c
SS
861
862The most usual way to start @value{GDBN} is with one argument,
863specifying an executable program:
864
474c8240 865@smallexample
c906108c 866@value{GDBP} @var{program}
474c8240 867@end smallexample
c906108c 868
c906108c
SS
869@noindent
870You can also start with both an executable program and a core file
871specified:
872
474c8240 873@smallexample
c906108c 874@value{GDBP} @var{program} @var{core}
474c8240 875@end smallexample
c906108c 876
4ed4690f
SM
877You can, instead, specify a process ID as a second argument or use option
878@code{-p}, if you want to debug a running process:
c906108c 879
474c8240 880@smallexample
c906108c 881@value{GDBP} @var{program} 1234
4ed4690f 882@value{GDBP} -p 1234
474c8240 883@end smallexample
c906108c
SS
884
885@noindent
4ed4690f
SM
886would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
887can omit the @var{program} filename.
c906108c 888
c906108c 889Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
890complete operating system; when you use @value{GDBN} as a remote
891debugger attached to a bare board, there may not be any notion of
892``process'', and there is often no way to get a core dump. @value{GDBN}
893will warn you if it is unable to attach or to read core dumps.
c906108c 894
aa26fa3a
TT
895You can optionally have @code{@value{GDBP}} pass any arguments after the
896executable file to the inferior using @code{--args}. This option stops
897option processing.
474c8240 898@smallexample
3f94c067 899@value{GDBP} --args gcc -O2 -c foo.c
474c8240 900@end smallexample
aa26fa3a
TT
901This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
902@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
903
96a2c332 904You can run @code{@value{GDBP}} without printing the front material, which describes
adcc0a31 905@value{GDBN}'s non-warranty, by specifying @code{--silent}
906(or @code{-q}/@code{--quiet}):
c906108c
SS
907
908@smallexample
adcc0a31 909@value{GDBP} --silent
c906108c
SS
910@end smallexample
911
912@noindent
913You can further control how @value{GDBN} starts up by using command-line
914options. @value{GDBN} itself can remind you of the options available.
915
916@noindent
917Type
918
474c8240 919@smallexample
c906108c 920@value{GDBP} -help
474c8240 921@end smallexample
c906108c
SS
922
923@noindent
924to display all available options and briefly describe their use
925(@samp{@value{GDBP} -h} is a shorter equivalent).
926
927All options and command line arguments you give are processed
928in sequential order. The order makes a difference when the
929@samp{-x} option is used.
930
931
932@menu
c906108c
SS
933* File Options:: Choosing files
934* Mode Options:: Choosing modes
6fc08d32 935* Startup:: What @value{GDBN} does during startup
c906108c
SS
936@end menu
937
6d2ebf8b 938@node File Options
79a6e687 939@subsection Choosing Files
c906108c 940
2df3850c 941When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
942specifying an executable file and core file (or process ID). This is
943the same as if the arguments were specified by the @samp{-se} and
d52fb0e9 944@samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
19837790
MS
945first argument that does not have an associated option flag as
946equivalent to the @samp{-se} option followed by that argument; and the
947second argument that does not have an associated option flag, if any, as
948equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
949If the second argument begins with a decimal digit, @value{GDBN} will
950first attempt to attach to it as a process, and if that fails, attempt
951to open it as a corefile. If you have a corefile whose name begins with
b383017d 952a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 953prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
954
955If @value{GDBN} has not been configured to included core file support,
956such as for most embedded targets, then it will complain about a second
957argument and ignore it.
c906108c
SS
958
959Many options have both long and short forms; both are shown in the
960following list. @value{GDBN} also recognizes the long forms if you truncate
961them, so long as enough of the option is present to be unambiguous.
962(If you prefer, you can flag option arguments with @samp{--} rather
963than @samp{-}, though we illustrate the more usual convention.)
964
d700128c
EZ
965@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
966@c way, both those who look for -foo and --foo in the index, will find
967@c it.
968
c906108c
SS
969@table @code
970@item -symbols @var{file}
971@itemx -s @var{file}
d700128c
EZ
972@cindex @code{--symbols}
973@cindex @code{-s}
c906108c
SS
974Read symbol table from file @var{file}.
975
976@item -exec @var{file}
977@itemx -e @var{file}
d700128c
EZ
978@cindex @code{--exec}
979@cindex @code{-e}
7a292a7a
SS
980Use file @var{file} as the executable file to execute when appropriate,
981and for examining pure data in conjunction with a core dump.
c906108c
SS
982
983@item -se @var{file}
d700128c 984@cindex @code{--se}
c906108c
SS
985Read symbol table from file @var{file} and use it as the executable
986file.
987
c906108c
SS
988@item -core @var{file}
989@itemx -c @var{file}
d700128c
EZ
990@cindex @code{--core}
991@cindex @code{-c}
b383017d 992Use file @var{file} as a core dump to examine.
c906108c 993
19837790
MS
994@item -pid @var{number}
995@itemx -p @var{number}
996@cindex @code{--pid}
997@cindex @code{-p}
998Connect to process ID @var{number}, as with the @code{attach} command.
c906108c
SS
999
1000@item -command @var{file}
1001@itemx -x @var{file}
d700128c
EZ
1002@cindex @code{--command}
1003@cindex @code{-x}
95433b34
JB
1004Execute commands from file @var{file}. The contents of this file is
1005evaluated exactly as the @code{source} command would.
8150ff9c 1006@xref{Command Files,, Command files}.
c906108c 1007
8a5a3c82
AS
1008@item -eval-command @var{command}
1009@itemx -ex @var{command}
1010@cindex @code{--eval-command}
1011@cindex @code{-ex}
1012Execute a single @value{GDBN} command.
1013
1014This option may be used multiple times to call multiple commands. It may
1015also be interleaved with @samp{-command} as required.
1016
1017@smallexample
1018@value{GDBP} -ex 'target sim' -ex 'load' \
1019 -x setbreakpoints -ex 'run' a.out
1020@end smallexample
1021
8320cc4f
JK
1022@item -init-command @var{file}
1023@itemx -ix @var{file}
1024@cindex @code{--init-command}
1025@cindex @code{-ix}
2d7b58e8
JK
1026Execute commands from file @var{file} before loading the inferior (but
1027after loading gdbinit files).
8320cc4f
JK
1028@xref{Startup}.
1029
1030@item -init-eval-command @var{command}
1031@itemx -iex @var{command}
1032@cindex @code{--init-eval-command}
1033@cindex @code{-iex}
2d7b58e8
JK
1034Execute a single @value{GDBN} command before loading the inferior (but
1035after loading gdbinit files).
8320cc4f
JK
1036@xref{Startup}.
1037
c906108c
SS
1038@item -directory @var{directory}
1039@itemx -d @var{directory}
d700128c
EZ
1040@cindex @code{--directory}
1041@cindex @code{-d}
4b505b12 1042Add @var{directory} to the path to search for source and script files.
c906108c 1043
c906108c
SS
1044@item -r
1045@itemx -readnow
d700128c
EZ
1046@cindex @code{--readnow}
1047@cindex @code{-r}
c906108c
SS
1048Read each symbol file's entire symbol table immediately, rather than
1049the default, which is to read it incrementally as it is needed.
1050This makes startup slower, but makes future operations faster.
53a5351d 1051
97cbe998
SDJ
1052@item --readnever
1053@anchor{--readnever}
1054@cindex @code{--readnever}, command-line option
1055Do not read each symbol file's symbolic debug information. This makes
1056startup faster but at the expense of not being able to perform
1057symbolic debugging. DWARF unwind information is also not read,
1058meaning backtraces may become incomplete or inaccurate. One use of
1059this is when a user simply wants to do the following sequence: attach,
1060dump core, detach. Loading the debugging information in this case is
1061an unnecessary cause of delay.
c906108c
SS
1062@end table
1063
6d2ebf8b 1064@node Mode Options
79a6e687 1065@subsection Choosing Modes
c906108c
SS
1066
1067You can run @value{GDBN} in various alternative modes---for example, in
1068batch mode or quiet mode.
1069
1070@table @code
bf88dd68 1071@anchor{-nx}
c906108c
SS
1072@item -nx
1073@itemx -n
d700128c
EZ
1074@cindex @code{--nx}
1075@cindex @code{-n}
07540c15
DE
1076Do not execute commands found in any initialization file.
1077There are three init files, loaded in the following order:
1078
1079@table @code
1080@item @file{system.gdbinit}
1081This is the system-wide init file.
1082Its location is specified with the @code{--with-system-gdbinit}
1083configure option (@pxref{System-wide configuration}).
1084It is loaded first when @value{GDBN} starts, before command line options
1085have been processed.
ed2a2229
CB
1086@item @file{system.gdbinit.d}
1087This is the system-wide init directory.
1088Its location is specified with the @code{--with-system-gdbinit-dir}
1089configure option (@pxref{System-wide configuration}).
1090Files in this directory are loaded in alphabetical order immediately after
1091system.gdbinit (if enabled) when @value{GDBN} starts, before command line
1092options have been processed. Files need to have a recognized scripting
1093language extension (@file{.py}/@file{.scm}) or be named with a @file{.gdb}
1094extension to be interpreted as regular @value{GDBN} commands. @value{GDBN}
1095will not recurse into any subdirectories of this directory.
07540c15
DE
1096@item @file{~/.gdbinit}
1097This is the init file in your home directory.
1098It is loaded next, after @file{system.gdbinit}, and before
1099command options have been processed.
1100@item @file{./.gdbinit}
1101This is the init file in the current directory.
1102It is loaded last, after command line options other than @code{-x} and
1103@code{-ex} have been processed. Command line options @code{-x} and
1104@code{-ex} are processed last, after @file{./.gdbinit} has been loaded.
1105@end table
1106
1107For further documentation on startup processing, @xref{Startup}.
1108For documentation on how to write command files,
1109@xref{Command Files,,Command Files}.
1110
1111@anchor{-nh}
1112@item -nh
1113@cindex @code{--nh}
1114Do not execute commands found in @file{~/.gdbinit}, the init file
1115in your home directory.
1116@xref{Startup}.
c906108c
SS
1117
1118@item -quiet
d700128c 1119@itemx -silent
c906108c 1120@itemx -q
d700128c
EZ
1121@cindex @code{--quiet}
1122@cindex @code{--silent}
1123@cindex @code{-q}
c906108c
SS
1124``Quiet''. Do not print the introductory and copyright messages. These
1125messages are also suppressed in batch mode.
1126
1127@item -batch
d700128c 1128@cindex @code{--batch}
c906108c
SS
1129Run in batch mode. Exit with status @code{0} after processing all the
1130command files specified with @samp{-x} (and all commands from
1131initialization files, if not inhibited with @samp{-n}). Exit with
1132nonzero status if an error occurs in executing the @value{GDBN} commands
5da1313b
JK
1133in the command files. Batch mode also disables pagination, sets unlimited
1134terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1135off} were in effect (@pxref{Messages/Warnings}).
c906108c 1136
2df3850c
JM
1137Batch mode may be useful for running @value{GDBN} as a filter, for
1138example to download and run a program on another computer; in order to
1139make this more useful, the message
c906108c 1140
474c8240 1141@smallexample
c906108c 1142Program exited normally.
474c8240 1143@end smallexample
c906108c
SS
1144
1145@noindent
2df3850c
JM
1146(which is ordinarily issued whenever a program running under
1147@value{GDBN} control terminates) is not issued when running in batch
1148mode.
1149
1a088d06
AS
1150@item -batch-silent
1151@cindex @code{--batch-silent}
1152Run in batch mode exactly like @samp{-batch}, but totally silently. All
1153@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1154unaffected). This is much quieter than @samp{-silent} and would be useless
1155for an interactive session.
1156
1157This is particularly useful when using targets that give @samp{Loading section}
1158messages, for example.
1159
1160Note that targets that give their output via @value{GDBN}, as opposed to
1161writing directly to @code{stdout}, will also be made silent.
1162
4b0ad762
AS
1163@item -return-child-result
1164@cindex @code{--return-child-result}
1165The return code from @value{GDBN} will be the return code from the child
1166process (the process being debugged), with the following exceptions:
1167
1168@itemize @bullet
1169@item
1170@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1171internal error. In this case the exit code is the same as it would have been
1172without @samp{-return-child-result}.
1173@item
1174The user quits with an explicit value. E.g., @samp{quit 1}.
1175@item
1176The child process never runs, or is not allowed to terminate, in which case
1177the exit code will be -1.
1178@end itemize
1179
1180This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1181when @value{GDBN} is being used as a remote program loader or simulator
1182interface.
1183
2df3850c
JM
1184@item -nowindows
1185@itemx -nw
d700128c
EZ
1186@cindex @code{--nowindows}
1187@cindex @code{-nw}
2df3850c 1188``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1189(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1190interface. If no GUI is available, this option has no effect.
1191
1192@item -windows
1193@itemx -w
d700128c
EZ
1194@cindex @code{--windows}
1195@cindex @code{-w}
2df3850c
JM
1196If @value{GDBN} includes a GUI, then this option requires it to be
1197used if possible.
c906108c
SS
1198
1199@item -cd @var{directory}
d700128c 1200@cindex @code{--cd}
c906108c
SS
1201Run @value{GDBN} using @var{directory} as its working directory,
1202instead of the current directory.
1203
aae1c79a 1204@item -data-directory @var{directory}
8d551b02 1205@itemx -D @var{directory}
aae1c79a 1206@cindex @code{--data-directory}
8d551b02 1207@cindex @code{-D}
aae1c79a
DE
1208Run @value{GDBN} using @var{directory} as its data directory.
1209The data directory is where @value{GDBN} searches for its
1210auxiliary files. @xref{Data Files}.
1211
c906108c
SS
1212@item -fullname
1213@itemx -f
d700128c
EZ
1214@cindex @code{--fullname}
1215@cindex @code{-f}
7a292a7a
SS
1216@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1217subprocess. It tells @value{GDBN} to output the full file name and line
1218number in a standard, recognizable fashion each time a stack frame is
1219displayed (which includes each time your program stops). This
1220recognizable format looks like two @samp{\032} characters, followed by
1221the file name, line number and character position separated by colons,
1222and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1223@samp{\032} characters as a signal to display the source code for the
1224frame.
c906108c 1225
d700128c
EZ
1226@item -annotate @var{level}
1227@cindex @code{--annotate}
1228This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1229effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1230(@pxref{Annotations}). The annotation @var{level} controls how much
1231information @value{GDBN} prints together with its prompt, values of
1232expressions, source lines, and other types of output. Level 0 is the
1233normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1234@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1235that control @value{GDBN}, and level 2 has been deprecated.
1236
265eeb58 1237The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1238(@pxref{GDB/MI}).
d700128c 1239
aa26fa3a
TT
1240@item --args
1241@cindex @code{--args}
1242Change interpretation of command line so that arguments following the
1243executable file are passed as command line arguments to the inferior.
1244This option stops option processing.
1245
2df3850c
JM
1246@item -baud @var{bps}
1247@itemx -b @var{bps}
d700128c
EZ
1248@cindex @code{--baud}
1249@cindex @code{-b}
c906108c
SS
1250Set the line speed (baud rate or bits per second) of any serial
1251interface used by @value{GDBN} for remote debugging.
c906108c 1252
f47b1503
AS
1253@item -l @var{timeout}
1254@cindex @code{-l}
1255Set the timeout (in seconds) of any communication used by @value{GDBN}
1256for remote debugging.
1257
c906108c 1258@item -tty @var{device}
d700128c
EZ
1259@itemx -t @var{device}
1260@cindex @code{--tty}
1261@cindex @code{-t}
c906108c
SS
1262Run using @var{device} for your program's standard input and output.
1263@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1264
53a5351d 1265@c resolve the situation of these eventually
c4555f82
SC
1266@item -tui
1267@cindex @code{--tui}
d0d5df6f
AC
1268Activate the @dfn{Text User Interface} when starting. The Text User
1269Interface manages several text windows on the terminal, showing
1270source, assembly, registers and @value{GDBN} command outputs
217bff3e
JK
1271(@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1272option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1273Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d 1274
d700128c
EZ
1275@item -interpreter @var{interp}
1276@cindex @code{--interpreter}
1277Use the interpreter @var{interp} for interface with the controlling
1278program or device. This option is meant to be set by programs which
94bbb2c0 1279communicate with @value{GDBN} using it as a back end.
21c294e6 1280@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1281
b4be1b06
SM
1282@samp{--interpreter=mi} (or @samp{--interpreter=mi3}) causes
1283@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} version 3 (@pxref{GDB/MI, ,
1284The @sc{gdb/mi} Interface}) included since @value{GDBN} version 9.1. @sc{gdb/mi}
1285version 2 (@code{mi2}), included in @value{GDBN} 6.0 and version 1 (@code{mi1}),
1286included in @value{GDBN} 5.3, are also available. Earlier @sc{gdb/mi}
1287interfaces are no longer supported.
d700128c
EZ
1288
1289@item -write
1290@cindex @code{--write}
1291Open the executable and core files for both reading and writing. This
1292is equivalent to the @samp{set write on} command inside @value{GDBN}
1293(@pxref{Patching}).
1294
1295@item -statistics
1296@cindex @code{--statistics}
1297This option causes @value{GDBN} to print statistics about time and
1298memory usage after it completes each command and returns to the prompt.
1299
1300@item -version
1301@cindex @code{--version}
1302This option causes @value{GDBN} to print its version number and
1303no-warranty blurb, and exit.
1304
6eaaf48b
EZ
1305@item -configuration
1306@cindex @code{--configuration}
1307This option causes @value{GDBN} to print details about its build-time
1308configuration parameters, and then exit. These details can be
1309important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1310
c906108c
SS
1311@end table
1312
6fc08d32 1313@node Startup
79a6e687 1314@subsection What @value{GDBN} Does During Startup
6fc08d32
EZ
1315@cindex @value{GDBN} startup
1316
1317Here's the description of what @value{GDBN} does during session startup:
1318
1319@enumerate
1320@item
1321Sets up the command interpreter as specified by the command line
1322(@pxref{Mode Options, interpreter}).
1323
1324@item
1325@cindex init file
098b41a6
JG
1326Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1327used when building @value{GDBN}; @pxref{System-wide configuration,
ed2a2229
CB
1328 ,System-wide configuration and settings}) and the files in the system-wide
1329gdbinit directory (if @option{--with-system-gdbinit-dir} was used) and executes
1330all the commands in those files. The files need to be named with a @file{.gdb}
1331extension to be interpreted as @value{GDBN} commands, or they can be written
1332in a supported scripting language with an appropriate file extension.
098b41a6 1333
bf88dd68 1334@anchor{Home Directory Init File}
098b41a6
JG
1335@item
1336Reads the init file (if any) in your home directory@footnote{On
6fc08d32
EZ
1337DOS/Windows systems, the home directory is the one pointed to by the
1338@code{HOME} environment variable.} and executes all the commands in
1339that file.
1340
2d7b58e8
JK
1341@anchor{Option -init-eval-command}
1342@item
1343Executes commands and command files specified by the @samp{-iex} and
1344@samp{-ix} options in their specified order. Usually you should use the
1345@samp{-ex} and @samp{-x} options instead, but this way you can apply
1346settings before @value{GDBN} init files get executed and before inferior
1347gets loaded.
1348
6fc08d32
EZ
1349@item
1350Processes command line options and operands.
1351
bf88dd68 1352@anchor{Init File in the Current Directory during Startup}
6fc08d32
EZ
1353@item
1354Reads and executes the commands from init file (if any) in the current
bf88dd68
JK
1355working directory as long as @samp{set auto-load local-gdbinit} is set to
1356@samp{on} (@pxref{Init File in the Current Directory}).
1357This is only done if the current directory is
119b882a
EZ
1358different from your home directory. Thus, you can have more than one
1359init file, one generic in your home directory, and another, specific
1360to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1361@value{GDBN}.
1362
a86caf66
DE
1363@item
1364If the command line specified a program to debug, or a process to
1365attach to, or a core file, @value{GDBN} loads any auto-loaded
1366scripts provided for the program or for its loaded shared libraries.
1367@xref{Auto-loading}.
1368
1369If you wish to disable the auto-loading during startup,
1370you must do something like the following:
1371
1372@smallexample
bf88dd68 1373$ gdb -iex "set auto-load python-scripts off" myprogram
a86caf66
DE
1374@end smallexample
1375
8320cc4f
JK
1376Option @samp{-ex} does not work because the auto-loading is then turned
1377off too late.
a86caf66 1378
6fc08d32 1379@item
6fe37d23
JK
1380Executes commands and command files specified by the @samp{-ex} and
1381@samp{-x} options in their specified order. @xref{Command Files}, for
1382more details about @value{GDBN} command files.
6fc08d32
EZ
1383
1384@item
1385Reads the command history recorded in the @dfn{history file}.
d620b259 1386@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1387files where @value{GDBN} records it.
1388@end enumerate
1389
1390Init files use the same syntax as @dfn{command files} (@pxref{Command
1391Files}) and are processed by @value{GDBN} in the same way. The init
1392file in your home directory can set options (such as @samp{set
1393complaints}) that affect subsequent processing of command line options
1394and operands. Init files are not executed if you use the @samp{-nx}
79a6e687 1395option (@pxref{Mode Options, ,Choosing Modes}).
6fc08d32 1396
098b41a6
JG
1397To display the list of init files loaded by gdb at startup, you
1398can use @kbd{gdb --help}.
1399
6fc08d32
EZ
1400@cindex init file name
1401@cindex @file{.gdbinit}
119b882a 1402@cindex @file{gdb.ini}
8807d78b 1403The @value{GDBN} init files are normally called @file{.gdbinit}.
119b882a
EZ
1404The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1405the limitations of file names imposed by DOS filesystems. The Windows
4d3f93a2
JB
1406port of @value{GDBN} uses the standard name, but if it finds a
1407@file{gdb.ini} file in your home directory, it warns you about that
1408and suggests to rename the file to the standard name.
119b882a 1409
6fc08d32 1410
6d2ebf8b 1411@node Quitting GDB
c906108c
SS
1412@section Quitting @value{GDBN}
1413@cindex exiting @value{GDBN}
1414@cindex leaving @value{GDBN}
1415
1416@table @code
1417@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1418@kindex q @r{(@code{quit})}
96a2c332
SS
1419@item quit @r{[}@var{expression}@r{]}
1420@itemx q
1421To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1422@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1423do not supply @var{expression}, @value{GDBN} will terminate normally;
1424otherwise it will terminate using the result of @var{expression} as the
1425error code.
c906108c
SS
1426@end table
1427
1428@cindex interrupt
c8aa23ab 1429An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1430terminates the action of any @value{GDBN} command that is in progress and
1431returns to @value{GDBN} command level. It is safe to type the interrupt
1432character at any time because @value{GDBN} does not allow it to take effect
1433until a time when it is safe.
1434
c906108c
SS
1435If you have been using @value{GDBN} to control an attached process or
1436device, you can release it with the @code{detach} command
79a6e687 1437(@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 1438
6d2ebf8b 1439@node Shell Commands
79a6e687 1440@section Shell Commands
c906108c
SS
1441
1442If you need to execute occasional shell commands during your
1443debugging session, there is no need to leave or suspend @value{GDBN}; you can
1444just use the @code{shell} command.
1445
1446@table @code
1447@kindex shell
ed59ded5 1448@kindex !
c906108c 1449@cindex shell escape
ed59ded5
DE
1450@item shell @var{command-string}
1451@itemx !@var{command-string}
1452Invoke a standard shell to execute @var{command-string}.
1453Note that no space is needed between @code{!} and @var{command-string}.
edf92af0
EZ
1454On GNU and Unix systems, the environment variable @code{SHELL}, if it
1455exists, determines which shell to run. Otherwise @value{GDBN} uses
1456the default shell (@file{/bin/sh} on GNU and Unix systems,
1457@file{cmd.exe} on MS-Windows, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1458@end table
1459
1460The utility @code{make} is often needed in development environments.
1461You do not have to use the @code{shell} command for this purpose in
1462@value{GDBN}:
1463
1464@table @code
1465@kindex make
1466@cindex calling make
1467@item make @var{make-args}
1468Execute the @code{make} program with the specified
1469arguments. This is equivalent to @samp{shell make @var{make-args}}.
1470@end table
1471
e2c52041
PW
1472@table @code
1473@kindex pipe
1474@kindex |
1475@cindex send the output of a gdb command to a shell command
1476@anchor{pipe}
1477@item pipe [@var{command}] | @var{shell_command}
1478@itemx | [@var{command}] | @var{shell_command}
1479@itemx pipe -d @var{delim} @var{command} @var{delim} @var{shell_command}
1480@itemx | -d @var{delim} @var{command} @var{delim} @var{shell_command}
1481Executes @var{command} and sends its output to @var{shell_command}.
1482Note that no space is needed around @code{|}.
1483If no @var{command} is provided, the last command executed is repeated.
1484
1485In case the @var{command} contains a @code{|}, the option @code{-d @var{delim}}
1486can be used to specify an alternate delimiter string @var{delim} that separates
1487the @var{command} from the @var{shell_command}.
1488
1489Example:
1490@smallexample
1491@group
1492(gdb) p var
1493$1 = @{
1494 black = 144,
1495 red = 233,
1496 green = 377,
1497 blue = 610,
1498 white = 987
1499@}
1500@end group
1501@group
1502(gdb) pipe p var|wc
1503 7 19 80
1504(gdb) |p var|wc -l
15057
1506@end group
1507@group
1508(gdb) p /x var
1509$4 = @{
1510 black = 0x90,
1511 red = 0xe9,
1512 green = 0x179,
1513 blue = 0x262,
1514 white = 0x3db
1515@}
1516(gdb) ||grep red
1517 red => 0xe9,
1518@end group
1519@group
1520(gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
1521this contains a PIPE char
1522(gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
1523this contains a PIPE char!
1524(gdb)
1525@end group
1526@end smallexample
1527@end table
1528
1529The convenience variables @code{$_shell_exitcode} and @code{$_shell_exitsignal}
1530can be used to examine the exit status of the last shell command launched
1531by @code{shell}, @code{make}, @code{pipe} and @code{|}.
1532@xref{Convenience Vars,, Convenience Variables}.
1533
79a6e687
BW
1534@node Logging Output
1535@section Logging Output
0fac0b41 1536@cindex logging @value{GDBN} output
9c16f35a 1537@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1538
1539You may want to save the output of @value{GDBN} commands to a file.
1540There are several commands to control @value{GDBN}'s logging.
1541
1542@table @code
1543@kindex set logging
1544@item set logging on
1545Enable logging.
1546@item set logging off
1547Disable logging.
9c16f35a 1548@cindex logging file name
0fac0b41
DJ
1549@item set logging file @var{file}
1550Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1551@item set logging overwrite [on|off]
1552By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1553you want @code{set logging on} to overwrite the logfile instead.
1554@item set logging redirect [on|off]
1555By default, @value{GDBN} output will go to both the terminal and the logfile.
1556Set @code{redirect} if you want output to go only to the log file.
b7060614
AH
1557@item set logging debugredirect [on|off]
1558By default, @value{GDBN} debug output will go to both the terminal and the logfile.
1559Set @code{debugredirect} if you want debug output to go only to the log file.
0fac0b41
DJ
1560@kindex show logging
1561@item show logging
1562Show the current values of the logging settings.
1563@end table
1564
e2c52041
PW
1565You can also redirect the output of a @value{GDBN} command to a
1566shell command. @xref{pipe}.
6d2ebf8b 1567@node Commands
c906108c
SS
1568@chapter @value{GDBN} Commands
1569
1570You can abbreviate a @value{GDBN} command to the first few letters of the command
1571name, if that abbreviation is unambiguous; and you can repeat certain
1572@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1573key to get @value{GDBN} to fill out the rest of a word in a command (or to
1574show you the alternatives available, if there is more than one possibility).
1575
1576@menu
1577* Command Syntax:: How to give commands to @value{GDBN}
fdbc9870 1578* Command Settings:: How to change default behavior of commands
c906108c 1579* Completion:: Command completion
3345721a 1580* Command Options:: Command options
5b860c93 1581* Command aliases default args:: Automatically prepend default arguments to user-defined aliases
c906108c
SS
1582* Help:: How to ask @value{GDBN} for help
1583@end menu
1584
6d2ebf8b 1585@node Command Syntax
79a6e687 1586@section Command Syntax
c906108c
SS
1587
1588A @value{GDBN} command is a single line of input. There is no limit on
1589how long it can be. It starts with a command name, which is followed by
1590arguments whose meaning depends on the command name. For example, the
1591command @code{step} accepts an argument which is the number of times to
1592step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1593with no arguments. Some commands do not allow any arguments.
c906108c
SS
1594
1595@cindex abbreviation
1596@value{GDBN} command names may always be truncated if that abbreviation is
1597unambiguous. Other possible command abbreviations are listed in the
1598documentation for individual commands. In some cases, even ambiguous
1599abbreviations are allowed; for example, @code{s} is specially defined as
1600equivalent to @code{step} even though there are other commands whose
1601names start with @code{s}. You can test abbreviations by using them as
1602arguments to the @code{help} command.
1603
1604@cindex repeating commands
41afff9a 1605@kindex RET @r{(repeat last command)}
c906108c 1606A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1607repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1608will not repeat this way; these are commands whose unintentional
1609repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1610repeat. User-defined commands can disable this feature; see
1611@ref{Define, dont-repeat}.
c906108c
SS
1612
1613The @code{list} and @code{x} commands, when you repeat them with
1614@key{RET}, construct new arguments rather than repeating
1615exactly as typed. This permits easy scanning of source or memory.
1616
1617@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1618output, in a way similar to the common utility @code{more}
79a6e687 1619(@pxref{Screen Size,,Screen Size}). Since it is easy to press one
c906108c
SS
1620@key{RET} too many in this situation, @value{GDBN} disables command
1621repetition after any command that generates this sort of display.
1622
41afff9a 1623@kindex # @r{(a comment)}
c906108c
SS
1624@cindex comment
1625Any text from a @kbd{#} to the end of the line is a comment; it does
1626nothing. This is useful mainly in command files (@pxref{Command
79a6e687 1627Files,,Command Files}).
c906108c 1628
88118b3a 1629@cindex repeating command sequences
c8aa23ab
EZ
1630@kindex Ctrl-o @r{(operate-and-get-next)}
1631The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1632commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1633then fetches the next line relative to the current line from the history
1634for editing.
1635
fdbc9870
PA
1636
1637@node Command Settings
1638@section Command Settings
1639@cindex default behavior of commands, changing
1640@cindex default settings, changing
1641
1642Many commands change their behavior according to command-specific
1643variables or settings. These settings can be changed with the
1644@code{set} subcommands. For example, the @code{print} command
1645(@pxref{Data, ,Examining Data}) prints arrays differently depending on
1646settings changeable with the commands @code{set print elements
1647NUMBER-OF-ELEMENTS} and @code{set print array-indexes}, among others.
1648
1649You can change these settings to your preference in the gdbinit files
1650loaded at @value{GDBN} startup. @xref{Startup}.
1651
1652The settings can also be changed interactively during the debugging
1653session. For example, to change the limit of array elements to print,
1654you can do the following:
1655@smallexample
1656(@value{GDBN}) set print elements 10
1657(@value{GDBN}) print some_array
1658$1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1659@end smallexample
1660
1661The above @code{set print elements 10} command changes the number of
1662elements to print from the default of 200 to 10. If you only intend
1663this limit of 10 to be used for printing @code{some_array}, then you
1664must restore the limit back to 200, with @code{set print elements
1665200}.
1666
1667Some commands allow overriding settings with command options. For
1668example, the @code{print} command supports a number of options that
1669allow overriding relevant global print settings as set by @code{set
1670print} subcommands. @xref{print options}. The example above could be
1671rewritten as:
1672@smallexample
1673(@value{GDBN}) print -elements 10 -- some_array
1674$1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1675@end smallexample
1676
1677Alternatively, you can use the @code{with} command to change a setting
1678temporarily, for the duration of a command invocation.
1679
1680@table @code
1681@kindex with command
1682@kindex w @r{(@code{with})}
1683@cindex settings
1684@cindex temporarily change settings
1685@item with @var{setting} [@var{value}] [-- @var{command}]
1686@itemx w @var{setting} [@var{value}] [-- @var{command}]
1687Temporarily set @var{setting} to @var{value} for the duration of
1688@var{command}.
1689
1690@var{setting} is any setting you can change with the @code{set}
1691subcommands. @var{value} is the value to assign to @code{setting}
1692while running @code{command}.
1693
1694If no @var{command} is provided, the last command executed is
1695repeated.
1696
1697If a @var{command} is provided, it must be preceded by a double dash
1698(@code{--}) separator. This is required because some settings accept
1699free-form arguments, such as expressions or filenames.
1700
1701For example, the command
1702@smallexample
1703(@value{GDBN}) with print array on -- print some_array
1704@end smallexample
1705@noindent
1706is equivalent to the following 3 commands:
1707@smallexample
1708(@value{GDBN}) set print array on
1709(@value{GDBN}) print some_array
1710(@value{GDBN}) set print array off
1711@end smallexample
1712
1713The @code{with} command is particularly useful when you want to
1714override a setting while running user-defined commands, or commands
1715defined in Python or Guile. @xref{Extending GDB,, Extending GDB}.
1716
1717@smallexample
1718(@value{GDBN}) with print pretty on -- my_complex_command
1719@end smallexample
1720
1721To change several settings for the same command, you can nest
1722@code{with} commands. For example, @code{with language ada -- with
1723print elements 10} temporarily changes the language to Ada and sets a
1724limit of 10 elements to print for arrays and strings.
1725
1726@end table
1727
6d2ebf8b 1728@node Completion
79a6e687 1729@section Command Completion
c906108c
SS
1730
1731@cindex completion
1732@cindex word completion
1733@value{GDBN} can fill in the rest of a word in a command for you, if there is
1734only one possibility; it can also show you what the valid possibilities
1735are for the next word in a command, at any time. This works for @value{GDBN}
3345721a
PA
1736commands, @value{GDBN} subcommands, command options, and the names of symbols
1737in your program.
c906108c
SS
1738
1739Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1740of a word. If there is only one possibility, @value{GDBN} fills in the
1741word, and waits for you to finish the command (or press @key{RET} to
1742enter it). For example, if you type
1743
1744@c FIXME "@key" does not distinguish its argument sufficiently to permit
1745@c complete accuracy in these examples; space introduced for clarity.
1746@c If texinfo enhancements make it unnecessary, it would be nice to
1747@c replace " @key" by "@key" in the following...
474c8240 1748@smallexample
c906108c 1749(@value{GDBP}) info bre @key{TAB}
474c8240 1750@end smallexample
c906108c
SS
1751
1752@noindent
1753@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1754the only @code{info} subcommand beginning with @samp{bre}:
1755
474c8240 1756@smallexample
c906108c 1757(@value{GDBP}) info breakpoints
474c8240 1758@end smallexample
c906108c
SS
1759
1760@noindent
1761You can either press @key{RET} at this point, to run the @code{info
1762breakpoints} command, or backspace and enter something else, if
1763@samp{breakpoints} does not look like the command you expected. (If you
1764were sure you wanted @code{info breakpoints} in the first place, you
1765might as well just type @key{RET} immediately after @samp{info bre},
1766to exploit command abbreviations rather than command completion).
1767
1768If there is more than one possibility for the next word when you press
1769@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1770characters and try again, or just press @key{TAB} a second time;
1771@value{GDBN} displays all the possible completions for that word. For
1772example, you might want to set a breakpoint on a subroutine whose name
1773begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1774just sounds the bell. Typing @key{TAB} again displays all the
1775function names in your program that begin with those characters, for
1776example:
1777
474c8240 1778@smallexample
c906108c
SS
1779(@value{GDBP}) b make_ @key{TAB}
1780@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1781make_a_section_from_file make_environ
1782make_abs_section make_function_type
1783make_blockvector make_pointer_type
1784make_cleanup make_reference_type
c906108c
SS
1785make_command make_symbol_completion_list
1786(@value{GDBP}) b make_
474c8240 1787@end smallexample
c906108c
SS
1788
1789@noindent
1790After displaying the available possibilities, @value{GDBN} copies your
1791partial input (@samp{b make_} in the example) so you can finish the
1792command.
1793
1794If you just want to see the list of alternatives in the first place, you
b37052ae 1795can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1796means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1797key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1798one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c 1799
ef0b411a
GB
1800If the number of possible completions is large, @value{GDBN} will
1801print as much of the list as it has collected, as well as a message
1802indicating that the list may be truncated.
1803
1804@smallexample
1805(@value{GDBP}) b m@key{TAB}@key{TAB}
1806main
1807<... the rest of the possible completions ...>
1808*** List may be truncated, max-completions reached. ***
1809(@value{GDBP}) b m
1810@end smallexample
1811
1812@noindent
1813This behavior can be controlled with the following commands:
1814
1815@table @code
1816@kindex set max-completions
1817@item set max-completions @var{limit}
1818@itemx set max-completions unlimited
1819Set the maximum number of completion candidates. @value{GDBN} will
1820stop looking for more completions once it collects this many candidates.
1821This is useful when completing on things like function names as collecting
1822all the possible candidates can be time consuming.
1823The default value is 200. A value of zero disables tab-completion.
1824Note that setting either no limit or a very large limit can make
1825completion slow.
1826@kindex show max-completions
1827@item show max-completions
1828Show the maximum number of candidates that @value{GDBN} will collect and show
1829during completion.
1830@end table
1831
c906108c
SS
1832@cindex quotes in commands
1833@cindex completion of quoted strings
1834Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1835parentheses or other characters that @value{GDBN} normally excludes from
1836its notion of a word. To permit word completion to work in this
1837situation, you may enclose words in @code{'} (single quote marks) in
1838@value{GDBN} commands.
c906108c 1839
d044bac8
PA
1840A likely situation where you might need this is in typing an
1841expression that involves a C@t{++} symbol name with template
1842parameters. This is because when completing expressions, GDB treats
1843the @samp{<} character as word delimiter, assuming that it's the
1844less-than comparison operator (@pxref{C Operators, , C and C@t{++}
1845Operators}).
1846
1847For example, when you want to call a C@t{++} template function
1848interactively using the @code{print} or @code{call} commands, you may
1849need to distinguish whether you mean the version of @code{name} that
1850was specialized for @code{int}, @code{name<int>()}, or the version
1851that was specialized for @code{float}, @code{name<float>()}. To use
1852the word-completion facilities in this situation, type a single quote
b37052ae
EZ
1853@code{'} at the beginning of the function name. This alerts
1854@value{GDBN} that it may need to consider more information than usual
1855when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1856
474c8240 1857@smallexample
d044bac8
PA
1858(@value{GDBP}) p 'func< @kbd{M-?}
1859func<int>() func<float>()
1860(@value{GDBP}) p 'func<
474c8240 1861@end smallexample
c906108c 1862
d044bac8
PA
1863When setting breakpoints however (@pxref{Specify Location}), you don't
1864usually need to type a quote before the function name, because
1865@value{GDBN} understands that you want to set a breakpoint on a
1866function:
c906108c 1867
474c8240 1868@smallexample
d044bac8
PA
1869(@value{GDBP}) b func< @kbd{M-?}
1870func<int>() func<float>()
1871(@value{GDBP}) b func<
474c8240 1872@end smallexample
c906108c 1873
d044bac8
PA
1874This is true even in the case of typing the name of C@t{++} overloaded
1875functions (multiple definitions of the same function, distinguished by
1876argument type). For example, when you want to set a breakpoint you
1877don't need to distinguish whether you mean the version of @code{name}
1878that takes an @code{int} parameter, @code{name(int)}, or the version
1879that takes a @code{float} parameter, @code{name(float)}.
1880
1881@smallexample
1882(@value{GDBP}) b bubble( @kbd{M-?}
1883bubble(int) bubble(double)
1884(@value{GDBP}) b bubble(dou @kbd{M-?}
1885bubble(double)
1886@end smallexample
1887
1888See @ref{quoting names} for a description of other scenarios that
1889require quoting.
c906108c 1890
79a6e687
BW
1891For more information about overloaded functions, see @ref{C Plus Plus
1892Expressions, ,C@t{++} Expressions}. You can use the command @code{set
c906108c 1893overload-resolution off} to disable overload resolution;
79a6e687 1894see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
c906108c 1895
65d12d83
TT
1896@cindex completion of structure field names
1897@cindex structure field name completion
1898@cindex completion of union field names
1899@cindex union field name completion
1900When completing in an expression which looks up a field in a
1901structure, @value{GDBN} also tries@footnote{The completer can be
1902confused by certain kinds of invalid expressions. Also, it only
1903examines the static type of the expression, not the dynamic type.} to
1904limit completions to the field names available in the type of the
1905left-hand-side:
1906
1907@smallexample
1908(@value{GDBP}) p gdb_stdout.@kbd{M-?}
01124a23
DE
1909magic to_fputs to_rewind
1910to_data to_isatty to_write
1911to_delete to_put to_write_async_safe
1912to_flush to_read
65d12d83
TT
1913@end smallexample
1914
1915@noindent
1916This is because the @code{gdb_stdout} is a variable of the type
1917@code{struct ui_file} that is defined in @value{GDBN} sources as
1918follows:
1919
1920@smallexample
1921struct ui_file
1922@{
1923 int *magic;
1924 ui_file_flush_ftype *to_flush;
1925 ui_file_write_ftype *to_write;
01124a23 1926 ui_file_write_async_safe_ftype *to_write_async_safe;
65d12d83
TT
1927 ui_file_fputs_ftype *to_fputs;
1928 ui_file_read_ftype *to_read;
1929 ui_file_delete_ftype *to_delete;
1930 ui_file_isatty_ftype *to_isatty;
1931 ui_file_rewind_ftype *to_rewind;
1932 ui_file_put_ftype *to_put;
1933 void *to_data;
1934@}
1935@end smallexample
1936
3345721a
PA
1937@node Command Options
1938@section Command options
1939
1940@cindex command options
1941Some commands accept options starting with a leading dash. For
1942example, @code{print -pretty}. Similarly to command names, you can
1943abbreviate a @value{GDBN} option to the first few letters of the
1944option name, if that abbreviation is unambiguous, and you can also use
1945the @key{TAB} key to get @value{GDBN} to fill out the rest of a word
1946in an option (or to show you the alternatives available, if there is
1947more than one possibility).
1948
1949@cindex command options, raw input
1950Some commands take raw input as argument. For example, the print
1951command processes arbitrary expressions in any of the languages
1952supported by @value{GDBN}. With such commands, because raw input may
1953start with a leading dash that would be confused with an option or any
d8edc8b7
PW
1954of its abbreviations, e.g.@: @code{print -p} (short for @code{print
1955-pretty} or printing negative @code{p}?), if you specify any command
3345721a
PA
1956option, then you must use a double-dash (@code{--}) delimiter to
1957indicate the end of options.
1958
1959@cindex command options, boolean
1960
1961Some options are described as accepting an argument which can be
1962either @code{on} or @code{off}. These are known as @dfn{boolean
1963options}. Similarly to boolean settings commands---@code{on} and
1964@code{off} are the typical values, but any of @code{1}, @code{yes} and
1965@code{enable} can also be used as ``true'' value, and any of @code{0},
1966@code{no} and @code{disable} can also be used as ``false'' value. You
1967can also omit a ``true'' value, as it is implied by default.
1968
1969For example, these are equivalent:
1970
1971@smallexample
1972(@value{GDBP}) print -object on -pretty off -element unlimited -- *myptr
1973(@value{GDBP}) p -o -p 0 -e u -- *myptr
1974@end smallexample
1975
1976You can discover the set of options some command accepts by completing
1977on @code{-} after the command name. For example:
1978
1979@smallexample
1980(@value{GDBP}) print -@key{TAB}@key{TAB}
d8edc8b7
PW
1981-address -max-depth -raw-values -union
1982-array -null-stop -repeats -vtbl
1983-array-indexes -object -static-members
1984-elements -pretty -symbol
3345721a
PA
1985@end smallexample
1986
1987Completion will in some cases guide you with a suggestion of what kind
1988of argument an option expects. For example:
1989
1990@smallexample
1991(@value{GDBP}) print -elements @key{TAB}@key{TAB}
1992NUMBER unlimited
1993@end smallexample
1994
1995Here, the option expects a number (e.g., @code{100}), not literal
1996@code{NUMBER}. Such metasyntactical arguments are always presented in
1997uppercase.
1998
1999(For more on using the @code{print} command, see @ref{Data, ,Examining
2000Data}.)
c906108c 2001
5b860c93
PW
2002@node Command aliases default args
2003@section Automatically prepend default arguments to user-defined aliases
2004
2005You can tell @value{GDBN} to always prepend some default arguments to
2006the list of arguments provided explicitly by the user when using a
2007user-defined alias.
2008
2009If you repeatedly use the same arguments or options for a command, you
2010can define an alias for this command and tell @value{GDBN} to
2011automatically prepend these arguments or options to the list of
2012arguments you type explicitly when using the alias@footnote{@value{GDBN}
2013could easily accept default arguments for pre-defined commands and aliases,
2014but it was deemed this would be confusing, and so is not allowed.}.
2015
2016For example, if you often use the command @code{thread apply all}
2017specifying to work on the threads in ascending order and to continue in case it
2018encounters an error, you can tell @value{GDBN} to automatically preprend
2019the @code{-ascending} and @code{-c} options by using:
2020
2021@smallexample
2022(@value{GDBP}) alias thread apply asc-all = thread apply all -ascending -c
2023@end smallexample
2024
2025Once you have defined this alias with its default args, any time you type
2026the @code{thread apply asc-all} followed by @code{some arguments},
2027@value{GDBN} will execute @code{thread apply all -ascending -c some arguments}.
2028
2029To have even less to type, you can also define a one word alias:
2030@smallexample
2031(@value{GDBP}) alias t_a_c = thread apply all -ascending -c
2032@end smallexample
2033
2034As usual, unambiguous abbreviations can be used for @var{alias}
2035and @var{default-args}.
2036
2037The different aliases of a command do not share their default args.
2038For example, you define a new alias @code{bt_ALL} showing all possible
2039information and another alias @code{bt_SMALL} showing very limited information
2040using:
2041@smallexample
2042(@value{GDBP}) alias bt_ALL = backtrace -entry-values both -frame-arg all \
2043 -past-main -past-entry -full
2044(@value{GDBP}) alias bt_SMALL = backtrace -entry-values no -frame-arg none \
2045 -past-main off -past-entry off
2046@end smallexample
2047
2048(For more on using the @code{alias} command, see @ref{Aliases}.)
2049
2050Default args are not limited to the arguments and options of @var{command},
2051but can specify nested commands if @var{command} accepts such a nested command
2052as argument.
2053For example, the below defines @code{faalocalsoftype} that lists the
2054frames having locals of a certain type, together with the matching
2055local vars:
2056@smallexample
2057(@value{GDBP}) alias faalocalsoftype = frame apply all info locals -q -t
2058(@value{GDBP}) faalocalsoftype int
2059#1 0x55554f5e in sleeper_or_burner (v=0xdf50) at sleepers.c:86
2060i = 0
2061ret = 21845
2062@end smallexample
2063
2064This is also very useful to define an alias for a set of nested @code{with}
2065commands to have a particular combination of temporary settings. For example,
2066the below defines the alias @code{pp10} that pretty prints an expression
2067argument, with a maximum of 10 elements if the expression is a string or
2068an array:
2069@smallexample
2070(@value{GDBP}) alias pp10 = with print pretty -- with print elements 10 -- print
2071@end smallexample
2072This defines the alias @code{pp10} as being a sequence of 3 commands.
2073The first part @code{with print pretty --} temporarily activates the setting
2074@code{set print pretty}, then launches the command that follows the separator
2075@code{--}.
2076The command following the first part is also a @code{with} command that
2077temporarily changes the setting @code{set print elements} to 10, then
2078launches the command that follows the second separator @code{--}.
2079The third part @code{print} is the command the @code{pp10} alias will launch,
2080using the temporary values of the settings and the arguments explicitly given
2081by the user.
2082For more information about the @code{with} command usage,
2083see @ref{Command Settings}.
2084
6d2ebf8b 2085@node Help
79a6e687 2086@section Getting Help
c906108c
SS
2087@cindex online documentation
2088@kindex help
2089
5d161b24 2090You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
2091using the command @code{help}.
2092
2093@table @code
41afff9a 2094@kindex h @r{(@code{help})}
c906108c
SS
2095@item help
2096@itemx h
2097You can use @code{help} (abbreviated @code{h}) with no arguments to
2098display a short list of named classes of commands:
2099
2100@smallexample
2101(@value{GDBP}) help
2102List of classes of commands:
2103
5b860c93 2104aliases -- User-defined aliases of other commands
c906108c 2105breakpoints -- Making program stop at certain points
2df3850c 2106data -- Examining data
c906108c 2107files -- Specifying and examining files
2df3850c
JM
2108internals -- Maintenance commands
2109obscure -- Obscure features
2110running -- Running the program
2111stack -- Examining the stack
c906108c
SS
2112status -- Status inquiries
2113support -- Support facilities
12c27660 2114tracepoints -- Tracing of program execution without
96a2c332 2115 stopping the program
c906108c 2116user-defined -- User-defined commands
c906108c 2117
5d161b24 2118Type "help" followed by a class name for a list of
c906108c 2119commands in that class.
5d161b24 2120Type "help" followed by command name for full
c906108c
SS
2121documentation.
2122Command name abbreviations are allowed if unambiguous.
2123(@value{GDBP})
2124@end smallexample
96a2c332 2125@c the above line break eliminates huge line overfull...
c906108c
SS
2126
2127@item help @var{class}
2128Using one of the general help classes as an argument, you can get a
5b4a1a8d
PW
2129list of the individual commands in that class. If a command has
2130aliases, the aliases are given after the command name, separated by
5b860c93
PW
2131commas. If an alias has default arguments, the full definition of
2132the alias is given after the first line.
2133For example, here is the help display for the class @code{status}:
c906108c
SS
2134
2135@smallexample
2136(@value{GDBP}) help status
2137Status inquiries.
2138
2139List of commands:
2140
2141@c Line break in "show" line falsifies real output, but needed
2142@c to fit in smallbook page size.
5b4a1a8d 2143info, inf, i -- Generic command for showing things
12c27660 2144 about the program being debugged
5b860c93
PW
2145info address, iamain -- Describe where symbol SYM is stored.
2146 alias iamain = info address main
2147info all-registers -- List of all registers and their contents,
2148 for selected stack frame.
5b4a1a8d
PW
2149...
2150show, info set -- Generic command for showing things
12c27660 2151 about the debugger
c906108c 2152
5d161b24 2153Type "help" followed by command name for full
c906108c
SS
2154documentation.
2155Command name abbreviations are allowed if unambiguous.
2156(@value{GDBP})
2157@end smallexample
2158
2159@item help @var{command}
2160With a command name as @code{help} argument, @value{GDBN} displays a
5b4a1a8d
PW
2161short paragraph on how to use that command. If that command has
2162one or more aliases, @value{GDBN} will display a first line with
2163the command name and all its aliases separated by commas.
5b860c93
PW
2164This first line will be followed by the full definition of all aliases
2165having default arguments.
c906108c 2166
6837a0a2 2167@kindex apropos
e664d728 2168@item apropos [-v] @var{regexp}
09d4efe1 2169The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2 2170commands, and their documentation, for the regular expression specified in
e664d728
PW
2171@var{args}. It prints out all matches found. The optional flag @samp{-v},
2172which stands for @samp{verbose}, indicates to output the full documentation
2173of the matching commands and highlight the parts of the documentation
2174matching @var{regexp}. For example:
6837a0a2
DB
2175
2176@smallexample
16899756 2177apropos alias
6837a0a2
DB
2178@end smallexample
2179
b37052ae
EZ
2180@noindent
2181results in:
6837a0a2
DB
2182
2183@smallexample
e664d728 2184@group
16899756 2185alias -- Define a new command that is an alias of an existing command
5b860c93 2186aliases -- User-defined aliases of other commands
e664d728
PW
2187@end group
2188@end smallexample
2189
2190@noindent
2191while
2192
2193@smallexample
2194apropos -v cut.*thread apply
2195@end smallexample
2196
2197@noindent
2198results in the below output, where @samp{cut for 'thread apply}
2199is highlighted if styling is enabled.
2200
2201@smallexample
2202@group
2203taas -- Apply a command to all threads (ignoring errors
2204and empty output).
2205Usage: taas COMMAND
2206shortcut for 'thread apply all -s COMMAND'
2207
2208tfaas -- Apply a command to all frames of all threads
2209(ignoring errors and empty output).
2210Usage: tfaas COMMAND
2211shortcut for 'thread apply all -s frame apply all -s COMMAND'
2212@end group
6837a0a2
DB
2213@end smallexample
2214
c906108c
SS
2215@kindex complete
2216@item complete @var{args}
2217The @code{complete @var{args}} command lists all the possible completions
2218for the beginning of a command. Use @var{args} to specify the beginning of the
2219command you want completed. For example:
2220
2221@smallexample
2222complete i
2223@end smallexample
2224
2225@noindent results in:
2226
2227@smallexample
2228@group
2df3850c
JM
2229if
2230ignore
c906108c
SS
2231info
2232inspect
c906108c
SS
2233@end group
2234@end smallexample
2235
2236@noindent This is intended for use by @sc{gnu} Emacs.
2237@end table
2238
2239In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
2240and @code{show} to inquire about the state of your program, or the state
2241of @value{GDBN} itself. Each command supports many topics of inquiry; this
2242manual introduces each of them in the appropriate context. The listings
00595b5e
EZ
2243under @code{info} and under @code{show} in the Command, Variable, and
2244Function Index point to all the sub-commands. @xref{Command and Variable
2245Index}.
c906108c
SS
2246
2247@c @group
2248@table @code
2249@kindex info
41afff9a 2250@kindex i @r{(@code{info})}
c906108c
SS
2251@item info
2252This command (abbreviated @code{i}) is for describing the state of your
cda4ce5a 2253program. For example, you can show the arguments passed to a function
c906108c
SS
2254with @code{info args}, list the registers currently in use with @code{info
2255registers}, or list the breakpoints you have set with @code{info breakpoints}.
2256You can get a complete list of the @code{info} sub-commands with
2257@w{@code{help info}}.
2258
2259@kindex set
2260@item set
5d161b24 2261You can assign the result of an expression to an environment variable with
c906108c
SS
2262@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
2263@code{set prompt $}.
2264
2265@kindex show
2266@item show
5d161b24 2267In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
2268@value{GDBN} itself.
2269You can change most of the things you can @code{show}, by using the
2270related command @code{set}; for example, you can control what number
2271system is used for displays with @code{set radix}, or simply inquire
2272which is currently in use with @code{show radix}.
2273
2274@kindex info set
2275To display all the settable parameters and their current
2276values, you can use @code{show} with no arguments; you may also use
2277@code{info set}. Both commands produce the same display.
2278@c FIXME: "info set" violates the rule that "info" is for state of
2279@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
2280@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2281@end table
2282@c @end group
2283
6eaaf48b 2284Here are several miscellaneous @code{show} subcommands, all of which are
c906108c
SS
2285exceptional in lacking corresponding @code{set} commands:
2286
2287@table @code
2288@kindex show version
9c16f35a 2289@cindex @value{GDBN} version number
c906108c
SS
2290@item show version
2291Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
2292information in @value{GDBN} bug-reports. If multiple versions of
2293@value{GDBN} are in use at your site, you may need to determine which
2294version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2295commands are introduced, and old ones may wither away. Also, many
2296system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 2297variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
2298The version number is the same as the one announced when you start
2299@value{GDBN}.
c906108c
SS
2300
2301@kindex show copying
09d4efe1 2302@kindex info copying
9c16f35a 2303@cindex display @value{GDBN} copyright
c906108c 2304@item show copying
09d4efe1 2305@itemx info copying
c906108c
SS
2306Display information about permission for copying @value{GDBN}.
2307
2308@kindex show warranty
09d4efe1 2309@kindex info warranty
c906108c 2310@item show warranty
09d4efe1 2311@itemx info warranty
2df3850c 2312Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 2313if your version of @value{GDBN} comes with one.
2df3850c 2314
6eaaf48b
EZ
2315@kindex show configuration
2316@item show configuration
2317Display detailed information about the way @value{GDBN} was configured
2318when it was built. This displays the optional arguments passed to the
2319@file{configure} script and also configuration parameters detected
2320automatically by @command{configure}. When reporting a @value{GDBN}
2321bug (@pxref{GDB Bugs}), it is important to include this information in
2322your report.
2323
c906108c
SS
2324@end table
2325
6d2ebf8b 2326@node Running
c906108c
SS
2327@chapter Running Programs Under @value{GDBN}
2328
2329When you run a program under @value{GDBN}, you must first generate
2330debugging information when you compile it.
7a292a7a
SS
2331
2332You may start @value{GDBN} with its arguments, if any, in an environment
2333of your choice. If you are doing native debugging, you may redirect
2334your program's input and output, debug an already running process, or
2335kill a child process.
c906108c
SS
2336
2337@menu
2338* Compilation:: Compiling for debugging
2339* Starting:: Starting your program
c906108c
SS
2340* Arguments:: Your program's arguments
2341* Environment:: Your program's environment
c906108c
SS
2342
2343* Working Directory:: Your program's working directory
2344* Input/Output:: Your program's input and output
2345* Attach:: Debugging an already-running process
2346* Kill Process:: Killing the child process
65c574f6
PA
2347* Inferiors Connections and Programs:: Debugging multiple inferiors
2348 connections and programs
c906108c 2349* Threads:: Debugging programs with multiple threads
6c95b8df 2350* Forks:: Debugging forks
5c95884b 2351* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
2352@end menu
2353
6d2ebf8b 2354@node Compilation
79a6e687 2355@section Compiling for Debugging
c906108c
SS
2356
2357In order to debug a program effectively, you need to generate
2358debugging information when you compile it. This debugging information
2359is stored in the object file; it describes the data type of each
2360variable or function and the correspondence between source line numbers
2361and addresses in the executable code.
2362
2363To request debugging information, specify the @samp{-g} option when you run
2364the compiler.
2365
514c4d71 2366Programs that are to be shipped to your customers are compiled with
edb3359d 2367optimizations, using the @samp{-O} compiler option. However, some
514c4d71
EZ
2368compilers are unable to handle the @samp{-g} and @samp{-O} options
2369together. Using those compilers, you cannot generate optimized
c906108c
SS
2370executables containing debugging information.
2371
514c4d71 2372@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
2373without @samp{-O}, making it possible to debug optimized code. We
2374recommend that you @emph{always} use @samp{-g} whenever you compile a
2375program. You may think your program is correct, but there is no sense
edb3359d 2376in pushing your luck. For more information, see @ref{Optimized Code}.
c906108c
SS
2377
2378Older versions of the @sc{gnu} C compiler permitted a variant option
2379@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2380format; if your @sc{gnu} C compiler has this option, do not use it.
2381
514c4d71
EZ
2382@value{GDBN} knows about preprocessor macros and can show you their
2383expansion (@pxref{Macros}). Most compilers do not include information
2384about preprocessor macros in the debugging information if you specify
e0f8f636
TT
2385the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2386the @sc{gnu} C compiler, provides macro information if you are using
2387the DWARF debugging format, and specify the option @option{-g3}.
2388
2389@xref{Debugging Options,,Options for Debugging Your Program or GCC,
f5a476a7 2390gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
e0f8f636
TT
2391information on @value{NGCC} options affecting debug information.
2392
2393You will have the best debugging experience if you use the latest
2394version of the DWARF debugging format that your compiler supports.
2395DWARF is currently the most expressive and best supported debugging
2396format in @value{GDBN}.
514c4d71 2397
c906108c 2398@need 2000
6d2ebf8b 2399@node Starting
79a6e687 2400@section Starting your Program
c906108c
SS
2401@cindex starting
2402@cindex running
2403
2404@table @code
2405@kindex run
41afff9a 2406@kindex r @r{(@code{run})}
c906108c
SS
2407@item run
2408@itemx r
7a292a7a 2409Use the @code{run} command to start your program under @value{GDBN}.
deb8ff2b
PA
2410You must first specify the program name with an argument to
2411@value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2412@value{GDBN}}), or by using the @code{file} or @code{exec-file}
2413command (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
2414
2415@end table
2416
c906108c
SS
2417If you are running your program in an execution environment that
2418supports processes, @code{run} creates an inferior process and makes
8edfe269
DJ
2419that process run your program. In some environments without processes,
2420@code{run} jumps to the start of your program. Other targets,
2421like @samp{remote}, are always running. If you get an error
2422message like this one:
2423
2424@smallexample
2425The "remote" target does not support "run".
2426Try "help target" or "continue".
2427@end smallexample
2428
2429@noindent
2430then use @code{continue} to run your program. You may need @code{load}
2431first (@pxref{load}).
c906108c
SS
2432
2433The execution of a program is affected by certain information it
2434receives from its superior. @value{GDBN} provides ways to specify this
2435information, which you must do @emph{before} starting your program. (You
2436can change it after starting your program, but such changes only affect
2437your program the next time you start it.) This information may be
2438divided into four categories:
2439
2440@table @asis
2441@item The @emph{arguments.}
2442Specify the arguments to give your program as the arguments of the
2443@code{run} command. If a shell is available on your target, the shell
2444is used to pass the arguments, so that you may use normal conventions
2445(such as wildcard expansion or variable substitution) in describing
2446the arguments.
2447In Unix systems, you can control which shell is used with the
98882a26
PA
2448@code{SHELL} environment variable. If you do not define @code{SHELL},
2449@value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2450use of any shell with the @code{set startup-with-shell} command (see
2451below for details).
c906108c
SS
2452
2453@item The @emph{environment.}
2454Your program normally inherits its environment from @value{GDBN}, but you can
2455use the @value{GDBN} commands @code{set environment} and @code{unset
2456environment} to change parts of the environment that affect
79a6e687 2457your program. @xref{Environment, ,Your Program's Environment}.
c906108c
SS
2458
2459@item The @emph{working directory.}
d092c5a2
SDJ
2460You can set your program's working directory with the command
2461@kbd{set cwd}. If you do not set any working directory with this
bc3b087d
SDJ
2462command, your program will inherit @value{GDBN}'s working directory if
2463native debugging, or the remote server's working directory if remote
2464debugging. @xref{Working Directory, ,Your Program's Working
2465Directory}.
c906108c
SS
2466
2467@item The @emph{standard input and output.}
2468Your program normally uses the same device for standard input and
2469standard output as @value{GDBN} is using. You can redirect input and output
2470in the @code{run} command line, or you can use the @code{tty} command to
2471set a different device for your program.
79a6e687 2472@xref{Input/Output, ,Your Program's Input and Output}.
c906108c
SS
2473
2474@cindex pipes
2475@emph{Warning:} While input and output redirection work, you cannot use
2476pipes to pass the output of the program you are debugging to another
2477program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2478wrong program.
2479@end table
c906108c
SS
2480
2481When you issue the @code{run} command, your program begins to execute
79a6e687 2482immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
c906108c
SS
2483of how to arrange for your program to stop. Once your program has
2484stopped, you may call functions in your program, using the @code{print}
2485or @code{call} commands. @xref{Data, ,Examining Data}.
2486
2487If the modification time of your symbol file has changed since the last
2488time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2489table, and reads it again. When it does this, @value{GDBN} tries to retain
2490your current breakpoints.
2491
4e8b0763
JB
2492@table @code
2493@kindex start
2494@item start
2495@cindex run to main procedure
2496The name of the main procedure can vary from language to language.
2497With C or C@t{++}, the main procedure name is always @code{main}, but
2498other languages such as Ada do not require a specific name for their
2499main procedure. The debugger provides a convenient way to start the
2500execution of the program and to stop at the beginning of the main
2501procedure, depending on the language used.
2502
2503The @samp{start} command does the equivalent of setting a temporary
2504breakpoint at the beginning of the main procedure and then invoking
2505the @samp{run} command.
2506
f018e82f
EZ
2507@cindex elaboration phase
2508Some programs contain an @dfn{elaboration} phase where some startup code is
2509executed before the main procedure is called. This depends on the
2510languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
2511constructors for static and global objects are executed before
2512@code{main} is called. It is therefore possible that the debugger stops
2513before reaching the main procedure. However, the temporary breakpoint
2514will remain to halt execution.
2515
2516Specify the arguments to give to your program as arguments to the
2517@samp{start} command. These arguments will be given verbatim to the
2518underlying @samp{run} command. Note that the same arguments will be
2519reused if no argument is provided during subsequent calls to
2520@samp{start} or @samp{run}.
2521
2522It is sometimes necessary to debug the program during elaboration. In
4e5a4f58
JB
2523these cases, using the @code{start} command would stop the execution
2524of your program too late, as the program would have already completed
2525the elaboration phase. Under these circumstances, either insert
2526breakpoints in your elaboration code before running your program or
2527use the @code{starti} command.
2528
2529@kindex starti
2530@item starti
2531@cindex run to first instruction
2532The @samp{starti} command does the equivalent of setting a temporary
2533breakpoint at the first instruction of a program's execution and then
2534invoking the @samp{run} command. For programs containing an
2535elaboration phase, the @code{starti} command will stop execution at
2536the start of the elaboration phase.
ccd213ac 2537
41ef2965 2538@anchor{set exec-wrapper}
ccd213ac
DJ
2539@kindex set exec-wrapper
2540@item set exec-wrapper @var{wrapper}
2541@itemx show exec-wrapper
2542@itemx unset exec-wrapper
2543When @samp{exec-wrapper} is set, the specified wrapper is used to
2544launch programs for debugging. @value{GDBN} starts your program
2545with a shell command of the form @kbd{exec @var{wrapper}
2546@var{program}}. Quoting is added to @var{program} and its
2547arguments, but not to @var{wrapper}, so you should add quotes if
2548appropriate for your shell. The wrapper runs until it executes
2549your program, and then @value{GDBN} takes control.
2550
2551You can use any program that eventually calls @code{execve} with
2552its arguments as a wrapper. Several standard Unix utilities do
2553this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2554with @code{exec "$@@"} will also work.
2555
2556For example, you can use @code{env} to pass an environment variable to
2557the debugged program, without setting the variable in your shell's
2558environment:
2559
2560@smallexample
2561(@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2562(@value{GDBP}) run
2563@end smallexample
2564
2565This command is available when debugging locally on most targets, excluding
2566@sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2567
98882a26 2568@kindex set startup-with-shell
aefd8b33 2569@anchor{set startup-with-shell}
98882a26
PA
2570@item set startup-with-shell
2571@itemx set startup-with-shell on
2572@itemx set startup-with-shell off
ca145713 2573@itemx show startup-with-shell
98882a26
PA
2574On Unix systems, by default, if a shell is available on your target,
2575@value{GDBN}) uses it to start your program. Arguments of the
2576@code{run} command are passed to the shell, which does variable
2577substitution, expands wildcard characters and performs redirection of
2578I/O. In some circumstances, it may be useful to disable such use of a
2579shell, for example, when debugging the shell itself or diagnosing
2580startup failures such as:
2581
2582@smallexample
2583(@value{GDBP}) run
2584Starting program: ./a.out
2585During startup program terminated with signal SIGSEGV, Segmentation fault.
2586@end smallexample
2587
2588@noindent
2589which indicates the shell or the wrapper specified with
2590@samp{exec-wrapper} crashed, not your program. Most often, this is
afa332ce
PA
2591caused by something odd in your shell's non-interactive mode
2592initialization file---such as @file{.cshrc} for C-shell,
2593$@file{.zshenv} for the Z shell, or the file specified in the
2594@samp{BASH_ENV} environment variable for BASH.
98882a26 2595
6a3cb8e8
PA
2596@anchor{set auto-connect-native-target}
2597@kindex set auto-connect-native-target
2598@item set auto-connect-native-target
2599@itemx set auto-connect-native-target on
2600@itemx set auto-connect-native-target off
2601@itemx show auto-connect-native-target
2602
65c574f6
PA
2603By default, if the current inferior is not connected to any target yet
2604(e.g., with @code{target remote}), the @code{run} command starts your
2605program as a native process under @value{GDBN}, on your local machine.
2606If you're sure you don't want to debug programs on your local machine,
2607you can tell @value{GDBN} to not connect to the native target
2608automatically with the @code{set auto-connect-native-target off}
2609command.
6a3cb8e8 2610
65c574f6 2611If @code{on}, which is the default, and if the current inferior is not
6a3cb8e8
PA
2612connected to a target already, the @code{run} command automaticaly
2613connects to the native target, if one is available.
2614
65c574f6
PA
2615If @code{off}, and if the current inferior is not connected to a
2616target already, the @code{run} command fails with an error:
6a3cb8e8
PA
2617
2618@smallexample
2619(@value{GDBP}) run
2620Don't know how to run. Try "help target".
2621@end smallexample
2622
65c574f6
PA
2623If the current inferior is already connected to a target, @value{GDBN}
2624always uses it with the @code{run} command.
6a3cb8e8
PA
2625
2626In any case, you can explicitly connect to the native target with the
2627@code{target native} command. For example,
2628
2629@smallexample
2630(@value{GDBP}) set auto-connect-native-target off
2631(@value{GDBP}) run
2632Don't know how to run. Try "help target".
2633(@value{GDBP}) target native
2634(@value{GDBP}) run
2635Starting program: ./a.out
2636[Inferior 1 (process 10421) exited normally]
2637@end smallexample
2638
2639In case you connected explicitly to the @code{native} target,
2640@value{GDBN} remains connected even if all inferiors exit, ready for
2641the next @code{run} command. Use the @code{disconnect} command to
2642disconnect.
2643
2644Examples of other commands that likewise respect the
2645@code{auto-connect-native-target} setting: @code{attach}, @code{info
2646proc}, @code{info os}.
2647
10568435
JK
2648@kindex set disable-randomization
2649@item set disable-randomization
2650@itemx set disable-randomization on
2651This option (enabled by default in @value{GDBN}) will turn off the native
2652randomization of the virtual address space of the started program. This option
2653is useful for multiple debugging sessions to make the execution better
2654reproducible and memory addresses reusable across debugging sessions.
2655
03583c20
UW
2656This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2657On @sc{gnu}/Linux you can get the same behavior using
10568435
JK
2658
2659@smallexample
2660(@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2661@end smallexample
2662
2663@item set disable-randomization off
2664Leave the behavior of the started executable unchanged. Some bugs rear their
2665ugly heads only when the program is loaded at certain addresses. If your bug
2666disappears when you run the program under @value{GDBN}, that might be because
2667@value{GDBN} by default disables the address randomization on platforms, such
2668as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2669disable-randomization off} to try to reproduce such elusive bugs.
2670
03583c20
UW
2671On targets where it is available, virtual address space randomization
2672protects the programs against certain kinds of security attacks. In these
10568435
JK
2673cases the attacker needs to know the exact location of a concrete executable
2674code. Randomizing its location makes it impossible to inject jumps misusing
2675a code at its expected addresses.
2676
2677Prelinking shared libraries provides a startup performance advantage but it
2678makes addresses in these libraries predictable for privileged processes by
2679having just unprivileged access at the target system. Reading the shared
2680library binary gives enough information for assembling the malicious code
2681misusing it. Still even a prelinked shared library can get loaded at a new
2682random address just requiring the regular relocation process during the
2683startup. Shared libraries not already prelinked are always loaded at
2684a randomly chosen address.
2685
2686Position independent executables (PIE) contain position independent code
2687similar to the shared libraries and therefore such executables get loaded at
2688a randomly chosen address upon startup. PIE executables always load even
2689already prelinked shared libraries at a random address. You can build such
2690executable using @command{gcc -fPIE -pie}.
2691
2692Heap (malloc storage), stack and custom mmap areas are always placed randomly
2693(as long as the randomization is enabled).
2694
2695@item show disable-randomization
2696Show the current setting of the explicit disable of the native randomization of
2697the virtual address space of the started program.
2698
4e8b0763
JB
2699@end table
2700
6d2ebf8b 2701@node Arguments
79a6e687 2702@section Your Program's Arguments
c906108c
SS
2703
2704@cindex arguments (to your program)
2705The arguments to your program can be specified by the arguments of the
5d161b24 2706@code{run} command.
c906108c
SS
2707They are passed to a shell, which expands wildcard characters and
2708performs redirection of I/O, and thence to your program. Your
2709@code{SHELL} environment variable (if it exists) specifies what shell
2710@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
2711the default shell (@file{/bin/sh} on Unix).
2712
2713On non-Unix systems, the program is usually invoked directly by
2714@value{GDBN}, which emulates I/O redirection via the appropriate system
2715calls, and the wildcard characters are expanded by the startup code of
2716the program, not by the shell.
c906108c
SS
2717
2718@code{run} with no arguments uses the same arguments used by the previous
2719@code{run}, or those set by the @code{set args} command.
2720
c906108c 2721@table @code
41afff9a 2722@kindex set args
c906108c
SS
2723@item set args
2724Specify the arguments to be used the next time your program is run. If
2725@code{set args} has no arguments, @code{run} executes your program
2726with no arguments. Once you have run your program with arguments,
2727using @code{set args} before the next @code{run} is the only way to run
2728it again without arguments.
2729
2730@kindex show args
2731@item show args
2732Show the arguments to give your program when it is started.
2733@end table
2734
6d2ebf8b 2735@node Environment
79a6e687 2736@section Your Program's Environment
c906108c
SS
2737
2738@cindex environment (of your program)
2739The @dfn{environment} consists of a set of environment variables and
2740their values. Environment variables conventionally record such things as
2741your user name, your home directory, your terminal type, and your search
2742path for programs to run. Usually you set up environment variables with
2743the shell and they are inherited by all the other programs you run. When
2744debugging, it can be useful to try running your program with a modified
2745environment without having to start @value{GDBN} over again.
2746
2747@table @code
2748@kindex path
2749@item path @var{directory}
2750Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
2751(the search path for executables) that will be passed to your program.
2752The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
2753You may specify several directory names, separated by whitespace or by a
2754system-dependent separator character (@samp{:} on Unix, @samp{;} on
2755MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2756is moved to the front, so it is searched sooner.
c906108c
SS
2757
2758You can use the string @samp{$cwd} to refer to whatever is the current
2759working directory at the time @value{GDBN} searches the path. If you
2760use @samp{.} instead, it refers to the directory where you executed the
2761@code{path} command. @value{GDBN} replaces @samp{.} in the
2762@var{directory} argument (with the current path) before adding
2763@var{directory} to the search path.
2764@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2765@c document that, since repeating it would be a no-op.
2766
2767@kindex show paths
2768@item show paths
2769Display the list of search paths for executables (the @code{PATH}
2770environment variable).
2771
2772@kindex show environment
2773@item show environment @r{[}@var{varname}@r{]}
2774Print the value of environment variable @var{varname} to be given to
2775your program when it starts. If you do not supply @var{varname},
2776print the names and values of all environment variables to be given to
2777your program. You can abbreviate @code{environment} as @code{env}.
2778
2779@kindex set environment
0a2dde4a 2780@anchor{set environment}
53a5351d 2781@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c 2782Set environment variable @var{varname} to @var{value}. The value
41ef2965 2783changes for your program (and the shell @value{GDBN} uses to launch
697aa1b7 2784it), not for @value{GDBN} itself. The @var{value} may be any string; the
41ef2965
PA
2785values of environment variables are just strings, and any
2786interpretation is supplied by your program itself. The @var{value}
c906108c
SS
2787parameter is optional; if it is eliminated, the variable is set to a
2788null value.
2789@c "any string" here does not include leading, trailing
2790@c blanks. Gnu asks: does anyone care?
2791
2792For example, this command:
2793
474c8240 2794@smallexample
c906108c 2795set env USER = foo
474c8240 2796@end smallexample
c906108c
SS
2797
2798@noindent
d4f3574e 2799tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2800@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2801are not actually required.)
2802
41ef2965
PA
2803Note that on Unix systems, @value{GDBN} runs your program via a shell,
2804which also inherits the environment set with @code{set environment}.
2805If necessary, you can avoid that by using the @samp{env} program as a
2806wrapper instead of using @code{set environment}. @xref{set
2807exec-wrapper}, for an example doing just that.
2808
0a2dde4a
SDJ
2809Environment variables that are set by the user are also transmitted to
2810@command{gdbserver} to be used when starting the remote inferior.
2811@pxref{QEnvironmentHexEncoded}.
2812
c906108c 2813@kindex unset environment
0a2dde4a 2814@anchor{unset environment}
c906108c
SS
2815@item unset environment @var{varname}
2816Remove variable @var{varname} from the environment to be passed to your
2817program. This is different from @samp{set env @var{varname} =};
2818@code{unset environment} removes the variable from the environment,
2819rather than assigning it an empty value.
0a2dde4a
SDJ
2820
2821Environment variables that are unset by the user are also unset on
2822@command{gdbserver} when starting the remote inferior.
2823@pxref{QEnvironmentUnset}.
c906108c
SS
2824@end table
2825
d4f3574e 2826@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
afa332ce
PA
2827the shell indicated by your @code{SHELL} environment variable if it
2828exists (or @code{/bin/sh} if not). If your @code{SHELL} variable
2829names a shell that runs an initialization file when started
2830non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2831for the Z shell, or the file specified in the @samp{BASH_ENV}
2832environment variable for BASH---any variables you set in that file
2833affect your program. You may wish to move setting of environment
2834variables to files that are only run when you sign on, such as
2835@file{.login} or @file{.profile}.
c906108c 2836
6d2ebf8b 2837@node Working Directory
79a6e687 2838@section Your Program's Working Directory
c906108c
SS
2839
2840@cindex working directory (of your program)
d092c5a2
SDJ
2841Each time you start your program with @code{run}, the inferior will be
2842initialized with the current working directory specified by the
2843@kbd{set cwd} command. If no directory has been specified by this
2844command, then the inferior will inherit @value{GDBN}'s current working
bc3b087d
SDJ
2845directory as its working directory if native debugging, or it will
2846inherit the remote server's current working directory if remote
2847debugging.
c906108c
SS
2848
2849@table @code
d092c5a2
SDJ
2850@kindex set cwd
2851@cindex change inferior's working directory
2852@anchor{set cwd command}
2853@item set cwd @r{[}@var{directory}@r{]}
2854Set the inferior's working directory to @var{directory}, which will be
2855@code{glob}-expanded in order to resolve tildes (@file{~}). If no
2856argument has been specified, the command clears the setting and resets
2857it to an empty state. This setting has no effect on @value{GDBN}'s
2858working directory, and it only takes effect the next time you start
2859the inferior. The @file{~} in @var{directory} is a short for the
2860@dfn{home directory}, usually pointed to by the @env{HOME} environment
2861variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2862uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2863fallback.
2864
2865You can also change @value{GDBN}'s current working directory by using
2866the @code{cd} command.
dbfa4523 2867@xref{cd command}.
d092c5a2
SDJ
2868
2869@kindex show cwd
2870@cindex show inferior's working directory
2871@item show cwd
2872Show the inferior's working directory. If no directory has been
2873specified by @kbd{set cwd}, then the default inferior's working
2874directory is the same as @value{GDBN}'s working directory.
2875
c906108c 2876@kindex cd
d092c5a2
SDJ
2877@cindex change @value{GDBN}'s working directory
2878@anchor{cd command}
f3c8a52a
JK
2879@item cd @r{[}@var{directory}@r{]}
2880Set the @value{GDBN} working directory to @var{directory}. If not
2881given, @var{directory} uses @file{'~'}.
c906108c 2882
d092c5a2
SDJ
2883The @value{GDBN} working directory serves as a default for the
2884commands that specify files for @value{GDBN} to operate on.
2885@xref{Files, ,Commands to Specify Files}.
dbfa4523 2886@xref{set cwd command}.
d092c5a2 2887
c906108c
SS
2888@kindex pwd
2889@item pwd
2890Print the @value{GDBN} working directory.
2891@end table
2892
60bf7e09
EZ
2893It is generally impossible to find the current working directory of
2894the process being debugged (since a program can change its directory
2d97a5d9 2895during its run). If you work on a system where @value{GDBN} supports
754452f0 2896the @code{info proc} command (@pxref{Process Information}), you can
2d97a5d9 2897use the @code{info proc} command to find out the
60bf7e09
EZ
2898current working directory of the debuggee.
2899
6d2ebf8b 2900@node Input/Output
79a6e687 2901@section Your Program's Input and Output
c906108c
SS
2902
2903@cindex redirection
2904@cindex i/o
2905@cindex terminal
2906By default, the program you run under @value{GDBN} does input and output to
5d161b24 2907the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2908to its own terminal modes to interact with you, but it records the terminal
2909modes your program was using and switches back to them when you continue
2910running your program.
2911
2912@table @code
2913@kindex info terminal
2914@item info terminal
2915Displays information recorded by @value{GDBN} about the terminal modes your
2916program is using.
2917@end table
2918
2919You can redirect your program's input and/or output using shell
2920redirection with the @code{run} command. For example,
2921
474c8240 2922@smallexample
c906108c 2923run > outfile
474c8240 2924@end smallexample
c906108c
SS
2925
2926@noindent
2927starts your program, diverting its output to the file @file{outfile}.
2928
2929@kindex tty
2930@cindex controlling terminal
2931Another way to specify where your program should do input and output is
2932with the @code{tty} command. This command accepts a file name as
2933argument, and causes this file to be the default for future @code{run}
2934commands. It also resets the controlling terminal for the child
2935process, for future @code{run} commands. For example,
2936
474c8240 2937@smallexample
c906108c 2938tty /dev/ttyb
474c8240 2939@end smallexample
c906108c
SS
2940
2941@noindent
2942directs that processes started with subsequent @code{run} commands
2943default to do input and output on the terminal @file{/dev/ttyb} and have
2944that as their controlling terminal.
2945
2946An explicit redirection in @code{run} overrides the @code{tty} command's
2947effect on the input/output device, but not its effect on the controlling
2948terminal.
2949
2950When you use the @code{tty} command or redirect input in the @code{run}
2951command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2952for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2953for @code{set inferior-tty}.
2954
2955@cindex inferior tty
2956@cindex set inferior controlling terminal
2957You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2958display the name of the terminal that will be used for future runs of your
2959program.
2960
2961@table @code
0a1ddfa6 2962@item set inferior-tty [ @var{tty} ]
3cb3b8df 2963@kindex set inferior-tty
0a1ddfa6
SM
2964Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
2965restores the default behavior, which is to use the same terminal as
2966@value{GDBN}.
3cb3b8df
BR
2967
2968@item show inferior-tty
2969@kindex show inferior-tty
2970Show the current tty for the program being debugged.
2971@end table
c906108c 2972
6d2ebf8b 2973@node Attach
79a6e687 2974@section Debugging an Already-running Process
c906108c
SS
2975@kindex attach
2976@cindex attach
2977
2978@table @code
2979@item attach @var{process-id}
2980This command attaches to a running process---one that was started
2981outside @value{GDBN}. (@code{info files} shows your active
2982targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2983find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2984or with the @samp{jobs -l} shell command.
2985
2986@code{attach} does not repeat if you press @key{RET} a second time after
2987executing the command.
2988@end table
2989
2990To use @code{attach}, your program must be running in an environment
2991which supports processes; for example, @code{attach} does not work for
2992programs on bare-board targets that lack an operating system. You must
2993also have permission to send the process a signal.
2994
2995When you use @code{attach}, the debugger finds the program running in
2996the process first by looking in the current working directory, then (if
2997the program is not found) by using the source file search path
79a6e687 2998(@pxref{Source Path, ,Specifying Source Directories}). You can also use
c906108c
SS
2999the @code{file} command to load the program. @xref{Files, ,Commands to
3000Specify Files}.
3001
e47e48f6 3002@anchor{set exec-file-mismatch}
98c59b52
PA
3003If the debugger can determine that the executable file running in the
3004process it is attaching to does not match the current exec-file loaded
3005by @value{GDBN}, the option @code{exec-file-mismatch} specifies how to
3006handle the mismatch. @value{GDBN} tries to compare the files by
3007comparing their build IDs (@pxref{build ID}), if available.
e47e48f6
PW
3008
3009@table @code
3010@kindex exec-file-mismatch
3011@cindex set exec-file-mismatch
3012@item set exec-file-mismatch @samp{ask|warn|off}
3013
98c59b52
PA
3014Whether to detect mismatch between the current executable file loaded
3015by @value{GDBN} and the executable file used to start the process. If
3016@samp{ask}, the default, display a warning and ask the user whether to
3017load the process executable file; if @samp{warn}, just display a
3018warning; if @samp{off}, don't attempt to detect a mismatch.
0a278aa7
PW
3019If the user confirms loading the process executable file, then its symbols
3020will be loaded as well.
e47e48f6
PW
3021
3022@cindex show exec-file-mismatch
3023@item show exec-file-mismatch
3024Show the current value of @code{exec-file-mismatch}.
3025
3026@end table
3027
c906108c
SS
3028The first thing @value{GDBN} does after arranging to debug the specified
3029process is to stop it. You can examine and modify an attached process
53a5351d
JM
3030with all the @value{GDBN} commands that are ordinarily available when
3031you start processes with @code{run}. You can insert breakpoints; you
3032can step and continue; you can modify storage. If you would rather the
3033process continue running, you may use the @code{continue} command after
c906108c
SS
3034attaching @value{GDBN} to the process.
3035
3036@table @code
3037@kindex detach
3038@item detach
3039When you have finished debugging the attached process, you can use the
3040@code{detach} command to release it from @value{GDBN} control. Detaching
3041the process continues its execution. After the @code{detach} command,
3042that process and @value{GDBN} become completely independent once more, and you
3043are ready to @code{attach} another process or start one with @code{run}.
3044@code{detach} does not repeat if you press @key{RET} again after
3045executing the command.
3046@end table
3047
159fcc13
JK
3048If you exit @value{GDBN} while you have an attached process, you detach
3049that process. If you use the @code{run} command, you kill that process.
3050By default, @value{GDBN} asks for confirmation if you try to do either of these
3051things; you can control whether or not you need to confirm by using the
3052@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
79a6e687 3053Messages}).
c906108c 3054
6d2ebf8b 3055@node Kill Process
79a6e687 3056@section Killing the Child Process
c906108c
SS
3057
3058@table @code
3059@kindex kill
3060@item kill
3061Kill the child process in which your program is running under @value{GDBN}.
3062@end table
3063
3064This command is useful if you wish to debug a core dump instead of a
3065running process. @value{GDBN} ignores any core dump file while your program
3066is running.
3067
3068On some operating systems, a program cannot be executed outside @value{GDBN}
3069while you have breakpoints set on it inside @value{GDBN}. You can use the
3070@code{kill} command in this situation to permit running your program
3071outside the debugger.
3072
3073The @code{kill} command is also useful if you wish to recompile and
3074relink your program, since on many systems it is impossible to modify an
3075executable file while it is running in a process. In this case, when you
3076next type @code{run}, @value{GDBN} notices that the file has changed, and
3077reads the symbol table again (while trying to preserve your current
3078breakpoint settings).
3079
65c574f6
PA
3080@node Inferiors Connections and Programs
3081@section Debugging Multiple Inferiors Connections and Programs
b77209e0 3082
6c95b8df
PA
3083@value{GDBN} lets you run and debug multiple programs in a single
3084session. In addition, @value{GDBN} on some systems may let you run
3085several programs simultaneously (otherwise you have to exit from one
65c574f6
PA
3086before starting another). On some systems @value{GDBN} may even let
3087you debug several programs simultaneously on different remote systems.
3088In the most general case, you can have multiple threads of execution
3089in each of multiple processes, launched from multiple executables,
3090running on different machines.
b77209e0
PA
3091
3092@cindex inferior
3093@value{GDBN} represents the state of each program execution with an
3094object called an @dfn{inferior}. An inferior typically corresponds to
3095a process, but is more general and applies also to targets that do not
3096have processes. Inferiors may be created before a process runs, and
6c95b8df
PA
3097may be retained after a process exits. Inferiors have unique
3098identifiers that are different from process ids. Usually each
3099inferior will also have its own distinct address space, although some
3100embedded targets may have several inferiors running in different parts
3101of a single address space. Each inferior may in turn have multiple
3102threads running in it.
b77209e0 3103
6c95b8df
PA
3104To find out what inferiors exist at any moment, use @w{@code{info
3105inferiors}}:
b77209e0
PA
3106
3107@table @code
a3c25011 3108@kindex info inferiors [ @var{id}@dots{} ]
b77209e0
PA
3109@item info inferiors
3110Print a list of all inferiors currently being managed by @value{GDBN}.
a3c25011
TT
3111By default all inferiors are printed, but the argument @var{id}@dots{}
3112-- a space separated list of inferior numbers -- can be used to limit
3113the display to just the requested inferiors.
3a1ff0b6
PA
3114
3115@value{GDBN} displays for each inferior (in this order):
3116
3117@enumerate
3118@item
3119the inferior number assigned by @value{GDBN}
3120
3121@item
3122the target system's inferior identifier
6c95b8df 3123
65c574f6
PA
3124@item
3125the target connection the inferior is bound to, including the unique
3126connection number assigned by @value{GDBN}, and the protocol used by
3127the connection.
3128
6c95b8df
PA
3129@item
3130the name of the executable the inferior is running.
3131
3a1ff0b6
PA
3132@end enumerate
3133
3134@noindent
3135An asterisk @samp{*} preceding the @value{GDBN} inferior number
3136indicates the current inferior.
3137
3138For example,
2277426b 3139@end table
3a1ff0b6
PA
3140@c end table here to get a little more width for example
3141
3142@smallexample
3143(@value{GDBP}) info inferiors
65c574f6
PA
3144 Num Description Connection Executable
3145* 1 process 3401 1 (native) goodbye
3146 2 process 2307 2 (extended-remote host:10000) hello
3147@end smallexample
3148
3149To find out what open target connections exist at any moment, use
3150@w{@code{info connections}}:
3151
3152@table @code
3153@kindex info connections [ @var{id}@dots{} ]
3154@item info connections
3155Print a list of all open target connections currently being managed by
3156@value{GDBN}. By default all connections are printed, but the
3157argument @var{id}@dots{} -- a space separated list of connections
3158numbers -- can be used to limit the display to just the requested
3159connections.
3160
3161@value{GDBN} displays for each connection (in this order):
3162
3163@enumerate
3164@item
3165the connection number assigned by @value{GDBN}.
3166
3167@item
3168the protocol used by the connection.
3169
3170@item
3171a textual description of the protocol used by the connection.
3172
3173@end enumerate
3174
3175@noindent
3176An asterisk @samp{*} preceding the connection number indicates the
3177connection of the current inferior.
3178
3179For example,
3180@end table
3181@c end table here to get a little more width for example
3182
3183@smallexample
3184(@value{GDBP}) info connections
3185 Num What Description
3186* 1 extended-remote host:10000 Extended remote serial target in gdb-specific protocol
3187 2 native Native process
3188 3 core Local core dump file
3a1ff0b6 3189@end smallexample
2277426b
PA
3190
3191To switch focus between inferiors, use the @code{inferior} command:
3192
3193@table @code
3a1ff0b6
PA
3194@kindex inferior @var{infno}
3195@item inferior @var{infno}
3196Make inferior number @var{infno} the current inferior. The argument
3197@var{infno} is the inferior number assigned by @value{GDBN}, as shown
3198in the first field of the @samp{info inferiors} display.
2277426b
PA
3199@end table
3200
e3940304
PA
3201@vindex $_inferior@r{, convenience variable}
3202The debugger convenience variable @samp{$_inferior} contains the
3203number of the current inferior. You may find this useful in writing
3204breakpoint conditional expressions, command scripts, and so forth.
3205@xref{Convenience Vars,, Convenience Variables}, for general
3206information on convenience variables.
6c95b8df
PA
3207
3208You can get multiple executables into a debugging session via the
3209@code{add-inferior} and @w{@code{clone-inferior}} commands. On some
3210systems @value{GDBN} can add inferiors to the debug session
3211automatically by following calls to @code{fork} and @code{exec}. To
3212remove inferiors from the debugging session use the
af624141 3213@w{@code{remove-inferiors}} command.
6c95b8df
PA
3214
3215@table @code
3216@kindex add-inferior
65c574f6 3217@item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
6c95b8df 3218Adds @var{n} inferiors to be run using @var{executable} as the
697aa1b7 3219executable; @var{n} defaults to 1. If no executable is specified,
6c95b8df
PA
3220the inferiors begins empty, with no program. You can still assign or
3221change the program assigned to the inferior at any time by using the
3222@code{file} command with the executable name as its argument.
3223
65c574f6
PA
3224By default, the new inferior begins connected to the same target
3225connection as the current inferior. For example, if the current
3226inferior was connected to @code{gdbserver} with @code{target remote},
3227then the new inferior will be connected to the same @code{gdbserver}
3228instance. The @samp{-no-connection} option starts the new inferior
3229with no connection yet. You can then for example use the @code{target
3230remote} command to connect to some other @code{gdbserver} instance,
3231use @code{run} to spawn a local program, etc.
3232
6c95b8df
PA
3233@kindex clone-inferior
3234@item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
3235Adds @var{n} inferiors ready to execute the same program as inferior
697aa1b7 3236@var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
6c95b8df
PA
3237number of the current inferior. This is a convenient command when you
3238want to run another instance of the inferior you are debugging.
3239
3240@smallexample
3241(@value{GDBP}) info inferiors
65c574f6
PA
3242 Num Description Connection Executable
3243* 1 process 29964 1 (native) helloworld
6c95b8df
PA
3244(@value{GDBP}) clone-inferior
3245Added inferior 2.
32461 inferiors added.
3247(@value{GDBP}) info inferiors
65c574f6
PA
3248 Num Description Connection Executable
3249* 1 process 29964 1 (native) helloworld
3250 2 <null> 1 (native) helloworld
6c95b8df
PA
3251@end smallexample
3252
3253You can now simply switch focus to inferior 2 and run it.
3254
af624141
MS
3255@kindex remove-inferiors
3256@item remove-inferiors @var{infno}@dots{}
3257Removes the inferior or inferiors @var{infno}@dots{}. It is not
3258possible to remove an inferior that is running with this command. For
3259those, use the @code{kill} or @code{detach} command first.
6c95b8df
PA
3260
3261@end table
3262
3263To quit debugging one of the running inferiors that is not the current
3264inferior, you can either detach from it by using the @w{@code{detach
3265inferior}} command (allowing it to run independently), or kill it
af624141 3266using the @w{@code{kill inferiors}} command:
2277426b
PA
3267
3268@table @code
af624141
MS
3269@kindex detach inferiors @var{infno}@dots{}
3270@item detach inferior @var{infno}@dots{}
3271Detach from the inferior or inferiors identified by @value{GDBN}
5e30da2c 3272inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
af624141
MS
3273still stays on the list of inferiors shown by @code{info inferiors},
3274but its Description will show @samp{<null>}.
3275
3276@kindex kill inferiors @var{infno}@dots{}
3277@item kill inferiors @var{infno}@dots{}
3278Kill the inferior or inferiors identified by @value{GDBN} inferior
3279number(s) @var{infno}@dots{}. Note that the inferior's entry still
3280stays on the list of inferiors shown by @code{info inferiors}, but its
3281Description will show @samp{<null>}.
2277426b
PA
3282@end table
3283
6c95b8df 3284After the successful completion of a command such as @code{detach},
af624141 3285@code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
6c95b8df
PA
3286a normal process exit, the inferior is still valid and listed with
3287@code{info inferiors}, ready to be restarted.
3288
3289
2277426b
PA
3290To be notified when inferiors are started or exit under @value{GDBN}'s
3291control use @w{@code{set print inferior-events}}:
b77209e0 3292
2277426b 3293@table @code
b77209e0
PA
3294@kindex set print inferior-events
3295@cindex print messages on inferior start and exit
3296@item set print inferior-events
3297@itemx set print inferior-events on
3298@itemx set print inferior-events off
3299The @code{set print inferior-events} command allows you to enable or
3300disable printing of messages when @value{GDBN} notices that new
3301inferiors have started or that inferiors have exited or have been
3302detached. By default, these messages will not be printed.
3303
3304@kindex show print inferior-events
3305@item show print inferior-events
3306Show whether messages will be printed when @value{GDBN} detects that
3307inferiors have started, exited or have been detached.
3308@end table
3309
6c95b8df
PA
3310Many commands will work the same with multiple programs as with a
3311single program: e.g., @code{print myglobal} will simply display the
3312value of @code{myglobal} in the current inferior.
3313
3314
6b92c0d3 3315Occasionally, when debugging @value{GDBN} itself, it may be useful to
6c95b8df
PA
3316get more info about the relationship of inferiors, programs, address
3317spaces in a debug session. You can do that with the @w{@code{maint
3318info program-spaces}} command.
3319
3320@table @code
3321@kindex maint info program-spaces
3322@item maint info program-spaces
3323Print a list of all program spaces currently being managed by
3324@value{GDBN}.
3325
3326@value{GDBN} displays for each program space (in this order):
3327
3328@enumerate
3329@item
3330the program space number assigned by @value{GDBN}
3331
3332@item
3333the name of the executable loaded into the program space, with e.g.,
3334the @code{file} command.
3335
3336@end enumerate
3337
3338@noindent
3339An asterisk @samp{*} preceding the @value{GDBN} program space number
3340indicates the current program space.
3341
3342In addition, below each program space line, @value{GDBN} prints extra
3343information that isn't suitable to display in tabular form. For
3344example, the list of inferiors bound to the program space.
3345
3346@smallexample
3347(@value{GDBP}) maint info program-spaces
3348 Id Executable
b05b1202 3349* 1 hello
6c95b8df
PA
3350 2 goodbye
3351 Bound inferiors: ID 1 (process 21561)
6c95b8df
PA
3352@end smallexample
3353
3354Here we can see that no inferior is running the program @code{hello},
3355while @code{process 21561} is running the program @code{goodbye}. On
3356some targets, it is possible that multiple inferiors are bound to the
3357same program space. The most common example is that of debugging both
3358the parent and child processes of a @code{vfork} call. For example,
3359
3360@smallexample
3361(@value{GDBP}) maint info program-spaces
3362 Id Executable
3363* 1 vfork-test
3364 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3365@end smallexample
3366
3367Here, both inferior 2 and inferior 1 are running in the same program
3368space as a result of inferior 1 having executed a @code{vfork} call.
3369@end table
3370
6d2ebf8b 3371@node Threads
79a6e687 3372@section Debugging Programs with Multiple Threads
c906108c
SS
3373
3374@cindex threads of execution
3375@cindex multiple threads
3376@cindex switching threads
b1236ac3 3377In some operating systems, such as GNU/Linux and Solaris, a single program
c906108c
SS
3378may have more than one @dfn{thread} of execution. The precise semantics
3379of threads differ from one operating system to another, but in general
3380the threads of a single program are akin to multiple processes---except
3381that they share one address space (that is, they can all examine and
3382modify the same variables). On the other hand, each thread has its own
3383registers and execution stack, and perhaps private memory.
3384
3385@value{GDBN} provides these facilities for debugging multi-thread
3386programs:
3387
3388@itemize @bullet
3389@item automatic notification of new threads
5d5658a1 3390@item @samp{thread @var{thread-id}}, a command to switch among threads
c906108c 3391@item @samp{info threads}, a command to inquire about existing threads
0a232300 3392@item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
c906108c
SS
3393a command to apply a command to a list of threads
3394@item thread-specific breakpoints
93815fbf
VP
3395@item @samp{set print thread-events}, which controls printing of
3396messages on thread start and exit.
17a37d48
PP
3397@item @samp{set libthread-db-search-path @var{path}}, which lets
3398the user specify which @code{libthread_db} to use if the default choice
3399isn't compatible with the program.
c906108c
SS
3400@end itemize
3401
c906108c
SS
3402@cindex focus of debugging
3403@cindex current thread
3404The @value{GDBN} thread debugging facility allows you to observe all
3405threads while your program runs---but whenever @value{GDBN} takes
3406control, one thread in particular is always the focus of debugging.
3407This thread is called the @dfn{current thread}. Debugging commands show
3408program information from the perspective of the current thread.
3409
41afff9a 3410@cindex @code{New} @var{systag} message
c906108c
SS
3411@cindex thread identifier (system)
3412@c FIXME-implementors!! It would be more helpful if the [New...] message
3413@c included GDB's numeric thread handle, so you could just go to that
3414@c thread without first checking `info threads'.
3415Whenever @value{GDBN} detects a new thread in your program, it displays
3416the target system's identification for the thread with a message in the
697aa1b7 3417form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
c906108c 3418whose form varies depending on the particular system. For example, on
8807d78b 3419@sc{gnu}/Linux, you might see
c906108c 3420
474c8240 3421@smallexample
08e796bc 3422[New Thread 0x41e02940 (LWP 25582)]
474c8240 3423@end smallexample
c906108c
SS
3424
3425@noindent
b1236ac3 3426when @value{GDBN} notices a new thread. In contrast, on other systems,
c906108c
SS
3427the @var{systag} is simply something like @samp{process 368}, with no
3428further qualifier.
3429
3430@c FIXME!! (1) Does the [New...] message appear even for the very first
3431@c thread of a program, or does it only appear for the
6ca652b0 3432@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
3433@c program?
3434@c (2) *Is* there necessarily a first thread always? Or do some
3435@c multithread systems permit starting a program with multiple
5d161b24 3436@c threads ab initio?
c906108c 3437
5d5658a1
PA
3438@anchor{thread numbers}
3439@cindex thread number, per inferior
c906108c 3440@cindex thread identifier (GDB)
5d5658a1
PA
3441For debugging purposes, @value{GDBN} associates its own thread number
3442---always a single integer---with each thread of an inferior. This
3443number is unique between all threads of an inferior, but not unique
3444between threads of different inferiors.
3445
3446@cindex qualified thread ID
3447You can refer to a given thread in an inferior using the qualified
3448@var{inferior-num}.@var{thread-num} syntax, also known as
3449@dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3450number and @var{thread-num} being the thread number of the given
3451inferior. For example, thread @code{2.3} refers to thread number 3 of
3452inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
3453then @value{GDBN} infers you're referring to a thread of the current
3454inferior.
3455
3456Until you create a second inferior, @value{GDBN} does not show the
3457@var{inferior-num} part of thread IDs, even though you can always use
3458the full @var{inferior-num}.@var{thread-num} form to refer to threads
3459of inferior 1, the initial inferior.
3460
3461@anchor{thread ID lists}
3462@cindex thread ID lists
3463Some commands accept a space-separated @dfn{thread ID list} as
71ef29a8
PA
3464argument. A list element can be:
3465
3466@enumerate
3467@item
3468A thread ID as shown in the first field of the @samp{info threads}
3469display, with or without an inferior qualifier. E.g., @samp{2.1} or
3470@samp{1}.
3471
3472@item
3473A range of thread numbers, again with or without an inferior
3474qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3475@var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3476
3477@item
3478All threads of an inferior, specified with a star wildcard, with or
3479without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3480@samp{1.*}) or @code{*}. The former refers to all threads of the
3481given inferior, and the latter form without an inferior qualifier
3482refers to all threads of the current inferior.
3483
3484@end enumerate
3485
3486For example, if the current inferior is 1, and inferior 7 has one
3487thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3488includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
34897 to 9 of inferior 6 and all threads of inferior 7. That is, in
3490expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
34917.1}.
3492
5d5658a1
PA
3493
3494@anchor{global thread numbers}
3495@cindex global thread number
3496@cindex global thread identifier (GDB)
3497In addition to a @emph{per-inferior} number, each thread is also
3498assigned a unique @emph{global} number, also known as @dfn{global
3499thread ID}, a single integer. Unlike the thread number component of
3500the thread ID, no two threads have the same global ID, even when
3501you're debugging multiple inferiors.
c906108c 3502
f4f4330e
PA
3503From @value{GDBN}'s perspective, a process always has at least one
3504thread. In other words, @value{GDBN} assigns a thread number to the
3505program's ``main thread'' even if the program is not multi-threaded.
3506
5d5658a1 3507@vindex $_thread@r{, convenience variable}
663f6d42
PA
3508@vindex $_gthread@r{, convenience variable}
3509The debugger convenience variables @samp{$_thread} and
3510@samp{$_gthread} contain, respectively, the per-inferior thread number
3511and the global thread number of the current thread. You may find this
5d5658a1
PA
3512useful in writing breakpoint conditional expressions, command scripts,
3513and so forth. @xref{Convenience Vars,, Convenience Variables}, for
3514general information on convenience variables.
3515
f303dbd6
PA
3516If @value{GDBN} detects the program is multi-threaded, it augments the
3517usual message about stopping at a breakpoint with the ID and name of
3518the thread that hit the breakpoint.
3519
3520@smallexample
3521Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3522@end smallexample
3523
3524Likewise when the program receives a signal:
3525
3526@smallexample
3527Thread 1 "main" received signal SIGINT, Interrupt.
3528@end smallexample
3529
c906108c
SS
3530@table @code
3531@kindex info threads
5d5658a1
PA
3532@item info threads @r{[}@var{thread-id-list}@r{]}
3533
3534Display information about one or more threads. With no arguments
3535displays information about all threads. You can specify the list of
3536threads that you want to display using the thread ID list syntax
3537(@pxref{thread ID lists}).
3538
60f98dde 3539@value{GDBN} displays for each thread (in this order):
c906108c
SS
3540
3541@enumerate
09d4efe1 3542@item
5d5658a1 3543the per-inferior thread number assigned by @value{GDBN}
c906108c 3544
c84f6bbf
PA
3545@item
3546the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3547option was specified
3548
09d4efe1
EZ
3549@item
3550the target system's thread identifier (@var{systag})
c906108c 3551
4694da01
TT
3552@item
3553the thread's name, if one is known. A thread can either be named by
3554the user (see @code{thread name}, below), or, in some cases, by the
3555program itself.
3556
09d4efe1
EZ
3557@item
3558the current stack frame summary for that thread
c906108c
SS
3559@end enumerate
3560
3561@noindent
3562An asterisk @samp{*} to the left of the @value{GDBN} thread number
3563indicates the current thread.
3564
5d161b24 3565For example,
c906108c
SS
3566@end table
3567@c end table here to get a little more width for example
3568
3569@smallexample
3570(@value{GDBP}) info threads
e56d7f1e 3571 Id Target Id Frame
c0ecb95f 3572* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
b05b1202
PA
3573 2 process 35 thread 23 0x34e5 in sigpause ()
3574 3 process 35 thread 27 0x34e5 in sigpause ()
c906108c
SS
3575 at threadtest.c:68
3576@end smallexample
53a5351d 3577
5d5658a1
PA
3578If you're debugging multiple inferiors, @value{GDBN} displays thread
3579IDs using the qualified @var{inferior-num}.@var{thread-num} format.
c84f6bbf
PA
3580Otherwise, only @var{thread-num} is shown.
3581
3582If you specify the @samp{-gid} option, @value{GDBN} displays a column
3583indicating each thread's global thread ID:
5d5658a1
PA
3584
3585@smallexample
3586(@value{GDBP}) info threads
c84f6bbf
PA
3587 Id GId Target Id Frame
3588 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3589 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3590 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3591* 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
5d5658a1
PA
3592@end smallexample
3593
c45da7e6
EZ
3594On Solaris, you can display more information about user threads with a
3595Solaris-specific command:
3596
3597@table @code
3598@item maint info sol-threads
3599@kindex maint info sol-threads
3600@cindex thread info (Solaris)
3601Display info on Solaris user threads.
3602@end table
3603
c906108c 3604@table @code
5d5658a1
PA
3605@kindex thread @var{thread-id}
3606@item thread @var{thread-id}
3607Make thread ID @var{thread-id} the current thread. The command
3608argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3609the first field of the @samp{info threads} display, with or without an
3610inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3611
3612@value{GDBN} responds by displaying the system identifier of the
3613thread you selected, and its current stack frame summary:
c906108c
SS
3614
3615@smallexample
c906108c 3616(@value{GDBP}) thread 2
13fd8b81
TT
3617[Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3618#0 some_function (ignore=0x0) at example.c:8
36198 printf ("hello\n");
c906108c
SS
3620@end smallexample
3621
3622@noindent
3623As with the @samp{[New @dots{}]} message, the form of the text after
3624@samp{Switching to} depends on your system's conventions for identifying
5d161b24 3625threads.
c906108c 3626
3345721a 3627@anchor{thread apply all}
9c16f35a 3628@kindex thread apply
638ac427 3629@cindex apply command to several threads
0a232300 3630@item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
839c27b7 3631The @code{thread apply} command allows you to apply the named
5d5658a1
PA
3632@var{command} to one or more threads. Specify the threads that you
3633want affected using the thread ID list syntax (@pxref{thread ID
3634lists}), or specify @code{all} to apply to all threads. To apply a
3635command to all threads in descending order, type @kbd{thread apply all
253828f1
JK
3636@var{command}}. To apply a command to all threads in ascending order,
3637type @kbd{thread apply all -ascending @var{command}}.
3638
0a232300
PW
3639The @var{flag} arguments control what output to produce and how to handle
3640errors raised when applying @var{command} to a thread. @var{flag}
3641must start with a @code{-} directly followed by one letter in
3642@code{qcs}. If several flags are provided, they must be given
3643individually, such as @code{-c -q}.
3644
3645By default, @value{GDBN} displays some thread information before the
3646output produced by @var{command}, and an error raised during the
3647execution of a @var{command} will abort @code{thread apply}. The
3648following flags can be used to fine-tune this behavior:
3649
3650@table @code
3651@item -c
3652The flag @code{-c}, which stands for @samp{continue}, causes any
3653errors in @var{command} to be displayed, and the execution of
3654@code{thread apply} then continues.
3655@item -s
3656The flag @code{-s}, which stands for @samp{silent}, causes any errors
3657or empty output produced by a @var{command} to be silently ignored.
3658That is, the execution continues, but the thread information and errors
3659are not printed.
3660@item -q
3661The flag @code{-q} (@samp{quiet}) disables printing the thread
3662information.
3663@end table
3664
3665Flags @code{-c} and @code{-s} cannot be used together.
3666
3667@kindex taas
3668@cindex apply command to all threads (ignoring errors and empty output)
3345721a
PA
3669@item taas [@var{option}]@dots{} @var{command}
3670Shortcut for @code{thread apply all -s [@var{option}]@dots{} @var{command}}.
0a232300
PW
3671Applies @var{command} on all threads, ignoring errors and empty output.
3672
3345721a
PA
3673The @code{taas} command accepts the same options as the @code{thread
3674apply all} command. @xref{thread apply all}.
3675
0a232300
PW
3676@kindex tfaas
3677@cindex apply a command to all frames of all threads (ignoring errors and empty output)
3345721a
PA
3678@item tfaas [@var{option}]@dots{} @var{command}
3679Shortcut for @code{thread apply all -s -- frame apply all -s [@var{option}]@dots{} @var{command}}.
0a232300
PW
3680Applies @var{command} on all frames of all threads, ignoring errors
3681and empty output. Note that the flag @code{-s} is specified twice:
3682The first @code{-s} ensures that @code{thread apply} only shows the thread
3683information of the threads for which @code{frame apply} produces
3684some output. The second @code{-s} is needed to ensure that @code{frame
3685apply} shows the frame information of a frame only if the
3686@var{command} successfully produced some output.
3687
3688It can for example be used to print a local variable or a function
3689argument without knowing the thread or frame where this variable or argument
3690is, using:
3691@smallexample
3692(@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3693@end smallexample
3694
3345721a 3695The @code{tfaas} command accepts the same options as the @code{frame
ed788fee 3696apply} command. @xref{Frame Apply,,frame apply}.
93815fbf 3697
4694da01
TT
3698@kindex thread name
3699@cindex name a thread
3700@item thread name [@var{name}]
3701This command assigns a name to the current thread. If no argument is
3702given, any existing user-specified name is removed. The thread name
3703appears in the @samp{info threads} display.
3704
3705On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3706determine the name of the thread as given by the OS. On these
3707systems, a name specified with @samp{thread name} will override the
3708system-give name, and removing the user-specified name will cause
3709@value{GDBN} to once again display the system-specified name.
3710
60f98dde
MS
3711@kindex thread find
3712@cindex search for a thread
3713@item thread find [@var{regexp}]
3714Search for and display thread ids whose name or @var{systag}
3715matches the supplied regular expression.
3716
3717As well as being the complement to the @samp{thread name} command,
3718this command also allows you to identify a thread by its target
3719@var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3720is the LWP id.
3721
3722@smallexample
3723(@value{GDBN}) thread find 26688
3724Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3725(@value{GDBN}) info thread 4
3726 Id Target Id Frame
3727 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3728@end smallexample
3729
93815fbf
VP
3730@kindex set print thread-events
3731@cindex print messages on thread start and exit
3732@item set print thread-events
3733@itemx set print thread-events on
3734@itemx set print thread-events off
3735The @code{set print thread-events} command allows you to enable or
3736disable printing of messages when @value{GDBN} notices that new threads have
3737started or that threads have exited. By default, these messages will
3738be printed if detection of these events is supported by the target.
3739Note that these messages cannot be disabled on all targets.
3740
3741@kindex show print thread-events
3742@item show print thread-events
3743Show whether messages will be printed when @value{GDBN} detects that threads
3744have started and exited.
c906108c
SS
3745@end table
3746
79a6e687 3747@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
c906108c
SS
3748more information about how @value{GDBN} behaves when you stop and start
3749programs with multiple threads.
3750
79a6e687 3751@xref{Set Watchpoints,,Setting Watchpoints}, for information about
c906108c 3752watchpoints in programs with multiple threads.
c906108c 3753
bf88dd68 3754@anchor{set libthread-db-search-path}
17a37d48
PP
3755@table @code
3756@kindex set libthread-db-search-path
3757@cindex search path for @code{libthread_db}
3758@item set libthread-db-search-path @r{[}@var{path}@r{]}
3759If this variable is set, @var{path} is a colon-separated list of
3760directories @value{GDBN} will use to search for @code{libthread_db}.
3761If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
98a5dd13 3762its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
7e0396aa
DE
3763Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3764macro.
17a37d48
PP
3765
3766On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3767@code{libthread_db} library to obtain information about threads in the
3768inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
bf88dd68
JK
3769to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3770specific thread debugging library loading is enabled
3771by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3772
3773A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3774refers to the default system directories that are
bf88dd68
JK
3775normally searched for loading shared libraries. The @samp{$sdir} entry
3776is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3777(@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3778
3779A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3780refers to the directory from which @code{libpthread}
3781was loaded in the inferior process.
17a37d48
PP
3782
3783For any @code{libthread_db} library @value{GDBN} finds in above directories,
3784@value{GDBN} attempts to initialize it with the current inferior process.
3785If this initialization fails (which could happen because of a version
3786mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3787will unload @code{libthread_db}, and continue with the next directory.
3788If none of @code{libthread_db} libraries initialize successfully,
3789@value{GDBN} will issue a warning and thread debugging will be disabled.
3790
3791Setting @code{libthread-db-search-path} is currently implemented
3792only on some platforms.
3793
3794@kindex show libthread-db-search-path
3795@item show libthread-db-search-path
3796Display current libthread_db search path.
02d868e8
PP
3797
3798@kindex set debug libthread-db
3799@kindex show debug libthread-db
3800@cindex debugging @code{libthread_db}
3801@item set debug libthread-db
3802@itemx show debug libthread-db
3803Turns on or off display of @code{libthread_db}-related events.
3804Use @code{1} to enable, @code{0} to disable.
17a37d48
PP
3805@end table
3806
6c95b8df
PA
3807@node Forks
3808@section Debugging Forks
c906108c
SS
3809
3810@cindex fork, debugging programs which call
3811@cindex multiple processes
3812@cindex processes, multiple
53a5351d
JM
3813On most systems, @value{GDBN} has no special support for debugging
3814programs which create additional processes using the @code{fork}
3815function. When a program forks, @value{GDBN} will continue to debug the
3816parent process and the child process will run unimpeded. If you have
3817set a breakpoint in any code which the child then executes, the child
3818will get a @code{SIGTRAP} signal which (unless it catches the signal)
3819will cause it to terminate.
c906108c
SS
3820
3821However, if you want to debug the child process there is a workaround
3822which isn't too painful. Put a call to @code{sleep} in the code which
3823the child process executes after the fork. It may be useful to sleep
3824only if a certain environment variable is set, or a certain file exists,
3825so that the delay need not occur when you don't want to run @value{GDBN}
3826on the child. While the child is sleeping, use the @code{ps} program to
3827get its process ID. Then tell @value{GDBN} (a new invocation of
3828@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 3829the child process (@pxref{Attach}). From that point on you can debug
c906108c 3830the child process just like any other process which you attached to.
c906108c 3831
b1236ac3
PA
3832On some systems, @value{GDBN} provides support for debugging programs
3833that create additional processes using the @code{fork} or @code{vfork}
3834functions. On @sc{gnu}/Linux platforms, this feature is supported
19d9d4ef 3835with kernel version 2.5.46 and later.
c906108c 3836
19d9d4ef
DB
3837The fork debugging commands are supported in native mode and when
3838connected to @code{gdbserver} in either @code{target remote} mode or
3839@code{target extended-remote} mode.
0d71eef5 3840
c906108c
SS
3841By default, when a program forks, @value{GDBN} will continue to debug
3842the parent process and the child process will run unimpeded.
3843
3844If you want to follow the child process instead of the parent process,
3845use the command @w{@code{set follow-fork-mode}}.
3846
3847@table @code
3848@kindex set follow-fork-mode
3849@item set follow-fork-mode @var{mode}
3850Set the debugger response to a program call of @code{fork} or
3851@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 3852process. The @var{mode} argument can be:
c906108c
SS
3853
3854@table @code
3855@item parent
3856The original process is debugged after a fork. The child process runs
2df3850c 3857unimpeded. This is the default.
c906108c
SS
3858
3859@item child
3860The new process is debugged after a fork. The parent process runs
3861unimpeded.
3862
c906108c
SS
3863@end table
3864
9c16f35a 3865@kindex show follow-fork-mode
c906108c 3866@item show follow-fork-mode
2df3850c 3867Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
3868@end table
3869
5c95884b
MS
3870@cindex debugging multiple processes
3871On Linux, if you want to debug both the parent and child processes, use the
3872command @w{@code{set detach-on-fork}}.
3873
3874@table @code
3875@kindex set detach-on-fork
3876@item set detach-on-fork @var{mode}
3877Tells gdb whether to detach one of the processes after a fork, or
3878retain debugger control over them both.
3879
3880@table @code
3881@item on
3882The child process (or parent process, depending on the value of
3883@code{follow-fork-mode}) will be detached and allowed to run
3884independently. This is the default.
3885
3886@item off
3887Both processes will be held under the control of @value{GDBN}.
3888One process (child or parent, depending on the value of
3889@code{follow-fork-mode}) is debugged as usual, while the other
3890is held suspended.
3891
3892@end table
3893
11310833
NR
3894@kindex show detach-on-fork
3895@item show detach-on-fork
3896Show whether detach-on-fork mode is on/off.
5c95884b
MS
3897@end table
3898
2277426b
PA
3899If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3900will retain control of all forked processes (including nested forks).
3901You can list the forked processes under the control of @value{GDBN} by
3902using the @w{@code{info inferiors}} command, and switch from one fork
65c574f6
PA
3903to another by using the @code{inferior} command (@pxref{Inferiors Connections and
3904Programs, ,Debugging Multiple Inferiors Connections and Programs}).
5c95884b
MS
3905
3906To quit debugging one of the forked processes, you can either detach
af624141
MS
3907from it by using the @w{@code{detach inferiors}} command (allowing it
3908to run independently), or kill it using the @w{@code{kill inferiors}}
65c574f6
PA
3909command. @xref{Inferiors Connections and Programs, ,Debugging
3910Multiple Inferiors Connections and Programs}.
5c95884b 3911
c906108c
SS
3912If you ask to debug a child process and a @code{vfork} is followed by an
3913@code{exec}, @value{GDBN} executes the new target up to the first
3914breakpoint in the new target. If you have a breakpoint set on
3915@code{main} in your original program, the breakpoint will also be set on
3916the child process's @code{main}.
3917
2277426b
PA
3918On some systems, when a child process is spawned by @code{vfork}, you
3919cannot debug the child or parent until an @code{exec} call completes.
c906108c
SS
3920
3921If you issue a @code{run} command to @value{GDBN} after an @code{exec}
6c95b8df
PA
3922call executes, the new target restarts. To restart the parent
3923process, use the @code{file} command with the parent executable name
3924as its argument. By default, after an @code{exec} call executes,
3925@value{GDBN} discards the symbols of the previous executable image.
3926You can change this behaviour with the @w{@code{set follow-exec-mode}}
3927command.
3928
3929@table @code
3930@kindex set follow-exec-mode
3931@item set follow-exec-mode @var{mode}
3932
3933Set debugger response to a program call of @code{exec}. An
3934@code{exec} call replaces the program image of a process.
3935
3936@code{follow-exec-mode} can be:
3937
3938@table @code
3939@item new
3940@value{GDBN} creates a new inferior and rebinds the process to this
3941new inferior. The program the process was running before the
3942@code{exec} call can be restarted afterwards by restarting the
3943original inferior.
3944
3945For example:
3946
3947@smallexample
3948(@value{GDBP}) info inferiors
3949(gdb) info inferior
3950 Id Description Executable
3951* 1 <null> prog1
3952(@value{GDBP}) run
3953process 12020 is executing new program: prog2
3954Program exited normally.
3955(@value{GDBP}) info inferiors
3956 Id Description Executable
c0ecb95f 3957 1 <null> prog1
b05b1202 3958* 2 <null> prog2
6c95b8df
PA
3959@end smallexample
3960
3961@item same
3962@value{GDBN} keeps the process bound to the same inferior. The new
3963executable image replaces the previous executable loaded in the
3964inferior. Restarting the inferior after the @code{exec} call, with
3965e.g., the @code{run} command, restarts the executable the process was
3966running after the @code{exec} call. This is the default mode.
3967
3968For example:
3969
3970@smallexample
3971(@value{GDBP}) info inferiors
3972 Id Description Executable
3973* 1 <null> prog1
3974(@value{GDBP}) run
3975process 12020 is executing new program: prog2
3976Program exited normally.
3977(@value{GDBP}) info inferiors
3978 Id Description Executable
3979* 1 <null> prog2
3980@end smallexample
3981
3982@end table
3983@end table
c906108c 3984
19d9d4ef
DB
3985@code{follow-exec-mode} is supported in native mode and
3986@code{target extended-remote} mode.
3987
c906108c
SS
3988You can use the @code{catch} command to make @value{GDBN} stop whenever
3989a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
79a6e687 3990Catchpoints, ,Setting Catchpoints}.
c906108c 3991
5c95884b 3992@node Checkpoint/Restart
79a6e687 3993@section Setting a @emph{Bookmark} to Return to Later
5c95884b
MS
3994
3995@cindex checkpoint
3996@cindex restart
3997@cindex bookmark
3998@cindex snapshot of a process
3999@cindex rewind program state
4000
4001On certain operating systems@footnote{Currently, only
4002@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
4003program's state, called a @dfn{checkpoint}, and come back to it
4004later.
4005
4006Returning to a checkpoint effectively undoes everything that has
4007happened in the program since the @code{checkpoint} was saved. This
4008includes changes in memory, registers, and even (within some limits)
4009system state. Effectively, it is like going back in time to the
4010moment when the checkpoint was saved.
4011
4012Thus, if you're stepping thru a program and you think you're
4013getting close to the point where things go wrong, you can save
4014a checkpoint. Then, if you accidentally go too far and miss
4015the critical statement, instead of having to restart your program
4016from the beginning, you can just go back to the checkpoint and
4017start again from there.
4018
4019This can be especially useful if it takes a lot of time or
4020steps to reach the point where you think the bug occurs.
4021
4022To use the @code{checkpoint}/@code{restart} method of debugging:
4023
4024@table @code
4025@kindex checkpoint
4026@item checkpoint
4027Save a snapshot of the debugged program's current execution state.
4028The @code{checkpoint} command takes no arguments, but each checkpoint
4029is assigned a small integer id, similar to a breakpoint id.
4030
4031@kindex info checkpoints
4032@item info checkpoints
4033List the checkpoints that have been saved in the current debugging
4034session. For each checkpoint, the following information will be
4035listed:
4036
4037@table @code
4038@item Checkpoint ID
4039@item Process ID
4040@item Code Address
4041@item Source line, or label
4042@end table
4043
4044@kindex restart @var{checkpoint-id}
4045@item restart @var{checkpoint-id}
4046Restore the program state that was saved as checkpoint number
4047@var{checkpoint-id}. All program variables, registers, stack frames
4048etc.@: will be returned to the values that they had when the checkpoint
4049was saved. In essence, gdb will ``wind back the clock'' to the point
4050in time when the checkpoint was saved.
4051
4052Note that breakpoints, @value{GDBN} variables, command history etc.
4053are not affected by restoring a checkpoint. In general, a checkpoint
4054only restores things that reside in the program being debugged, not in
4055the debugger.
4056
b8db102d
MS
4057@kindex delete checkpoint @var{checkpoint-id}
4058@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
4059Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
4060
4061@end table
4062
4063Returning to a previously saved checkpoint will restore the user state
4064of the program being debugged, plus a significant subset of the system
4065(OS) state, including file pointers. It won't ``un-write'' data from
4066a file, but it will rewind the file pointer to the previous location,
4067so that the previously written data can be overwritten. For files
4068opened in read mode, the pointer will also be restored so that the
4069previously read data can be read again.
4070
4071Of course, characters that have been sent to a printer (or other
4072external device) cannot be ``snatched back'', and characters received
4073from eg.@: a serial device can be removed from internal program buffers,
4074but they cannot be ``pushed back'' into the serial pipeline, ready to
4075be received again. Similarly, the actual contents of files that have
4076been changed cannot be restored (at this time).
4077
4078However, within those constraints, you actually can ``rewind'' your
4079program to a previously saved point in time, and begin debugging it
4080again --- and you can change the course of events so as to debug a
4081different execution path this time.
4082
4083@cindex checkpoints and process id
4084Finally, there is one bit of internal program state that will be
4085different when you return to a checkpoint --- the program's process
4086id. Each checkpoint will have a unique process id (or @var{pid}),
4087and each will be different from the program's original @var{pid}.
4088If your program has saved a local copy of its process id, this could
4089potentially pose a problem.
4090
79a6e687 4091@subsection A Non-obvious Benefit of Using Checkpoints
5c95884b
MS
4092
4093On some systems such as @sc{gnu}/Linux, address space randomization
4094is performed on new processes for security reasons. This makes it
4095difficult or impossible to set a breakpoint, or watchpoint, on an
4096absolute address if you have to restart the program, since the
4097absolute location of a symbol will change from one execution to the
4098next.
4099
4100A checkpoint, however, is an @emph{identical} copy of a process.
4101Therefore if you create a checkpoint at (eg.@:) the start of main,
4102and simply return to that checkpoint instead of restarting the
4103process, you can avoid the effects of address randomization and
4104your symbols will all stay in the same place.
4105
6d2ebf8b 4106@node Stopping
c906108c
SS
4107@chapter Stopping and Continuing
4108
4109The principal purposes of using a debugger are so that you can stop your
4110program before it terminates; or so that, if your program runs into
4111trouble, you can investigate and find out why.
4112
7a292a7a
SS
4113Inside @value{GDBN}, your program may stop for any of several reasons,
4114such as a signal, a breakpoint, or reaching a new line after a
4115@value{GDBN} command such as @code{step}. You may then examine and
4116change variables, set new breakpoints or remove old ones, and then
4117continue execution. Usually, the messages shown by @value{GDBN} provide
4118ample explanation of the status of your program---but you can also
4119explicitly request this information at any time.
c906108c
SS
4120
4121@table @code
4122@kindex info program
4123@item info program
4124Display information about the status of your program: whether it is
7a292a7a 4125running or not, what process it is, and why it stopped.
c906108c
SS
4126@end table
4127
4128@menu
4129* Breakpoints:: Breakpoints, watchpoints, and catchpoints
4130* Continuing and Stepping:: Resuming execution
aad1c02c
TT
4131* Skipping Over Functions and Files::
4132 Skipping over functions and files
c906108c 4133* Signals:: Signals
c906108c 4134* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
4135@end menu
4136
6d2ebf8b 4137@node Breakpoints
79a6e687 4138@section Breakpoints, Watchpoints, and Catchpoints
c906108c
SS
4139
4140@cindex breakpoints
4141A @dfn{breakpoint} makes your program stop whenever a certain point in
4142the program is reached. For each breakpoint, you can add conditions to
4143control in finer detail whether your program stops. You can set
4144breakpoints with the @code{break} command and its variants (@pxref{Set
79a6e687 4145Breaks, ,Setting Breakpoints}), to specify the place where your program
c906108c
SS
4146should stop by line number, function name or exact address in the
4147program.
4148
09d4efe1 4149On some systems, you can set breakpoints in shared libraries before
b1236ac3 4150the executable is run.
c906108c
SS
4151
4152@cindex watchpoints
fd60e0df 4153@cindex data breakpoints
c906108c
SS
4154@cindex memory tracing
4155@cindex breakpoint on memory address
4156@cindex breakpoint on variable modification
4157A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 4158when the value of an expression changes. The expression may be a value
0ced0c34 4159of a variable, or it could involve values of one or more variables
fd60e0df
EZ
4160combined by operators, such as @samp{a + b}. This is sometimes called
4161@dfn{data breakpoints}. You must use a different command to set
79a6e687 4162watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
fd60e0df
EZ
4163from that, you can manage a watchpoint like any other breakpoint: you
4164enable, disable, and delete both breakpoints and watchpoints using the
4165same commands.
c906108c
SS
4166
4167You can arrange to have values from your program displayed automatically
4168whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
79a6e687 4169Automatic Display}.
c906108c
SS
4170
4171@cindex catchpoints
4172@cindex breakpoint on events
4173A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 4174when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
4175exception or the loading of a library. As with watchpoints, you use a
4176different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
79a6e687 4177Catchpoints}), but aside from that, you can manage a catchpoint like any
c906108c 4178other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 4179@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
4180
4181@cindex breakpoint numbers
4182@cindex numbers for breakpoints
4183@value{GDBN} assigns a number to each breakpoint, watchpoint, or
4184catchpoint when you create it; these numbers are successive integers
4185starting with one. In many of the commands for controlling various
4186features of breakpoints you use the breakpoint number to say which
4187breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
4188@dfn{disabled}; if disabled, it has no effect on your program until you
4189enable it again.
4190
c5394b80 4191@cindex breakpoint ranges
18da0c51 4192@cindex breakpoint lists
c5394b80 4193@cindex ranges of breakpoints
18da0c51
MG
4194@cindex lists of breakpoints
4195Some @value{GDBN} commands accept a space-separated list of breakpoints
4196on which to operate. A list element can be either a single breakpoint number,
4197like @samp{5}, or a range of such numbers, like @samp{5-7}.
4198When a breakpoint list is given to a command, all breakpoints in that list
4199are operated on.
c5394b80 4200
c906108c
SS
4201@menu
4202* Set Breaks:: Setting breakpoints
4203* Set Watchpoints:: Setting watchpoints
4204* Set Catchpoints:: Setting catchpoints
4205* Delete Breaks:: Deleting breakpoints
4206* Disabling:: Disabling breakpoints
4207* Conditions:: Break conditions
4208* Break Commands:: Breakpoint command lists
e7e0cddf 4209* Dynamic Printf:: Dynamic printf
6149aea9 4210* Save Breakpoints:: How to save breakpoints in a file
62e5f89c 4211* Static Probe Points:: Listing static probe points
d4f3574e 4212* Error in Breakpoints:: ``Cannot insert breakpoints''
79a6e687 4213* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
c906108c
SS
4214@end menu
4215
6d2ebf8b 4216@node Set Breaks
79a6e687 4217@subsection Setting Breakpoints
c906108c 4218
5d161b24 4219@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
4220@c consider in particular declaration with/without initialization.
4221@c
4222@c FIXME 2 is there stuff on this already? break at fun start, already init?
4223
4224@kindex break
41afff9a
EZ
4225@kindex b @r{(@code{break})}
4226@vindex $bpnum@r{, convenience variable}
c906108c
SS
4227@cindex latest breakpoint
4228Breakpoints are set with the @code{break} command (abbreviated
5d161b24 4229@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 4230number of the breakpoint you've set most recently; see @ref{Convenience
79a6e687 4231Vars,, Convenience Variables}, for a discussion of what you can do with
c906108c
SS
4232convenience variables.
4233
c906108c 4234@table @code
2a25a5ba
EZ
4235@item break @var{location}
4236Set a breakpoint at the given @var{location}, which can specify a
4237function name, a line number, or an address of an instruction.
4238(@xref{Specify Location}, for a list of all the possible ways to
4239specify a @var{location}.) The breakpoint will stop your program just
4240before it executes any of the code in the specified @var{location}.
4241
c906108c 4242When using source languages that permit overloading of symbols, such as
2a25a5ba 4243C@t{++}, a function name may refer to more than one possible place to break.
6ba66d6a
JB
4244@xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
4245that situation.
c906108c 4246
45ac276d 4247It is also possible to insert a breakpoint that will stop the program
2c88c651
JB
4248only if a specific thread (@pxref{Thread-Specific Breakpoints})
4249or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
45ac276d 4250
c906108c
SS
4251@item break
4252When called without any arguments, @code{break} sets a breakpoint at
4253the next instruction to be executed in the selected stack frame
4254(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
4255innermost, this makes your program stop as soon as control
4256returns to that frame. This is similar to the effect of a
4257@code{finish} command in the frame inside the selected frame---except
4258that @code{finish} does not leave an active breakpoint. If you use
4259@code{break} without an argument in the innermost frame, @value{GDBN} stops
4260the next time it reaches the current location; this may be useful
4261inside loops.
4262
4263@value{GDBN} normally ignores breakpoints when it resumes execution, until at
4264least one instruction has been executed. If it did not do this, you
4265would be unable to proceed past a breakpoint without first disabling the
4266breakpoint. This rule applies whether or not the breakpoint already
4267existed when your program stopped.
4268
4269@item break @dots{} if @var{cond}
4270Set a breakpoint with condition @var{cond}; evaluate the expression
4271@var{cond} each time the breakpoint is reached, and stop only if the
4272value is nonzero---that is, if @var{cond} evaluates as true.
4273@samp{@dots{}} stands for one of the possible arguments described
4274above (or no argument) specifying where to break. @xref{Conditions,
79a6e687 4275,Break Conditions}, for more information on breakpoint conditions.
c906108c
SS
4276
4277@kindex tbreak
4278@item tbreak @var{args}
697aa1b7 4279Set a breakpoint enabled only for one stop. The @var{args} are the
c906108c
SS
4280same as for the @code{break} command, and the breakpoint is set in the same
4281way, but the breakpoint is automatically deleted after the first time your
79a6e687 4282program stops there. @xref{Disabling, ,Disabling Breakpoints}.
c906108c 4283
c906108c 4284@kindex hbreak
ba04e063 4285@cindex hardware breakpoints
c906108c 4286@item hbreak @var{args}
697aa1b7 4287Set a hardware-assisted breakpoint. The @var{args} are the same as for the
d4f3574e 4288@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
4289breakpoint requires hardware support and some target hardware may not
4290have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
4291debugging, so you can set a breakpoint at an instruction without
4292changing the instruction. This can be used with the new trap-generation
09d4efe1 4293provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
4294will generate traps when a program accesses some data or instruction
4295address that is assigned to the debug registers. However the hardware
4296breakpoint registers can take a limited number of breakpoints. For
4297example, on the DSU, only two data breakpoints can be set at a time, and
4298@value{GDBN} will reject this command if more than two are used. Delete
4299or disable unused hardware breakpoints before setting new ones
79a6e687
BW
4300(@pxref{Disabling, ,Disabling Breakpoints}).
4301@xref{Conditions, ,Break Conditions}.
9c16f35a
EZ
4302For remote targets, you can restrict the number of hardware
4303breakpoints @value{GDBN} will use, see @ref{set remote
4304hardware-breakpoint-limit}.
501eef12 4305
c906108c
SS
4306@kindex thbreak
4307@item thbreak @var{args}
697aa1b7 4308Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
c906108c 4309are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 4310the same way. However, like the @code{tbreak} command,
c906108c
SS
4311the breakpoint is automatically deleted after the
4312first time your program stops there. Also, like the @code{hbreak}
5d161b24 4313command, the breakpoint requires hardware support and some target hardware
79a6e687
BW
4314may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
4315See also @ref{Conditions, ,Break Conditions}.
c906108c
SS
4316
4317@kindex rbreak
4318@cindex regular expression
8bd10a10 4319@cindex breakpoints at functions matching a regexp
c45da7e6 4320@cindex set breakpoints in many functions
c906108c 4321@item rbreak @var{regex}
c906108c 4322Set breakpoints on all functions matching the regular expression
11cf8741
JM
4323@var{regex}. This command sets an unconditional breakpoint on all
4324matches, printing a list of all breakpoints it set. Once these
4325breakpoints are set, they are treated just like the breakpoints set with
4326the @code{break} command. You can delete them, disable them, or make
4327them conditional the same way as any other breakpoint.
4328
20813a0b
PW
4329In programs using different languages, @value{GDBN} chooses the syntax
4330to print the list of all breakpoints it sets according to the
4331@samp{set language} value: using @samp{set language auto}
4332(see @ref{Automatically, ,Set Language Automatically}) means to use the
4333language of the breakpoint's function, other values mean to use
4334the manually specified language (see @ref{Manually, ,Set Language Manually}).
4335
11cf8741
JM
4336The syntax of the regular expression is the standard one used with tools
4337like @file{grep}. Note that this is different from the syntax used by
4338shells, so for instance @code{foo*} matches all functions that include
4339an @code{fo} followed by zero or more @code{o}s. There is an implicit
4340@code{.*} leading and trailing the regular expression you supply, so to
4341match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 4342
f7dc1244 4343@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 4344When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
4345breakpoints on overloaded functions that are not members of any special
4346classes.
c906108c 4347
f7dc1244
EZ
4348@cindex set breakpoints on all functions
4349The @code{rbreak} command can be used to set breakpoints in
4350@strong{all} the functions in a program, like this:
4351
4352@smallexample
4353(@value{GDBP}) rbreak .
4354@end smallexample
4355
8bd10a10
CM
4356@item rbreak @var{file}:@var{regex}
4357If @code{rbreak} is called with a filename qualification, it limits
4358the search for functions matching the given regular expression to the
4359specified @var{file}. This can be used, for example, to set breakpoints on
4360every function in a given file:
4361
4362@smallexample
4363(@value{GDBP}) rbreak file.c:.
4364@end smallexample
4365
4366The colon separating the filename qualifier from the regex may
4367optionally be surrounded by spaces.
4368
c906108c
SS
4369@kindex info breakpoints
4370@cindex @code{$_} and @code{info breakpoints}
18da0c51
MG
4371@item info breakpoints @r{[}@var{list}@dots{}@r{]}
4372@itemx info break @r{[}@var{list}@dots{}@r{]}
c906108c 4373Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734 4374not deleted. Optional argument @var{n} means print information only
e5a67952
MS
4375about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4376For each breakpoint, following columns are printed:
c906108c
SS
4377
4378@table @emph
4379@item Breakpoint Numbers
4380@item Type
4381Breakpoint, watchpoint, or catchpoint.
4382@item Disposition
4383Whether the breakpoint is marked to be disabled or deleted when hit.
4384@item Enabled or Disabled
4385Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
b3db7447 4386that are not enabled.
c906108c 4387@item Address
fe6fbf8b 4388Where the breakpoint is in your program, as a memory address. For a
b3db7447
NR
4389pending breakpoint whose address is not yet known, this field will
4390contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
4391library that has the symbol or line referred by breakpoint is loaded.
4392See below for details. A breakpoint with several locations will
3b784c4f 4393have @samp{<MULTIPLE>} in this field---see below for details.
c906108c
SS
4394@item What
4395Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
4396line number. For a pending breakpoint, the original string passed to
4397the breakpoint command will be listed as it cannot be resolved until
4398the appropriate shared library is loaded in the future.
c906108c
SS
4399@end table
4400
4401@noindent
83364271
LM
4402If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4403``target''. If mode is ``host'', breakpoint condition evaluation is done by
4404@value{GDBN} on the host's side. If it is ``target'', then the condition
4405is evaluated by the target. The @code{info break} command shows
4406the condition on the line following the affected breakpoint, together with
4407its condition evaluation mode in between parentheses.
4408
4409Breakpoint commands, if any, are listed after that. A pending breakpoint is
4410allowed to have a condition specified for it. The condition is not parsed for
4411validity until a shared library is loaded that allows the pending
4412breakpoint to resolve to a valid location.
c906108c
SS
4413
4414@noindent
4415@code{info break} with a breakpoint
4416number @var{n} as argument lists only that breakpoint. The
4417convenience variable @code{$_} and the default examining-address for
4418the @code{x} command are set to the address of the last breakpoint
79a6e687 4419listed (@pxref{Memory, ,Examining Memory}).
c906108c
SS
4420
4421@noindent
4422@code{info break} displays a count of the number of times the breakpoint
4423has been hit. This is especially useful in conjunction with the
4424@code{ignore} command. You can ignore a large number of breakpoint
4425hits, look at the breakpoint info to see how many times the breakpoint
4426was hit, and then run again, ignoring one less than that number. This
4427will get you quickly to the last hit of that breakpoint.
816338b5
SS
4428
4429@noindent
4430For a breakpoints with an enable count (xref) greater than 1,
4431@code{info break} also displays that count.
4432
c906108c
SS
4433@end table
4434
4435@value{GDBN} allows you to set any number of breakpoints at the same place in
4436your program. There is nothing silly or meaningless about this. When
4437the breakpoints are conditional, this is even useful
79a6e687 4438(@pxref{Conditions, ,Break Conditions}).
c906108c 4439
2e9132cc
EZ
4440@cindex multiple locations, breakpoints
4441@cindex breakpoints, multiple locations
fcda367b 4442It is possible that a breakpoint corresponds to several locations
fe6fbf8b
VP
4443in your program. Examples of this situation are:
4444
4445@itemize @bullet
f8eba3c6
TT
4446@item
4447Multiple functions in the program may have the same name.
4448
fe6fbf8b
VP
4449@item
4450For a C@t{++} constructor, the @value{NGCC} compiler generates several
4451instances of the function body, used in different cases.
4452
4453@item
4454For a C@t{++} template function, a given line in the function can
4455correspond to any number of instantiations.
4456
4457@item
4458For an inlined function, a given source line can correspond to
4459several places where that function is inlined.
fe6fbf8b
VP
4460@end itemize
4461
4462In all those cases, @value{GDBN} will insert a breakpoint at all
f8eba3c6 4463the relevant locations.
fe6fbf8b 4464
3b784c4f
EZ
4465A breakpoint with multiple locations is displayed in the breakpoint
4466table using several rows---one header row, followed by one row for
4467each breakpoint location. The header row has @samp{<MULTIPLE>} in the
4468address column. The rows for individual locations contain the actual
4469addresses for locations, and show the functions to which those
4470locations belong. The number column for a location is of the form
fe6fbf8b
VP
4471@var{breakpoint-number}.@var{location-number}.
4472
4473For example:
3b784c4f 4474
fe6fbf8b
VP
4475@smallexample
4476Num Type Disp Enb Address What
44771 breakpoint keep y <MULTIPLE>
4478 stop only if i==1
4479 breakpoint already hit 1 time
44801.1 y 0x080486a2 in void foo<int>() at t.cc:8
44811.2 y 0x080486ca in void foo<double>() at t.cc:8
4482@end smallexample
4483
d0fe4701
XR
4484You cannot delete the individual locations from a breakpoint. However,
4485each location can be individually enabled or disabled by passing
fe6fbf8b 4486@var{breakpoint-number}.@var{location-number} as argument to the
d0fe4701
XR
4487@code{enable} and @code{disable} commands. It's also possible to
4488@code{enable} and @code{disable} a range of @var{location-number}
4489locations using a @var{breakpoint-number} and two @var{location-number}s,
4490in increasing order, separated by a hyphen, like
4491@kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4492in which case @value{GDBN} acts on all the locations in the range (inclusive).
4493Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4494all of the locations that belong to that breakpoint.
fe6fbf8b 4495
2650777c 4496@cindex pending breakpoints
fe6fbf8b 4497It's quite common to have a breakpoint inside a shared library.
3b784c4f 4498Shared libraries can be loaded and unloaded explicitly,
fe6fbf8b
VP
4499and possibly repeatedly, as the program is executed. To support
4500this use case, @value{GDBN} updates breakpoint locations whenever
4501any shared library is loaded or unloaded. Typically, you would
fcda367b 4502set a breakpoint in a shared library at the beginning of your
fe6fbf8b
VP
4503debugging session, when the library is not loaded, and when the
4504symbols from the library are not available. When you try to set
4505breakpoint, @value{GDBN} will ask you if you want to set
3b784c4f 4506a so called @dfn{pending breakpoint}---breakpoint whose address
fe6fbf8b
VP
4507is not yet resolved.
4508
4509After the program is run, whenever a new shared library is loaded,
4510@value{GDBN} reevaluates all the breakpoints. When a newly loaded
4511shared library contains the symbol or line referred to by some
4512pending breakpoint, that breakpoint is resolved and becomes an
4513ordinary breakpoint. When a library is unloaded, all breakpoints
4514that refer to its symbols or source lines become pending again.
4515
4516This logic works for breakpoints with multiple locations, too. For
4517example, if you have a breakpoint in a C@t{++} template function, and
4518a newly loaded shared library has an instantiation of that template,
4519a new location is added to the list of locations for the breakpoint.
4520
4521Except for having unresolved address, pending breakpoints do not
4522differ from regular breakpoints. You can set conditions or commands,
4523enable and disable them and perform other breakpoint operations.
4524
4525@value{GDBN} provides some additional commands for controlling what
4526happens when the @samp{break} command cannot resolve breakpoint
4527address specification to an address:
dd79a6cf
JJ
4528
4529@kindex set breakpoint pending
4530@kindex show breakpoint pending
4531@table @code
4532@item set breakpoint pending auto
4533This is the default behavior. When @value{GDBN} cannot find the breakpoint
4534location, it queries you whether a pending breakpoint should be created.
4535
4536@item set breakpoint pending on
4537This indicates that an unrecognized breakpoint location should automatically
4538result in a pending breakpoint being created.
4539
4540@item set breakpoint pending off
4541This indicates that pending breakpoints are not to be created. Any
4542unrecognized breakpoint location results in an error. This setting does
4543not affect any pending breakpoints previously created.
4544
4545@item show breakpoint pending
4546Show the current behavior setting for creating pending breakpoints.
4547@end table
2650777c 4548
fe6fbf8b
VP
4549The settings above only affect the @code{break} command and its
4550variants. Once breakpoint is set, it will be automatically updated
4551as shared libraries are loaded and unloaded.
2650777c 4552
765dc015
VP
4553@cindex automatic hardware breakpoints
4554For some targets, @value{GDBN} can automatically decide if hardware or
4555software breakpoints should be used, depending on whether the
4556breakpoint address is read-only or read-write. This applies to
4557breakpoints set with the @code{break} command as well as to internal
4558breakpoints set by commands like @code{next} and @code{finish}. For
fcda367b 4559breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
765dc015
VP
4560breakpoints.
4561
18da0c51 4562You can control this automatic behaviour with the following commands:
765dc015
VP
4563
4564@kindex set breakpoint auto-hw
4565@kindex show breakpoint auto-hw
4566@table @code
4567@item set breakpoint auto-hw on
4568This is the default behavior. When @value{GDBN} sets a breakpoint, it
4569will try to use the target memory map to decide if software or hardware
4570breakpoint must be used.
4571
4572@item set breakpoint auto-hw off
4573This indicates @value{GDBN} should not automatically select breakpoint
4574type. If the target provides a memory map, @value{GDBN} will warn when
4575trying to set software breakpoint at a read-only address.
4576@end table
4577
74960c60
VP
4578@value{GDBN} normally implements breakpoints by replacing the program code
4579at the breakpoint address with a special instruction, which, when
4580executed, given control to the debugger. By default, the program
4581code is so modified only when the program is resumed. As soon as
4582the program stops, @value{GDBN} restores the original instructions. This
4583behaviour guards against leaving breakpoints inserted in the
4584target should gdb abrubptly disconnect. However, with slow remote
4585targets, inserting and removing breakpoint can reduce the performance.
4586This behavior can be controlled with the following commands::
4587
4588@kindex set breakpoint always-inserted
4589@kindex show breakpoint always-inserted
4590@table @code
4591@item set breakpoint always-inserted off
33e5cbd6
PA
4592All breakpoints, including newly added by the user, are inserted in
4593the target only when the target is resumed. All breakpoints are
a25a5a45 4594removed from the target when it stops. This is the default mode.
74960c60
VP
4595
4596@item set breakpoint always-inserted on
4597Causes all breakpoints to be inserted in the target at all times. If
4598the user adds a new breakpoint, or changes an existing breakpoint, the
4599breakpoints in the target are updated immediately. A breakpoint is
a25a5a45 4600removed from the target only when breakpoint itself is deleted.
342cc091 4601@end table
765dc015 4602
83364271
LM
4603@value{GDBN} handles conditional breakpoints by evaluating these conditions
4604when a breakpoint breaks. If the condition is true, then the process being
4605debugged stops, otherwise the process is resumed.
4606
4607If the target supports evaluating conditions on its end, @value{GDBN} may
4608download the breakpoint, together with its conditions, to it.
4609
4610This feature can be controlled via the following commands:
4611
4612@kindex set breakpoint condition-evaluation
4613@kindex show breakpoint condition-evaluation
4614@table @code
4615@item set breakpoint condition-evaluation host
4616This option commands @value{GDBN} to evaluate the breakpoint
4617conditions on the host's side. Unconditional breakpoints are sent to
4618the target which in turn receives the triggers and reports them back to GDB
4619for condition evaluation. This is the standard evaluation mode.
4620
4621@item set breakpoint condition-evaluation target
4622This option commands @value{GDBN} to download breakpoint conditions
4623to the target at the moment of their insertion. The target
4624is responsible for evaluating the conditional expression and reporting
4625breakpoint stop events back to @value{GDBN} whenever the condition
4626is true. Due to limitations of target-side evaluation, some conditions
4627cannot be evaluated there, e.g., conditions that depend on local data
4628that is only known to the host. Examples include
4629conditional expressions involving convenience variables, complex types
4630that cannot be handled by the agent expression parser and expressions
4631that are too long to be sent over to the target, specially when the
4632target is a remote system. In these cases, the conditions will be
4633evaluated by @value{GDBN}.
4634
4635@item set breakpoint condition-evaluation auto
4636This is the default mode. If the target supports evaluating breakpoint
4637conditions on its end, @value{GDBN} will download breakpoint conditions to
4638the target (limitations mentioned previously apply). If the target does
4639not support breakpoint condition evaluation, then @value{GDBN} will fallback
4640to evaluating all these conditions on the host's side.
4641@end table
4642
4643
c906108c
SS
4644@cindex negative breakpoint numbers
4645@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
4646@value{GDBN} itself sometimes sets breakpoints in your program for
4647special purposes, such as proper handling of @code{longjmp} (in C
4648programs). These internal breakpoints are assigned negative numbers,
4649starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 4650You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 4651@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
4652
4653
6d2ebf8b 4654@node Set Watchpoints
79a6e687 4655@subsection Setting Watchpoints
c906108c
SS
4656
4657@cindex setting watchpoints
c906108c
SS
4658You can use a watchpoint to stop execution whenever the value of an
4659expression changes, without having to predict a particular place where
fd60e0df
EZ
4660this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4661The expression may be as simple as the value of a single variable, or
4662as complex as many variables combined by operators. Examples include:
4663
4664@itemize @bullet
4665@item
4666A reference to the value of a single variable.
4667
4668@item
4669An address cast to an appropriate data type. For example,
4670@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4671address (assuming an @code{int} occupies 4 bytes).
4672
4673@item
4674An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4675expression can use any operators valid in the program's native
4676language (@pxref{Languages}).
4677@end itemize
c906108c 4678
fa4727a6
DJ
4679You can set a watchpoint on an expression even if the expression can
4680not be evaluated yet. For instance, you can set a watchpoint on
4681@samp{*global_ptr} before @samp{global_ptr} is initialized.
4682@value{GDBN} will stop when your program sets @samp{global_ptr} and
4683the expression produces a valid value. If the expression becomes
4684valid in some other way than changing a variable (e.g.@: if the memory
4685pointed to by @samp{*global_ptr} becomes readable as the result of a
4686@code{malloc} call), @value{GDBN} may not stop until the next time
4687the expression changes.
4688
82f2d802
EZ
4689@cindex software watchpoints
4690@cindex hardware watchpoints
c906108c 4691Depending on your system, watchpoints may be implemented in software or
2df3850c 4692hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
4693program and testing the variable's value each time, which is hundreds of
4694times slower than normal execution. (But this may still be worth it, to
4695catch errors where you have no clue what part of your program is the
4696culprit.)
4697
b1236ac3
PA
4698On some systems, such as most PowerPC or x86-based targets,
4699@value{GDBN} includes support for hardware watchpoints, which do not
4700slow down the running of your program.
c906108c
SS
4701
4702@table @code
4703@kindex watch
5d5658a1 4704@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
fd60e0df
EZ
4705Set a watchpoint for an expression. @value{GDBN} will break when the
4706expression @var{expr} is written into by the program and its value
4707changes. The simplest (and the most popular) use of this command is
4708to watch the value of a single variable:
4709
4710@smallexample
4711(@value{GDBP}) watch foo
4712@end smallexample
c906108c 4713
5d5658a1 4714If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
9c06b0b4 4715argument, @value{GDBN} breaks only when the thread identified by
5d5658a1 4716@var{thread-id} changes the value of @var{expr}. If any other threads
d8b2a693
JB
4717change the value of @var{expr}, @value{GDBN} will not break. Note
4718that watchpoints restricted to a single thread in this way only work
4719with Hardware Watchpoints.
4720
06a64a0b
TT
4721Ordinarily a watchpoint respects the scope of variables in @var{expr}
4722(see below). The @code{-location} argument tells @value{GDBN} to
4723instead watch the memory referred to by @var{expr}. In this case,
4724@value{GDBN} will evaluate @var{expr}, take the address of the result,
4725and watch the memory at that address. The type of the result is used
4726to determine the size of the watched memory. If the expression's
4727result does not have an address, then @value{GDBN} will print an
4728error.
4729
9c06b0b4
TJB
4730The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4731of masked watchpoints, if the current architecture supports this
4732feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4733Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4734to an address to watch. The mask specifies that some bits of an address
4735(the bits which are reset in the mask) should be ignored when matching
4736the address accessed by the inferior against the watchpoint address.
4737Thus, a masked watchpoint watches many addresses simultaneously---those
4738addresses whose unmasked bits are identical to the unmasked bits in the
4739watchpoint address. The @code{mask} argument implies @code{-location}.
4740Examples:
4741
4742@smallexample
4743(@value{GDBP}) watch foo mask 0xffff00ff
4744(@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4745@end smallexample
4746
c906108c 4747@kindex rwatch
5d5658a1 4748@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4749Set a watchpoint that will break when the value of @var{expr} is read
4750by the program.
c906108c
SS
4751
4752@kindex awatch
5d5658a1 4753@item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4754Set a watchpoint that will break when @var{expr} is either read from
4755or written into by the program.
c906108c 4756
18da0c51
MG
4757@kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4758@item info watchpoints @r{[}@var{list}@dots{}@r{]}
d77f58be
SS
4759This command prints a list of watchpoints, using the same format as
4760@code{info break} (@pxref{Set Breaks}).
c906108c
SS
4761@end table
4762
65d79d4b
SDJ
4763If you watch for a change in a numerically entered address you need to
4764dereference it, as the address itself is just a constant number which will
4765never change. @value{GDBN} refuses to create a watchpoint that watches
4766a never-changing value:
4767
4768@smallexample
4769(@value{GDBP}) watch 0x600850
4770Cannot watch constant value 0x600850.
4771(@value{GDBP}) watch *(int *) 0x600850
4772Watchpoint 1: *(int *) 6293584
4773@end smallexample
4774
c906108c
SS
4775@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4776watchpoints execute very quickly, and the debugger reports a change in
4777value at the exact instruction where the change occurs. If @value{GDBN}
4778cannot set a hardware watchpoint, it sets a software watchpoint, which
4779executes more slowly and reports the change in value at the next
82f2d802
EZ
4780@emph{statement}, not the instruction, after the change occurs.
4781
82f2d802
EZ
4782@cindex use only software watchpoints
4783You can force @value{GDBN} to use only software watchpoints with the
4784@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4785zero, @value{GDBN} will never try to use hardware watchpoints, even if
4786the underlying system supports them. (Note that hardware-assisted
4787watchpoints that were set @emph{before} setting
4788@code{can-use-hw-watchpoints} to zero will still use the hardware
d3e8051b 4789mechanism of watching expression values.)
c906108c 4790
9c16f35a
EZ
4791@table @code
4792@item set can-use-hw-watchpoints
4793@kindex set can-use-hw-watchpoints
4794Set whether or not to use hardware watchpoints.
4795
4796@item show can-use-hw-watchpoints
4797@kindex show can-use-hw-watchpoints
4798Show the current mode of using hardware watchpoints.
4799@end table
4800
4801For remote targets, you can restrict the number of hardware
4802watchpoints @value{GDBN} will use, see @ref{set remote
4803hardware-breakpoint-limit}.
4804
c906108c
SS
4805When you issue the @code{watch} command, @value{GDBN} reports
4806
474c8240 4807@smallexample
c906108c 4808Hardware watchpoint @var{num}: @var{expr}
474c8240 4809@end smallexample
c906108c
SS
4810
4811@noindent
4812if it was able to set a hardware watchpoint.
4813
7be570e7
JM
4814Currently, the @code{awatch} and @code{rwatch} commands can only set
4815hardware watchpoints, because accesses to data that don't change the
4816value of the watched expression cannot be detected without examining
4817every instruction as it is being executed, and @value{GDBN} does not do
4818that currently. If @value{GDBN} finds that it is unable to set a
4819hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4820will print a message like this:
4821
4822@smallexample
4823Expression cannot be implemented with read/access watchpoint.
4824@end smallexample
4825
4826Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4827data type of the watched expression is wider than what a hardware
4828watchpoint on the target machine can handle. For example, some systems
4829can only watch regions that are up to 4 bytes wide; on such systems you
4830cannot set hardware watchpoints for an expression that yields a
4831double-precision floating-point number (which is typically 8 bytes
4832wide). As a work-around, it might be possible to break the large region
4833into a series of smaller ones and watch them with separate watchpoints.
4834
4835If you set too many hardware watchpoints, @value{GDBN} might be unable
4836to insert all of them when you resume the execution of your program.
4837Since the precise number of active watchpoints is unknown until such
4838time as the program is about to be resumed, @value{GDBN} might not be
4839able to warn you about this when you set the watchpoints, and the
4840warning will be printed only when the program is resumed:
4841
4842@smallexample
4843Hardware watchpoint @var{num}: Could not insert watchpoint
4844@end smallexample
4845
4846@noindent
4847If this happens, delete or disable some of the watchpoints.
4848
fd60e0df
EZ
4849Watching complex expressions that reference many variables can also
4850exhaust the resources available for hardware-assisted watchpoints.
4851That's because @value{GDBN} needs to watch every variable in the
4852expression with separately allocated resources.
4853
c906108c 4854If you call a function interactively using @code{print} or @code{call},
2df3850c 4855any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
4856kind of breakpoint or the call completes.
4857
7be570e7
JM
4858@value{GDBN} automatically deletes watchpoints that watch local
4859(automatic) variables, or expressions that involve such variables, when
4860they go out of scope, that is, when the execution leaves the block in
4861which these variables were defined. In particular, when the program
4862being debugged terminates, @emph{all} local variables go out of scope,
4863and so only watchpoints that watch global variables remain set. If you
4864rerun the program, you will need to set all such watchpoints again. One
4865way of doing that would be to set a code breakpoint at the entry to the
4866@code{main} function and when it breaks, set all the watchpoints.
4867
c906108c
SS
4868@cindex watchpoints and threads
4869@cindex threads and watchpoints
d983da9c
DJ
4870In multi-threaded programs, watchpoints will detect changes to the
4871watched expression from every thread.
4872
4873@quotation
4874@emph{Warning:} In multi-threaded programs, software watchpoints
53a5351d
JM
4875have only limited usefulness. If @value{GDBN} creates a software
4876watchpoint, it can only watch the value of an expression @emph{in a
4877single thread}. If you are confident that the expression can only
4878change due to the current thread's activity (and if you are also
4879confident that no other thread can become current), then you can use
4880software watchpoints as usual. However, @value{GDBN} may not notice
4881when a non-current thread's activity changes the expression. (Hardware
4882watchpoints, in contrast, watch an expression in all threads.)
c906108c 4883@end quotation
c906108c 4884
501eef12
AC
4885@xref{set remote hardware-watchpoint-limit}.
4886
6d2ebf8b 4887@node Set Catchpoints
79a6e687 4888@subsection Setting Catchpoints
d4f3574e 4889@cindex catchpoints, setting
c906108c
SS
4890@cindex exception handlers
4891@cindex event handling
4892
4893You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 4894kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
4895shared library. Use the @code{catch} command to set a catchpoint.
4896
4897@table @code
4898@kindex catch
4899@item catch @var{event}
697aa1b7 4900Stop when @var{event} occurs. The @var{event} can be any of the following:
591f19e8 4901
c906108c 4902@table @code
cc16e6c9
TT
4903@item throw @r{[}@var{regexp}@r{]}
4904@itemx rethrow @r{[}@var{regexp}@r{]}
4905@itemx catch @r{[}@var{regexp}@r{]}
1a4f73eb
TT
4906@kindex catch throw
4907@kindex catch rethrow
4908@kindex catch catch
4644b6e3 4909@cindex stop on C@t{++} exceptions
591f19e8
TT
4910The throwing, re-throwing, or catching of a C@t{++} exception.
4911
cc16e6c9
TT
4912If @var{regexp} is given, then only exceptions whose type matches the
4913regular expression will be caught.
4914
72f1fe8a
TT
4915@vindex $_exception@r{, convenience variable}
4916The convenience variable @code{$_exception} is available at an
4917exception-related catchpoint, on some systems. This holds the
4918exception being thrown.
4919
591f19e8
TT
4920There are currently some limitations to C@t{++} exception handling in
4921@value{GDBN}:
c906108c 4922
591f19e8
TT
4923@itemize @bullet
4924@item
4925The support for these commands is system-dependent. Currently, only
4926systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
4927supported.
4928
72f1fe8a 4929@item
cc16e6c9
TT
4930The regular expression feature and the @code{$_exception} convenience
4931variable rely on the presence of some SDT probes in @code{libstdc++}.
4932If these probes are not present, then these features cannot be used.
dee368d3
TT
4933These probes were first available in the GCC 4.8 release, but whether
4934or not they are available in your GCC also depends on how it was
4935built.
72f1fe8a
TT
4936
4937@item
4938The @code{$_exception} convenience variable is only valid at the
4939instruction at which an exception-related catchpoint is set.
4940
591f19e8
TT
4941@item
4942When an exception-related catchpoint is hit, @value{GDBN} stops at a
4943location in the system library which implements runtime exception
4944support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
4945(@pxref{Selection}) to get to your code.
4946
4947@item
4948If you call a function interactively, @value{GDBN} normally returns
4949control to you when the function has finished executing. If the call
4950raises an exception, however, the call may bypass the mechanism that
4951returns control to you and cause your program either to abort or to
4952simply continue running until it hits a breakpoint, catches a signal
4953that @value{GDBN} is listening for, or exits. This is the case even if
4954you set a catchpoint for the exception; catchpoints on exceptions are
4955disabled within interactive calls. @xref{Calling}, for information on
4956controlling this with @code{set unwind-on-terminating-exception}.
4957
4958@item
4959You cannot raise an exception interactively.
4960
4961@item
4962You cannot install an exception handler interactively.
4963@end itemize
c906108c 4964
b8e07335 4965@item exception @r{[}@var{name}@r{]}
1a4f73eb 4966@kindex catch exception
8936fcda
JB
4967@cindex Ada exception catching
4968@cindex catch Ada exceptions
4969An Ada exception being raised. If an exception name is specified
4970at the end of the command (eg @code{catch exception Program_Error}),
4971the debugger will stop only when this specific exception is raised.
4972Otherwise, the debugger stops execution when any Ada exception is raised.
4973
87f67dba
JB
4974When inserting an exception catchpoint on a user-defined exception whose
4975name is identical to one of the exceptions defined by the language, the
4976fully qualified name must be used as the exception name. Otherwise,
4977@value{GDBN} will assume that it should stop on the pre-defined exception
4978rather than the user-defined one. For instance, assuming an exception
4979called @code{Constraint_Error} is defined in package @code{Pck}, then
4980the command to use to catch such exceptions is @kbd{catch exception
4981Pck.Constraint_Error}.
4982
37f6a7f4
TT
4983@vindex $_ada_exception@r{, convenience variable}
4984The convenience variable @code{$_ada_exception} holds the address of
4985the exception being thrown. This can be useful when setting a
4986condition for such a catchpoint.
4987
b8e07335
TT
4988@item exception unhandled
4989@kindex catch exception unhandled
37f6a7f4
TT
4990An exception that was raised but is not handled by the program. The
4991convenience variable @code{$_ada_exception} is set as for @code{catch
4992exception}.
b8e07335
TT
4993
4994@item handlers @r{[}@var{name}@r{]}
9f757bf7
XR
4995@kindex catch handlers
4996@cindex Ada exception handlers catching
4997@cindex catch Ada exceptions when handled
4998An Ada exception being handled. If an exception name is
4999specified at the end of the command
5000 (eg @kbd{catch handlers Program_Error}), the debugger will stop
5001only when this specific exception is handled.
5002Otherwise, the debugger stops execution when any Ada exception is handled.
5003
5004When inserting a handlers catchpoint on a user-defined
5005exception whose name is identical to one of the exceptions
5006defined by the language, the fully qualified name must be used
5007as the exception name. Otherwise, @value{GDBN} will assume that it
5008should stop on the pre-defined exception rather than the
5009user-defined one. For instance, assuming an exception called
5010 @code{Constraint_Error} is defined in package @code{Pck}, then the
5011command to use to catch such exceptions handling is
5012@kbd{catch handlers Pck.Constraint_Error}.
5013
37f6a7f4
TT
5014The convenience variable @code{$_ada_exception} is set as for
5015@code{catch exception}.
5016
8936fcda 5017@item assert
1a4f73eb 5018@kindex catch assert
37f6a7f4
TT
5019A failed Ada assertion. Note that the convenience variable
5020@code{$_ada_exception} is @emph{not} set by this catchpoint.
8936fcda 5021
c906108c 5022@item exec
1a4f73eb 5023@kindex catch exec
4644b6e3 5024@cindex break on fork/exec
b1236ac3 5025A call to @code{exec}.
c906108c 5026
e9076973 5027@anchor{catch syscall}
a96d9b2e 5028@item syscall
e3487908 5029@itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
1a4f73eb 5030@kindex catch syscall
a96d9b2e
SDJ
5031@cindex break on a system call.
5032A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
5033syscall is a mechanism for application programs to request a service
5034from the operating system (OS) or one of the OS system services.
5035@value{GDBN} can catch some or all of the syscalls issued by the
5036debuggee, and show the related information for each syscall. If no
5037argument is specified, calls to and returns from all system calls
5038will be caught.
5039
5040@var{name} can be any system call name that is valid for the
5041underlying OS. Just what syscalls are valid depends on the OS. On
5042GNU and Unix systems, you can find the full list of valid syscall
5043names on @file{/usr/include/asm/unistd.h}.
5044
5045@c For MS-Windows, the syscall names and the corresponding numbers
5046@c can be found, e.g., on this URL:
5047@c http://www.metasploit.com/users/opcode/syscalls.html
5048@c but we don't support Windows syscalls yet.
5049
5050Normally, @value{GDBN} knows in advance which syscalls are valid for
5051each OS, so you can use the @value{GDBN} command-line completion
5052facilities (@pxref{Completion,, command completion}) to list the
5053available choices.
5054
5055You may also specify the system call numerically. A syscall's
5056number is the value passed to the OS's syscall dispatcher to
5057identify the requested service. When you specify the syscall by its
5058name, @value{GDBN} uses its database of syscalls to convert the name
5059into the corresponding numeric code, but using the number directly
5060may be useful if @value{GDBN}'s database does not have the complete
5061list of syscalls on your system (e.g., because @value{GDBN} lags
5062behind the OS upgrades).
5063
e3487908
GKB
5064You may specify a group of related syscalls to be caught at once using
5065the @code{group:} syntax (@code{g:} is a shorter equivalent). For
5066instance, on some platforms @value{GDBN} allows you to catch all
5067network related syscalls, by passing the argument @code{group:network}
5068to @code{catch syscall}. Note that not all syscall groups are
5069available in every system. You can use the command completion
5070facilities (@pxref{Completion,, command completion}) to list the
5071syscall groups available on your environment.
5072
a96d9b2e
SDJ
5073The example below illustrates how this command works if you don't provide
5074arguments to it:
5075
5076@smallexample
5077(@value{GDBP}) catch syscall
5078Catchpoint 1 (syscall)
5079(@value{GDBP}) r
5080Starting program: /tmp/catch-syscall
5081
5082Catchpoint 1 (call to syscall 'close'), \
5083 0xffffe424 in __kernel_vsyscall ()
5084(@value{GDBP}) c
5085Continuing.
5086
5087Catchpoint 1 (returned from syscall 'close'), \
5088 0xffffe424 in __kernel_vsyscall ()
5089(@value{GDBP})
5090@end smallexample
5091
5092Here is an example of catching a system call by name:
5093
5094@smallexample
5095(@value{GDBP}) catch syscall chroot
5096Catchpoint 1 (syscall 'chroot' [61])
5097(@value{GDBP}) r
5098Starting program: /tmp/catch-syscall
5099
5100Catchpoint 1 (call to syscall 'chroot'), \
5101 0xffffe424 in __kernel_vsyscall ()
5102(@value{GDBP}) c
5103Continuing.
5104
5105Catchpoint 1 (returned from syscall 'chroot'), \
5106 0xffffe424 in __kernel_vsyscall ()
5107(@value{GDBP})
5108@end smallexample
5109
5110An example of specifying a system call numerically. In the case
5111below, the syscall number has a corresponding entry in the XML
5112file, so @value{GDBN} finds its name and prints it:
5113
5114@smallexample
5115(@value{GDBP}) catch syscall 252
5116Catchpoint 1 (syscall(s) 'exit_group')
5117(@value{GDBP}) r
5118Starting program: /tmp/catch-syscall
5119
5120Catchpoint 1 (call to syscall 'exit_group'), \
5121 0xffffe424 in __kernel_vsyscall ()
5122(@value{GDBP}) c
5123Continuing.
5124
5125Program exited normally.
5126(@value{GDBP})
5127@end smallexample
5128
e3487908
GKB
5129Here is an example of catching a syscall group:
5130
5131@smallexample
5132(@value{GDBP}) catch syscall group:process
5133Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
5134'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
5135'exit_group' [252] 'waitid' [284] 'unshare' [310])
5136(@value{GDBP}) r
5137Starting program: /tmp/catch-syscall
5138
5139Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
5140 from /lib64/ld-linux-x86-64.so.2
5141
5142(@value{GDBP}) c
5143Continuing.
5144@end smallexample
5145
a96d9b2e
SDJ
5146However, there can be situations when there is no corresponding name
5147in XML file for that syscall number. In this case, @value{GDBN} prints
5148a warning message saying that it was not able to find the syscall name,
5149but the catchpoint will be set anyway. See the example below:
5150
5151@smallexample
5152(@value{GDBP}) catch syscall 764
5153warning: The number '764' does not represent a known syscall.
5154Catchpoint 2 (syscall 764)
5155(@value{GDBP})
5156@end smallexample
5157
5158If you configure @value{GDBN} using the @samp{--without-expat} option,
5159it will not be able to display syscall names. Also, if your
5160architecture does not have an XML file describing its system calls,
5161you will not be able to see the syscall names. It is important to
5162notice that these two features are used for accessing the syscall
5163name database. In either case, you will see a warning like this:
5164
5165@smallexample
5166(@value{GDBP}) catch syscall
5167warning: Could not open "syscalls/i386-linux.xml"
5168warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
5169GDB will not be able to display syscall names.
5170Catchpoint 1 (syscall)
5171(@value{GDBP})
5172@end smallexample
5173
5174Of course, the file name will change depending on your architecture and system.
5175
5176Still using the example above, you can also try to catch a syscall by its
5177number. In this case, you would see something like:
5178
5179@smallexample
5180(@value{GDBP}) catch syscall 252
5181Catchpoint 1 (syscall(s) 252)
5182@end smallexample
5183
5184Again, in this case @value{GDBN} would not be able to display syscall's names.
5185
c906108c 5186@item fork
1a4f73eb 5187@kindex catch fork
b1236ac3 5188A call to @code{fork}.
c906108c
SS
5189
5190@item vfork
1a4f73eb 5191@kindex catch vfork
b1236ac3 5192A call to @code{vfork}.
c906108c 5193
b8e07335
TT
5194@item load @r{[}@var{regexp}@r{]}
5195@itemx unload @r{[}@var{regexp}@r{]}
1a4f73eb
TT
5196@kindex catch load
5197@kindex catch unload
edcc5120
TT
5198The loading or unloading of a shared library. If @var{regexp} is
5199given, then the catchpoint will stop only if the regular expression
5200matches one of the affected libraries.
5201
ab04a2af 5202@item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
1a4f73eb 5203@kindex catch signal
ab04a2af
TT
5204The delivery of a signal.
5205
5206With no arguments, this catchpoint will catch any signal that is not
5207used internally by @value{GDBN}, specifically, all signals except
5208@samp{SIGTRAP} and @samp{SIGINT}.
5209
5210With the argument @samp{all}, all signals, including those used by
5211@value{GDBN}, will be caught. This argument cannot be used with other
5212signal names.
5213
5214Otherwise, the arguments are a list of signal names as given to
5215@code{handle} (@pxref{Signals}). Only signals specified in this list
5216will be caught.
5217
5218One reason that @code{catch signal} can be more useful than
5219@code{handle} is that you can attach commands and conditions to the
5220catchpoint.
5221
5222When a signal is caught by a catchpoint, the signal's @code{stop} and
5223@code{print} settings, as specified by @code{handle}, are ignored.
5224However, whether the signal is still delivered to the inferior depends
5225on the @code{pass} setting; this can be changed in the catchpoint's
5226commands.
5227
c906108c
SS
5228@end table
5229
5230@item tcatch @var{event}
1a4f73eb 5231@kindex tcatch
c906108c
SS
5232Set a catchpoint that is enabled only for one stop. The catchpoint is
5233automatically deleted after the first time the event is caught.
5234
5235@end table
5236
5237Use the @code{info break} command to list the current catchpoints.
5238
c906108c 5239
6d2ebf8b 5240@node Delete Breaks
79a6e687 5241@subsection Deleting Breakpoints
c906108c
SS
5242
5243@cindex clearing breakpoints, watchpoints, catchpoints
5244@cindex deleting breakpoints, watchpoints, catchpoints
5245It is often necessary to eliminate a breakpoint, watchpoint, or
5246catchpoint once it has done its job and you no longer want your program
5247to stop there. This is called @dfn{deleting} the breakpoint. A
5248breakpoint that has been deleted no longer exists; it is forgotten.
5249
5250With the @code{clear} command you can delete breakpoints according to
5251where they are in your program. With the @code{delete} command you can
5252delete individual breakpoints, watchpoints, or catchpoints by specifying
5253their breakpoint numbers.
5254
5255It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
5256automatically ignores breakpoints on the first instruction to be executed
5257when you continue execution without changing the execution address.
5258
5259@table @code
5260@kindex clear
5261@item clear
5262Delete any breakpoints at the next instruction to be executed in the
79a6e687 5263selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
c906108c
SS
5264the innermost frame is selected, this is a good way to delete a
5265breakpoint where your program just stopped.
5266
2a25a5ba
EZ
5267@item clear @var{location}
5268Delete any breakpoints set at the specified @var{location}.
5269@xref{Specify Location}, for the various forms of @var{location}; the
5270most useful ones are listed below:
5271
5272@table @code
c906108c
SS
5273@item clear @var{function}
5274@itemx clear @var{filename}:@var{function}
09d4efe1 5275Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
5276
5277@item clear @var{linenum}
5278@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
5279Delete any breakpoints set at or within the code of the specified
5280@var{linenum} of the specified @var{filename}.
2a25a5ba 5281@end table
c906108c
SS
5282
5283@cindex delete breakpoints
5284@kindex delete
41afff9a 5285@kindex d @r{(@code{delete})}
18da0c51 5286@item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c5394b80 5287Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
18da0c51 5288list specified as argument. If no argument is specified, delete all
c906108c
SS
5289breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
5290confirm off}). You can abbreviate this command as @code{d}.
5291@end table
5292
6d2ebf8b 5293@node Disabling
79a6e687 5294@subsection Disabling Breakpoints
c906108c 5295
4644b6e3 5296@cindex enable/disable a breakpoint
c906108c
SS
5297Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
5298prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
5299it had been deleted, but remembers the information on the breakpoint so
5300that you can @dfn{enable} it again later.
5301
5302You disable and enable breakpoints, watchpoints, and catchpoints with
d77f58be
SS
5303the @code{enable} and @code{disable} commands, optionally specifying
5304one or more breakpoint numbers as arguments. Use @code{info break} to
5305print a list of all breakpoints, watchpoints, and catchpoints if you
5306do not know which numbers to use.
c906108c 5307
3b784c4f
EZ
5308Disabling and enabling a breakpoint that has multiple locations
5309affects all of its locations.
5310
816338b5
SS
5311A breakpoint, watchpoint, or catchpoint can have any of several
5312different states of enablement:
c906108c
SS
5313
5314@itemize @bullet
5315@item
5316Enabled. The breakpoint stops your program. A breakpoint set
5317with the @code{break} command starts out in this state.
5318@item
5319Disabled. The breakpoint has no effect on your program.
5320@item
5321Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 5322disabled.
c906108c 5323@item
816338b5
SS
5324Enabled for a count. The breakpoint stops your program for the next
5325N times, then becomes disabled.
5326@item
c906108c 5327Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
5328immediately after it does so it is deleted permanently. A breakpoint
5329set with the @code{tbreak} command starts out in this state.
c906108c
SS
5330@end itemize
5331
5332You can use the following commands to enable or disable breakpoints,
5333watchpoints, and catchpoints:
5334
5335@table @code
c906108c 5336@kindex disable
41afff9a 5337@kindex dis @r{(@code{disable})}
18da0c51 5338@item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5339Disable the specified breakpoints---or all breakpoints, if none are
5340listed. A disabled breakpoint has no effect but is not forgotten. All
5341options such as ignore-counts, conditions and commands are remembered in
5342case the breakpoint is enabled again later. You may abbreviate
5343@code{disable} as @code{dis}.
5344
c906108c 5345@kindex enable
18da0c51 5346@item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5347Enable the specified breakpoints (or all defined breakpoints). They
5348become effective once again in stopping your program.
5349
18da0c51 5350@item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
c906108c
SS
5351Enable the specified breakpoints temporarily. @value{GDBN} disables any
5352of these breakpoints immediately after stopping your program.
5353
18da0c51 5354@item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
816338b5
SS
5355Enable the specified breakpoints temporarily. @value{GDBN} records
5356@var{count} with each of the specified breakpoints, and decrements a
5357breakpoint's count when it is hit. When any count reaches 0,
5358@value{GDBN} disables that breakpoint. If a breakpoint has an ignore
5359count (@pxref{Conditions, ,Break Conditions}), that will be
5360decremented to 0 before @var{count} is affected.
5361
18da0c51 5362@item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
c906108c
SS
5363Enable the specified breakpoints to work once, then die. @value{GDBN}
5364deletes any of these breakpoints as soon as your program stops there.
09d4efe1 5365Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
5366@end table
5367
d4f3574e
SS
5368@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5369@c confusing: tbreak is also initially enabled.
c906108c 5370Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
79a6e687 5371,Setting Breakpoints}), breakpoints that you set are initially enabled;
c906108c
SS
5372subsequently, they become disabled or enabled only when you use one of
5373the commands above. (The command @code{until} can set and delete a
5374breakpoint of its own, but it does not change the state of your other
5375breakpoints; see @ref{Continuing and Stepping, ,Continuing and
79a6e687 5376Stepping}.)
c906108c 5377
6d2ebf8b 5378@node Conditions
79a6e687 5379@subsection Break Conditions
c906108c
SS
5380@cindex conditional breakpoints
5381@cindex breakpoint conditions
5382
5383@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 5384@c in particular for a watchpoint?
c906108c
SS
5385The simplest sort of breakpoint breaks every time your program reaches a
5386specified place. You can also specify a @dfn{condition} for a
5387breakpoint. A condition is just a Boolean expression in your
5388programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
5389a condition evaluates the expression each time your program reaches it,
5390and your program stops only if the condition is @emph{true}.
5391
5392This is the converse of using assertions for program validation; in that
5393situation, you want to stop when the assertion is violated---that is,
5394when the condition is false. In C, if you want to test an assertion expressed
5395by the condition @var{assert}, you should set the condition
5396@samp{! @var{assert}} on the appropriate breakpoint.
5397
5398Conditions are also accepted for watchpoints; you may not need them,
5399since a watchpoint is inspecting the value of an expression anyhow---but
5400it might be simpler, say, to just set a watchpoint on a variable name,
5401and specify a condition that tests whether the new value is an interesting
5402one.
5403
5404Break conditions can have side effects, and may even call functions in
5405your program. This can be useful, for example, to activate functions
5406that log program progress, or to use your own print functions to
99e008fe 5407format special data structures. The effects are completely predictable
c906108c
SS
5408unless there is another enabled breakpoint at the same address. (In
5409that case, @value{GDBN} might see the other breakpoint first and stop your
5410program without checking the condition of this one.) Note that
d4f3574e
SS
5411breakpoint commands are usually more convenient and flexible than break
5412conditions for the
c906108c 5413purpose of performing side effects when a breakpoint is reached
79a6e687 5414(@pxref{Break Commands, ,Breakpoint Command Lists}).
c906108c 5415
83364271
LM
5416Breakpoint conditions can also be evaluated on the target's side if
5417the target supports it. Instead of evaluating the conditions locally,
5418@value{GDBN} encodes the expression into an agent expression
5419(@pxref{Agent Expressions}) suitable for execution on the target,
5420independently of @value{GDBN}. Global variables become raw memory
5421locations, locals become stack accesses, and so forth.
5422
5423In this case, @value{GDBN} will only be notified of a breakpoint trigger
5424when its condition evaluates to true. This mechanism may provide faster
5425response times depending on the performance characteristics of the target
5426since it does not need to keep @value{GDBN} informed about
5427every breakpoint trigger, even those with false conditions.
5428
c906108c
SS
5429Break conditions can be specified when a breakpoint is set, by using
5430@samp{if} in the arguments to the @code{break} command. @xref{Set
79a6e687 5431Breaks, ,Setting Breakpoints}. They can also be changed at any time
c906108c 5432with the @code{condition} command.
53a5351d 5433
c906108c
SS
5434You can also use the @code{if} keyword with the @code{watch} command.
5435The @code{catch} command does not recognize the @code{if} keyword;
5436@code{condition} is the only way to impose a further condition on a
5437catchpoint.
c906108c
SS
5438
5439@table @code
5440@kindex condition
5441@item condition @var{bnum} @var{expression}
5442Specify @var{expression} as the break condition for breakpoint,
5443watchpoint, or catchpoint number @var{bnum}. After you set a condition,
5444breakpoint @var{bnum} stops your program only if the value of
5445@var{expression} is true (nonzero, in C). When you use
5446@code{condition}, @value{GDBN} checks @var{expression} immediately for
5447syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
5448referents in the context of your breakpoint. If @var{expression} uses
5449symbols not referenced in the context of the breakpoint, @value{GDBN}
5450prints an error message:
5451
474c8240 5452@smallexample
d4f3574e 5453No symbol "foo" in current context.
474c8240 5454@end smallexample
d4f3574e
SS
5455
5456@noindent
c906108c
SS
5457@value{GDBN} does
5458not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
5459command (or a command that sets a breakpoint with a condition, like
5460@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
5461
5462@item condition @var{bnum}
5463Remove the condition from breakpoint number @var{bnum}. It becomes
5464an ordinary unconditional breakpoint.
5465@end table
5466
5467@cindex ignore count (of breakpoint)
5468A special case of a breakpoint condition is to stop only when the
5469breakpoint has been reached a certain number of times. This is so
5470useful that there is a special way to do it, using the @dfn{ignore
5471count} of the breakpoint. Every breakpoint has an ignore count, which
5472is an integer. Most of the time, the ignore count is zero, and
5473therefore has no effect. But if your program reaches a breakpoint whose
5474ignore count is positive, then instead of stopping, it just decrements
5475the ignore count by one and continues. As a result, if the ignore count
5476value is @var{n}, the breakpoint does not stop the next @var{n} times
5477your program reaches it.
5478
5479@table @code
5480@kindex ignore
5481@item ignore @var{bnum} @var{count}
5482Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5483The next @var{count} times the breakpoint is reached, your program's
5484execution does not stop; other than to decrement the ignore count, @value{GDBN}
5485takes no action.
5486
5487To make the breakpoint stop the next time it is reached, specify
5488a count of zero.
5489
5490When you use @code{continue} to resume execution of your program from a
5491breakpoint, you can specify an ignore count directly as an argument to
5492@code{continue}, rather than using @code{ignore}. @xref{Continuing and
79a6e687 5493Stepping,,Continuing and Stepping}.
c906108c
SS
5494
5495If a breakpoint has a positive ignore count and a condition, the
5496condition is not checked. Once the ignore count reaches zero,
5497@value{GDBN} resumes checking the condition.
5498
5499You could achieve the effect of the ignore count with a condition such
5500as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5501is decremented each time. @xref{Convenience Vars, ,Convenience
79a6e687 5502Variables}.
c906108c
SS
5503@end table
5504
5505Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5506
5507
6d2ebf8b 5508@node Break Commands
79a6e687 5509@subsection Breakpoint Command Lists
c906108c
SS
5510
5511@cindex breakpoint commands
5512You can give any breakpoint (or watchpoint or catchpoint) a series of
5513commands to execute when your program stops due to that breakpoint. For
5514example, you might want to print the values of certain expressions, or
5515enable other breakpoints.
5516
5517@table @code
5518@kindex commands
ca91424e 5519@kindex end@r{ (breakpoint commands)}
18da0c51 5520@item commands @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5521@itemx @dots{} @var{command-list} @dots{}
5522@itemx end
95a42b64 5523Specify a list of commands for the given breakpoints. The commands
c906108c
SS
5524themselves appear on the following lines. Type a line containing just
5525@code{end} to terminate the commands.
5526
5527To remove all commands from a breakpoint, type @code{commands} and
5528follow it immediately with @code{end}; that is, give no commands.
5529
95a42b64
TT
5530With no argument, @code{commands} refers to the last breakpoint,
5531watchpoint, or catchpoint set (not to the breakpoint most recently
5532encountered). If the most recent breakpoints were set with a single
5533command, then the @code{commands} will apply to all the breakpoints
5534set by that command. This applies to breakpoints set by
86b17b60
PA
5535@code{rbreak}, and also applies when a single @code{break} command
5536creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5537Expressions}).
c906108c
SS
5538@end table
5539
5540Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5541disabled within a @var{command-list}.
5542
5543You can use breakpoint commands to start your program up again. Simply
5544use the @code{continue} command, or @code{step}, or any other command
5545that resumes execution.
5546
5547Any other commands in the command list, after a command that resumes
5548execution, are ignored. This is because any time you resume execution
5549(even with a simple @code{next} or @code{step}), you may encounter
5550another breakpoint---which could have its own command list, leading to
5551ambiguities about which list to execute.
5552
5553@kindex silent
5554If the first command you specify in a command list is @code{silent}, the
5555usual message about stopping at a breakpoint is not printed. This may
5556be desirable for breakpoints that are to print a specific message and
5557then continue. If none of the remaining commands print anything, you
5558see no sign that the breakpoint was reached. @code{silent} is
5559meaningful only at the beginning of a breakpoint command list.
5560
5561The commands @code{echo}, @code{output}, and @code{printf} allow you to
5562print precisely controlled output, and are often useful in silent
79a6e687 5563breakpoints. @xref{Output, ,Commands for Controlled Output}.
c906108c
SS
5564
5565For example, here is how you could use breakpoint commands to print the
5566value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5567
474c8240 5568@smallexample
c906108c
SS
5569break foo if x>0
5570commands
5571silent
5572printf "x is %d\n",x
5573cont
5574end
474c8240 5575@end smallexample
c906108c
SS
5576
5577One application for breakpoint commands is to compensate for one bug so
5578you can test for another. Put a breakpoint just after the erroneous line
5579of code, give it a condition to detect the case in which something
5580erroneous has been done, and give it commands to assign correct values
5581to any variables that need them. End with the @code{continue} command
5582so that your program does not stop, and start with the @code{silent}
5583command so that no output is produced. Here is an example:
5584
474c8240 5585@smallexample
c906108c
SS
5586break 403
5587commands
5588silent
5589set x = y + 4
5590cont
5591end
474c8240 5592@end smallexample
c906108c 5593
e7e0cddf
SS
5594@node Dynamic Printf
5595@subsection Dynamic Printf
5596
5597@cindex dynamic printf
5598@cindex dprintf
5599The dynamic printf command @code{dprintf} combines a breakpoint with
5600formatted printing of your program's data to give you the effect of
5601inserting @code{printf} calls into your program on-the-fly, without
5602having to recompile it.
5603
5604In its most basic form, the output goes to the GDB console. However,
5605you can set the variable @code{dprintf-style} for alternate handling.
5606For instance, you can ask to format the output by calling your
5607program's @code{printf} function. This has the advantage that the
5608characters go to the program's output device, so they can recorded in
5609redirects to files and so forth.
5610
d3ce09f5
SS
5611If you are doing remote debugging with a stub or agent, you can also
5612ask to have the printf handled by the remote agent. In addition to
5613ensuring that the output goes to the remote program's device along
5614with any other output the program might produce, you can also ask that
5615the dprintf remain active even after disconnecting from the remote
5616target. Using the stub/agent is also more efficient, as it can do
5617everything without needing to communicate with @value{GDBN}.
5618
e7e0cddf
SS
5619@table @code
5620@kindex dprintf
5621@item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
5622Whenever execution reaches @var{location}, print the values of one or
5623more @var{expressions} under the control of the string @var{template}.
5624To print several values, separate them with commas.
5625
5626@item set dprintf-style @var{style}
5627Set the dprintf output to be handled in one of several different
5628styles enumerated below. A change of style affects all existing
5629dynamic printfs immediately. (If you need individual control over the
5630print commands, simply define normal breakpoints with
5631explicitly-supplied command lists.)
5632
18da0c51 5633@table @code
e7e0cddf
SS
5634@item gdb
5635@kindex dprintf-style gdb
5636Handle the output using the @value{GDBN} @code{printf} command.
5637
5638@item call
5639@kindex dprintf-style call
5640Handle the output by calling a function in your program (normally
5641@code{printf}).
5642
d3ce09f5
SS
5643@item agent
5644@kindex dprintf-style agent
5645Have the remote debugging agent (such as @code{gdbserver}) handle
5646the output itself. This style is only available for agents that
5647support running commands on the target.
18da0c51 5648@end table
d3ce09f5 5649
e7e0cddf
SS
5650@item set dprintf-function @var{function}
5651Set the function to call if the dprintf style is @code{call}. By
5652default its value is @code{printf}. You may set it to any expression.
5653that @value{GDBN} can evaluate to a function, as per the @code{call}
5654command.
5655
5656@item set dprintf-channel @var{channel}
5657Set a ``channel'' for dprintf. If set to a non-empty value,
5658@value{GDBN} will evaluate it as an expression and pass the result as
5659a first argument to the @code{dprintf-function}, in the manner of
5660@code{fprintf} and similar functions. Otherwise, the dprintf format
5661string will be the first argument, in the manner of @code{printf}.
5662
5663As an example, if you wanted @code{dprintf} output to go to a logfile
5664that is a standard I/O stream assigned to the variable @code{mylog},
5665you could do the following:
5666
5667@example
5668(gdb) set dprintf-style call
5669(gdb) set dprintf-function fprintf
5670(gdb) set dprintf-channel mylog
5671(gdb) dprintf 25,"at line 25, glob=%d\n",glob
5672Dprintf 1 at 0x123456: file main.c, line 25.
5673(gdb) info break
56741 dprintf keep y 0x00123456 in main at main.c:25
5675 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5676 continue
5677(gdb)
5678@end example
5679
5680Note that the @code{info break} displays the dynamic printf commands
5681as normal breakpoint commands; you can thus easily see the effect of
5682the variable settings.
5683
d3ce09f5
SS
5684@item set disconnected-dprintf on
5685@itemx set disconnected-dprintf off
5686@kindex set disconnected-dprintf
5687Choose whether @code{dprintf} commands should continue to run if
5688@value{GDBN} has disconnected from the target. This only applies
5689if the @code{dprintf-style} is @code{agent}.
5690
5691@item show disconnected-dprintf off
5692@kindex show disconnected-dprintf
5693Show the current choice for disconnected @code{dprintf}.
5694
e7e0cddf
SS
5695@end table
5696
5697@value{GDBN} does not check the validity of function and channel,
5698relying on you to supply values that are meaningful for the contexts
5699in which they are being used. For instance, the function and channel
5700may be the values of local variables, but if that is the case, then
5701all enabled dynamic prints must be at locations within the scope of
5702those locals. If evaluation fails, @value{GDBN} will report an error.
5703
6149aea9
PA
5704@node Save Breakpoints
5705@subsection How to save breakpoints to a file
5706
5707To save breakpoint definitions to a file use the @w{@code{save
5708breakpoints}} command.
5709
5710@table @code
5711@kindex save breakpoints
5712@cindex save breakpoints to a file for future sessions
5713@item save breakpoints [@var{filename}]
5714This command saves all current breakpoint definitions together with
5715their commands and ignore counts, into a file @file{@var{filename}}
5716suitable for use in a later debugging session. This includes all
5717types of breakpoints (breakpoints, watchpoints, catchpoints,
5718tracepoints). To read the saved breakpoint definitions, use the
5719@code{source} command (@pxref{Command Files}). Note that watchpoints
5720with expressions involving local variables may fail to be recreated
5721because it may not be possible to access the context where the
5722watchpoint is valid anymore. Because the saved breakpoint definitions
5723are simply a sequence of @value{GDBN} commands that recreate the
5724breakpoints, you can edit the file in your favorite editing program,
5725and remove the breakpoint definitions you're not interested in, or
5726that can no longer be recreated.
5727@end table
5728
62e5f89c
SDJ
5729@node Static Probe Points
5730@subsection Static Probe Points
5731
5732@cindex static probe point, SystemTap
3133f8c1 5733@cindex static probe point, DTrace
62e5f89c
SDJ
5734@value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5735for Statically Defined Tracing, and the probes are designed to have a tiny
3133f8c1
JM
5736runtime code and data footprint, and no dynamic relocations.
5737
5738Currently, the following types of probes are supported on
5739ELF-compatible systems:
5740
5741@itemize @bullet
62e5f89c 5742
3133f8c1
JM
5743@item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5744@acronym{SDT} probes@footnote{See
62e5f89c 5745@uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
3133f8c1
JM
5746for more information on how to add @code{SystemTap} @acronym{SDT}
5747probes in your applications.}. @code{SystemTap} probes are usable
5748from assembly, C and C@t{++} languages@footnote{See
5749@uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5750for a good reference on how the @acronym{SDT} probes are implemented.}.
5751
5752@item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5753@acronym{USDT} probes. @code{DTrace} probes are usable from C and
5754C@t{++} languages.
5755@end itemize
62e5f89c
SDJ
5756
5757@cindex semaphores on static probe points
3133f8c1
JM
5758Some @code{SystemTap} probes have an associated semaphore variable;
5759for instance, this happens automatically if you defined your probe
5760using a DTrace-style @file{.d} file. If your probe has a semaphore,
5761@value{GDBN} will automatically enable it when you specify a
5762breakpoint using the @samp{-probe-stap} notation. But, if you put a
5763breakpoint at a probe's location by some other method (e.g.,
5764@code{break file:line}), then @value{GDBN} will not automatically set
5765the semaphore. @code{DTrace} probes do not support semaphores.
62e5f89c
SDJ
5766
5767You can examine the available static static probes using @code{info
5768probes}, with optional arguments:
5769
5770@table @code
5771@kindex info probes
3133f8c1
JM
5772@item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5773If given, @var{type} is either @code{stap} for listing
5774@code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5775probes. If omitted all probes are listed regardless of their types.
5776
62e5f89c
SDJ
5777If given, @var{provider} is a regular expression used to match against provider
5778names when selecting which probes to list. If omitted, probes by all
5779probes from all providers are listed.
5780
5781If given, @var{name} is a regular expression to match against probe names
5782when selecting which probes to list. If omitted, probe names are not
5783considered when deciding whether to display them.
5784
5785If given, @var{objfile} is a regular expression used to select which
5786object files (executable or shared libraries) to examine. If not
5787given, all object files are considered.
5788
5789@item info probes all
5790List the available static probes, from all types.
5791@end table
5792
9aca2ff8
JM
5793@cindex enabling and disabling probes
5794Some probe points can be enabled and/or disabled. The effect of
5795enabling or disabling a probe depends on the type of probe being
3133f8c1
JM
5796handled. Some @code{DTrace} probes can be enabled or
5797disabled, but @code{SystemTap} probes cannot be disabled.
9aca2ff8
JM
5798
5799You can enable (or disable) one or more probes using the following
5800commands, with optional arguments:
5801
5802@table @code
5803@kindex enable probes
5804@item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5805If given, @var{provider} is a regular expression used to match against
5806provider names when selecting which probes to enable. If omitted,
5807all probes from all providers are enabled.
5808
5809If given, @var{name} is a regular expression to match against probe
5810names when selecting which probes to enable. If omitted, probe names
5811are not considered when deciding whether to enable them.
5812
5813If given, @var{objfile} is a regular expression used to select which
5814object files (executable or shared libraries) to examine. If not
5815given, all object files are considered.
5816
5817@kindex disable probes
5818@item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5819See the @code{enable probes} command above for a description of the
5820optional arguments accepted by this command.
5821@end table
5822
62e5f89c
SDJ
5823@vindex $_probe_arg@r{, convenience variable}
5824A probe may specify up to twelve arguments. These are available at the
5825point at which the probe is defined---that is, when the current PC is
5826at the probe's location. The arguments are available using the
5827convenience variables (@pxref{Convenience Vars})
3133f8c1
JM
5828@code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
5829probes each probe argument is an integer of the appropriate size;
5830types are not preserved. In @code{DTrace} probes types are preserved
5831provided that they are recognized as such by @value{GDBN}; otherwise
5832the value of the probe argument will be a long integer. The
62e5f89c
SDJ
5833convenience variable @code{$_probe_argc} holds the number of arguments
5834at the current probe point.
5835
5836These variables are always available, but attempts to access them at
5837any location other than a probe point will cause @value{GDBN} to give
5838an error message.
5839
5840
c906108c 5841@c @ifclear BARETARGET
6d2ebf8b 5842@node Error in Breakpoints
d4f3574e 5843@subsection ``Cannot insert breakpoints''
c906108c 5844
fa3a767f
PA
5845If you request too many active hardware-assisted breakpoints and
5846watchpoints, you will see this error message:
d4f3574e
SS
5847
5848@c FIXME: the precise wording of this message may change; the relevant
5849@c source change is not committed yet (Sep 3, 1999).
5850@smallexample
5851Stopped; cannot insert breakpoints.
5852You may have requested too many hardware breakpoints and watchpoints.
5853@end smallexample
5854
5855@noindent
5856This message is printed when you attempt to resume the program, since
5857only then @value{GDBN} knows exactly how many hardware breakpoints and
5858watchpoints it needs to insert.
5859
5860When this message is printed, you need to disable or remove some of the
5861hardware-assisted breakpoints and watchpoints, and then continue.
5862
79a6e687 5863@node Breakpoint-related Warnings
1485d690
KB
5864@subsection ``Breakpoint address adjusted...''
5865@cindex breakpoint address adjusted
5866
5867Some processor architectures place constraints on the addresses at
5868which breakpoints may be placed. For architectures thus constrained,
5869@value{GDBN} will attempt to adjust the breakpoint's address to comply
5870with the constraints dictated by the architecture.
5871
5872One example of such an architecture is the Fujitsu FR-V. The FR-V is
5873a VLIW architecture in which a number of RISC-like instructions may be
5874bundled together for parallel execution. The FR-V architecture
5875constrains the location of a breakpoint instruction within such a
5876bundle to the instruction with the lowest address. @value{GDBN}
5877honors this constraint by adjusting a breakpoint's address to the
5878first in the bundle.
5879
5880It is not uncommon for optimized code to have bundles which contain
5881instructions from different source statements, thus it may happen that
5882a breakpoint's address will be adjusted from one source statement to
5883another. Since this adjustment may significantly alter @value{GDBN}'s
5884breakpoint related behavior from what the user expects, a warning is
5885printed when the breakpoint is first set and also when the breakpoint
5886is hit.
5887
5888A warning like the one below is printed when setting a breakpoint
5889that's been subject to address adjustment:
5890
5891@smallexample
5892warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
5893@end smallexample
5894
5895Such warnings are printed both for user settable and @value{GDBN}'s
5896internal breakpoints. If you see one of these warnings, you should
5897verify that a breakpoint set at the adjusted address will have the
5898desired affect. If not, the breakpoint in question may be removed and
b383017d 5899other breakpoints may be set which will have the desired behavior.
1485d690
KB
5900E.g., it may be sufficient to place the breakpoint at a later
5901instruction. A conditional breakpoint may also be useful in some
5902cases to prevent the breakpoint from triggering too often.
5903
5904@value{GDBN} will also issue a warning when stopping at one of these
5905adjusted breakpoints:
5906
5907@smallexample
5908warning: Breakpoint 1 address previously adjusted from 0x00010414
5909to 0x00010410.
5910@end smallexample
5911
5912When this warning is encountered, it may be too late to take remedial
5913action except in cases where the breakpoint is hit earlier or more
5914frequently than expected.
d4f3574e 5915
6d2ebf8b 5916@node Continuing and Stepping
79a6e687 5917@section Continuing and Stepping
c906108c
SS
5918
5919@cindex stepping
5920@cindex continuing
5921@cindex resuming execution
5922@dfn{Continuing} means resuming program execution until your program
5923completes normally. In contrast, @dfn{stepping} means executing just
5924one more ``step'' of your program, where ``step'' may mean either one
5925line of source code, or one machine instruction (depending on what
7a292a7a
SS
5926particular command you use). Either when continuing or when stepping,
5927your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e 5928it stops due to a signal, you may want to use @code{handle}, or use
e5f8a7cc
PA
5929@samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
5930or you may step into the signal's handler (@pxref{stepping and signal
5931handlers}).)
c906108c
SS
5932
5933@table @code
5934@kindex continue
41afff9a
EZ
5935@kindex c @r{(@code{continue})}
5936@kindex fg @r{(resume foreground execution)}
c906108c
SS
5937@item continue @r{[}@var{ignore-count}@r{]}
5938@itemx c @r{[}@var{ignore-count}@r{]}
5939@itemx fg @r{[}@var{ignore-count}@r{]}
5940Resume program execution, at the address where your program last stopped;
5941any breakpoints set at that address are bypassed. The optional argument
5942@var{ignore-count} allows you to specify a further number of times to
5943ignore a breakpoint at this location; its effect is like that of
79a6e687 5944@code{ignore} (@pxref{Conditions, ,Break Conditions}).
c906108c
SS
5945
5946The argument @var{ignore-count} is meaningful only when your program
5947stopped due to a breakpoint. At other times, the argument to
5948@code{continue} is ignored.
5949
d4f3574e
SS
5950The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
5951debugged program is deemed to be the foreground program) are provided
5952purely for convenience, and have exactly the same behavior as
5953@code{continue}.
c906108c
SS
5954@end table
5955
5956To resume execution at a different place, you can use @code{return}
79a6e687 5957(@pxref{Returning, ,Returning from a Function}) to go back to the
c906108c 5958calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
79a6e687 5959Different Address}) to go to an arbitrary location in your program.
c906108c
SS
5960
5961A typical technique for using stepping is to set a breakpoint
79a6e687 5962(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
c906108c
SS
5963beginning of the function or the section of your program where a problem
5964is believed to lie, run your program until it stops at that breakpoint,
5965and then step through the suspect area, examining the variables that are
5966interesting, until you see the problem happen.
5967
5968@table @code
5969@kindex step
41afff9a 5970@kindex s @r{(@code{step})}
c906108c
SS
5971@item step
5972Continue running your program until control reaches a different source
5973line, then stop it and return control to @value{GDBN}. This command is
5974abbreviated @code{s}.
5975
5976@quotation
5977@c "without debugging information" is imprecise; actually "without line
5978@c numbers in the debugging information". (gcc -g1 has debugging info but
5979@c not line numbers). But it seems complex to try to make that
5980@c distinction here.
5981@emph{Warning:} If you use the @code{step} command while control is
5982within a function that was compiled without debugging information,
5983execution proceeds until control reaches a function that does have
5984debugging information. Likewise, it will not step into a function which
5985is compiled without debugging information. To step through functions
5986without debugging information, use the @code{stepi} command, described
5987below.
5988@end quotation
5989
4a92d011
EZ
5990The @code{step} command only stops at the first instruction of a source
5991line. This prevents the multiple stops that could otherwise occur in
5992@code{switch} statements, @code{for} loops, etc. @code{step} continues
5993to stop if a function that has debugging information is called within
5994the line. In other words, @code{step} @emph{steps inside} any functions
5995called within the line.
c906108c 5996
d4f3574e
SS
5997Also, the @code{step} command only enters a function if there is line
5998number information for the function. Otherwise it acts like the
5d161b24 5999@code{next} command. This avoids problems when using @code{cc -gl}
eb17f351 6000on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5d161b24 6001was any debugging information about the routine.
c906108c
SS
6002
6003@item step @var{count}
6004Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
6005breakpoint is reached, or a signal not related to stepping occurs before
6006@var{count} steps, stepping stops right away.
c906108c
SS
6007
6008@kindex next
41afff9a 6009@kindex n @r{(@code{next})}
c906108c
SS
6010@item next @r{[}@var{count}@r{]}
6011Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
6012This is similar to @code{step}, but function calls that appear within
6013the line of code are executed without stopping. Execution stops when
6014control reaches a different line of code at the original stack level
6015that was executing when you gave the @code{next} command. This command
6016is abbreviated @code{n}.
c906108c
SS
6017
6018An argument @var{count} is a repeat count, as for @code{step}.
6019
6020
6021@c FIX ME!! Do we delete this, or is there a way it fits in with
6022@c the following paragraph? --- Vctoria
6023@c
6024@c @code{next} within a function that lacks debugging information acts like
6025@c @code{step}, but any function calls appearing within the code of the
6026@c function are executed without stopping.
6027
d4f3574e
SS
6028The @code{next} command only stops at the first instruction of a
6029source line. This prevents multiple stops that could otherwise occur in
4a92d011 6030@code{switch} statements, @code{for} loops, etc.
c906108c 6031
b90a5f51
CF
6032@kindex set step-mode
6033@item set step-mode
6034@cindex functions without line info, and stepping
6035@cindex stepping into functions with no line info
6036@itemx set step-mode on
4a92d011 6037The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
6038stop at the first instruction of a function which contains no debug line
6039information rather than stepping over it.
6040
4a92d011
EZ
6041This is useful in cases where you may be interested in inspecting the
6042machine instructions of a function which has no symbolic info and do not
6043want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
6044
6045@item set step-mode off
4a92d011 6046Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
6047debug information. This is the default.
6048
9c16f35a
EZ
6049@item show step-mode
6050Show whether @value{GDBN} will stop in or step over functions without
6051source line debug information.
6052
c906108c 6053@kindex finish
8dfa32fc 6054@kindex fin @r{(@code{finish})}
c906108c
SS
6055@item finish
6056Continue running until just after function in the selected stack frame
8dfa32fc
JB
6057returns. Print the returned value (if any). This command can be
6058abbreviated as @code{fin}.
c906108c
SS
6059
6060Contrast this with the @code{return} command (@pxref{Returning,
79a6e687 6061,Returning from a Function}).
c906108c 6062
000439d5
TT
6063@kindex set print finish
6064@kindex show print finish
6065@item set print finish @r{[}on|off@r{]}
6066@itemx show print finish
6067By default the @code{finish} command will show the value that is
6068returned by the function. This can be disabled using @code{set print
6069finish off}. When disabled, the value is still entered into the value
6070history (@pxref{Value History}), but not displayed.
6071
c906108c 6072@kindex until
41afff9a 6073@kindex u @r{(@code{until})}
09d4efe1 6074@cindex run until specified location
c906108c
SS
6075@item until
6076@itemx u
6077Continue running until a source line past the current line, in the
6078current stack frame, is reached. This command is used to avoid single
6079stepping through a loop more than once. It is like the @code{next}
6080command, except that when @code{until} encounters a jump, it
6081automatically continues execution until the program counter is greater
6082than the address of the jump.
6083
6084This means that when you reach the end of a loop after single stepping
6085though it, @code{until} makes your program continue execution until it
6086exits the loop. In contrast, a @code{next} command at the end of a loop
6087simply steps back to the beginning of the loop, which forces you to step
6088through the next iteration.
6089
6090@code{until} always stops your program if it attempts to exit the current
6091stack frame.
6092
6093@code{until} may produce somewhat counterintuitive results if the order
6094of machine code does not match the order of the source lines. For
6095example, in the following excerpt from a debugging session, the @code{f}
6096(@code{frame}) command shows that execution is stopped at line
6097@code{206}; yet when we use @code{until}, we get to line @code{195}:
6098
474c8240 6099@smallexample
c906108c
SS
6100(@value{GDBP}) f
6101#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
6102206 expand_input();
6103(@value{GDBP}) until
6104195 for ( ; argc > 0; NEXTARG) @{
474c8240 6105@end smallexample
c906108c
SS
6106
6107This happened because, for execution efficiency, the compiler had
6108generated code for the loop closure test at the end, rather than the
6109start, of the loop---even though the test in a C @code{for}-loop is
6110written before the body of the loop. The @code{until} command appeared
6111to step back to the beginning of the loop when it advanced to this
6112expression; however, it has not really gone to an earlier
6113statement---not in terms of the actual machine code.
6114
6115@code{until} with no argument works by means of single
6116instruction stepping, and hence is slower than @code{until} with an
6117argument.
6118
6119@item until @var{location}
6120@itemx u @var{location}
697aa1b7
EZ
6121Continue running your program until either the specified @var{location} is
6122reached, or the current stack frame returns. The location is any of
2a25a5ba
EZ
6123the forms described in @ref{Specify Location}.
6124This form of the command uses temporary breakpoints, and
c60eb6f1
EZ
6125hence is quicker than @code{until} without an argument. The specified
6126location is actually reached only if it is in the current frame. This
6127implies that @code{until} can be used to skip over recursive function
6128invocations. For instance in the code below, if the current location is
6129line @code{96}, issuing @code{until 99} will execute the program up to
db2e3e2e 6130line @code{99} in the same invocation of factorial, i.e., after the inner
c60eb6f1
EZ
6131invocations have returned.
6132
6133@smallexample
613494 int factorial (int value)
613595 @{
613696 if (value > 1) @{
613797 value *= factorial (value - 1);
613898 @}
613999 return (value);
6140100 @}
6141@end smallexample
6142
6143
6144@kindex advance @var{location}
984359d2 6145@item advance @var{location}
09d4efe1 6146Continue running the program up to the given @var{location}. An argument is
2a25a5ba
EZ
6147required, which should be of one of the forms described in
6148@ref{Specify Location}.
6149Execution will also stop upon exit from the current stack
c60eb6f1
EZ
6150frame. This command is similar to @code{until}, but @code{advance} will
6151not skip over recursive function calls, and the target location doesn't
6152have to be in the same frame as the current one.
6153
c906108c
SS
6154
6155@kindex stepi
41afff9a 6156@kindex si @r{(@code{stepi})}
c906108c 6157@item stepi
96a2c332 6158@itemx stepi @var{arg}
c906108c
SS
6159@itemx si
6160Execute one machine instruction, then stop and return to the debugger.
6161
6162It is often useful to do @samp{display/i $pc} when stepping by machine
6163instructions. This makes @value{GDBN} automatically display the next
6164instruction to be executed, each time your program stops. @xref{Auto
79a6e687 6165Display,, Automatic Display}.
c906108c
SS
6166
6167An argument is a repeat count, as in @code{step}.
6168
6169@need 750
6170@kindex nexti
41afff9a 6171@kindex ni @r{(@code{nexti})}
c906108c 6172@item nexti
96a2c332 6173@itemx nexti @var{arg}
c906108c
SS
6174@itemx ni
6175Execute one machine instruction, but if it is a function call,
6176proceed until the function returns.
6177
6178An argument is a repeat count, as in @code{next}.
c1e36e3e
PA
6179
6180@end table
6181
6182@anchor{range stepping}
6183@cindex range stepping
6184@cindex target-assisted range stepping
6185By default, and if available, @value{GDBN} makes use of
6186target-assisted @dfn{range stepping}. In other words, whenever you
6187use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
6188tells the target to step the corresponding range of instruction
6189addresses instead of issuing multiple single-steps. This speeds up
6190line stepping, particularly for remote targets. Ideally, there should
6191be no reason you would want to turn range stepping off. However, it's
6192possible that a bug in the debug info, a bug in the remote stub (for
6193remote targets), or even a bug in @value{GDBN} could make line
6194stepping behave incorrectly when target-assisted range stepping is
6195enabled. You can use the following command to turn off range stepping
6196if necessary:
6197
6198@table @code
6199@kindex set range-stepping
6200@kindex show range-stepping
6201@item set range-stepping
6202@itemx show range-stepping
6203Control whether range stepping is enabled.
6204
6205If @code{on}, and the target supports it, @value{GDBN} tells the
6206target to step a range of addresses itself, instead of issuing
6207multiple single-steps. If @code{off}, @value{GDBN} always issues
6208single-steps, even if range stepping is supported by the target. The
6209default is @code{on}.
6210
c906108c
SS
6211@end table
6212
aad1c02c
TT
6213@node Skipping Over Functions and Files
6214@section Skipping Over Functions and Files
1bfeeb0f
JL
6215@cindex skipping over functions and files
6216
6217The program you are debugging may contain some functions which are
8244c20d 6218uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
cce0e923
DE
6219skip a function, all functions in a file or a particular function in
6220a particular file when stepping.
1bfeeb0f
JL
6221
6222For example, consider the following C function:
6223
6224@smallexample
6225101 int func()
6226102 @{
6227103 foo(boring());
6228104 bar(boring());
6229105 @}
6230@end smallexample
6231
6232@noindent
6233Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
6234are not interested in stepping through @code{boring}. If you run @code{step}
6235at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
6236step over both @code{foo} and @code{boring}!
6237
6238One solution is to @code{step} into @code{boring} and use the @code{finish}
6239command to immediately exit it. But this can become tedious if @code{boring}
6240is called from many places.
6241
6242A more flexible solution is to execute @kbd{skip boring}. This instructs
6243@value{GDBN} never to step into @code{boring}. Now when you execute
6244@code{step} at line 103, you'll step over @code{boring} and directly into
6245@code{foo}.
6246
cce0e923
DE
6247Functions may be skipped by providing either a function name, linespec
6248(@pxref{Specify Location}), regular expression that matches the function's
6249name, file name or a @code{glob}-style pattern that matches the file name.
6250
6251On Posix systems the form of the regular expression is
6252``Extended Regular Expressions''. See for example @samp{man 7 regex}
6253on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
6254expression is whatever is provided by the @code{regcomp} function of
6255the underlying system.
6256See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
6257description of @code{glob}-style patterns.
6258
6259@table @code
6260@kindex skip
6261@item skip @r{[}@var{options}@r{]}
6262The basic form of the @code{skip} command takes zero or more options
6263that specify what to skip.
6264The @var{options} argument is any useful combination of the following:
1bfeeb0f
JL
6265
6266@table @code
cce0e923
DE
6267@item -file @var{file}
6268@itemx -fi @var{file}
6269Functions in @var{file} will be skipped over when stepping.
6270
6271@item -gfile @var{file-glob-pattern}
6272@itemx -gfi @var{file-glob-pattern}
6273@cindex skipping over files via glob-style patterns
6274Functions in files matching @var{file-glob-pattern} will be skipped
6275over when stepping.
6276
6277@smallexample
6278(gdb) skip -gfi utils/*.c
6279@end smallexample
6280
6281@item -function @var{linespec}
6282@itemx -fu @var{linespec}
6283Functions named by @var{linespec} or the function containing the line
6284named by @var{linespec} will be skipped over when stepping.
6285@xref{Specify Location}.
6286
6287@item -rfunction @var{regexp}
6288@itemx -rfu @var{regexp}
6289@cindex skipping over functions via regular expressions
6290Functions whose name matches @var{regexp} will be skipped over when stepping.
6291
6292This form is useful for complex function names.
6293For example, there is generally no need to step into C@t{++} @code{std::string}
6294constructors or destructors. Plus with C@t{++} templates it can be hard to
6295write out the full name of the function, and often it doesn't matter what
6296the template arguments are. Specifying the function to be skipped as a
6297regular expression makes this easier.
6298
6299@smallexample
6300(gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
6301@end smallexample
6302
6303If you want to skip every templated C@t{++} constructor and destructor
6304in the @code{std} namespace you can do:
6305
6306@smallexample
6307(gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
6308@end smallexample
6309@end table
6310
6311If no options are specified, the function you're currently debugging
6312will be skipped.
6313
1bfeeb0f 6314@kindex skip function
cce0e923 6315@item skip function @r{[}@var{linespec}@r{]}
1bfeeb0f
JL
6316After running this command, the function named by @var{linespec} or the
6317function containing the line named by @var{linespec} will be skipped over when
983fb131 6318stepping. @xref{Specify Location}.
1bfeeb0f
JL
6319
6320If you do not specify @var{linespec}, the function you're currently debugging
6321will be skipped.
6322
6323(If you have a function called @code{file} that you want to skip, use
6324@kbd{skip function file}.)
6325
6326@kindex skip file
6327@item skip file @r{[}@var{filename}@r{]}
6328After running this command, any function whose source lives in @var{filename}
6329will be skipped over when stepping.
6330
cce0e923
DE
6331@smallexample
6332(gdb) skip file boring.c
6333File boring.c will be skipped when stepping.
6334@end smallexample
6335
1bfeeb0f
JL
6336If you do not specify @var{filename}, functions whose source lives in the file
6337you're currently debugging will be skipped.
6338@end table
6339
6340Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
6341These are the commands for managing your list of skips:
6342
6343@table @code
6344@kindex info skip
6345@item info skip @r{[}@var{range}@r{]}
6346Print details about the specified skip(s). If @var{range} is not specified,
6347print a table with details about all functions and files marked for skipping.
6348@code{info skip} prints the following information about each skip:
6349
6350@table @emph
6351@item Identifier
6352A number identifying this skip.
1bfeeb0f 6353@item Enabled or Disabled
cce0e923
DE
6354Enabled skips are marked with @samp{y}.
6355Disabled skips are marked with @samp{n}.
6356@item Glob
6357If the file name is a @samp{glob} pattern this is @samp{y}.
6358Otherwise it is @samp{n}.
6359@item File
6360The name or @samp{glob} pattern of the file to be skipped.
6361If no file is specified this is @samp{<none>}.
6362@item RE
6363If the function name is a @samp{regular expression} this is @samp{y}.
6364Otherwise it is @samp{n}.
6365@item Function
6366The name or regular expression of the function to skip.
6367If no function is specified this is @samp{<none>}.
1bfeeb0f
JL
6368@end table
6369
6370@kindex skip delete
6371@item skip delete @r{[}@var{range}@r{]}
6372Delete the specified skip(s). If @var{range} is not specified, delete all
6373skips.
6374
6375@kindex skip enable
6376@item skip enable @r{[}@var{range}@r{]}
6377Enable the specified skip(s). If @var{range} is not specified, enable all
6378skips.
6379
6380@kindex skip disable
6381@item skip disable @r{[}@var{range}@r{]}
6382Disable the specified skip(s). If @var{range} is not specified, disable all
6383skips.
6384
3e68067f
SM
6385@kindex set debug skip
6386@item set debug skip @r{[}on|off@r{]}
6387Set whether to print the debug output about skipping files and functions.
6388
6389@kindex show debug skip
6390@item show debug skip
6391Show whether the debug output about skipping files and functions is printed.
6392
1bfeeb0f
JL
6393@end table
6394
6d2ebf8b 6395@node Signals
c906108c
SS
6396@section Signals
6397@cindex signals
6398
6399A signal is an asynchronous event that can happen in a program. The
6400operating system defines the possible kinds of signals, and gives each
6401kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 6402signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
6403@code{SIGSEGV} is the signal a program gets from referencing a place in
6404memory far away from all the areas in use; @code{SIGALRM} occurs when
6405the alarm clock timer goes off (which happens only if your program has
6406requested an alarm).
6407
6408@cindex fatal signals
6409Some signals, including @code{SIGALRM}, are a normal part of the
6410functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 6411errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
6412program has not specified in advance some other way to handle the signal.
6413@code{SIGINT} does not indicate an error in your program, but it is normally
6414fatal so it can carry out the purpose of the interrupt: to kill the program.
6415
6416@value{GDBN} has the ability to detect any occurrence of a signal in your
6417program. You can tell @value{GDBN} in advance what to do for each kind of
6418signal.
6419
6420@cindex handling signals
24f93129
EZ
6421Normally, @value{GDBN} is set up to let the non-erroneous signals like
6422@code{SIGALRM} be silently passed to your program
6423(so as not to interfere with their role in the program's functioning)
c906108c
SS
6424but to stop your program immediately whenever an error signal happens.
6425You can change these settings with the @code{handle} command.
6426
6427@table @code
6428@kindex info signals
09d4efe1 6429@kindex info handle
c906108c 6430@item info signals
96a2c332 6431@itemx info handle
c906108c
SS
6432Print a table of all the kinds of signals and how @value{GDBN} has been told to
6433handle each one. You can use this to see the signal numbers of all
6434the defined types of signals.
6435
45ac1734
EZ
6436@item info signals @var{sig}
6437Similar, but print information only about the specified signal number.
6438
d4f3574e 6439@code{info handle} is an alias for @code{info signals}.
c906108c 6440
ab04a2af
TT
6441@item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6442Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
6443for details about this command.
6444
c906108c 6445@kindex handle
45ac1734 6446@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
697aa1b7 6447Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
5ece1a18 6448can be the number of a signal or its name (with or without the
24f93129 6449@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 6450@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
6451known signals. Optional arguments @var{keywords}, described below,
6452say what change to make.
c906108c
SS
6453@end table
6454
6455@c @group
6456The keywords allowed by the @code{handle} command can be abbreviated.
6457Their full names are:
6458
6459@table @code
6460@item nostop
6461@value{GDBN} should not stop your program when this signal happens. It may
6462still print a message telling you that the signal has come in.
6463
6464@item stop
6465@value{GDBN} should stop your program when this signal happens. This implies
6466the @code{print} keyword as well.
6467
6468@item print
6469@value{GDBN} should print a message when this signal happens.
6470
6471@item noprint
6472@value{GDBN} should not mention the occurrence of the signal at all. This
6473implies the @code{nostop} keyword as well.
6474
6475@item pass
5ece1a18 6476@itemx noignore
c906108c
SS
6477@value{GDBN} should allow your program to see this signal; your program
6478can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 6479and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
6480
6481@item nopass
5ece1a18 6482@itemx ignore
c906108c 6483@value{GDBN} should not allow your program to see this signal.
5ece1a18 6484@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
6485@end table
6486@c @end group
6487
d4f3574e
SS
6488When a signal stops your program, the signal is not visible to the
6489program until you
c906108c
SS
6490continue. Your program sees the signal then, if @code{pass} is in
6491effect for the signal in question @emph{at that time}. In other words,
6492after @value{GDBN} reports a signal, you can use the @code{handle}
6493command with @code{pass} or @code{nopass} to control whether your
6494program sees that signal when you continue.
6495
24f93129
EZ
6496The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6497non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6498@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6499erroneous signals.
6500
c906108c
SS
6501You can also use the @code{signal} command to prevent your program from
6502seeing a signal, or cause it to see a signal it normally would not see,
6503or to give it any signal at any time. For example, if your program stopped
6504due to some sort of memory reference error, you might store correct
6505values into the erroneous variables and continue, hoping to see more
6506execution; but your program would probably terminate immediately as
6507a result of the fatal signal once it saw the signal. To prevent this,
6508you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
79a6e687 6509Program a Signal}.
c906108c 6510
e5f8a7cc
PA
6511@cindex stepping and signal handlers
6512@anchor{stepping and signal handlers}
6513
6514@value{GDBN} optimizes for stepping the mainline code. If a signal
6515that has @code{handle nostop} and @code{handle pass} set arrives while
6516a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6517in progress, @value{GDBN} lets the signal handler run and then resumes
6518stepping the mainline code once the signal handler returns. In other
6519words, @value{GDBN} steps over the signal handler. This prevents
6520signals that you've specified as not interesting (with @code{handle
6521nostop}) from changing the focus of debugging unexpectedly. Note that
6522the signal handler itself may still hit a breakpoint, stop for another
6523signal that has @code{handle stop} in effect, or for any other event
6524that normally results in stopping the stepping command sooner. Also
6525note that @value{GDBN} still informs you that the program received a
6526signal if @code{handle print} is set.
6527
6528@anchor{stepping into signal handlers}
6529
6530If you set @code{handle pass} for a signal, and your program sets up a
6531handler for it, then issuing a stepping command, such as @code{step}
6532or @code{stepi}, when your program is stopped due to the signal will
6533step @emph{into} the signal handler (if the target supports that).
6534
6535Likewise, if you use the @code{queue-signal} command to queue a signal
6536to be delivered to the current thread when execution of the thread
6537resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6538stepping command will step into the signal handler.
6539
6540Here's an example, using @code{stepi} to step to the first instruction
6541of @code{SIGUSR1}'s handler:
6542
6543@smallexample
6544(@value{GDBP}) handle SIGUSR1
6545Signal Stop Print Pass to program Description
6546SIGUSR1 Yes Yes Yes User defined signal 1
6547(@value{GDBP}) c
6548Continuing.
6549
6550Program received signal SIGUSR1, User defined signal 1.
6551main () sigusr1.c:28
655228 p = 0;
6553(@value{GDBP}) si
6554sigusr1_handler () at sigusr1.c:9
65559 @{
6556@end smallexample
6557
6558The same, but using @code{queue-signal} instead of waiting for the
6559program to receive the signal first:
6560
6561@smallexample
6562(@value{GDBP}) n
656328 p = 0;
6564(@value{GDBP}) queue-signal SIGUSR1
6565(@value{GDBP}) si
6566sigusr1_handler () at sigusr1.c:9
65679 @{
6568(@value{GDBP})
6569@end smallexample
6570
4aa995e1
PA
6571@cindex extra signal information
6572@anchor{extra signal information}
6573
6574On some targets, @value{GDBN} can inspect extra signal information
6575associated with the intercepted signal, before it is actually
6576delivered to the program being debugged. This information is exported
6577by the convenience variable @code{$_siginfo}, and consists of data
6578that is passed by the kernel to the signal handler at the time of the
6579receipt of a signal. The data type of the information itself is
6580target dependent. You can see the data type using the @code{ptype
6581$_siginfo} command. On Unix systems, it typically corresponds to the
6582standard @code{siginfo_t} type, as defined in the @file{signal.h}
6583system header.
6584
6585Here's an example, on a @sc{gnu}/Linux system, printing the stray
6586referenced address that raised a segmentation fault.
6587
6588@smallexample
6589@group
6590(@value{GDBP}) continue
6591Program received signal SIGSEGV, Segmentation fault.
65920x0000000000400766 in main ()
659369 *(int *)p = 0;
6594(@value{GDBP}) ptype $_siginfo
6595type = struct @{
6596 int si_signo;
6597 int si_errno;
6598 int si_code;
6599 union @{
6600 int _pad[28];
6601 struct @{...@} _kill;
6602 struct @{...@} _timer;
6603 struct @{...@} _rt;
6604 struct @{...@} _sigchld;
6605 struct @{...@} _sigfault;
6606 struct @{...@} _sigpoll;
6607 @} _sifields;
6608@}
6609(@value{GDBP}) ptype $_siginfo._sifields._sigfault
6610type = struct @{
6611 void *si_addr;
6612@}
6613(@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6614$1 = (void *) 0x7ffff7ff7000
6615@end group
6616@end smallexample
6617
6618Depending on target support, @code{$_siginfo} may also be writable.
6619
012b3a21
WT
6620@cindex Intel MPX boundary violations
6621@cindex boundary violations, Intel MPX
6622On some targets, a @code{SIGSEGV} can be caused by a boundary
6623violation, i.e., accessing an address outside of the allowed range.
6624In those cases @value{GDBN} may displays additional information,
6625depending on how @value{GDBN} has been told to handle the signal.
6626With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6627kind: "Upper" or "Lower", the memory address accessed and the
6628bounds, while with @code{handle nostop SIGSEGV} no additional
6629information is displayed.
6630
6631The usual output of a segfault is:
6632@smallexample
6633Program received signal SIGSEGV, Segmentation fault
66340x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
663568 value = *(p + len);
6636@end smallexample
6637
6638While a bound violation is presented as:
6639@smallexample
6640Program received signal SIGSEGV, Segmentation fault
6641Upper bound violation while accessing address 0x7fffffffc3b3
6642Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
66430x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
664468 value = *(p + len);
6645@end smallexample
6646
6d2ebf8b 6647@node Thread Stops
79a6e687 6648@section Stopping and Starting Multi-thread Programs
c906108c 6649
0606b73b
SL
6650@cindex stopped threads
6651@cindex threads, stopped
6652
6653@cindex continuing threads
6654@cindex threads, continuing
6655
6656@value{GDBN} supports debugging programs with multiple threads
6657(@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6658are two modes of controlling execution of your program within the
6659debugger. In the default mode, referred to as @dfn{all-stop mode},
6660when any thread in your program stops (for example, at a breakpoint
6661or while being stepped), all other threads in the program are also stopped by
6662@value{GDBN}. On some targets, @value{GDBN} also supports
6663@dfn{non-stop mode}, in which other threads can continue to run freely while
6664you examine the stopped thread in the debugger.
6665
6666@menu
6667* All-Stop Mode:: All threads stop when GDB takes control
6668* Non-Stop Mode:: Other threads continue to execute
6669* Background Execution:: Running your program asynchronously
6670* Thread-Specific Breakpoints:: Controlling breakpoints
6671* Interrupted System Calls:: GDB may interfere with system calls
d914c394 6672* Observer Mode:: GDB does not alter program behavior
0606b73b
SL
6673@end menu
6674
6675@node All-Stop Mode
6676@subsection All-Stop Mode
6677
6678@cindex all-stop mode
6679
6680In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6681@emph{all} threads of execution stop, not just the current thread. This
6682allows you to examine the overall state of the program, including
6683switching between threads, without worrying that things may change
6684underfoot.
6685
6686Conversely, whenever you restart the program, @emph{all} threads start
6687executing. @emph{This is true even when single-stepping} with commands
6688like @code{step} or @code{next}.
6689
6690In particular, @value{GDBN} cannot single-step all threads in lockstep.
6691Since thread scheduling is up to your debugging target's operating
6692system (not controlled by @value{GDBN}), other threads may
6693execute more than one statement while the current thread completes a
6694single step. Moreover, in general other threads stop in the middle of a
6695statement, rather than at a clean statement boundary, when the program
6696stops.
6697
6698You might even find your program stopped in another thread after
6699continuing or even single-stepping. This happens whenever some other
6700thread runs into a breakpoint, a signal, or an exception before the
6701first thread completes whatever you requested.
6702
6703@cindex automatic thread selection
6704@cindex switching threads automatically
6705@cindex threads, automatic switching
6706Whenever @value{GDBN} stops your program, due to a breakpoint or a
6707signal, it automatically selects the thread where that breakpoint or
6708signal happened. @value{GDBN} alerts you to the context switch with a
6709message such as @samp{[Switching to Thread @var{n}]} to identify the
6710thread.
6711
6712On some OSes, you can modify @value{GDBN}'s default behavior by
6713locking the OS scheduler to allow only a single thread to run.
6714
6715@table @code
6716@item set scheduler-locking @var{mode}
6717@cindex scheduler locking mode
6718@cindex lock scheduler
f2665db5
MM
6719Set the scheduler locking mode. It applies to normal execution,
6720record mode, and replay mode. If it is @code{off}, then there is no
6721locking and any thread may run at any time. If @code{on}, then only
6722the current thread may run when the inferior is resumed. The
6723@code{step} mode optimizes for single-stepping; it prevents other
6724threads from preempting the current thread while you are stepping, so
6725that the focus of debugging does not change unexpectedly. Other
6726threads never get a chance to run when you step, and they are
6727completely free to run when you use commands like @samp{continue},
6728@samp{until}, or @samp{finish}. However, unless another thread hits a
6729breakpoint during its timeslice, @value{GDBN} does not change the
6730current thread away from the thread that you are debugging. The
6731@code{replay} mode behaves like @code{off} in record mode and like
6732@code{on} in replay mode.
0606b73b
SL
6733
6734@item show scheduler-locking
6735Display the current scheduler locking mode.
6736@end table
6737
d4db2f36
PA
6738@cindex resume threads of multiple processes simultaneously
6739By default, when you issue one of the execution commands such as
6740@code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6741threads of the current inferior to run. For example, if @value{GDBN}
6742is attached to two inferiors, each with two threads, the
6743@code{continue} command resumes only the two threads of the current
6744inferior. This is useful, for example, when you debug a program that
6745forks and you want to hold the parent stopped (so that, for instance,
6746it doesn't run to exit), while you debug the child. In other
6747situations, you may not be interested in inspecting the current state
6748of any of the processes @value{GDBN} is attached to, and you may want
6749to resume them all until some breakpoint is hit. In the latter case,
6750you can instruct @value{GDBN} to allow all threads of all the
6751inferiors to run with the @w{@code{set schedule-multiple}} command.
6752
6753@table @code
6754@kindex set schedule-multiple
6755@item set schedule-multiple
6756Set the mode for allowing threads of multiple processes to be resumed
6757when an execution command is issued. When @code{on}, all threads of
6758all processes are allowed to run. When @code{off}, only the threads
6759of the current process are resumed. The default is @code{off}. The
6760@code{scheduler-locking} mode takes precedence when set to @code{on},
6761or while you are stepping and set to @code{step}.
6762
6763@item show schedule-multiple
6764Display the current mode for resuming the execution of threads of
6765multiple processes.
6766@end table
6767
0606b73b
SL
6768@node Non-Stop Mode
6769@subsection Non-Stop Mode
6770
6771@cindex non-stop mode
6772
6773@c This section is really only a place-holder, and needs to be expanded
97d8f0ee 6774@c with more details.
0606b73b
SL
6775
6776For some multi-threaded targets, @value{GDBN} supports an optional
6777mode of operation in which you can examine stopped program threads in
6778the debugger while other threads continue to execute freely. This
97d8f0ee
DE
6779minimizes intrusion when debugging live systems, such as programs
6780where some threads have real-time constraints or must continue to
0606b73b
SL
6781respond to external events. This is referred to as @dfn{non-stop} mode.
6782
6783In non-stop mode, when a thread stops to report a debugging event,
6784@emph{only} that thread is stopped; @value{GDBN} does not stop other
6785threads as well, in contrast to the all-stop mode behavior. Additionally,
6786execution commands such as @code{continue} and @code{step} apply by default
6787only to the current thread in non-stop mode, rather than all threads as
6788in all-stop mode. This allows you to control threads explicitly in
97d8f0ee 6789ways that are not possible in all-stop mode --- for example, stepping
0606b73b 6790one thread while allowing others to run freely, stepping
97d8f0ee 6791one thread while holding all others stopped, or stepping several threads
0606b73b
SL
6792independently and simultaneously.
6793
6794To enter non-stop mode, use this sequence of commands before you run
6795or attach to your program:
6796
0606b73b 6797@smallexample
0606b73b
SL
6798# If using the CLI, pagination breaks non-stop.
6799set pagination off
6800
6801# Finally, turn it on!
6802set non-stop on
6803@end smallexample
6804
6805You can use these commands to manipulate the non-stop mode setting:
6806
6807@table @code
6808@kindex set non-stop
6809@item set non-stop on
6810Enable selection of non-stop mode.
6811@item set non-stop off
6812Disable selection of non-stop mode.
6813@kindex show non-stop
6814@item show non-stop
6815Show the current non-stop enablement setting.
6816@end table
6817
6818Note these commands only reflect whether non-stop mode is enabled,
97d8f0ee 6819not whether the currently-executing program is being run in non-stop mode.
0606b73b 6820In particular, the @code{set non-stop} preference is only consulted when
97d8f0ee 6821@value{GDBN} starts or connects to the target program, and it is generally
0606b73b
SL
6822not possible to switch modes once debugging has started. Furthermore,
6823since not all targets support non-stop mode, even when you have enabled
6824non-stop mode, @value{GDBN} may still fall back to all-stop operation by
6825default.
6826
6827In non-stop mode, all execution commands apply only to the current thread
97d8f0ee 6828by default. That is, @code{continue} only continues one thread.
0606b73b
SL
6829To continue all threads, issue @code{continue -a} or @code{c -a}.
6830
97d8f0ee 6831You can use @value{GDBN}'s background execution commands
0606b73b 6832(@pxref{Background Execution}) to run some threads in the background
97d8f0ee 6833while you continue to examine or step others from @value{GDBN}.
0606b73b
SL
6834The MI execution commands (@pxref{GDB/MI Program Execution}) are
6835always executed asynchronously in non-stop mode.
6836
6837Suspending execution is done with the @code{interrupt} command when
97d8f0ee
DE
6838running in the background, or @kbd{Ctrl-c} during foreground execution.
6839In all-stop mode, this stops the whole process;
6840but in non-stop mode the interrupt applies only to the current thread.
0606b73b
SL
6841To stop the whole program, use @code{interrupt -a}.
6842
6843Other execution commands do not currently support the @code{-a} option.
6844
6845In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
6846that thread current, as it does in all-stop mode. This is because the
97d8f0ee 6847thread stop notifications are asynchronous with respect to @value{GDBN}'s
0606b73b
SL
6848command interpreter, and it would be confusing if @value{GDBN} unexpectedly
6849changed to a different thread just as you entered a command to operate on the
6850previously current thread.
6851
6852@node Background Execution
6853@subsection Background Execution
6854
6855@cindex foreground execution
6856@cindex background execution
6857@cindex asynchronous execution
6858@cindex execution, foreground, background and asynchronous
6859
6860@value{GDBN}'s execution commands have two variants: the normal
6861foreground (synchronous) behavior, and a background
97d8f0ee 6862(asynchronous) behavior. In foreground execution, @value{GDBN} waits for
0606b73b
SL
6863the program to report that some thread has stopped before prompting for
6864another command. In background execution, @value{GDBN} immediately gives
6865a command prompt so that you can issue other commands while your program runs.
6866
32fc0df9
PA
6867If the target doesn't support async mode, @value{GDBN} issues an error
6868message if you attempt to use the background execution commands.
6869
74fdb8ff 6870@cindex @code{&}, background execution of commands
0606b73b
SL
6871To specify background execution, add a @code{&} to the command. For example,
6872the background form of the @code{continue} command is @code{continue&}, or
6873just @code{c&}. The execution commands that accept background execution
6874are:
6875
6876@table @code
6877@kindex run&
6878@item run
6879@xref{Starting, , Starting your Program}.
6880
6881@item attach
6882@kindex attach&
6883@xref{Attach, , Debugging an Already-running Process}.
6884
6885@item step
6886@kindex step&
6887@xref{Continuing and Stepping, step}.
6888
6889@item stepi
6890@kindex stepi&
6891@xref{Continuing and Stepping, stepi}.
6892
6893@item next
6894@kindex next&
6895@xref{Continuing and Stepping, next}.
6896
7ce58dd2
DE
6897@item nexti
6898@kindex nexti&
6899@xref{Continuing and Stepping, nexti}.
6900
0606b73b
SL
6901@item continue
6902@kindex continue&
6903@xref{Continuing and Stepping, continue}.
6904
6905@item finish
6906@kindex finish&
6907@xref{Continuing and Stepping, finish}.
6908
6909@item until
6910@kindex until&
6911@xref{Continuing and Stepping, until}.
6912
6913@end table
6914
6915Background execution is especially useful in conjunction with non-stop
6916mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
6917However, you can also use these commands in the normal all-stop mode with
6918the restriction that you cannot issue another execution command until the
6919previous one finishes. Examples of commands that are valid in all-stop
6920mode while the program is running include @code{help} and @code{info break}.
6921
6922You can interrupt your program while it is running in the background by
6923using the @code{interrupt} command.
6924
6925@table @code
6926@kindex interrupt
6927@item interrupt
6928@itemx interrupt -a
6929
97d8f0ee 6930Suspend execution of the running program. In all-stop mode,
0606b73b 6931@code{interrupt} stops the whole process, but in non-stop mode, it stops
97d8f0ee 6932only the current thread. To stop the whole program in non-stop mode,
0606b73b
SL
6933use @code{interrupt -a}.
6934@end table
6935
0606b73b
SL
6936@node Thread-Specific Breakpoints
6937@subsection Thread-Specific Breakpoints
6938
c906108c 6939When your program has multiple threads (@pxref{Threads,, Debugging
79a6e687 6940Programs with Multiple Threads}), you can choose whether to set
c906108c
SS
6941breakpoints on all threads, or on a particular thread.
6942
6943@table @code
6944@cindex breakpoints and threads
6945@cindex thread breakpoints
5d5658a1
PA
6946@kindex break @dots{} thread @var{thread-id}
6947@item break @var{location} thread @var{thread-id}
6948@itemx break @var{location} thread @var{thread-id} if @dots{}
629500fa 6949@var{location} specifies source lines; there are several ways of
2a25a5ba
EZ
6950writing them (@pxref{Specify Location}), but the effect is always to
6951specify some source line.
c906108c 6952
5d5658a1 6953Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
c906108c 6954to specify that you only want @value{GDBN} to stop the program when a
5d5658a1
PA
6955particular thread reaches this breakpoint. The @var{thread-id} specifier
6956is one of the thread identifiers assigned by @value{GDBN}, shown
697aa1b7 6957in the first column of the @samp{info threads} display.
c906108c 6958
5d5658a1 6959If you do not specify @samp{thread @var{thread-id}} when you set a
c906108c
SS
6960breakpoint, the breakpoint applies to @emph{all} threads of your
6961program.
6962
6963You can use the @code{thread} qualifier on conditional breakpoints as
5d5658a1 6964well; in this case, place @samp{thread @var{thread-id}} before or
b6199126 6965after the breakpoint condition, like this:
c906108c
SS
6966
6967@smallexample
2df3850c 6968(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
6969@end smallexample
6970
6971@end table
6972
f4fb82a1
PA
6973Thread-specific breakpoints are automatically deleted when
6974@value{GDBN} detects the corresponding thread is no longer in the
6975thread list. For example:
6976
6977@smallexample
6978(@value{GDBP}) c
6979Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
6980@end smallexample
6981
6982There are several ways for a thread to disappear, such as a regular
6983thread exit, but also when you detach from the process with the
6984@code{detach} command (@pxref{Attach, ,Debugging an Already-running
6985Process}), or if @value{GDBN} loses the remote connection
6986(@pxref{Remote Debugging}), etc. Note that with some targets,
6987@value{GDBN} is only able to detect a thread has exited when the user
6988explictly asks for the thread list with the @code{info threads}
6989command.
6990
0606b73b
SL
6991@node Interrupted System Calls
6992@subsection Interrupted System Calls
c906108c 6993
36d86913
MC
6994@cindex thread breakpoints and system calls
6995@cindex system calls and thread breakpoints
6996@cindex premature return from system calls
0606b73b
SL
6997There is an unfortunate side effect when using @value{GDBN} to debug
6998multi-threaded programs. If one thread stops for a
36d86913
MC
6999breakpoint, or for some other reason, and another thread is blocked in a
7000system call, then the system call may return prematurely. This is a
7001consequence of the interaction between multiple threads and the signals
7002that @value{GDBN} uses to implement breakpoints and other events that
7003stop execution.
7004
7005To handle this problem, your program should check the return value of
7006each system call and react appropriately. This is good programming
7007style anyways.
7008
7009For example, do not write code like this:
7010
7011@smallexample
7012 sleep (10);
7013@end smallexample
7014
7015The call to @code{sleep} will return early if a different thread stops
7016at a breakpoint or for some other reason.
7017
7018Instead, write this:
7019
7020@smallexample
7021 int unslept = 10;
7022 while (unslept > 0)
7023 unslept = sleep (unslept);
7024@end smallexample
7025
7026A system call is allowed to return early, so the system is still
7027conforming to its specification. But @value{GDBN} does cause your
7028multi-threaded program to behave differently than it would without
7029@value{GDBN}.
7030
7031Also, @value{GDBN} uses internal breakpoints in the thread library to
7032monitor certain events such as thread creation and thread destruction.
7033When such an event happens, a system call in another thread may return
7034prematurely, even though your program does not appear to stop.
7035
d914c394
SS
7036@node Observer Mode
7037@subsection Observer Mode
7038
7039If you want to build on non-stop mode and observe program behavior
7040without any chance of disruption by @value{GDBN}, you can set
7041variables to disable all of the debugger's attempts to modify state,
7042whether by writing memory, inserting breakpoints, etc. These operate
7043at a low level, intercepting operations from all commands.
7044
7045When all of these are set to @code{off}, then @value{GDBN} is said to
7046be @dfn{observer mode}. As a convenience, the variable
7047@code{observer} can be set to disable these, plus enable non-stop
7048mode.
7049
7050Note that @value{GDBN} will not prevent you from making nonsensical
7051combinations of these settings. For instance, if you have enabled
7052@code{may-insert-breakpoints} but disabled @code{may-write-memory},
7053then breakpoints that work by writing trap instructions into the code
7054stream will still not be able to be placed.
7055
7056@table @code
7057
7058@kindex observer
7059@item set observer on
7060@itemx set observer off
7061When set to @code{on}, this disables all the permission variables
7062below (except for @code{insert-fast-tracepoints}), plus enables
7063non-stop debugging. Setting this to @code{off} switches back to
7064normal debugging, though remaining in non-stop mode.
7065
7066@item show observer
7067Show whether observer mode is on or off.
7068
7069@kindex may-write-registers
7070@item set may-write-registers on
7071@itemx set may-write-registers off
7072This controls whether @value{GDBN} will attempt to alter the values of
7073registers, such as with assignment expressions in @code{print}, or the
7074@code{jump} command. It defaults to @code{on}.
7075
7076@item show may-write-registers
7077Show the current permission to write registers.
7078
7079@kindex may-write-memory
7080@item set may-write-memory on
7081@itemx set may-write-memory off
7082This controls whether @value{GDBN} will attempt to alter the contents
7083of memory, such as with assignment expressions in @code{print}. It
7084defaults to @code{on}.
7085
7086@item show may-write-memory
7087Show the current permission to write memory.
7088
7089@kindex may-insert-breakpoints
7090@item set may-insert-breakpoints on
7091@itemx set may-insert-breakpoints off
7092This controls whether @value{GDBN} will attempt to insert breakpoints.
7093This affects all breakpoints, including internal breakpoints defined
7094by @value{GDBN}. It defaults to @code{on}.
7095
7096@item show may-insert-breakpoints
7097Show the current permission to insert breakpoints.
7098
7099@kindex may-insert-tracepoints
7100@item set may-insert-tracepoints on
7101@itemx set may-insert-tracepoints off
7102This controls whether @value{GDBN} will attempt to insert (regular)
7103tracepoints at the beginning of a tracing experiment. It affects only
7104non-fast tracepoints, fast tracepoints being under the control of
7105@code{may-insert-fast-tracepoints}. It defaults to @code{on}.
7106
7107@item show may-insert-tracepoints
7108Show the current permission to insert tracepoints.
7109
7110@kindex may-insert-fast-tracepoints
7111@item set may-insert-fast-tracepoints on
7112@itemx set may-insert-fast-tracepoints off
7113This controls whether @value{GDBN} will attempt to insert fast
7114tracepoints at the beginning of a tracing experiment. It affects only
7115fast tracepoints, regular (non-fast) tracepoints being under the
7116control of @code{may-insert-tracepoints}. It defaults to @code{on}.
7117
7118@item show may-insert-fast-tracepoints
7119Show the current permission to insert fast tracepoints.
7120
7121@kindex may-interrupt
7122@item set may-interrupt on
7123@itemx set may-interrupt off
7124This controls whether @value{GDBN} will attempt to interrupt or stop
7125program execution. When this variable is @code{off}, the
7126@code{interrupt} command will have no effect, nor will
7127@kbd{Ctrl-c}. It defaults to @code{on}.
7128
7129@item show may-interrupt
7130Show the current permission to interrupt or stop the program.
7131
7132@end table
c906108c 7133
bacec72f
MS
7134@node Reverse Execution
7135@chapter Running programs backward
7136@cindex reverse execution
7137@cindex running programs backward
7138
7139When you are debugging a program, it is not unusual to realize that
7140you have gone too far, and some event of interest has already happened.
7141If the target environment supports it, @value{GDBN} can allow you to
7142``rewind'' the program by running it backward.
7143
7144A target environment that supports reverse execution should be able
7145to ``undo'' the changes in machine state that have taken place as the
7146program was executing normally. Variables, registers etc.@: should
7147revert to their previous values. Obviously this requires a great
7148deal of sophistication on the part of the target environment; not
7149all target environments can support reverse execution.
7150
7151When a program is executed in reverse, the instructions that
7152have most recently been executed are ``un-executed'', in reverse
7153order. The program counter runs backward, following the previous
7154thread of execution in reverse. As each instruction is ``un-executed'',
7155the values of memory and/or registers that were changed by that
7156instruction are reverted to their previous states. After executing
7157a piece of source code in reverse, all side effects of that code
7158should be ``undone'', and all variables should be returned to their
7159prior values@footnote{
7160Note that some side effects are easier to undo than others. For instance,
7161memory and registers are relatively easy, but device I/O is hard. Some
7162targets may be able undo things like device I/O, and some may not.
7163
7164The contract between @value{GDBN} and the reverse executing target
7165requires only that the target do something reasonable when
7166@value{GDBN} tells it to execute backwards, and then report the
7167results back to @value{GDBN}. Whatever the target reports back to
7168@value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
7169assumes that the memory and registers that the target reports are in a
6b92c0d3 7170consistent state, but @value{GDBN} accepts whatever it is given.
bacec72f
MS
7171}.
7172
73f8a590
PA
7173On some platforms, @value{GDBN} has built-in support for reverse
7174execution, activated with the @code{record} or @code{record btrace}
7175commands. @xref{Process Record and Replay}. Some remote targets,
7176typically full system emulators, support reverse execution directly
7177without requiring any special command.
7178
bacec72f
MS
7179If you are debugging in a target environment that supports
7180reverse execution, @value{GDBN} provides the following commands.
7181
7182@table @code
7183@kindex reverse-continue
7184@kindex rc @r{(@code{reverse-continue})}
7185@item reverse-continue @r{[}@var{ignore-count}@r{]}
7186@itemx rc @r{[}@var{ignore-count}@r{]}
7187Beginning at the point where your program last stopped, start executing
7188in reverse. Reverse execution will stop for breakpoints and synchronous
7189exceptions (signals), just like normal execution. Behavior of
7190asynchronous signals depends on the target environment.
7191
7192@kindex reverse-step
7193@kindex rs @r{(@code{step})}
7194@item reverse-step @r{[}@var{count}@r{]}
7195Run the program backward until control reaches the start of a
7196different source line; then stop it, and return control to @value{GDBN}.
7197
7198Like the @code{step} command, @code{reverse-step} will only stop
7199at the beginning of a source line. It ``un-executes'' the previously
7200executed source line. If the previous source line included calls to
7201debuggable functions, @code{reverse-step} will step (backward) into
7202the called function, stopping at the beginning of the @emph{last}
7203statement in the called function (typically a return statement).
7204
7205Also, as with the @code{step} command, if non-debuggable functions are
7206called, @code{reverse-step} will run thru them backward without stopping.
7207
7208@kindex reverse-stepi
7209@kindex rsi @r{(@code{reverse-stepi})}
7210@item reverse-stepi @r{[}@var{count}@r{]}
7211Reverse-execute one machine instruction. Note that the instruction
7212to be reverse-executed is @emph{not} the one pointed to by the program
7213counter, but the instruction executed prior to that one. For instance,
7214if the last instruction was a jump, @code{reverse-stepi} will take you
7215back from the destination of the jump to the jump instruction itself.
7216
7217@kindex reverse-next
7218@kindex rn @r{(@code{reverse-next})}
7219@item reverse-next @r{[}@var{count}@r{]}
7220Run backward to the beginning of the previous line executed in
7221the current (innermost) stack frame. If the line contains function
7222calls, they will be ``un-executed'' without stopping. Starting from
7223the first line of a function, @code{reverse-next} will take you back
7224to the caller of that function, @emph{before} the function was called,
7225just as the normal @code{next} command would take you from the last
7226line of a function back to its return to its caller
16af530a 7227@footnote{Unless the code is too heavily optimized.}.
bacec72f
MS
7228
7229@kindex reverse-nexti
7230@kindex rni @r{(@code{reverse-nexti})}
7231@item reverse-nexti @r{[}@var{count}@r{]}
7232Like @code{nexti}, @code{reverse-nexti} executes a single instruction
7233in reverse, except that called functions are ``un-executed'' atomically.
7234That is, if the previously executed instruction was a return from
540aa8e7 7235another function, @code{reverse-nexti} will continue to execute
bacec72f
MS
7236in reverse until the call to that function (from the current stack
7237frame) is reached.
7238
7239@kindex reverse-finish
7240@item reverse-finish
7241Just as the @code{finish} command takes you to the point where the
7242current function returns, @code{reverse-finish} takes you to the point
7243where it was called. Instead of ending up at the end of the current
7244function invocation, you end up at the beginning.
7245
7246@kindex set exec-direction
7247@item set exec-direction
7248Set the direction of target execution.
984359d2 7249@item set exec-direction reverse
bacec72f
MS
7250@cindex execute forward or backward in time
7251@value{GDBN} will perform all execution commands in reverse, until the
7252exec-direction mode is changed to ``forward''. Affected commands include
7253@code{step, stepi, next, nexti, continue, and finish}. The @code{return}
7254command cannot be used in reverse mode.
7255@item set exec-direction forward
7256@value{GDBN} will perform all execution commands in the normal fashion.
7257This is the default.
7258@end table
7259
c906108c 7260
a2311334
EZ
7261@node Process Record and Replay
7262@chapter Recording Inferior's Execution and Replaying It
53cc454a
HZ
7263@cindex process record and replay
7264@cindex recording inferior's execution and replaying it
7265
8e05493c
EZ
7266On some platforms, @value{GDBN} provides a special @dfn{process record
7267and replay} target that can record a log of the process execution, and
7268replay it later with both forward and reverse execution commands.
a2311334
EZ
7269
7270@cindex replay mode
7271When this target is in use, if the execution log includes the record
7272for the next instruction, @value{GDBN} will debug in @dfn{replay
7273mode}. In the replay mode, the inferior does not really execute code
7274instructions. Instead, all the events that normally happen during
7275code execution are taken from the execution log. While code is not
7276really executed in replay mode, the values of registers (including the
7277program counter register) and the memory of the inferior are still
8e05493c
EZ
7278changed as they normally would. Their contents are taken from the
7279execution log.
a2311334
EZ
7280
7281@cindex record mode
7282If the record for the next instruction is not in the execution log,
7283@value{GDBN} will debug in @dfn{record mode}. In this mode, the
7284inferior executes normally, and @value{GDBN} records the execution log
7285for future replay.
7286
8e05493c
EZ
7287The process record and replay target supports reverse execution
7288(@pxref{Reverse Execution}), even if the platform on which the
7289inferior runs does not. However, the reverse execution is limited in
7290this case by the range of the instructions recorded in the execution
7291log. In other words, reverse execution on platforms that don't
7292support it directly can only be done in the replay mode.
7293
7294When debugging in the reverse direction, @value{GDBN} will work in
7295replay mode as long as the execution log includes the record for the
7296previous instruction; otherwise, it will work in record mode, if the
7297platform supports reverse execution, or stop if not.
7298
73f8a590
PA
7299Currently, process record and replay is supported on ARM, Aarch64,
7300Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
7301GNU/Linux. Process record and replay can be used both when native
7302debugging, and when remote debugging via @code{gdbserver}.
7303
a2311334
EZ
7304For architecture environments that support process record and replay,
7305@value{GDBN} provides the following commands:
53cc454a
HZ
7306
7307@table @code
7308@kindex target record
59ea5688
MM
7309@kindex target record-full
7310@kindex target record-btrace
53cc454a 7311@kindex record
59ea5688
MM
7312@kindex record full
7313@kindex record btrace
f4abbc16 7314@kindex record btrace bts
b20a6524 7315@kindex record btrace pt
f4abbc16 7316@kindex record bts
b20a6524 7317@kindex record pt
53cc454a 7318@kindex rec
59ea5688
MM
7319@kindex rec full
7320@kindex rec btrace
f4abbc16 7321@kindex rec btrace bts
b20a6524 7322@kindex rec btrace pt
f4abbc16 7323@kindex rec bts
b20a6524 7324@kindex rec pt
59ea5688
MM
7325@item record @var{method}
7326This command starts the process record and replay target. The
7327recording method can be specified as parameter. Without a parameter
7328the command uses the @code{full} recording method. The following
7329recording methods are available:
a2311334 7330
59ea5688
MM
7331@table @code
7332@item full
7333Full record/replay recording using @value{GDBN}'s software record and
7334replay implementation. This method allows replaying and reverse
7335execution.
7336
f4abbc16 7337@item btrace @var{format}
73f8a590
PA
7338Hardware-supported instruction recording, supported on Intel
7339processors. This method does not record data. Further, the data is
7340collected in a ring buffer so old data will be overwritten when the
7341buffer is full. It allows limited reverse execution. Variables and
7342registers are not available during reverse execution. In remote
7343debugging, recording continues on disconnect. Recorded data can be
7344inspected after reconnecting. The recording may be stopped using
7345@code{record stop}.
59ea5688 7346
f4abbc16
MM
7347The recording format can be specified as parameter. Without a parameter
7348the command chooses the recording format. The following recording
7349formats are available:
7350
7351@table @code
7352@item bts
7353@cindex branch trace store
7354Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
7355this format, the processor stores a from/to record for each executed
7356branch in the btrace ring buffer.
b20a6524
MM
7357
7358@item pt
bc504a31
PA
7359@cindex Intel Processor Trace
7360Use the @dfn{Intel Processor Trace} recording format. In this
b20a6524
MM
7361format, the processor stores the execution trace in a compressed form
7362that is afterwards decoded by @value{GDBN}.
7363
7364The trace can be recorded with very low overhead. The compressed
7365trace format also allows small trace buffers to already contain a big
7366number of instructions compared to @acronym{BTS}.
7367
7368Decoding the recorded execution trace, on the other hand, is more
7369expensive than decoding @acronym{BTS} trace. This is mostly due to the
7370increased number of instructions to process. You should increase the
7371buffer-size with care.
f4abbc16
MM
7372@end table
7373
7374Not all recording formats may be available on all processors.
59ea5688
MM
7375@end table
7376
7377The process record and replay target can only debug a process that is
7378already running. Therefore, you need first to start the process with
7379the @kbd{run} or @kbd{start} commands, and then start the recording
7380with the @kbd{record @var{method}} command.
7381
a2311334
EZ
7382@cindex displaced stepping, and process record and replay
7383Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7384will be automatically disabled when process record and replay target
7385is started. That's because the process record and replay target
7386doesn't support displaced stepping.
7387
7388@cindex non-stop mode, and process record and replay
7389@cindex asynchronous execution, and process record and replay
7390If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
59ea5688
MM
7391the asynchronous execution mode (@pxref{Background Execution}), not
7392all recording methods are available. The @code{full} recording method
7393does not support these two modes.
53cc454a
HZ
7394
7395@kindex record stop
7396@kindex rec s
7397@item record stop
a2311334
EZ
7398Stop the process record and replay target. When process record and
7399replay target stops, the entire execution log will be deleted and the
7400inferior will either be terminated, or will remain in its final state.
53cc454a 7401
a2311334
EZ
7402When you stop the process record and replay target in record mode (at
7403the end of the execution log), the inferior will be stopped at the
7404next instruction that would have been recorded. In other words, if
7405you record for a while and then stop recording, the inferior process
7406will be left in the same state as if the recording never happened.
53cc454a 7407
a2311334
EZ
7408On the other hand, if the process record and replay target is stopped
7409while in replay mode (that is, not at the end of the execution log,
7410but at some earlier point), the inferior process will become ``live''
7411at that earlier state, and it will then be possible to continue the
7412usual ``live'' debugging of the process from that state.
53cc454a 7413
a2311334
EZ
7414When the inferior process exits, or @value{GDBN} detaches from it,
7415process record and replay target will automatically stop itself.
53cc454a 7416
742ce053
MM
7417@kindex record goto
7418@item record goto
7419Go to a specific location in the execution log. There are several
7420ways to specify the location to go to:
7421
7422@table @code
7423@item record goto begin
7424@itemx record goto start
7425Go to the beginning of the execution log.
7426
7427@item record goto end
7428Go to the end of the execution log.
7429
7430@item record goto @var{n}
7431Go to instruction number @var{n} in the execution log.
7432@end table
7433
24e933df
HZ
7434@kindex record save
7435@item record save @var{filename}
7436Save the execution log to a file @file{@var{filename}}.
7437Default filename is @file{gdb_record.@var{process_id}}, where
7438@var{process_id} is the process ID of the inferior.
7439
59ea5688
MM
7440This command may not be available for all recording methods.
7441
24e933df
HZ
7442@kindex record restore
7443@item record restore @var{filename}
7444Restore the execution log from a file @file{@var{filename}}.
7445File must have been created with @code{record save}.
7446
59ea5688
MM
7447@kindex set record full
7448@item set record full insn-number-max @var{limit}
f81d1120 7449@itemx set record full insn-number-max unlimited
59ea5688
MM
7450Set the limit of instructions to be recorded for the @code{full}
7451recording method. Default value is 200000.
53cc454a 7452
a2311334
EZ
7453If @var{limit} is a positive number, then @value{GDBN} will start
7454deleting instructions from the log once the number of the record
7455instructions becomes greater than @var{limit}. For every new recorded
7456instruction, @value{GDBN} will delete the earliest recorded
7457instruction to keep the number of recorded instructions at the limit.
7458(Since deleting recorded instructions loses information, @value{GDBN}
7459lets you control what happens when the limit is reached, by means of
7460the @code{stop-at-limit} option, described below.)
53cc454a 7461
f81d1120
PA
7462If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7463delete recorded instructions from the execution log. The number of
7464recorded instructions is limited only by the available memory.
53cc454a 7465
59ea5688
MM
7466@kindex show record full
7467@item show record full insn-number-max
7468Show the limit of instructions to be recorded with the @code{full}
7469recording method.
53cc454a 7470
59ea5688
MM
7471@item set record full stop-at-limit
7472Control the behavior of the @code{full} recording method when the
7473number of recorded instructions reaches the limit. If ON (the
7474default), @value{GDBN} will stop when the limit is reached for the
7475first time and ask you whether you want to stop the inferior or
7476continue running it and recording the execution log. If you decide
7477to continue recording, each new recorded instruction will cause the
7478oldest one to be deleted.
53cc454a 7479
a2311334
EZ
7480If this option is OFF, @value{GDBN} will automatically delete the
7481oldest record to make room for each new one, without asking.
53cc454a 7482
59ea5688 7483@item show record full stop-at-limit
a2311334 7484Show the current setting of @code{stop-at-limit}.
53cc454a 7485
59ea5688 7486@item set record full memory-query
bb08c432 7487Control the behavior when @value{GDBN} is unable to record memory
59ea5688
MM
7488changes caused by an instruction for the @code{full} recording method.
7489If ON, @value{GDBN} will query whether to stop the inferior in that
7490case.
bb08c432
HZ
7491
7492If this option is OFF (the default), @value{GDBN} will automatically
7493ignore the effect of such instructions on memory. Later, when
7494@value{GDBN} replays this execution log, it will mark the log of this
7495instruction as not accessible, and it will not affect the replay
7496results.
7497
59ea5688 7498@item show record full memory-query
bb08c432
HZ
7499Show the current setting of @code{memory-query}.
7500
67b5c0c1
MM
7501@kindex set record btrace
7502The @code{btrace} record target does not trace data. As a
7503convenience, when replaying, @value{GDBN} reads read-only memory off
7504the live program directly, assuming that the addresses of the
7505read-only areas don't change. This for example makes it possible to
7506disassemble code while replaying, but not to print variables.
7507In some cases, being able to inspect variables might be useful.
7508You can use the following command for that:
7509
7510@item set record btrace replay-memory-access
7511Control the behavior of the @code{btrace} recording method when
7512accessing memory during replay. If @code{read-only} (the default),
7513@value{GDBN} will only allow accesses to read-only memory.
7514If @code{read-write}, @value{GDBN} will allow accesses to read-only
7515and to read-write memory. Beware that the accessed memory corresponds
7516to the live target and not necessarily to the current replay
7517position.
7518
4a4495d6
MM
7519@item set record btrace cpu @var{identifier}
7520Set the processor to be used for enabling workarounds for processor
7521errata when decoding the trace.
7522
7523Processor errata are defects in processor operation, caused by its
7524design or manufacture. They can cause a trace not to match the
7525specification. This, in turn, may cause trace decode to fail.
7526@value{GDBN} can detect erroneous trace packets and correct them, thus
7527avoiding the decoding failures. These corrections are known as
7528@dfn{errata workarounds}, and are enabled based on the processor on
7529which the trace was recorded.
7530
7531By default, @value{GDBN} attempts to detect the processor
7532automatically, and apply the necessary workarounds for it. However,
7533you may need to specify the processor if @value{GDBN} does not yet
7534support it. This command allows you to do that, and also allows to
7535disable the workarounds.
7536
7537The argument @var{identifier} identifies the @sc{cpu} and is of the
6b92c0d3 7538form: @code{@var{vendor}:@var{processor identifier}}. In addition,
4a4495d6
MM
7539there are two special identifiers, @code{none} and @code{auto}
7540(default).
7541
7542The following vendor identifiers and corresponding processor
7543identifiers are currently supported:
7544
7545@multitable @columnfractions .1 .9
7546
7547@item @code{intel}
7548@tab @var{family}/@var{model}[/@var{stepping}]
7549
7550@end multitable
7551
7552On GNU/Linux systems, the processor @var{family}, @var{model}, and
7553@var{stepping} can be obtained from @code{/proc/cpuinfo}.
7554
7555If @var{identifier} is @code{auto}, enable errata workarounds for the
7556processor on which the trace was recorded. If @var{identifier} is
7557@code{none}, errata workarounds are disabled.
7558
7559For example, when using an old @value{GDBN} on a new system, decode
7560may fail because @value{GDBN} does not support the new processor. It
7561often suffices to specify an older processor that @value{GDBN}
7562supports.
7563
7564@smallexample
7565(gdb) info record
7566Active record target: record-btrace
7567Recording format: Intel Processor Trace.
7568Buffer size: 16kB.
7569Failed to configure the Intel Processor Trace decoder: unknown cpu.
7570(gdb) set record btrace cpu intel:6/158
7571(gdb) info record
7572Active record target: record-btrace
7573Recording format: Intel Processor Trace.
7574Buffer size: 16kB.
7575Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7576@end smallexample
7577
67b5c0c1
MM
7578@kindex show record btrace
7579@item show record btrace replay-memory-access
7580Show the current setting of @code{replay-memory-access}.
7581
4a4495d6
MM
7582@item show record btrace cpu
7583Show the processor to be used for enabling trace decode errata
7584workarounds.
7585
d33501a5
MM
7586@kindex set record btrace bts
7587@item set record btrace bts buffer-size @var{size}
7588@itemx set record btrace bts buffer-size unlimited
7589Set the requested ring buffer size for branch tracing in @acronym{BTS}
7590format. Default is 64KB.
7591
7592If @var{size} is a positive number, then @value{GDBN} will try to
7593allocate a buffer of at least @var{size} bytes for each new thread
7594that uses the btrace recording method and the @acronym{BTS} format.
7595The actually obtained buffer size may differ from the requested
7596@var{size}. Use the @code{info record} command to see the actual
7597buffer size for each thread that uses the btrace recording method and
7598the @acronym{BTS} format.
7599
7600If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7601allocate a buffer of 4MB.
7602
7603Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7604also need longer to process the branch trace data before it can be used.
7605
7606@item show record btrace bts buffer-size @var{size}
7607Show the current setting of the requested ring buffer size for branch
7608tracing in @acronym{BTS} format.
7609
b20a6524
MM
7610@kindex set record btrace pt
7611@item set record btrace pt buffer-size @var{size}
7612@itemx set record btrace pt buffer-size unlimited
bc504a31 7613Set the requested ring buffer size for branch tracing in Intel
b20a6524
MM
7614Processor Trace format. Default is 16KB.
7615
7616If @var{size} is a positive number, then @value{GDBN} will try to
7617allocate a buffer of at least @var{size} bytes for each new thread
bc504a31 7618that uses the btrace recording method and the Intel Processor Trace
b20a6524
MM
7619format. The actually obtained buffer size may differ from the
7620requested @var{size}. Use the @code{info record} command to see the
7621actual buffer size for each thread.
7622
7623If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7624allocate a buffer of 4MB.
7625
7626Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7627also need longer to process the branch trace data before it can be used.
7628
7629@item show record btrace pt buffer-size @var{size}
7630Show the current setting of the requested ring buffer size for branch
bc504a31 7631tracing in Intel Processor Trace format.
b20a6524 7632
29153c24
MS
7633@kindex info record
7634@item info record
59ea5688
MM
7635Show various statistics about the recording depending on the recording
7636method:
7637
7638@table @code
7639@item full
7640For the @code{full} recording method, it shows the state of process
7641record and its in-memory execution log buffer, including:
29153c24
MS
7642
7643@itemize @bullet
7644@item
7645Whether in record mode or replay mode.
7646@item
7647Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7648@item
7649Highest recorded instruction number.
7650@item
7651Current instruction about to be replayed (if in replay mode).
7652@item
7653Number of instructions contained in the execution log.
7654@item
7655Maximum number of instructions that may be contained in the execution log.
7656@end itemize
53cc454a 7657
59ea5688 7658@item btrace
d33501a5
MM
7659For the @code{btrace} recording method, it shows:
7660
7661@itemize @bullet
7662@item
7663Recording format.
7664@item
7665Number of instructions that have been recorded.
7666@item
7667Number of blocks of sequential control-flow formed by the recorded
7668instructions.
7669@item
7670Whether in record mode or replay mode.
7671@end itemize
7672
7673For the @code{bts} recording format, it also shows:
7674@itemize @bullet
7675@item
7676Size of the perf ring buffer.
7677@end itemize
b20a6524
MM
7678
7679For the @code{pt} recording format, it also shows:
7680@itemize @bullet
7681@item
7682Size of the perf ring buffer.
7683@end itemize
59ea5688
MM
7684@end table
7685
53cc454a
HZ
7686@kindex record delete
7687@kindex rec del
7688@item record delete
a2311334 7689When record target runs in replay mode (``in the past''), delete the
53cc454a 7690subsequent execution log and begin to record a new execution log starting
a2311334 7691from the current address. This means you will abandon the previously
53cc454a 7692recorded ``future'' and begin recording a new ``future''.
59ea5688
MM
7693
7694@kindex record instruction-history
7695@kindex rec instruction-history
7696@item record instruction-history
7697Disassembles instructions from the recorded execution log. By
7698default, ten instructions are disassembled. This can be changed using
7699the @code{set record instruction-history-size} command. Instructions
da8c46d2
MM
7700are printed in execution order.
7701
0c532a29
MM
7702It can also print mixed source+disassembly if you specify the the
7703@code{/m} or @code{/s} modifier, and print the raw instructions in hex
7704as well as in symbolic form by specifying the @code{/r} modifier.
7705
7706The current position marker is printed for the instruction at the
7707current program counter value. This instruction can appear multiple
7708times in the trace and the current position marker will be printed
7709every time. To omit the current position marker, specify the
7710@code{/p} modifier.
7711
7712To better align the printed instructions when the trace contains
7713instructions from more than one function, the function name may be
7714omitted by specifying the @code{/f} modifier.
7715
da8c46d2
MM
7716Speculatively executed instructions are prefixed with @samp{?}. This
7717feature is not available for all recording formats.
7718
7719There are several ways to specify what part of the execution log to
7720disassemble:
59ea5688
MM
7721
7722@table @code
7723@item record instruction-history @var{insn}
7724Disassembles ten instructions starting from instruction number
7725@var{insn}.
7726
7727@item record instruction-history @var{insn}, +/-@var{n}
7728Disassembles @var{n} instructions around instruction number
7729@var{insn}. If @var{n} is preceded with @code{+}, disassembles
7730@var{n} instructions after instruction number @var{insn}. If
7731@var{n} is preceded with @code{-}, disassembles @var{n}
7732instructions before instruction number @var{insn}.
7733
7734@item record instruction-history
7735Disassembles ten more instructions after the last disassembly.
7736
7737@item record instruction-history -
7738Disassembles ten more instructions before the last disassembly.
7739
792005b0 7740@item record instruction-history @var{begin}, @var{end}
59ea5688
MM
7741Disassembles instructions beginning with instruction number
7742@var{begin} until instruction number @var{end}. The instruction
0688d04e 7743number @var{end} is included.
59ea5688
MM
7744@end table
7745
7746This command may not be available for all recording methods.
7747
7748@kindex set record
f81d1120
PA
7749@item set record instruction-history-size @var{size}
7750@itemx set record instruction-history-size unlimited
59ea5688
MM
7751Define how many instructions to disassemble in the @code{record
7752instruction-history} command. The default value is 10.
f81d1120 7753A @var{size} of @code{unlimited} means unlimited instructions.
59ea5688
MM
7754
7755@kindex show record
7756@item show record instruction-history-size
7757Show how many instructions to disassemble in the @code{record
7758instruction-history} command.
7759
7760@kindex record function-call-history
7761@kindex rec function-call-history
7762@item record function-call-history
7763Prints the execution history at function granularity. It prints one
7764line for each sequence of instructions that belong to the same
7765function giving the name of that function, the source lines
7766for this instruction sequence (if the @code{/l} modifier is
7767specified), and the instructions numbers that form the sequence (if
8710b709
MM
7768the @code{/i} modifier is specified). The function names are indented
7769to reflect the call stack depth if the @code{/c} modifier is
7770specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be
7771given together.
59ea5688
MM
7772
7773@smallexample
7774(@value{GDBP}) @b{list 1, 10}
77751 void foo (void)
77762 @{
77773 @}
77784
77795 void bar (void)
77806 @{
77817 ...
77828 foo ();
77839 ...
778410 @}
8710b709
MM
7785(@value{GDBP}) @b{record function-call-history /ilc}
77861 bar inst 1,4 at foo.c:6,8
77872 foo inst 5,10 at foo.c:2,3
77883 bar inst 11,13 at foo.c:9,10
59ea5688
MM
7789@end smallexample
7790
7791By default, ten lines are printed. This can be changed using the
7792@code{set record function-call-history-size} command. Functions are
7793printed in execution order. There are several ways to specify what
7794to print:
7795
7796@table @code
7797@item record function-call-history @var{func}
7798Prints ten functions starting from function number @var{func}.
7799
7800@item record function-call-history @var{func}, +/-@var{n}
7801Prints @var{n} functions around function number @var{func}. If
7802@var{n} is preceded with @code{+}, prints @var{n} functions after
7803function number @var{func}. If @var{n} is preceded with @code{-},
7804prints @var{n} functions before function number @var{func}.
7805
7806@item record function-call-history
7807Prints ten more functions after the last ten-line print.
7808
7809@item record function-call-history -
7810Prints ten more functions before the last ten-line print.
7811
792005b0 7812@item record function-call-history @var{begin}, @var{end}
59ea5688 7813Prints functions beginning with function number @var{begin} until
0688d04e 7814function number @var{end}. The function number @var{end} is included.
59ea5688
MM
7815@end table
7816
7817This command may not be available for all recording methods.
7818
f81d1120
PA
7819@item set record function-call-history-size @var{size}
7820@itemx set record function-call-history-size unlimited
59ea5688
MM
7821Define how many lines to print in the
7822@code{record function-call-history} command. The default value is 10.
f81d1120 7823A size of @code{unlimited} means unlimited lines.
59ea5688
MM
7824
7825@item show record function-call-history-size
7826Show how many lines to print in the
7827@code{record function-call-history} command.
53cc454a
HZ
7828@end table
7829
7830
6d2ebf8b 7831@node Stack
c906108c
SS
7832@chapter Examining the Stack
7833
7834When your program has stopped, the first thing you need to know is where it
7835stopped and how it got there.
7836
7837@cindex call stack
5d161b24
DB
7838Each time your program performs a function call, information about the call
7839is generated.
7840That information includes the location of the call in your program,
7841the arguments of the call,
c906108c 7842and the local variables of the function being called.
5d161b24 7843The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
7844The stack frames are allocated in a region of memory called the @dfn{call
7845stack}.
7846
7847When your program stops, the @value{GDBN} commands for examining the
7848stack allow you to see all of this information.
7849
7850@cindex selected frame
7851One of the stack frames is @dfn{selected} by @value{GDBN} and many
7852@value{GDBN} commands refer implicitly to the selected frame. In
7853particular, whenever you ask @value{GDBN} for the value of a variable in
7854your program, the value is found in the selected frame. There are
7855special @value{GDBN} commands to select whichever frame you are
79a6e687 7856interested in. @xref{Selection, ,Selecting a Frame}.
c906108c
SS
7857
7858When your program stops, @value{GDBN} automatically selects the
5d161b24 7859currently executing frame and describes it briefly, similar to the
79a6e687 7860@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
c906108c
SS
7861
7862@menu
7863* Frames:: Stack frames
7864* Backtrace:: Backtraces
7865* Selection:: Selecting a frame
7866* Frame Info:: Information on a frame
0a232300 7867* Frame Apply:: Applying a command to several frames
0f59c28f 7868* Frame Filter Management:: Managing frame filters
c906108c
SS
7869
7870@end menu
7871
6d2ebf8b 7872@node Frames
79a6e687 7873@section Stack Frames
c906108c 7874
d4f3574e 7875@cindex frame, definition
c906108c
SS
7876@cindex stack frame
7877The call stack is divided up into contiguous pieces called @dfn{stack
7878frames}, or @dfn{frames} for short; each frame is the data associated
7879with one call to one function. The frame contains the arguments given
7880to the function, the function's local variables, and the address at
7881which the function is executing.
7882
7883@cindex initial frame
7884@cindex outermost frame
7885@cindex innermost frame
7886When your program is started, the stack has only one frame, that of the
7887function @code{main}. This is called the @dfn{initial} frame or the
7888@dfn{outermost} frame. Each time a function is called, a new frame is
7889made. Each time a function returns, the frame for that function invocation
7890is eliminated. If a function is recursive, there can be many frames for
7891the same function. The frame for the function in which execution is
7892actually occurring is called the @dfn{innermost} frame. This is the most
7893recently created of all the stack frames that still exist.
7894
7895@cindex frame pointer
7896Inside your program, stack frames are identified by their addresses. A
7897stack frame consists of many bytes, each of which has its own address; each
7898kind of computer has a convention for choosing one byte whose
7899address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
7900in a register called the @dfn{frame pointer register}
7901(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c 7902
f67ffa6a 7903@cindex frame level
c906108c 7904@cindex frame number
f67ffa6a
AB
7905@value{GDBN} labels each existing stack frame with a @dfn{level}, a
7906number that is zero for the innermost frame, one for the frame that
7907called it, and so on upward. These level numbers give you a way of
7908designating stack frames in @value{GDBN} commands. The terms
7909@dfn{frame number} and @dfn{frame level} can be used interchangeably to
7910describe this number.
c906108c 7911
6d2ebf8b
SS
7912@c The -fomit-frame-pointer below perennially causes hbox overflow
7913@c underflow problems.
c906108c
SS
7914@cindex frameless execution
7915Some compilers provide a way to compile functions so that they operate
e22ea452 7916without stack frames. (For example, the @value{NGCC} option
474c8240 7917@smallexample
6d2ebf8b 7918@samp{-fomit-frame-pointer}
474c8240 7919@end smallexample
6d2ebf8b 7920generates functions without a frame.)
c906108c
SS
7921This is occasionally done with heavily used library functions to save
7922the frame setup time. @value{GDBN} has limited facilities for dealing
7923with these function invocations. If the innermost function invocation
7924has no stack frame, @value{GDBN} nevertheless regards it as though
7925it had a separate frame, which is numbered zero as usual, allowing
7926correct tracing of the function call chain. However, @value{GDBN} has
7927no provision for frameless functions elsewhere in the stack.
7928
6d2ebf8b 7929@node Backtrace
c906108c
SS
7930@section Backtraces
7931
09d4efe1
EZ
7932@cindex traceback
7933@cindex call stack traces
c906108c
SS
7934A backtrace is a summary of how your program got where it is. It shows one
7935line per frame, for many frames, starting with the currently executing
7936frame (frame zero), followed by its caller (frame one), and on up the
7937stack.
7938
1e611234 7939@anchor{backtrace-command}
c906108c 7940@kindex backtrace
41afff9a 7941@kindex bt @r{(@code{backtrace})}
ea3b0687
TT
7942To print a backtrace of the entire stack, use the @code{backtrace}
7943command, or its alias @code{bt}. This command will print one line per
7944frame for frames in the stack. By default, all stack frames are
7945printed. You can stop the backtrace at any time by typing the system
7946interrupt character, normally @kbd{Ctrl-c}.
7947
7948@table @code
3345721a
PA
7949@item backtrace [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
7950@itemx bt [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
7951Print the backtrace of the entire stack.
7952
7953The optional @var{count} can be one of the following:
ea3b0687
TT
7954
7955@table @code
7956@item @var{n}
7957@itemx @var{n}
7958Print only the innermost @var{n} frames, where @var{n} is a positive
7959number.
7960
7961@item -@var{n}
7962@itemx -@var{n}
7963Print only the outermost @var{n} frames, where @var{n} is a positive
7964number.
3345721a 7965@end table
ea3b0687 7966
3345721a
PA
7967Options:
7968
7969@table @code
7970@item -full
ea3b0687 7971Print the values of the local variables also. This can be combined
3345721a 7972with the optional @var{count} to limit the number of frames shown.
ea3b0687 7973
3345721a 7974@item -no-filters
1e611234
PM
7975Do not run Python frame filters on this backtrace. @xref{Frame
7976Filter API}, for more information. Additionally use @ref{disable
7977frame-filter all} to turn off all frame filters. This is only
7978relevant when @value{GDBN} has been configured with @code{Python}
7979support.
978d6c75 7980
3345721a 7981@item -hide
978d6c75
TT
7982A Python frame filter might decide to ``elide'' some frames. Normally
7983such elided frames are still printed, but they are indented relative
3345721a 7984to the filtered frames that cause them to be elided. The @code{-hide}
978d6c75 7985option causes elided frames to not be printed at all.
c906108c 7986@end table
3345721a
PA
7987
7988The @code{backtrace} command also supports a number of options that
7989allow overriding relevant global print settings as set by @code{set
7990backtrace} and @code{set print} subcommands:
7991
7992@table @code
7993@item -past-main [@code{on}|@code{off}]
7994Set whether backtraces should continue past @code{main}. Related setting:
7995@ref{set backtrace past-main}.
7996
7997@item -past-entry [@code{on}|@code{off}]
7998Set whether backtraces should continue past the entry point of a program.
7999Related setting: @ref{set backtrace past-entry}.
8000
8001@item -entry-values @code{no}|@code{only}|@code{preferred}|@code{if-needed}|@code{both}|@code{compact}|@code{default}
8002Set printing of function arguments at function entry.
8003Related setting: @ref{set print entry-values}.
8004
8005@item -frame-arguments @code{all}|@code{scalars}|@code{none}
8006Set printing of non-scalar frame arguments.
8007Related setting: @ref{set print frame-arguments}.
8008
8009@item -raw-frame-arguments [@code{on}|@code{off}]
8010Set whether to print frame arguments in raw form.
8011Related setting: @ref{set print raw-frame-arguments}.
bc4268a5
PW
8012
8013@item -frame-info @code{auto}|@code{source-line}|@code{location}|@code{source-and-location}|@code{location-and-address}|@code{short-location}
8014Set printing of frame information.
8015Related setting: @ref{set print frame-info}.
3345721a
PA
8016@end table
8017
8018The optional @var{qualifier} is maintained for backward compatibility.
8019It can be one of the following:
8020
8021@table @code
8022@item full
8023Equivalent to the @code{-full} option.
8024
8025@item no-filters
8026Equivalent to the @code{-no-filters} option.
8027
8028@item hide
8029Equivalent to the @code{-hide} option.
8030@end table
8031
ea3b0687 8032@end table
c906108c
SS
8033
8034@kindex where
8035@kindex info stack
c906108c
SS
8036The names @code{where} and @code{info stack} (abbreviated @code{info s})
8037are additional aliases for @code{backtrace}.
8038
839c27b7
EZ
8039@cindex multiple threads, backtrace
8040In a multi-threaded program, @value{GDBN} by default shows the
8041backtrace only for the current thread. To display the backtrace for
8042several or all of the threads, use the command @code{thread apply}
8043(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
8044apply all backtrace}, @value{GDBN} will display the backtrace for all
8045the threads; this is handy when you debug a core dump of a
8046multi-threaded program.
8047
c906108c
SS
8048Each line in the backtrace shows the frame number and the function name.
8049The program counter value is also shown---unless you use @code{set
8050print address off}. The backtrace also shows the source file name and
8051line number, as well as the arguments to the function. The program
8052counter value is omitted if it is at the beginning of the code for that
8053line number.
8054
8055Here is an example of a backtrace. It was made with the command
8056@samp{bt 3}, so it shows the innermost three frames.
8057
8058@smallexample
8059@group
5d161b24 8060#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c 8061 at builtin.c:993
4f5376b2 8062#1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
c906108c
SS
8063#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
8064 at macro.c:71
8065(More stack frames follow...)
8066@end group
8067@end smallexample
8068
8069@noindent
8070The display for frame zero does not begin with a program counter
8071value, indicating that your program has stopped at the beginning of the
8072code for line @code{993} of @code{builtin.c}.
8073
4f5376b2
JB
8074@noindent
8075The value of parameter @code{data} in frame 1 has been replaced by
8076@code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
8077only if it is a scalar (integer, pointer, enumeration, etc). See command
8078@kbd{set print frame-arguments} in @ref{Print Settings} for more details
8079on how to configure the way function parameter values are printed.
bc4268a5
PW
8080The command @kbd{set print frame-info} (@pxref{Print Settings}) controls
8081what frame information is printed.
4f5376b2 8082
585fdaa1 8083@cindex optimized out, in backtrace
18999be5
EZ
8084@cindex function call arguments, optimized out
8085If your program was compiled with optimizations, some compilers will
8086optimize away arguments passed to functions if those arguments are
8087never used after the call. Such optimizations generate code that
8088passes arguments through registers, but doesn't store those arguments
8089in the stack frame. @value{GDBN} has no way of displaying such
8090arguments in stack frames other than the innermost one. Here's what
8091such a backtrace might look like:
8092
8093@smallexample
8094@group
8095#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8096 at builtin.c:993
585fdaa1
PA
8097#1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
8098#2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
18999be5
EZ
8099 at macro.c:71
8100(More stack frames follow...)
8101@end group
8102@end smallexample
8103
8104@noindent
8105The values of arguments that were not saved in their stack frames are
585fdaa1 8106shown as @samp{<optimized out>}.
18999be5
EZ
8107
8108If you need to display the values of such optimized-out arguments,
8109either deduce that from other variables whose values depend on the one
8110you are interested in, or recompile without optimizations.
8111
a8f24a35
EZ
8112@cindex backtrace beyond @code{main} function
8113@cindex program entry point
8114@cindex startup code, and backtrace
25d29d70
AC
8115Most programs have a standard user entry point---a place where system
8116libraries and startup code transition into user code. For C this is
d416eeec
EZ
8117@code{main}@footnote{
8118Note that embedded programs (the so-called ``free-standing''
8119environment) are not required to have a @code{main} function as the
8120entry point. They could even have multiple entry points.}.
8121When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
8122it will terminate the backtrace, to avoid tracing into highly
8123system-specific (and generally uninteresting) code.
8124
8125If you need to examine the startup code, or limit the number of levels
8126in a backtrace, you can change this behavior:
95f90d25
DJ
8127
8128@table @code
25d29d70
AC
8129@item set backtrace past-main
8130@itemx set backtrace past-main on
3345721a 8131@anchor{set backtrace past-main}
4644b6e3 8132@kindex set backtrace
25d29d70
AC
8133Backtraces will continue past the user entry point.
8134
8135@item set backtrace past-main off
95f90d25
DJ
8136Backtraces will stop when they encounter the user entry point. This is the
8137default.
8138
25d29d70 8139@item show backtrace past-main
4644b6e3 8140@kindex show backtrace
25d29d70
AC
8141Display the current user entry point backtrace policy.
8142
2315ffec
RC
8143@item set backtrace past-entry
8144@itemx set backtrace past-entry on
3345721a 8145@anchor{set backtrace past-entry}
a8f24a35 8146Backtraces will continue past the internal entry point of an application.
2315ffec
RC
8147This entry point is encoded by the linker when the application is built,
8148and is likely before the user entry point @code{main} (or equivalent) is called.
8149
8150@item set backtrace past-entry off
d3e8051b 8151Backtraces will stop when they encounter the internal entry point of an
2315ffec
RC
8152application. This is the default.
8153
8154@item show backtrace past-entry
8155Display the current internal entry point backtrace policy.
8156
25d29d70
AC
8157@item set backtrace limit @var{n}
8158@itemx set backtrace limit 0
f81d1120 8159@itemx set backtrace limit unlimited
3345721a 8160@anchor{set backtrace limit}
25d29d70 8161@cindex backtrace limit
f81d1120
PA
8162Limit the backtrace to @var{n} levels. A value of @code{unlimited}
8163or zero means unlimited levels.
95f90d25 8164
25d29d70
AC
8165@item show backtrace limit
8166Display the current limit on backtrace levels.
95f90d25
DJ
8167@end table
8168
1b56eb55
JK
8169You can control how file names are displayed.
8170
8171@table @code
8172@item set filename-display
8173@itemx set filename-display relative
8174@cindex filename-display
8175Display file names relative to the compilation directory. This is the default.
8176
8177@item set filename-display basename
8178Display only basename of a filename.
8179
8180@item set filename-display absolute
8181Display an absolute filename.
8182
8183@item show filename-display
8184Show the current way to display filenames.
8185@end table
8186
6d2ebf8b 8187@node Selection
79a6e687 8188@section Selecting a Frame
c906108c
SS
8189
8190Most commands for examining the stack and other data in your program work on
8191whichever stack frame is selected at the moment. Here are the commands for
8192selecting a stack frame; all of them finish by printing a brief description
8193of the stack frame just selected.
8194
8195@table @code
d4f3574e 8196@kindex frame@r{, selecting}
41afff9a 8197@kindex f @r{(@code{frame})}
f67ffa6a
AB
8198@item frame @r{[} @var{frame-selection-spec} @r{]}
8199@item f @r{[} @var{frame-selection-spec} @r{]}
8200The @command{frame} command allows different stack frames to be
8201selected. The @var{frame-selection-spec} can be any of the following:
8202
8203@table @code
8204@kindex frame level
8205@item @var{num}
8206@item level @var{num}
8207Select frame level @var{num}. Recall that frame zero is the innermost
c906108c 8208(currently executing) frame, frame one is the frame that called the
f67ffa6a
AB
8209innermost one, and so on. The highest level frame is usually the one
8210for @code{main}.
8211
8212As this is the most common method of navigating the frame stack, the
8213string @command{level} can be omitted. For example, the following two
8214commands are equivalent:
8215
8216@smallexample
8217(@value{GDBP}) frame 3
8218(@value{GDBP}) frame level 3
8219@end smallexample
8220
8221@kindex frame address
8222@item address @var{stack-address}
8223Select the frame with stack address @var{stack-address}. The
8224@var{stack-address} for a frame can be seen in the output of
8225@command{info frame}, for example:
8226
8227@smallexample
8228(gdb) info frame
8229Stack level 1, frame at 0x7fffffffda30:
8230 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
8231 tail call frame, caller of frame at 0x7fffffffda30
8232 source language c++.
8233 Arglist at unknown address.
8234 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
8235@end smallexample
8236
8237The @var{stack-address} for this frame is @code{0x7fffffffda30} as
8238indicated by the line:
8239
8240@smallexample
8241Stack level 1, frame at 0x7fffffffda30:
8242@end smallexample
8243
8244@kindex frame function
8245@item function @var{function-name}
8246Select the stack frame for function @var{function-name}. If there are
8247multiple stack frames for function @var{function-name} then the inner
8248most stack frame is selected.
8249
8250@kindex frame view
8251@item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
8252View a frame that is not part of @value{GDBN}'s backtrace. The frame
8253viewed has stack address @var{stack-addr}, and optionally, a program
8254counter address of @var{pc-addr}.
8255
8256This is useful mainly if the chaining of stack frames has been
8257damaged by a bug, making it impossible for @value{GDBN} to assign
8258numbers properly to all frames. In addition, this can be useful
8259when your program has multiple stacks and switches between them.
8260
8261When viewing a frame outside the current backtrace using
8262@command{frame view} then you can always return to the original
8263stack using one of the previous stack frame selection instructions,
8264for example @command{frame level 0}.
8265
8266@end table
c906108c
SS
8267
8268@kindex up
8269@item up @var{n}
697aa1b7
EZ
8270Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
8271numbers @var{n}, this advances toward the outermost frame, to higher
8272frame numbers, to frames that have existed longer.
c906108c
SS
8273
8274@kindex down
41afff9a 8275@kindex do @r{(@code{down})}
c906108c 8276@item down @var{n}
697aa1b7
EZ
8277Move @var{n} frames down the stack; @var{n} defaults to 1. For
8278positive numbers @var{n}, this advances toward the innermost frame, to
8279lower frame numbers, to frames that were created more recently.
8280You may abbreviate @code{down} as @code{do}.
c906108c
SS
8281@end table
8282
8283All of these commands end by printing two lines of output describing the
8284frame. The first line shows the frame number, the function name, the
8285arguments, and the source file and line number of execution in that
5d161b24 8286frame. The second line shows the text of that source line.
c906108c
SS
8287
8288@need 1000
8289For example:
8290
8291@smallexample
8292@group
8293(@value{GDBP}) up
8294#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
8295 at env.c:10
829610 read_input_file (argv[i]);
8297@end group
8298@end smallexample
8299
8300After such a printout, the @code{list} command with no arguments
8301prints ten lines centered on the point of execution in the frame.
87885426
FN
8302You can also edit the program at the point of execution with your favorite
8303editing program by typing @code{edit}.
79a6e687 8304@xref{List, ,Printing Source Lines},
87885426 8305for details.
c906108c
SS
8306
8307@table @code
fc58fa65 8308@kindex select-frame
f67ffa6a 8309@item select-frame @r{[} @var{frame-selection-spec} @r{]}
fc58fa65
AB
8310The @code{select-frame} command is a variant of @code{frame} that does
8311not display the new frame after selecting it. This command is
8312intended primarily for use in @value{GDBN} command scripts, where the
f67ffa6a
AB
8313output might be unnecessary and distracting. The
8314@var{frame-selection-spec} is as for the @command{frame} command
8315described in @ref{Selection, ,Selecting a Frame}.
fc58fa65 8316
c906108c
SS
8317@kindex down-silently
8318@kindex up-silently
8319@item up-silently @var{n}
8320@itemx down-silently @var{n}
8321These two commands are variants of @code{up} and @code{down},
8322respectively; they differ in that they do their work silently, without
8323causing display of the new frame. They are intended primarily for use
8324in @value{GDBN} command scripts, where the output might be unnecessary and
8325distracting.
8326@end table
8327
6d2ebf8b 8328@node Frame Info
79a6e687 8329@section Information About a Frame
c906108c
SS
8330
8331There are several other commands to print information about the selected
8332stack frame.
8333
8334@table @code
8335@item frame
8336@itemx f
8337When used without any argument, this command does not change which
8338frame is selected, but prints a brief description of the currently
8339selected stack frame. It can be abbreviated @code{f}. With an
8340argument, this command is used to select a stack frame.
79a6e687 8341@xref{Selection, ,Selecting a Frame}.
c906108c
SS
8342
8343@kindex info frame
41afff9a 8344@kindex info f @r{(@code{info frame})}
c906108c
SS
8345@item info frame
8346@itemx info f
8347This command prints a verbose description of the selected stack frame,
8348including:
8349
8350@itemize @bullet
5d161b24
DB
8351@item
8352the address of the frame
c906108c
SS
8353@item
8354the address of the next frame down (called by this frame)
8355@item
8356the address of the next frame up (caller of this frame)
8357@item
8358the language in which the source code corresponding to this frame is written
8359@item
8360the address of the frame's arguments
8361@item
d4f3574e
SS
8362the address of the frame's local variables
8363@item
c906108c
SS
8364the program counter saved in it (the address of execution in the caller frame)
8365@item
8366which registers were saved in the frame
8367@end itemize
8368
8369@noindent The verbose description is useful when
8370something has gone wrong that has made the stack format fail to fit
8371the usual conventions.
8372
f67ffa6a
AB
8373@item info frame @r{[} @var{frame-selection-spec} @r{]}
8374@itemx info f @r{[} @var{frame-selection-spec} @r{]}
8375Print a verbose description of the frame selected by
8376@var{frame-selection-spec}. The @var{frame-selection-spec} is the
8377same as for the @command{frame} command (@pxref{Selection, ,Selecting
8378a Frame}). The selected frame remains unchanged by this command.
c906108c
SS
8379
8380@kindex info args
d321477b 8381@item info args [-q]
c906108c
SS
8382Print the arguments of the selected frame, each on a separate line.
8383
d321477b
PW
8384The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8385printing header information and messages explaining why no argument
8386have been printed.
8387
8388@item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
8389Like @kbd{info args}, but only print the arguments selected
8390with the provided regexp(s).
8391
8392If @var{regexp} is provided, print only the arguments whose names
8393match the regular expression @var{regexp}.
8394
8395If @var{type_regexp} is provided, print only the arguments whose
8396types, as printed by the @code{whatis} command, match
8397the regular expression @var{type_regexp}.
8398If @var{type_regexp} contains space(s), it should be enclosed in
8399quote characters. If needed, use backslash to escape the meaning
8400of special characters or quotes.
8401
8402If both @var{regexp} and @var{type_regexp} are provided, an argument
8403is printed only if its name matches @var{regexp} and its type matches
8404@var{type_regexp}.
8405
8406@item info locals [-q]
c906108c
SS
8407@kindex info locals
8408Print the local variables of the selected frame, each on a separate
8409line. These are all variables (declared either static or automatic)
8410accessible at the point of execution of the selected frame.
8411
d321477b
PW
8412The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8413printing header information and messages explaining why no local variables
8414have been printed.
8415
8416@item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
8417Like @kbd{info locals}, but only print the local variables selected
8418with the provided regexp(s).
8419
8420If @var{regexp} is provided, print only the local variables whose names
8421match the regular expression @var{regexp}.
8422
8423If @var{type_regexp} is provided, print only the local variables whose
8424types, as printed by the @code{whatis} command, match
8425the regular expression @var{type_regexp}.
8426If @var{type_regexp} contains space(s), it should be enclosed in
8427quote characters. If needed, use backslash to escape the meaning
8428of special characters or quotes.
8429
8430If both @var{regexp} and @var{type_regexp} are provided, a local variable
8431is printed only if its name matches @var{regexp} and its type matches
8432@var{type_regexp}.
8433
8434The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8435combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8436For example, your program might use Resource Acquisition Is
8437Initialization types (RAII) such as @code{lock_something_t}: each
8438local variable of type @code{lock_something_t} automatically places a
8439lock that is destroyed when the variable goes out of scope. You can
8440then list all acquired locks in your program by doing
8441@smallexample
8442thread apply all -s frame apply all -s info locals -q -t lock_something_t
8443@end smallexample
8444@noindent
8445or the equivalent shorter form
8446@smallexample
8447tfaas i lo -q -t lock_something_t
8448@end smallexample
8449
c906108c
SS
8450@end table
8451
0a232300
PW
8452@node Frame Apply
8453@section Applying a Command to Several Frames.
8454@kindex frame apply
8455@cindex apply command to several frames
8456@table @code
3345721a 8457@item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{option}]@dots{} @var{command}
0a232300
PW
8458The @code{frame apply} command allows you to apply the named
8459@var{command} to one or more frames.
8460
8461@table @code
8462@item @code{all}
8463Specify @code{all} to apply @var{command} to all frames.
8464
8465@item @var{count}
8466Use @var{count} to apply @var{command} to the innermost @var{count}
8467frames, where @var{count} is a positive number.
8468
8469@item @var{-count}
8470Use @var{-count} to apply @var{command} to the outermost @var{count}
8471frames, where @var{count} is a positive number.
8472
8473@item @code{level}
8474Use @code{level} to apply @var{command} to the set of frames identified
8475by the @var{level} list. @var{level} is a frame level or a range of frame
8476levels as @var{level1}-@var{level2}. The frame level is the number shown
8477in the first field of the @samp{backtrace} command output.
8478E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8479at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8480
8481@end table
8482
0a232300
PW
8483Note that the frames on which @code{frame apply} applies a command are
8484also influenced by the @code{set backtrace} settings such as @code{set
3345721a 8485backtrace past-main} and @code{set backtrace limit N}.
0a232300
PW
8486@xref{Backtrace,,Backtraces}.
8487
3345721a
PA
8488The @code{frame apply} command also supports a number of options that
8489allow overriding relevant @code{set backtrace} settings:
8490
8491@table @code
8492@item -past-main [@code{on}|@code{off}]
8493Whether backtraces should continue past @code{main}.
8494Related setting: @ref{set backtrace past-main}.
8495
8496@item -past-entry [@code{on}|@code{off}]
8497Whether backtraces should continue past the entry point of a program.
8498Related setting: @ref{set backtrace past-entry}.
8499@end table
0a232300
PW
8500
8501By default, @value{GDBN} displays some frame information before the
8502output produced by @var{command}, and an error raised during the
8503execution of a @var{command} will abort @code{frame apply}. The
3345721a 8504following options can be used to fine-tune these behaviors:
0a232300
PW
8505
8506@table @code
8507@item -c
8508The flag @code{-c}, which stands for @samp{continue}, causes any
8509errors in @var{command} to be displayed, and the execution of
8510@code{frame apply} then continues.
8511@item -s
8512The flag @code{-s}, which stands for @samp{silent}, causes any errors
8513or empty output produced by a @var{command} to be silently ignored.
8514That is, the execution continues, but the frame information and errors
8515are not printed.
8516@item -q
8517The flag @code{-q} (@samp{quiet}) disables printing the frame
8518information.
8519@end table
8520
8521The following example shows how the flags @code{-c} and @code{-s} are
8522working when applying the command @code{p j} to all frames, where
8523variable @code{j} can only be successfully printed in the outermost
8524@code{#1 main} frame.
8525
8526@smallexample
8527@group
8528(gdb) frame apply all p j
8529#0 some_function (i=5) at fun.c:4
8530No symbol "j" in current context.
8531(gdb) frame apply all -c p j
8532#0 some_function (i=5) at fun.c:4
8533No symbol "j" in current context.
8534#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8535$1 = 5
8536(gdb) frame apply all -s p j
8537#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8538$2 = 5
8539(gdb)
8540@end group
8541@end smallexample
8542
8543By default, @samp{frame apply}, prints the frame location
8544information before the command output:
8545
8546@smallexample
8547@group
8548(gdb) frame apply all p $sp
8549#0 some_function (i=5) at fun.c:4
8550$4 = (void *) 0xffffd1e0
8551#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8552$5 = (void *) 0xffffd1f0
8553(gdb)
8554@end group
8555@end smallexample
8556
3345721a 8557If the flag @code{-q} is given, no frame information is printed:
0a232300
PW
8558@smallexample
8559@group
8560(gdb) frame apply all -q p $sp
8561$12 = (void *) 0xffffd1e0
8562$13 = (void *) 0xffffd1f0
8563(gdb)
8564@end group
8565@end smallexample
8566
3345721a
PA
8567@end table
8568
0a232300
PW
8569@table @code
8570
8571@kindex faas
8572@cindex apply a command to all frames (ignoring errors and empty output)
8573@item faas @var{command}
8574Shortcut for @code{frame apply all -s @var{command}}.
8575Applies @var{command} on all frames, ignoring errors and empty output.
8576
8577It can for example be used to print a local variable or a function
8578argument without knowing the frame where this variable or argument
8579is, using:
8580@smallexample
8581(@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8582@end smallexample
8583
3345721a 8584The @code{faas} command accepts the same options as the @code{frame
ed788fee 8585apply} command. @xref{Frame Apply,,frame apply}.
3345721a 8586
0a232300
PW
8587Note that the command @code{tfaas @var{command}} applies @var{command}
8588on all frames of all threads. See @xref{Threads,,Threads}.
8589@end table
8590
8591
fc58fa65
AB
8592@node Frame Filter Management
8593@section Management of Frame Filters.
8594@cindex managing frame filters
8595
8596Frame filters are Python based utilities to manage and decorate the
8597output of frames. @xref{Frame Filter API}, for further information.
8598
8599Managing frame filters is performed by several commands available
8600within @value{GDBN}, detailed here.
8601
8602@table @code
8603@kindex info frame-filter
8604@item info frame-filter
8605Print a list of installed frame filters from all dictionaries, showing
8606their name, priority and enabled status.
8607
8608@kindex disable frame-filter
8609@anchor{disable frame-filter all}
8610@item disable frame-filter @var{filter-dictionary} @var{filter-name}
8611Disable a frame filter in the dictionary matching
8612@var{filter-dictionary} and @var{filter-name}. The
8613@var{filter-dictionary} may be @code{all}, @code{global},
8614@code{progspace}, or the name of the object file where the frame filter
8615dictionary resides. When @code{all} is specified, all frame filters
8616across all dictionaries are disabled. The @var{filter-name} is the name
8617of the frame filter and is used when @code{all} is not the option for
8618@var{filter-dictionary}. A disabled frame-filter is not deleted, it
8619may be enabled again later.
8620
8621@kindex enable frame-filter
8622@item enable frame-filter @var{filter-dictionary} @var{filter-name}
8623Enable a frame filter in the dictionary matching
8624@var{filter-dictionary} and @var{filter-name}. The
8625@var{filter-dictionary} may be @code{all}, @code{global},
8626@code{progspace} or the name of the object file where the frame filter
8627dictionary resides. When @code{all} is specified, all frame filters across
8628all dictionaries are enabled. The @var{filter-name} is the name of the frame
8629filter and is used when @code{all} is not the option for
8630@var{filter-dictionary}.
8631
8632Example:
8633
8634@smallexample
8635(gdb) info frame-filter
8636
8637global frame-filters:
8638 Priority Enabled Name
8639 1000 No PrimaryFunctionFilter
8640 100 Yes Reverse
8641
8642progspace /build/test frame-filters:
8643 Priority Enabled Name
8644 100 Yes ProgspaceFilter
8645
8646objfile /build/test frame-filters:
8647 Priority Enabled Name
6b92c0d3 8648 999 Yes BuildProgramFilter
fc58fa65
AB
8649
8650(gdb) disable frame-filter /build/test BuildProgramFilter
8651(gdb) info frame-filter
8652
8653global frame-filters:
8654 Priority Enabled Name
8655 1000 No PrimaryFunctionFilter
8656 100 Yes Reverse
8657
8658progspace /build/test frame-filters:
8659 Priority Enabled Name
8660 100 Yes ProgspaceFilter
8661
8662objfile /build/test frame-filters:
8663 Priority Enabled Name
8664 999 No BuildProgramFilter
8665
8666(gdb) enable frame-filter global PrimaryFunctionFilter
8667(gdb) info frame-filter
8668
8669global frame-filters:
8670 Priority Enabled Name
8671 1000 Yes PrimaryFunctionFilter
8672 100 Yes Reverse
8673
8674progspace /build/test frame-filters:
8675 Priority Enabled Name
8676 100 Yes ProgspaceFilter
8677
8678objfile /build/test frame-filters:
8679 Priority Enabled Name
8680 999 No BuildProgramFilter
8681@end smallexample
8682
8683@kindex set frame-filter priority
8684@item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
8685Set the @var{priority} of a frame filter in the dictionary matching
8686@var{filter-dictionary}, and the frame filter name matching
8687@var{filter-name}. The @var{filter-dictionary} may be @code{global},
8688@code{progspace} or the name of the object file where the frame filter
8689dictionary resides. The @var{priority} is an integer.
8690
8691@kindex show frame-filter priority
8692@item show frame-filter priority @var{filter-dictionary} @var{filter-name}
8693Show the @var{priority} of a frame filter in the dictionary matching
8694@var{filter-dictionary}, and the frame filter name matching
8695@var{filter-name}. The @var{filter-dictionary} may be @code{global},
8696@code{progspace} or the name of the object file where the frame filter
8697dictionary resides.
8698
8699Example:
8700
8701@smallexample
8702(gdb) info frame-filter
8703
8704global frame-filters:
8705 Priority Enabled Name
8706 1000 Yes PrimaryFunctionFilter
8707 100 Yes Reverse
8708
8709progspace /build/test frame-filters:
8710 Priority Enabled Name
8711 100 Yes ProgspaceFilter
8712
8713objfile /build/test frame-filters:
8714 Priority Enabled Name
8715 999 No BuildProgramFilter
8716
8717(gdb) set frame-filter priority global Reverse 50
8718(gdb) info frame-filter
8719
8720global frame-filters:
8721 Priority Enabled Name
8722 1000 Yes PrimaryFunctionFilter
8723 50 Yes Reverse
8724
8725progspace /build/test frame-filters:
8726 Priority Enabled Name
8727 100 Yes ProgspaceFilter
8728
8729objfile /build/test frame-filters:
8730 Priority Enabled Name
8731 999 No BuildProgramFilter
8732@end smallexample
8733@end table
c906108c 8734
6d2ebf8b 8735@node Source
c906108c
SS
8736@chapter Examining Source Files
8737
8738@value{GDBN} can print parts of your program's source, since the debugging
8739information recorded in the program tells @value{GDBN} what source files were
8740used to build it. When your program stops, @value{GDBN} spontaneously prints
8741the line where it stopped. Likewise, when you select a stack frame
79a6e687 8742(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
c906108c
SS
8743execution in that frame has stopped. You can print other portions of
8744source files by explicit command.
8745
7a292a7a 8746If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 8747prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 8748@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
8749
8750@menu
8751* List:: Printing source lines
2a25a5ba 8752* Specify Location:: How to specify code locations
87885426 8753* Edit:: Editing source files
c906108c 8754* Search:: Searching source files
c906108c
SS
8755* Source Path:: Specifying source directories
8756* Machine Code:: Source and machine code
8757@end menu
8758
6d2ebf8b 8759@node List
79a6e687 8760@section Printing Source Lines
c906108c
SS
8761
8762@kindex list
41afff9a 8763@kindex l @r{(@code{list})}
c906108c 8764To print lines from a source file, use the @code{list} command
5d161b24 8765(abbreviated @code{l}). By default, ten lines are printed.
2a25a5ba
EZ
8766There are several ways to specify what part of the file you want to
8767print; see @ref{Specify Location}, for the full list.
c906108c
SS
8768
8769Here are the forms of the @code{list} command most commonly used:
8770
8771@table @code
8772@item list @var{linenum}
8773Print lines centered around line number @var{linenum} in the
8774current source file.
8775
8776@item list @var{function}
8777Print lines centered around the beginning of function
8778@var{function}.
8779
8780@item list
8781Print more lines. If the last lines printed were printed with a
8782@code{list} command, this prints lines following the last lines
8783printed; however, if the last line printed was a solitary line printed
8784as part of displaying a stack frame (@pxref{Stack, ,Examining the
8785Stack}), this prints lines centered around that line.
8786
8787@item list -
8788Print lines just before the lines last printed.
8789@end table
8790
9c16f35a 8791@cindex @code{list}, how many lines to display
c906108c
SS
8792By default, @value{GDBN} prints ten source lines with any of these forms of
8793the @code{list} command. You can change this using @code{set listsize}:
8794
8795@table @code
8796@kindex set listsize
8797@item set listsize @var{count}
f81d1120 8798@itemx set listsize unlimited
c906108c
SS
8799Make the @code{list} command display @var{count} source lines (unless
8800the @code{list} argument explicitly specifies some other number).
f81d1120 8801Setting @var{count} to @code{unlimited} or 0 means there's no limit.
c906108c
SS
8802
8803@kindex show listsize
8804@item show listsize
8805Display the number of lines that @code{list} prints.
8806@end table
8807
8808Repeating a @code{list} command with @key{RET} discards the argument,
8809so it is equivalent to typing just @code{list}. This is more useful
8810than listing the same lines again. An exception is made for an
8811argument of @samp{-}; that argument is preserved in repetition so that
8812each repetition moves up in the source file.
8813
c906108c 8814In general, the @code{list} command expects you to supply zero, one or two
629500fa 8815@dfn{locations}. Locations specify source lines; there are several ways
2a25a5ba
EZ
8816of writing them (@pxref{Specify Location}), but the effect is always
8817to specify some source line.
8818
c906108c
SS
8819Here is a complete description of the possible arguments for @code{list}:
8820
8821@table @code
629500fa
KS
8822@item list @var{location}
8823Print lines centered around the line specified by @var{location}.
c906108c
SS
8824
8825@item list @var{first},@var{last}
8826Print lines from @var{first} to @var{last}. Both arguments are
629500fa
KS
8827locations. When a @code{list} command has two locations, and the
8828source file of the second location is omitted, this refers to
8829the same source file as the first location.
c906108c
SS
8830
8831@item list ,@var{last}
8832Print lines ending with @var{last}.
8833
8834@item list @var{first},
8835Print lines starting with @var{first}.
8836
8837@item list +
8838Print lines just after the lines last printed.
8839
8840@item list -
8841Print lines just before the lines last printed.
8842
8843@item list
8844As described in the preceding table.
8845@end table
8846
2a25a5ba
EZ
8847@node Specify Location
8848@section Specifying a Location
8849@cindex specifying location
629500fa
KS
8850@cindex location
8851@cindex source location
8852
8853@menu
8854* Linespec Locations:: Linespec locations
8855* Explicit Locations:: Explicit locations
8856* Address Locations:: Address locations
8857@end menu
c906108c 8858
2a25a5ba
EZ
8859Several @value{GDBN} commands accept arguments that specify a location
8860of your program's code. Since @value{GDBN} is a source-level
629500fa
KS
8861debugger, a location usually specifies some line in the source code.
8862Locations may be specified using three different formats:
8863linespec locations, explicit locations, or address locations.
c906108c 8864
629500fa
KS
8865@node Linespec Locations
8866@subsection Linespec Locations
8867@cindex linespec locations
8868
8869A @dfn{linespec} is a colon-separated list of source location parameters such
8870as file name, function name, etc. Here are all the different ways of
8871specifying a linespec:
c906108c 8872
2a25a5ba
EZ
8873@table @code
8874@item @var{linenum}
8875Specifies the line number @var{linenum} of the current source file.
c906108c 8876
2a25a5ba
EZ
8877@item -@var{offset}
8878@itemx +@var{offset}
8879Specifies the line @var{offset} lines before or after the @dfn{current
8880line}. For the @code{list} command, the current line is the last one
8881printed; for the breakpoint commands, this is the line at which
8882execution stopped in the currently selected @dfn{stack frame}
8883(@pxref{Frames, ,Frames}, for a description of stack frames.) When
8884used as the second of the two linespecs in a @code{list} command,
8885this specifies the line @var{offset} lines up or down from the first
8886linespec.
8887
8888@item @var{filename}:@var{linenum}
8889Specifies the line @var{linenum} in the source file @var{filename}.
4aac40c8
TT
8890If @var{filename} is a relative file name, then it will match any
8891source file name with the same trailing components. For example, if
8892@var{filename} is @samp{gcc/expr.c}, then it will match source file
8893name of @file{/build/trunk/gcc/expr.c}, but not
8894@file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
c906108c
SS
8895
8896@item @var{function}
8897Specifies the line that begins the body of the function @var{function}.
2a25a5ba 8898For example, in C, this is the line with the open brace.
c906108c 8899
a20714ff
PA
8900By default, in C@t{++} and Ada, @var{function} is interpreted as
8901specifying all functions named @var{function} in all scopes. For
8902C@t{++}, this means in all namespaces and classes. For Ada, this
8903means in all packages.
8904
8905For example, assuming a program with C@t{++} symbols named
8906@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8907func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
8908
8909Commands that accept a linespec let you override this with the
8910@code{-qualified} option. For example, @w{@kbd{break -qualified
8911func}} sets a breakpoint on a free-function named @code{func} ignoring
8912any C@t{++} class methods and namespace functions called @code{func}.
8913
8914@xref{Explicit Locations}.
8915
9ef07c8c
TT
8916@item @var{function}:@var{label}
8917Specifies the line where @var{label} appears in @var{function}.
8918
c906108c 8919@item @var{filename}:@var{function}
2a25a5ba
EZ
8920Specifies the line that begins the body of the function @var{function}
8921in the file @var{filename}. You only need the file name with a
8922function name to avoid ambiguity when there are identically named
8923functions in different source files.
c906108c 8924
0f5238ed 8925@item @var{label}
629500fa
KS
8926Specifies the line at which the label named @var{label} appears
8927in the function corresponding to the currently selected stack frame.
8928If there is no current selected stack frame (for instance, if the inferior
8929is not running), then @value{GDBN} will not search for a label.
8930
8931@cindex breakpoint at static probe point
8932@item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
8933The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
8934applications to embed static probes. @xref{Static Probe Points}, for more
8935information on finding and using static probes. This form of linespec
8936specifies the location of such a static probe.
8937
8938If @var{objfile} is given, only probes coming from that shared library
8939or executable matching @var{objfile} as a regular expression are considered.
8940If @var{provider} is given, then only probes from that provider are considered.
8941If several probes match the spec, @value{GDBN} will insert a breakpoint at
8942each one of those probes.
8943@end table
8944
8945@node Explicit Locations
8946@subsection Explicit Locations
8947@cindex explicit locations
8948
8949@dfn{Explicit locations} allow the user to directly specify the source
8950location's parameters using option-value pairs.
8951
8952Explicit locations are useful when several functions, labels, or
8953file names have the same name (base name for files) in the program's
8954sources. In these cases, explicit locations point to the source
8955line you meant more accurately and unambiguously. Also, using
8956explicit locations might be faster in large programs.
8957
8958For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
8959defined in the file named @file{foo} or the label @code{bar} in a function
8960named @code{foo}. @value{GDBN} must search either the file system or
8961the symbol table to know.
8962
8963The list of valid explicit location options is summarized in the
8964following table:
8965
8966@table @code
8967@item -source @var{filename}
8968The value specifies the source file name. To differentiate between
8969files with the same base name, prepend as many directories as is necessary
8970to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
8971@value{GDBN} will use the first file it finds with the given base
8972name. This option requires the use of either @code{-function} or @code{-line}.
8973
8974@item -function @var{function}
8975The value specifies the name of a function. Operations
8976on function locations unmodified by other options (such as @code{-label}
8977or @code{-line}) refer to the line that begins the body of the function.
8978In C, for example, this is the line with the open brace.
8979
a20714ff
PA
8980By default, in C@t{++} and Ada, @var{function} is interpreted as
8981specifying all functions named @var{function} in all scopes. For
8982C@t{++}, this means in all namespaces and classes. For Ada, this
8983means in all packages.
8984
8985For example, assuming a program with C@t{++} symbols named
8986@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8987-function func}} and @w{@kbd{break -function B::func}} set a
8988breakpoint on both symbols.
8989
8990You can use the @kbd{-qualified} flag to override this (see below).
8991
8992@item -qualified
8993
8994This flag makes @value{GDBN} interpret a function name specified with
8995@kbd{-function} as a complete fully-qualified name.
8996
8997For example, assuming a C@t{++} program with symbols named
8998@code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
8999-function B::func}} command sets a breakpoint on @code{B::func}, only.
9000
9001(Note: the @kbd{-qualified} option can precede a linespec as well
9002(@pxref{Linespec Locations}), so the particular example above could be
9003simplified as @w{@kbd{break -qualified B::func}}.)
9004
629500fa
KS
9005@item -label @var{label}
9006The value specifies the name of a label. When the function
9007name is not specified, the label is searched in the function of the currently
9008selected stack frame.
9009
9010@item -line @var{number}
9011The value specifies a line offset for the location. The offset may either
9012be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
9013the command. When specified without any other options, the line offset is
9014relative to the current line.
9015@end table
9016
9017Explicit location options may be abbreviated by omitting any non-unique
a20714ff 9018trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
629500fa
KS
9019
9020@node Address Locations
9021@subsection Address Locations
9022@cindex address locations
9023
9024@dfn{Address locations} indicate a specific program address. They have
9025the generalized form *@var{address}.
9026
9027For line-oriented commands, such as @code{list} and @code{edit}, this
9028specifies a source line that contains @var{address}. For @code{break} and
9029other breakpoint-oriented commands, this can be used to set breakpoints in
2a25a5ba
EZ
9030parts of your program which do not have debugging information or
9031source files.
9032
9033Here @var{address} may be any expression valid in the current working
9034language (@pxref{Languages, working language}) that specifies a code
5fa54e5d 9035address. In addition, as a convenience, @value{GDBN} extends the
629500fa
KS
9036semantics of expressions used in locations to cover several situations
9037that frequently occur during debugging. Here are the various forms
5fa54e5d 9038of @var{address}:
2a25a5ba
EZ
9039
9040@table @code
9041@item @var{expression}
9042Any expression valid in the current working language.
9043
9044@item @var{funcaddr}
9045An address of a function or procedure derived from its name. In C,
9c37b5ae 9046C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
2a25a5ba
EZ
9047simply the function's name @var{function} (and actually a special case
9048of a valid expression). In Pascal and Modula-2, this is
9049@code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
9050(although the Pascal form also works).
9051
9052This form specifies the address of the function's first instruction,
9053before the stack frame and arguments have been set up.
9054
9a284c97 9055@item '@var{filename}':@var{funcaddr}
2a25a5ba
EZ
9056Like @var{funcaddr} above, but also specifies the name of the source
9057file explicitly. This is useful if the name of the function does not
9058specify the function unambiguously, e.g., if there are several
9059functions with identical names in different source files.
c906108c
SS
9060@end table
9061
87885426 9062@node Edit
79a6e687 9063@section Editing Source Files
87885426
FN
9064@cindex editing source files
9065
9066@kindex edit
9067@kindex e @r{(@code{edit})}
9068To edit the lines in a source file, use the @code{edit} command.
9069The editing program of your choice
9070is invoked with the current line set to
9071the active line in the program.
9072Alternatively, there are several ways to specify what part of the file you
2a25a5ba 9073want to print if you want to see other parts of the program:
87885426
FN
9074
9075@table @code
2a25a5ba
EZ
9076@item edit @var{location}
9077Edit the source file specified by @code{location}. Editing starts at
9078that @var{location}, e.g., at the specified source line of the
9079specified file. @xref{Specify Location}, for all the possible forms
9080of the @var{location} argument; here are the forms of the @code{edit}
9081command most commonly used:
87885426 9082
2a25a5ba 9083@table @code
87885426
FN
9084@item edit @var{number}
9085Edit the current source file with @var{number} as the active line number.
9086
9087@item edit @var{function}
9088Edit the file containing @var{function} at the beginning of its definition.
2a25a5ba 9089@end table
87885426 9090
87885426
FN
9091@end table
9092
79a6e687 9093@subsection Choosing your Editor
87885426
FN
9094You can customize @value{GDBN} to use any editor you want
9095@footnote{
9096The only restriction is that your editor (say @code{ex}), recognizes the
9097following command-line syntax:
10998722 9098@smallexample
87885426 9099ex +@var{number} file
10998722 9100@end smallexample
15387254
EZ
9101The optional numeric value +@var{number} specifies the number of the line in
9102the file where to start editing.}.
9103By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
9104by setting the environment variable @code{EDITOR} before using
9105@value{GDBN}. For example, to configure @value{GDBN} to use the
9106@code{vi} editor, you could use these commands with the @code{sh} shell:
9107@smallexample
87885426
FN
9108EDITOR=/usr/bin/vi
9109export EDITOR
15387254 9110gdb @dots{}
10998722 9111@end smallexample
87885426 9112or in the @code{csh} shell,
10998722 9113@smallexample
87885426 9114setenv EDITOR /usr/bin/vi
15387254 9115gdb @dots{}
10998722 9116@end smallexample
87885426 9117
6d2ebf8b 9118@node Search
79a6e687 9119@section Searching Source Files
15387254 9120@cindex searching source files
c906108c
SS
9121
9122There are two commands for searching through the current source file for a
9123regular expression.
9124
9125@table @code
9126@kindex search
9127@kindex forward-search
1e96de83 9128@kindex fo @r{(@code{forward-search})}
c906108c
SS
9129@item forward-search @var{regexp}
9130@itemx search @var{regexp}
9131The command @samp{forward-search @var{regexp}} checks each line,
9132starting with the one following the last line listed, for a match for
5d161b24 9133@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
9134synonym @samp{search @var{regexp}} or abbreviate the command name as
9135@code{fo}.
9136
09d4efe1 9137@kindex reverse-search
c906108c
SS
9138@item reverse-search @var{regexp}
9139The command @samp{reverse-search @var{regexp}} checks each line, starting
9140with the one before the last line listed and going backward, for a match
9141for @var{regexp}. It lists the line that is found. You can abbreviate
9142this command as @code{rev}.
9143@end table
c906108c 9144
6d2ebf8b 9145@node Source Path
79a6e687 9146@section Specifying Source Directories
c906108c
SS
9147
9148@cindex source path
9149@cindex directories for source files
9150Executable programs sometimes do not record the directories of the source
9151files from which they were compiled, just the names. Even when they do,
9152the directories could be moved between the compilation and your debugging
9153session. @value{GDBN} has a list of directories to search for source files;
9154this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
9155it tries all the directories in the list, in the order they are present
0b66e38c
EZ
9156in the list, until it finds a file with the desired name.
9157
9158For example, suppose an executable references the file
f1b620e9
MG
9159@file{/usr/src/foo-1.0/lib/foo.c}, does not record a compilation
9160directory, and the @dfn{source path} is @file{/mnt/cross}.
9161@value{GDBN} would look for the source file in the following
9162locations:
9163
9164@enumerate
9165
9166@item @file{/usr/src/foo-1.0/lib/foo.c}
9167@item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9168@item @file{/mnt/cross/foo.c}
9169
9170@end enumerate
9171
9172If the source file is not present at any of the above locations then
9173an error is printed. @value{GDBN} does not look up the parts of the
0b66e38c
EZ
9174source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
9175Likewise, the subdirectories of the source path are not searched: if
9176the source path is @file{/mnt/cross}, and the binary refers to
9177@file{foo.c}, @value{GDBN} would not find it under
9178@file{/mnt/cross/usr/src/foo-1.0/lib}.
9179
9180Plain file names, relative file names with leading directories, file
f1b620e9
MG
9181names containing dots, etc.@: are all treated as described above,
9182except that non-absolute file names are not looked up literally. If
9183the @dfn{source path} is @file{/mnt/cross}, the source file is
9184recorded as @file{../lib/foo.c}, and no compilation directory is
9185recorded, then @value{GDBN} will search in the following locations:
9186
9187@enumerate
9188
9189@item @file{/mnt/cross/../lib/foo.c}
9190@item @file{/mnt/cross/foo.c}
9191
9192@end enumerate
9193
9194@kindex cdir
9195@kindex cwd
9196@vindex $cdir@r{, convenience variable}
9197@vindex $cwd@r{, convenience variable}
9198@cindex compilation directory
9199@cindex current directory
9200@cindex working directory
9201@cindex directory, current
9202@cindex directory, compilation
9203The @dfn{source path} will always include two special entries
9204@samp{$cdir} and @samp{$cwd}, these refer to the compilation directory
9205(if one is recorded) and the current working directory respectively.
9206
9207@samp{$cdir} causes @value{GDBN} to search within the compilation
9208directory, if one is recorded in the debug information. If no
9209compilation directory is recorded in the debug information then
9210@samp{$cdir} is ignored.
9211
9212@samp{$cwd} is not the same as @samp{.}---the former tracks the
9213current working directory as it changes during your @value{GDBN}
9214session, while the latter is immediately expanded to the current
9215directory at the time you add an entry to the source path.
9216
9217If a compilation directory is recorded in the debug information, and
9218@value{GDBN} has not found the source file after the first search
9219using @dfn{source path}, then @value{GDBN} will combine the
9220compilation directory and the filename, and then search for the source
9221file again using the @dfn{source path}.
9222
9223For example, if the executable records the source file as
9224@file{/usr/src/foo-1.0/lib/foo.c}, the compilation directory is
9225recorded as @file{/project/build}, and the @dfn{source path} is
9226@file{/mnt/cross:$cdir:$cwd} while the current working directory of
9227the @value{GDBN} session is @file{/home/user}, then @value{GDBN} will
6b92c0d3 9228search for the source file in the following locations:
f1b620e9
MG
9229
9230@enumerate
9231
9232@item @file{/usr/src/foo-1.0/lib/foo.c}
9233@item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9234@item @file{/project/build/usr/src/foo-1.0/lib/foo.c}
9235@item @file{/home/user/usr/src/foo-1.0/lib/foo.c}
9236@item @file{/mnt/cross/project/build/usr/src/foo-1.0/lib/foo.c}
9237@item @file{/project/build/project/build/usr/src/foo-1.0/lib/foo.c}
9238@item @file{/home/user/project/build/usr/src/foo-1.0/lib/foo.c}
9239@item @file{/mnt/cross/foo.c}
9240@item @file{/project/build/foo.c}
9241@item @file{/home/user/foo.c}
9242
9243@end enumerate
9244
9245If the file name in the previous example had been recorded in the
9246executable as a relative path rather than an absolute path, then the
9247first look up would not have occurred, but all of the remaining steps
9248would be similar.
9249
9250When searching for source files on MS-DOS and MS-Windows, where
9251absolute paths start with a drive letter (e.g.
9252@file{C:/project/foo.c}), @value{GDBN} will remove the drive letter
9253from the file name before appending it to a search directory from
9254@dfn{source path}; for instance if the executable references the
9255source file @file{C:/project/foo.c} and @dfn{source path} is set to
9256@file{D:/mnt/cross}, then @value{GDBN} will search in the following
9257locations for the source file:
9258
9259@enumerate
9260
9261@item @file{C:/project/foo.c}
9262@item @file{D:/mnt/cross/project/foo.c}
9263@item @file{D:/mnt/cross/foo.c}
9264
9265@end enumerate
0b66e38c
EZ
9266
9267Note that the executable search path is @emph{not} used to locate the
cd852561 9268source files.
c906108c
SS
9269
9270Whenever you reset or rearrange the source path, @value{GDBN} clears out
9271any information it has cached about where source files are found and where
9272each line is in the file.
9273
9274@kindex directory
9275@kindex dir
f1b620e9
MG
9276When you start @value{GDBN}, its source path includes only @samp{$cdir}
9277and @samp{$cwd}, in that order.
c906108c
SS
9278To add other directories, use the @code{directory} command.
9279
4b505b12
AS
9280The search path is used to find both program source files and @value{GDBN}
9281script files (read using the @samp{-command} option and @samp{source} command).
9282
30daae6c
JB
9283In addition to the source path, @value{GDBN} provides a set of commands
9284that manage a list of source path substitution rules. A @dfn{substitution
9285rule} specifies how to rewrite source directories stored in the program's
9286debug information in case the sources were moved to a different
9287directory between compilation and debugging. A rule is made of
9288two strings, the first specifying what needs to be rewritten in
9289the path, and the second specifying how it should be rewritten.
9290In @ref{set substitute-path}, we name these two parts @var{from} and
9291@var{to} respectively. @value{GDBN} does a simple string replacement
9292of @var{from} with @var{to} at the start of the directory part of the
9293source file name, and uses that result instead of the original file
9294name to look up the sources.
9295
9296Using the previous example, suppose the @file{foo-1.0} tree has been
9297moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
3f94c067 9298@value{GDBN} to replace @file{/usr/src} in all source path names with
30daae6c
JB
9299@file{/mnt/cross}. The first lookup will then be
9300@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
9301of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
9302substitution rule, use the @code{set substitute-path} command
9303(@pxref{set substitute-path}).
9304
9305To avoid unexpected substitution results, a rule is applied only if the
9306@var{from} part of the directory name ends at a directory separator.
9307For instance, a rule substituting @file{/usr/source} into
9308@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
9309not to @file{/usr/sourceware/foo-2.0}. And because the substitution
d3e8051b 9310is applied only at the beginning of the directory name, this rule will
30daae6c
JB
9311not be applied to @file{/root/usr/source/baz.c} either.
9312
9313In many cases, you can achieve the same result using the @code{directory}
9314command. However, @code{set substitute-path} can be more efficient in
9315the case where the sources are organized in a complex tree with multiple
9316subdirectories. With the @code{directory} command, you need to add each
9317subdirectory of your project. If you moved the entire tree while
9318preserving its internal organization, then @code{set substitute-path}
9319allows you to direct the debugger to all the sources with one single
9320command.
9321
9322@code{set substitute-path} is also more than just a shortcut command.
9323The source path is only used if the file at the original location no
9324longer exists. On the other hand, @code{set substitute-path} modifies
9325the debugger behavior to look at the rewritten location instead. So, if
9326for any reason a source file that is not relevant to your executable is
9327located at the original location, a substitution rule is the only
3f94c067 9328method available to point @value{GDBN} at the new location.
30daae6c 9329
29b0e8a2
JM
9330@cindex @samp{--with-relocated-sources}
9331@cindex default source path substitution
9332You can configure a default source path substitution rule by
9333configuring @value{GDBN} with the
9334@samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
9335should be the name of a directory under @value{GDBN}'s configured
9336prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
9337directory names in debug information under @var{dir} will be adjusted
9338automatically if the installed @value{GDBN} is moved to a new
9339location. This is useful if @value{GDBN}, libraries or executables
9340with debug information and corresponding source code are being moved
9341together.
9342
c906108c
SS
9343@table @code
9344@item directory @var{dirname} @dots{}
9345@item dir @var{dirname} @dots{}
9346Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
9347directory names may be given to this command, separated by @samp{:}
9348(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
9349part of absolute file names) or
c906108c
SS
9350whitespace. You may specify a directory that is already in the source
9351path; this moves it forward, so @value{GDBN} searches it sooner.
9352
f1b620e9
MG
9353The special strings @samp{$cdir} (to refer to the compilation
9354directory, if one is recorded), and @samp{$cwd} (to refer to the
9355current working directory) can also be included in the list of
9356directories @var{dirname}. Though these will already be in the source
9357path they will be moved forward in the list so @value{GDBN} searches
9358them sooner.
c906108c
SS
9359
9360@item directory
cd852561 9361Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
9362
9363@c RET-repeat for @code{directory} is explicitly disabled, but since
9364@c repeating it would be a no-op we do not say that. (thanks to RMS)
9365
99e7ae30
DE
9366@item set directories @var{path-list}
9367@kindex set directories
9368Set the source path to @var{path-list}.
9369@samp{$cdir:$cwd} are added if missing.
9370
c906108c
SS
9371@item show directories
9372@kindex show directories
9373Print the source path: show which directories it contains.
30daae6c
JB
9374
9375@anchor{set substitute-path}
9376@item set substitute-path @var{from} @var{to}
9377@kindex set substitute-path
9378Define a source path substitution rule, and add it at the end of the
9379current list of existing substitution rules. If a rule with the same
9380@var{from} was already defined, then the old rule is also deleted.
9381
9382For example, if the file @file{/foo/bar/baz.c} was moved to
9383@file{/mnt/cross/baz.c}, then the command
9384
9385@smallexample
c58b006b 9386(@value{GDBP}) set substitute-path /foo/bar /mnt/cross
30daae6c
JB
9387@end smallexample
9388
9389@noindent
c58b006b 9390will tell @value{GDBN} to replace @samp{/foo/bar} with
30daae6c
JB
9391@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
9392@file{baz.c} even though it was moved.
9393
9394In the case when more than one substitution rule have been defined,
9395the rules are evaluated one by one in the order where they have been
9396defined. The first one matching, if any, is selected to perform
9397the substitution.
9398
9399For instance, if we had entered the following commands:
9400
9401@smallexample
9402(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
9403(@value{GDBP}) set substitute-path /usr/src /mnt/src
9404@end smallexample
9405
9406@noindent
9407@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
9408@file{/mnt/include/defs.h} by using the first rule. However, it would
9409use the second rule to rewrite @file{/usr/src/lib/foo.c} into
9410@file{/mnt/src/lib/foo.c}.
9411
9412
9413@item unset substitute-path [path]
9414@kindex unset substitute-path
9415If a path is specified, search the current list of substitution rules
9416for a rule that would rewrite that path. Delete that rule if found.
9417A warning is emitted by the debugger if no rule could be found.
9418
9419If no path is specified, then all substitution rules are deleted.
9420
9421@item show substitute-path [path]
9422@kindex show substitute-path
9423If a path is specified, then print the source path substitution rule
9424which would rewrite that path, if any.
9425
9426If no path is specified, then print all existing source path substitution
9427rules.
9428
c906108c
SS
9429@end table
9430
9431If your source path is cluttered with directories that are no longer of
9432interest, @value{GDBN} may sometimes cause confusion by finding the wrong
9433versions of source. You can correct the situation as follows:
9434
9435@enumerate
9436@item
cd852561 9437Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
9438
9439@item
9440Use @code{directory} with suitable arguments to reinstall the
9441directories you want in the source path. You can add all the
9442directories in one command.
9443@end enumerate
9444
6d2ebf8b 9445@node Machine Code
79a6e687 9446@section Source and Machine Code
15387254 9447@cindex source line and its code address
c906108c
SS
9448
9449You can use the command @code{info line} to map source lines to program
9450addresses (and vice versa), and the command @code{disassemble} to display
91440f57
HZ
9451a range of addresses as machine instructions. You can use the command
9452@code{set disassemble-next-line} to set whether to disassemble next
9453source line when execution stops. When run under @sc{gnu} Emacs
d4f3574e 9454mode, the @code{info line} command causes the arrow to point to the
5d161b24 9455line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
9456well as hex.
9457
9458@table @code
9459@kindex info line
db1ae9c5
AB
9460@item info line
9461@itemx info line @var{location}
c906108c 9462Print the starting and ending addresses of the compiled code for
629500fa 9463source line @var{location}. You can specify source lines in any of
db1ae9c5
AB
9464the ways documented in @ref{Specify Location}. With no @var{location}
9465information about the current source line is printed.
c906108c
SS
9466@end table
9467
9468For example, we can use @code{info line} to discover the location of
9469the object code for the first line of function
9470@code{m4_changequote}:
9471
9472@smallexample
96a2c332 9473(@value{GDBP}) info line m4_changequote
db1ae9c5
AB
9474Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
9475 ends at 0x6350 <m4_changequote+4>.
c906108c
SS
9476@end smallexample
9477
9478@noindent
15387254 9479@cindex code address and its source line
c906108c 9480We can also inquire (using @code{*@var{addr}} as the form for
629500fa 9481@var{location}) what source line covers a particular address:
c906108c
SS
9482@smallexample
9483(@value{GDBP}) info line *0x63ff
db1ae9c5
AB
9484Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
9485 ends at 0x6404 <m4_changequote+184>.
c906108c
SS
9486@end smallexample
9487
9488@cindex @code{$_} and @code{info line}
15387254 9489@cindex @code{x} command, default address
41afff9a 9490@kindex x@r{(examine), and} info line
c906108c
SS
9491After @code{info line}, the default address for the @code{x} command
9492is changed to the starting address of the line, so that @samp{x/i} is
9493sufficient to begin examining the machine code (@pxref{Memory,
79a6e687 9494,Examining Memory}). Also, this address is saved as the value of the
c906108c 9495convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
79a6e687 9496Variables}).
c906108c 9497
db1ae9c5
AB
9498@cindex info line, repeated calls
9499After @code{info line}, using @code{info line} again without
9500specifying a location will display information about the next source
9501line.
9502
c906108c
SS
9503@table @code
9504@kindex disassemble
9505@cindex assembly instructions
9506@cindex instructions, assembly
9507@cindex machine instructions
9508@cindex listing machine instructions
9509@item disassemble
d14508fe 9510@itemx disassemble /m
6ff0ba5f 9511@itemx disassemble /s
9b117ef3 9512@itemx disassemble /r
c906108c 9513This specialized command dumps a range of memory as machine
d14508fe 9514instructions. It can also print mixed source+disassembly by specifying
6ff0ba5f
DE
9515the @code{/m} or @code{/s} modifier and print the raw instructions in hex
9516as well as in symbolic form by specifying the @code{/r} modifier.
d14508fe 9517The default memory range is the function surrounding the
c906108c
SS
9518program counter of the selected frame. A single argument to this
9519command is a program counter value; @value{GDBN} dumps the function
21a0512e
PP
9520surrounding this value. When two arguments are given, they should
9521be separated by a comma, possibly surrounded by whitespace. The
53a71c06
CR
9522arguments specify a range of addresses to dump, in one of two forms:
9523
9524@table @code
9525@item @var{start},@var{end}
9526the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9527@item @var{start},+@var{length}
9528the addresses from @var{start} (inclusive) to
9529@code{@var{start}+@var{length}} (exclusive).
9530@end table
9531
9532@noindent
9533When 2 arguments are specified, the name of the function is also
9534printed (since there could be several functions in the given range).
21a0512e
PP
9535
9536The argument(s) can be any expression yielding a numeric value, such as
9537@samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
2b28d209
PP
9538
9539If the range of memory being disassembled contains current program counter,
9540the instruction at that location is shown with a @code{=>} marker.
c906108c
SS
9541@end table
9542
c906108c
SS
9543The following example shows the disassembly of a range of addresses of
9544HP PA-RISC 2.0 code:
9545
9546@smallexample
21a0512e 9547(@value{GDBP}) disas 0x32c4, 0x32e4
c906108c 9548Dump of assembler code from 0x32c4 to 0x32e4:
2b28d209
PP
9549 0x32c4 <main+204>: addil 0,dp
9550 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
9551 0x32cc <main+212>: ldil 0x3000,r31
9552 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
9553 0x32d4 <main+220>: ldo 0(r31),rp
9554 0x32d8 <main+224>: addil -0x800,dp
9555 0x32dc <main+228>: ldo 0x588(r1),r26
9556 0x32e0 <main+232>: ldil 0x3000,r31
c906108c
SS
9557End of assembler dump.
9558@end smallexample
c906108c 9559
6ff0ba5f
DE
9560Here is an example showing mixed source+assembly for Intel x86
9561with @code{/m} or @code{/s}, when the program is stopped just after
9562function prologue in a non-optimized function with no inline code.
d14508fe
DE
9563
9564@smallexample
9565(@value{GDBP}) disas /m main
9566Dump of assembler code for function main:
95675 @{
9c419145
PP
9568 0x08048330 <+0>: push %ebp
9569 0x08048331 <+1>: mov %esp,%ebp
9570 0x08048333 <+3>: sub $0x8,%esp
9571 0x08048336 <+6>: and $0xfffffff0,%esp
9572 0x08048339 <+9>: sub $0x10,%esp
d14508fe
DE
9573
95746 printf ("Hello.\n");
9c419145
PP
9575=> 0x0804833c <+12>: movl $0x8048440,(%esp)
9576 0x08048343 <+19>: call 0x8048284 <puts@@plt>
d14508fe
DE
9577
95787 return 0;
95798 @}
9c419145
PP
9580 0x08048348 <+24>: mov $0x0,%eax
9581 0x0804834d <+29>: leave
9582 0x0804834e <+30>: ret
d14508fe
DE
9583
9584End of assembler dump.
9585@end smallexample
9586
6ff0ba5f
DE
9587The @code{/m} option is deprecated as its output is not useful when
9588there is either inlined code or re-ordered code.
9589The @code{/s} option is the preferred choice.
9590Here is an example for AMD x86-64 showing the difference between
9591@code{/m} output and @code{/s} output.
9592This example has one inline function defined in a header file,
9593and the code is compiled with @samp{-O2} optimization.
9594Note how the @code{/m} output is missing the disassembly of
9595several instructions that are present in the @code{/s} output.
9596
9597@file{foo.h}:
9598
9599@smallexample
9600int
9601foo (int a)
9602@{
9603 if (a < 0)
9604 return a * 2;
9605 if (a == 0)
9606 return 1;
9607 return a + 10;
9608@}
9609@end smallexample
9610
9611@file{foo.c}:
9612
9613@smallexample
9614#include "foo.h"
9615volatile int x, y;
9616int
9617main ()
9618@{
9619 x = foo (y);
9620 return 0;
9621@}
9622@end smallexample
9623
9624@smallexample
9625(@value{GDBP}) disas /m main
9626Dump of assembler code for function main:
96275 @{
9628
96296 x = foo (y);
9630 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9631 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9632
96337 return 0;
96348 @}
9635 0x000000000040041d <+29>: xor %eax,%eax
9636 0x000000000040041f <+31>: retq
9637 0x0000000000400420 <+32>: add %eax,%eax
9638 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9639
9640End of assembler dump.
9641(@value{GDBP}) disas /s main
9642Dump of assembler code for function main:
9643foo.c:
96445 @{
96456 x = foo (y);
9646 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9647
9648foo.h:
96494 if (a < 0)
9650 0x0000000000400406 <+6>: test %eax,%eax
9651 0x0000000000400408 <+8>: js 0x400420 <main+32>
9652
96536 if (a == 0)
96547 return 1;
96558 return a + 10;
9656 0x000000000040040a <+10>: lea 0xa(%rax),%edx
9657 0x000000000040040d <+13>: test %eax,%eax
9658 0x000000000040040f <+15>: mov $0x1,%eax
9659 0x0000000000400414 <+20>: cmovne %edx,%eax
9660
9661foo.c:
96626 x = foo (y);
9663 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9664
96657 return 0;
96668 @}
9667 0x000000000040041d <+29>: xor %eax,%eax
9668 0x000000000040041f <+31>: retq
9669
9670foo.h:
96715 return a * 2;
9672 0x0000000000400420 <+32>: add %eax,%eax
9673 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9674End of assembler dump.
9675@end smallexample
9676
53a71c06
CR
9677Here is another example showing raw instructions in hex for AMD x86-64,
9678
9679@smallexample
9680(gdb) disas /r 0x400281,+10
9681Dump of assembler code from 0x400281 to 0x40028b:
9682 0x0000000000400281: 38 36 cmp %dh,(%rsi)
9683 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
9684 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
9685 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
9686End of assembler dump.
9687@end smallexample
9688
629500fa 9689Addresses cannot be specified as a location (@pxref{Specify Location}).
7e1e0340
DE
9690So, for example, if you want to disassemble function @code{bar}
9691in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
9692and not @samp{disassemble foo.c:bar}.
9693
c906108c
SS
9694Some architectures have more than one commonly-used set of instruction
9695mnemonics or other syntax.
9696
76d17f34
EZ
9697For programs that were dynamically linked and use shared libraries,
9698instructions that call functions or branch to locations in the shared
9699libraries might show a seemingly bogus location---it's actually a
9700location of the relocation table. On some architectures, @value{GDBN}
9701might be able to resolve these to actual function names.
9702
65b48a81
PB
9703@table @code
9704@kindex set disassembler-options
9705@cindex disassembler options
9706@item set disassembler-options @var{option1}[,@var{option2}@dots{}]
9707This command controls the passing of target specific information to
9708the disassembler. For a list of valid options, please refer to the
9709@code{-M}/@code{--disassembler-options} section of the @samp{objdump}
9710manual and/or the output of @kbd{objdump --help}
f5a476a7 9711(@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
65b48a81
PB
9712The default value is the empty string.
9713
9714If it is necessary to specify more than one disassembler option, then
9715multiple options can be placed together into a comma separated list.
471b9d15 9716Currently this command is only supported on targets ARM, MIPS, PowerPC
65b48a81
PB
9717and S/390.
9718
9719@kindex show disassembler-options
9720@item show disassembler-options
9721Show the current setting of the disassembler options.
9722@end table
9723
c906108c 9724@table @code
d4f3574e 9725@kindex set disassembly-flavor
d4f3574e
SS
9726@cindex Intel disassembly flavor
9727@cindex AT&T disassembly flavor
9728@item set disassembly-flavor @var{instruction-set}
c906108c
SS
9729Select the instruction set to use when disassembling the
9730program via the @code{disassemble} or @code{x/i} commands.
9731
9732Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
9733can set @var{instruction-set} to either @code{intel} or @code{att}.
9734The default is @code{att}, the AT&T flavor used by default by Unix
9735assemblers for x86-based targets.
9c16f35a
EZ
9736
9737@kindex show disassembly-flavor
9738@item show disassembly-flavor
9739Show the current setting of the disassembly flavor.
c906108c
SS
9740@end table
9741
91440f57
HZ
9742@table @code
9743@kindex set disassemble-next-line
9744@kindex show disassemble-next-line
9745@item set disassemble-next-line
9746@itemx show disassemble-next-line
32ae1842
EZ
9747Control whether or not @value{GDBN} will disassemble the next source
9748line or instruction when execution stops. If ON, @value{GDBN} will
9749display disassembly of the next source line when execution of the
9750program being debugged stops. This is @emph{in addition} to
9751displaying the source line itself, which @value{GDBN} always does if
9752possible. If the next source line cannot be displayed for some reason
9753(e.g., if @value{GDBN} cannot find the source file, or there's no line
9754info in the debug info), @value{GDBN} will display disassembly of the
9755next @emph{instruction} instead of showing the next source line. If
9756AUTO, @value{GDBN} will display disassembly of next instruction only
9757if the source line cannot be displayed. This setting causes
9758@value{GDBN} to display some feedback when you step through a function
9759with no line info or whose source file is unavailable. The default is
9760OFF, which means never display the disassembly of the next line or
9761instruction.
91440f57
HZ
9762@end table
9763
c906108c 9764
6d2ebf8b 9765@node Data
c906108c
SS
9766@chapter Examining Data
9767
9768@cindex printing data
9769@cindex examining data
9770@kindex print
9771@kindex inspect
c906108c 9772The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
9773command (abbreviated @code{p}), or its synonym @code{inspect}. It
9774evaluates and prints the value of an expression of the language your
9775program is written in (@pxref{Languages, ,Using @value{GDBN} with
78e2826b
TT
9776Different Languages}). It may also print the expression using a
9777Python-based pretty-printer (@pxref{Pretty Printing}).
c906108c
SS
9778
9779@table @code
3345721a
PA
9780@item print [[@var{options}] --] @var{expr}
9781@itemx print [[@var{options}] --] /@var{f} @var{expr}
d4f3574e
SS
9782@var{expr} is an expression (in the source language). By default the
9783value of @var{expr} is printed in a format appropriate to its data type;
c906108c 9784you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 9785@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
79a6e687 9786Formats}.
c906108c 9787
3345721a
PA
9788@anchor{print options}
9789The @code{print} command supports a number of options that allow
9790overriding relevant global print settings as set by @code{set print}
9791subcommands:
9792
9793@table @code
9794@item -address [@code{on}|@code{off}]
9795Set printing of addresses.
9796Related setting: @ref{set print address}.
9797
9798@item -array [@code{on}|@code{off}]
9799Pretty formatting of arrays.
9800Related setting: @ref{set print array}.
9801
9802@item -array-indexes [@code{on}|@code{off}]
9803Set printing of array indexes.
9804Related setting: @ref{set print array-indexes}.
9805
9806@item -elements @var{number-of-elements}|@code{unlimited}
9807Set limit on string chars or array elements to print. The value
9808@code{unlimited} causes there to be no limit. Related setting:
9809@ref{set print elements}.
9810
9811@item -max-depth @var{depth}|@code{unlimited}
9812Set the threshold after which nested structures are replaced with
9813ellipsis. Related setting: @ref{set print max-depth}.
9814
9815@item -null-stop [@code{on}|@code{off}]
9816Set printing of char arrays to stop at first null char. Related
9817setting: @ref{set print null-stop}.
9818
9819@item -object [@code{on}|@code{off}]
9820Set printing C@t{++} virtual function tables. Related setting:
9821@ref{set print object}.
9822
9823@item -pretty [@code{on}|@code{off}]
9824Set pretty formatting of structures. Related setting: @ref{set print
9825pretty}.
9826
d8edc8b7
PW
9827@item -raw-values [@code{on}|@code{off}]
9828Set whether to print values in raw form, bypassing any
9829pretty-printers for that value. Related setting: @ref{set print
9830raw-values}.
9831
3345721a
PA
9832@item -repeats @var{number-of-repeats}|@code{unlimited}
9833Set threshold for repeated print elements. @code{unlimited} causes
9834all elements to be individually printed. Related setting: @ref{set
9835print repeats}.
9836
9837@item -static-members [@code{on}|@code{off}]
9838Set printing C@t{++} static members. Related setting: @ref{set print
9839static-members}.
9840
9841@item -symbol [@code{on}|@code{off}]
9842Set printing of symbol names when printing pointers. Related setting:
9843@ref{set print symbol}.
9844
9845@item -union [@code{on}|@code{off}]
9846Set printing of unions interior to structures. Related setting:
9847@ref{set print union}.
9848
9849@item -vtbl [@code{on}|@code{off}]
9850Set printing of C++ virtual function tables. Related setting:
9851@ref{set print vtbl}.
9852@end table
9853
9854Because the @code{print} command accepts arbitrary expressions which
9855may look like options (including abbreviations), if you specify any
9856command option, then you must use a double dash (@code{--}) to mark
9857the end of option processing.
9858
d8edc8b7 9859For example, this prints the value of the @code{-p} expression:
3345721a
PA
9860
9861@smallexample
d8edc8b7 9862(@value{GDBP}) print -p
3345721a
PA
9863@end smallexample
9864
9865While this repeats the last value in the value history (see below)
d8edc8b7 9866with the @code{-pretty} option in effect:
3345721a
PA
9867
9868@smallexample
d8edc8b7 9869(@value{GDBP}) print -p --
3345721a
PA
9870@end smallexample
9871
9872Here is an example including both on option and an expression:
9873
9874@smallexample
9875@group
9876(@value{GDBP}) print -pretty -- *myptr
9877$1 = @{
9878 next = 0x0,
9879 flags = @{
9880 sweet = 1,
9881 sour = 1
9882 @},
9883 meat = 0x54 "Pork"
9884@}
9885@end group
9886@end smallexample
9887
9888@item print [@var{options}]
9889@itemx print [@var{options}] /@var{f}
15387254 9890@cindex reprint the last value
d4f3574e 9891If you omit @var{expr}, @value{GDBN} displays the last value again (from the
79a6e687 9892@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
c906108c
SS
9893conveniently inspect the same value in an alternative format.
9894@end table
9895
9896A more low-level way of examining data is with the @code{x} command.
9897It examines data in memory at a specified address and prints it in a
79a6e687 9898specified format. @xref{Memory, ,Examining Memory}.
c906108c 9899
7a292a7a 9900If you are interested in information about types, or about how the
d4f3574e
SS
9901fields of a struct or a class are declared, use the @code{ptype @var{exp}}
9902command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 9903Table}.
c906108c 9904
06fc020f
SCR
9905@cindex exploring hierarchical data structures
9906@kindex explore
9907Another way of examining values of expressions and type information is
9908through the Python extension command @code{explore} (available only if
9909the @value{GDBN} build is configured with @code{--with-python}). It
9910offers an interactive way to start at the highest level (or, the most
9911abstract level) of the data type of an expression (or, the data type
9912itself) and explore all the way down to leaf scalar values/fields
9913embedded in the higher level data types.
9914
9915@table @code
9916@item explore @var{arg}
9917@var{arg} is either an expression (in the source language), or a type
9918visible in the current context of the program being debugged.
9919@end table
9920
9921The working of the @code{explore} command can be illustrated with an
9922example. If a data type @code{struct ComplexStruct} is defined in your
9923C program as
9924
9925@smallexample
9926struct SimpleStruct
9927@{
9928 int i;
9929 double d;
9930@};
9931
9932struct ComplexStruct
9933@{
9934 struct SimpleStruct *ss_p;
9935 int arr[10];
9936@};
9937@end smallexample
9938
9939@noindent
9940followed by variable declarations as
9941
9942@smallexample
9943struct SimpleStruct ss = @{ 10, 1.11 @};
9944struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
9945@end smallexample
9946
9947@noindent
9948then, the value of the variable @code{cs} can be explored using the
9949@code{explore} command as follows.
9950
9951@smallexample
9952(gdb) explore cs
9953The value of `cs' is a struct/class of type `struct ComplexStruct' with
9954the following fields:
9955
9956 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
9957 arr = <Enter 1 to explore this field of type `int [10]'>
9958
9959Enter the field number of choice:
9960@end smallexample
9961
9962@noindent
9963Since the fields of @code{cs} are not scalar values, you are being
9964prompted to chose the field you want to explore. Let's say you choose
9965the field @code{ss_p} by entering @code{0}. Then, since this field is a
9966pointer, you will be asked if it is pointing to a single value. From
9967the declaration of @code{cs} above, it is indeed pointing to a single
9968value, hence you enter @code{y}. If you enter @code{n}, then you will
9969be asked if it were pointing to an array of values, in which case this
9970field will be explored as if it were an array.
9971
9972@smallexample
9973`cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
9974Continue exploring it as a pointer to a single value [y/n]: y
9975The value of `*(cs.ss_p)' is a struct/class of type `struct
9976SimpleStruct' with the following fields:
9977
9978 i = 10 .. (Value of type `int')
9979 d = 1.1100000000000001 .. (Value of type `double')
9980
9981Press enter to return to parent value:
9982@end smallexample
9983
9984@noindent
9985If the field @code{arr} of @code{cs} was chosen for exploration by
9986entering @code{1} earlier, then since it is as array, you will be
9987prompted to enter the index of the element in the array that you want
9988to explore.
9989
9990@smallexample
9991`cs.arr' is an array of `int'.
9992Enter the index of the element you want to explore in `cs.arr': 5
9993
9994`(cs.arr)[5]' is a scalar value of type `int'.
9995
9996(cs.arr)[5] = 4
9997
9998Press enter to return to parent value:
9999@end smallexample
10000
10001In general, at any stage of exploration, you can go deeper towards the
10002leaf values by responding to the prompts appropriately, or hit the
10003return key to return to the enclosing data structure (the @i{higher}
10004level data structure).
10005
10006Similar to exploring values, you can use the @code{explore} command to
10007explore types. Instead of specifying a value (which is typically a
10008variable name or an expression valid in the current context of the
10009program being debugged), you specify a type name. If you consider the
10010same example as above, your can explore the type
10011@code{struct ComplexStruct} by passing the argument
10012@code{struct ComplexStruct} to the @code{explore} command.
10013
10014@smallexample
10015(gdb) explore struct ComplexStruct
10016@end smallexample
10017
10018@noindent
10019By responding to the prompts appropriately in the subsequent interactive
10020session, you can explore the type @code{struct ComplexStruct} in a
10021manner similar to how the value @code{cs} was explored in the above
10022example.
10023
10024The @code{explore} command also has two sub-commands,
10025@code{explore value} and @code{explore type}. The former sub-command is
10026a way to explicitly specify that value exploration of the argument is
10027being invoked, while the latter is a way to explicitly specify that type
10028exploration of the argument is being invoked.
10029
10030@table @code
10031@item explore value @var{expr}
10032@cindex explore value
10033This sub-command of @code{explore} explores the value of the
10034expression @var{expr} (if @var{expr} is an expression valid in the
10035current context of the program being debugged). The behavior of this
10036command is identical to that of the behavior of the @code{explore}
10037command being passed the argument @var{expr}.
10038
10039@item explore type @var{arg}
10040@cindex explore type
10041This sub-command of @code{explore} explores the type of @var{arg} (if
10042@var{arg} is a type visible in the current context of program being
10043debugged), or the type of the value/expression @var{arg} (if @var{arg}
10044is an expression valid in the current context of the program being
10045debugged). If @var{arg} is a type, then the behavior of this command is
10046identical to that of the @code{explore} command being passed the
10047argument @var{arg}. If @var{arg} is an expression, then the behavior of
10048this command will be identical to that of the @code{explore} command
10049being passed the type of @var{arg} as the argument.
10050@end table
10051
c906108c
SS
10052@menu
10053* Expressions:: Expressions
6ba66d6a 10054* Ambiguous Expressions:: Ambiguous Expressions
c906108c
SS
10055* Variables:: Program variables
10056* Arrays:: Artificial arrays
10057* Output Formats:: Output formats
10058* Memory:: Examining memory
10059* Auto Display:: Automatic display
10060* Print Settings:: Print settings
4c374409 10061* Pretty Printing:: Python pretty printing
c906108c
SS
10062* Value History:: Value history
10063* Convenience Vars:: Convenience variables
a72c3253 10064* Convenience Funs:: Convenience functions
c906108c 10065* Registers:: Registers
c906108c 10066* Floating Point Hardware:: Floating point hardware
53c69bd7 10067* Vector Unit:: Vector Unit
721c2651 10068* OS Information:: Auxiliary data provided by operating system
29e57380 10069* Memory Region Attributes:: Memory region attributes
16d9dec6 10070* Dump/Restore Files:: Copy between memory and a file
384ee23f 10071* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
10072* Character Sets:: Debugging programs that use a different
10073 character set than GDB does
b12039c6 10074* Caching Target Data:: Data caching for targets
08388c79 10075* Searching Memory:: Searching memory for a sequence of bytes
5fdf6324 10076* Value Sizes:: Managing memory allocated for values
c906108c
SS
10077@end menu
10078
6d2ebf8b 10079@node Expressions
c906108c
SS
10080@section Expressions
10081
10082@cindex expressions
10083@code{print} and many other @value{GDBN} commands accept an expression and
10084compute its value. Any kind of constant, variable or operator defined
10085by the programming language you are using is valid in an expression in
e2e0bcd1
JB
10086@value{GDBN}. This includes conditional expressions, function calls,
10087casts, and string constants. It also includes preprocessor macros, if
10088you compiled your program to include this information; see
10089@ref{Compilation}.
c906108c 10090
15387254 10091@cindex arrays in expressions
d4f3574e
SS
10092@value{GDBN} supports array constants in expressions input by
10093the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
63092375
DJ
10094you can use the command @code{print @{1, 2, 3@}} to create an array
10095of three integers. If you pass an array to a function or assign it
10096to a program variable, @value{GDBN} copies the array to memory that
10097is @code{malloc}ed in the target program.
c906108c 10098
c906108c
SS
10099Because C is so widespread, most of the expressions shown in examples in
10100this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
10101Languages}, for information on how to use expressions in other
10102languages.
10103
10104In this section, we discuss operators that you can use in @value{GDBN}
10105expressions regardless of your programming language.
10106
15387254 10107@cindex casts, in expressions
c906108c
SS
10108Casts are supported in all languages, not just in C, because it is so
10109useful to cast a number into a pointer in order to examine a structure
10110at that address in memory.
10111@c FIXME: casts supported---Mod2 true?
c906108c
SS
10112
10113@value{GDBN} supports these operators, in addition to those common
10114to programming languages:
10115
10116@table @code
10117@item @@
10118@samp{@@} is a binary operator for treating parts of memory as arrays.
79a6e687 10119@xref{Arrays, ,Artificial Arrays}, for more information.
c906108c
SS
10120
10121@item ::
10122@samp{::} allows you to specify a variable in terms of the file or
79a6e687 10123function where it is defined. @xref{Variables, ,Program Variables}.
c906108c
SS
10124
10125@cindex @{@var{type}@}
10126@cindex type casting memory
10127@cindex memory, viewing as typed object
10128@cindex casts, to view memory
10129@item @{@var{type}@} @var{addr}
10130Refers to an object of type @var{type} stored at address @var{addr} in
697aa1b7
EZ
10131memory. The address @var{addr} may be any expression whose value is
10132an integer or pointer (but parentheses are required around binary
10133operators, just as in a cast). This construct is allowed regardless
10134of what kind of data is normally supposed to reside at @var{addr}.
c906108c
SS
10135@end table
10136
6ba66d6a
JB
10137@node Ambiguous Expressions
10138@section Ambiguous Expressions
10139@cindex ambiguous expressions
10140
10141Expressions can sometimes contain some ambiguous elements. For instance,
10142some programming languages (notably Ada, C@t{++} and Objective-C) permit
10143a single function name to be defined several times, for application in
10144different contexts. This is called @dfn{overloading}. Another example
10145involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
10146templates and is typically instantiated several times, resulting in
10147the same function name being defined in different contexts.
10148
10149In some cases and depending on the language, it is possible to adjust
10150the expression to remove the ambiguity. For instance in C@t{++}, you
10151can specify the signature of the function you want to break on, as in
10152@kbd{break @var{function}(@var{types})}. In Ada, using the fully
10153qualified name of your function often makes the expression unambiguous
10154as well.
10155
10156When an ambiguity that needs to be resolved is detected, the debugger
10157has the capability to display a menu of numbered choices for each
10158possibility, and then waits for the selection with the prompt @samp{>}.
10159The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
10160aborts the current command. If the command in which the expression was
10161used allows more than one choice to be selected, the next option in the
10162menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
10163choices.
10164
10165For example, the following session excerpt shows an attempt to set a
10166breakpoint at the overloaded symbol @code{String::after}.
10167We choose three particular definitions of that function name:
10168
10169@c FIXME! This is likely to change to show arg type lists, at least
10170@smallexample
10171@group
10172(@value{GDBP}) b String::after
10173[0] cancel
10174[1] all
10175[2] file:String.cc; line number:867
10176[3] file:String.cc; line number:860
10177[4] file:String.cc; line number:875
10178[5] file:String.cc; line number:853
10179[6] file:String.cc; line number:846
10180[7] file:String.cc; line number:735
10181> 2 4 6
10182Breakpoint 1 at 0xb26c: file String.cc, line 867.
10183Breakpoint 2 at 0xb344: file String.cc, line 875.
10184Breakpoint 3 at 0xafcc: file String.cc, line 846.
10185Multiple breakpoints were set.
10186Use the "delete" command to delete unwanted
10187 breakpoints.
10188(@value{GDBP})
10189@end group
10190@end smallexample
10191
10192@table @code
10193@kindex set multiple-symbols
10194@item set multiple-symbols @var{mode}
10195@cindex multiple-symbols menu
10196
10197This option allows you to adjust the debugger behavior when an expression
10198is ambiguous.
10199
10200By default, @var{mode} is set to @code{all}. If the command with which
10201the expression is used allows more than one choice, then @value{GDBN}
10202automatically selects all possible choices. For instance, inserting
10203a breakpoint on a function using an ambiguous name results in a breakpoint
10204inserted on each possible match. However, if a unique choice must be made,
10205then @value{GDBN} uses the menu to help you disambiguate the expression.
10206For instance, printing the address of an overloaded function will result
10207in the use of the menu.
10208
10209When @var{mode} is set to @code{ask}, the debugger always uses the menu
10210when an ambiguity is detected.
10211
10212Finally, when @var{mode} is set to @code{cancel}, the debugger reports
10213an error due to the ambiguity and the command is aborted.
10214
10215@kindex show multiple-symbols
10216@item show multiple-symbols
10217Show the current value of the @code{multiple-symbols} setting.
10218@end table
10219
6d2ebf8b 10220@node Variables
79a6e687 10221@section Program Variables
c906108c
SS
10222
10223The most common kind of expression to use is the name of a variable
10224in your program.
10225
10226Variables in expressions are understood in the selected stack frame
79a6e687 10227(@pxref{Selection, ,Selecting a Frame}); they must be either:
c906108c
SS
10228
10229@itemize @bullet
10230@item
10231global (or file-static)
10232@end itemize
10233
5d161b24 10234@noindent or
c906108c
SS
10235
10236@itemize @bullet
10237@item
10238visible according to the scope rules of the
10239programming language from the point of execution in that frame
5d161b24 10240@end itemize
c906108c
SS
10241
10242@noindent This means that in the function
10243
474c8240 10244@smallexample
c906108c
SS
10245foo (a)
10246 int a;
10247@{
10248 bar (a);
10249 @{
10250 int b = test ();
10251 bar (b);
10252 @}
10253@}
474c8240 10254@end smallexample
c906108c
SS
10255
10256@noindent
10257you can examine and use the variable @code{a} whenever your program is
10258executing within the function @code{foo}, but you can only use or
10259examine the variable @code{b} while your program is executing inside
10260the block where @code{b} is declared.
10261
10262@cindex variable name conflict
10263There is an exception: you can refer to a variable or function whose
10264scope is a single source file even if the current execution point is not
10265in this file. But it is possible to have more than one such variable or
10266function with the same name (in different source files). If that
10267happens, referring to that name has unpredictable effects. If you wish,
72384ba3 10268you can specify a static variable in a particular function or file by
15387254 10269using the colon-colon (@code{::}) notation:
c906108c 10270
d4f3574e 10271@cindex colon-colon, context for variables/functions
12c27660 10272@ifnotinfo
c906108c 10273@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 10274@cindex @code{::}, context for variables/functions
12c27660 10275@end ifnotinfo
474c8240 10276@smallexample
c906108c
SS
10277@var{file}::@var{variable}
10278@var{function}::@var{variable}
474c8240 10279@end smallexample
c906108c
SS
10280
10281@noindent
10282Here @var{file} or @var{function} is the name of the context for the
10283static @var{variable}. In the case of file names, you can use quotes to
10284make sure @value{GDBN} parses the file name as a single word---for example,
10285to print a global value of @code{x} defined in @file{f2.c}:
10286
474c8240 10287@smallexample
c906108c 10288(@value{GDBP}) p 'f2.c'::x
474c8240 10289@end smallexample
c906108c 10290
72384ba3
PH
10291The @code{::} notation is normally used for referring to
10292static variables, since you typically disambiguate uses of local variables
10293in functions by selecting the appropriate frame and using the
10294simple name of the variable. However, you may also use this notation
10295to refer to local variables in frames enclosing the selected frame:
10296
10297@smallexample
10298void
10299foo (int a)
10300@{
10301 if (a < 10)
10302 bar (a);
10303 else
10304 process (a); /* Stop here */
10305@}
10306
10307int
10308bar (int a)
10309@{
10310 foo (a + 5);
10311@}
10312@end smallexample
10313
10314@noindent
10315For example, if there is a breakpoint at the commented line,
10316here is what you might see
10317when the program stops after executing the call @code{bar(0)}:
10318
10319@smallexample
10320(@value{GDBP}) p a
10321$1 = 10
10322(@value{GDBP}) p bar::a
10323$2 = 5
10324(@value{GDBP}) up 2
10325#2 0x080483d0 in foo (a=5) at foobar.c:12
10326(@value{GDBP}) p a
10327$3 = 5
10328(@value{GDBP}) p bar::a
10329$4 = 0
10330@end smallexample
10331
b37052ae 10332@cindex C@t{++} scope resolution
805e1f19
TT
10333These uses of @samp{::} are very rarely in conflict with the very
10334similar use of the same notation in C@t{++}. When they are in
10335conflict, the C@t{++} meaning takes precedence; however, this can be
10336overridden by quoting the file or function name with single quotes.
10337
10338For example, suppose the program is stopped in a method of a class
10339that has a field named @code{includefile}, and there is also an
10340include file named @file{includefile} that defines a variable,
10341@code{some_global}.
10342
10343@smallexample
10344(@value{GDBP}) p includefile
10345$1 = 23
10346(@value{GDBP}) p includefile::some_global
10347A syntax error in expression, near `'.
10348(@value{GDBP}) p 'includefile'::some_global
10349$2 = 27
10350@end smallexample
c906108c
SS
10351
10352@cindex wrong values
10353@cindex variable values, wrong
15387254
EZ
10354@cindex function entry/exit, wrong values of variables
10355@cindex optimized code, wrong values of variables
c906108c
SS
10356@quotation
10357@emph{Warning:} Occasionally, a local variable may appear to have the
10358wrong value at certain points in a function---just after entry to a new
10359scope, and just before exit.
10360@end quotation
10361You may see this problem when you are stepping by machine instructions.
10362This is because, on most machines, it takes more than one instruction to
10363set up a stack frame (including local variable definitions); if you are
10364stepping by machine instructions, variables may appear to have the wrong
10365values until the stack frame is completely built. On exit, it usually
10366also takes more than one machine instruction to destroy a stack frame;
10367after you begin stepping through that group of instructions, local
10368variable definitions may be gone.
10369
10370This may also happen when the compiler does significant optimizations.
10371To be sure of always seeing accurate values, turn off all optimization
10372when compiling.
10373
d4f3574e
SS
10374@cindex ``No symbol "foo" in current context''
10375Another possible effect of compiler optimizations is to optimize
10376unused variables out of existence, or assign variables to registers (as
10377opposed to memory addresses). Depending on the support for such cases
10378offered by the debug info format used by the compiler, @value{GDBN}
10379might not be able to display values for such local variables. If that
10380happens, @value{GDBN} will print a message like this:
10381
474c8240 10382@smallexample
d4f3574e 10383No symbol "foo" in current context.
474c8240 10384@end smallexample
d4f3574e
SS
10385
10386To solve such problems, either recompile without optimizations, or use a
10387different debug info format, if the compiler supports several such
e0f8f636
TT
10388formats. @xref{Compilation}, for more information on choosing compiler
10389options. @xref{C, ,C and C@t{++}}, for more information about debug
10390info formats that are best suited to C@t{++} programs.
d4f3574e 10391
ab1adacd
EZ
10392If you ask to print an object whose contents are unknown to
10393@value{GDBN}, e.g., because its data type is not completely specified
10394by the debug information, @value{GDBN} will say @samp{<incomplete
10395type>}. @xref{Symbols, incomplete type}, for more about this.
10396
d69cf9b2
PA
10397@cindex no debug info variables
10398If you try to examine or use the value of a (global) variable for
10399which @value{GDBN} has no type information, e.g., because the program
10400includes no debug information, @value{GDBN} displays an error message.
10401@xref{Symbols, unknown type}, for more about unknown types. If you
10402cast the variable to its declared type, @value{GDBN} gets the
10403variable's value using the cast-to type as the variable's type. For
10404example, in a C program:
10405
10406@smallexample
10407 (@value{GDBP}) p var
10408 'var' has unknown type; cast it to its declared type
10409 (@value{GDBP}) p (float) var
10410 $1 = 3.14
10411@end smallexample
10412
36b11add
JK
10413If you append @kbd{@@entry} string to a function parameter name you get its
10414value at the time the function got called. If the value is not available an
10415error message is printed. Entry values are available only with some compilers.
10416Entry values are normally also printed at the function parameter list according
10417to @ref{set print entry-values}.
10418
10419@smallexample
10420Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
1042129 i++;
10422(gdb) next
1042330 e (i);
10424(gdb) print i
10425$1 = 31
10426(gdb) print i@@entry
10427$2 = 30
10428@end smallexample
10429
3a60f64e
JK
10430Strings are identified as arrays of @code{char} values without specified
10431signedness. Arrays of either @code{signed char} or @code{unsigned char} get
10432printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
10433@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
10434defines literal string type @code{"char"} as @code{char} without a sign.
10435For program code
10436
10437@smallexample
10438char var0[] = "A";
10439signed char var1[] = "A";
10440@end smallexample
10441
10442You get during debugging
10443@smallexample
10444(gdb) print var0
10445$1 = "A"
10446(gdb) print var1
10447$2 = @{65 'A', 0 '\0'@}
10448@end smallexample
10449
6d2ebf8b 10450@node Arrays
79a6e687 10451@section Artificial Arrays
c906108c
SS
10452
10453@cindex artificial array
15387254 10454@cindex arrays
41afff9a 10455@kindex @@@r{, referencing memory as an array}
c906108c
SS
10456It is often useful to print out several successive objects of the
10457same type in memory; a section of an array, or an array of
10458dynamically determined size for which only a pointer exists in the
10459program.
10460
10461You can do this by referring to a contiguous span of memory as an
10462@dfn{artificial array}, using the binary operator @samp{@@}. The left
10463operand of @samp{@@} should be the first element of the desired array
10464and be an individual object. The right operand should be the desired length
10465of the array. The result is an array value whose elements are all of
10466the type of the left argument. The first element is actually the left
10467argument; the second element comes from bytes of memory immediately
10468following those that hold the first element, and so on. Here is an
10469example. If a program says
10470
474c8240 10471@smallexample
c906108c 10472int *array = (int *) malloc (len * sizeof (int));
474c8240 10473@end smallexample
c906108c
SS
10474
10475@noindent
10476you can print the contents of @code{array} with
10477
474c8240 10478@smallexample
c906108c 10479p *array@@len
474c8240 10480@end smallexample
c906108c
SS
10481
10482The left operand of @samp{@@} must reside in memory. Array values made
10483with @samp{@@} in this way behave just like other arrays in terms of
10484subscripting, and are coerced to pointers when used in expressions.
10485Artificial arrays most often appear in expressions via the value history
79a6e687 10486(@pxref{Value History, ,Value History}), after printing one out.
c906108c
SS
10487
10488Another way to create an artificial array is to use a cast.
10489This re-interprets a value as if it were an array.
10490The value need not be in memory:
474c8240 10491@smallexample
c906108c
SS
10492(@value{GDBP}) p/x (short[2])0x12345678
10493$1 = @{0x1234, 0x5678@}
474c8240 10494@end smallexample
c906108c
SS
10495
10496As a convenience, if you leave the array length out (as in
c3f6f71d 10497@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 10498the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 10499@smallexample
c906108c
SS
10500(@value{GDBP}) p/x (short[])0x12345678
10501$2 = @{0x1234, 0x5678@}
474c8240 10502@end smallexample
c906108c
SS
10503
10504Sometimes the artificial array mechanism is not quite enough; in
10505moderately complex data structures, the elements of interest may not
10506actually be adjacent---for example, if you are interested in the values
10507of pointers in an array. One useful work-around in this situation is
10508to use a convenience variable (@pxref{Convenience Vars, ,Convenience
79a6e687 10509Variables}) as a counter in an expression that prints the first
c906108c
SS
10510interesting value, and then repeat that expression via @key{RET}. For
10511instance, suppose you have an array @code{dtab} of pointers to
10512structures, and you are interested in the values of a field @code{fv}
10513in each structure. Here is an example of what you might type:
10514
474c8240 10515@smallexample
c906108c
SS
10516set $i = 0
10517p dtab[$i++]->fv
10518@key{RET}
10519@key{RET}
10520@dots{}
474c8240 10521@end smallexample
c906108c 10522
6d2ebf8b 10523@node Output Formats
79a6e687 10524@section Output Formats
c906108c
SS
10525
10526@cindex formatted output
10527@cindex output formats
10528By default, @value{GDBN} prints a value according to its data type. Sometimes
10529this is not what you want. For example, you might want to print a number
10530in hex, or a pointer in decimal. Or you might want to view data in memory
10531at a certain address as a character string or as an instruction. To do
10532these things, specify an @dfn{output format} when you print a value.
10533
10534The simplest use of output formats is to say how to print a value
10535already computed. This is done by starting the arguments of the
10536@code{print} command with a slash and a format letter. The format
10537letters supported are:
10538
10539@table @code
10540@item x
10541Regard the bits of the value as an integer, and print the integer in
10542hexadecimal.
10543
10544@item d
10545Print as integer in signed decimal.
10546
10547@item u
10548Print as integer in unsigned decimal.
10549
10550@item o
10551Print as integer in octal.
10552
10553@item t
10554Print as integer in binary. The letter @samp{t} stands for ``two''.
10555@footnote{@samp{b} cannot be used because these format letters are also
10556used with the @code{x} command, where @samp{b} stands for ``byte'';
79a6e687 10557see @ref{Memory,,Examining Memory}.}
c906108c
SS
10558
10559@item a
10560@cindex unknown address, locating
3d67e040 10561@cindex locate address
c906108c
SS
10562Print as an address, both absolute in hexadecimal and as an offset from
10563the nearest preceding symbol. You can use this format used to discover
10564where (in what function) an unknown address is located:
10565
474c8240 10566@smallexample
c906108c
SS
10567(@value{GDBP}) p/a 0x54320
10568$3 = 0x54320 <_initialize_vx+396>
474c8240 10569@end smallexample
c906108c 10570
3d67e040
EZ
10571@noindent
10572The command @code{info symbol 0x54320} yields similar results.
10573@xref{Symbols, info symbol}.
10574
c906108c 10575@item c
51274035
EZ
10576Regard as an integer and print it as a character constant. This
10577prints both the numerical value and its character representation. The
10578character representation is replaced with the octal escape @samp{\nnn}
10579for characters outside the 7-bit @sc{ascii} range.
c906108c 10580
ea37ba09
DJ
10581Without this format, @value{GDBN} displays @code{char},
10582@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
10583constants. Single-byte members of vectors are displayed as integer
10584data.
10585
c906108c
SS
10586@item f
10587Regard the bits of the value as a floating point number and print
10588using typical floating point syntax.
ea37ba09
DJ
10589
10590@item s
10591@cindex printing strings
10592@cindex printing byte arrays
10593Regard as a string, if possible. With this format, pointers to single-byte
10594data are displayed as null-terminated strings and arrays of single-byte data
10595are displayed as fixed-length strings. Other values are displayed in their
10596natural types.
10597
10598Without this format, @value{GDBN} displays pointers to and arrays of
10599@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
10600strings. Single-byte members of a vector are displayed as an integer
10601array.
a6bac58e 10602
6fbe845e
AB
10603@item z
10604Like @samp{x} formatting, the value is treated as an integer and
10605printed as hexadecimal, but leading zeros are printed to pad the value
10606to the size of the integer type.
10607
a6bac58e
TT
10608@item r
10609@cindex raw printing
10610Print using the @samp{raw} formatting. By default, @value{GDBN} will
78e2826b
TT
10611use a Python-based pretty-printer, if one is available (@pxref{Pretty
10612Printing}). This typically results in a higher-level display of the
10613value's contents. The @samp{r} format bypasses any Python
10614pretty-printer which might exist.
c906108c
SS
10615@end table
10616
10617For example, to print the program counter in hex (@pxref{Registers}), type
10618
474c8240 10619@smallexample
c906108c 10620p/x $pc
474c8240 10621@end smallexample
c906108c
SS
10622
10623@noindent
10624Note that no space is required before the slash; this is because command
10625names in @value{GDBN} cannot contain a slash.
10626
10627To reprint the last value in the value history with a different format,
10628you can use the @code{print} command with just a format and no
10629expression. For example, @samp{p/x} reprints the last value in hex.
10630
6d2ebf8b 10631@node Memory
79a6e687 10632@section Examining Memory
c906108c
SS
10633
10634You can use the command @code{x} (for ``examine'') to examine memory in
10635any of several formats, independently of your program's data types.
10636
10637@cindex examining memory
10638@table @code
41afff9a 10639@kindex x @r{(examine memory)}
c906108c
SS
10640@item x/@var{nfu} @var{addr}
10641@itemx x @var{addr}
10642@itemx x
10643Use the @code{x} command to examine memory.
10644@end table
10645
10646@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
10647much memory to display and how to format it; @var{addr} is an
10648expression giving the address where you want to start displaying memory.
10649If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
10650Several commands set convenient defaults for @var{addr}.
10651
10652@table @r
10653@item @var{n}, the repeat count
10654The repeat count is a decimal integer; the default is 1. It specifies
bb556f1f
TK
10655how much memory (counting by units @var{u}) to display. If a negative
10656number is specified, memory is examined backward from @var{addr}.
c906108c
SS
10657@c This really is **decimal**; unaffected by 'set radix' as of GDB
10658@c 4.1.2.
10659
10660@item @var{f}, the display format
51274035
EZ
10661The display format is one of the formats used by @code{print}
10662(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
ea37ba09
DJ
10663@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
10664The default is @samp{x} (hexadecimal) initially. The default changes
10665each time you use either @code{x} or @code{print}.
c906108c
SS
10666
10667@item @var{u}, the unit size
10668The unit size is any of
10669
10670@table @code
10671@item b
10672Bytes.
10673@item h
10674Halfwords (two bytes).
10675@item w
10676Words (four bytes). This is the initial default.
10677@item g
10678Giant words (eight bytes).
10679@end table
10680
10681Each time you specify a unit size with @code{x}, that size becomes the
9a22f0d0
PM
10682default unit the next time you use @code{x}. For the @samp{i} format,
10683the unit size is ignored and is normally not written. For the @samp{s} format,
10684the unit size defaults to @samp{b}, unless it is explicitly given.
10685Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
1068632-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
10687Note that the results depend on the programming language of the
10688current compilation unit. If the language is C, the @samp{s}
10689modifier will use the UTF-16 encoding while @samp{w} will use
10690UTF-32. The encoding is set by the programming language and cannot
10691be altered.
c906108c
SS
10692
10693@item @var{addr}, starting display address
10694@var{addr} is the address where you want @value{GDBN} to begin displaying
10695memory. The expression need not have a pointer value (though it may);
10696it is always interpreted as an integer address of a byte of memory.
10697@xref{Expressions, ,Expressions}, for more information on expressions. The default for
10698@var{addr} is usually just after the last address examined---but several
10699other commands also set the default address: @code{info breakpoints} (to
10700the address of the last breakpoint listed), @code{info line} (to the
10701starting address of a line), and @code{print} (if you use it to display
10702a value from memory).
10703@end table
10704
10705For example, @samp{x/3uh 0x54320} is a request to display three halfwords
10706(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
10707starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
10708words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 10709@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c 10710
bb556f1f
TK
10711You can also specify a negative repeat count to examine memory backward
10712from the given address. For example, @samp{x/-3uh 0x54320} prints three
10713halfwords (@code{h}) at @code{0x54314}, @code{0x54328}, and @code{0x5431c}.
10714
c906108c
SS
10715Since the letters indicating unit sizes are all distinct from the
10716letters specifying output formats, you do not have to remember whether
10717unit size or format comes first; either order works. The output
10718specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
10719(However, the count @var{n} must come first; @samp{wx4} does not work.)
10720
10721Even though the unit size @var{u} is ignored for the formats @samp{s}
10722and @samp{i}, you might still want to use a count @var{n}; for example,
10723@samp{3i} specifies that you want to see three machine instructions,
a4642986
MR
10724including any operands. For convenience, especially when used with
10725the @code{display} command, the @samp{i} format also prints branch delay
10726slot instructions, if any, beyond the count specified, which immediately
10727follow the last instruction that is within the count. The command
10728@code{disassemble} gives an alternative way of inspecting machine
10729instructions; see @ref{Machine Code,,Source and Machine Code}.
c906108c 10730
bb556f1f
TK
10731If a negative repeat count is specified for the formats @samp{s} or @samp{i},
10732the command displays null-terminated strings or instructions before the given
10733address as many as the absolute value of the given number. For the @samp{i}
10734format, we use line number information in the debug info to accurately locate
10735instruction boundaries while disassembling backward. If line info is not
10736available, the command stops examining memory with an error message.
10737
c906108c
SS
10738All the defaults for the arguments to @code{x} are designed to make it
10739easy to continue scanning memory with minimal specifications each time
10740you use @code{x}. For example, after you have inspected three machine
10741instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
10742with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
10743the repeat count @var{n} is used again; the other arguments default as
10744for successive uses of @code{x}.
10745
2b28d209
PP
10746When examining machine instructions, the instruction at current program
10747counter is shown with a @code{=>} marker. For example:
10748
10749@smallexample
10750(@value{GDBP}) x/5i $pc-6
10751 0x804837f <main+11>: mov %esp,%ebp
10752 0x8048381 <main+13>: push %ecx
10753 0x8048382 <main+14>: sub $0x4,%esp
10754=> 0x8048385 <main+17>: movl $0x8048460,(%esp)
10755 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
10756@end smallexample
10757
c906108c
SS
10758@cindex @code{$_}, @code{$__}, and value history
10759The addresses and contents printed by the @code{x} command are not saved
10760in the value history because there is often too much of them and they
10761would get in the way. Instead, @value{GDBN} makes these values available for
10762subsequent use in expressions as values of the convenience variables
10763@code{$_} and @code{$__}. After an @code{x} command, the last address
10764examined is available for use in expressions in the convenience variable
10765@code{$_}. The contents of that address, as examined, are available in
10766the convenience variable @code{$__}.
10767
10768If the @code{x} command has a repeat count, the address and contents saved
10769are from the last memory unit printed; this is not the same as the last
10770address printed if several units were printed on the last line of output.
10771
a86c90e6
SM
10772@anchor{addressable memory unit}
10773@cindex addressable memory unit
10774Most targets have an addressable memory unit size of 8 bits. This means
10775that to each memory address are associated 8 bits of data. Some
10776targets, however, have other addressable memory unit sizes.
10777Within @value{GDBN} and this document, the term
10778@dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
10779when explicitly referring to a chunk of data of that size. The word
10780@dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
10781the addressable memory unit size of the target. For most systems,
10782addressable memory unit is a synonym of byte.
10783
09d4efe1 10784@cindex remote memory comparison
936d2992 10785@cindex target memory comparison
09d4efe1 10786@cindex verify remote memory image
936d2992 10787@cindex verify target memory image
09d4efe1 10788When you are debugging a program running on a remote target machine
936d2992
PA
10789(@pxref{Remote Debugging}), you may wish to verify the program's image
10790in the remote machine's memory against the executable file you
10791downloaded to the target. Or, on any target, you may want to check
10792whether the program has corrupted its own read-only sections. The
10793@code{compare-sections} command is provided for such situations.
09d4efe1
EZ
10794
10795@table @code
10796@kindex compare-sections
95cf3b38 10797@item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
09d4efe1
EZ
10798Compare the data of a loadable section @var{section-name} in the
10799executable file of the program being debugged with the same section in
936d2992 10800the target machine's memory, and report any mismatches. With no
95cf3b38 10801arguments, compares all loadable sections. With an argument of
936d2992
PA
10802@code{-r}, compares all loadable read-only sections.
10803
10804Note: for remote targets, this command can be accelerated if the
10805target supports computing the CRC checksum of a block of memory
10806(@pxref{qCRC packet}).
09d4efe1
EZ
10807@end table
10808
6d2ebf8b 10809@node Auto Display
79a6e687 10810@section Automatic Display
c906108c
SS
10811@cindex automatic display
10812@cindex display of expressions
10813
10814If you find that you want to print the value of an expression frequently
10815(to see how it changes), you might want to add it to the @dfn{automatic
10816display list} so that @value{GDBN} prints its value each time your program stops.
10817Each expression added to the list is given a number to identify it;
10818to remove an expression from the list, you specify that number.
10819The automatic display looks like this:
10820
474c8240 10821@smallexample
c906108c
SS
108222: foo = 38
108233: bar[5] = (struct hack *) 0x3804
474c8240 10824@end smallexample
c906108c
SS
10825
10826@noindent
10827This display shows item numbers, expressions and their current values. As with
10828displays you request manually using @code{x} or @code{print}, you can
10829specify the output format you prefer; in fact, @code{display} decides
ea37ba09
DJ
10830whether to use @code{print} or @code{x} depending your format
10831specification---it uses @code{x} if you specify either the @samp{i}
10832or @samp{s} format, or a unit size; otherwise it uses @code{print}.
c906108c
SS
10833
10834@table @code
10835@kindex display
d4f3574e
SS
10836@item display @var{expr}
10837Add the expression @var{expr} to the list of expressions to display
c906108c
SS
10838each time your program stops. @xref{Expressions, ,Expressions}.
10839
10840@code{display} does not repeat if you press @key{RET} again after using it.
10841
d4f3574e 10842@item display/@var{fmt} @var{expr}
c906108c 10843For @var{fmt} specifying only a display format and not a size or
d4f3574e 10844count, add the expression @var{expr} to the auto-display list but
c906108c 10845arrange to display it each time in the specified format @var{fmt}.
79a6e687 10846@xref{Output Formats,,Output Formats}.
c906108c
SS
10847
10848@item display/@var{fmt} @var{addr}
10849For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
10850number of units, add the expression @var{addr} as a memory address to
10851be examined each time your program stops. Examining means in effect
79a6e687 10852doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
c906108c
SS
10853@end table
10854
10855For example, @samp{display/i $pc} can be helpful, to see the machine
10856instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 10857is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
10858
10859@table @code
10860@kindex delete display
10861@kindex undisplay
10862@item undisplay @var{dnums}@dots{}
10863@itemx delete display @var{dnums}@dots{}
c9174737
PA
10864Remove items from the list of expressions to display. Specify the
10865numbers of the displays that you want affected with the command
10866argument @var{dnums}. It can be a single display number, one of the
10867numbers shown in the first field of the @samp{info display} display;
10868or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
10869
10870@code{undisplay} does not repeat if you press @key{RET} after using it.
10871(Otherwise you would just get the error @samp{No display number @dots{}}.)
10872
10873@kindex disable display
10874@item disable display @var{dnums}@dots{}
10875Disable the display of item numbers @var{dnums}. A disabled display
10876item is not printed automatically, but is not forgotten. It may be
c9174737
PA
10877enabled again later. Specify the numbers of the displays that you
10878want affected with the command argument @var{dnums}. It can be a
10879single display number, one of the numbers shown in the first field of
10880the @samp{info display} display; or it could be a range of display
10881numbers, as in @code{2-4}.
c906108c
SS
10882
10883@kindex enable display
10884@item enable display @var{dnums}@dots{}
10885Enable display of item numbers @var{dnums}. It becomes effective once
10886again in auto display of its expression, until you specify otherwise.
c9174737
PA
10887Specify the numbers of the displays that you want affected with the
10888command argument @var{dnums}. It can be a single display number, one
10889of the numbers shown in the first field of the @samp{info display}
10890display; or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
10891
10892@item display
10893Display the current values of the expressions on the list, just as is
10894done when your program stops.
10895
10896@kindex info display
10897@item info display
10898Print the list of expressions previously set up to display
10899automatically, each one with its item number, but without showing the
10900values. This includes disabled expressions, which are marked as such.
10901It also includes expressions which would not be displayed right now
10902because they refer to automatic variables not currently available.
10903@end table
10904
15387254 10905@cindex display disabled out of scope
c906108c
SS
10906If a display expression refers to local variables, then it does not make
10907sense outside the lexical context for which it was set up. Such an
10908expression is disabled when execution enters a context where one of its
10909variables is not defined. For example, if you give the command
10910@code{display last_char} while inside a function with an argument
10911@code{last_char}, @value{GDBN} displays this argument while your program
10912continues to stop inside that function. When it stops elsewhere---where
10913there is no variable @code{last_char}---the display is disabled
10914automatically. The next time your program stops where @code{last_char}
10915is meaningful, you can enable the display expression once again.
10916
6d2ebf8b 10917@node Print Settings
79a6e687 10918@section Print Settings
c906108c
SS
10919
10920@cindex format options
10921@cindex print settings
10922@value{GDBN} provides the following ways to control how arrays, structures,
10923and symbols are printed.
10924
10925@noindent
10926These settings are useful for debugging programs in any language:
10927
10928@table @code
4644b6e3 10929@kindex set print
3345721a 10930@anchor{set print address}
c906108c
SS
10931@item set print address
10932@itemx set print address on
4644b6e3 10933@cindex print/don't print memory addresses
c906108c
SS
10934@value{GDBN} prints memory addresses showing the location of stack
10935traces, structure values, pointer values, breakpoints, and so forth,
10936even when it also displays the contents of those addresses. The default
10937is @code{on}. For example, this is what a stack frame display looks like with
10938@code{set print address on}:
10939
10940@smallexample
10941@group
10942(@value{GDBP}) f
10943#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
10944 at input.c:530
10945530 if (lquote != def_lquote)
10946@end group
10947@end smallexample
10948
10949@item set print address off
10950Do not print addresses when displaying their contents. For example,
10951this is the same stack frame displayed with @code{set print address off}:
10952
10953@smallexample
10954@group
10955(@value{GDBP}) set print addr off
10956(@value{GDBP}) f
10957#0 set_quotes (lq="<<", rq=">>") at input.c:530
10958530 if (lquote != def_lquote)
10959@end group
10960@end smallexample
10961
10962You can use @samp{set print address off} to eliminate all machine
10963dependent displays from the @value{GDBN} interface. For example, with
10964@code{print address off}, you should get the same text for backtraces on
10965all machines---whether or not they involve pointer arguments.
10966
4644b6e3 10967@kindex show print
c906108c
SS
10968@item show print address
10969Show whether or not addresses are to be printed.
10970@end table
10971
10972When @value{GDBN} prints a symbolic address, it normally prints the
10973closest earlier symbol plus an offset. If that symbol does not uniquely
10974identify the address (for example, it is a name whose scope is a single
10975source file), you may need to clarify. One way to do this is with
10976@code{info line}, for example @samp{info line *0x4537}. Alternately,
10977you can set @value{GDBN} to print the source file and line number when
10978it prints a symbolic address:
10979
10980@table @code
c906108c 10981@item set print symbol-filename on
9c16f35a
EZ
10982@cindex source file and line of a symbol
10983@cindex symbol, source file and line
c906108c
SS
10984Tell @value{GDBN} to print the source file name and line number of a
10985symbol in the symbolic form of an address.
10986
10987@item set print symbol-filename off
10988Do not print source file name and line number of a symbol. This is the
10989default.
10990
c906108c
SS
10991@item show print symbol-filename
10992Show whether or not @value{GDBN} will print the source file name and
10993line number of a symbol in the symbolic form of an address.
10994@end table
10995
10996Another situation where it is helpful to show symbol filenames and line
10997numbers is when disassembling code; @value{GDBN} shows you the line
10998number and source file that corresponds to each instruction.
10999
11000Also, you may wish to see the symbolic form only if the address being
11001printed is reasonably close to the closest earlier symbol:
11002
11003@table @code
c906108c 11004@item set print max-symbolic-offset @var{max-offset}
f81d1120 11005@itemx set print max-symbolic-offset unlimited
4644b6e3 11006@cindex maximum value for offset of closest symbol
c906108c
SS
11007Tell @value{GDBN} to only display the symbolic form of an address if the
11008offset between the closest earlier symbol and the address is less than
f81d1120
PA
11009@var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
11010to always print the symbolic form of an address if any symbol precedes
11011it. Zero is equivalent to @code{unlimited}.
c906108c 11012
c906108c
SS
11013@item show print max-symbolic-offset
11014Ask how large the maximum offset is that @value{GDBN} prints in a
11015symbolic address.
11016@end table
11017
11018@cindex wild pointer, interpreting
11019@cindex pointer, finding referent
11020If you have a pointer and you are not sure where it points, try
11021@samp{set print symbol-filename on}. Then you can determine the name
11022and source file location of the variable where it points, using
11023@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
11024For example, here @value{GDBN} shows that a variable @code{ptt} points
11025at another variable @code{t}, defined in @file{hi2.c}:
11026
474c8240 11027@smallexample
c906108c
SS
11028(@value{GDBP}) set print symbol-filename on
11029(@value{GDBP}) p/a ptt
11030$4 = 0xe008 <t in hi2.c>
474c8240 11031@end smallexample
c906108c
SS
11032
11033@quotation
11034@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
11035does not show the symbol name and filename of the referent, even with
11036the appropriate @code{set print} options turned on.
11037@end quotation
11038
9cb709b6
TT
11039You can also enable @samp{/a}-like formatting all the time using
11040@samp{set print symbol on}:
11041
3345721a 11042@anchor{set print symbol}
9cb709b6
TT
11043@table @code
11044@item set print symbol on
11045Tell @value{GDBN} to print the symbol corresponding to an address, if
11046one exists.
11047
11048@item set print symbol off
11049Tell @value{GDBN} not to print the symbol corresponding to an
11050address. In this mode, @value{GDBN} will still print the symbol
11051corresponding to pointers to functions. This is the default.
11052
11053@item show print symbol
11054Show whether @value{GDBN} will display the symbol corresponding to an
11055address.
11056@end table
11057
c906108c
SS
11058Other settings control how different kinds of objects are printed:
11059
11060@table @code
3345721a 11061@anchor{set print array}
c906108c
SS
11062@item set print array
11063@itemx set print array on
4644b6e3 11064@cindex pretty print arrays
c906108c
SS
11065Pretty print arrays. This format is more convenient to read,
11066but uses more space. The default is off.
11067
11068@item set print array off
11069Return to compressed format for arrays.
11070
c906108c
SS
11071@item show print array
11072Show whether compressed or pretty format is selected for displaying
11073arrays.
11074
3c9c013a 11075@cindex print array indexes
3345721a 11076@anchor{set print array-indexes}
3c9c013a
JB
11077@item set print array-indexes
11078@itemx set print array-indexes on
11079Print the index of each element when displaying arrays. May be more
11080convenient to locate a given element in the array or quickly find the
11081index of a given element in that printed array. The default is off.
11082
11083@item set print array-indexes off
11084Stop printing element indexes when displaying arrays.
11085
11086@item show print array-indexes
11087Show whether the index of each element is printed when displaying
11088arrays.
11089
3345721a 11090@anchor{set print elements}
c906108c 11091@item set print elements @var{number-of-elements}
f81d1120 11092@itemx set print elements unlimited
4644b6e3 11093@cindex number of array elements to print
9c16f35a 11094@cindex limit on number of printed array elements
c906108c
SS
11095Set a limit on how many elements of an array @value{GDBN} will print.
11096If @value{GDBN} is printing a large array, it stops printing after it has
11097printed the number of elements set by the @code{set print elements} command.
11098This limit also applies to the display of strings.
d4f3574e 11099When @value{GDBN} starts, this limit is set to 200.
f81d1120
PA
11100Setting @var{number-of-elements} to @code{unlimited} or zero means
11101that the number of elements to print is unlimited.
c906108c 11102
c906108c
SS
11103@item show print elements
11104Display the number of elements of a large array that @value{GDBN} will print.
11105If the number is 0, then the printing is unlimited.
11106
3345721a 11107@anchor{set print frame-arguments}
b4740add 11108@item set print frame-arguments @var{value}
a0381d3a 11109@kindex set print frame-arguments
b4740add
JB
11110@cindex printing frame argument values
11111@cindex print all frame argument values
11112@cindex print frame argument values for scalars only
bc4268a5 11113@cindex do not print frame arguments
b4740add
JB
11114This command allows to control how the values of arguments are printed
11115when the debugger prints a frame (@pxref{Frames}). The possible
11116values are:
11117
11118@table @code
11119@item all
4f5376b2 11120The values of all arguments are printed.
b4740add
JB
11121
11122@item scalars
11123Print the value of an argument only if it is a scalar. The value of more
11124complex arguments such as arrays, structures, unions, etc, is replaced
4f5376b2
JB
11125by @code{@dots{}}. This is the default. Here is an example where
11126only scalar arguments are shown:
b4740add
JB
11127
11128@smallexample
11129#1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
11130 at frame-args.c:23
11131@end smallexample
11132
11133@item none
11134None of the argument values are printed. Instead, the value of each argument
11135is replaced by @code{@dots{}}. In this case, the example above now becomes:
11136
11137@smallexample
11138#1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
11139 at frame-args.c:23
11140@end smallexample
bc4268a5
PW
11141
11142@item presence
11143Only the presence of arguments is indicated by @code{@dots{}}.
11144The @code{@dots{}} are not printed for function without any arguments.
11145None of the argument names and values are printed.
11146In this case, the example above now becomes:
11147
11148@smallexample
11149#1 0x08048361 in call_me (@dots{}) at frame-args.c:23
11150@end smallexample
11151
b4740add
JB
11152@end table
11153
4f5376b2
JB
11154By default, only scalar arguments are printed. This command can be used
11155to configure the debugger to print the value of all arguments, regardless
11156of their type. However, it is often advantageous to not print the value
11157of more complex parameters. For instance, it reduces the amount of
11158information printed in each frame, making the backtrace more readable.
11159Also, it improves performance when displaying Ada frames, because
11160the computation of large arguments can sometimes be CPU-intensive,
11161especially in large applications. Setting @code{print frame-arguments}
bc4268a5
PW
11162to @code{scalars} (the default), @code{none} or @code{presence} avoids
11163this computation, thus speeding up the display of each Ada frame.
b4740add
JB
11164
11165@item show print frame-arguments
11166Show how the value of arguments should be displayed when printing a frame.
11167
3345721a 11168@anchor{set print raw-frame-arguments}
2daf894e 11169@item set print raw-frame-arguments on
e7045703
DE
11170Print frame arguments in raw, non pretty-printed, form.
11171
2daf894e 11172@item set print raw-frame-arguments off
e7045703
DE
11173Print frame arguments in pretty-printed form, if there is a pretty-printer
11174for the value (@pxref{Pretty Printing}),
11175otherwise print the value in raw form.
11176This is the default.
11177
2daf894e 11178@item show print raw-frame-arguments
e7045703
DE
11179Show whether to print frame arguments in raw form.
11180
36b11add 11181@anchor{set print entry-values}
e18b2753
JK
11182@item set print entry-values @var{value}
11183@kindex set print entry-values
11184Set printing of frame argument values at function entry. In some cases
11185@value{GDBN} can determine the value of function argument which was passed by
11186the function caller, even if the value was modified inside the called function
11187and therefore is different. With optimized code, the current value could be
11188unavailable, but the entry value may still be known.
11189
11190The default value is @code{default} (see below for its description). Older
11191@value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
11192this feature will behave in the @code{default} setting the same way as with the
11193@code{no} setting.
11194
11195This functionality is currently supported only by DWARF 2 debugging format and
216f72a1 11196the compiler has to produce @samp{DW_TAG_call_site} tags. With
e18b2753
JK
11197@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11198this information.
11199
11200The @var{value} parameter can be one of the following:
11201
11202@table @code
11203@item no
11204Print only actual parameter values, never print values from function entry
11205point.
11206@smallexample
11207#0 equal (val=5)
11208#0 different (val=6)
11209#0 lost (val=<optimized out>)
11210#0 born (val=10)
11211#0 invalid (val=<optimized out>)
11212@end smallexample
11213
11214@item only
11215Print only parameter values from function entry point. The actual parameter
11216values are never printed.
11217@smallexample
11218#0 equal (val@@entry=5)
11219#0 different (val@@entry=5)
11220#0 lost (val@@entry=5)
11221#0 born (val@@entry=<optimized out>)
11222#0 invalid (val@@entry=<optimized out>)
11223@end smallexample
11224
11225@item preferred
11226Print only parameter values from function entry point. If value from function
11227entry point is not known while the actual value is known, print the actual
11228value for such parameter.
11229@smallexample
11230#0 equal (val@@entry=5)
11231#0 different (val@@entry=5)
11232#0 lost (val@@entry=5)
11233#0 born (val=10)
11234#0 invalid (val@@entry=<optimized out>)
11235@end smallexample
11236
11237@item if-needed
11238Print actual parameter values. If actual parameter value is not known while
11239value from function entry point is known, print the entry point value for such
11240parameter.
11241@smallexample
11242#0 equal (val=5)
11243#0 different (val=6)
11244#0 lost (val@@entry=5)
11245#0 born (val=10)
11246#0 invalid (val=<optimized out>)
11247@end smallexample
11248
11249@item both
11250Always print both the actual parameter value and its value from function entry
11251point, even if values of one or both are not available due to compiler
11252optimizations.
11253@smallexample
11254#0 equal (val=5, val@@entry=5)
11255#0 different (val=6, val@@entry=5)
11256#0 lost (val=<optimized out>, val@@entry=5)
11257#0 born (val=10, val@@entry=<optimized out>)
11258#0 invalid (val=<optimized out>, val@@entry=<optimized out>)
11259@end smallexample
11260
11261@item compact
11262Print the actual parameter value if it is known and also its value from
11263function entry point if it is known. If neither is known, print for the actual
11264value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
11265values are known and identical, print the shortened
11266@code{param=param@@entry=VALUE} notation.
11267@smallexample
11268#0 equal (val=val@@entry=5)
11269#0 different (val=6, val@@entry=5)
11270#0 lost (val@@entry=5)
11271#0 born (val=10)
11272#0 invalid (val=<optimized out>)
11273@end smallexample
11274
11275@item default
11276Always print the actual parameter value. Print also its value from function
11277entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
11278if both values are known and identical, print the shortened
11279@code{param=param@@entry=VALUE} notation.
11280@smallexample
11281#0 equal (val=val@@entry=5)
11282#0 different (val=6, val@@entry=5)
11283#0 lost (val=<optimized out>, val@@entry=5)
11284#0 born (val=10)
11285#0 invalid (val=<optimized out>)
11286@end smallexample
11287@end table
11288
11289For analysis messages on possible failures of frame argument values at function
11290entry resolution see @ref{set debug entry-values}.
11291
11292@item show print entry-values
11293Show the method being used for printing of frame argument values at function
11294entry.
11295
bc4268a5
PW
11296@anchor{set print frame-info}
11297@item set print frame-info @var{value}
11298@kindex set print frame-info
11299@cindex printing frame information
11300@cindex frame information, printing
11301This command allows to control the information printed when
11302the debugger prints a frame. See @ref{Frames}, @ref{Backtrace},
11303for a general explanation about frames and frame information.
11304Note that some other settings (such as @code{set print frame-arguments}
11305and @code{set print address}) are also influencing if and how some frame
11306information is displayed. In particular, the frame program counter is never
11307printed if @code{set print address} is off.
11308
11309The possible values for @code{set print frame-info} are:
11310@table @code
11311@item short-location
11312Print the frame level, the program counter (if not at the
11313beginning of the location source line), the function, the function
11314arguments.
11315@item location
11316Same as @code{short-location} but also print the source file and source line
11317number.
11318@item location-and-address
11319Same as @code{location} but print the program counter even if located at the
11320beginning of the location source line.
11321@item source-line
11322Print the program counter (if not at the beginning of the location
11323source line), the line number and the source line.
11324@item source-and-location
11325Print what @code{location} and @code{source-line} are printing.
11326@item auto
11327The information printed for a frame is decided automatically
11328by the @value{GDBN} command that prints a frame.
11329For example, @code{frame} prints the information printed by
11330@code{source-and-location} while @code{stepi} will switch between
11331@code{source-line} and @code{source-and-location} depending on the program
11332counter.
11333The default value is @code{auto}.
11334@end table
11335
3345721a 11336@anchor{set print repeats}
f81d1120
PA
11337@item set print repeats @var{number-of-repeats}
11338@itemx set print repeats unlimited
9c16f35a
EZ
11339@cindex repeated array elements
11340Set the threshold for suppressing display of repeated array
d3e8051b 11341elements. When the number of consecutive identical elements of an
9c16f35a
EZ
11342array exceeds the threshold, @value{GDBN} prints the string
11343@code{"<repeats @var{n} times>"}, where @var{n} is the number of
11344identical repetitions, instead of displaying the identical elements
f81d1120
PA
11345themselves. Setting the threshold to @code{unlimited} or zero will
11346cause all elements to be individually printed. The default threshold
11347is 10.
9c16f35a
EZ
11348
11349@item show print repeats
11350Display the current threshold for printing repeated identical
11351elements.
11352
3345721a 11353@anchor{set print max-depth}
2e62ab40
AB
11354@item set print max-depth @var{depth}
11355@item set print max-depth unlimited
11356@cindex printing nested structures
11357Set the threshold after which nested structures are replaced with
11358ellipsis, this can make visualising deeply nested structures easier.
11359
11360For example, given this C code
11361
11362@smallexample
11363typedef struct s1 @{ int a; @} s1;
11364typedef struct s2 @{ s1 b; @} s2;
11365typedef struct s3 @{ s2 c; @} s3;
11366typedef struct s4 @{ s3 d; @} s4;
11367
11368s4 var = @{ @{ @{ @{ 3 @} @} @} @};
11369@end smallexample
11370
11371The following table shows how different values of @var{depth} will
11372effect how @code{var} is printed by @value{GDBN}:
11373
11374@multitable @columnfractions .3 .7
11375@headitem @var{depth} setting @tab Result of @samp{p var}
11376@item unlimited
11377@tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11378@item @code{0}
11379@tab @code{$1 = @{...@}}
11380@item @code{1}
11381@tab @code{$1 = @{d = @{...@}@}}
11382@item @code{2}
11383@tab @code{$1 = @{d = @{c = @{...@}@}@}}
11384@item @code{3}
11385@tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
11386@item @code{4}
11387@tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11388@end multitable
11389
11390To see the contents of structures that have been hidden the user can
11391either increase the print max-depth, or they can print the elements of
11392the structure that are visible, for example
11393
11394@smallexample
11395(gdb) set print max-depth 2
11396(gdb) p var
11397$1 = @{d = @{c = @{...@}@}@}
11398(gdb) p var.d
11399$2 = @{c = @{b = @{...@}@}@}
11400(gdb) p var.d.c
11401$3 = @{b = @{a = 3@}@}
11402@end smallexample
11403
11404The pattern used to replace nested structures varies based on
11405language, for most languages @code{@{...@}} is used, but Fortran uses
11406@code{(...)}.
11407
11408@item show print max-depth
11409Display the current threshold after which nested structures are
11410replaces with ellipsis.
11411
3345721a 11412@anchor{set print null-stop}
c906108c 11413@item set print null-stop
4644b6e3 11414@cindex @sc{null} elements in arrays
c906108c 11415Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 11416@sc{null} is encountered. This is useful when large arrays actually
c906108c 11417contain only short strings.
d4f3574e 11418The default is off.
c906108c 11419
9c16f35a
EZ
11420@item show print null-stop
11421Show whether @value{GDBN} stops printing an array on the first
11422@sc{null} character.
11423
3345721a 11424@anchor{set print pretty}
c906108c 11425@item set print pretty on
9c16f35a
EZ
11426@cindex print structures in indented form
11427@cindex indentation in structure display
5d161b24 11428Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
11429per line, like this:
11430
11431@smallexample
11432@group
11433$1 = @{
11434 next = 0x0,
11435 flags = @{
11436 sweet = 1,
11437 sour = 1
11438 @},
11439 meat = 0x54 "Pork"
11440@}
11441@end group
11442@end smallexample
11443
11444@item set print pretty off
11445Cause @value{GDBN} to print structures in a compact format, like this:
11446
11447@smallexample
11448@group
11449$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
11450meat = 0x54 "Pork"@}
11451@end group
11452@end smallexample
11453
11454@noindent
11455This is the default format.
11456
c906108c
SS
11457@item show print pretty
11458Show which format @value{GDBN} is using to print structures.
11459
d8edc8b7
PW
11460@anchor{set print raw-values}
11461@item set print raw-values on
11462Print values in raw form, without applying the pretty
11463printers for the value.
11464
11465@item set print raw-values off
11466Print values in pretty-printed form, if there is a pretty-printer
11467for the value (@pxref{Pretty Printing}),
11468otherwise print the value in raw form.
11469
11470The default setting is ``off''.
11471
11472@item show print raw-values
11473Show whether to print values in raw form.
11474
c906108c 11475@item set print sevenbit-strings on
4644b6e3
EZ
11476@cindex eight-bit characters in strings
11477@cindex octal escapes in strings
c906108c
SS
11478Print using only seven-bit characters; if this option is set,
11479@value{GDBN} displays any eight-bit characters (in strings or
11480character values) using the notation @code{\}@var{nnn}. This setting is
11481best if you are working in English (@sc{ascii}) and you use the
11482high-order bit of characters as a marker or ``meta'' bit.
11483
11484@item set print sevenbit-strings off
11485Print full eight-bit characters. This allows the use of more
11486international character sets, and is the default.
11487
c906108c
SS
11488@item show print sevenbit-strings
11489Show whether or not @value{GDBN} is printing only seven-bit characters.
11490
3345721a 11491@anchor{set print union}
c906108c 11492@item set print union on
4644b6e3 11493@cindex unions in structures, printing
9c16f35a
EZ
11494Tell @value{GDBN} to print unions which are contained in structures
11495and other unions. This is the default setting.
c906108c
SS
11496
11497@item set print union off
9c16f35a
EZ
11498Tell @value{GDBN} not to print unions which are contained in
11499structures and other unions. @value{GDBN} will print @code{"@{...@}"}
11500instead.
c906108c 11501
c906108c
SS
11502@item show print union
11503Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 11504structures and other unions.
c906108c
SS
11505
11506For example, given the declarations
11507
11508@smallexample
11509typedef enum @{Tree, Bug@} Species;
11510typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 11511typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
11512 Bug_forms;
11513
11514struct thing @{
11515 Species it;
11516 union @{
11517 Tree_forms tree;
11518 Bug_forms bug;
11519 @} form;
11520@};
11521
11522struct thing foo = @{Tree, @{Acorn@}@};
11523@end smallexample
11524
11525@noindent
11526with @code{set print union on} in effect @samp{p foo} would print
11527
11528@smallexample
11529$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
11530@end smallexample
11531
11532@noindent
11533and with @code{set print union off} in effect it would print
11534
11535@smallexample
11536$1 = @{it = Tree, form = @{...@}@}
11537@end smallexample
9c16f35a
EZ
11538
11539@noindent
11540@code{set print union} affects programs written in C-like languages
11541and in Pascal.
c906108c
SS
11542@end table
11543
c906108c
SS
11544@need 1000
11545@noindent
b37052ae 11546These settings are of interest when debugging C@t{++} programs:
c906108c
SS
11547
11548@table @code
4644b6e3 11549@cindex demangling C@t{++} names
c906108c
SS
11550@item set print demangle
11551@itemx set print demangle on
b37052ae 11552Print C@t{++} names in their source form rather than in the encoded
c906108c 11553(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 11554linkage. The default is on.
c906108c 11555
c906108c 11556@item show print demangle
b37052ae 11557Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 11558
c906108c
SS
11559@item set print asm-demangle
11560@itemx set print asm-demangle on
b37052ae 11561Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
11562in assembler code printouts such as instruction disassemblies.
11563The default is off.
11564
c906108c 11565@item show print asm-demangle
b37052ae 11566Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
11567or demangled form.
11568
b37052ae
EZ
11569@cindex C@t{++} symbol decoding style
11570@cindex symbol decoding style, C@t{++}
a8f24a35 11571@kindex set demangle-style
c906108c 11572@item set demangle-style @var{style}
041be526
SM
11573Choose among several encoding schemes used by different compilers to represent
11574C@t{++} names. If you omit @var{style}, you will see a list of possible
11575formats. The default value is @var{auto}, which lets @value{GDBN} choose a
11576decoding style by inspecting your program.
c906108c 11577
c906108c 11578@item show demangle-style
b37052ae 11579Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 11580
3345721a 11581@anchor{set print object}
c906108c
SS
11582@item set print object
11583@itemx set print object on
4644b6e3 11584@cindex derived type of an object, printing
9c16f35a 11585@cindex display derived types
c906108c
SS
11586When displaying a pointer to an object, identify the @emph{actual}
11587(derived) type of the object rather than the @emph{declared} type, using
625c0d47
TT
11588the virtual function table. Note that the virtual function table is
11589required---this feature can only work for objects that have run-time
11590type identification; a single virtual method in the object's declared
8264ba82
AG
11591type is sufficient. Note that this setting is also taken into account when
11592working with variable objects via MI (@pxref{GDB/MI}).
c906108c
SS
11593
11594@item set print object off
11595Display only the declared type of objects, without reference to the
11596virtual function table. This is the default setting.
11597
c906108c
SS
11598@item show print object
11599Show whether actual, or declared, object types are displayed.
11600
3345721a 11601@anchor{set print static-members}
c906108c
SS
11602@item set print static-members
11603@itemx set print static-members on
4644b6e3 11604@cindex static members of C@t{++} objects
b37052ae 11605Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
11606
11607@item set print static-members off
b37052ae 11608Do not print static members when displaying a C@t{++} object.
c906108c 11609
c906108c 11610@item show print static-members
9c16f35a
EZ
11611Show whether C@t{++} static members are printed or not.
11612
11613@item set print pascal_static-members
11614@itemx set print pascal_static-members on
d3e8051b
EZ
11615@cindex static members of Pascal objects
11616@cindex Pascal objects, static members display
9c16f35a
EZ
11617Print static members when displaying a Pascal object. The default is on.
11618
11619@item set print pascal_static-members off
11620Do not print static members when displaying a Pascal object.
11621
11622@item show print pascal_static-members
11623Show whether Pascal static members are printed or not.
c906108c
SS
11624
11625@c These don't work with HP ANSI C++ yet.
3345721a 11626@anchor{set print vtbl}
c906108c
SS
11627@item set print vtbl
11628@itemx set print vtbl on
4644b6e3 11629@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
11630@cindex virtual functions (C@t{++}) display
11631@cindex VTBL display
b37052ae 11632Pretty print C@t{++} virtual function tables. The default is off.
c906108c 11633(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 11634ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
11635
11636@item set print vtbl off
b37052ae 11637Do not pretty print C@t{++} virtual function tables.
c906108c 11638
c906108c 11639@item show print vtbl
b37052ae 11640Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 11641@end table
c906108c 11642
4c374409
JK
11643@node Pretty Printing
11644@section Pretty Printing
11645
11646@value{GDBN} provides a mechanism to allow pretty-printing of values using
11647Python code. It greatly simplifies the display of complex objects. This
11648mechanism works for both MI and the CLI.
11649
7b51bc51
DE
11650@menu
11651* Pretty-Printer Introduction:: Introduction to pretty-printers
11652* Pretty-Printer Example:: An example pretty-printer
11653* Pretty-Printer Commands:: Pretty-printer commands
11654@end menu
11655
11656@node Pretty-Printer Introduction
11657@subsection Pretty-Printer Introduction
11658
11659When @value{GDBN} prints a value, it first sees if there is a pretty-printer
11660registered for the value. If there is then @value{GDBN} invokes the
11661pretty-printer to print the value. Otherwise the value is printed normally.
11662
11663Pretty-printers are normally named. This makes them easy to manage.
11664The @samp{info pretty-printer} command will list all the installed
11665pretty-printers with their names.
11666If a pretty-printer can handle multiple data types, then its
11667@dfn{subprinters} are the printers for the individual data types.
11668Each such subprinter has its own name.
4e04c971 11669The format of the name is @var{printer-name};@var{subprinter-name}.
7b51bc51
DE
11670
11671Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
11672Typically they are automatically loaded and registered when the corresponding
11673debug information is loaded, thus making them available without having to
11674do anything special.
11675
11676There are three places where a pretty-printer can be registered.
11677
11678@itemize @bullet
11679@item
11680Pretty-printers registered globally are available when debugging
11681all inferiors.
11682
11683@item
11684Pretty-printers registered with a program space are available only
11685when debugging that program.
11686@xref{Progspaces In Python}, for more details on program spaces in Python.
11687
11688@item
11689Pretty-printers registered with an objfile are loaded and unloaded
11690with the corresponding objfile (e.g., shared library).
11691@xref{Objfiles In Python}, for more details on objfiles in Python.
11692@end itemize
11693
11694@xref{Selecting Pretty-Printers}, for further information on how
11695pretty-printers are selected,
11696
11697@xref{Writing a Pretty-Printer}, for implementing pretty printers
11698for new types.
11699
11700@node Pretty-Printer Example
11701@subsection Pretty-Printer Example
11702
11703Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
4c374409
JK
11704
11705@smallexample
11706(@value{GDBP}) print s
11707$1 = @{
11708 static npos = 4294967295,
11709 _M_dataplus = @{
11710 <std::allocator<char>> = @{
11711 <__gnu_cxx::new_allocator<char>> = @{
11712 <No data fields>@}, <No data fields>
11713 @},
11714 members of std::basic_string<char, std::char_traits<char>,
11715 std::allocator<char> >::_Alloc_hider:
11716 _M_p = 0x804a014 "abcd"
11717 @}
11718@}
11719@end smallexample
11720
11721With a pretty-printer for @code{std::string} only the contents are printed:
11722
11723@smallexample
11724(@value{GDBP}) print s
11725$2 = "abcd"
11726@end smallexample
11727
7b51bc51
DE
11728@node Pretty-Printer Commands
11729@subsection Pretty-Printer Commands
11730@cindex pretty-printer commands
11731
11732@table @code
11733@kindex info pretty-printer
11734@item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11735Print the list of installed pretty-printers.
11736This includes disabled pretty-printers, which are marked as such.
11737
11738@var{object-regexp} is a regular expression matching the objects
11739whose pretty-printers to list.
11740Objects can be @code{global}, the program space's file
11741(@pxref{Progspaces In Python}),
11742and the object files within that program space (@pxref{Objfiles In Python}).
11743@xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
11744looks up a printer from these three objects.
11745
11746@var{name-regexp} is a regular expression matching the name of the printers
11747to list.
11748
11749@kindex disable pretty-printer
11750@item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11751Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11752A disabled pretty-printer is not forgotten, it may be enabled again later.
11753
11754@kindex enable pretty-printer
11755@item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11756Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11757@end table
11758
11759Example:
11760
11761Suppose we have three pretty-printers installed: one from library1.so
11762named @code{foo} that prints objects of type @code{foo}, and
11763another from library2.so named @code{bar} that prints two types of objects,
11764@code{bar1} and @code{bar2}.
11765
11766@smallexample
11767(gdb) info pretty-printer
11768library1.so:
11769 foo
11770library2.so:
11771 bar
11772 bar1
11773 bar2
11774(gdb) info pretty-printer library2
11775library2.so:
11776 bar
11777 bar1
11778 bar2
11779(gdb) disable pretty-printer library1
117801 printer disabled
117812 of 3 printers enabled
11782(gdb) info pretty-printer
11783library1.so:
11784 foo [disabled]
11785library2.so:
11786 bar
11787 bar1
11788 bar2
088a96da 11789(gdb) disable pretty-printer library2 bar;bar1
7b51bc51
DE
117901 printer disabled
117911 of 3 printers enabled
11792(gdb) info pretty-printer library2
11793library1.so:
11794 foo [disabled]
11795library2.so:
11796 bar
11797 bar1 [disabled]
11798 bar2
11799(gdb) disable pretty-printer library2 bar
118001 printer disabled
118010 of 3 printers enabled
11802(gdb) info pretty-printer library2
11803library1.so:
11804 foo [disabled]
11805library2.so:
11806 bar [disabled]
11807 bar1 [disabled]
11808 bar2
11809@end smallexample
11810
11811Note that for @code{bar} the entire printer can be disabled,
11812as can each individual subprinter.
4c374409 11813
d8edc8b7
PW
11814Printing values and frame arguments is done by default using
11815the enabled pretty printers.
11816
11817The print option @code{-raw-values} and @value{GDBN} setting
11818@code{set print raw-values} (@pxref{set print raw-values}) can be
11819used to print values without applying the enabled pretty printers.
11820
11821Similarly, the backtrace option @code{-raw-frame-arguments} and
11822@value{GDBN} setting @code{set print raw-frame-arguments}
11823(@pxref{set print raw-frame-arguments}) can be used to ignore the
11824enabled pretty printers when printing frame argument values.
11825
6d2ebf8b 11826@node Value History
79a6e687 11827@section Value History
c906108c
SS
11828
11829@cindex value history
9c16f35a 11830@cindex history of values printed by @value{GDBN}
5d161b24
DB
11831Values printed by the @code{print} command are saved in the @value{GDBN}
11832@dfn{value history}. This allows you to refer to them in other expressions.
11833Values are kept until the symbol table is re-read or discarded
11834(for example with the @code{file} or @code{symbol-file} commands).
11835When the symbol table changes, the value history is discarded,
11836since the values may contain pointers back to the types defined in the
c906108c
SS
11837symbol table.
11838
11839@cindex @code{$}
11840@cindex @code{$$}
11841@cindex history number
11842The values printed are given @dfn{history numbers} by which you can
11843refer to them. These are successive integers starting with one.
11844@code{print} shows you the history number assigned to a value by
11845printing @samp{$@var{num} = } before the value; here @var{num} is the
11846history number.
11847
11848To refer to any previous value, use @samp{$} followed by the value's
11849history number. The way @code{print} labels its output is designed to
11850remind you of this. Just @code{$} refers to the most recent value in
11851the history, and @code{$$} refers to the value before that.
11852@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
11853is the value just prior to @code{$$}, @code{$$1} is equivalent to
11854@code{$$}, and @code{$$0} is equivalent to @code{$}.
11855
11856For example, suppose you have just printed a pointer to a structure and
11857want to see the contents of the structure. It suffices to type
11858
474c8240 11859@smallexample
c906108c 11860p *$
474c8240 11861@end smallexample
c906108c
SS
11862
11863If you have a chain of structures where the component @code{next} points
11864to the next one, you can print the contents of the next one with this:
11865
474c8240 11866@smallexample
c906108c 11867p *$.next
474c8240 11868@end smallexample
c906108c
SS
11869
11870@noindent
11871You can print successive links in the chain by repeating this
11872command---which you can do by just typing @key{RET}.
11873
11874Note that the history records values, not expressions. If the value of
11875@code{x} is 4 and you type these commands:
11876
474c8240 11877@smallexample
c906108c
SS
11878print x
11879set x=5
474c8240 11880@end smallexample
c906108c
SS
11881
11882@noindent
11883then the value recorded in the value history by the @code{print} command
11884remains 4 even though the value of @code{x} has changed.
11885
11886@table @code
11887@kindex show values
11888@item show values
11889Print the last ten values in the value history, with their item numbers.
11890This is like @samp{p@ $$9} repeated ten times, except that @code{show
11891values} does not change the history.
11892
11893@item show values @var{n}
11894Print ten history values centered on history item number @var{n}.
11895
11896@item show values +
11897Print ten history values just after the values last printed. If no more
11898values are available, @code{show values +} produces no display.
11899@end table
11900
11901Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
11902same effect as @samp{show values +}.
11903
6d2ebf8b 11904@node Convenience Vars
79a6e687 11905@section Convenience Variables
c906108c
SS
11906
11907@cindex convenience variables
9c16f35a 11908@cindex user-defined variables
c906108c
SS
11909@value{GDBN} provides @dfn{convenience variables} that you can use within
11910@value{GDBN} to hold on to a value and refer to it later. These variables
11911exist entirely within @value{GDBN}; they are not part of your program, and
11912setting a convenience variable has no direct effect on further execution
11913of your program. That is why you can use them freely.
11914
11915Convenience variables are prefixed with @samp{$}. Any name preceded by
11916@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 11917the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c 11918(Value history references, in contrast, are @emph{numbers} preceded
79a6e687 11919by @samp{$}. @xref{Value History, ,Value History}.)
c906108c
SS
11920
11921You can save a value in a convenience variable with an assignment
11922expression, just as you would set a variable in your program.
11923For example:
11924
474c8240 11925@smallexample
c906108c 11926set $foo = *object_ptr
474c8240 11927@end smallexample
c906108c
SS
11928
11929@noindent
11930would save in @code{$foo} the value contained in the object pointed to by
11931@code{object_ptr}.
11932
11933Using a convenience variable for the first time creates it, but its
11934value is @code{void} until you assign a new value. You can alter the
11935value with another assignment at any time.
11936
11937Convenience variables have no fixed types. You can assign a convenience
11938variable any type of value, including structures and arrays, even if
11939that variable already has a value of a different type. The convenience
11940variable, when used as an expression, has the type of its current value.
11941
11942@table @code
11943@kindex show convenience
f47f77df 11944@cindex show all user variables and functions
c906108c 11945@item show convenience
f47f77df
DE
11946Print a list of convenience variables used so far, and their values,
11947as well as a list of the convenience functions.
d4f3574e 11948Abbreviated @code{show conv}.
53e5f3cf
AS
11949
11950@kindex init-if-undefined
11951@cindex convenience variables, initializing
11952@item init-if-undefined $@var{variable} = @var{expression}
11953Set a convenience variable if it has not already been set. This is useful
11954for user-defined commands that keep some state. It is similar, in concept,
11955to using local static variables with initializers in C (except that
11956convenience variables are global). It can also be used to allow users to
11957override default values used in a command script.
11958
11959If the variable is already defined then the expression is not evaluated so
11960any side-effects do not occur.
c906108c
SS
11961@end table
11962
11963One of the ways to use a convenience variable is as a counter to be
11964incremented or a pointer to be advanced. For example, to print
11965a field from successive elements of an array of structures:
11966
474c8240 11967@smallexample
c906108c
SS
11968set $i = 0
11969print bar[$i++]->contents
474c8240 11970@end smallexample
c906108c 11971
d4f3574e
SS
11972@noindent
11973Repeat that command by typing @key{RET}.
c906108c
SS
11974
11975Some convenience variables are created automatically by @value{GDBN} and given
11976values likely to be useful.
11977
11978@table @code
41afff9a 11979@vindex $_@r{, convenience variable}
c906108c
SS
11980@item $_
11981The variable @code{$_} is automatically set by the @code{x} command to
79a6e687 11982the last address examined (@pxref{Memory, ,Examining Memory}). Other
c906108c
SS
11983commands which provide a default address for @code{x} to examine also
11984set @code{$_} to that address; these commands include @code{info line}
11985and @code{info breakpoint}. The type of @code{$_} is @code{void *}
11986except when set by the @code{x} command, in which case it is a pointer
11987to the type of @code{$__}.
11988
41afff9a 11989@vindex $__@r{, convenience variable}
c906108c
SS
11990@item $__
11991The variable @code{$__} is automatically set by the @code{x} command
11992to the value found in the last address examined. Its type is chosen
11993to match the format in which the data was printed.
11994
11995@item $_exitcode
41afff9a 11996@vindex $_exitcode@r{, convenience variable}
0c557179
SDJ
11997When the program being debugged terminates normally, @value{GDBN}
11998automatically sets this variable to the exit code of the program, and
11999resets @code{$_exitsignal} to @code{void}.
12000
12001@item $_exitsignal
12002@vindex $_exitsignal@r{, convenience variable}
12003When the program being debugged dies due to an uncaught signal,
12004@value{GDBN} automatically sets this variable to that signal's number,
12005and resets @code{$_exitcode} to @code{void}.
12006
12007To distinguish between whether the program being debugged has exited
12008(i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
12009@code{$_exitsignal} is not @code{void}), the convenience function
12010@code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
12011Functions}). For example, considering the following source code:
12012
12013@smallexample
12014#include <signal.h>
12015
12016int
12017main (int argc, char *argv[])
12018@{
12019 raise (SIGALRM);
12020 return 0;
12021@}
12022@end smallexample
12023
12024A valid way of telling whether the program being debugged has exited
12025or signalled would be:
12026
12027@smallexample
12028(@value{GDBP}) define has_exited_or_signalled
12029Type commands for definition of ``has_exited_or_signalled''.
12030End with a line saying just ``end''.
12031>if $_isvoid ($_exitsignal)
12032 >echo The program has exited\n
12033 >else
12034 >echo The program has signalled\n
12035 >end
12036>end
12037(@value{GDBP}) run
12038Starting program:
12039
12040Program terminated with signal SIGALRM, Alarm clock.
12041The program no longer exists.
12042(@value{GDBP}) has_exited_or_signalled
12043The program has signalled
12044@end smallexample
12045
12046As can be seen, @value{GDBN} correctly informs that the program being
12047debugged has signalled, since it calls @code{raise} and raises a
12048@code{SIGALRM} signal. If the program being debugged had not called
12049@code{raise}, then @value{GDBN} would report a normal exit:
12050
12051@smallexample
12052(@value{GDBP}) has_exited_or_signalled
12053The program has exited
12054@end smallexample
4aa995e1 12055
72f1fe8a
TT
12056@item $_exception
12057The variable @code{$_exception} is set to the exception object being
12058thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
12059
37f6a7f4
TT
12060@item $_ada_exception
12061The variable @code{$_ada_exception} is set to the address of the
12062exception being caught or thrown at an Ada exception-related
12063catchpoint. @xref{Set Catchpoints}.
12064
62e5f89c
SDJ
12065@item $_probe_argc
12066@itemx $_probe_arg0@dots{}$_probe_arg11
12067Arguments to a static probe. @xref{Static Probe Points}.
12068
0fb4aa4b
PA
12069@item $_sdata
12070@vindex $_sdata@r{, inspect, convenience variable}
12071The variable @code{$_sdata} contains extra collected static tracepoint
12072data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
12073@code{$_sdata} could be empty, if not inspecting a trace buffer, or
12074if extra static tracepoint data has not been collected.
12075
4aa995e1
PA
12076@item $_siginfo
12077@vindex $_siginfo@r{, convenience variable}
ec7e75e7
PP
12078The variable @code{$_siginfo} contains extra signal information
12079(@pxref{extra signal information}). Note that @code{$_siginfo}
12080could be empty, if the application has not yet received any signals.
12081For example, it will be empty before you execute the @code{run} command.
711e434b
PM
12082
12083@item $_tlb
12084@vindex $_tlb@r{, convenience variable}
12085The variable @code{$_tlb} is automatically set when debugging
12086applications running on MS-Windows in native mode or connected to
7734102d 12087gdbserver that supports the @code{qGetTIBAddr} request.
711e434b
PM
12088@xref{General Query Packets}.
12089This variable contains the address of the thread information block.
12090
e3940304 12091@item $_inferior
65c574f6
PA
12092The number of the current inferior. @xref{Inferiors Connections and
12093Programs, ,Debugging Multiple Inferiors Connections and Programs}.
e3940304 12094
5d5658a1
PA
12095@item $_thread
12096The thread number of the current thread. @xref{thread numbers}.
12097
663f6d42
PA
12098@item $_gthread
12099The global number of the current thread. @xref{global thread numbers}.
12100
7734102d
EZ
12101@item $_gdb_major
12102@itemx $_gdb_minor
12103@vindex $_gdb_major@r{, convenience variable}
12104@vindex $_gdb_minor@r{, convenience variable}
12105The major and minor version numbers of the running @value{GDBN}.
12106Development snapshots and pretest versions have their minor version
12107incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
12108the value 12 for @code{$_gdb_minor}. These variables allow you to
12109write scripts that work with different versions of @value{GDBN}
12110without errors caused by features unavailable in some of those
12111versions.
e2c52041
PW
12112
12113@item $_shell_exitcode
12114@itemx $_shell_exitsignal
12115@vindex $_shell_exitcode@r{, convenience variable}
12116@vindex $_shell_exitsignal@r{, convenience variable}
12117@cindex shell command, exit code
12118@cindex shell command, exit signal
12119@cindex exit status of shell commands
12120@value{GDBN} commands such as @code{shell} and @code{|} are launching
12121shell commands. When a launched command terminates, @value{GDBN}
12122automatically maintains the variables @code{$_shell_exitcode}
12123and @code{$_shell_exitsignal} according to the exit status of the last
12124launched command. These variables are set and used similarly to
12125the variables @code{$_exitcode} and @code{$_exitsignal}.
12126
c906108c
SS
12127@end table
12128
a72c3253
DE
12129@node Convenience Funs
12130@section Convenience Functions
12131
bc3b79fd
TJB
12132@cindex convenience functions
12133@value{GDBN} also supplies some @dfn{convenience functions}. These
12134have a syntax similar to convenience variables. A convenience
12135function can be used in an expression just like an ordinary function;
12136however, a convenience function is implemented internally to
12137@value{GDBN}.
12138
a280dbd1
SDJ
12139These functions do not require @value{GDBN} to be configured with
12140@code{Python} support, which means that they are always available.
12141
12142@table @code
12143
12144@item $_isvoid (@var{expr})
12145@findex $_isvoid@r{, convenience function}
12146Return one if the expression @var{expr} is @code{void}. Otherwise it
12147returns zero.
12148
12149A @code{void} expression is an expression where the type of the result
12150is @code{void}. For example, you can examine a convenience variable
12151(see @ref{Convenience Vars,, Convenience Variables}) to check whether
12152it is @code{void}:
12153
12154@smallexample
12155(@value{GDBP}) print $_exitcode
12156$1 = void
12157(@value{GDBP}) print $_isvoid ($_exitcode)
12158$2 = 1
12159(@value{GDBP}) run
12160Starting program: ./a.out
12161[Inferior 1 (process 29572) exited normally]
12162(@value{GDBP}) print $_exitcode
12163$3 = 0
12164(@value{GDBP}) print $_isvoid ($_exitcode)
12165$4 = 0
12166@end smallexample
12167
12168In the example above, we used @code{$_isvoid} to check whether
12169@code{$_exitcode} is @code{void} before and after the execution of the
12170program being debugged. Before the execution there is no exit code to
12171be examined, therefore @code{$_exitcode} is @code{void}. After the
12172execution the program being debugged returned zero, therefore
12173@code{$_exitcode} is zero, which means that it is not @code{void}
12174anymore.
12175
12176The @code{void} expression can also be a call of a function from the
12177program being debugged. For example, given the following function:
12178
12179@smallexample
12180void
12181foo (void)
12182@{
12183@}
12184@end smallexample
12185
12186The result of calling it inside @value{GDBN} is @code{void}:
12187
12188@smallexample
12189(@value{GDBP}) print foo ()
12190$1 = void
12191(@value{GDBP}) print $_isvoid (foo ())
12192$2 = 1
12193(@value{GDBP}) set $v = foo ()
12194(@value{GDBP}) print $v
12195$3 = void
12196(@value{GDBP}) print $_isvoid ($v)
12197$4 = 1
12198@end smallexample
12199
aed61d02
PW
12200@item $_gdb_setting_str (@var{setting})
12201@findex $_gdb_setting_str@r{, convenience function}
12202Return the value of the @value{GDBN} @var{setting} as a string.
12203@var{setting} is any setting that can be used in a @code{set} or
12204@code{show} command (@pxref{Controlling GDB}).
12205
12206@smallexample
12207(@value{GDBP}) show print frame-arguments
12208Printing of non-scalar frame arguments is "scalars".
12209(@value{GDBP}) p $_gdb_setting_str("print frame-arguments")
12210$1 = "scalars"
12211(@value{GDBP}) p $_gdb_setting_str("height")
12212$2 = "30"
12213(@value{GDBP})
12214@end smallexample
12215
12216@item $_gdb_setting (@var{setting})
12217@findex $_gdb_setting@r{, convenience function}
12218Return the value of the @value{GDBN} @var{setting}.
12219The type of the returned value depends on the setting.
12220
12221The value type for boolean and auto boolean settings is @code{int}.
12222The boolean values @code{off} and @code{on} are converted to
12223the integer values @code{0} and @code{1}. The value @code{auto} is
12224converted to the value @code{-1}.
12225
12226The value type for integer settings is either @code{unsigned int}
12227or @code{int}, depending on the setting.
12228
12229Some integer settings accept an @code{unlimited} value.
12230Depending on the setting, the @code{set} command also accepts
12231the value @code{0} or the value @code{@minus{}1} as a synonym for
12232@code{unlimited}.
12233For example, @code{set height unlimited} is equivalent to
12234@code{set height 0}.
12235
12236Some other settings that accept the @code{unlimited} value
12237use the value @code{0} to literally mean zero.
12238For example, @code{set history size 0} indicates to not
12239record any @value{GDBN} commands in the command history.
12240For such settings, @code{@minus{}1} is the synonym
12241for @code{unlimited}.
12242
12243See the documentation of the corresponding @code{set} command for
12244the numerical value equivalent to @code{unlimited}.
12245
12246The @code{$_gdb_setting} function converts the unlimited value
12247to a @code{0} or a @code{@minus{}1} value according to what the
12248@code{set} command uses.
12249
12250@smallexample
12251@group
12252(@value{GDBP}) p $_gdb_setting_str("height")
12253$1 = "30"
12254(@value{GDBP}) p $_gdb_setting("height")
12255$2 = 30
12256(@value{GDBP}) set height unlimited
12257(@value{GDBP}) p $_gdb_setting_str("height")
12258$3 = "unlimited"
12259(@value{GDBP}) p $_gdb_setting("height")
12260$4 = 0
12261@end group
12262@group
12263(@value{GDBP}) p $_gdb_setting_str("history size")
12264$5 = "unlimited"
12265(@value{GDBP}) p $_gdb_setting("history size")
12266$6 = -1
12267(@value{GDBP}) p $_gdb_setting_str("disassemble-next-line")
12268$7 = "auto"
12269(@value{GDBP}) p $_gdb_setting("disassemble-next-line")
12270$8 = -1
12271(@value{GDBP})
12272@end group
12273@end smallexample
12274
12275Other setting types (enum, filename, optional filename, string, string noescape)
12276are returned as string values.
12277
12278
12279@item $_gdb_maint_setting_str (@var{setting})
12280@findex $_gdb_maint_setting_str@r{, convenience function}
12281Like the @code{$_gdb_setting_str} function, but works with
12282@code{maintenance set} variables.
12283
12284@item $_gdb_maint_setting (@var{setting})
12285@findex $_gdb_maint_setting@r{, convenience function}
12286Like the @code{$_gdb_setting} function, but works with
12287@code{maintenance set} variables.
12288
a280dbd1
SDJ
12289@end table
12290
aed61d02 12291The following functions require @value{GDBN} to be configured with
a72c3253
DE
12292@code{Python} support.
12293
12294@table @code
12295
12296@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
12297@findex $_memeq@r{, convenience function}
12298Returns one if the @var{length} bytes at the addresses given by
12299@var{buf1} and @var{buf2} are equal.
12300Otherwise it returns zero.
12301
12302@item $_regex(@var{str}, @var{regex})
12303@findex $_regex@r{, convenience function}
12304Returns one if the string @var{str} matches the regular expression
12305@var{regex}. Otherwise it returns zero.
12306The syntax of the regular expression is that specified by @code{Python}'s
12307regular expression support.
12308
12309@item $_streq(@var{str1}, @var{str2})
12310@findex $_streq@r{, convenience function}
12311Returns one if the strings @var{str1} and @var{str2} are equal.
12312Otherwise it returns zero.
12313
12314@item $_strlen(@var{str})
12315@findex $_strlen@r{, convenience function}
12316Returns the length of string @var{str}.
12317
faa42425
DE
12318@item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12319@findex $_caller_is@r{, convenience function}
12320Returns one if the calling function's name is equal to @var{name}.
12321Otherwise it returns zero.
12322
12323If the optional argument @var{number_of_frames} is provided,
12324it is the number of frames up in the stack to look.
12325The default is 1.
12326
12327Example:
12328
12329@smallexample
12330(gdb) backtrace
12331#0 bottom_func ()
12332 at testsuite/gdb.python/py-caller-is.c:21
12333#1 0x00000000004005a0 in middle_func ()
12334 at testsuite/gdb.python/py-caller-is.c:27
12335#2 0x00000000004005ab in top_func ()
12336 at testsuite/gdb.python/py-caller-is.c:33
12337#3 0x00000000004005b6 in main ()
12338 at testsuite/gdb.python/py-caller-is.c:39
12339(gdb) print $_caller_is ("middle_func")
12340$1 = 1
12341(gdb) print $_caller_is ("top_func", 2)
12342$1 = 1
12343@end smallexample
12344
12345@item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12346@findex $_caller_matches@r{, convenience function}
12347Returns one if the calling function's name matches the regular expression
12348@var{regexp}. Otherwise it returns zero.
12349
12350If the optional argument @var{number_of_frames} is provided,
12351it is the number of frames up in the stack to look.
12352The default is 1.
12353
12354@item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12355@findex $_any_caller_is@r{, convenience function}
12356Returns one if any calling function's name is equal to @var{name}.
12357Otherwise it returns zero.
12358
12359If the optional argument @var{number_of_frames} is provided,
12360it is the number of frames up in the stack to look.
12361The default is 1.
12362
12363This function differs from @code{$_caller_is} in that this function
12364checks all stack frames from the immediate caller to the frame specified
12365by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
12366frame specified by @var{number_of_frames}.
12367
12368@item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12369@findex $_any_caller_matches@r{, convenience function}
12370Returns one if any calling function's name matches the regular expression
12371@var{regexp}. Otherwise it returns zero.
12372
12373If the optional argument @var{number_of_frames} is provided,
12374it is the number of frames up in the stack to look.
12375The default is 1.
12376
12377This function differs from @code{$_caller_matches} in that this function
12378checks all stack frames from the immediate caller to the frame specified
12379by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
12380frame specified by @var{number_of_frames}.
12381
f2f3ccb9
SM
12382@item $_as_string(@var{value})
12383@findex $_as_string@r{, convenience function}
12384Return the string representation of @var{value}.
12385
12386This function is useful to obtain the textual label (enumerator) of an
12387enumeration value. For example, assuming the variable @var{node} is of
12388an enumerated type:
12389
12390@smallexample
12391(gdb) printf "Visiting node of type %s\n", $_as_string(node)
12392Visiting node of type NODE_INTEGER
12393@end smallexample
12394
8bdc1658
AB
12395@item $_cimag(@var{value})
12396@itemx $_creal(@var{value})
12397@findex $_cimag@r{, convenience function}
12398@findex $_creal@r{, convenience function}
12399Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
12400the complex number @var{value}.
12401
12402The type of the imaginary or real part depends on the type of the
12403complex number, e.g., using @code{$_cimag} on a @code{float complex}
12404will return an imaginary part of type @code{float}.
12405
a72c3253
DE
12406@end table
12407
12408@value{GDBN} provides the ability to list and get help on
12409convenience functions.
12410
bc3b79fd
TJB
12411@table @code
12412@item help function
12413@kindex help function
12414@cindex show all convenience functions
12415Print a list of all convenience functions.
12416@end table
12417
6d2ebf8b 12418@node Registers
c906108c
SS
12419@section Registers
12420
12421@cindex registers
12422You can refer to machine register contents, in expressions, as variables
12423with names starting with @samp{$}. The names of registers are different
12424for each machine; use @code{info registers} to see the names used on
12425your machine.
12426
12427@table @code
12428@kindex info registers
12429@item info registers
12430Print the names and values of all registers except floating-point
c85508ee 12431and vector registers (in the selected stack frame).
c906108c
SS
12432
12433@kindex info all-registers
12434@cindex floating point registers
12435@item info all-registers
12436Print the names and values of all registers, including floating-point
c85508ee 12437and vector registers (in the selected stack frame).
c906108c 12438
64cb3757 12439@anchor{info_registers_reggroup}
b67d92b0
SH
12440@item info registers @var{reggroup} @dots{}
12441Print the name and value of the registers in each of the specified
6b92c0d3 12442@var{reggroup}s. The @var{reggroup} can be any of those returned by
b67d92b0
SH
12443@code{maint print reggroups} (@pxref{Maintenance Commands}).
12444
c906108c
SS
12445@item info registers @var{regname} @dots{}
12446Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24 12447As discussed in detail below, register values are normally relative to
697aa1b7 12448the selected stack frame. The @var{regname} may be any register name valid on
c906108c
SS
12449the machine you are using, with or without the initial @samp{$}.
12450@end table
12451
f5b95c01 12452@anchor{standard registers}
e09f16f9
EZ
12453@cindex stack pointer register
12454@cindex program counter register
12455@cindex process status register
12456@cindex frame pointer register
12457@cindex standard registers
c906108c
SS
12458@value{GDBN} has four ``standard'' register names that are available (in
12459expressions) on most machines---whenever they do not conflict with an
12460architecture's canonical mnemonics for registers. The register names
12461@code{$pc} and @code{$sp} are used for the program counter register and
12462the stack pointer. @code{$fp} is used for a register that contains a
12463pointer to the current stack frame, and @code{$ps} is used for a
12464register that contains the processor status. For example,
12465you could print the program counter in hex with
12466
474c8240 12467@smallexample
c906108c 12468p/x $pc
474c8240 12469@end smallexample
c906108c
SS
12470
12471@noindent
12472or print the instruction to be executed next with
12473
474c8240 12474@smallexample
c906108c 12475x/i $pc
474c8240 12476@end smallexample
c906108c
SS
12477
12478@noindent
12479or add four to the stack pointer@footnote{This is a way of removing
12480one word from the stack, on machines where stacks grow downward in
12481memory (most machines, nowadays). This assumes that the innermost
12482stack frame is selected; setting @code{$sp} is not allowed when other
12483stack frames are selected. To pop entire frames off the stack,
12484regardless of machine architecture, use @code{return};
79a6e687 12485see @ref{Returning, ,Returning from a Function}.} with
c906108c 12486
474c8240 12487@smallexample
c906108c 12488set $sp += 4
474c8240 12489@end smallexample
c906108c
SS
12490
12491Whenever possible, these four standard register names are available on
12492your machine even though the machine has different canonical mnemonics,
12493so long as there is no conflict. The @code{info registers} command
12494shows the canonical names. For example, on the SPARC, @code{info
12495registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
12496can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
12497is an alias for the @sc{eflags} register.
c906108c
SS
12498
12499@value{GDBN} always considers the contents of an ordinary register as an
12500integer when the register is examined in this way. Some machines have
12501special registers which can hold nothing but floating point; these
12502registers are considered to have floating point values. There is no way
12503to refer to the contents of an ordinary register as floating point value
12504(although you can @emph{print} it as a floating point value with
12505@samp{print/f $@var{regname}}).
12506
12507Some registers have distinct ``raw'' and ``virtual'' data formats. This
12508means that the data format in which the register contents are saved by
12509the operating system is not the same one that your program normally
12510sees. For example, the registers of the 68881 floating point
12511coprocessor are always saved in ``extended'' (raw) format, but all C
12512programs expect to work with ``double'' (virtual) format. In such
5d161b24 12513cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
12514that makes sense for your program), but the @code{info registers} command
12515prints the data in both formats.
12516
36b80e65
EZ
12517@cindex SSE registers (x86)
12518@cindex MMX registers (x86)
12519Some machines have special registers whose contents can be interpreted
12520in several different ways. For example, modern x86-based machines
12521have SSE and MMX registers that can hold several values packed
12522together in several different formats. @value{GDBN} refers to such
12523registers in @code{struct} notation:
12524
12525@smallexample
12526(@value{GDBP}) print $xmm1
12527$1 = @{
12528 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
12529 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
12530 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
12531 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
12532 v4_int32 = @{0, 20657912, 11, 13@},
12533 v2_int64 = @{88725056443645952, 55834574859@},
12534 uint128 = 0x0000000d0000000b013b36f800000000
12535@}
12536@end smallexample
12537
12538@noindent
12539To set values of such registers, you need to tell @value{GDBN} which
12540view of the register you wish to change, as if you were assigning
12541value to a @code{struct} member:
12542
12543@smallexample
12544 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
12545@end smallexample
12546
c906108c 12547Normally, register values are relative to the selected stack frame
79a6e687 12548(@pxref{Selection, ,Selecting a Frame}). This means that you get the
c906108c
SS
12549value that the register would contain if all stack frames farther in
12550were exited and their saved registers restored. In order to see the
12551true contents of hardware registers, you must select the innermost
12552frame (with @samp{frame 0}).
12553
901461f8
PA
12554@cindex caller-saved registers
12555@cindex call-clobbered registers
12556@cindex volatile registers
12557@cindex <not saved> values
12558Usually ABIs reserve some registers as not needed to be saved by the
12559callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
12560registers). It may therefore not be possible for @value{GDBN} to know
12561the value a register had before the call (in other words, in the outer
12562frame), if the register value has since been changed by the callee.
12563@value{GDBN} tries to deduce where the inner frame saved
12564(``callee-saved'') registers, from the debug info, unwind info, or the
12565machine code generated by your compiler. If some register is not
12566saved, and @value{GDBN} knows the register is ``caller-saved'' (via
12567its own knowledge of the ABI, or because the debug/unwind info
12568explicitly says the register's value is undefined), @value{GDBN}
12569displays @w{@samp{<not saved>}} as the register's value. With targets
12570that @value{GDBN} has no knowledge of the register saving convention,
12571if a register was not saved by the callee, then its value and location
12572in the outer frame are assumed to be the same of the inner frame.
12573This is usually harmless, because if the register is call-clobbered,
12574the caller either does not care what is in the register after the
12575call, or has code to restore the value that it does care about. Note,
12576however, that if you change such a register in the outer frame, you
12577may also be affecting the inner frame. Also, the more ``outer'' the
12578frame is you're looking at, the more likely a call-clobbered
12579register's value is to be wrong, in the sense that it doesn't actually
12580represent the value the register had just before the call.
c906108c 12581
6d2ebf8b 12582@node Floating Point Hardware
79a6e687 12583@section Floating Point Hardware
c906108c
SS
12584@cindex floating point
12585
12586Depending on the configuration, @value{GDBN} may be able to give
12587you more information about the status of the floating point hardware.
12588
12589@table @code
12590@kindex info float
12591@item info float
12592Display hardware-dependent information about the floating
12593point unit. The exact contents and layout vary depending on the
12594floating point chip. Currently, @samp{info float} is supported on
12595the ARM and x86 machines.
12596@end table
c906108c 12597
e76f1f2e
AC
12598@node Vector Unit
12599@section Vector Unit
12600@cindex vector unit
12601
12602Depending on the configuration, @value{GDBN} may be able to give you
12603more information about the status of the vector unit.
12604
12605@table @code
12606@kindex info vector
12607@item info vector
12608Display information about the vector unit. The exact contents and
12609layout vary depending on the hardware.
12610@end table
12611
721c2651 12612@node OS Information
79a6e687 12613@section Operating System Auxiliary Information
721c2651
EZ
12614@cindex OS information
12615
12616@value{GDBN} provides interfaces to useful OS facilities that can help
12617you debug your program.
12618
b383017d
RM
12619@cindex auxiliary vector
12620@cindex vector, auxiliary
b383017d
RM
12621Some operating systems supply an @dfn{auxiliary vector} to programs at
12622startup. This is akin to the arguments and environment that you
12623specify for a program, but contains a system-dependent variety of
12624binary values that tell system libraries important details about the
12625hardware, operating system, and process. Each value's purpose is
12626identified by an integer tag; the meanings are well-known but system-specific.
12627Depending on the configuration and operating system facilities,
9c16f35a
EZ
12628@value{GDBN} may be able to show you this information. For remote
12629targets, this functionality may further depend on the remote stub's
427c3a89
DJ
12630support of the @samp{qXfer:auxv:read} packet, see
12631@ref{qXfer auxiliary vector read}.
b383017d
RM
12632
12633@table @code
12634@kindex info auxv
12635@item info auxv
12636Display the auxiliary vector of the inferior, which can be either a
e4937fc1 12637live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
12638numerically, and also shows names and text descriptions for recognized
12639tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 12640pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
12641most appropriate form for a recognized tag, and in hexadecimal for
12642an unrecognized tag.
12643@end table
12644
85d4a676
SS
12645On some targets, @value{GDBN} can access operating system-specific
12646information and show it to you. The types of information available
12647will differ depending on the type of operating system running on the
12648target. The mechanism used to fetch the data is described in
12649@ref{Operating System Information}. For remote targets, this
12650functionality depends on the remote stub's support of the
07e059b5
VP
12651@samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
12652
12653@table @code
a61408f8 12654@kindex info os
85d4a676
SS
12655@item info os @var{infotype}
12656
12657Display OS information of the requested type.
a61408f8 12658
85d4a676
SS
12659On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
12660
12661@anchor{linux info os infotypes}
12662@table @code
d33279b3
AT
12663@kindex info os cpus
12664@item cpus
12665Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
12666the available fields from /proc/cpuinfo. For each supported architecture
12667different fields are available. Two common entries are processor which gives
12668CPU number and bogomips; a system constant that is calculated during
12669kernel initialization.
12670
12671@kindex info os files
12672@item files
12673Display the list of open file descriptors on the target. For each
12674file descriptor, @value{GDBN} prints the identifier of the process
12675owning the descriptor, the command of the owning process, the value
12676of the descriptor, and the target of the descriptor.
12677
12678@kindex info os modules
12679@item modules
12680Display the list of all loaded kernel modules on the target. For each
12681module, @value{GDBN} prints the module name, the size of the module in
12682bytes, the number of times the module is used, the dependencies of the
12683module, the status of the module, and the address of the loaded module
12684in memory.
12685
12686@kindex info os msg
12687@item msg
12688Display the list of all System V message queues on the target. For each
12689message queue, @value{GDBN} prints the message queue key, the message
12690queue identifier, the access permissions, the current number of bytes
12691on the queue, the current number of messages on the queue, the processes
12692that last sent and received a message on the queue, the user and group
12693of the owner and creator of the message queue, the times at which a
12694message was last sent and received on the queue, and the time at which
12695the message queue was last changed.
12696
07e059b5 12697@kindex info os processes
85d4a676 12698@item processes
07e059b5 12699Display the list of processes on the target. For each process,
85d4a676
SS
12700@value{GDBN} prints the process identifier, the name of the user, the
12701command corresponding to the process, and the list of processor cores
12702that the process is currently running on. (To understand what these
12703properties mean, for this and the following info types, please consult
12704the general @sc{gnu}/Linux documentation.)
12705
12706@kindex info os procgroups
12707@item procgroups
12708Display the list of process groups on the target. For each process,
12709@value{GDBN} prints the identifier of the process group that it belongs
12710to, the command corresponding to the process group leader, the process
12711identifier, and the command line of the process. The list is sorted
12712first by the process group identifier, then by the process identifier,
12713so that processes belonging to the same process group are grouped together
12714and the process group leader is listed first.
12715
d33279b3
AT
12716@kindex info os semaphores
12717@item semaphores
12718Display the list of all System V semaphore sets on the target. For each
12719semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
12720set identifier, the access permissions, the number of semaphores in the
12721set, the user and group of the owner and creator of the semaphore set,
12722and the times at which the semaphore set was operated upon and changed.
85d4a676
SS
12723
12724@kindex info os shm
12725@item shm
12726Display the list of all System V shared-memory regions on the target.
12727For each shared-memory region, @value{GDBN} prints the region key,
12728the shared-memory identifier, the access permissions, the size of the
12729region, the process that created the region, the process that last
12730attached to or detached from the region, the current number of live
12731attaches to the region, and the times at which the region was last
12732attached to, detach from, and changed.
12733
d33279b3
AT
12734@kindex info os sockets
12735@item sockets
12736Display the list of Internet-domain sockets on the target. For each
12737socket, @value{GDBN} prints the address and port of the local and
12738remote endpoints, the current state of the connection, the creator of
12739the socket, the IP address family of the socket, and the type of the
12740connection.
85d4a676 12741
d33279b3
AT
12742@kindex info os threads
12743@item threads
12744Display the list of threads running on the target. For each thread,
12745@value{GDBN} prints the identifier of the process that the thread
12746belongs to, the command of the process, the thread identifier, and the
12747processor core that it is currently running on. The main thread of a
12748process is not listed.
85d4a676
SS
12749@end table
12750
12751@item info os
12752If @var{infotype} is omitted, then list the possible values for
12753@var{infotype} and the kind of OS information available for each
12754@var{infotype}. If the target does not return a list of possible
12755types, this command will report an error.
07e059b5 12756@end table
721c2651 12757
29e57380 12758@node Memory Region Attributes
79a6e687 12759@section Memory Region Attributes
29e57380
C
12760@cindex memory region attributes
12761
b383017d 12762@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
12763required by regions of your target's memory. @value{GDBN} uses
12764attributes to determine whether to allow certain types of memory
12765accesses; whether to use specific width accesses; and whether to cache
12766target memory. By default the description of memory regions is
12767fetched from the target (if the current target supports this), but the
12768user can override the fetched regions.
29e57380
C
12769
12770Defined memory regions can be individually enabled and disabled. When a
12771memory region is disabled, @value{GDBN} uses the default attributes when
12772accessing memory in that region. Similarly, if no memory regions have
12773been defined, @value{GDBN} uses the default attributes when accessing
12774all memory.
12775
b383017d 12776When a memory region is defined, it is given a number to identify it;
29e57380
C
12777to enable, disable, or remove a memory region, you specify that number.
12778
12779@table @code
12780@kindex mem
bfac230e 12781@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
12782Define a memory region bounded by @var{lower} and @var{upper} with
12783attributes @var{attributes}@dots{}, and add it to the list of regions
12784monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
d3e8051b 12785case: it is treated as the target's maximum memory address.
bfac230e 12786(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 12787
fd79ecee
DJ
12788@item mem auto
12789Discard any user changes to the memory regions and use target-supplied
12790regions, if available, or no regions if the target does not support.
12791
29e57380
C
12792@kindex delete mem
12793@item delete mem @var{nums}@dots{}
09d4efe1
EZ
12794Remove memory regions @var{nums}@dots{} from the list of regions
12795monitored by @value{GDBN}.
29e57380
C
12796
12797@kindex disable mem
12798@item disable mem @var{nums}@dots{}
09d4efe1 12799Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 12800A disabled memory region is not forgotten.
29e57380
C
12801It may be enabled again later.
12802
12803@kindex enable mem
12804@item enable mem @var{nums}@dots{}
09d4efe1 12805Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
12806
12807@kindex info mem
12808@item info mem
12809Print a table of all defined memory regions, with the following columns
09d4efe1 12810for each region:
29e57380
C
12811
12812@table @emph
12813@item Memory Region Number
12814@item Enabled or Disabled.
b383017d 12815Enabled memory regions are marked with @samp{y}.
29e57380
C
12816Disabled memory regions are marked with @samp{n}.
12817
12818@item Lo Address
12819The address defining the inclusive lower bound of the memory region.
12820
12821@item Hi Address
12822The address defining the exclusive upper bound of the memory region.
12823
12824@item Attributes
12825The list of attributes set for this memory region.
12826@end table
12827@end table
12828
12829
12830@subsection Attributes
12831
b383017d 12832@subsubsection Memory Access Mode
29e57380
C
12833The access mode attributes set whether @value{GDBN} may make read or
12834write accesses to a memory region.
12835
12836While these attributes prevent @value{GDBN} from performing invalid
12837memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 12838etc.@: from accessing memory.
29e57380
C
12839
12840@table @code
12841@item ro
12842Memory is read only.
12843@item wo
12844Memory is write only.
12845@item rw
6ca652b0 12846Memory is read/write. This is the default.
29e57380
C
12847@end table
12848
12849@subsubsection Memory Access Size
d3e8051b 12850The access size attribute tells @value{GDBN} to use specific sized
29e57380
C
12851accesses in the memory region. Often memory mapped device registers
12852require specific sized accesses. If no access size attribute is
12853specified, @value{GDBN} may use accesses of any size.
12854
12855@table @code
12856@item 8
12857Use 8 bit memory accesses.
12858@item 16
12859Use 16 bit memory accesses.
12860@item 32
12861Use 32 bit memory accesses.
12862@item 64
12863Use 64 bit memory accesses.
12864@end table
12865
12866@c @subsubsection Hardware/Software Breakpoints
12867@c The hardware/software breakpoint attributes set whether @value{GDBN}
12868@c will use hardware or software breakpoints for the internal breakpoints
12869@c used by the step, next, finish, until, etc. commands.
12870@c
12871@c @table @code
12872@c @item hwbreak
b383017d 12873@c Always use hardware breakpoints
29e57380
C
12874@c @item swbreak (default)
12875@c @end table
12876
12877@subsubsection Data Cache
12878The data cache attributes set whether @value{GDBN} will cache target
12879memory. While this generally improves performance by reducing debug
12880protocol overhead, it can lead to incorrect results because @value{GDBN}
12881does not know about volatile variables or memory mapped device
12882registers.
12883
12884@table @code
12885@item cache
b383017d 12886Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
12887@item nocache
12888Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
12889@end table
12890
4b5752d0
VP
12891@subsection Memory Access Checking
12892@value{GDBN} can be instructed to refuse accesses to memory that is
12893not explicitly described. This can be useful if accessing such
12894regions has undesired effects for a specific target, or to provide
12895better error checking. The following commands control this behaviour.
12896
12897@table @code
12898@kindex set mem inaccessible-by-default
12899@item set mem inaccessible-by-default [on|off]
12900If @code{on} is specified, make @value{GDBN} treat memory not
12901explicitly described by the memory ranges as non-existent and refuse accesses
12902to such memory. The checks are only performed if there's at least one
12903memory range defined. If @code{off} is specified, make @value{GDBN}
12904treat the memory not explicitly described by the memory ranges as RAM.
56cf5405 12905The default value is @code{on}.
4b5752d0
VP
12906@kindex show mem inaccessible-by-default
12907@item show mem inaccessible-by-default
12908Show the current handling of accesses to unknown memory.
12909@end table
12910
12911
29e57380 12912@c @subsubsection Memory Write Verification
b383017d 12913@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
12914@c will re-reads data after each write to verify the write was successful.
12915@c
12916@c @table @code
12917@c @item verify
12918@c @item noverify (default)
12919@c @end table
12920
16d9dec6 12921@node Dump/Restore Files
79a6e687 12922@section Copy Between Memory and a File
16d9dec6
MS
12923@cindex dump/restore files
12924@cindex append data to a file
12925@cindex dump data to a file
12926@cindex restore data from a file
16d9dec6 12927
df5215a6
JB
12928You can use the commands @code{dump}, @code{append}, and
12929@code{restore} to copy data between target memory and a file. The
12930@code{dump} and @code{append} commands write data to a file, and the
12931@code{restore} command reads data from a file back into the inferior's
cf75d6c3
AB
12932memory. Files may be in binary, Motorola S-record, Intel hex,
12933Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
12934append to binary files, and cannot read from Verilog Hex files.
df5215a6
JB
12935
12936@table @code
12937
12938@kindex dump
12939@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12940@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
12941Dump the contents of memory from @var{start_addr} to @var{end_addr},
12942or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 12943
df5215a6 12944The @var{format} parameter may be any one of:
16d9dec6 12945@table @code
df5215a6
JB
12946@item binary
12947Raw binary form.
12948@item ihex
12949Intel hex format.
12950@item srec
12951Motorola S-record format.
12952@item tekhex
12953Tektronix Hex format.
cf75d6c3
AB
12954@item verilog
12955Verilog Hex format.
df5215a6
JB
12956@end table
12957
12958@value{GDBN} uses the same definitions of these formats as the
12959@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
12960@var{format} is omitted, @value{GDBN} dumps the data in raw binary
12961form.
12962
12963@kindex append
12964@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12965@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
12966Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 12967or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
12968(@value{GDBN} can only append data to files in raw binary form.)
12969
12970@kindex restore
12971@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
12972Restore the contents of file @var{filename} into memory. The
12973@code{restore} command can automatically recognize any known @sc{bfd}
12974file format, except for raw binary. To restore a raw binary file you
12975must specify the optional keyword @code{binary} after the filename.
16d9dec6 12976
b383017d 12977If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
12978contained in the file. Binary files always start at address zero, so
12979they will be restored at address @var{bias}. Other bfd files have
12980a built-in location; they will be restored at offset @var{bias}
12981from that location.
12982
12983If @var{start} and/or @var{end} are non-zero, then only data between
12984file offset @var{start} and file offset @var{end} will be restored.
b383017d 12985These offsets are relative to the addresses in the file, before
16d9dec6
MS
12986the @var{bias} argument is applied.
12987
12988@end table
12989
384ee23f
EZ
12990@node Core File Generation
12991@section How to Produce a Core File from Your Program
12992@cindex dump core from inferior
12993
12994A @dfn{core file} or @dfn{core dump} is a file that records the memory
12995image of a running process and its process status (register values
12996etc.). Its primary use is post-mortem debugging of a program that
12997crashed while it ran outside a debugger. A program that crashes
12998automatically produces a core file, unless this feature is disabled by
12999the user. @xref{Files}, for information on invoking @value{GDBN} in
13000the post-mortem debugging mode.
13001
13002Occasionally, you may wish to produce a core file of the program you
13003are debugging in order to preserve a snapshot of its state.
13004@value{GDBN} has a special command for that.
13005
13006@table @code
13007@kindex gcore
13008@kindex generate-core-file
13009@item generate-core-file [@var{file}]
13010@itemx gcore [@var{file}]
13011Produce a core dump of the inferior process. The optional argument
13012@var{file} specifies the file name where to put the core dump. If not
13013specified, the file name defaults to @file{core.@var{pid}}, where
13014@var{pid} is the inferior process ID.
13015
13016Note that this command is implemented only for some systems (as of
05b4bd79 13017this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
df8411da
SDJ
13018
13019On @sc{gnu}/Linux, this command can take into account the value of the
13020file @file{/proc/@var{pid}/coredump_filter} when generating the core
1e52e849
SL
13021dump (@pxref{set use-coredump-filter}), and by default honors the
13022@code{VM_DONTDUMP} flag for mappings where it is present in the file
13023@file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
df8411da
SDJ
13024
13025@kindex set use-coredump-filter
13026@anchor{set use-coredump-filter}
13027@item set use-coredump-filter on
13028@itemx set use-coredump-filter off
13029Enable or disable the use of the file
13030@file{/proc/@var{pid}/coredump_filter} when generating core dump
13031files. This file is used by the Linux kernel to decide what types of
13032memory mappings will be dumped or ignored when generating a core dump
13033file. @var{pid} is the process ID of a currently running process.
13034
13035To make use of this feature, you have to write in the
13036@file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
13037which is a bit mask representing the memory mapping types. If a bit
13038is set in the bit mask, then the memory mappings of the corresponding
13039types will be dumped; otherwise, they will be ignored. This
13040configuration is inherited by child processes. For more information
13041about the bits that can be set in the
13042@file{/proc/@var{pid}/coredump_filter} file, please refer to the
13043manpage of @code{core(5)}.
13044
13045By default, this option is @code{on}. If this option is turned
13046@code{off}, @value{GDBN} does not read the @file{coredump_filter} file
13047and instead uses the same default value as the Linux kernel in order
13048to decide which pages will be dumped in the core dump file. This
13049value is currently @code{0x33}, which means that bits @code{0}
13050(anonymous private mappings), @code{1} (anonymous shared mappings),
13051@code{4} (ELF headers) and @code{5} (private huge pages) are active.
13052This will cause these memory mappings to be dumped automatically.
1e52e849
SL
13053
13054@kindex set dump-excluded-mappings
13055@anchor{set dump-excluded-mappings}
13056@item set dump-excluded-mappings on
13057@itemx set dump-excluded-mappings off
13058If @code{on} is specified, @value{GDBN} will dump memory mappings
13059marked with the @code{VM_DONTDUMP} flag. This flag is represented in
13060the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
13061
13062The default value is @code{off}.
384ee23f
EZ
13063@end table
13064
a0eb71c5
KB
13065@node Character Sets
13066@section Character Sets
13067@cindex character sets
13068@cindex charset
13069@cindex translating between character sets
13070@cindex host character set
13071@cindex target character set
13072
13073If the program you are debugging uses a different character set to
13074represent characters and strings than the one @value{GDBN} uses itself,
13075@value{GDBN} can automatically translate between the character sets for
13076you. The character set @value{GDBN} uses we call the @dfn{host
13077character set}; the one the inferior program uses we call the
13078@dfn{target character set}.
13079
13080For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
13081uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
ea35711c 13082remote protocol (@pxref{Remote Debugging}) to debug a program
a0eb71c5
KB
13083running on an IBM mainframe, which uses the @sc{ebcdic} character set,
13084then the host character set is Latin-1, and the target character set is
13085@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 13086target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
13087@sc{ebcdic} and Latin 1 as you print character or string values, or use
13088character and string literals in expressions.
13089
13090@value{GDBN} has no way to automatically recognize which character set
13091the inferior program uses; you must tell it, using the @code{set
13092target-charset} command, described below.
13093
13094Here are the commands for controlling @value{GDBN}'s character set
13095support:
13096
13097@table @code
13098@item set target-charset @var{charset}
13099@kindex set target-charset
10af6951
EZ
13100Set the current target character set to @var{charset}. To display the
13101list of supported target character sets, type
13102@kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
a0eb71c5 13103
a0eb71c5
KB
13104@item set host-charset @var{charset}
13105@kindex set host-charset
13106Set the current host character set to @var{charset}.
13107
13108By default, @value{GDBN} uses a host character set appropriate to the
13109system it is running on; you can override that default using the
732f6a93
TT
13110@code{set host-charset} command. On some systems, @value{GDBN} cannot
13111automatically determine the appropriate host character set. In this
13112case, @value{GDBN} uses @samp{UTF-8}.
a0eb71c5
KB
13113
13114@value{GDBN} can only use certain character sets as its host character
c1b6b909 13115set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
10af6951 13116@value{GDBN} will list the host character sets it supports.
a0eb71c5
KB
13117
13118@item set charset @var{charset}
13119@kindex set charset
e33d66ec 13120Set the current host and target character sets to @var{charset}. As
10af6951
EZ
13121above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
13122@value{GDBN} will list the names of the character sets that can be used
e33d66ec
EZ
13123for both host and target.
13124
a0eb71c5 13125@item show charset
a0eb71c5 13126@kindex show charset
10af6951 13127Show the names of the current host and target character sets.
e33d66ec 13128
10af6951 13129@item show host-charset
a0eb71c5 13130@kindex show host-charset
10af6951 13131Show the name of the current host character set.
e33d66ec 13132
10af6951 13133@item show target-charset
a0eb71c5 13134@kindex show target-charset
10af6951 13135Show the name of the current target character set.
a0eb71c5 13136
10af6951
EZ
13137@item set target-wide-charset @var{charset}
13138@kindex set target-wide-charset
13139Set the current target's wide character set to @var{charset}. This is
13140the character set used by the target's @code{wchar_t} type. To
13141display the list of supported wide character sets, type
13142@kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
13143
13144@item show target-wide-charset
13145@kindex show target-wide-charset
13146Show the name of the current target's wide character set.
a0eb71c5
KB
13147@end table
13148
a0eb71c5
KB
13149Here is an example of @value{GDBN}'s character set support in action.
13150Assume that the following source code has been placed in the file
13151@file{charset-test.c}:
13152
13153@smallexample
13154#include <stdio.h>
13155
13156char ascii_hello[]
13157 = @{72, 101, 108, 108, 111, 44, 32, 119,
13158 111, 114, 108, 100, 33, 10, 0@};
13159char ibm1047_hello[]
13160 = @{200, 133, 147, 147, 150, 107, 64, 166,
13161 150, 153, 147, 132, 90, 37, 0@};
13162
13163main ()
13164@{
13165 printf ("Hello, world!\n");
13166@}
10998722 13167@end smallexample
a0eb71c5
KB
13168
13169In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
13170containing the string @samp{Hello, world!} followed by a newline,
13171encoded in the @sc{ascii} and @sc{ibm1047} character sets.
13172
13173We compile the program, and invoke the debugger on it:
13174
13175@smallexample
13176$ gcc -g charset-test.c -o charset-test
13177$ gdb -nw charset-test
13178GNU gdb 2001-12-19-cvs
13179Copyright 2001 Free Software Foundation, Inc.
13180@dots{}
f7dc1244 13181(@value{GDBP})
10998722 13182@end smallexample
a0eb71c5
KB
13183
13184We can use the @code{show charset} command to see what character sets
13185@value{GDBN} is currently using to interpret and display characters and
13186strings:
13187
13188@smallexample
f7dc1244 13189(@value{GDBP}) show charset
e33d66ec 13190The current host and target character set is `ISO-8859-1'.
f7dc1244 13191(@value{GDBP})
10998722 13192@end smallexample
a0eb71c5
KB
13193
13194For the sake of printing this manual, let's use @sc{ascii} as our
13195initial character set:
13196@smallexample
f7dc1244
EZ
13197(@value{GDBP}) set charset ASCII
13198(@value{GDBP}) show charset
e33d66ec 13199The current host and target character set is `ASCII'.
f7dc1244 13200(@value{GDBP})
10998722 13201@end smallexample
a0eb71c5
KB
13202
13203Let's assume that @sc{ascii} is indeed the correct character set for our
13204host system --- in other words, let's assume that if @value{GDBN} prints
13205characters using the @sc{ascii} character set, our terminal will display
13206them properly. Since our current target character set is also
13207@sc{ascii}, the contents of @code{ascii_hello} print legibly:
13208
13209@smallexample
f7dc1244 13210(@value{GDBP}) print ascii_hello
a0eb71c5 13211$1 = 0x401698 "Hello, world!\n"
f7dc1244 13212(@value{GDBP}) print ascii_hello[0]
a0eb71c5 13213$2 = 72 'H'
f7dc1244 13214(@value{GDBP})
10998722 13215@end smallexample
a0eb71c5
KB
13216
13217@value{GDBN} uses the target character set for character and string
13218literals you use in expressions:
13219
13220@smallexample
f7dc1244 13221(@value{GDBP}) print '+'
a0eb71c5 13222$3 = 43 '+'
f7dc1244 13223(@value{GDBP})
10998722 13224@end smallexample
a0eb71c5
KB
13225
13226The @sc{ascii} character set uses the number 43 to encode the @samp{+}
13227character.
13228
13229@value{GDBN} relies on the user to tell it which character set the
13230target program uses. If we print @code{ibm1047_hello} while our target
13231character set is still @sc{ascii}, we get jibberish:
13232
13233@smallexample
f7dc1244 13234(@value{GDBP}) print ibm1047_hello
a0eb71c5 13235$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 13236(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 13237$5 = 200 '\310'
f7dc1244 13238(@value{GDBP})
10998722 13239@end smallexample
a0eb71c5 13240
e33d66ec 13241If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
13242@value{GDBN} tells us the character sets it supports:
13243
13244@smallexample
f7dc1244 13245(@value{GDBP}) set target-charset
b383017d 13246ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 13247(@value{GDBP}) set target-charset
10998722 13248@end smallexample
a0eb71c5
KB
13249
13250We can select @sc{ibm1047} as our target character set, and examine the
13251program's strings again. Now the @sc{ascii} string is wrong, but
13252@value{GDBN} translates the contents of @code{ibm1047_hello} from the
13253target character set, @sc{ibm1047}, to the host character set,
13254@sc{ascii}, and they display correctly:
13255
13256@smallexample
f7dc1244
EZ
13257(@value{GDBP}) set target-charset IBM1047
13258(@value{GDBP}) show charset
e33d66ec
EZ
13259The current host character set is `ASCII'.
13260The current target character set is `IBM1047'.
f7dc1244 13261(@value{GDBP}) print ascii_hello
a0eb71c5 13262$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 13263(@value{GDBP}) print ascii_hello[0]
a0eb71c5 13264$7 = 72 '\110'
f7dc1244 13265(@value{GDBP}) print ibm1047_hello
a0eb71c5 13266$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 13267(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 13268$9 = 200 'H'
f7dc1244 13269(@value{GDBP})
10998722 13270@end smallexample
a0eb71c5
KB
13271
13272As above, @value{GDBN} uses the target character set for character and
13273string literals you use in expressions:
13274
13275@smallexample
f7dc1244 13276(@value{GDBP}) print '+'
a0eb71c5 13277$10 = 78 '+'
f7dc1244 13278(@value{GDBP})
10998722 13279@end smallexample
a0eb71c5 13280
e33d66ec 13281The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
13282character.
13283
b12039c6
YQ
13284@node Caching Target Data
13285@section Caching Data of Targets
13286@cindex caching data of targets
13287
13288@value{GDBN} caches data exchanged between the debugger and a target.
b26dfc9a 13289Each cache is associated with the address space of the inferior.
65c574f6 13290@xref{Inferiors Connections and Programs}, about inferior and address space.
b12039c6
YQ
13291Such caching generally improves performance in remote debugging
13292(@pxref{Remote Debugging}), because it reduces the overhead of the
13293remote protocol by bundling memory reads and writes into large chunks.
13294Unfortunately, simply caching everything would lead to incorrect results,
13295since @value{GDBN} does not necessarily know anything about volatile
13296values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
13297(@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
13298is executing.
29b090c0
DE
13299Therefore, by default, @value{GDBN} only caches data
13300known to be on the stack@footnote{In non-stop mode, it is moderately
13301rare for a running thread to modify the stack of a stopped thread
13302in a way that would interfere with a backtrace, and caching of
29453a14
YQ
13303stack reads provides a significant speed up of remote backtraces.} or
13304in the code segment.
29b090c0 13305Other regions of memory can be explicitly marked as
27b81af3 13306cacheable; @pxref{Memory Region Attributes}.
09d4efe1
EZ
13307
13308@table @code
13309@kindex set remotecache
13310@item set remotecache on
13311@itemx set remotecache off
4e5d721f
DE
13312This option no longer does anything; it exists for compatibility
13313with old scripts.
09d4efe1
EZ
13314
13315@kindex show remotecache
13316@item show remotecache
4e5d721f
DE
13317Show the current state of the obsolete remotecache flag.
13318
13319@kindex set stack-cache
13320@item set stack-cache on
13321@itemx set stack-cache off
6dd315ba
YQ
13322Enable or disable caching of stack accesses. When @code{on}, use
13323caching. By default, this option is @code{on}.
4e5d721f
DE
13324
13325@kindex show stack-cache
13326@item show stack-cache
13327Show the current state of data caching for memory accesses.
09d4efe1 13328
29453a14
YQ
13329@kindex set code-cache
13330@item set code-cache on
13331@itemx set code-cache off
13332Enable or disable caching of code segment accesses. When @code{on},
13333use caching. By default, this option is @code{on}. This improves
13334performance of disassembly in remote debugging.
13335
13336@kindex show code-cache
13337@item show code-cache
13338Show the current state of target memory cache for code segment
13339accesses.
13340
09d4efe1 13341@kindex info dcache
4e5d721f 13342@item info dcache @r{[}line@r{]}
b26dfc9a
YQ
13343Print the information about the performance of data cache of the
13344current inferior's address space. The information displayed
13345includes the dcache width and depth, and for each cache line, its
13346number, address, and how many times it was referenced. This
13347command is useful for debugging the data cache operation.
4e5d721f
DE
13348
13349If a line number is specified, the contents of that line will be
13350printed in hex.
1a532630
PP
13351
13352@item set dcache size @var{size}
13353@cindex dcache size
13354@kindex set dcache size
13355Set maximum number of entries in dcache (dcache depth above).
13356
13357@item set dcache line-size @var{line-size}
13358@cindex dcache line-size
13359@kindex set dcache line-size
13360Set number of bytes each dcache entry caches (dcache width above).
13361Must be a power of 2.
13362
13363@item show dcache size
13364@kindex show dcache size
b12039c6 13365Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
1a532630
PP
13366
13367@item show dcache line-size
13368@kindex show dcache line-size
b12039c6 13369Show default size of dcache lines.
1a532630 13370
09d4efe1
EZ
13371@end table
13372
08388c79
DE
13373@node Searching Memory
13374@section Search Memory
13375@cindex searching memory
13376
13377Memory can be searched for a particular sequence of bytes with the
13378@code{find} command.
13379
13380@table @code
13381@kindex find
13382@item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13383@itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13384Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
13385etc. The search begins at address @var{start_addr} and continues for either
13386@var{len} bytes or through to @var{end_addr} inclusive.
13387@end table
13388
13389@var{s} and @var{n} are optional parameters.
13390They may be specified in either order, apart or together.
13391
13392@table @r
13393@item @var{s}, search query size
13394The size of each search query value.
13395
13396@table @code
13397@item b
13398bytes
13399@item h
13400halfwords (two bytes)
13401@item w
13402words (four bytes)
13403@item g
13404giant words (eight bytes)
13405@end table
13406
13407All values are interpreted in the current language.
13408This means, for example, that if the current source language is C/C@t{++}
13409then searching for the string ``hello'' includes the trailing '\0'.
ee9a09e9
DC
13410The null terminator can be removed from searching by using casts,
13411e.g.: @samp{@{char[5]@}"hello"}.
08388c79
DE
13412
13413If the value size is not specified, it is taken from the
13414value's type in the current language.
13415This is useful when one wants to specify the search
13416pattern as a mixture of types.
13417Note that this means, for example, that in the case of C-like languages
13418a search for an untyped 0x42 will search for @samp{(int) 0x42}
13419which is typically four bytes.
13420
13421@item @var{n}, maximum number of finds
13422The maximum number of matches to print. The default is to print all finds.
13423@end table
13424
13425You can use strings as search values. Quote them with double-quotes
13426 (@code{"}).
13427The string value is copied into the search pattern byte by byte,
13428regardless of the endianness of the target and the size specification.
13429
13430The address of each match found is printed as well as a count of the
13431number of matches found.
13432
13433The address of the last value found is stored in convenience variable
13434@samp{$_}.
13435A count of the number of matches is stored in @samp{$numfound}.
13436
13437For example, if stopped at the @code{printf} in this function:
13438
13439@smallexample
13440void
13441hello ()
13442@{
13443 static char hello[] = "hello-hello";
13444 static struct @{ char c; short s; int i; @}
13445 __attribute__ ((packed)) mixed
13446 = @{ 'c', 0x1234, 0x87654321 @};
13447 printf ("%s\n", hello);
13448@}
13449@end smallexample
13450
13451@noindent
13452you get during debugging:
13453
13454@smallexample
13455(gdb) find &hello[0], +sizeof(hello), "hello"
134560x804956d <hello.1620+6>
134571 pattern found
13458(gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
134590x8049567 <hello.1620>
134600x804956d <hello.1620+6>
ee9a09e9
DC
134612 patterns found.
13462(gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
134630x8049567 <hello.1620>
134640x804956d <hello.1620+6>
134652 patterns found.
08388c79
DE
13466(gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
134670x8049567 <hello.1620>
134681 pattern found
13469(gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
134700x8049560 <mixed.1625>
134711 pattern found
13472(gdb) print $numfound
13473$1 = 1
13474(gdb) print $_
13475$2 = (void *) 0x8049560
13476@end smallexample
a0eb71c5 13477
5fdf6324
AB
13478@node Value Sizes
13479@section Value Sizes
13480
13481Whenever @value{GDBN} prints a value memory will be allocated within
13482@value{GDBN} to hold the contents of the value. It is possible in
13483some languages with dynamic typing systems, that an invalid program
13484may indicate a value that is incorrectly large, this in turn may cause
6b92c0d3 13485@value{GDBN} to try and allocate an overly large amount of memory.
5fdf6324
AB
13486
13487@table @code
13488@kindex set max-value-size
713cdcbf 13489@item set max-value-size @var{bytes}
5fdf6324
AB
13490@itemx set max-value-size unlimited
13491Set the maximum size of memory that @value{GDBN} will allocate for the
13492contents of a value to @var{bytes}, trying to display a value that
13493requires more memory than that will result in an error.
13494
13495Setting this variable does not effect values that have already been
13496allocated within @value{GDBN}, only future allocations.
13497
13498There's a minimum size that @code{max-value-size} can be set to in
13499order that @value{GDBN} can still operate correctly, this minimum is
13500currently 16 bytes.
13501
13502The limit applies to the results of some subexpressions as well as to
13503complete expressions. For example, an expression denoting a simple
13504integer component, such as @code{x.y.z}, may fail if the size of
13505@var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
13506@value{GDBN} is sometimes clever; the expression @code{A[i]}, where
13507@var{A} is an array variable with non-constant size, will generally
13508succeed regardless of the bounds on @var{A}, as long as the component
13509size is less than @var{bytes}.
13510
13511The default value of @code{max-value-size} is currently 64k.
13512
13513@kindex show max-value-size
13514@item show max-value-size
13515Show the maximum size of memory, in bytes, that @value{GDBN} will
13516allocate for the contents of a value.
13517@end table
13518
edb3359d
DJ
13519@node Optimized Code
13520@chapter Debugging Optimized Code
13521@cindex optimized code, debugging
13522@cindex debugging optimized code
13523
13524Almost all compilers support optimization. With optimization
13525disabled, the compiler generates assembly code that corresponds
13526directly to your source code, in a simplistic way. As the compiler
13527applies more powerful optimizations, the generated assembly code
13528diverges from your original source code. With help from debugging
13529information generated by the compiler, @value{GDBN} can map from
13530the running program back to constructs from your original source.
13531
13532@value{GDBN} is more accurate with optimization disabled. If you
13533can recompile without optimization, it is easier to follow the
13534progress of your program during debugging. But, there are many cases
13535where you may need to debug an optimized version.
13536
13537When you debug a program compiled with @samp{-g -O}, remember that the
13538optimizer has rearranged your code; the debugger shows you what is
13539really there. Do not be too surprised when the execution path does not
13540exactly match your source file! An extreme example: if you define a
13541variable, but never use it, @value{GDBN} never sees that
13542variable---because the compiler optimizes it out of existence.
13543
13544Some things do not work as well with @samp{-g -O} as with just
13545@samp{-g}, particularly on machines with instruction scheduling. If in
13546doubt, recompile with @samp{-g} alone, and if this fixes the problem,
13547please report it to us as a bug (including a test case!).
13548@xref{Variables}, for more information about debugging optimized code.
13549
13550@menu
13551* Inline Functions:: How @value{GDBN} presents inlining
111c6489 13552* Tail Call Frames:: @value{GDBN} analysis of jumps to functions
edb3359d
DJ
13553@end menu
13554
13555@node Inline Functions
13556@section Inline Functions
13557@cindex inline functions, debugging
13558
13559@dfn{Inlining} is an optimization that inserts a copy of the function
13560body directly at each call site, instead of jumping to a shared
13561routine. @value{GDBN} displays inlined functions just like
13562non-inlined functions. They appear in backtraces. You can view their
13563arguments and local variables, step into them with @code{step}, skip
13564them with @code{next}, and escape from them with @code{finish}.
13565You can check whether a function was inlined by using the
13566@code{info frame} command.
13567
13568For @value{GDBN} to support inlined functions, the compiler must
13569record information about inlining in the debug information ---
13570@value{NGCC} using the @sc{dwarf 2} format does this, and several
13571other compilers do also. @value{GDBN} only supports inlined functions
13572when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
13573do not emit two required attributes (@samp{DW_AT_call_file} and
13574@samp{DW_AT_call_line}); @value{GDBN} does not display inlined
13575function calls with earlier versions of @value{NGCC}. It instead
13576displays the arguments and local variables of inlined functions as
13577local variables in the caller.
13578
13579The body of an inlined function is directly included at its call site;
13580unlike a non-inlined function, there are no instructions devoted to
13581the call. @value{GDBN} still pretends that the call site and the
13582start of the inlined function are different instructions. Stepping to
13583the call site shows the call site, and then stepping again shows
13584the first line of the inlined function, even though no additional
13585instructions are executed.
13586
13587This makes source-level debugging much clearer; you can see both the
13588context of the call and then the effect of the call. Only stepping by
13589a single instruction using @code{stepi} or @code{nexti} does not do
13590this; single instruction steps always show the inlined body.
13591
13592There are some ways that @value{GDBN} does not pretend that inlined
13593function calls are the same as normal calls:
13594
13595@itemize @bullet
edb3359d
DJ
13596@item
13597Setting breakpoints at the call site of an inlined function may not
13598work, because the call site does not contain any code. @value{GDBN}
13599may incorrectly move the breakpoint to the next line of the enclosing
13600function, after the call. This limitation will be removed in a future
13601version of @value{GDBN}; until then, set a breakpoint on an earlier line
13602or inside the inlined function instead.
13603
13604@item
13605@value{GDBN} cannot locate the return value of inlined calls after
13606using the @code{finish} command. This is a limitation of compiler-generated
13607debugging information; after @code{finish}, you can step to the next line
13608and print a variable where your program stored the return value.
13609
13610@end itemize
13611
111c6489
JK
13612@node Tail Call Frames
13613@section Tail Call Frames
13614@cindex tail call frames, debugging
13615
13616Function @code{B} can call function @code{C} in its very last statement. In
13617unoptimized compilation the call of @code{C} is immediately followed by return
13618instruction at the end of @code{B} code. Optimizing compiler may replace the
13619call and return in function @code{B} into one jump to function @code{C}
13620instead. Such use of a jump instruction is called @dfn{tail call}.
13621
13622During execution of function @code{C}, there will be no indication in the
13623function call stack frames that it was tail-called from @code{B}. If function
13624@code{A} regularly calls function @code{B} which tail-calls function @code{C},
13625then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
13626some cases @value{GDBN} can determine that @code{C} was tail-called from
13627@code{B}, and it will then create fictitious call frame for that, with the
13628return address set up as if @code{B} called @code{C} normally.
13629
13630This functionality is currently supported only by DWARF 2 debugging format and
216f72a1 13631the compiler has to produce @samp{DW_TAG_call_site} tags. With
111c6489
JK
13632@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
13633this information.
13634
13635@kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
13636kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
13637
13638@smallexample
13639(gdb) x/i $pc - 2
13640 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
13641(gdb) info frame
13642Stack level 1, frame at 0x7fffffffda30:
13643 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
13644 tail call frame, caller of frame at 0x7fffffffda30
13645 source language c++.
13646 Arglist at unknown address.
13647 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
13648@end smallexample
13649
13650The detection of all the possible code path executions can find them ambiguous.
13651There is no execution history stored (possible @ref{Reverse Execution} is never
13652used for this purpose) and the last known caller could have reached the known
13653callee by multiple different jump sequences. In such case @value{GDBN} still
13654tries to show at least all the unambiguous top tail callers and all the
13655unambiguous bottom tail calees, if any.
13656
13657@table @code
e18b2753 13658@anchor{set debug entry-values}
111c6489
JK
13659@item set debug entry-values
13660@kindex set debug entry-values
13661When set to on, enables printing of analysis messages for both frame argument
13662values at function entry and tail calls. It will show all the possible valid
13663tail calls code paths it has considered. It will also print the intersection
13664of them with the final unambiguous (possibly partial or even empty) code path
13665result.
13666
13667@item show debug entry-values
13668@kindex show debug entry-values
13669Show the current state of analysis messages printing for both frame argument
13670values at function entry and tail calls.
13671@end table
13672
13673The analysis messages for tail calls can for example show why the virtual tail
13674call frame for function @code{c} has not been recognized (due to the indirect
13675reference by variable @code{x}):
13676
13677@smallexample
13678static void __attribute__((noinline, noclone)) c (void);
13679void (*x) (void) = c;
13680static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13681static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
13682int main (void) @{ x (); return 0; @}
13683
216f72a1
JK
13684Breakpoint 1, DW_OP_entry_value resolving cannot find
13685DW_TAG_call_site 0x40039a in main
111c6489
JK
13686a () at t.c:3
136873 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13688(gdb) bt
13689#0 a () at t.c:3
13690#1 0x000000000040039a in main () at t.c:5
13691@end smallexample
13692
13693Another possibility is an ambiguous virtual tail call frames resolution:
13694
13695@smallexample
13696int i;
13697static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
13698static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
13699static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
13700static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
13701static void __attribute__((noinline, noclone)) b (void)
13702@{ if (i) c (); else e (); @}
13703static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
13704int main (void) @{ a (); return 0; @}
13705
13706tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
13707tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
13708tailcall: reduced: 0x4004d2(a) |
13709(gdb) bt
13710#0 f () at t.c:2
13711#1 0x00000000004004d2 in a () at t.c:8
13712#2 0x0000000000400395 in main () at t.c:9
13713@end smallexample
13714
5048e516
JK
13715@set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
13716@set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
13717
13718@c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
13719@ifset HAVE_MAKEINFO_CLICK
13720@set ARROW @click{}
13721@set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
13722@set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
13723@end ifset
13724@ifclear HAVE_MAKEINFO_CLICK
13725@set ARROW ->
13726@set CALLSEQ1B @value{CALLSEQ1A}
13727@set CALLSEQ2B @value{CALLSEQ2A}
13728@end ifclear
13729
13730Frames #0 and #2 are real, #1 is a virtual tail call frame.
13731The code can have possible execution paths @value{CALLSEQ1B} or
13732@value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
111c6489
JK
13733
13734@code{initial:} state shows some random possible calling sequence @value{GDBN}
6b92c0d3 13735has found. It then finds another possible calling sequence - that one is
111c6489
JK
13736prefixed by @code{compare:}. The non-ambiguous intersection of these two is
13737printed as the @code{reduced:} calling sequence. That one could have many
6b92c0d3 13738further @code{compare:} and @code{reduced:} statements as long as there remain
111c6489
JK
13739any non-ambiguous sequence entries.
13740
13741For the frame of function @code{b} in both cases there are different possible
13742@code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
6b92c0d3 13743also ambiguous. The only non-ambiguous frame is the one for function @code{a},
111c6489
JK
13744therefore this one is displayed to the user while the ambiguous frames are
13745omitted.
edb3359d 13746
e18b2753
JK
13747There can be also reasons why printing of frame argument values at function
13748entry may fail:
13749
13750@smallexample
13751int v;
13752static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
13753static void __attribute__((noinline, noclone)) a (int i);
13754static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
13755static void __attribute__((noinline, noclone)) a (int i)
13756@{ if (i) b (i - 1); else c (0); @}
13757int main (void) @{ a (5); return 0; @}
13758
13759(gdb) bt
13760#0 c (i=i@@entry=0) at t.c:2
216f72a1 13761#1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
e18b2753
JK
13762function "a" at 0x400420 can call itself via tail calls
13763i=<optimized out>) at t.c:6
13764#2 0x000000000040036e in main () at t.c:7
13765@end smallexample
13766
13767@value{GDBN} cannot find out from the inferior state if and how many times did
13768function @code{a} call itself (via function @code{b}) as these calls would be
6b92c0d3 13769tail calls. Such tail calls would modify the @code{i} variable, therefore
e18b2753
JK
13770@value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
13771prints @code{<optimized out>} instead.
13772
e2e0bcd1
JB
13773@node Macros
13774@chapter C Preprocessor Macros
13775
49efadf5 13776Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
13777``preprocessor macros'' which expand into strings of tokens.
13778@value{GDBN} can evaluate expressions containing macro invocations, show
13779the result of macro expansion, and show a macro's definition, including
13780where it was defined.
13781
13782You may need to compile your program specially to provide @value{GDBN}
13783with information about preprocessor macros. Most compilers do not
13784include macros in their debugging information, even when you compile
13785with the @option{-g} flag. @xref{Compilation}.
13786
13787A program may define a macro at one point, remove that definition later,
13788and then provide a different definition after that. Thus, at different
13789points in the program, a macro may have different definitions, or have
13790no definition at all. If there is a current stack frame, @value{GDBN}
13791uses the macros in scope at that frame's source code line. Otherwise,
13792@value{GDBN} uses the macros in scope at the current listing location;
13793see @ref{List}.
13794
e2e0bcd1
JB
13795Whenever @value{GDBN} evaluates an expression, it always expands any
13796macro invocations present in the expression. @value{GDBN} also provides
13797the following commands for working with macros explicitly.
13798
13799@table @code
13800
13801@kindex macro expand
13802@cindex macro expansion, showing the results of preprocessor
13803@cindex preprocessor macro expansion, showing the results of
13804@cindex expanding preprocessor macros
13805@item macro expand @var{expression}
13806@itemx macro exp @var{expression}
13807Show the results of expanding all preprocessor macro invocations in
13808@var{expression}. Since @value{GDBN} simply expands macros, but does
13809not parse the result, @var{expression} need not be a valid expression;
13810it can be any string of tokens.
13811
09d4efe1 13812@kindex macro exp1
e2e0bcd1
JB
13813@item macro expand-once @var{expression}
13814@itemx macro exp1 @var{expression}
4644b6e3 13815@cindex expand macro once
e2e0bcd1
JB
13816@i{(This command is not yet implemented.)} Show the results of
13817expanding those preprocessor macro invocations that appear explicitly in
13818@var{expression}. Macro invocations appearing in that expansion are
13819left unchanged. This command allows you to see the effect of a
13820particular macro more clearly, without being confused by further
13821expansions. Since @value{GDBN} simply expands macros, but does not
13822parse the result, @var{expression} need not be a valid expression; it
13823can be any string of tokens.
13824
475b0867 13825@kindex info macro
e2e0bcd1 13826@cindex macro definition, showing
9b158ba0 13827@cindex definition of a macro, showing
13828@cindex macros, from debug info
71eba9c2 13829@item info macro [-a|-all] [--] @var{macro}
13830Show the current definition or all definitions of the named @var{macro},
13831and describe the source location or compiler command-line where that
13832definition was established. The optional double dash is to signify the end of
13833argument processing and the beginning of @var{macro} for non C-like macros where
13834the macro may begin with a hyphen.
e2e0bcd1 13835
9b158ba0 13836@kindex info macros
629500fa 13837@item info macros @var{location}
9b158ba0 13838Show all macro definitions that are in effect at the location specified
629500fa 13839by @var{location}, and describe the source location or compiler
9b158ba0 13840command-line where those definitions were established.
13841
e2e0bcd1
JB
13842@kindex macro define
13843@cindex user-defined macros
13844@cindex defining macros interactively
13845@cindex macros, user-defined
13846@item macro define @var{macro} @var{replacement-list}
13847@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
d7d9f01e
TT
13848Introduce a definition for a preprocessor macro named @var{macro},
13849invocations of which are replaced by the tokens given in
13850@var{replacement-list}. The first form of this command defines an
13851``object-like'' macro, which takes no arguments; the second form
13852defines a ``function-like'' macro, which takes the arguments given in
13853@var{arglist}.
13854
13855A definition introduced by this command is in scope in every
13856expression evaluated in @value{GDBN}, until it is removed with the
13857@code{macro undef} command, described below. The definition overrides
13858all definitions for @var{macro} present in the program being debugged,
13859as well as any previous user-supplied definition.
e2e0bcd1
JB
13860
13861@kindex macro undef
13862@item macro undef @var{macro}
d7d9f01e
TT
13863Remove any user-supplied definition for the macro named @var{macro}.
13864This command only affects definitions provided with the @code{macro
13865define} command, described above; it cannot remove definitions present
13866in the program being debugged.
e2e0bcd1 13867
09d4efe1
EZ
13868@kindex macro list
13869@item macro list
d7d9f01e 13870List all the macros defined using the @code{macro define} command.
e2e0bcd1
JB
13871@end table
13872
13873@cindex macros, example of debugging with
13874Here is a transcript showing the above commands in action. First, we
13875show our source files:
13876
13877@smallexample
13878$ cat sample.c
13879#include <stdio.h>
13880#include "sample.h"
13881
13882#define M 42
13883#define ADD(x) (M + x)
13884
13885main ()
13886@{
13887#define N 28
13888 printf ("Hello, world!\n");
13889#undef N
13890 printf ("We're so creative.\n");
13891#define N 1729
13892 printf ("Goodbye, world!\n");
13893@}
13894$ cat sample.h
13895#define Q <
13896$
13897@end smallexample
13898
e0f8f636
TT
13899Now, we compile the program using the @sc{gnu} C compiler,
13900@value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
13901minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
13902and @option{-gdwarf-4}; we recommend always choosing the most recent
13903version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
13904includes information about preprocessor macros in the debugging
e2e0bcd1
JB
13905information.
13906
13907@smallexample
13908$ gcc -gdwarf-2 -g3 sample.c -o sample
13909$
13910@end smallexample
13911
13912Now, we start @value{GDBN} on our sample program:
13913
13914@smallexample
13915$ gdb -nw sample
13916GNU gdb 2002-05-06-cvs
13917Copyright 2002 Free Software Foundation, Inc.
13918GDB is free software, @dots{}
f7dc1244 13919(@value{GDBP})
e2e0bcd1
JB
13920@end smallexample
13921
13922We can expand macros and examine their definitions, even when the
13923program is not running. @value{GDBN} uses the current listing position
13924to decide which macro definitions are in scope:
13925
13926@smallexample
f7dc1244 13927(@value{GDBP}) list main
e2e0bcd1
JB
139283
139294 #define M 42
139305 #define ADD(x) (M + x)
139316
139327 main ()
139338 @{
139349 #define N 28
1393510 printf ("Hello, world!\n");
1393611 #undef N
1393712 printf ("We're so creative.\n");
f7dc1244 13938(@value{GDBP}) info macro ADD
e2e0bcd1
JB
13939Defined at /home/jimb/gdb/macros/play/sample.c:5
13940#define ADD(x) (M + x)
f7dc1244 13941(@value{GDBP}) info macro Q
e2e0bcd1
JB
13942Defined at /home/jimb/gdb/macros/play/sample.h:1
13943 included at /home/jimb/gdb/macros/play/sample.c:2
13944#define Q <
f7dc1244 13945(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 13946expands to: (42 + 1)
f7dc1244 13947(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 13948expands to: once (M + 1)
f7dc1244 13949(@value{GDBP})
e2e0bcd1
JB
13950@end smallexample
13951
d7d9f01e 13952In the example above, note that @code{macro expand-once} expands only
e2e0bcd1
JB
13953the macro invocation explicit in the original text --- the invocation of
13954@code{ADD} --- but does not expand the invocation of the macro @code{M},
13955which was introduced by @code{ADD}.
13956
3f94c067
BW
13957Once the program is running, @value{GDBN} uses the macro definitions in
13958force at the source line of the current stack frame:
e2e0bcd1
JB
13959
13960@smallexample
f7dc1244 13961(@value{GDBP}) break main
e2e0bcd1 13962Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 13963(@value{GDBP}) run
b383017d 13964Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
13965
13966Breakpoint 1, main () at sample.c:10
1396710 printf ("Hello, world!\n");
f7dc1244 13968(@value{GDBP})
e2e0bcd1
JB
13969@end smallexample
13970
13971At line 10, the definition of the macro @code{N} at line 9 is in force:
13972
13973@smallexample
f7dc1244 13974(@value{GDBP}) info macro N
e2e0bcd1
JB
13975Defined at /home/jimb/gdb/macros/play/sample.c:9
13976#define N 28
f7dc1244 13977(@value{GDBP}) macro expand N Q M
e2e0bcd1 13978expands to: 28 < 42
f7dc1244 13979(@value{GDBP}) print N Q M
e2e0bcd1 13980$1 = 1
f7dc1244 13981(@value{GDBP})
e2e0bcd1
JB
13982@end smallexample
13983
13984As we step over directives that remove @code{N}'s definition, and then
13985give it a new definition, @value{GDBN} finds the definition (or lack
13986thereof) in force at each point:
13987
13988@smallexample
f7dc1244 13989(@value{GDBP}) next
e2e0bcd1
JB
13990Hello, world!
1399112 printf ("We're so creative.\n");
f7dc1244 13992(@value{GDBP}) info macro N
e2e0bcd1
JB
13993The symbol `N' has no definition as a C/C++ preprocessor macro
13994at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 13995(@value{GDBP}) next
e2e0bcd1
JB
13996We're so creative.
1399714 printf ("Goodbye, world!\n");
f7dc1244 13998(@value{GDBP}) info macro N
e2e0bcd1
JB
13999Defined at /home/jimb/gdb/macros/play/sample.c:13
14000#define N 1729
f7dc1244 14001(@value{GDBP}) macro expand N Q M
e2e0bcd1 14002expands to: 1729 < 42
f7dc1244 14003(@value{GDBP}) print N Q M
e2e0bcd1 14004$2 = 0
f7dc1244 14005(@value{GDBP})
e2e0bcd1
JB
14006@end smallexample
14007
484086b7
JK
14008In addition to source files, macros can be defined on the compilation command
14009line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
14010such a way, @value{GDBN} displays the location of their definition as line zero
14011of the source file submitted to the compiler.
14012
14013@smallexample
14014(@value{GDBP}) info macro __STDC__
14015Defined at /home/jimb/gdb/macros/play/sample.c:0
14016-D__STDC__=1
14017(@value{GDBP})
14018@end smallexample
14019
e2e0bcd1 14020
b37052ae
EZ
14021@node Tracepoints
14022@chapter Tracepoints
14023@c This chapter is based on the documentation written by Michael
14024@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
14025
14026@cindex tracepoints
14027In some applications, it is not feasible for the debugger to interrupt
14028the program's execution long enough for the developer to learn
14029anything helpful about its behavior. If the program's correctness
14030depends on its real-time behavior, delays introduced by a debugger
14031might cause the program to change its behavior drastically, or perhaps
14032fail, even when the code itself is correct. It is useful to be able
14033to observe the program's behavior without interrupting it.
14034
14035Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
14036specify locations in the program, called @dfn{tracepoints}, and
14037arbitrary expressions to evaluate when those tracepoints are reached.
14038Later, using the @code{tfind} command, you can examine the values
14039those expressions had when the program hit the tracepoints. The
14040expressions may also denote objects in memory---structures or arrays,
14041for example---whose values @value{GDBN} should record; while visiting
14042a particular tracepoint, you may inspect those objects as if they were
14043in memory at that moment. However, because @value{GDBN} records these
14044values without interacting with you, it can do so quickly and
14045unobtrusively, hopefully not disturbing the program's behavior.
14046
14047The tracepoint facility is currently available only for remote
9d29849a
JB
14048targets. @xref{Targets}. In addition, your remote target must know
14049how to collect trace data. This functionality is implemented in the
14050remote stub; however, none of the stubs distributed with @value{GDBN}
14051support tracepoints as of this writing. The format of the remote
14052packets used to implement tracepoints are described in @ref{Tracepoint
14053Packets}.
b37052ae 14054
00bf0b85
SS
14055It is also possible to get trace data from a file, in a manner reminiscent
14056of corefiles; you specify the filename, and use @code{tfind} to search
14057through the file. @xref{Trace Files}, for more details.
14058
b37052ae
EZ
14059This chapter describes the tracepoint commands and features.
14060
14061@menu
b383017d
RM
14062* Set Tracepoints::
14063* Analyze Collected Data::
14064* Tracepoint Variables::
00bf0b85 14065* Trace Files::
b37052ae
EZ
14066@end menu
14067
14068@node Set Tracepoints
14069@section Commands to Set Tracepoints
14070
14071Before running such a @dfn{trace experiment}, an arbitrary number of
1042e4c0
SS
14072tracepoints can be set. A tracepoint is actually a special type of
14073breakpoint (@pxref{Set Breaks}), so you can manipulate it using
14074standard breakpoint commands. For instance, as with breakpoints,
14075tracepoint numbers are successive integers starting from one, and many
14076of the commands associated with tracepoints take the tracepoint number
14077as their argument, to identify which tracepoint to work on.
b37052ae
EZ
14078
14079For each tracepoint, you can specify, in advance, some arbitrary set
14080of data that you want the target to collect in the trace buffer when
14081it hits that tracepoint. The collected data can include registers,
14082local variables, or global data. Later, you can use @value{GDBN}
14083commands to examine the values these data had at the time the
14084tracepoint was hit.
14085
7d13fe92
SS
14086Tracepoints do not support every breakpoint feature. Ignore counts on
14087tracepoints have no effect, and tracepoints cannot run @value{GDBN}
14088commands when they are hit. Tracepoints may not be thread-specific
14089either.
1042e4c0 14090
7a697b8d
SS
14091@cindex fast tracepoints
14092Some targets may support @dfn{fast tracepoints}, which are inserted in
14093a different way (such as with a jump instead of a trap), that is
14094faster but possibly restricted in where they may be installed.
14095
0fb4aa4b
PA
14096@cindex static tracepoints
14097@cindex markers, static tracepoints
14098@cindex probing markers, static tracepoints
14099Regular and fast tracepoints are dynamic tracing facilities, meaning
14100that they can be used to insert tracepoints at (almost) any location
14101in the target. Some targets may also support controlling @dfn{static
14102tracepoints} from @value{GDBN}. With static tracing, a set of
14103instrumentation points, also known as @dfn{markers}, are embedded in
14104the target program, and can be activated or deactivated by name or
14105address. These are usually placed at locations which facilitate
14106investigating what the target is actually doing. @value{GDBN}'s
14107support for static tracing includes being able to list instrumentation
14108points, and attach them with @value{GDBN} defined high level
14109tracepoints that expose the whole range of convenience of
8786b2bd 14110@value{GDBN}'s tracepoints support. Namely, support for collecting
0fb4aa4b
PA
14111registers values and values of global or local (to the instrumentation
14112point) variables; tracepoint conditions and trace state variables.
14113The act of installing a @value{GDBN} static tracepoint on an
14114instrumentation point, or marker, is referred to as @dfn{probing} a
14115static tracepoint marker.
14116
fa593d66
PA
14117@code{gdbserver} supports tracepoints on some target systems.
14118@xref{Server,,Tracepoints support in @code{gdbserver}}.
14119
b37052ae
EZ
14120This section describes commands to set tracepoints and associated
14121conditions and actions.
14122
14123@menu
b383017d
RM
14124* Create and Delete Tracepoints::
14125* Enable and Disable Tracepoints::
14126* Tracepoint Passcounts::
782b2b07 14127* Tracepoint Conditions::
f61e138d 14128* Trace State Variables::
b383017d
RM
14129* Tracepoint Actions::
14130* Listing Tracepoints::
0fb4aa4b 14131* Listing Static Tracepoint Markers::
79a6e687 14132* Starting and Stopping Trace Experiments::
c9429232 14133* Tracepoint Restrictions::
b37052ae
EZ
14134@end menu
14135
14136@node Create and Delete Tracepoints
14137@subsection Create and Delete Tracepoints
14138
14139@table @code
14140@cindex set tracepoint
14141@kindex trace
1042e4c0 14142@item trace @var{location}
b37052ae 14143The @code{trace} command is very similar to the @code{break} command.
629500fa
KS
14144Its argument @var{location} can be any valid location.
14145@xref{Specify Location}. The @code{trace} command defines a tracepoint,
14146which is a point in the target program where the debugger will briefly stop,
14147collect some data, and then allow the program to continue. Setting a tracepoint
14148or changing its actions takes effect immediately if the remote stub
1e4d1764
YQ
14149supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
14150in tracing}).
14151If remote stub doesn't support the @samp{InstallInTrace} feature, all
14152these changes don't take effect until the next @code{tstart}
1042e4c0 14153command, and once a trace experiment is running, further changes will
bfccc43c
YQ
14154not have any effect until the next trace experiment starts. In addition,
14155@value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
14156address is not yet resolved. (This is similar to pending breakpoints.)
14157Pending tracepoints are not downloaded to the target and not installed
14158until they are resolved. The resolution of pending tracepoints requires
14159@value{GDBN} support---when debugging with the remote target, and
14160@value{GDBN} disconnects from the remote stub (@pxref{disconnected
14161tracing}), pending tracepoints can not be resolved (and downloaded to
14162the remote stub) while @value{GDBN} is disconnected.
b37052ae
EZ
14163
14164Here are some examples of using the @code{trace} command:
14165
14166@smallexample
14167(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
14168
14169(@value{GDBP}) @b{trace +2} // 2 lines forward
14170
14171(@value{GDBP}) @b{trace my_function} // first source line of function
14172
14173(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
14174
14175(@value{GDBP}) @b{trace *0x2117c4} // an address
14176@end smallexample
14177
14178@noindent
14179You can abbreviate @code{trace} as @code{tr}.
14180
782b2b07
SS
14181@item trace @var{location} if @var{cond}
14182Set a tracepoint with condition @var{cond}; evaluate the expression
14183@var{cond} each time the tracepoint is reached, and collect data only
14184if the value is nonzero---that is, if @var{cond} evaluates as true.
14185@xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
14186information on tracepoint conditions.
14187
7a697b8d
SS
14188@item ftrace @var{location} [ if @var{cond} ]
14189@cindex set fast tracepoint
74c761c1 14190@cindex fast tracepoints, setting
7a697b8d
SS
14191@kindex ftrace
14192The @code{ftrace} command sets a fast tracepoint. For targets that
14193support them, fast tracepoints will use a more efficient but possibly
14194less general technique to trigger data collection, such as a jump
14195instruction instead of a trap, or some sort of hardware support. It
14196may not be possible to create a fast tracepoint at the desired
14197location, in which case the command will exit with an explanatory
14198message.
14199
14200@value{GDBN} handles arguments to @code{ftrace} exactly as for
14201@code{trace}.
14202
405f8e94
SS
14203On 32-bit x86-architecture systems, fast tracepoints normally need to
14204be placed at an instruction that is 5 bytes or longer, but can be
14205placed at 4-byte instructions if the low 64K of memory of the target
14206program is available to install trampolines. Some Unix-type systems,
14207such as @sc{gnu}/Linux, exclude low addresses from the program's
14208address space; but for instance with the Linux kernel it is possible
14209to let @value{GDBN} use this area by doing a @command{sysctl} command
14210to set the @code{mmap_min_addr} kernel parameter, as in
14211
14212@example
14213sudo sysctl -w vm.mmap_min_addr=32768
14214@end example
14215
14216@noindent
14217which sets the low address to 32K, which leaves plenty of room for
14218trampolines. The minimum address should be set to a page boundary.
14219
0fb4aa4b 14220@item strace @var{location} [ if @var{cond} ]
74c761c1
PA
14221@cindex set static tracepoint
14222@cindex static tracepoints, setting
14223@cindex probe static tracepoint marker
0fb4aa4b
PA
14224@kindex strace
14225The @code{strace} command sets a static tracepoint. For targets that
14226support it, setting a static tracepoint probes a static
14227instrumentation point, or marker, found at @var{location}. It may not
14228be possible to set a static tracepoint at the desired location, in
14229which case the command will exit with an explanatory message.
14230
14231@value{GDBN} handles arguments to @code{strace} exactly as for
14232@code{trace}, with the addition that the user can also specify
14233@code{-m @var{marker}} as @var{location}. This probes the marker
14234identified by the @var{marker} string identifier. This identifier
14235depends on the static tracepoint backend library your program is
14236using. You can find all the marker identifiers in the @samp{ID} field
14237of the @code{info static-tracepoint-markers} command output.
14238@xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
14239Markers}. For example, in the following small program using the UST
14240tracing engine:
14241
14242@smallexample
14243main ()
14244@{
14245 trace_mark(ust, bar33, "str %s", "FOOBAZ");
14246@}
14247@end smallexample
14248
14249@noindent
14250the marker id is composed of joining the first two arguments to the
14251@code{trace_mark} call with a slash, which translates to:
14252
14253@smallexample
14254(@value{GDBP}) info static-tracepoint-markers
14255Cnt Enb ID Address What
142561 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
14257 Data: "str %s"
14258[etc...]
14259@end smallexample
14260
14261@noindent
14262so you may probe the marker above with:
14263
14264@smallexample
14265(@value{GDBP}) strace -m ust/bar33
14266@end smallexample
14267
14268Static tracepoints accept an extra collect action --- @code{collect
14269$_sdata}. This collects arbitrary user data passed in the probe point
14270call to the tracing library. In the UST example above, you'll see
14271that the third argument to @code{trace_mark} is a printf-like format
6b92c0d3 14272string. The user data is then the result of running that formatting
0fb4aa4b
PA
14273string against the following arguments. Note that @code{info
14274static-tracepoint-markers} command output lists that format string in
14275the @samp{Data:} field.
14276
14277You can inspect this data when analyzing the trace buffer, by printing
14278the $_sdata variable like any other variable available to
14279@value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
14280
b37052ae
EZ
14281@vindex $tpnum
14282@cindex last tracepoint number
14283@cindex recent tracepoint number
14284@cindex tracepoint number
14285The convenience variable @code{$tpnum} records the tracepoint number
14286of the most recently set tracepoint.
14287
14288@kindex delete tracepoint
14289@cindex tracepoint deletion
14290@item delete tracepoint @r{[}@var{num}@r{]}
14291Permanently delete one or more tracepoints. With no argument, the
1042e4c0
SS
14292default is to delete all tracepoints. Note that the regular
14293@code{delete} command can remove tracepoints also.
b37052ae
EZ
14294
14295Examples:
14296
14297@smallexample
14298(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
14299
14300(@value{GDBP}) @b{delete trace} // remove all tracepoints
14301@end smallexample
14302
14303@noindent
14304You can abbreviate this command as @code{del tr}.
14305@end table
14306
14307@node Enable and Disable Tracepoints
14308@subsection Enable and Disable Tracepoints
14309
1042e4c0
SS
14310These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
14311
b37052ae
EZ
14312@table @code
14313@kindex disable tracepoint
14314@item disable tracepoint @r{[}@var{num}@r{]}
14315Disable tracepoint @var{num}, or all tracepoints if no argument
14316@var{num} is given. A disabled tracepoint will have no effect during
d248b706 14317a trace experiment, but it is not forgotten. You can re-enable
b37052ae 14318a disabled tracepoint using the @code{enable tracepoint} command.
d248b706
KY
14319If the command is issued during a trace experiment and the debug target
14320has support for disabling tracepoints during a trace experiment, then the
14321change will be effective immediately. Otherwise, it will be applied to the
14322next trace experiment.
b37052ae
EZ
14323
14324@kindex enable tracepoint
14325@item enable tracepoint @r{[}@var{num}@r{]}
d248b706
KY
14326Enable tracepoint @var{num}, or all tracepoints. If this command is
14327issued during a trace experiment and the debug target supports enabling
14328tracepoints during a trace experiment, then the enabled tracepoints will
14329become effective immediately. Otherwise, they will become effective the
14330next time a trace experiment is run.
b37052ae
EZ
14331@end table
14332
14333@node Tracepoint Passcounts
14334@subsection Tracepoint Passcounts
14335
14336@table @code
14337@kindex passcount
14338@cindex tracepoint pass count
14339@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
14340Set the @dfn{passcount} of a tracepoint. The passcount is a way to
14341automatically stop a trace experiment. If a tracepoint's passcount is
14342@var{n}, then the trace experiment will be automatically stopped on
14343the @var{n}'th time that tracepoint is hit. If the tracepoint number
14344@var{num} is not specified, the @code{passcount} command sets the
14345passcount of the most recently defined tracepoint. If no passcount is
14346given, the trace experiment will run until stopped explicitly by the
14347user.
14348
14349Examples:
14350
14351@smallexample
b383017d 14352(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 14353@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
14354
14355(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 14356@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
14357(@value{GDBP}) @b{trace foo}
14358(@value{GDBP}) @b{pass 3}
14359(@value{GDBP}) @b{trace bar}
14360(@value{GDBP}) @b{pass 2}
14361(@value{GDBP}) @b{trace baz}
14362(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
14363@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
14364@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
14365@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
14366@end smallexample
14367@end table
14368
782b2b07
SS
14369@node Tracepoint Conditions
14370@subsection Tracepoint Conditions
14371@cindex conditional tracepoints
14372@cindex tracepoint conditions
14373
14374The simplest sort of tracepoint collects data every time your program
14375reaches a specified place. You can also specify a @dfn{condition} for
14376a tracepoint. A condition is just a Boolean expression in your
14377programming language (@pxref{Expressions, ,Expressions}). A
14378tracepoint with a condition evaluates the expression each time your
14379program reaches it, and data collection happens only if the condition
14380is true.
14381
14382Tracepoint conditions can be specified when a tracepoint is set, by
14383using @samp{if} in the arguments to the @code{trace} command.
14384@xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
14385also be set or changed at any time with the @code{condition} command,
14386just as with breakpoints.
14387
14388Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
14389the conditional expression itself. Instead, @value{GDBN} encodes the
6dcd5565 14390expression into an agent expression (@pxref{Agent Expressions})
782b2b07
SS
14391suitable for execution on the target, independently of @value{GDBN}.
14392Global variables become raw memory locations, locals become stack
14393accesses, and so forth.
14394
14395For instance, suppose you have a function that is usually called
14396frequently, but should not be called after an error has occurred. You
14397could use the following tracepoint command to collect data about calls
14398of that function that happen while the error code is propagating
14399through the program; an unconditional tracepoint could end up
14400collecting thousands of useless trace frames that you would have to
14401search through.
14402
14403@smallexample
14404(@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
14405@end smallexample
14406
f61e138d
SS
14407@node Trace State Variables
14408@subsection Trace State Variables
14409@cindex trace state variables
14410
14411A @dfn{trace state variable} is a special type of variable that is
14412created and managed by target-side code. The syntax is the same as
14413that for GDB's convenience variables (a string prefixed with ``$''),
14414but they are stored on the target. They must be created explicitly,
14415using a @code{tvariable} command. They are always 64-bit signed
14416integers.
14417
14418Trace state variables are remembered by @value{GDBN}, and downloaded
14419to the target along with tracepoint information when the trace
14420experiment starts. There are no intrinsic limits on the number of
14421trace state variables, beyond memory limitations of the target.
14422
14423@cindex convenience variables, and trace state variables
14424Although trace state variables are managed by the target, you can use
14425them in print commands and expressions as if they were convenience
14426variables; @value{GDBN} will get the current value from the target
14427while the trace experiment is running. Trace state variables share
14428the same namespace as other ``$'' variables, which means that you
14429cannot have trace state variables with names like @code{$23} or
14430@code{$pc}, nor can you have a trace state variable and a convenience
14431variable with the same name.
14432
14433@table @code
14434
14435@item tvariable $@var{name} [ = @var{expression} ]
14436@kindex tvariable
14437The @code{tvariable} command creates a new trace state variable named
14438@code{$@var{name}}, and optionally gives it an initial value of
697aa1b7 14439@var{expression}. The @var{expression} is evaluated when this command is
f61e138d
SS
14440entered; the result will be converted to an integer if possible,
14441otherwise @value{GDBN} will report an error. A subsequent
14442@code{tvariable} command specifying the same name does not create a
14443variable, but instead assigns the supplied initial value to the
14444existing variable of that name, overwriting any previous initial
14445value. The default initial value is 0.
14446
14447@item info tvariables
14448@kindex info tvariables
14449List all the trace state variables along with their initial values.
14450Their current values may also be displayed, if the trace experiment is
14451currently running.
14452
14453@item delete tvariable @r{[} $@var{name} @dots{} @r{]}
14454@kindex delete tvariable
14455Delete the given trace state variables, or all of them if no arguments
14456are specified.
14457
14458@end table
14459
b37052ae
EZ
14460@node Tracepoint Actions
14461@subsection Tracepoint Action Lists
14462
14463@table @code
14464@kindex actions
14465@cindex tracepoint actions
14466@item actions @r{[}@var{num}@r{]}
14467This command will prompt for a list of actions to be taken when the
14468tracepoint is hit. If the tracepoint number @var{num} is not
14469specified, this command sets the actions for the one that was most
14470recently defined (so that you can define a tracepoint and then say
14471@code{actions} without bothering about its number). You specify the
14472actions themselves on the following lines, one action at a time, and
14473terminate the actions list with a line containing just @code{end}. So
7d13fe92 14474far, the only defined actions are @code{collect}, @code{teval}, and
b37052ae
EZ
14475@code{while-stepping}.
14476
5a9351ae
SS
14477@code{actions} is actually equivalent to @code{commands} (@pxref{Break
14478Commands, ,Breakpoint Command Lists}), except that only the defined
14479actions are allowed; any other @value{GDBN} command is rejected.
14480
b37052ae
EZ
14481@cindex remove actions from a tracepoint
14482To remove all actions from a tracepoint, type @samp{actions @var{num}}
14483and follow it immediately with @samp{end}.
14484
14485@smallexample
14486(@value{GDBP}) @b{collect @var{data}} // collect some data
14487
6826cf00 14488(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 14489
6826cf00 14490(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
14491@end smallexample
14492
14493In the following example, the action list begins with @code{collect}
14494commands indicating the things to be collected when the tracepoint is
14495hit. Then, in order to single-step and collect additional data
14496following the tracepoint, a @code{while-stepping} command is used,
7d13fe92
SS
14497followed by the list of things to be collected after each step in a
14498sequence of single steps. The @code{while-stepping} command is
14499terminated by its own separate @code{end} command. Lastly, the action
14500list is terminated by an @code{end} command.
b37052ae
EZ
14501
14502@smallexample
14503(@value{GDBP}) @b{trace foo}
14504(@value{GDBP}) @b{actions}
14505Enter actions for tracepoint 1, one per line:
14506> collect bar,baz
14507> collect $regs
14508> while-stepping 12
5a9351ae 14509 > collect $pc, arr[i]
b37052ae
EZ
14510 > end
14511end
14512@end smallexample
14513
14514@kindex collect @r{(tracepoints)}
3065dfb6 14515@item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
b37052ae
EZ
14516Collect values of the given expressions when the tracepoint is hit.
14517This command accepts a comma-separated list of any valid expressions.
14518In addition to global, static, or local variables, the following
14519special arguments are supported:
14520
14521@table @code
14522@item $regs
0fb4aa4b 14523Collect all registers.
b37052ae
EZ
14524
14525@item $args
0fb4aa4b 14526Collect all function arguments.
b37052ae
EZ
14527
14528@item $locals
0fb4aa4b
PA
14529Collect all local variables.
14530
6710bf39
SS
14531@item $_ret
14532Collect the return address. This is helpful if you want to see more
14533of a backtrace.
14534
2a60e18f 14535@emph{Note:} The return address location can not always be reliably
45fa2529
PA
14536determined up front, and the wrong address / registers may end up
14537collected instead. On some architectures the reliability is higher
14538for tracepoints at function entry, while on others it's the opposite.
14539When this happens, backtracing will stop because the return address is
14540found unavailable (unless another collect rule happened to match it).
14541
62e5f89c
SDJ
14542@item $_probe_argc
14543Collects the number of arguments from the static probe at which the
14544tracepoint is located.
14545@xref{Static Probe Points}.
14546
14547@item $_probe_arg@var{n}
14548@var{n} is an integer between 0 and 11. Collects the @var{n}th argument
14549from the static probe at which the tracepoint is located.
14550@xref{Static Probe Points}.
14551
0fb4aa4b
PA
14552@item $_sdata
14553@vindex $_sdata@r{, collect}
14554Collect static tracepoint marker specific data. Only available for
14555static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
14556Lists}. On the UST static tracepoints library backend, an
14557instrumentation point resembles a @code{printf} function call. The
14558tracing library is able to collect user specified data formatted to a
14559character string using the format provided by the programmer that
14560instrumented the program. Other backends have similar mechanisms.
14561Here's an example of a UST marker call:
14562
14563@smallexample
14564 const char master_name[] = "$your_name";
14565 trace_mark(channel1, marker1, "hello %s", master_name)
14566@end smallexample
14567
14568In this case, collecting @code{$_sdata} collects the string
14569@samp{hello $yourname}. When analyzing the trace buffer, you can
14570inspect @samp{$_sdata} like any other variable available to
14571@value{GDBN}.
b37052ae
EZ
14572@end table
14573
14574You can give several consecutive @code{collect} commands, each one
14575with a single argument, or one @code{collect} command with several
5a9351ae 14576arguments separated by commas; the effect is the same.
b37052ae 14577
3065dfb6
SS
14578The optional @var{mods} changes the usual handling of the arguments.
14579@code{s} requests that pointers to chars be handled as strings, in
14580particular collecting the contents of the memory being pointed at, up
14581to the first zero. The upper bound is by default the value of the
14582@code{print elements} variable; if @code{s} is followed by a decimal
14583number, that is the upper bound instead. So for instance
14584@samp{collect/s25 mystr} collects as many as 25 characters at
14585@samp{mystr}.
14586
f5c37c66
EZ
14587The command @code{info scope} (@pxref{Symbols, info scope}) is
14588particularly useful for figuring out what data to collect.
14589
6da95a67
SS
14590@kindex teval @r{(tracepoints)}
14591@item teval @var{expr1}, @var{expr2}, @dots{}
14592Evaluate the given expressions when the tracepoint is hit. This
14593command accepts a comma-separated list of expressions. The results
14594are discarded, so this is mainly useful for assigning values to trace
14595state variables (@pxref{Trace State Variables}) without adding those
14596values to the trace buffer, as would be the case if the @code{collect}
14597action were used.
14598
b37052ae
EZ
14599@kindex while-stepping @r{(tracepoints)}
14600@item while-stepping @var{n}
c9429232 14601Perform @var{n} single-step instruction traces after the tracepoint,
7d13fe92 14602collecting new data after each step. The @code{while-stepping}
c9429232
SS
14603command is followed by the list of what to collect while stepping
14604(followed by its own @code{end} command):
b37052ae
EZ
14605
14606@smallexample
14607> while-stepping 12
14608 > collect $regs, myglobal
14609 > end
14610>
14611@end smallexample
14612
14613@noindent
7d13fe92
SS
14614Note that @code{$pc} is not automatically collected by
14615@code{while-stepping}; you need to explicitly collect that register if
14616you need it. You may abbreviate @code{while-stepping} as @code{ws} or
b37052ae 14617@code{stepping}.
236f1d4d
SS
14618
14619@item set default-collect @var{expr1}, @var{expr2}, @dots{}
14620@kindex set default-collect
14621@cindex default collection action
14622This variable is a list of expressions to collect at each tracepoint
14623hit. It is effectively an additional @code{collect} action prepended
14624to every tracepoint action list. The expressions are parsed
14625individually for each tracepoint, so for instance a variable named
14626@code{xyz} may be interpreted as a global for one tracepoint, and a
14627local for another, as appropriate to the tracepoint's location.
14628
14629@item show default-collect
14630@kindex show default-collect
14631Show the list of expressions that are collected by default at each
14632tracepoint hit.
14633
b37052ae
EZ
14634@end table
14635
14636@node Listing Tracepoints
14637@subsection Listing Tracepoints
14638
14639@table @code
e5a67952
MS
14640@kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
14641@kindex info tp @r{[}@var{n}@dots{}@r{]}
b37052ae 14642@cindex information about tracepoints
e5a67952 14643@item info tracepoints @r{[}@var{num}@dots{}@r{]}
1042e4c0
SS
14644Display information about the tracepoint @var{num}. If you don't
14645specify a tracepoint number, displays information about all the
14646tracepoints defined so far. The format is similar to that used for
14647@code{info breakpoints}; in fact, @code{info tracepoints} is the same
14648command, simply restricting itself to tracepoints.
14649
14650A tracepoint's listing may include additional information specific to
14651tracing:
b37052ae
EZ
14652
14653@itemize @bullet
14654@item
b37052ae 14655its passcount as given by the @code{passcount @var{n}} command
f2a8bc8a
YQ
14656
14657@item
14658the state about installed on target of each location
b37052ae
EZ
14659@end itemize
14660
14661@smallexample
14662(@value{GDBP}) @b{info trace}
1042e4c0
SS
14663Num Type Disp Enb Address What
146641 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
5a9351ae
SS
14665 while-stepping 20
14666 collect globfoo, $regs
14667 end
14668 collect globfoo2
14669 end
1042e4c0 14670 pass count 1200
f2a8bc8a
YQ
146712 tracepoint keep y <MULTIPLE>
14672 collect $eip
146732.1 y 0x0804859c in func4 at change-loc.h:35
14674 installed on target
146752.2 y 0xb7ffc480 in func4 at change-loc.h:35
14676 installed on target
146772.3 y <PENDING> set_tracepoint
146783 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
14679 not installed on target
b37052ae
EZ
14680(@value{GDBP})
14681@end smallexample
14682
14683@noindent
14684This command can be abbreviated @code{info tp}.
14685@end table
14686
0fb4aa4b
PA
14687@node Listing Static Tracepoint Markers
14688@subsection Listing Static Tracepoint Markers
14689
14690@table @code
14691@kindex info static-tracepoint-markers
14692@cindex information about static tracepoint markers
14693@item info static-tracepoint-markers
14694Display information about all static tracepoint markers defined in the
14695program.
14696
14697For each marker, the following columns are printed:
14698
14699@table @emph
14700@item Count
14701An incrementing counter, output to help readability. This is not a
14702stable identifier.
14703@item ID
14704The marker ID, as reported by the target.
14705@item Enabled or Disabled
14706Probed markers are tagged with @samp{y}. @samp{n} identifies marks
14707that are not enabled.
14708@item Address
14709Where the marker is in your program, as a memory address.
14710@item What
14711Where the marker is in the source for your program, as a file and line
14712number. If the debug information included in the program does not
14713allow @value{GDBN} to locate the source of the marker, this column
14714will be left blank.
14715@end table
14716
14717@noindent
14718In addition, the following information may be printed for each marker:
14719
14720@table @emph
14721@item Data
14722User data passed to the tracing library by the marker call. In the
14723UST backend, this is the format string passed as argument to the
14724marker call.
14725@item Static tracepoints probing the marker
14726The list of static tracepoints attached to the marker.
14727@end table
14728
14729@smallexample
14730(@value{GDBP}) info static-tracepoint-markers
14731Cnt ID Enb Address What
147321 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
14733 Data: number1 %d number2 %d
14734 Probed by static tracepoints: #2
147352 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
14736 Data: str %s
14737(@value{GDBP})
14738@end smallexample
14739@end table
14740
79a6e687
BW
14741@node Starting and Stopping Trace Experiments
14742@subsection Starting and Stopping Trace Experiments
b37052ae
EZ
14743
14744@table @code
f196051f 14745@kindex tstart [ @var{notes} ]
b37052ae
EZ
14746@cindex start a new trace experiment
14747@cindex collected data discarded
14748@item tstart
f196051f
SS
14749This command starts the trace experiment, and begins collecting data.
14750It has the side effect of discarding all the data collected in the
14751trace buffer during the previous trace experiment. If any arguments
14752are supplied, they are taken as a note and stored with the trace
14753experiment's state. The notes may be arbitrary text, and are
14754especially useful with disconnected tracing in a multi-user context;
14755the notes can explain what the trace is doing, supply user contact
14756information, and so forth.
14757
14758@kindex tstop [ @var{notes} ]
b37052ae
EZ
14759@cindex stop a running trace experiment
14760@item tstop
f196051f
SS
14761This command stops the trace experiment. If any arguments are
14762supplied, they are recorded with the experiment as a note. This is
14763useful if you are stopping a trace started by someone else, for
14764instance if the trace is interfering with the system's behavior and
14765needs to be stopped quickly.
b37052ae 14766
68c71a2e 14767@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
14768automatically if any tracepoint's passcount is reached
14769(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
14770
14771@kindex tstatus
14772@cindex status of trace data collection
14773@cindex trace experiment, status of
14774@item tstatus
14775This command displays the status of the current trace data
14776collection.
14777@end table
14778
14779Here is an example of the commands we described so far:
14780
14781@smallexample
14782(@value{GDBP}) @b{trace gdb_c_test}
14783(@value{GDBP}) @b{actions}
14784Enter actions for tracepoint #1, one per line.
14785> collect $regs,$locals,$args
14786> while-stepping 11
14787 > collect $regs
14788 > end
14789> end
14790(@value{GDBP}) @b{tstart}
14791 [time passes @dots{}]
14792(@value{GDBP}) @b{tstop}
14793@end smallexample
14794
03f2bd59 14795@anchor{disconnected tracing}
d5551862
SS
14796@cindex disconnected tracing
14797You can choose to continue running the trace experiment even if
14798@value{GDBN} disconnects from the target, voluntarily or
14799involuntarily. For commands such as @code{detach}, the debugger will
14800ask what you want to do with the trace. But for unexpected
14801terminations (@value{GDBN} crash, network outage), it would be
14802unfortunate to lose hard-won trace data, so the variable
14803@code{disconnected-tracing} lets you decide whether the trace should
14804continue running without @value{GDBN}.
14805
14806@table @code
14807@item set disconnected-tracing on
14808@itemx set disconnected-tracing off
14809@kindex set disconnected-tracing
14810Choose whether a tracing run should continue to run if @value{GDBN}
14811has disconnected from the target. Note that @code{detach} or
14812@code{quit} will ask you directly what to do about a running trace no
14813matter what this variable's setting, so the variable is mainly useful
14814for handling unexpected situations, such as loss of the network.
14815
14816@item show disconnected-tracing
14817@kindex show disconnected-tracing
14818Show the current choice for disconnected tracing.
14819
14820@end table
14821
14822When you reconnect to the target, the trace experiment may or may not
14823still be running; it might have filled the trace buffer in the
14824meantime, or stopped for one of the other reasons. If it is running,
14825it will continue after reconnection.
14826
14827Upon reconnection, the target will upload information about the
14828tracepoints in effect. @value{GDBN} will then compare that
14829information to the set of tracepoints currently defined, and attempt
14830to match them up, allowing for the possibility that the numbers may
14831have changed due to creation and deletion in the meantime. If one of
14832the target's tracepoints does not match any in @value{GDBN}, the
14833debugger will create a new tracepoint, so that you have a number with
14834which to specify that tracepoint. This matching-up process is
14835necessarily heuristic, and it may result in useless tracepoints being
14836created; you may simply delete them if they are of no use.
b37052ae 14837
4daf5ac0
SS
14838@cindex circular trace buffer
14839If your target agent supports a @dfn{circular trace buffer}, then you
14840can run a trace experiment indefinitely without filling the trace
14841buffer; when space runs out, the agent deletes already-collected trace
14842frames, oldest first, until there is enough room to continue
14843collecting. This is especially useful if your tracepoints are being
14844hit too often, and your trace gets terminated prematurely because the
14845buffer is full. To ask for a circular trace buffer, simply set
81896e36 14846@samp{circular-trace-buffer} to on. You can set this at any time,
4daf5ac0
SS
14847including during tracing; if the agent can do it, it will change
14848buffer handling on the fly, otherwise it will not take effect until
14849the next run.
14850
14851@table @code
14852@item set circular-trace-buffer on
14853@itemx set circular-trace-buffer off
14854@kindex set circular-trace-buffer
14855Choose whether a tracing run should use a linear or circular buffer
14856for trace data. A linear buffer will not lose any trace data, but may
14857fill up prematurely, while a circular buffer will discard old trace
14858data, but it will have always room for the latest tracepoint hits.
14859
14860@item show circular-trace-buffer
14861@kindex show circular-trace-buffer
14862Show the current choice for the trace buffer. Note that this may not
14863match the agent's current buffer handling, nor is it guaranteed to
14864match the setting that might have been in effect during a past run,
14865for instance if you are looking at frames from a trace file.
14866
14867@end table
14868
f6f899bf
HAQ
14869@table @code
14870@item set trace-buffer-size @var{n}
f81d1120 14871@itemx set trace-buffer-size unlimited
f6f899bf
HAQ
14872@kindex set trace-buffer-size
14873Request that the target use a trace buffer of @var{n} bytes. Not all
14874targets will honor the request; they may have a compiled-in size for
14875the trace buffer, or some other limitation. Set to a value of
f81d1120
PA
14876@code{unlimited} or @code{-1} to let the target use whatever size it
14877likes. This is also the default.
f6f899bf
HAQ
14878
14879@item show trace-buffer-size
14880@kindex show trace-buffer-size
14881Show the current requested size for the trace buffer. Note that this
14882will only match the actual size if the target supports size-setting,
14883and was able to handle the requested size. For instance, if the
14884target can only change buffer size between runs, this variable will
14885not reflect the change until the next run starts. Use @code{tstatus}
14886to get a report of the actual buffer size.
14887@end table
14888
f196051f
SS
14889@table @code
14890@item set trace-user @var{text}
14891@kindex set trace-user
14892
14893@item show trace-user
14894@kindex show trace-user
14895
14896@item set trace-notes @var{text}
14897@kindex set trace-notes
14898Set the trace run's notes.
14899
14900@item show trace-notes
14901@kindex show trace-notes
14902Show the trace run's notes.
14903
14904@item set trace-stop-notes @var{text}
14905@kindex set trace-stop-notes
14906Set the trace run's stop notes. The handling of the note is as for
14907@code{tstop} arguments; the set command is convenient way to fix a
14908stop note that is mistaken or incomplete.
14909
14910@item show trace-stop-notes
14911@kindex show trace-stop-notes
14912Show the trace run's stop notes.
14913
14914@end table
14915
c9429232
SS
14916@node Tracepoint Restrictions
14917@subsection Tracepoint Restrictions
14918
14919@cindex tracepoint restrictions
14920There are a number of restrictions on the use of tracepoints. As
14921described above, tracepoint data gathering occurs on the target
14922without interaction from @value{GDBN}. Thus the full capabilities of
14923the debugger are not available during data gathering, and then at data
14924examination time, you will be limited by only having what was
14925collected. The following items describe some common problems, but it
14926is not exhaustive, and you may run into additional difficulties not
14927mentioned here.
14928
14929@itemize @bullet
14930
14931@item
14932Tracepoint expressions are intended to gather objects (lvalues). Thus
14933the full flexibility of GDB's expression evaluator is not available.
14934You cannot call functions, cast objects to aggregate types, access
14935convenience variables or modify values (except by assignment to trace
14936state variables). Some language features may implicitly call
14937functions (for instance Objective-C fields with accessors), and therefore
14938cannot be collected either.
14939
14940@item
14941Collection of local variables, either individually or in bulk with
14942@code{$locals} or @code{$args}, during @code{while-stepping} may
14943behave erratically. The stepping action may enter a new scope (for
14944instance by stepping into a function), or the location of the variable
14945may change (for instance it is loaded into a register). The
14946tracepoint data recorded uses the location information for the
14947variables that is correct for the tracepoint location. When the
14948tracepoint is created, it is not possible, in general, to determine
14949where the steps of a @code{while-stepping} sequence will advance the
14950program---particularly if a conditional branch is stepped.
14951
14952@item
14953Collection of an incompletely-initialized or partially-destroyed object
14954may result in something that @value{GDBN} cannot display, or displays
14955in a misleading way.
14956
14957@item
14958When @value{GDBN} displays a pointer to character it automatically
14959dereferences the pointer to also display characters of the string
14960being pointed to. However, collecting the pointer during tracing does
14961not automatically collect the string. You need to explicitly
14962dereference the pointer and provide size information if you want to
14963collect not only the pointer, but the memory pointed to. For example,
14964@code{*ptr@@50} can be used to collect the 50 element array pointed to
14965by @code{ptr}.
14966
14967@item
14968It is not possible to collect a complete stack backtrace at a
14969tracepoint. Instead, you may collect the registers and a few hundred
d99f7e48 14970bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
c9429232
SS
14971(adjust to use the name of the actual stack pointer register on your
14972target architecture, and the amount of stack you wish to capture).
14973Then the @code{backtrace} command will show a partial backtrace when
14974using a trace frame. The number of stack frames that can be examined
14975depends on the sizes of the frames in the collected stack. Note that
14976if you ask for a block so large that it goes past the bottom of the
14977stack, the target agent may report an error trying to read from an
14978invalid address.
14979
af54718e
SS
14980@item
14981If you do not collect registers at a tracepoint, @value{GDBN} can
14982infer that the value of @code{$pc} must be the same as the address of
14983the tracepoint and use that when you are looking at a trace frame
14984for that tracepoint. However, this cannot work if the tracepoint has
14985multiple locations (for instance if it was set in a function that was
14986inlined), or if it has a @code{while-stepping} loop. In those cases
14987@value{GDBN} will warn you that it can't infer @code{$pc}, and default
14988it to zero.
14989
c9429232
SS
14990@end itemize
14991
b37052ae 14992@node Analyze Collected Data
79a6e687 14993@section Using the Collected Data
b37052ae
EZ
14994
14995After the tracepoint experiment ends, you use @value{GDBN} commands
14996for examining the trace data. The basic idea is that each tracepoint
14997collects a trace @dfn{snapshot} every time it is hit and another
14998snapshot every time it single-steps. All these snapshots are
14999consecutively numbered from zero and go into a buffer, and you can
15000examine them later. The way you examine them is to @dfn{focus} on a
15001specific trace snapshot. When the remote stub is focused on a trace
15002snapshot, it will respond to all @value{GDBN} requests for memory and
15003registers by reading from the buffer which belongs to that snapshot,
15004rather than from @emph{real} memory or registers of the program being
15005debugged. This means that @strong{all} @value{GDBN} commands
15006(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
15007behave as if we were currently debugging the program state as it was
15008when the tracepoint occurred. Any requests for data that are not in
15009the buffer will fail.
15010
15011@menu
15012* tfind:: How to select a trace snapshot
15013* tdump:: How to display all data for a snapshot
6149aea9 15014* save tracepoints:: How to save tracepoints for a future run
b37052ae
EZ
15015@end menu
15016
15017@node tfind
15018@subsection @code{tfind @var{n}}
15019
15020@kindex tfind
15021@cindex select trace snapshot
15022@cindex find trace snapshot
15023The basic command for selecting a trace snapshot from the buffer is
15024@code{tfind @var{n}}, which finds trace snapshot number @var{n},
15025counting from zero. If no argument @var{n} is given, the next
15026snapshot is selected.
15027
15028Here are the various forms of using the @code{tfind} command.
15029
15030@table @code
15031@item tfind start
15032Find the first snapshot in the buffer. This is a synonym for
15033@code{tfind 0} (since 0 is the number of the first snapshot).
15034
15035@item tfind none
15036Stop debugging trace snapshots, resume @emph{live} debugging.
15037
15038@item tfind end
15039Same as @samp{tfind none}.
15040
15041@item tfind
310cdbb6
YQ
15042No argument means find the next trace snapshot or find the first
15043one if no trace snapshot is selected.
b37052ae
EZ
15044
15045@item tfind -
15046Find the previous trace snapshot before the current one. This permits
15047retracing earlier steps.
15048
15049@item tfind tracepoint @var{num}
15050Find the next snapshot associated with tracepoint @var{num}. Search
15051proceeds forward from the last examined trace snapshot. If no
15052argument @var{num} is given, it means find the next snapshot collected
15053for the same tracepoint as the current snapshot.
15054
15055@item tfind pc @var{addr}
15056Find the next snapshot associated with the value @var{addr} of the
15057program counter. Search proceeds forward from the last examined trace
15058snapshot. If no argument @var{addr} is given, it means find the next
15059snapshot with the same value of PC as the current snapshot.
15060
15061@item tfind outside @var{addr1}, @var{addr2}
15062Find the next snapshot whose PC is outside the given range of
081dfbf7 15063addresses (exclusive).
b37052ae
EZ
15064
15065@item tfind range @var{addr1}, @var{addr2}
15066Find the next snapshot whose PC is between @var{addr1} and
081dfbf7 15067@var{addr2} (inclusive).
b37052ae
EZ
15068
15069@item tfind line @r{[}@var{file}:@r{]}@var{n}
15070Find the next snapshot associated with the source line @var{n}. If
15071the optional argument @var{file} is given, refer to line @var{n} in
15072that source file. Search proceeds forward from the last examined
15073trace snapshot. If no argument @var{n} is given, it means find the
15074next line other than the one currently being examined; thus saying
15075@code{tfind line} repeatedly can appear to have the same effect as
15076stepping from line to line in a @emph{live} debugging session.
15077@end table
15078
15079The default arguments for the @code{tfind} commands are specifically
15080designed to make it easy to scan through the trace buffer. For
15081instance, @code{tfind} with no argument selects the next trace
15082snapshot, and @code{tfind -} with no argument selects the previous
15083trace snapshot. So, by giving one @code{tfind} command, and then
15084simply hitting @key{RET} repeatedly you can examine all the trace
15085snapshots in order. Or, by saying @code{tfind -} and then hitting
15086@key{RET} repeatedly you can examine the snapshots in reverse order.
15087The @code{tfind line} command with no argument selects the snapshot
15088for the next source line executed. The @code{tfind pc} command with
15089no argument selects the next snapshot with the same program counter
15090(PC) as the current frame. The @code{tfind tracepoint} command with
15091no argument selects the next trace snapshot collected by the same
15092tracepoint as the current one.
15093
15094In addition to letting you scan through the trace buffer manually,
15095these commands make it easy to construct @value{GDBN} scripts that
15096scan through the trace buffer and print out whatever collected data
15097you are interested in. Thus, if we want to examine the PC, FP, and SP
15098registers from each trace frame in the buffer, we can say this:
15099
15100@smallexample
15101(@value{GDBP}) @b{tfind start}
15102(@value{GDBP}) @b{while ($trace_frame != -1)}
15103> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
15104 $trace_frame, $pc, $sp, $fp
15105> tfind
15106> end
15107
15108Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
15109Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
15110Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
15111Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
15112Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
15113Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
15114Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
15115Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
15116Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
15117Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
15118Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
15119@end smallexample
15120
15121Or, if we want to examine the variable @code{X} at each source line in
15122the buffer:
15123
15124@smallexample
15125(@value{GDBP}) @b{tfind start}
15126(@value{GDBP}) @b{while ($trace_frame != -1)}
15127> printf "Frame %d, X == %d\n", $trace_frame, X
15128> tfind line
15129> end
15130
15131Frame 0, X = 1
15132Frame 7, X = 2
15133Frame 13, X = 255
15134@end smallexample
15135
15136@node tdump
15137@subsection @code{tdump}
15138@kindex tdump
15139@cindex dump all data collected at tracepoint
15140@cindex tracepoint data, display
15141
15142This command takes no arguments. It prints all the data collected at
15143the current trace snapshot.
15144
15145@smallexample
15146(@value{GDBP}) @b{trace 444}
15147(@value{GDBP}) @b{actions}
15148Enter actions for tracepoint #2, one per line:
15149> collect $regs, $locals, $args, gdb_long_test
15150> end
15151
15152(@value{GDBP}) @b{tstart}
15153
15154(@value{GDBP}) @b{tfind line 444}
15155#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
15156at gdb_test.c:444
15157444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
15158
15159(@value{GDBP}) @b{tdump}
15160Data collected at tracepoint 2, trace frame 1:
15161d0 0xc4aa0085 -995491707
15162d1 0x18 24
15163d2 0x80 128
15164d3 0x33 51
15165d4 0x71aea3d 119204413
15166d5 0x22 34
15167d6 0xe0 224
15168d7 0x380035 3670069
15169a0 0x19e24a 1696330
15170a1 0x3000668 50333288
15171a2 0x100 256
15172a3 0x322000 3284992
15173a4 0x3000698 50333336
15174a5 0x1ad3cc 1758156
15175fp 0x30bf3c 0x30bf3c
15176sp 0x30bf34 0x30bf34
15177ps 0x0 0
15178pc 0x20b2c8 0x20b2c8
15179fpcontrol 0x0 0
15180fpstatus 0x0 0
15181fpiaddr 0x0 0
15182p = 0x20e5b4 "gdb-test"
15183p1 = (void *) 0x11
15184p2 = (void *) 0x22
15185p3 = (void *) 0x33
15186p4 = (void *) 0x44
15187p5 = (void *) 0x55
15188p6 = (void *) 0x66
15189gdb_long_test = 17 '\021'
15190
15191(@value{GDBP})
15192@end smallexample
15193
af54718e
SS
15194@code{tdump} works by scanning the tracepoint's current collection
15195actions and printing the value of each expression listed. So
15196@code{tdump} can fail, if after a run, you change the tracepoint's
15197actions to mention variables that were not collected during the run.
15198
15199Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
15200uses the collected value of @code{$pc} to distinguish between trace
15201frames that were collected at the tracepoint hit, and frames that were
15202collected while stepping. This allows it to correctly choose whether
15203to display the basic list of collections, or the collections from the
15204body of the while-stepping loop. However, if @code{$pc} was not collected,
15205then @code{tdump} will always attempt to dump using the basic collection
15206list, and may fail if a while-stepping frame does not include all the
15207same data that is collected at the tracepoint hit.
15208@c This is getting pretty arcane, example would be good.
15209
6149aea9
PA
15210@node save tracepoints
15211@subsection @code{save tracepoints @var{filename}}
15212@kindex save tracepoints
b37052ae
EZ
15213@kindex save-tracepoints
15214@cindex save tracepoints for future sessions
15215
15216This command saves all current tracepoint definitions together with
15217their actions and passcounts, into a file @file{@var{filename}}
15218suitable for use in a later debugging session. To read the saved
15219tracepoint definitions, use the @code{source} command (@pxref{Command
6149aea9
PA
15220Files}). The @w{@code{save-tracepoints}} command is a deprecated
15221alias for @w{@code{save tracepoints}}
b37052ae
EZ
15222
15223@node Tracepoint Variables
15224@section Convenience Variables for Tracepoints
15225@cindex tracepoint variables
15226@cindex convenience variables for tracepoints
15227
15228@table @code
15229@vindex $trace_frame
15230@item (int) $trace_frame
15231The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
15232snapshot is selected.
15233
15234@vindex $tracepoint
15235@item (int) $tracepoint
15236The tracepoint for the current trace snapshot.
15237
15238@vindex $trace_line
15239@item (int) $trace_line
15240The line number for the current trace snapshot.
15241
15242@vindex $trace_file
15243@item (char []) $trace_file
15244The source file for the current trace snapshot.
15245
15246@vindex $trace_func
15247@item (char []) $trace_func
15248The name of the function containing @code{$tracepoint}.
15249@end table
15250
15251Note: @code{$trace_file} is not suitable for use in @code{printf},
15252use @code{output} instead.
15253
15254Here's a simple example of using these convenience variables for
15255stepping through all the trace snapshots and printing some of their
f61e138d
SS
15256data. Note that these are not the same as trace state variables,
15257which are managed by the target.
b37052ae
EZ
15258
15259@smallexample
15260(@value{GDBP}) @b{tfind start}
15261
15262(@value{GDBP}) @b{while $trace_frame != -1}
15263> output $trace_file
15264> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
15265> tfind
15266> end
15267@end smallexample
15268
00bf0b85
SS
15269@node Trace Files
15270@section Using Trace Files
15271@cindex trace files
15272
15273In some situations, the target running a trace experiment may no
15274longer be available; perhaps it crashed, or the hardware was needed
15275for a different activity. To handle these cases, you can arrange to
15276dump the trace data into a file, and later use that file as a source
15277of trace data, via the @code{target tfile} command.
15278
15279@table @code
15280
15281@kindex tsave
15282@item tsave [ -r ] @var{filename}
d0353e76 15283@itemx tsave [-ctf] @var{dirname}
00bf0b85
SS
15284Save the trace data to @var{filename}. By default, this command
15285assumes that @var{filename} refers to the host filesystem, so if
15286necessary @value{GDBN} will copy raw trace data up from the target and
15287then save it. If the target supports it, you can also supply the
15288optional argument @code{-r} (``remote'') to direct the target to save
15289the data directly into @var{filename} in its own filesystem, which may be
15290more efficient if the trace buffer is very large. (Note, however, that
15291@code{target tfile} can only read from files accessible to the host.)
d0353e76 15292By default, this command will save trace frame in tfile format.
be06ba8c 15293You can supply the optional argument @code{-ctf} to save data in CTF
d0353e76
YQ
15294format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
15295that can be shared by multiple debugging and tracing tools. Please go to
15296@indicateurl{http://www.efficios.com/ctf} to get more information.
00bf0b85
SS
15297
15298@kindex target tfile
15299@kindex tfile
393fd4c3
YQ
15300@kindex target ctf
15301@kindex ctf
00bf0b85 15302@item target tfile @var{filename}
393fd4c3
YQ
15303@itemx target ctf @var{dirname}
15304Use the file named @var{filename} or directory named @var{dirname} as
15305a source of trace data. Commands that examine data work as they do with
15306a live target, but it is not possible to run any new trace experiments.
15307@code{tstatus} will report the state of the trace run at the moment
15308the data was saved, as well as the current trace frame you are examining.
697aa1b7 15309Both @var{filename} and @var{dirname} must be on a filesystem accessible to
393fd4c3
YQ
15310the host.
15311
15312@smallexample
15313(@value{GDBP}) target ctf ctf.ctf
15314(@value{GDBP}) tfind
15315Found trace frame 0, tracepoint 2
1531639 ++a; /* set tracepoint 1 here */
15317(@value{GDBP}) tdump
15318Data collected at tracepoint 2, trace frame 0:
15319i = 0
15320a = 0
15321b = 1 '\001'
15322c = @{"123", "456", "789", "123", "456", "789"@}
15323d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
15324(@value{GDBP}) p b
15325$1 = 1
15326@end smallexample
00bf0b85
SS
15327
15328@end table
15329
df0cd8c5
JB
15330@node Overlays
15331@chapter Debugging Programs That Use Overlays
15332@cindex overlays
15333
15334If your program is too large to fit completely in your target system's
15335memory, you can sometimes use @dfn{overlays} to work around this
15336problem. @value{GDBN} provides some support for debugging programs that
15337use overlays.
15338
15339@menu
15340* How Overlays Work:: A general explanation of overlays.
15341* Overlay Commands:: Managing overlays in @value{GDBN}.
15342* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
15343 mapped by asking the inferior.
15344* Overlay Sample Program:: A sample program using overlays.
15345@end menu
15346
15347@node How Overlays Work
15348@section How Overlays Work
15349@cindex mapped overlays
15350@cindex unmapped overlays
15351@cindex load address, overlay's
15352@cindex mapped address
15353@cindex overlay area
15354
15355Suppose you have a computer whose instruction address space is only 64
15356kilobytes long, but which has much more memory which can be accessed by
15357other means: special instructions, segment registers, or memory
15358management hardware, for example. Suppose further that you want to
15359adapt a program which is larger than 64 kilobytes to run on this system.
15360
15361One solution is to identify modules of your program which are relatively
15362independent, and need not call each other directly; call these modules
15363@dfn{overlays}. Separate the overlays from the main program, and place
15364their machine code in the larger memory. Place your main program in
15365instruction memory, but leave at least enough space there to hold the
15366largest overlay as well.
15367
15368Now, to call a function located in an overlay, you must first copy that
15369overlay's machine code from the large memory into the space set aside
15370for it in the instruction memory, and then jump to its entry point
15371there.
15372
c928edc0
AC
15373@c NB: In the below the mapped area's size is greater or equal to the
15374@c size of all overlays. This is intentional to remind the developer
15375@c that overlays don't necessarily need to be the same size.
15376
474c8240 15377@smallexample
df0cd8c5 15378@group
c928edc0
AC
15379 Data Instruction Larger
15380Address Space Address Space Address Space
15381+-----------+ +-----------+ +-----------+
15382| | | | | |
15383+-----------+ +-----------+ +-----------+<-- overlay 1
15384| program | | main | .----| overlay 1 | load address
15385| variables | | program | | +-----------+
15386| and heap | | | | | |
15387+-----------+ | | | +-----------+<-- overlay 2
15388| | +-----------+ | | | load address
15389+-----------+ | | | .-| overlay 2 |
15390 | | | | | |
15391 mapped --->+-----------+ | | +-----------+
15392 address | | | | | |
15393 | overlay | <-' | | |
15394 | area | <---' +-----------+<-- overlay 3
15395 | | <---. | | load address
15396 +-----------+ `--| overlay 3 |
15397 | | | |
15398 +-----------+ | |
15399 +-----------+
15400 | |
15401 +-----------+
15402
15403 @anchor{A code overlay}A code overlay
df0cd8c5 15404@end group
474c8240 15405@end smallexample
df0cd8c5 15406
c928edc0
AC
15407The diagram (@pxref{A code overlay}) shows a system with separate data
15408and instruction address spaces. To map an overlay, the program copies
15409its code from the larger address space to the instruction address space.
15410Since the overlays shown here all use the same mapped address, only one
15411may be mapped at a time. For a system with a single address space for
15412data and instructions, the diagram would be similar, except that the
15413program variables and heap would share an address space with the main
15414program and the overlay area.
df0cd8c5
JB
15415
15416An overlay loaded into instruction memory and ready for use is called a
15417@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
15418instruction memory. An overlay not present (or only partially present)
15419in instruction memory is called @dfn{unmapped}; its @dfn{load address}
15420is its address in the larger memory. The mapped address is also called
15421the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
15422called the @dfn{load memory address}, or @dfn{LMA}.
15423
15424Unfortunately, overlays are not a completely transparent way to adapt a
15425program to limited instruction memory. They introduce a new set of
15426global constraints you must keep in mind as you design your program:
15427
15428@itemize @bullet
15429
15430@item
15431Before calling or returning to a function in an overlay, your program
15432must make sure that overlay is actually mapped. Otherwise, the call or
15433return will transfer control to the right address, but in the wrong
15434overlay, and your program will probably crash.
15435
15436@item
15437If the process of mapping an overlay is expensive on your system, you
15438will need to choose your overlays carefully to minimize their effect on
15439your program's performance.
15440
15441@item
15442The executable file you load onto your system must contain each
15443overlay's instructions, appearing at the overlay's load address, not its
15444mapped address. However, each overlay's instructions must be relocated
15445and its symbols defined as if the overlay were at its mapped address.
15446You can use GNU linker scripts to specify different load and relocation
15447addresses for pieces of your program; see @ref{Overlay Description,,,
15448ld.info, Using ld: the GNU linker}.
15449
15450@item
15451The procedure for loading executable files onto your system must be able
15452to load their contents into the larger address space as well as the
15453instruction and data spaces.
15454
15455@end itemize
15456
15457The overlay system described above is rather simple, and could be
15458improved in many ways:
15459
15460@itemize @bullet
15461
15462@item
15463If your system has suitable bank switch registers or memory management
15464hardware, you could use those facilities to make an overlay's load area
15465contents simply appear at their mapped address in instruction space.
15466This would probably be faster than copying the overlay to its mapped
15467area in the usual way.
15468
15469@item
15470If your overlays are small enough, you could set aside more than one
15471overlay area, and have more than one overlay mapped at a time.
15472
15473@item
15474You can use overlays to manage data, as well as instructions. In
15475general, data overlays are even less transparent to your design than
15476code overlays: whereas code overlays only require care when you call or
15477return to functions, data overlays require care every time you access
15478the data. Also, if you change the contents of a data overlay, you
15479must copy its contents back out to its load address before you can copy a
15480different data overlay into the same mapped area.
15481
15482@end itemize
15483
15484
15485@node Overlay Commands
15486@section Overlay Commands
15487
15488To use @value{GDBN}'s overlay support, each overlay in your program must
15489correspond to a separate section of the executable file. The section's
15490virtual memory address and load memory address must be the overlay's
15491mapped and load addresses. Identifying overlays with sections allows
15492@value{GDBN} to determine the appropriate address of a function or
15493variable, depending on whether the overlay is mapped or not.
15494
15495@value{GDBN}'s overlay commands all start with the word @code{overlay};
15496you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
15497
15498@table @code
15499@item overlay off
4644b6e3 15500@kindex overlay
df0cd8c5
JB
15501Disable @value{GDBN}'s overlay support. When overlay support is
15502disabled, @value{GDBN} assumes that all functions and variables are
15503always present at their mapped addresses. By default, @value{GDBN}'s
15504overlay support is disabled.
15505
15506@item overlay manual
df0cd8c5
JB
15507@cindex manual overlay debugging
15508Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
15509relies on you to tell it which overlays are mapped, and which are not,
15510using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
15511commands described below.
15512
15513@item overlay map-overlay @var{overlay}
15514@itemx overlay map @var{overlay}
df0cd8c5
JB
15515@cindex map an overlay
15516Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
15517be the name of the object file section containing the overlay. When an
15518overlay is mapped, @value{GDBN} assumes it can find the overlay's
15519functions and variables at their mapped addresses. @value{GDBN} assumes
15520that any other overlays whose mapped ranges overlap that of
15521@var{overlay} are now unmapped.
15522
15523@item overlay unmap-overlay @var{overlay}
15524@itemx overlay unmap @var{overlay}
df0cd8c5
JB
15525@cindex unmap an overlay
15526Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
15527must be the name of the object file section containing the overlay.
15528When an overlay is unmapped, @value{GDBN} assumes it can find the
15529overlay's functions and variables at their load addresses.
15530
15531@item overlay auto
df0cd8c5
JB
15532Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
15533consults a data structure the overlay manager maintains in the inferior
15534to see which overlays are mapped. For details, see @ref{Automatic
15535Overlay Debugging}.
15536
15537@item overlay load-target
15538@itemx overlay load
df0cd8c5
JB
15539@cindex reloading the overlay table
15540Re-read the overlay table from the inferior. Normally, @value{GDBN}
15541re-reads the table @value{GDBN} automatically each time the inferior
15542stops, so this command should only be necessary if you have changed the
15543overlay mapping yourself using @value{GDBN}. This command is only
15544useful when using automatic overlay debugging.
15545
15546@item overlay list-overlays
15547@itemx overlay list
15548@cindex listing mapped overlays
15549Display a list of the overlays currently mapped, along with their mapped
15550addresses, load addresses, and sizes.
15551
15552@end table
15553
15554Normally, when @value{GDBN} prints a code address, it includes the name
15555of the function the address falls in:
15556
474c8240 15557@smallexample
f7dc1244 15558(@value{GDBP}) print main
df0cd8c5 15559$3 = @{int ()@} 0x11a0 <main>
474c8240 15560@end smallexample
df0cd8c5
JB
15561@noindent
15562When overlay debugging is enabled, @value{GDBN} recognizes code in
15563unmapped overlays, and prints the names of unmapped functions with
15564asterisks around them. For example, if @code{foo} is a function in an
15565unmapped overlay, @value{GDBN} prints it this way:
15566
474c8240 15567@smallexample
f7dc1244 15568(@value{GDBP}) overlay list
df0cd8c5 15569No sections are mapped.
f7dc1244 15570(@value{GDBP}) print foo
df0cd8c5 15571$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 15572@end smallexample
df0cd8c5
JB
15573@noindent
15574When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
15575name normally:
15576
474c8240 15577@smallexample
f7dc1244 15578(@value{GDBP}) overlay list
b383017d 15579Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 15580 mapped at 0x1016 - 0x104a
f7dc1244 15581(@value{GDBP}) print foo
df0cd8c5 15582$6 = @{int (int)@} 0x1016 <foo>
474c8240 15583@end smallexample
df0cd8c5
JB
15584
15585When overlay debugging is enabled, @value{GDBN} can find the correct
15586address for functions and variables in an overlay, whether or not the
15587overlay is mapped. This allows most @value{GDBN} commands, like
15588@code{break} and @code{disassemble}, to work normally, even on unmapped
15589code. However, @value{GDBN}'s breakpoint support has some limitations:
15590
15591@itemize @bullet
15592@item
15593@cindex breakpoints in overlays
15594@cindex overlays, setting breakpoints in
15595You can set breakpoints in functions in unmapped overlays, as long as
15596@value{GDBN} can write to the overlay at its load address.
15597@item
15598@value{GDBN} can not set hardware or simulator-based breakpoints in
15599unmapped overlays. However, if you set a breakpoint at the end of your
15600overlay manager (and tell @value{GDBN} which overlays are now mapped, if
15601you are using manual overlay management), @value{GDBN} will re-set its
15602breakpoints properly.
15603@end itemize
15604
15605
15606@node Automatic Overlay Debugging
15607@section Automatic Overlay Debugging
15608@cindex automatic overlay debugging
15609
15610@value{GDBN} can automatically track which overlays are mapped and which
15611are not, given some simple co-operation from the overlay manager in the
15612inferior. If you enable automatic overlay debugging with the
15613@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
15614looks in the inferior's memory for certain variables describing the
15615current state of the overlays.
15616
15617Here are the variables your overlay manager must define to support
15618@value{GDBN}'s automatic overlay debugging:
15619
15620@table @asis
15621
15622@item @code{_ovly_table}:
15623This variable must be an array of the following structures:
15624
474c8240 15625@smallexample
df0cd8c5
JB
15626struct
15627@{
15628 /* The overlay's mapped address. */
15629 unsigned long vma;
15630
15631 /* The size of the overlay, in bytes. */
15632 unsigned long size;
15633
15634 /* The overlay's load address. */
15635 unsigned long lma;
15636
15637 /* Non-zero if the overlay is currently mapped;
15638 zero otherwise. */
15639 unsigned long mapped;
15640@}
474c8240 15641@end smallexample
df0cd8c5
JB
15642
15643@item @code{_novlys}:
15644This variable must be a four-byte signed integer, holding the total
15645number of elements in @code{_ovly_table}.
15646
15647@end table
15648
15649To decide whether a particular overlay is mapped or not, @value{GDBN}
15650looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
15651@code{lma} members equal the VMA and LMA of the overlay's section in the
15652executable file. When @value{GDBN} finds a matching entry, it consults
15653the entry's @code{mapped} member to determine whether the overlay is
15654currently mapped.
15655
81d46470 15656In addition, your overlay manager may define a function called
def71bfa 15657@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
15658will silently set a breakpoint there. If the overlay manager then
15659calls this function whenever it has changed the overlay table, this
15660will enable @value{GDBN} to accurately keep track of which overlays
15661are in program memory, and update any breakpoints that may be set
b383017d 15662in overlays. This will allow breakpoints to work even if the
81d46470
MS
15663overlays are kept in ROM or other non-writable memory while they
15664are not being executed.
df0cd8c5
JB
15665
15666@node Overlay Sample Program
15667@section Overlay Sample Program
15668@cindex overlay example program
15669
15670When linking a program which uses overlays, you must place the overlays
15671at their load addresses, while relocating them to run at their mapped
15672addresses. To do this, you must write a linker script (@pxref{Overlay
15673Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
15674since linker scripts are specific to a particular host system, target
15675architecture, and target memory layout, this manual cannot provide
15676portable sample code demonstrating @value{GDBN}'s overlay support.
15677
15678However, the @value{GDBN} source distribution does contain an overlaid
15679program, with linker scripts for a few systems, as part of its test
15680suite. The program consists of the following files from
15681@file{gdb/testsuite/gdb.base}:
15682
15683@table @file
15684@item overlays.c
15685The main program file.
15686@item ovlymgr.c
15687A simple overlay manager, used by @file{overlays.c}.
15688@item foo.c
15689@itemx bar.c
15690@itemx baz.c
15691@itemx grbx.c
15692Overlay modules, loaded and used by @file{overlays.c}.
15693@item d10v.ld
15694@itemx m32r.ld
15695Linker scripts for linking the test program on the @code{d10v-elf}
15696and @code{m32r-elf} targets.
15697@end table
15698
15699You can build the test program using the @code{d10v-elf} GCC
15700cross-compiler like this:
15701
474c8240 15702@smallexample
df0cd8c5
JB
15703$ d10v-elf-gcc -g -c overlays.c
15704$ d10v-elf-gcc -g -c ovlymgr.c
15705$ d10v-elf-gcc -g -c foo.c
15706$ d10v-elf-gcc -g -c bar.c
15707$ d10v-elf-gcc -g -c baz.c
15708$ d10v-elf-gcc -g -c grbx.c
15709$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
15710 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 15711@end smallexample
df0cd8c5
JB
15712
15713The build process is identical for any other architecture, except that
15714you must substitute the appropriate compiler and linker script for the
15715target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
15716
15717
6d2ebf8b 15718@node Languages
c906108c
SS
15719@chapter Using @value{GDBN} with Different Languages
15720@cindex languages
15721
c906108c
SS
15722Although programming languages generally have common aspects, they are
15723rarely expressed in the same manner. For instance, in ANSI C,
15724dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
15725Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 15726represented (and displayed) differently. Hex numbers in C appear as
c906108c 15727@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
15728
15729@cindex working language
15730Language-specific information is built into @value{GDBN} for some languages,
15731allowing you to express operations like the above in your program's
15732native language, and allowing @value{GDBN} to output values in a manner
15733consistent with the syntax of your program's native language. The
15734language you use to build expressions is called the @dfn{working
15735language}.
15736
15737@menu
15738* Setting:: Switching between source languages
15739* Show:: Displaying the language
c906108c 15740* Checks:: Type and range checks
79a6e687
BW
15741* Supported Languages:: Supported languages
15742* Unsupported Languages:: Unsupported languages
c906108c
SS
15743@end menu
15744
6d2ebf8b 15745@node Setting
79a6e687 15746@section Switching Between Source Languages
c906108c
SS
15747
15748There are two ways to control the working language---either have @value{GDBN}
15749set it automatically, or select it manually yourself. You can use the
15750@code{set language} command for either purpose. On startup, @value{GDBN}
15751defaults to setting the language automatically. The working language is
15752used to determine how expressions you type are interpreted, how values
15753are printed, etc.
15754
15755In addition to the working language, every source file that
15756@value{GDBN} knows about has its own working language. For some object
15757file formats, the compiler might indicate which language a particular
15758source file is in. However, most of the time @value{GDBN} infers the
15759language from the name of the file. The language of a source file
b37052ae 15760controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 15761show each frame appropriately for its own language. There is no way to
d4f3574e
SS
15762set the language of a source file from within @value{GDBN}, but you can
15763set the language associated with a filename extension. @xref{Show, ,
79a6e687 15764Displaying the Language}.
c906108c
SS
15765
15766This is most commonly a problem when you use a program, such
5d161b24 15767as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
15768another language. In that case, make the
15769program use @code{#line} directives in its C output; that way
15770@value{GDBN} will know the correct language of the source code of the original
15771program, and will display that source code, not the generated C code.
15772
15773@menu
15774* Filenames:: Filename extensions and languages.
15775* Manually:: Setting the working language manually
15776* Automatically:: Having @value{GDBN} infer the source language
15777@end menu
15778
6d2ebf8b 15779@node Filenames
79a6e687 15780@subsection List of Filename Extensions and Languages
c906108c
SS
15781
15782If a source file name ends in one of the following extensions, then
15783@value{GDBN} infers that its language is the one indicated.
15784
15785@table @file
e07c999f
PH
15786@item .ada
15787@itemx .ads
15788@itemx .adb
15789@itemx .a
15790Ada source file.
c906108c
SS
15791
15792@item .c
15793C source file
15794
15795@item .C
15796@itemx .cc
15797@itemx .cp
15798@itemx .cpp
15799@itemx .cxx
15800@itemx .c++
b37052ae 15801C@t{++} source file
c906108c 15802
6aecb9c2
JB
15803@item .d
15804D source file
15805
b37303ee
AF
15806@item .m
15807Objective-C source file
15808
c906108c
SS
15809@item .f
15810@itemx .F
15811Fortran source file
15812
c906108c
SS
15813@item .mod
15814Modula-2 source file
c906108c
SS
15815
15816@item .s
15817@itemx .S
15818Assembler source file. This actually behaves almost like C, but
15819@value{GDBN} does not skip over function prologues when stepping.
15820@end table
15821
15822In addition, you may set the language associated with a filename
79a6e687 15823extension. @xref{Show, , Displaying the Language}.
c906108c 15824
6d2ebf8b 15825@node Manually
79a6e687 15826@subsection Setting the Working Language
c906108c
SS
15827
15828If you allow @value{GDBN} to set the language automatically,
15829expressions are interpreted the same way in your debugging session and
15830your program.
15831
15832@kindex set language
15833If you wish, you may set the language manually. To do this, issue the
15834command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 15835a language, such as
c906108c 15836@code{c} or @code{modula-2}.
c906108c
SS
15837For a list of the supported languages, type @samp{set language}.
15838
c906108c
SS
15839Setting the language manually prevents @value{GDBN} from updating the working
15840language automatically. This can lead to confusion if you try
15841to debug a program when the working language is not the same as the
15842source language, when an expression is acceptable to both
15843languages---but means different things. For instance, if the current
15844source file were written in C, and @value{GDBN} was parsing Modula-2, a
15845command such as:
15846
474c8240 15847@smallexample
c906108c 15848print a = b + c
474c8240 15849@end smallexample
c906108c
SS
15850
15851@noindent
15852might not have the effect you intended. In C, this means to add
15853@code{b} and @code{c} and place the result in @code{a}. The result
15854printed would be the value of @code{a}. In Modula-2, this means to compare
15855@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 15856
6d2ebf8b 15857@node Automatically
79a6e687 15858@subsection Having @value{GDBN} Infer the Source Language
c906108c
SS
15859
15860To have @value{GDBN} set the working language automatically, use
15861@samp{set language local} or @samp{set language auto}. @value{GDBN}
15862then infers the working language. That is, when your program stops in a
15863frame (usually by encountering a breakpoint), @value{GDBN} sets the
15864working language to the language recorded for the function in that
15865frame. If the language for a frame is unknown (that is, if the function
15866or block corresponding to the frame was defined in a source file that
15867does not have a recognized extension), the current working language is
15868not changed, and @value{GDBN} issues a warning.
15869
15870This may not seem necessary for most programs, which are written
15871entirely in one source language. However, program modules and libraries
15872written in one source language can be used by a main program written in
15873a different source language. Using @samp{set language auto} in this
15874case frees you from having to set the working language manually.
15875
6d2ebf8b 15876@node Show
79a6e687 15877@section Displaying the Language
c906108c
SS
15878
15879The following commands help you find out which language is the
15880working language, and also what language source files were written in.
15881
c906108c
SS
15882@table @code
15883@item show language
403cb6b1 15884@anchor{show language}
9c16f35a 15885@kindex show language
c906108c
SS
15886Display the current working language. This is the
15887language you can use with commands such as @code{print} to
15888build and compute expressions that may involve variables in your program.
15889
15890@item info frame
4644b6e3 15891@kindex info frame@r{, show the source language}
5d161b24 15892Display the source language for this frame. This language becomes the
c906108c 15893working language if you use an identifier from this frame.
79a6e687 15894@xref{Frame Info, ,Information about a Frame}, to identify the other
c906108c
SS
15895information listed here.
15896
15897@item info source
4644b6e3 15898@kindex info source@r{, show the source language}
c906108c 15899Display the source language of this source file.
5d161b24 15900@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
15901information listed here.
15902@end table
15903
15904In unusual circumstances, you may have source files with extensions
15905not in the standard list. You can then set the extension associated
15906with a language explicitly:
15907
c906108c 15908@table @code
09d4efe1 15909@item set extension-language @var{ext} @var{language}
9c16f35a 15910@kindex set extension-language
09d4efe1
EZ
15911Tell @value{GDBN} that source files with extension @var{ext} are to be
15912assumed as written in the source language @var{language}.
c906108c
SS
15913
15914@item info extensions
9c16f35a 15915@kindex info extensions
c906108c
SS
15916List all the filename extensions and the associated languages.
15917@end table
15918
6d2ebf8b 15919@node Checks
79a6e687 15920@section Type and Range Checking
c906108c 15921
c906108c
SS
15922Some languages are designed to guard you against making seemingly common
15923errors through a series of compile- and run-time checks. These include
a451cb65 15924checking the type of arguments to functions and operators and making
c906108c
SS
15925sure mathematical overflows are caught at run time. Checks such as
15926these help to ensure a program's correctness once it has been compiled
a451cb65 15927by eliminating type mismatches and providing active checks for range
c906108c
SS
15928errors when your program is running.
15929
a451cb65
KS
15930By default @value{GDBN} checks for these errors according to the
15931rules of the current source language. Although @value{GDBN} does not check
15932the statements in your program, it can check expressions entered directly
15933into @value{GDBN} for evaluation via the @code{print} command, for example.
c906108c
SS
15934
15935@menu
15936* Type Checking:: An overview of type checking
15937* Range Checking:: An overview of range checking
15938@end menu
15939
15940@cindex type checking
15941@cindex checks, type
6d2ebf8b 15942@node Type Checking
79a6e687 15943@subsection An Overview of Type Checking
c906108c 15944
a451cb65 15945Some languages, such as C and C@t{++}, are strongly typed, meaning that the
c906108c
SS
15946arguments to operators and functions have to be of the correct type,
15947otherwise an error occurs. These checks prevent type mismatch
15948errors from ever causing any run-time problems. For example,
15949
15950@smallexample
a451cb65
KS
15951int klass::my_method(char *b) @{ return b ? 1 : 2; @}
15952
15953(@value{GDBP}) print obj.my_method (0)
15954$1 = 2
c906108c 15955@exdent but
a451cb65
KS
15956(@value{GDBP}) print obj.my_method (0x1234)
15957Cannot resolve method klass::my_method to any overloaded instance
c906108c
SS
15958@end smallexample
15959
a451cb65
KS
15960The second example fails because in C@t{++} the integer constant
15961@samp{0x1234} is not type-compatible with the pointer parameter type.
c906108c 15962
a451cb65
KS
15963For the expressions you use in @value{GDBN} commands, you can tell
15964@value{GDBN} to not enforce strict type checking or
5d161b24 15965to treat any mismatches as errors and abandon the expression;
a451cb65
KS
15966When type checking is disabled, @value{GDBN} successfully evaluates
15967expressions like the second example above.
c906108c 15968
a451cb65 15969Even if type checking is off, there may be other reasons
5d161b24
DB
15970related to type that prevent @value{GDBN} from evaluating an expression.
15971For instance, @value{GDBN} does not know how to add an @code{int} and
15972a @code{struct foo}. These particular type errors have nothing to do
a451cb65
KS
15973with the language in use and usually arise from expressions which make
15974little sense to evaluate anyway.
c906108c 15975
a451cb65 15976@value{GDBN} provides some additional commands for controlling type checking:
c906108c 15977
c906108c
SS
15978@kindex set check type
15979@kindex show check type
15980@table @code
c906108c
SS
15981@item set check type on
15982@itemx set check type off
a451cb65 15983Set strict type checking on or off. If any type mismatches occur in
d4f3574e 15984evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
15985message and aborts evaluation of the expression.
15986
a451cb65
KS
15987@item show check type
15988Show the current setting of type checking and whether @value{GDBN}
15989is enforcing strict type checking rules.
c906108c
SS
15990@end table
15991
15992@cindex range checking
15993@cindex checks, range
6d2ebf8b 15994@node Range Checking
79a6e687 15995@subsection An Overview of Range Checking
c906108c
SS
15996
15997In some languages (such as Modula-2), it is an error to exceed the
15998bounds of a type; this is enforced with run-time checks. Such range
15999checking is meant to ensure program correctness by making sure
16000computations do not overflow, or indices on an array element access do
16001not exceed the bounds of the array.
16002
16003For expressions you use in @value{GDBN} commands, you can tell
16004@value{GDBN} to treat range errors in one of three ways: ignore them,
16005always treat them as errors and abandon the expression, or issue
16006warnings but evaluate the expression anyway.
16007
16008A range error can result from numerical overflow, from exceeding an
16009array index bound, or when you type a constant that is not a member
16010of any type. Some languages, however, do not treat overflows as an
16011error. In many implementations of C, mathematical overflow causes the
16012result to ``wrap around'' to lower values---for example, if @var{m} is
16013the largest integer value, and @var{s} is the smallest, then
16014
474c8240 16015@smallexample
c906108c 16016@var{m} + 1 @result{} @var{s}
474c8240 16017@end smallexample
c906108c
SS
16018
16019This, too, is specific to individual languages, and in some cases
79a6e687
BW
16020specific to individual compilers or machines. @xref{Supported Languages, ,
16021Supported Languages}, for further details on specific languages.
c906108c
SS
16022
16023@value{GDBN} provides some additional commands for controlling the range checker:
16024
c906108c
SS
16025@kindex set check range
16026@kindex show check range
16027@table @code
16028@item set check range auto
16029Set range checking on or off based on the current working language.
79a6e687 16030@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
16031each language.
16032
16033@item set check range on
16034@itemx set check range off
16035Set range checking on or off, overriding the default setting for the
16036current working language. A warning is issued if the setting does not
c3f6f71d
JM
16037match the language default. If a range error occurs and range checking is on,
16038then a message is printed and evaluation of the expression is aborted.
c906108c
SS
16039
16040@item set check range warn
16041Output messages when the @value{GDBN} range checker detects a range error,
16042but attempt to evaluate the expression anyway. Evaluating the
16043expression may still be impossible for other reasons, such as accessing
16044memory that the process does not own (a typical example from many Unix
16045systems).
16046
16047@item show range
16048Show the current setting of the range checker, and whether or not it is
16049being set automatically by @value{GDBN}.
16050@end table
c906108c 16051
79a6e687
BW
16052@node Supported Languages
16053@section Supported Languages
c906108c 16054
9c37b5ae 16055@value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
0bdfa368 16056OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
cce74817 16057@c This is false ...
c906108c
SS
16058Some @value{GDBN} features may be used in expressions regardless of the
16059language you use: the @value{GDBN} @code{@@} and @code{::} operators,
16060and the @samp{@{type@}addr} construct (@pxref{Expressions,
16061,Expressions}) can be used with the constructs of any supported
16062language.
16063
16064The following sections detail to what degree each source language is
16065supported by @value{GDBN}. These sections are not meant to be language
16066tutorials or references, but serve only as a reference guide to what the
16067@value{GDBN} expression parser accepts, and what input and output
16068formats should look like for different languages. There are many good
16069books written on each of these languages; please look to these for a
16070language reference or tutorial.
16071
c906108c 16072@menu
b37303ee 16073* C:: C and C@t{++}
6aecb9c2 16074* D:: D
a766d390 16075* Go:: Go
b383017d 16076* Objective-C:: Objective-C
f4b8a18d 16077* OpenCL C:: OpenCL C
09d4efe1 16078* Fortran:: Fortran
9c16f35a 16079* Pascal:: Pascal
0bdfa368 16080* Rust:: Rust
b37303ee 16081* Modula-2:: Modula-2
e07c999f 16082* Ada:: Ada
c906108c
SS
16083@end menu
16084
6d2ebf8b 16085@node C
b37052ae 16086@subsection C and C@t{++}
7a292a7a 16087
b37052ae
EZ
16088@cindex C and C@t{++}
16089@cindex expressions in C or C@t{++}
c906108c 16090
b37052ae 16091Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
16092to both languages. Whenever this is the case, we discuss those languages
16093together.
16094
41afff9a
EZ
16095@cindex C@t{++}
16096@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
16097@cindex @sc{gnu} C@t{++}
16098The C@t{++} debugging facilities are jointly implemented by the C@t{++}
16099compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
16100effectively, you must compile your C@t{++} programs with a supported
16101C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
16102compiler (@code{aCC}).
16103
c906108c 16104@menu
b37052ae
EZ
16105* C Operators:: C and C@t{++} operators
16106* C Constants:: C and C@t{++} constants
79a6e687 16107* C Plus Plus Expressions:: C@t{++} expressions
b37052ae
EZ
16108* C Defaults:: Default settings for C and C@t{++}
16109* C Checks:: C and C@t{++} type and range checks
c906108c 16110* Debugging C:: @value{GDBN} and C
79a6e687 16111* Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
febe4383 16112* Decimal Floating Point:: Numbers in Decimal Floating Point format
c906108c 16113@end menu
c906108c 16114
6d2ebf8b 16115@node C Operators
79a6e687 16116@subsubsection C and C@t{++} Operators
7a292a7a 16117
b37052ae 16118@cindex C and C@t{++} operators
c906108c
SS
16119
16120Operators must be defined on values of specific types. For instance,
16121@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 16122often defined on groups of types.
c906108c 16123
b37052ae 16124For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
16125
16126@itemize @bullet
53a5351d 16127
c906108c 16128@item
c906108c 16129@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 16130specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
16131
16132@item
d4f3574e
SS
16133@emph{Floating-point types} include @code{float}, @code{double}, and
16134@code{long double} (if supported by the target platform).
c906108c
SS
16135
16136@item
53a5351d 16137@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
16138
16139@item
16140@emph{Scalar types} include all of the above.
53a5351d 16141
c906108c
SS
16142@end itemize
16143
16144@noindent
16145The following operators are supported. They are listed here
16146in order of increasing precedence:
16147
16148@table @code
16149@item ,
16150The comma or sequencing operator. Expressions in a comma-separated list
16151are evaluated from left to right, with the result of the entire
16152expression being the last expression evaluated.
16153
16154@item =
16155Assignment. The value of an assignment expression is the value
16156assigned. Defined on scalar types.
16157
16158@item @var{op}=
16159Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
16160and translated to @w{@code{@var{a} = @var{a op b}}}.
697aa1b7 16161@w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
c906108c
SS
16162@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
16163@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
16164
16165@item ?:
16166The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
697aa1b7
EZ
16167of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
16168should be of an integral type.
c906108c
SS
16169
16170@item ||
16171Logical @sc{or}. Defined on integral types.
16172
16173@item &&
16174Logical @sc{and}. Defined on integral types.
16175
16176@item |
16177Bitwise @sc{or}. Defined on integral types.
16178
16179@item ^
16180Bitwise exclusive-@sc{or}. Defined on integral types.
16181
16182@item &
16183Bitwise @sc{and}. Defined on integral types.
16184
16185@item ==@r{, }!=
16186Equality and inequality. Defined on scalar types. The value of these
16187expressions is 0 for false and non-zero for true.
16188
16189@item <@r{, }>@r{, }<=@r{, }>=
16190Less than, greater than, less than or equal, greater than or equal.
16191Defined on scalar types. The value of these expressions is 0 for false
16192and non-zero for true.
16193
16194@item <<@r{, }>>
16195left shift, and right shift. Defined on integral types.
16196
16197@item @@
16198The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16199
16200@item +@r{, }-
16201Addition and subtraction. Defined on integral types, floating-point types and
16202pointer types.
16203
16204@item *@r{, }/@r{, }%
16205Multiplication, division, and modulus. Multiplication and division are
16206defined on integral and floating-point types. Modulus is defined on
16207integral types.
16208
16209@item ++@r{, }--
16210Increment and decrement. When appearing before a variable, the
16211operation is performed before the variable is used in an expression;
16212when appearing after it, the variable's value is used before the
16213operation takes place.
16214
16215@item *
16216Pointer dereferencing. Defined on pointer types. Same precedence as
16217@code{++}.
16218
16219@item &
16220Address operator. Defined on variables. Same precedence as @code{++}.
16221
b37052ae
EZ
16222For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
16223allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
b17828ca 16224to examine the address
b37052ae 16225where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 16226stored.
c906108c
SS
16227
16228@item -
16229Negative. Defined on integral and floating-point types. Same
16230precedence as @code{++}.
16231
16232@item !
16233Logical negation. Defined on integral types. Same precedence as
16234@code{++}.
16235
16236@item ~
16237Bitwise complement operator. Defined on integral types. Same precedence as
16238@code{++}.
16239
16240
16241@item .@r{, }->
16242Structure member, and pointer-to-structure member. For convenience,
16243@value{GDBN} regards the two as equivalent, choosing whether to dereference a
16244pointer based on the stored type information.
16245Defined on @code{struct} and @code{union} data.
16246
c906108c
SS
16247@item .*@r{, }->*
16248Dereferences of pointers to members.
c906108c
SS
16249
16250@item []
16251Array indexing. @code{@var{a}[@var{i}]} is defined as
16252@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
16253
16254@item ()
16255Function parameter list. Same precedence as @code{->}.
16256
c906108c 16257@item ::
b37052ae 16258C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 16259and @code{class} types.
c906108c
SS
16260
16261@item ::
7a292a7a
SS
16262Doubled colons also represent the @value{GDBN} scope operator
16263(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
16264above.
c906108c
SS
16265@end table
16266
c906108c
SS
16267If an operator is redefined in the user code, @value{GDBN} usually
16268attempts to invoke the redefined version instead of using the operator's
16269predefined meaning.
c906108c 16270
6d2ebf8b 16271@node C Constants
79a6e687 16272@subsubsection C and C@t{++} Constants
c906108c 16273
b37052ae 16274@cindex C and C@t{++} constants
c906108c 16275
b37052ae 16276@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 16277following ways:
c906108c
SS
16278
16279@itemize @bullet
16280@item
16281Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
16282specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
16283by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
16284@samp{l}, specifying that the constant should be treated as a
16285@code{long} value.
16286
16287@item
16288Floating point constants are a sequence of digits, followed by a decimal
16289point, followed by a sequence of digits, and optionally followed by an
16290exponent. An exponent is of the form:
16291@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
16292sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
16293A floating-point constant may also end with a letter @samp{f} or
16294@samp{F}, specifying that the constant should be treated as being of
16295the @code{float} (as opposed to the default @code{double}) type; or with
16296a letter @samp{l} or @samp{L}, which specifies a @code{long double}
16297constant.
c906108c
SS
16298
16299@item
16300Enumerated constants consist of enumerated identifiers, or their
16301integral equivalents.
16302
16303@item
16304Character constants are a single character surrounded by single quotes
16305(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 16306(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
16307be represented by a letter or by @dfn{escape sequences}, which are of
16308the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
16309of the character's ordinal value; or of the form @samp{\@var{x}}, where
16310@samp{@var{x}} is a predefined special character---for example,
16311@samp{\n} for newline.
16312
e0f8f636
TT
16313Wide character constants can be written by prefixing a character
16314constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
16315form of @samp{x}. The target wide character set is used when
16316computing the value of this constant (@pxref{Character Sets}).
16317
c906108c 16318@item
96a2c332
SS
16319String constants are a sequence of character constants surrounded by
16320double quotes (@code{"}). Any valid character constant (as described
16321above) may appear. Double quotes within the string must be preceded by
16322a backslash, so for instance @samp{"a\"b'c"} is a string of five
16323characters.
c906108c 16324
e0f8f636
TT
16325Wide string constants can be written by prefixing a string constant
16326with @samp{L}, as in C. The target wide character set is used when
16327computing the value of this constant (@pxref{Character Sets}).
16328
c906108c
SS
16329@item
16330Pointer constants are an integral value. You can also write pointers
16331to constants using the C operator @samp{&}.
16332
16333@item
16334Array constants are comma-separated lists surrounded by braces @samp{@{}
16335and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
16336integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
16337and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
16338@end itemize
16339
79a6e687
BW
16340@node C Plus Plus Expressions
16341@subsubsection C@t{++} Expressions
b37052ae
EZ
16342
16343@cindex expressions in C@t{++}
16344@value{GDBN} expression handling can interpret most C@t{++} expressions.
16345
0179ffac
DC
16346@cindex debugging C@t{++} programs
16347@cindex C@t{++} compilers
16348@cindex debug formats and C@t{++}
16349@cindex @value{NGCC} and C@t{++}
c906108c 16350@quotation
e0f8f636
TT
16351@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
16352the proper compiler and the proper debug format. Currently,
16353@value{GDBN} works best when debugging C@t{++} code that is compiled
16354with the most recent version of @value{NGCC} possible. The DWARF
16355debugging format is preferred; @value{NGCC} defaults to this on most
16356popular platforms. Other compilers and/or debug formats are likely to
16357work badly or not at all when using @value{GDBN} to debug C@t{++}
16358code. @xref{Compilation}.
c906108c 16359@end quotation
c906108c
SS
16360
16361@enumerate
16362
16363@cindex member functions
16364@item
16365Member function calls are allowed; you can use expressions like
16366
474c8240 16367@smallexample
c906108c 16368count = aml->GetOriginal(x, y)
474c8240 16369@end smallexample
c906108c 16370
41afff9a 16371@vindex this@r{, inside C@t{++} member functions}
b37052ae 16372@cindex namespace in C@t{++}
c906108c
SS
16373@item
16374While a member function is active (in the selected stack frame), your
16375expressions have the same namespace available as the member function;
16376that is, @value{GDBN} allows implicit references to the class instance
e0f8f636
TT
16377pointer @code{this} following the same rules as C@t{++}. @code{using}
16378declarations in the current scope are also respected by @value{GDBN}.
c906108c 16379
c906108c 16380@cindex call overloaded functions
d4f3574e 16381@cindex overloaded functions, calling
b37052ae 16382@cindex type conversions in C@t{++}
c906108c
SS
16383@item
16384You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 16385call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
16386perform overload resolution involving user-defined type conversions,
16387calls to constructors, or instantiations of templates that do not exist
16388in the program. It also cannot handle ellipsis argument lists or
16389default arguments.
16390
16391It does perform integral conversions and promotions, floating-point
16392promotions, arithmetic conversions, pointer conversions, conversions of
16393class objects to base classes, and standard conversions such as those of
16394functions or arrays to pointers; it requires an exact match on the
16395number of function arguments.
16396
16397Overload resolution is always performed, unless you have specified
79a6e687
BW
16398@code{set overload-resolution off}. @xref{Debugging C Plus Plus,
16399,@value{GDBN} Features for C@t{++}}.
c906108c 16400
d4f3574e 16401You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
16402explicit function signature to call an overloaded function, as in
16403@smallexample
16404p 'foo(char,int)'('x', 13)
16405@end smallexample
d4f3574e 16406
c906108c 16407The @value{GDBN} command-completion facility can simplify this;
79a6e687 16408see @ref{Completion, ,Command Completion}.
c906108c 16409
c906108c
SS
16410@cindex reference declarations
16411@item
c0f55cc6
AV
16412@value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
16413references; you can use them in expressions just as you do in C@t{++}
16414source---they are automatically dereferenced.
c906108c
SS
16415
16416In the parameter list shown when @value{GDBN} displays a frame, the values of
16417reference variables are not displayed (unlike other variables); this
16418avoids clutter, since references are often used for large structures.
16419The @emph{address} of a reference variable is always shown, unless
16420you have specified @samp{set print address off}.
16421
16422@item
b37052ae 16423@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
16424expressions can use it just as expressions in your program do. Since
16425one scope may be defined in another, you can use @code{::} repeatedly if
16426necessary, for example in an expression like
16427@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 16428resolving name scope by reference to source files, in both C and C@t{++}
79a6e687 16429debugging (@pxref{Variables, ,Program Variables}).
c906108c 16430
e0f8f636
TT
16431@item
16432@value{GDBN} performs argument-dependent lookup, following the C@t{++}
16433specification.
16434@end enumerate
c906108c 16435
6d2ebf8b 16436@node C Defaults
79a6e687 16437@subsubsection C and C@t{++} Defaults
7a292a7a 16438
b37052ae 16439@cindex C and C@t{++} defaults
c906108c 16440
a451cb65
KS
16441If you allow @value{GDBN} to set range checking automatically, it
16442defaults to @code{off} whenever the working language changes to
b37052ae 16443C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 16444selects the working language.
c906108c
SS
16445
16446If you allow @value{GDBN} to set the language automatically, it
16447recognizes source files whose names end with @file{.c}, @file{.C}, or
16448@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 16449these files, it sets the working language to C or C@t{++}.
79a6e687 16450@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
c906108c
SS
16451for further details.
16452
6d2ebf8b 16453@node C Checks
79a6e687 16454@subsubsection C and C@t{++} Type and Range Checks
7a292a7a 16455
b37052ae 16456@cindex C and C@t{++} checks
c906108c 16457
a451cb65
KS
16458By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
16459checking is used. However, if you turn type checking off, @value{GDBN}
16460will allow certain non-standard conversions, such as promoting integer
16461constants to pointers.
c906108c
SS
16462
16463Range checking, if turned on, is done on mathematical operations. Array
16464indices are not checked, since they are often used to index a pointer
16465that is not itself an array.
c906108c 16466
6d2ebf8b 16467@node Debugging C
c906108c 16468@subsubsection @value{GDBN} and C
c906108c
SS
16469
16470The @code{set print union} and @code{show print union} commands apply to
16471the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
16472inside a @code{struct} or @code{class} is also printed. Otherwise, it
16473appears as @samp{@{...@}}.
c906108c
SS
16474
16475The @code{@@} operator aids in the debugging of dynamic arrays, formed
16476with pointers and a memory allocation function. @xref{Expressions,
16477,Expressions}.
16478
79a6e687
BW
16479@node Debugging C Plus Plus
16480@subsubsection @value{GDBN} Features for C@t{++}
c906108c 16481
b37052ae 16482@cindex commands for C@t{++}
7a292a7a 16483
b37052ae
EZ
16484Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
16485designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
16486
16487@table @code
16488@cindex break in overloaded functions
16489@item @r{breakpoint menus}
16490When you want a breakpoint in a function whose name is overloaded,
6ba66d6a
JB
16491@value{GDBN} has the capability to display a menu of possible breakpoint
16492locations to help you specify which function definition you want.
16493@xref{Ambiguous Expressions,,Ambiguous Expressions}.
c906108c 16494
b37052ae 16495@cindex overloading in C@t{++}
c906108c
SS
16496@item rbreak @var{regex}
16497Setting breakpoints using regular expressions is helpful for setting
16498breakpoints on overloaded functions that are not members of any special
16499classes.
79a6e687 16500@xref{Set Breaks, ,Setting Breakpoints}.
c906108c 16501
b37052ae 16502@cindex C@t{++} exception handling
c906108c 16503@item catch throw
591f19e8 16504@itemx catch rethrow
c906108c 16505@itemx catch catch
b37052ae 16506Debug C@t{++} exception handling using these commands. @xref{Set
79a6e687 16507Catchpoints, , Setting Catchpoints}.
c906108c
SS
16508
16509@cindex inheritance
16510@item ptype @var{typename}
16511Print inheritance relationships as well as other information for type
16512@var{typename}.
16513@xref{Symbols, ,Examining the Symbol Table}.
16514
c4aeac85
TT
16515@item info vtbl @var{expression}.
16516The @code{info vtbl} command can be used to display the virtual
16517method tables of the object computed by @var{expression}. This shows
16518one entry per virtual table; there may be multiple virtual tables when
16519multiple inheritance is in use.
16520
439250fb
DE
16521@cindex C@t{++} demangling
16522@item demangle @var{name}
16523Demangle @var{name}.
16524@xref{Symbols}, for a more complete description of the @code{demangle} command.
16525
b37052ae 16526@cindex C@t{++} symbol display
c906108c
SS
16527@item set print demangle
16528@itemx show print demangle
16529@itemx set print asm-demangle
16530@itemx show print asm-demangle
b37052ae
EZ
16531Control whether C@t{++} symbols display in their source form, both when
16532displaying code as C@t{++} source and when displaying disassemblies.
79a6e687 16533@xref{Print Settings, ,Print Settings}.
c906108c
SS
16534
16535@item set print object
16536@itemx show print object
16537Choose whether to print derived (actual) or declared types of objects.
79a6e687 16538@xref{Print Settings, ,Print Settings}.
c906108c
SS
16539
16540@item set print vtbl
16541@itemx show print vtbl
16542Control the format for printing virtual function tables.
79a6e687 16543@xref{Print Settings, ,Print Settings}.
c906108c 16544(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 16545ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
16546
16547@kindex set overload-resolution
d4f3574e 16548@cindex overloaded functions, overload resolution
c906108c 16549@item set overload-resolution on
b37052ae 16550Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
16551is on. For overloaded functions, @value{GDBN} evaluates the arguments
16552and searches for a function whose signature matches the argument types,
79a6e687
BW
16553using the standard C@t{++} conversion rules (see @ref{C Plus Plus
16554Expressions, ,C@t{++} Expressions}, for details).
16555If it cannot find a match, it emits a message.
c906108c
SS
16556
16557@item set overload-resolution off
b37052ae 16558Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
16559overloaded functions that are not class member functions, @value{GDBN}
16560chooses the first function of the specified name that it finds in the
16561symbol table, whether or not its arguments are of the correct type. For
16562overloaded functions that are class member functions, @value{GDBN}
16563searches for a function whose signature @emph{exactly} matches the
16564argument types.
c906108c 16565
9c16f35a
EZ
16566@kindex show overload-resolution
16567@item show overload-resolution
16568Show the current setting of overload resolution.
16569
c906108c
SS
16570@item @r{Overloaded symbol names}
16571You can specify a particular definition of an overloaded symbol, using
b37052ae 16572the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
16573@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
16574also use the @value{GDBN} command-line word completion facilities to list the
16575available choices, or to finish the type list for you.
79a6e687 16576@xref{Completion,, Command Completion}, for details on how to do this.
bd69330d
PA
16577
16578@item @r{Breakpoints in functions with ABI tags}
16579
16580The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
16581correspond to changes in the ABI of a type, function, or variable that
16582would not otherwise be reflected in a mangled name. See
16583@url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
16584for more detail.
16585
16586The ABI tags are visible in C@t{++} demangled names. For example, a
16587function that returns a std::string:
16588
16589@smallexample
16590std::string function(int);
16591@end smallexample
16592
16593@noindent
16594when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
16595tag, and @value{GDBN} displays the symbol like this:
16596
16597@smallexample
16598function[abi:cxx11](int)
16599@end smallexample
16600
16601You can set a breakpoint on such functions simply as if they had no
16602tag. For example:
16603
16604@smallexample
16605(gdb) b function(int)
16606Breakpoint 2 at 0x40060d: file main.cc, line 10.
16607(gdb) info breakpoints
16608Num Type Disp Enb Address What
166091 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
16610 at main.cc:10
16611@end smallexample
16612
16613On the rare occasion you need to disambiguate between different ABI
16614tags, you can do so by simply including the ABI tag in the function
16615name, like:
16616
16617@smallexample
16618(@value{GDBP}) b ambiguous[abi:other_tag](int)
16619@end smallexample
c906108c 16620@end table
c906108c 16621
febe4383
TJB
16622@node Decimal Floating Point
16623@subsubsection Decimal Floating Point format
16624@cindex decimal floating point format
16625
16626@value{GDBN} can examine, set and perform computations with numbers in
16627decimal floating point format, which in the C language correspond to the
16628@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
16629specified by the extension to support decimal floating-point arithmetic.
16630
16631There are two encodings in use, depending on the architecture: BID (Binary
16632Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
4ac33720
UW
16633PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
16634configured target.
febe4383
TJB
16635
16636Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
16637to manipulate decimal floating point numbers, it is not possible to convert
16638(using a cast, for example) integers wider than 32-bit to decimal float.
16639
16640In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
16641point computations, error checking in decimal float operations ignores
16642underflow, overflow and divide by zero exceptions.
16643
4acd40f3 16644In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
99e008fe
EZ
16645to inspect @code{_Decimal128} values stored in floating point registers.
16646See @ref{PowerPC,,PowerPC} for more details.
4acd40f3 16647
6aecb9c2
JB
16648@node D
16649@subsection D
16650
16651@cindex D
16652@value{GDBN} can be used to debug programs written in D and compiled with
16653GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
16654specific feature --- dynamic arrays.
16655
a766d390
DE
16656@node Go
16657@subsection Go
16658
16659@cindex Go (programming language)
16660@value{GDBN} can be used to debug programs written in Go and compiled with
16661@file{gccgo} or @file{6g} compilers.
16662
16663Here is a summary of the Go-specific features and restrictions:
16664
16665@table @code
16666@cindex current Go package
16667@item The current Go package
16668The name of the current package does not need to be specified when
16669specifying global variables and functions.
16670
16671For example, given the program:
16672
16673@example
16674package main
16675var myglob = "Shall we?"
16676func main () @{
16677 // ...
16678@}
16679@end example
16680
16681When stopped inside @code{main} either of these work:
16682
16683@example
16684(gdb) p myglob
16685(gdb) p main.myglob
16686@end example
16687
16688@cindex builtin Go types
16689@item Builtin Go types
16690The @code{string} type is recognized by @value{GDBN} and is printed
16691as a string.
16692
16693@cindex builtin Go functions
16694@item Builtin Go functions
16695The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
16696function and handles it internally.
a766d390
DE
16697
16698@cindex restrictions on Go expressions
16699@item Restrictions on Go expressions
16700All Go operators are supported except @code{&^}.
16701The Go @code{_} ``blank identifier'' is not supported.
16702Automatic dereferencing of pointers is not supported.
50f042b9 16703@end table
a766d390 16704
b37303ee
AF
16705@node Objective-C
16706@subsection Objective-C
16707
16708@cindex Objective-C
16709This section provides information about some commands and command
721c2651
EZ
16710options that are useful for debugging Objective-C code. See also
16711@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
16712few more commands specific to Objective-C support.
b37303ee
AF
16713
16714@menu
b383017d
RM
16715* Method Names in Commands::
16716* The Print Command with Objective-C::
b37303ee
AF
16717@end menu
16718
c8f4133a 16719@node Method Names in Commands
b37303ee
AF
16720@subsubsection Method Names in Commands
16721
16722The following commands have been extended to accept Objective-C method
16723names as line specifications:
16724
16725@kindex clear@r{, and Objective-C}
16726@kindex break@r{, and Objective-C}
16727@kindex info line@r{, and Objective-C}
16728@kindex jump@r{, and Objective-C}
16729@kindex list@r{, and Objective-C}
16730@itemize
16731@item @code{clear}
16732@item @code{break}
16733@item @code{info line}
16734@item @code{jump}
16735@item @code{list}
16736@end itemize
16737
16738A fully qualified Objective-C method name is specified as
16739
16740@smallexample
16741-[@var{Class} @var{methodName}]
16742@end smallexample
16743
c552b3bb
JM
16744where the minus sign is used to indicate an instance method and a
16745plus sign (not shown) is used to indicate a class method. The class
16746name @var{Class} and method name @var{methodName} are enclosed in
16747brackets, similar to the way messages are specified in Objective-C
16748source code. For example, to set a breakpoint at the @code{create}
16749instance method of class @code{Fruit} in the program currently being
16750debugged, enter:
b37303ee
AF
16751
16752@smallexample
16753break -[Fruit create]
16754@end smallexample
16755
16756To list ten program lines around the @code{initialize} class method,
16757enter:
16758
16759@smallexample
16760list +[NSText initialize]
16761@end smallexample
16762
c552b3bb
JM
16763In the current version of @value{GDBN}, the plus or minus sign is
16764required. In future versions of @value{GDBN}, the plus or minus
16765sign will be optional, but you can use it to narrow the search. It
16766is also possible to specify just a method name:
b37303ee
AF
16767
16768@smallexample
16769break create
16770@end smallexample
16771
16772You must specify the complete method name, including any colons. If
16773your program's source files contain more than one @code{create} method,
16774you'll be presented with a numbered list of classes that implement that
16775method. Indicate your choice by number, or type @samp{0} to exit if
16776none apply.
16777
16778As another example, to clear a breakpoint established at the
16779@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
16780
16781@smallexample
16782clear -[NSWindow makeKeyAndOrderFront:]
16783@end smallexample
16784
16785@node The Print Command with Objective-C
16786@subsubsection The Print Command With Objective-C
721c2651 16787@cindex Objective-C, print objects
c552b3bb
JM
16788@kindex print-object
16789@kindex po @r{(@code{print-object})}
b37303ee 16790
c552b3bb 16791The print command has also been extended to accept methods. For example:
b37303ee
AF
16792
16793@smallexample
c552b3bb 16794print -[@var{object} hash]
b37303ee
AF
16795@end smallexample
16796
16797@cindex print an Objective-C object description
c552b3bb
JM
16798@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
16799@noindent
16800will tell @value{GDBN} to send the @code{hash} message to @var{object}
16801and print the result. Also, an additional command has been added,
16802@code{print-object} or @code{po} for short, which is meant to print
16803the description of an object. However, this command may only work
16804with certain Objective-C libraries that have a particular hook
16805function, @code{_NSPrintForDebugger}, defined.
b37303ee 16806
f4b8a18d
KW
16807@node OpenCL C
16808@subsection OpenCL C
16809
16810@cindex OpenCL C
16811This section provides information about @value{GDBN}s OpenCL C support.
16812
16813@menu
16814* OpenCL C Datatypes::
16815* OpenCL C Expressions::
16816* OpenCL C Operators::
16817@end menu
16818
16819@node OpenCL C Datatypes
16820@subsubsection OpenCL C Datatypes
16821
16822@cindex OpenCL C Datatypes
16823@value{GDBN} supports the builtin scalar and vector datatypes specified
16824by OpenCL 1.1. In addition the half- and double-precision floating point
16825data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
16826extensions are also known to @value{GDBN}.
16827
16828@node OpenCL C Expressions
16829@subsubsection OpenCL C Expressions
16830
16831@cindex OpenCL C Expressions
16832@value{GDBN} supports accesses to vector components including the access as
16833lvalue where possible. Since OpenCL C is based on C99 most C expressions
16834supported by @value{GDBN} can be used as well.
16835
16836@node OpenCL C Operators
16837@subsubsection OpenCL C Operators
16838
16839@cindex OpenCL C Operators
16840@value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
16841vector data types.
16842
09d4efe1
EZ
16843@node Fortran
16844@subsection Fortran
16845@cindex Fortran-specific support in @value{GDBN}
16846
814e32d7
WZ
16847@value{GDBN} can be used to debug programs written in Fortran, but it
16848currently supports only the features of Fortran 77 language.
16849
16850@cindex trailing underscore, in Fortran symbols
16851Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
16852among them) append an underscore to the names of variables and
16853functions. When you debug programs compiled by those compilers, you
16854will need to refer to variables and functions with a trailing
16855underscore.
16856
16857@menu
16858* Fortran Operators:: Fortran operators and expressions
16859* Fortran Defaults:: Default settings for Fortran
79a6e687 16860* Special Fortran Commands:: Special @value{GDBN} commands for Fortran
814e32d7
WZ
16861@end menu
16862
16863@node Fortran Operators
79a6e687 16864@subsubsection Fortran Operators and Expressions
814e32d7
WZ
16865
16866@cindex Fortran operators and expressions
16867
16868Operators must be defined on values of specific types. For instance,
16869@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 16870arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
16871
16872@table @code
16873@item **
99e008fe 16874The exponentiation operator. It raises the first operand to the power
814e32d7
WZ
16875of the second one.
16876
16877@item :
16878The range operator. Normally used in the form of array(low:high) to
16879represent a section of array.
68837c9d
MD
16880
16881@item %
16882The access component operator. Normally used to access elements in derived
16883types. Also suitable for unions. As unions aren't part of regular Fortran,
16884this can only happen when accessing a register that uses a gdbarch-defined
16885union type.
0a4b0913
AB
16886@item ::
16887The scope operator. Normally used to access variables in modules or
16888to set breakpoints on subroutines nested in modules or in other
16889subroutines (internal subroutines).
814e32d7
WZ
16890@end table
16891
16892@node Fortran Defaults
16893@subsubsection Fortran Defaults
16894
16895@cindex Fortran Defaults
16896
16897Fortran symbols are usually case-insensitive, so @value{GDBN} by
16898default uses case-insensitive matches for Fortran symbols. You can
16899change that with the @samp{set case-insensitive} command, see
16900@ref{Symbols}, for the details.
16901
79a6e687
BW
16902@node Special Fortran Commands
16903@subsubsection Special Fortran Commands
814e32d7
WZ
16904
16905@cindex Special Fortran commands
16906
db2e3e2e
BW
16907@value{GDBN} has some commands to support Fortran-specific features,
16908such as displaying common blocks.
814e32d7 16909
09d4efe1
EZ
16910@table @code
16911@cindex @code{COMMON} blocks, Fortran
16912@kindex info common
16913@item info common @r{[}@var{common-name}@r{]}
16914This command prints the values contained in the Fortran @code{COMMON}
16915block whose name is @var{common-name}. With no argument, the names of
d52fb0e9 16916all @code{COMMON} blocks visible at the current program location are
09d4efe1
EZ
16917printed.
16918@end table
16919
9c16f35a
EZ
16920@node Pascal
16921@subsection Pascal
16922
16923@cindex Pascal support in @value{GDBN}, limitations
16924Debugging Pascal programs which use sets, subranges, file variables, or
16925nested functions does not currently work. @value{GDBN} does not support
16926entering expressions, printing values, or similar features using Pascal
16927syntax.
16928
16929The Pascal-specific command @code{set print pascal_static-members}
16930controls whether static members of Pascal objects are displayed.
16931@xref{Print Settings, pascal_static-members}.
16932
0bdfa368
TT
16933@node Rust
16934@subsection Rust
16935
16936@value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
16937Programming Language}. Type- and value-printing, and expression
16938parsing, are reasonably complete. However, there are a few
16939peculiarities and holes to be aware of.
16940
16941@itemize @bullet
16942@item
16943Linespecs (@pxref{Specify Location}) are never relative to the current
16944crate. Instead, they act as if there were a global namespace of
16945crates, somewhat similar to the way @code{extern crate} behaves.
16946
16947That is, if @value{GDBN} is stopped at a breakpoint in a function in
16948crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
16949to set a breakpoint in a function named @samp{f} in a crate named
16950@samp{B}.
16951
16952As a consequence of this approach, linespecs also cannot refer to
16953items using @samp{self::} or @samp{super::}.
16954
16955@item
16956Because @value{GDBN} implements Rust name-lookup semantics in
16957expressions, it will sometimes prepend the current crate to a name.
16958For example, if @value{GDBN} is stopped at a breakpoint in the crate
16959@samp{K}, then @code{print ::x::y} will try to find the symbol
16960@samp{K::x::y}.
16961
16962However, since it is useful to be able to refer to other crates when
16963debugging, @value{GDBN} provides the @code{extern} extension to
16964circumvent this. To use the extension, just put @code{extern} before
16965a path expression to refer to the otherwise unavailable ``global''
16966scope.
16967
16968In the above example, if you wanted to refer to the symbol @samp{y} in
16969the crate @samp{x}, you would use @code{print extern x::y}.
16970
16971@item
16972The Rust expression evaluator does not support ``statement-like''
16973expressions such as @code{if} or @code{match}, or lambda expressions.
16974
16975@item
16976Tuple expressions are not implemented.
16977
16978@item
16979The Rust expression evaluator does not currently implement the
16980@code{Drop} trait. Objects that may be created by the evaluator will
16981never be destroyed.
16982
16983@item
16984@value{GDBN} does not implement type inference for generics. In order
16985to call generic functions or otherwise refer to generic items, you
16986will have to specify the type parameters manually.
16987
16988@item
16989@value{GDBN} currently uses the C@t{++} demangler for Rust. In most
16990cases this does not cause any problems. However, in an expression
16991context, completing a generic function name will give syntactically
16992invalid results. This happens because Rust requires the @samp{::}
16993operator between the function name and its generic arguments. For
16994example, @value{GDBN} might provide a completion like
16995@code{crate::f<u32>}, where the parser would require
16996@code{crate::f::<u32>}.
16997
16998@item
16999As of this writing, the Rust compiler (version 1.8) has a few holes in
17000the debugging information it generates. These holes prevent certain
17001features from being implemented by @value{GDBN}:
17002@itemize @bullet
17003
17004@item
17005Method calls cannot be made via traits.
17006
0bdfa368
TT
17007@item
17008Operator overloading is not implemented.
17009
17010@item
17011When debugging in a monomorphized function, you cannot use the generic
17012type names.
17013
17014@item
17015The type @code{Self} is not available.
17016
17017@item
17018@code{use} statements are not available, so some names may not be
17019available in the crate.
17020@end itemize
17021@end itemize
17022
09d4efe1 17023@node Modula-2
c906108c 17024@subsection Modula-2
7a292a7a 17025
d4f3574e 17026@cindex Modula-2, @value{GDBN} support
c906108c
SS
17027
17028The extensions made to @value{GDBN} to support Modula-2 only support
17029output from the @sc{gnu} Modula-2 compiler (which is currently being
17030developed). Other Modula-2 compilers are not currently supported, and
17031attempting to debug executables produced by them is most likely
17032to give an error as @value{GDBN} reads in the executable's symbol
17033table.
17034
17035@cindex expressions in Modula-2
17036@menu
17037* M2 Operators:: Built-in operators
17038* Built-In Func/Proc:: Built-in functions and procedures
17039* M2 Constants:: Modula-2 constants
72019c9c 17040* M2 Types:: Modula-2 types
c906108c
SS
17041* M2 Defaults:: Default settings for Modula-2
17042* Deviations:: Deviations from standard Modula-2
17043* M2 Checks:: Modula-2 type and range checks
17044* M2 Scope:: The scope operators @code{::} and @code{.}
17045* GDB/M2:: @value{GDBN} and Modula-2
17046@end menu
17047
6d2ebf8b 17048@node M2 Operators
c906108c
SS
17049@subsubsection Operators
17050@cindex Modula-2 operators
17051
17052Operators must be defined on values of specific types. For instance,
17053@code{+} is defined on numbers, but not on structures. Operators are
17054often defined on groups of types. For the purposes of Modula-2, the
17055following definitions hold:
17056
17057@itemize @bullet
17058
17059@item
17060@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
17061their subranges.
17062
17063@item
17064@emph{Character types} consist of @code{CHAR} and its subranges.
17065
17066@item
17067@emph{Floating-point types} consist of @code{REAL}.
17068
17069@item
17070@emph{Pointer types} consist of anything declared as @code{POINTER TO
17071@var{type}}.
17072
17073@item
17074@emph{Scalar types} consist of all of the above.
17075
17076@item
17077@emph{Set types} consist of @code{SET} and @code{BITSET} types.
17078
17079@item
17080@emph{Boolean types} consist of @code{BOOLEAN}.
17081@end itemize
17082
17083@noindent
17084The following operators are supported, and appear in order of
17085increasing precedence:
17086
17087@table @code
17088@item ,
17089Function argument or array index separator.
17090
17091@item :=
17092Assignment. The value of @var{var} @code{:=} @var{value} is
17093@var{value}.
17094
17095@item <@r{, }>
17096Less than, greater than on integral, floating-point, or enumerated
17097types.
17098
17099@item <=@r{, }>=
96a2c332 17100Less than or equal to, greater than or equal to
c906108c
SS
17101on integral, floating-point and enumerated types, or set inclusion on
17102set types. Same precedence as @code{<}.
17103
17104@item =@r{, }<>@r{, }#
17105Equality and two ways of expressing inequality, valid on scalar types.
17106Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
17107available for inequality, since @code{#} conflicts with the script
17108comment character.
17109
17110@item IN
17111Set membership. Defined on set types and the types of their members.
17112Same precedence as @code{<}.
17113
17114@item OR
17115Boolean disjunction. Defined on boolean types.
17116
17117@item AND@r{, }&
d4f3574e 17118Boolean conjunction. Defined on boolean types.
c906108c
SS
17119
17120@item @@
17121The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
17122
17123@item +@r{, }-
17124Addition and subtraction on integral and floating-point types, or union
17125and difference on set types.
17126
17127@item *
17128Multiplication on integral and floating-point types, or set intersection
17129on set types.
17130
17131@item /
17132Division on floating-point types, or symmetric set difference on set
17133types. Same precedence as @code{*}.
17134
17135@item DIV@r{, }MOD
17136Integer division and remainder. Defined on integral types. Same
17137precedence as @code{*}.
17138
17139@item -
99e008fe 17140Negative. Defined on @code{INTEGER} and @code{REAL} data.
c906108c
SS
17141
17142@item ^
17143Pointer dereferencing. Defined on pointer types.
17144
17145@item NOT
17146Boolean negation. Defined on boolean types. Same precedence as
17147@code{^}.
17148
17149@item .
17150@code{RECORD} field selector. Defined on @code{RECORD} data. Same
17151precedence as @code{^}.
17152
17153@item []
17154Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
17155
17156@item ()
17157Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
17158as @code{^}.
17159
17160@item ::@r{, }.
17161@value{GDBN} and Modula-2 scope operators.
17162@end table
17163
17164@quotation
72019c9c 17165@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
17166treats the use of the operator @code{IN}, or the use of operators
17167@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
17168@code{<=}, and @code{>=} on sets as an error.
17169@end quotation
17170
cb51c4e0 17171
6d2ebf8b 17172@node Built-In Func/Proc
79a6e687 17173@subsubsection Built-in Functions and Procedures
cb51c4e0 17174@cindex Modula-2 built-ins
c906108c
SS
17175
17176Modula-2 also makes available several built-in procedures and functions.
17177In describing these, the following metavariables are used:
17178
17179@table @var
17180
17181@item a
17182represents an @code{ARRAY} variable.
17183
17184@item c
17185represents a @code{CHAR} constant or variable.
17186
17187@item i
17188represents a variable or constant of integral type.
17189
17190@item m
17191represents an identifier that belongs to a set. Generally used in the
17192same function with the metavariable @var{s}. The type of @var{s} should
17193be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
17194
17195@item n
17196represents a variable or constant of integral or floating-point type.
17197
17198@item r
17199represents a variable or constant of floating-point type.
17200
17201@item t
17202represents a type.
17203
17204@item v
17205represents a variable.
17206
17207@item x
17208represents a variable or constant of one of many types. See the
17209explanation of the function for details.
17210@end table
17211
17212All Modula-2 built-in procedures also return a result, described below.
17213
17214@table @code
17215@item ABS(@var{n})
17216Returns the absolute value of @var{n}.
17217
17218@item CAP(@var{c})
17219If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 17220equivalent, otherwise it returns its argument.
c906108c
SS
17221
17222@item CHR(@var{i})
17223Returns the character whose ordinal value is @var{i}.
17224
17225@item DEC(@var{v})
c3f6f71d 17226Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
17227
17228@item DEC(@var{v},@var{i})
17229Decrements the value in the variable @var{v} by @var{i}. Returns the
17230new value.
17231
17232@item EXCL(@var{m},@var{s})
17233Removes the element @var{m} from the set @var{s}. Returns the new
17234set.
17235
17236@item FLOAT(@var{i})
17237Returns the floating point equivalent of the integer @var{i}.
17238
17239@item HIGH(@var{a})
17240Returns the index of the last member of @var{a}.
17241
17242@item INC(@var{v})
c3f6f71d 17243Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
17244
17245@item INC(@var{v},@var{i})
17246Increments the value in the variable @var{v} by @var{i}. Returns the
17247new value.
17248
17249@item INCL(@var{m},@var{s})
17250Adds the element @var{m} to the set @var{s} if it is not already
17251there. Returns the new set.
17252
17253@item MAX(@var{t})
17254Returns the maximum value of the type @var{t}.
17255
17256@item MIN(@var{t})
17257Returns the minimum value of the type @var{t}.
17258
17259@item ODD(@var{i})
17260Returns boolean TRUE if @var{i} is an odd number.
17261
17262@item ORD(@var{x})
17263Returns the ordinal value of its argument. For example, the ordinal
697aa1b7
EZ
17264value of a character is its @sc{ascii} value (on machines supporting
17265the @sc{ascii} character set). The argument @var{x} must be of an
17266ordered type, which include integral, character and enumerated types.
c906108c
SS
17267
17268@item SIZE(@var{x})
697aa1b7
EZ
17269Returns the size of its argument. The argument @var{x} can be a
17270variable or a type.
c906108c
SS
17271
17272@item TRUNC(@var{r})
17273Returns the integral part of @var{r}.
17274
844781a1 17275@item TSIZE(@var{x})
697aa1b7
EZ
17276Returns the size of its argument. The argument @var{x} can be a
17277variable or a type.
844781a1 17278
c906108c
SS
17279@item VAL(@var{t},@var{i})
17280Returns the member of the type @var{t} whose ordinal value is @var{i}.
17281@end table
17282
17283@quotation
17284@emph{Warning:} Sets and their operations are not yet supported, so
17285@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
17286an error.
17287@end quotation
17288
17289@cindex Modula-2 constants
6d2ebf8b 17290@node M2 Constants
c906108c
SS
17291@subsubsection Constants
17292
17293@value{GDBN} allows you to express the constants of Modula-2 in the following
17294ways:
17295
17296@itemize @bullet
17297
17298@item
17299Integer constants are simply a sequence of digits. When used in an
17300expression, a constant is interpreted to be type-compatible with the
17301rest of the expression. Hexadecimal integers are specified by a
17302trailing @samp{H}, and octal integers by a trailing @samp{B}.
17303
17304@item
17305Floating point constants appear as a sequence of digits, followed by a
17306decimal point and another sequence of digits. An optional exponent can
17307then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
17308@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
17309digits of the floating point constant must be valid decimal (base 10)
17310digits.
17311
17312@item
17313Character constants consist of a single character enclosed by a pair of
17314like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 17315also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
17316followed by a @samp{C}.
17317
17318@item
17319String constants consist of a sequence of characters enclosed by a
17320pair of like quotes, either single (@code{'}) or double (@code{"}).
17321Escape sequences in the style of C are also allowed. @xref{C
79a6e687 17322Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
c906108c
SS
17323sequences.
17324
17325@item
17326Enumerated constants consist of an enumerated identifier.
17327
17328@item
17329Boolean constants consist of the identifiers @code{TRUE} and
17330@code{FALSE}.
17331
17332@item
17333Pointer constants consist of integral values only.
17334
17335@item
17336Set constants are not yet supported.
17337@end itemize
17338
72019c9c
GM
17339@node M2 Types
17340@subsubsection Modula-2 Types
17341@cindex Modula-2 types
17342
17343Currently @value{GDBN} can print the following data types in Modula-2
17344syntax: array types, record types, set types, pointer types, procedure
17345types, enumerated types, subrange types and base types. You can also
17346print the contents of variables declared using these type.
17347This section gives a number of simple source code examples together with
17348sample @value{GDBN} sessions.
17349
17350The first example contains the following section of code:
17351
17352@smallexample
17353VAR
17354 s: SET OF CHAR ;
17355 r: [20..40] ;
17356@end smallexample
17357
17358@noindent
17359and you can request @value{GDBN} to interrogate the type and value of
17360@code{r} and @code{s}.
17361
17362@smallexample
17363(@value{GDBP}) print s
17364@{'A'..'C', 'Z'@}
17365(@value{GDBP}) ptype s
17366SET OF CHAR
17367(@value{GDBP}) print r
1736821
17369(@value{GDBP}) ptype r
17370[20..40]
17371@end smallexample
17372
17373@noindent
17374Likewise if your source code declares @code{s} as:
17375
17376@smallexample
17377VAR
17378 s: SET ['A'..'Z'] ;
17379@end smallexample
17380
17381@noindent
17382then you may query the type of @code{s} by:
17383
17384@smallexample
17385(@value{GDBP}) ptype s
17386type = SET ['A'..'Z']
17387@end smallexample
17388
17389@noindent
17390Note that at present you cannot interactively manipulate set
17391expressions using the debugger.
17392
17393The following example shows how you might declare an array in Modula-2
17394and how you can interact with @value{GDBN} to print its type and contents:
17395
17396@smallexample
17397VAR
17398 s: ARRAY [-10..10] OF CHAR ;
17399@end smallexample
17400
17401@smallexample
17402(@value{GDBP}) ptype s
17403ARRAY [-10..10] OF CHAR
17404@end smallexample
17405
17406Note that the array handling is not yet complete and although the type
17407is printed correctly, expression handling still assumes that all
17408arrays have a lower bound of zero and not @code{-10} as in the example
844781a1 17409above.
72019c9c
GM
17410
17411Here are some more type related Modula-2 examples:
17412
17413@smallexample
17414TYPE
17415 colour = (blue, red, yellow, green) ;
17416 t = [blue..yellow] ;
17417VAR
17418 s: t ;
17419BEGIN
17420 s := blue ;
17421@end smallexample
17422
17423@noindent
17424The @value{GDBN} interaction shows how you can query the data type
17425and value of a variable.
17426
17427@smallexample
17428(@value{GDBP}) print s
17429$1 = blue
17430(@value{GDBP}) ptype t
17431type = [blue..yellow]
17432@end smallexample
17433
17434@noindent
17435In this example a Modula-2 array is declared and its contents
17436displayed. Observe that the contents are written in the same way as
17437their @code{C} counterparts.
17438
17439@smallexample
17440VAR
17441 s: ARRAY [1..5] OF CARDINAL ;
17442BEGIN
17443 s[1] := 1 ;
17444@end smallexample
17445
17446@smallexample
17447(@value{GDBP}) print s
17448$1 = @{1, 0, 0, 0, 0@}
17449(@value{GDBP}) ptype s
17450type = ARRAY [1..5] OF CARDINAL
17451@end smallexample
17452
17453The Modula-2 language interface to @value{GDBN} also understands
17454pointer types as shown in this example:
17455
17456@smallexample
17457VAR
17458 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
17459BEGIN
17460 NEW(s) ;
17461 s^[1] := 1 ;
17462@end smallexample
17463
17464@noindent
17465and you can request that @value{GDBN} describes the type of @code{s}.
17466
17467@smallexample
17468(@value{GDBP}) ptype s
17469type = POINTER TO ARRAY [1..5] OF CARDINAL
17470@end smallexample
17471
17472@value{GDBN} handles compound types as we can see in this example.
17473Here we combine array types, record types, pointer types and subrange
17474types:
17475
17476@smallexample
17477TYPE
17478 foo = RECORD
17479 f1: CARDINAL ;
17480 f2: CHAR ;
17481 f3: myarray ;
17482 END ;
17483
17484 myarray = ARRAY myrange OF CARDINAL ;
17485 myrange = [-2..2] ;
17486VAR
17487 s: POINTER TO ARRAY myrange OF foo ;
17488@end smallexample
17489
17490@noindent
17491and you can ask @value{GDBN} to describe the type of @code{s} as shown
17492below.
17493
17494@smallexample
17495(@value{GDBP}) ptype s
17496type = POINTER TO ARRAY [-2..2] OF foo = RECORD
17497 f1 : CARDINAL;
17498 f2 : CHAR;
17499 f3 : ARRAY [-2..2] OF CARDINAL;
17500END
17501@end smallexample
17502
6d2ebf8b 17503@node M2 Defaults
79a6e687 17504@subsubsection Modula-2 Defaults
c906108c
SS
17505@cindex Modula-2 defaults
17506
17507If type and range checking are set automatically by @value{GDBN}, they
17508both default to @code{on} whenever the working language changes to
d4f3574e 17509Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
17510selected the working language.
17511
17512If you allow @value{GDBN} to set the language automatically, then entering
17513code compiled from a file whose name ends with @file{.mod} sets the
79a6e687
BW
17514working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
17515Infer the Source Language}, for further details.
c906108c 17516
6d2ebf8b 17517@node Deviations
79a6e687 17518@subsubsection Deviations from Standard Modula-2
c906108c
SS
17519@cindex Modula-2, deviations from
17520
17521A few changes have been made to make Modula-2 programs easier to debug.
17522This is done primarily via loosening its type strictness:
17523
17524@itemize @bullet
17525@item
17526Unlike in standard Modula-2, pointer constants can be formed by
17527integers. This allows you to modify pointer variables during
17528debugging. (In standard Modula-2, the actual address contained in a
17529pointer variable is hidden from you; it can only be modified
17530through direct assignment to another pointer variable or expression that
17531returned a pointer.)
17532
17533@item
17534C escape sequences can be used in strings and characters to represent
17535non-printable characters. @value{GDBN} prints out strings with these
17536escape sequences embedded. Single non-printable characters are
17537printed using the @samp{CHR(@var{nnn})} format.
17538
17539@item
17540The assignment operator (@code{:=}) returns the value of its right-hand
17541argument.
17542
17543@item
17544All built-in procedures both modify @emph{and} return their argument.
17545@end itemize
17546
6d2ebf8b 17547@node M2 Checks
79a6e687 17548@subsubsection Modula-2 Type and Range Checks
c906108c
SS
17549@cindex Modula-2 checks
17550
17551@quotation
17552@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
17553range checking.
17554@end quotation
17555@c FIXME remove warning when type/range checks added
17556
17557@value{GDBN} considers two Modula-2 variables type equivalent if:
17558
17559@itemize @bullet
17560@item
17561They are of types that have been declared equivalent via a @code{TYPE
17562@var{t1} = @var{t2}} statement
17563
17564@item
17565They have been declared on the same line. (Note: This is true of the
17566@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
17567@end itemize
17568
17569As long as type checking is enabled, any attempt to combine variables
17570whose types are not equivalent is an error.
17571
17572Range checking is done on all mathematical operations, assignment, array
17573index bounds, and all built-in functions and procedures.
17574
6d2ebf8b 17575@node M2 Scope
79a6e687 17576@subsubsection The Scope Operators @code{::} and @code{.}
c906108c 17577@cindex scope
41afff9a 17578@cindex @code{.}, Modula-2 scope operator
c906108c
SS
17579@cindex colon, doubled as scope operator
17580@ifinfo
41afff9a 17581@vindex colon-colon@r{, in Modula-2}
c906108c
SS
17582@c Info cannot handle :: but TeX can.
17583@end ifinfo
a67ec3f4 17584@ifnotinfo
41afff9a 17585@vindex ::@r{, in Modula-2}
a67ec3f4 17586@end ifnotinfo
c906108c
SS
17587
17588There are a few subtle differences between the Modula-2 scope operator
17589(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
17590similar syntax:
17591
474c8240 17592@smallexample
c906108c
SS
17593
17594@var{module} . @var{id}
17595@var{scope} :: @var{id}
474c8240 17596@end smallexample
c906108c
SS
17597
17598@noindent
17599where @var{scope} is the name of a module or a procedure,
17600@var{module} the name of a module, and @var{id} is any declared
17601identifier within your program, except another module.
17602
17603Using the @code{::} operator makes @value{GDBN} search the scope
17604specified by @var{scope} for the identifier @var{id}. If it is not
17605found in the specified scope, then @value{GDBN} searches all scopes
17606enclosing the one specified by @var{scope}.
17607
17608Using the @code{.} operator makes @value{GDBN} search the current scope for
17609the identifier specified by @var{id} that was imported from the
17610definition module specified by @var{module}. With this operator, it is
17611an error if the identifier @var{id} was not imported from definition
17612module @var{module}, or if @var{id} is not an identifier in
17613@var{module}.
17614
6d2ebf8b 17615@node GDB/M2
c906108c
SS
17616@subsubsection @value{GDBN} and Modula-2
17617
17618Some @value{GDBN} commands have little use when debugging Modula-2 programs.
17619Five subcommands of @code{set print} and @code{show print} apply
b37052ae 17620specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 17621@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 17622apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
17623analogue in Modula-2.
17624
17625The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 17626with any language, is not useful with Modula-2. Its
c906108c 17627intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 17628created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 17629address can be specified by an integral constant, the construct
d4f3574e 17630@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
17631
17632@cindex @code{#} in Modula-2
17633In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
17634interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 17635
e07c999f
PH
17636@node Ada
17637@subsection Ada
17638@cindex Ada
17639
17640The extensions made to @value{GDBN} for Ada only support
17641output from the @sc{gnu} Ada (GNAT) compiler.
17642Other Ada compilers are not currently supported, and
17643attempting to debug executables produced by them is most likely
17644to be difficult.
17645
17646
17647@cindex expressions in Ada
17648@menu
17649* Ada Mode Intro:: General remarks on the Ada syntax
17650 and semantics supported by Ada mode
17651 in @value{GDBN}.
17652* Omissions from Ada:: Restrictions on the Ada expression syntax.
17653* Additions to Ada:: Extensions of the Ada expression syntax.
3685b09f
PMR
17654* Overloading support for Ada:: Support for expressions involving overloaded
17655 subprograms.
e07c999f 17656* Stopping Before Main Program:: Debugging the program during elaboration.
58d06528 17657* Ada Exceptions:: Ada Exceptions
20924a55
JB
17658* Ada Tasks:: Listing and setting breakpoints in tasks.
17659* Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
6e1bb179
JB
17660* Ravenscar Profile:: Tasking Support when using the Ravenscar
17661 Profile
3fcded8f 17662* Ada Settings:: New settable GDB parameters for Ada.
e07c999f
PH
17663* Ada Glitches:: Known peculiarities of Ada mode.
17664@end menu
17665
17666@node Ada Mode Intro
17667@subsubsection Introduction
17668@cindex Ada mode, general
17669
17670The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
17671syntax, with some extensions.
17672The philosophy behind the design of this subset is
17673
17674@itemize @bullet
17675@item
17676That @value{GDBN} should provide basic literals and access to operations for
17677arithmetic, dereferencing, field selection, indexing, and subprogram calls,
17678leaving more sophisticated computations to subprograms written into the
17679program (which therefore may be called from @value{GDBN}).
17680
17681@item
17682That type safety and strict adherence to Ada language restrictions
17683are not particularly important to the @value{GDBN} user.
17684
17685@item
17686That brevity is important to the @value{GDBN} user.
17687@end itemize
17688
f3a2dd1a
JB
17689Thus, for brevity, the debugger acts as if all names declared in
17690user-written packages are directly visible, even if they are not visible
17691according to Ada rules, thus making it unnecessary to fully qualify most
17692names with their packages, regardless of context. Where this causes
17693ambiguity, @value{GDBN} asks the user's intent.
e07c999f
PH
17694
17695The debugger will start in Ada mode if it detects an Ada main program.
17696As for other languages, it will enter Ada mode when stopped in a program that
17697was translated from an Ada source file.
17698
17699While in Ada mode, you may use `@t{--}' for comments. This is useful
17700mostly for documenting command files. The standard @value{GDBN} comment
17701(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
17702middle (to allow based literals).
17703
e07c999f
PH
17704@node Omissions from Ada
17705@subsubsection Omissions from Ada
17706@cindex Ada, omissions from
17707
17708Here are the notable omissions from the subset:
17709
17710@itemize @bullet
17711@item
17712Only a subset of the attributes are supported:
17713
17714@itemize @minus
17715@item
17716@t{'First}, @t{'Last}, and @t{'Length}
17717 on array objects (not on types and subtypes).
17718
17719@item
17720@t{'Min} and @t{'Max}.
17721
17722@item
17723@t{'Pos} and @t{'Val}.
17724
17725@item
17726@t{'Tag}.
17727
17728@item
17729@t{'Range} on array objects (not subtypes), but only as the right
17730operand of the membership (@code{in}) operator.
17731
17732@item
17733@t{'Access}, @t{'Unchecked_Access}, and
17734@t{'Unrestricted_Access} (a GNAT extension).
17735
17736@item
17737@t{'Address}.
17738@end itemize
17739
17740@item
17741The names in
17742@code{Characters.Latin_1} are not available and
17743concatenation is not implemented. Thus, escape characters in strings are
17744not currently available.
17745
17746@item
17747Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
17748equality of representations. They will generally work correctly
17749for strings and arrays whose elements have integer or enumeration types.
17750They may not work correctly for arrays whose element
17751types have user-defined equality, for arrays of real values
17752(in particular, IEEE-conformant floating point, because of negative
17753zeroes and NaNs), and for arrays whose elements contain unused bits with
17754indeterminate values.
17755
17756@item
17757The other component-by-component array operations (@code{and}, @code{or},
17758@code{xor}, @code{not}, and relational tests other than equality)
17759are not implemented.
17760
17761@item
860701dc
PH
17762@cindex array aggregates (Ada)
17763@cindex record aggregates (Ada)
17764@cindex aggregates (Ada)
17765There is limited support for array and record aggregates. They are
17766permitted only on the right sides of assignments, as in these examples:
17767
17768@smallexample
077e0a52
JB
17769(@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
17770(@value{GDBP}) set An_Array := (1, others => 0)
17771(@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
17772(@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
17773(@value{GDBP}) set A_Record := (1, "Peter", True);
17774(@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
860701dc
PH
17775@end smallexample
17776
17777Changing a
17778discriminant's value by assigning an aggregate has an
17779undefined effect if that discriminant is used within the record.
17780However, you can first modify discriminants by directly assigning to
17781them (which normally would not be allowed in Ada), and then performing an
17782aggregate assignment. For example, given a variable @code{A_Rec}
17783declared to have a type such as:
17784
17785@smallexample
17786type Rec (Len : Small_Integer := 0) is record
17787 Id : Integer;
17788 Vals : IntArray (1 .. Len);
17789end record;
17790@end smallexample
17791
17792you can assign a value with a different size of @code{Vals} with two
17793assignments:
17794
17795@smallexample
077e0a52
JB
17796(@value{GDBP}) set A_Rec.Len := 4
17797(@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
860701dc
PH
17798@end smallexample
17799
17800As this example also illustrates, @value{GDBN} is very loose about the usual
17801rules concerning aggregates. You may leave out some of the
17802components of an array or record aggregate (such as the @code{Len}
17803component in the assignment to @code{A_Rec} above); they will retain their
17804original values upon assignment. You may freely use dynamic values as
17805indices in component associations. You may even use overlapping or
17806redundant component associations, although which component values are
17807assigned in such cases is not defined.
e07c999f
PH
17808
17809@item
17810Calls to dispatching subprograms are not implemented.
17811
17812@item
17813The overloading algorithm is much more limited (i.e., less selective)
ae21e955
BW
17814than that of real Ada. It makes only limited use of the context in
17815which a subexpression appears to resolve its meaning, and it is much
17816looser in its rules for allowing type matches. As a result, some
17817function calls will be ambiguous, and the user will be asked to choose
17818the proper resolution.
e07c999f
PH
17819
17820@item
17821The @code{new} operator is not implemented.
17822
17823@item
17824Entry calls are not implemented.
17825
17826@item
17827Aside from printing, arithmetic operations on the native VAX floating-point
17828formats are not supported.
17829
17830@item
17831It is not possible to slice a packed array.
158c7665
PH
17832
17833@item
17834The names @code{True} and @code{False}, when not part of a qualified name,
17835are interpreted as if implicitly prefixed by @code{Standard}, regardless of
17836context.
17837Should your program
17838redefine these names in a package or procedure (at best a dubious practice),
17839you will have to use fully qualified names to access their new definitions.
e07c999f
PH
17840@end itemize
17841
17842@node Additions to Ada
17843@subsubsection Additions to Ada
17844@cindex Ada, deviations from
17845
17846As it does for other languages, @value{GDBN} makes certain generic
17847extensions to Ada (@pxref{Expressions}):
17848
17849@itemize @bullet
17850@item
ae21e955
BW
17851If the expression @var{E} is a variable residing in memory (typically
17852a local variable or array element) and @var{N} is a positive integer,
17853then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
17854@var{N}-1 adjacent variables following it in memory as an array. In
17855Ada, this operator is generally not necessary, since its prime use is
17856in displaying parts of an array, and slicing will usually do this in
17857Ada. However, there are occasional uses when debugging programs in
17858which certain debugging information has been optimized away.
e07c999f
PH
17859
17860@item
ae21e955
BW
17861@code{@var{B}::@var{var}} means ``the variable named @var{var} that
17862appears in function or file @var{B}.'' When @var{B} is a file name,
17863you must typically surround it in single quotes.
e07c999f
PH
17864
17865@item
17866The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
17867@var{type} that appears at address @var{addr}.''
17868
17869@item
17870A name starting with @samp{$} is a convenience variable
17871(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
17872@end itemize
17873
ae21e955
BW
17874In addition, @value{GDBN} provides a few other shortcuts and outright
17875additions specific to Ada:
e07c999f
PH
17876
17877@itemize @bullet
17878@item
17879The assignment statement is allowed as an expression, returning
17880its right-hand operand as its value. Thus, you may enter
17881
17882@smallexample
077e0a52
JB
17883(@value{GDBP}) set x := y + 3
17884(@value{GDBP}) print A(tmp := y + 1)
e07c999f
PH
17885@end smallexample
17886
17887@item
17888The semicolon is allowed as an ``operator,'' returning as its value
17889the value of its right-hand operand.
17890This allows, for example,
17891complex conditional breaks:
17892
17893@smallexample
077e0a52
JB
17894(@value{GDBP}) break f
17895(@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
e07c999f
PH
17896@end smallexample
17897
17898@item
17899Rather than use catenation and symbolic character names to introduce special
17900characters into strings, one may instead use a special bracket notation,
17901which is also used to print strings. A sequence of characters of the form
17902@samp{["@var{XX}"]} within a string or character literal denotes the
17903(single) character whose numeric encoding is @var{XX} in hexadecimal. The
17904sequence of characters @samp{["""]} also denotes a single quotation mark
17905in strings. For example,
17906@smallexample
17907 "One line.["0a"]Next line.["0a"]"
17908@end smallexample
17909@noindent
ae21e955
BW
17910contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
17911after each period.
e07c999f
PH
17912
17913@item
17914The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
17915@t{'Max} is optional (and is ignored in any case). For example, it is valid
17916to write
17917
17918@smallexample
077e0a52 17919(@value{GDBP}) print 'max(x, y)
e07c999f
PH
17920@end smallexample
17921
17922@item
17923When printing arrays, @value{GDBN} uses positional notation when the
17924array has a lower bound of 1, and uses a modified named notation otherwise.
ae21e955
BW
17925For example, a one-dimensional array of three integers with a lower bound
17926of 3 might print as
e07c999f
PH
17927
17928@smallexample
17929(3 => 10, 17, 1)
17930@end smallexample
17931
17932@noindent
17933That is, in contrast to valid Ada, only the first component has a @code{=>}
17934clause.
17935
17936@item
17937You may abbreviate attributes in expressions with any unique,
17938multi-character subsequence of
17939their names (an exact match gets preference).
17940For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
17941in place of @t{a'length}.
17942
17943@item
17944@cindex quoting Ada internal identifiers
17945Since Ada is case-insensitive, the debugger normally maps identifiers you type
17946to lower case. The GNAT compiler uses upper-case characters for
17947some of its internal identifiers, which are normally of no interest to users.
17948For the rare occasions when you actually have to look at them,
17949enclose them in angle brackets to avoid the lower-case mapping.
17950For example,
17951@smallexample
077e0a52 17952(@value{GDBP}) print <JMPBUF_SAVE>[0]
e07c999f
PH
17953@end smallexample
17954
17955@item
17956Printing an object of class-wide type or dereferencing an
17957access-to-class-wide value will display all the components of the object's
17958specific type (as indicated by its run-time tag). Likewise, component
17959selection on such a value will operate on the specific type of the
17960object.
17961
17962@end itemize
17963
3685b09f
PMR
17964@node Overloading support for Ada
17965@subsubsection Overloading support for Ada
17966@cindex overloading, Ada
17967
17968The debugger supports limited overloading. Given a subprogram call in which
17969the function symbol has multiple definitions, it will use the number of
17970actual parameters and some information about their types to attempt to narrow
17971the set of definitions. It also makes very limited use of context, preferring
17972procedures to functions in the context of the @code{call} command, and
17973functions to procedures elsewhere.
17974
17975If, after narrowing, the set of matching definitions still contains more than
17976one definition, @value{GDBN} will display a menu to query which one it should
17977use, for instance:
17978
17979@smallexample
17980(@value{GDBP}) print f(1)
17981Multiple matches for f
17982[0] cancel
17983[1] foo.f (integer) return boolean at foo.adb:23
17984[2] foo.f (foo.new_integer) return boolean at foo.adb:28
17985>
17986@end smallexample
17987
17988In this case, just select one menu entry either to cancel expression evaluation
17989(type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
17990instance (type the corresponding number and press @key{RET}).
17991
17992Here are a couple of commands to customize @value{GDBN}'s behavior in this
17993case:
17994
17995@table @code
17996
17997@kindex set ada print-signatures
17998@item set ada print-signatures
17999Control whether parameter types and return types are displayed in overloads
18000selection menus. It is @code{on} by default.
18001@xref{Overloading support for Ada}.
18002
18003@kindex show ada print-signatures
18004@item show ada print-signatures
18005Show the current setting for displaying parameter types and return types in
18006overloads selection menu.
18007@xref{Overloading support for Ada}.
18008
18009@end table
18010
e07c999f
PH
18011@node Stopping Before Main Program
18012@subsubsection Stopping at the Very Beginning
18013
18014@cindex breakpointing Ada elaboration code
18015It is sometimes necessary to debug the program during elaboration, and
18016before reaching the main procedure.
18017As defined in the Ada Reference
18018Manual, the elaboration code is invoked from a procedure called
18019@code{adainit}. To run your program up to the beginning of
18020elaboration, simply use the following two commands:
18021@code{tbreak adainit} and @code{run}.
18022
58d06528
JB
18023@node Ada Exceptions
18024@subsubsection Ada Exceptions
18025
18026A command is provided to list all Ada exceptions:
18027
18028@table @code
18029@kindex info exceptions
18030@item info exceptions
18031@itemx info exceptions @var{regexp}
18032The @code{info exceptions} command allows you to list all Ada exceptions
18033defined within the program being debugged, as well as their addresses.
18034With a regular expression, @var{regexp}, as argument, only those exceptions
18035whose names match @var{regexp} are listed.
18036@end table
18037
18038Below is a small example, showing how the command can be used, first
18039without argument, and next with a regular expression passed as an
18040argument.
18041
18042@smallexample
18043(@value{GDBP}) info exceptions
18044All defined Ada exceptions:
18045constraint_error: 0x613da0
18046program_error: 0x613d20
18047storage_error: 0x613ce0
18048tasking_error: 0x613ca0
18049const.aint_global_e: 0x613b00
18050(@value{GDBP}) info exceptions const.aint
18051All Ada exceptions matching regular expression "const.aint":
18052constraint_error: 0x613da0
18053const.aint_global_e: 0x613b00
18054@end smallexample
18055
18056It is also possible to ask @value{GDBN} to stop your program's execution
18057when an exception is raised. For more details, see @ref{Set Catchpoints}.
18058
20924a55
JB
18059@node Ada Tasks
18060@subsubsection Extensions for Ada Tasks
18061@cindex Ada, tasking
18062
18063Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
18064@value{GDBN} provides the following task-related commands:
18065
18066@table @code
18067@kindex info tasks
18068@item info tasks
18069This command shows a list of current Ada tasks, as in the following example:
18070
18071
18072@smallexample
18073@iftex
18074@leftskip=0.5cm
18075@end iftex
18076(@value{GDBP}) info tasks
18077 ID TID P-ID Pri State Name
18078 1 8088000 0 15 Child Activation Wait main_task
18079 2 80a4000 1 15 Accept Statement b
18080 3 809a800 1 15 Child Activation Wait a
32cd1edc 18081* 4 80ae800 3 15 Runnable c
20924a55
JB
18082
18083@end smallexample
18084
18085@noindent
18086In this listing, the asterisk before the last task indicates it to be the
18087task currently being inspected.
18088
18089@table @asis
18090@item ID
18091Represents @value{GDBN}'s internal task number.
18092
18093@item TID
18094The Ada task ID.
18095
18096@item P-ID
18097The parent's task ID (@value{GDBN}'s internal task number).
18098
18099@item Pri
18100The base priority of the task.
18101
18102@item State
18103Current state of the task.
18104
18105@table @code
18106@item Unactivated
18107The task has been created but has not been activated. It cannot be
18108executing.
18109
20924a55
JB
18110@item Runnable
18111The task is not blocked for any reason known to Ada. (It may be waiting
18112for a mutex, though.) It is conceptually "executing" in normal mode.
18113
18114@item Terminated
18115The task is terminated, in the sense of ARM 9.3 (5). Any dependents
18116that were waiting on terminate alternatives have been awakened and have
18117terminated themselves.
18118
18119@item Child Activation Wait
18120The task is waiting for created tasks to complete activation.
18121
18122@item Accept Statement
18123The task is waiting on an accept or selective wait statement.
18124
18125@item Waiting on entry call
18126The task is waiting on an entry call.
18127
18128@item Async Select Wait
18129The task is waiting to start the abortable part of an asynchronous
18130select statement.
18131
18132@item Delay Sleep
18133The task is waiting on a select statement with only a delay
18134alternative open.
18135
18136@item Child Termination Wait
18137The task is sleeping having completed a master within itself, and is
18138waiting for the tasks dependent on that master to become terminated or
18139waiting on a terminate Phase.
18140
18141@item Wait Child in Term Alt
18142The task is sleeping waiting for tasks on terminate alternatives to
18143finish terminating.
18144
18145@item Accepting RV with @var{taskno}
18146The task is accepting a rendez-vous with the task @var{taskno}.
18147@end table
18148
18149@item Name
18150Name of the task in the program.
18151
18152@end table
18153
18154@kindex info task @var{taskno}
18155@item info task @var{taskno}
6b92c0d3 18156This command shows detailed informations on the specified task, as in
20924a55
JB
18157the following example:
18158@smallexample
18159@iftex
18160@leftskip=0.5cm
18161@end iftex
18162(@value{GDBP}) info tasks
18163 ID TID P-ID Pri State Name
18164 1 8077880 0 15 Child Activation Wait main_task
32cd1edc 18165* 2 807c468 1 15 Runnable task_1
20924a55
JB
18166(@value{GDBP}) info task 2
18167Ada Task: 0x807c468
4993045d 18168Name: "task_1"
87f7ab7b
JB
18169Thread: 0
18170LWP: 0x1fac
4993045d 18171Parent: 1 ("main_task")
20924a55
JB
18172Base Priority: 15
18173State: Runnable
18174@end smallexample
18175
18176@item task
18177@kindex task@r{ (Ada)}
18178@cindex current Ada task ID
4993045d 18179This command prints the ID and name of the current task.
20924a55
JB
18180
18181@smallexample
18182@iftex
18183@leftskip=0.5cm
18184@end iftex
18185(@value{GDBP}) info tasks
18186 ID TID P-ID Pri State Name
18187 1 8077870 0 15 Child Activation Wait main_task
4993045d 18188* 2 807c458 1 15 Runnable some_task
20924a55 18189(@value{GDBP}) task
4993045d 18190[Current task is 2 "some_task"]
20924a55
JB
18191@end smallexample
18192
18193@item task @var{taskno}
18194@cindex Ada task switching
5d5658a1 18195This command is like the @code{thread @var{thread-id}}
20924a55
JB
18196command (@pxref{Threads}). It switches the context of debugging
18197from the current task to the given task.
18198
18199@smallexample
18200@iftex
18201@leftskip=0.5cm
18202@end iftex
18203(@value{GDBP}) info tasks
18204 ID TID P-ID Pri State Name
18205 1 8077870 0 15 Child Activation Wait main_task
4993045d 18206* 2 807c458 1 15 Runnable some_task
20924a55 18207(@value{GDBP}) task 1
4993045d 18208[Switching to task 1 "main_task"]
20924a55
JB
18209#0 0x8067726 in pthread_cond_wait ()
18210(@value{GDBP}) bt
18211#0 0x8067726 in pthread_cond_wait ()
18212#1 0x8056714 in system.os_interface.pthread_cond_wait ()
18213#2 0x805cb63 in system.task_primitives.operations.sleep ()
18214#3 0x806153e in system.tasking.stages.activate_tasks ()
18215#4 0x804aacc in un () at un.adb:5
18216@end smallexample
18217
629500fa
KS
18218@item break @var{location} task @var{taskno}
18219@itemx break @var{location} task @var{taskno} if @dots{}
45ac276d
JB
18220@cindex breakpoints and tasks, in Ada
18221@cindex task breakpoints, in Ada
18222@kindex break @dots{} task @var{taskno}@r{ (Ada)}
18223These commands are like the @code{break @dots{} thread @dots{}}
697aa1b7 18224command (@pxref{Thread Stops}). The
629500fa 18225@var{location} argument specifies source lines, as described
45ac276d
JB
18226in @ref{Specify Location}.
18227
18228Use the qualifier @samp{task @var{taskno}} with a breakpoint command
18229to specify that you only want @value{GDBN} to stop the program when a
697aa1b7 18230particular Ada task reaches this breakpoint. The @var{taskno} is one of the
45ac276d
JB
18231numeric task identifiers assigned by @value{GDBN}, shown in the first
18232column of the @samp{info tasks} display.
18233
18234If you do not specify @samp{task @var{taskno}} when you set a
18235breakpoint, the breakpoint applies to @emph{all} tasks of your
18236program.
18237
18238You can use the @code{task} qualifier on conditional breakpoints as
18239well; in this case, place @samp{task @var{taskno}} before the
18240breakpoint condition (before the @code{if}).
18241
18242For example,
18243
18244@smallexample
18245@iftex
18246@leftskip=0.5cm
18247@end iftex
18248(@value{GDBP}) info tasks
18249 ID TID P-ID Pri State Name
18250 1 140022020 0 15 Child Activation Wait main_task
18251 2 140045060 1 15 Accept/Select Wait t2
18252 3 140044840 1 15 Runnable t1
18253* 4 140056040 1 15 Runnable t3
18254(@value{GDBP}) b 15 task 2
18255Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
18256(@value{GDBP}) cont
18257Continuing.
18258task # 1 running
18259task # 2 running
18260
18261Breakpoint 5, test_task_debug () at test_task_debug.adb:15
1826215 flush;
18263(@value{GDBP}) info tasks
18264 ID TID P-ID Pri State Name
18265 1 140022020 0 15 Child Activation Wait main_task
18266* 2 140045060 1 15 Runnable t2
18267 3 140044840 1 15 Runnable t1
18268 4 140056040 1 15 Delay Sleep t3
18269@end smallexample
20924a55
JB
18270@end table
18271
18272@node Ada Tasks and Core Files
18273@subsubsection Tasking Support when Debugging Core Files
18274@cindex Ada tasking and core file debugging
18275
18276When inspecting a core file, as opposed to debugging a live program,
18277tasking support may be limited or even unavailable, depending on
18278the platform being used.
18279For instance, on x86-linux, the list of tasks is available, but task
32a8097b 18280switching is not supported.
20924a55 18281
32a8097b 18282On certain platforms, the debugger needs to perform some
20924a55
JB
18283memory writes in order to provide Ada tasking support. When inspecting
18284a core file, this means that the core file must be opened with read-write
18285privileges, using the command @samp{"set write on"} (@pxref{Patching}).
18286Under these circumstances, you should make a backup copy of the core
18287file before inspecting it with @value{GDBN}.
18288
6e1bb179
JB
18289@node Ravenscar Profile
18290@subsubsection Tasking Support when using the Ravenscar Profile
18291@cindex Ravenscar Profile
18292
18293The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
18294specifically designed for systems with safety-critical real-time
18295requirements.
18296
18297@table @code
18298@kindex set ravenscar task-switching on
18299@cindex task switching with program using Ravenscar Profile
18300@item set ravenscar task-switching on
18301Allows task switching when debugging a program that uses the Ravenscar
18302Profile. This is the default.
18303
18304@kindex set ravenscar task-switching off
18305@item set ravenscar task-switching off
18306Turn off task switching when debugging a program that uses the Ravenscar
18307Profile. This is mostly intended to disable the code that adds support
18308for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
18309the Ravenscar runtime is preventing @value{GDBN} from working properly.
18310To be effective, this command should be run before the program is started.
18311
18312@kindex show ravenscar task-switching
18313@item show ravenscar task-switching
18314Show whether it is possible to switch from task to task in a program
18315using the Ravenscar Profile.
18316
18317@end table
18318
3fcded8f
JB
18319@node Ada Settings
18320@subsubsection Ada Settings
18321@cindex Ada settings
18322
18323@table @code
18324@kindex set varsize-limit
18325@item set varsize-limit @var{size}
18326Prevent @value{GDBN} from attempting to evaluate objects whose size
18327is above the given limit (@var{size}) when those sizes are computed
18328from run-time quantities. This is typically the case when the object
18329has a variable size, such as an array whose bounds are not known at
18330compile time for example. Setting @var{size} to @code{unlimited}
18331removes the size limitation. By default, the limit is about 65KB.
18332
18333The purpose of having such a limit is to prevent @value{GDBN} from
18334trying to grab enormous chunks of virtual memory when asked to evaluate
18335a quantity whose bounds have been corrupted or have not yet been fully
18336initialized. The limit applies to the results of some subexpressions
18337as well as to complete expressions. For example, an expression denoting
18338a simple integer component, such as @code{x.y.z}, may fail if the size of
18339@code{x.y} is variable and exceeds @code{size}. On the other hand,
18340@value{GDBN} is sometimes clever; the expression @code{A(i)}, where
18341@code{A} is an array variable with non-constant size, will generally
18342succeed regardless of the bounds on @code{A}, as long as the component
18343size is less than @var{size}.
18344
18345@kindex show varsize-limit
18346@item show varsize-limit
18347Show the limit on types whose size is determined by run-time quantities.
18348@end table
18349
e07c999f
PH
18350@node Ada Glitches
18351@subsubsection Known Peculiarities of Ada Mode
18352@cindex Ada, problems
18353
18354Besides the omissions listed previously (@pxref{Omissions from Ada}),
18355we know of several problems with and limitations of Ada mode in
18356@value{GDBN},
18357some of which will be fixed with planned future releases of the debugger
18358and the GNU Ada compiler.
18359
18360@itemize @bullet
e07c999f
PH
18361@item
18362Static constants that the compiler chooses not to materialize as objects in
18363storage are invisible to the debugger.
18364
18365@item
18366Named parameter associations in function argument lists are ignored (the
18367argument lists are treated as positional).
18368
18369@item
18370Many useful library packages are currently invisible to the debugger.
18371
18372@item
18373Fixed-point arithmetic, conversions, input, and output is carried out using
18374floating-point arithmetic, and may give results that only approximate those on
18375the host machine.
18376
e07c999f
PH
18377@item
18378The GNAT compiler never generates the prefix @code{Standard} for any of
18379the standard symbols defined by the Ada language. @value{GDBN} knows about
18380this: it will strip the prefix from names when you use it, and will never
18381look for a name you have so qualified among local symbols, nor match against
18382symbols in other packages or subprograms. If you have
18383defined entities anywhere in your program other than parameters and
18384local variables whose simple names match names in @code{Standard},
18385GNAT's lack of qualification here can cause confusion. When this happens,
18386you can usually resolve the confusion
18387by qualifying the problematic names with package
18388@code{Standard} explicitly.
18389@end itemize
18390
95433b34
JB
18391Older versions of the compiler sometimes generate erroneous debugging
18392information, resulting in the debugger incorrectly printing the value
18393of affected entities. In some cases, the debugger is able to work
18394around an issue automatically. In other cases, the debugger is able
18395to work around the issue, but the work-around has to be specifically
18396enabled.
18397
18398@kindex set ada trust-PAD-over-XVS
18399@kindex show ada trust-PAD-over-XVS
18400@table @code
18401
18402@item set ada trust-PAD-over-XVS on
18403Configure GDB to strictly follow the GNAT encoding when computing the
18404value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
18405types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
18406a complete description of the encoding used by the GNAT compiler).
18407This is the default.
18408
18409@item set ada trust-PAD-over-XVS off
18410This is related to the encoding using by the GNAT compiler. If @value{GDBN}
18411sometimes prints the wrong value for certain entities, changing @code{ada
18412trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
18413the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
18414@code{off}, but this incurs a slight performance penalty, so it is
18415recommended to leave this setting to @code{on} unless necessary.
18416
18417@end table
18418
c6044dd1
JB
18419@cindex GNAT descriptive types
18420@cindex GNAT encoding
18421Internally, the debugger also relies on the compiler following a number
18422of conventions known as the @samp{GNAT Encoding}, all documented in
18423@file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
18424how the debugging information should be generated for certain types.
18425In particular, this convention makes use of @dfn{descriptive types},
18426which are artificial types generated purely to help the debugger.
18427
18428These encodings were defined at a time when the debugging information
18429format used was not powerful enough to describe some of the more complex
18430types available in Ada. Since DWARF allows us to express nearly all
18431Ada features, the long-term goal is to slowly replace these descriptive
18432types by their pure DWARF equivalent. To facilitate that transition,
18433a new maintenance option is available to force the debugger to ignore
18434those descriptive types. It allows the user to quickly evaluate how
18435well @value{GDBN} works without them.
18436
18437@table @code
18438
18439@kindex maint ada set ignore-descriptive-types
18440@item maintenance ada set ignore-descriptive-types [on|off]
18441Control whether the debugger should ignore descriptive types.
18442The default is not to ignore descriptives types (@code{off}).
18443
18444@kindex maint ada show ignore-descriptive-types
18445@item maintenance ada show ignore-descriptive-types
18446Show if descriptive types are ignored by @value{GDBN}.
18447
18448@end table
18449
79a6e687
BW
18450@node Unsupported Languages
18451@section Unsupported Languages
4e562065
JB
18452
18453@cindex unsupported languages
18454@cindex minimal language
18455In addition to the other fully-supported programming languages,
18456@value{GDBN} also provides a pseudo-language, called @code{minimal}.
18457It does not represent a real programming language, but provides a set
18458of capabilities close to what the C or assembly languages provide.
18459This should allow most simple operations to be performed while debugging
18460an application that uses a language currently not supported by @value{GDBN}.
18461
18462If the language is set to @code{auto}, @value{GDBN} will automatically
18463select this language if the current frame corresponds to an unsupported
18464language.
18465
6d2ebf8b 18466@node Symbols
c906108c
SS
18467@chapter Examining the Symbol Table
18468
d4f3574e 18469The commands described in this chapter allow you to inquire about the
c906108c
SS
18470symbols (names of variables, functions and types) defined in your
18471program. This information is inherent in the text of your program and
18472does not change as your program executes. @value{GDBN} finds it in your
18473program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
18474(@pxref{File Options, ,Choosing Files}), or by one of the
18475file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
18476
18477@cindex symbol names
18478@cindex names of symbols
18479@cindex quoting names
d044bac8 18480@anchor{quoting names}
c906108c
SS
18481Occasionally, you may need to refer to symbols that contain unusual
18482characters, which @value{GDBN} ordinarily treats as word delimiters. The
18483most frequent case is in referring to static variables in other
79a6e687 18484source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
18485are recorded in object files as debugging symbols, but @value{GDBN} would
18486ordinarily parse a typical file name, like @file{foo.c}, as the three words
18487@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
18488@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
18489
474c8240 18490@smallexample
c906108c 18491p 'foo.c'::x
474c8240 18492@end smallexample
c906108c
SS
18493
18494@noindent
18495looks up the value of @code{x} in the scope of the file @file{foo.c}.
18496
18497@table @code
a8f24a35
EZ
18498@cindex case-insensitive symbol names
18499@cindex case sensitivity in symbol names
18500@kindex set case-sensitive
18501@item set case-sensitive on
18502@itemx set case-sensitive off
18503@itemx set case-sensitive auto
18504Normally, when @value{GDBN} looks up symbols, it matches their names
18505with case sensitivity determined by the current source language.
18506Occasionally, you may wish to control that. The command @code{set
18507case-sensitive} lets you do that by specifying @code{on} for
18508case-sensitive matches or @code{off} for case-insensitive ones. If
18509you specify @code{auto}, case sensitivity is reset to the default
18510suitable for the source language. The default is case-sensitive
18511matches for all languages except for Fortran, for which the default is
18512case-insensitive matches.
18513
9c16f35a
EZ
18514@kindex show case-sensitive
18515@item show case-sensitive
a8f24a35
EZ
18516This command shows the current setting of case sensitivity for symbols
18517lookups.
18518
53342f27
TT
18519@kindex set print type methods
18520@item set print type methods
18521@itemx set print type methods on
18522@itemx set print type methods off
18523Normally, when @value{GDBN} prints a class, it displays any methods
18524declared in that class. You can control this behavior either by
18525passing the appropriate flag to @code{ptype}, or using @command{set
18526print type methods}. Specifying @code{on} will cause @value{GDBN} to
18527display the methods; this is the default. Specifying @code{off} will
18528cause @value{GDBN} to omit the methods.
18529
18530@kindex show print type methods
18531@item show print type methods
18532This command shows the current setting of method display when printing
18533classes.
18534
883fd55a
KS
18535@kindex set print type nested-type-limit
18536@item set print type nested-type-limit @var{limit}
18537@itemx set print type nested-type-limit unlimited
18538Set the limit of displayed nested types that the type printer will
18539show. A @var{limit} of @code{unlimited} or @code{-1} will show all
18540nested definitions. By default, the type printer will not show any nested
18541types defined in classes.
18542
18543@kindex show print type nested-type-limit
18544@item show print type nested-type-limit
18545This command shows the current display limit of nested types when
18546printing classes.
18547
53342f27
TT
18548@kindex set print type typedefs
18549@item set print type typedefs
18550@itemx set print type typedefs on
18551@itemx set print type typedefs off
18552
18553Normally, when @value{GDBN} prints a class, it displays any typedefs
18554defined in that class. You can control this behavior either by
18555passing the appropriate flag to @code{ptype}, or using @command{set
18556print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
18557display the typedef definitions; this is the default. Specifying
18558@code{off} will cause @value{GDBN} to omit the typedef definitions.
18559Note that this controls whether the typedef definition itself is
18560printed, not whether typedef names are substituted when printing other
18561types.
18562
18563@kindex show print type typedefs
18564@item show print type typedefs
18565This command shows the current setting of typedef display when
18566printing classes.
18567
c906108c 18568@kindex info address
b37052ae 18569@cindex address of a symbol
c906108c
SS
18570@item info address @var{symbol}
18571Describe where the data for @var{symbol} is stored. For a register
18572variable, this says which register it is kept in. For a non-register
18573local variable, this prints the stack-frame offset at which the variable
18574is always stored.
18575
18576Note the contrast with @samp{print &@var{symbol}}, which does not work
18577at all for a register variable, and for a stack local variable prints
18578the exact address of the current instantiation of the variable.
18579
3d67e040 18580@kindex info symbol
b37052ae 18581@cindex symbol from address
9c16f35a 18582@cindex closest symbol and offset for an address
3d67e040
EZ
18583@item info symbol @var{addr}
18584Print the name of a symbol which is stored at the address @var{addr}.
18585If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
18586nearest symbol and an offset from it:
18587
474c8240 18588@smallexample
3d67e040
EZ
18589(@value{GDBP}) info symbol 0x54320
18590_initialize_vx + 396 in section .text
474c8240 18591@end smallexample
3d67e040
EZ
18592
18593@noindent
18594This is the opposite of the @code{info address} command. You can use
18595it to find out the name of a variable or a function given its address.
18596
c14c28ba
PP
18597For dynamically linked executables, the name of executable or shared
18598library containing the symbol is also printed:
18599
18600@smallexample
18601(@value{GDBP}) info symbol 0x400225
18602_start + 5 in section .text of /tmp/a.out
18603(@value{GDBP}) info symbol 0x2aaaac2811cf
18604__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
18605@end smallexample
18606
439250fb
DE
18607@kindex demangle
18608@cindex demangle
18609@item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
18610Demangle @var{name}.
18611If @var{language} is provided it is the name of the language to demangle
18612@var{name} in. Otherwise @var{name} is demangled in the current language.
18613
18614The @samp{--} option specifies the end of options,
18615and is useful when @var{name} begins with a dash.
18616
18617The parameter @code{demangle-style} specifies how to interpret the kind
18618of mangling used. @xref{Print Settings}.
18619
c906108c 18620@kindex whatis
53342f27 18621@item whatis[/@var{flags}] [@var{arg}]
177bc839
JK
18622Print the data type of @var{arg}, which can be either an expression
18623or a name of a data type. With no argument, print the data type of
18624@code{$}, the last value in the value history.
18625
18626If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
18627is not actually evaluated, and any side-effecting operations (such as
18628assignments or function calls) inside it do not take place.
18629
18630If @var{arg} is a variable or an expression, @code{whatis} prints its
18631literal type as it is used in the source code. If the type was
18632defined using a @code{typedef}, @code{whatis} will @emph{not} print
18633the data type underlying the @code{typedef}. If the type of the
18634variable or the expression is a compound data type, such as
18635@code{struct} or @code{class}, @code{whatis} never prints their
18636fields or methods. It just prints the @code{struct}/@code{class}
18637name (a.k.a.@: its @dfn{tag}). If you want to see the members of
18638such a compound data type, use @code{ptype}.
18639
18640If @var{arg} is a type name that was defined using @code{typedef},
18641@code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
18642Unrolling means that @code{whatis} will show the underlying type used
18643in the @code{typedef} declaration of @var{arg}. However, if that
18644underlying type is also a @code{typedef}, @code{whatis} will not
18645unroll it.
18646
18647For C code, the type names may also have the form @samp{class
18648@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
18649@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 18650
53342f27
TT
18651@var{flags} can be used to modify how the type is displayed.
18652Available flags are:
18653
18654@table @code
18655@item r
18656Display in ``raw'' form. Normally, @value{GDBN} substitutes template
18657parameters and typedefs defined in a class when printing the class'
18658members. The @code{/r} flag disables this.
18659
18660@item m
18661Do not print methods defined in the class.
18662
18663@item M
18664Print methods defined in the class. This is the default, but the flag
18665exists in case you change the default with @command{set print type methods}.
18666
18667@item t
18668Do not print typedefs defined in the class. Note that this controls
18669whether the typedef definition itself is printed, not whether typedef
18670names are substituted when printing other types.
18671
18672@item T
18673Print typedefs defined in the class. This is the default, but the flag
18674exists in case you change the default with @command{set print type typedefs}.
7c161838
SDJ
18675
18676@item o
18677Print the offsets and sizes of fields in a struct, similar to what the
18678@command{pahole} tool does. This option implies the @code{/tm} flags.
18679
18680For example, given the following declarations:
18681
18682@smallexample
18683struct tuv
18684@{
18685 int a1;
18686 char *a2;
18687 int a3;
18688@};
18689
18690struct xyz
18691@{
18692 int f1;
18693 char f2;
18694 void *f3;
18695 struct tuv f4;
18696@};
18697
18698union qwe
18699@{
18700 struct tuv fff1;
18701 struct xyz fff2;
18702@};
18703
18704struct tyu
18705@{
18706 int a1 : 1;
18707 int a2 : 3;
18708 int a3 : 23;
18709 char a4 : 2;
18710 int64_t a5;
18711 int a6 : 5;
18712 int64_t a7 : 3;
18713@};
18714@end smallexample
18715
18716Issuing a @kbd{ptype /o struct tuv} command would print:
18717
18718@smallexample
18719(@value{GDBP}) ptype /o struct tuv
18720/* offset | size */ type = struct tuv @{
18721/* 0 | 4 */ int a1;
18722/* XXX 4-byte hole */
18723/* 8 | 8 */ char *a2;
18724/* 16 | 4 */ int a3;
18725
18726 /* total size (bytes): 24 */
18727 @}
18728@end smallexample
18729
18730Notice the format of the first column of comments. There, you can
18731find two parts separated by the @samp{|} character: the @emph{offset},
18732which indicates where the field is located inside the struct, in
18733bytes, and the @emph{size} of the field. Another interesting line is
18734the marker of a @emph{hole} in the struct, indicating that it may be
18735possible to pack the struct and make it use less space by reorganizing
18736its fields.
18737
18738It is also possible to print offsets inside an union:
18739
18740@smallexample
18741(@value{GDBP}) ptype /o union qwe
18742/* offset | size */ type = union qwe @{
18743/* 24 */ struct tuv @{
18744/* 0 | 4 */ int a1;
18745/* XXX 4-byte hole */
18746/* 8 | 8 */ char *a2;
18747/* 16 | 4 */ int a3;
18748
18749 /* total size (bytes): 24 */
18750 @} fff1;
18751/* 40 */ struct xyz @{
18752/* 0 | 4 */ int f1;
18753/* 4 | 1 */ char f2;
18754/* XXX 3-byte hole */
18755/* 8 | 8 */ void *f3;
18756/* 16 | 24 */ struct tuv @{
18757/* 16 | 4 */ int a1;
18758/* XXX 4-byte hole */
18759/* 24 | 8 */ char *a2;
18760/* 32 | 4 */ int a3;
18761
18762 /* total size (bytes): 24 */
18763 @} f4;
18764
18765 /* total size (bytes): 40 */
18766 @} fff2;
18767
18768 /* total size (bytes): 40 */
18769 @}
18770@end smallexample
18771
18772In this case, since @code{struct tuv} and @code{struct xyz} occupy the
18773same space (because we are dealing with an union), the offset is not
18774printed for them. However, you can still examine the offset of each
18775of these structures' fields.
18776
18777Another useful scenario is printing the offsets of a struct containing
18778bitfields:
18779
18780@smallexample
18781(@value{GDBP}) ptype /o struct tyu
18782/* offset | size */ type = struct tyu @{
18783/* 0:31 | 4 */ int a1 : 1;
18784/* 0:28 | 4 */ int a2 : 3;
18785/* 0: 5 | 4 */ int a3 : 23;
18786/* 3: 3 | 1 */ signed char a4 : 2;
18787/* XXX 3-bit hole */
18788/* XXX 4-byte hole */
18789/* 8 | 8 */ int64_t a5;
9d3421af
TT
18790/* 16: 0 | 4 */ int a6 : 5;
18791/* 16: 5 | 8 */ int64_t a7 : 3;
18792"/* XXX 7-byte padding */
7c161838
SDJ
18793
18794 /* total size (bytes): 24 */
18795 @}
18796@end smallexample
18797
9d3421af
TT
18798Note how the offset information is now extended to also include the
18799first bit of the bitfield.
53342f27
TT
18800@end table
18801
c906108c 18802@kindex ptype
53342f27 18803@item ptype[/@var{flags}] [@var{arg}]
62f3a2ba
FF
18804@code{ptype} accepts the same arguments as @code{whatis}, but prints a
18805detailed description of the type, instead of just the name of the type.
18806@xref{Expressions, ,Expressions}.
c906108c 18807
177bc839
JK
18808Contrary to @code{whatis}, @code{ptype} always unrolls any
18809@code{typedef}s in its argument declaration, whether the argument is
18810a variable, expression, or a data type. This means that @code{ptype}
18811of a variable or an expression will not print literally its type as
18812present in the source code---use @code{whatis} for that. @code{typedef}s at
18813the pointer or reference targets are also unrolled. Only @code{typedef}s of
18814fields, methods and inner @code{class typedef}s of @code{struct}s,
18815@code{class}es and @code{union}s are not unrolled even with @code{ptype}.
18816
c906108c
SS
18817For example, for this variable declaration:
18818
474c8240 18819@smallexample
177bc839
JK
18820typedef double real_t;
18821struct complex @{ real_t real; double imag; @};
18822typedef struct complex complex_t;
18823complex_t var;
18824real_t *real_pointer_var;
474c8240 18825@end smallexample
c906108c
SS
18826
18827@noindent
18828the two commands give this output:
18829
474c8240 18830@smallexample
c906108c 18831@group
177bc839
JK
18832(@value{GDBP}) whatis var
18833type = complex_t
18834(@value{GDBP}) ptype var
18835type = struct complex @{
18836 real_t real;
18837 double imag;
18838@}
18839(@value{GDBP}) whatis complex_t
18840type = struct complex
18841(@value{GDBP}) whatis struct complex
c906108c 18842type = struct complex
177bc839 18843(@value{GDBP}) ptype struct complex
c906108c 18844type = struct complex @{
177bc839 18845 real_t real;
c906108c
SS
18846 double imag;
18847@}
177bc839
JK
18848(@value{GDBP}) whatis real_pointer_var
18849type = real_t *
18850(@value{GDBP}) ptype real_pointer_var
18851type = double *
c906108c 18852@end group
474c8240 18853@end smallexample
c906108c
SS
18854
18855@noindent
18856As with @code{whatis}, using @code{ptype} without an argument refers to
18857the type of @code{$}, the last value in the value history.
18858
ab1adacd
EZ
18859@cindex incomplete type
18860Sometimes, programs use opaque data types or incomplete specifications
18861of complex data structure. If the debug information included in the
18862program does not allow @value{GDBN} to display a full declaration of
18863the data type, it will say @samp{<incomplete type>}. For example,
18864given these declarations:
18865
18866@smallexample
18867 struct foo;
18868 struct foo *fooptr;
18869@end smallexample
18870
18871@noindent
18872but no definition for @code{struct foo} itself, @value{GDBN} will say:
18873
18874@smallexample
ddb50cd7 18875 (@value{GDBP}) ptype foo
ab1adacd
EZ
18876 $1 = <incomplete type>
18877@end smallexample
18878
18879@noindent
18880``Incomplete type'' is C terminology for data types that are not
18881completely specified.
18882
d69cf9b2
PA
18883@cindex unknown type
18884Othertimes, information about a variable's type is completely absent
18885from the debug information included in the program. This most often
18886happens when the program or library where the variable is defined
18887includes no debug information at all. @value{GDBN} knows the variable
18888exists from inspecting the linker/loader symbol table (e.g., the ELF
18889dynamic symbol table), but such symbols do not contain type
18890information. Inspecting the type of a (global) variable for which
18891@value{GDBN} has no type information shows:
18892
18893@smallexample
18894 (@value{GDBP}) ptype var
18895 type = <data variable, no debug info>
18896@end smallexample
18897
18898@xref{Variables, no debug info variables}, for how to print the values
18899of such variables.
18900
c906108c 18901@kindex info types
a8eab7c6 18902@item info types [-q] [@var{regexp}]
09d4efe1
EZ
18903Print a brief description of all types whose names match the regular
18904expression @var{regexp} (or all types in your program, if you supply
18905no argument). Each complete typename is matched as though it were a
18906complete line; thus, @samp{i type value} gives information on all
18907types in your program whose names include the string @code{value}, but
18908@samp{i type ^value$} gives information only on types whose complete
18909name is @code{value}.
c906108c 18910
20813a0b
PW
18911In programs using different languages, @value{GDBN} chooses the syntax
18912to print the type description according to the
18913@samp{set language} value: using @samp{set language auto}
18914(see @ref{Automatically, ,Set Language Automatically}) means to use the
18915language of the type, other values mean to use
18916the manually specified language (see @ref{Manually, ,Set Language Manually}).
18917
c906108c
SS
18918This command differs from @code{ptype} in two ways: first, like
18919@code{whatis}, it does not print a detailed description; second, it
b744723f 18920lists all source files and line numbers where a type is defined.
c906108c 18921
a8eab7c6
AB
18922The output from @samp{into types} is proceeded with a header line
18923describing what types are being listed. The optional flag @samp{-q},
18924which stands for @samp{quiet}, disables printing this header
18925information.
18926
18a9fc12
TT
18927@kindex info type-printers
18928@item info type-printers
18929Versions of @value{GDBN} that ship with Python scripting enabled may
18930have ``type printers'' available. When using @command{ptype} or
18931@command{whatis}, these printers are consulted when the name of a type
18932is needed. @xref{Type Printing API}, for more information on writing
18933type printers.
18934
18935@code{info type-printers} displays all the available type printers.
18936
18937@kindex enable type-printer
18938@kindex disable type-printer
18939@item enable type-printer @var{name}@dots{}
18940@item disable type-printer @var{name}@dots{}
18941These commands can be used to enable or disable type printers.
18942
b37052ae
EZ
18943@kindex info scope
18944@cindex local variables
09d4efe1 18945@item info scope @var{location}
b37052ae 18946List all the variables local to a particular scope. This command
09d4efe1
EZ
18947accepts a @var{location} argument---a function name, a source line, or
18948an address preceded by a @samp{*}, and prints all the variables local
2a25a5ba
EZ
18949to the scope defined by that location. (@xref{Specify Location}, for
18950details about supported forms of @var{location}.) For example:
b37052ae
EZ
18951
18952@smallexample
18953(@value{GDBP}) @b{info scope command_line_handler}
18954Scope for command_line_handler:
18955Symbol rl is an argument at stack/frame offset 8, length 4.
18956Symbol linebuffer is in static storage at address 0x150a18, length 4.
18957Symbol linelength is in static storage at address 0x150a1c, length 4.
18958Symbol p is a local variable in register $esi, length 4.
18959Symbol p1 is a local variable in register $ebx, length 4.
18960Symbol nline is a local variable in register $edx, length 4.
18961Symbol repeat is a local variable at frame offset -8, length 4.
18962@end smallexample
18963
f5c37c66
EZ
18964@noindent
18965This command is especially useful for determining what data to collect
18966during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
18967collect}.
18968
c906108c
SS
18969@kindex info source
18970@item info source
919d772c
JB
18971Show information about the current source file---that is, the source file for
18972the function containing the current point of execution:
18973@itemize @bullet
18974@item
18975the name of the source file, and the directory containing it,
18976@item
18977the directory it was compiled in,
18978@item
18979its length, in lines,
18980@item
18981which programming language it is written in,
18982@item
b6577aab
DE
18983if the debug information provides it, the program that compiled the file
18984(which may include, e.g., the compiler version and command line arguments),
18985@item
919d772c
JB
18986whether the executable includes debugging information for that file, and
18987if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
18988@item
18989whether the debugging information includes information about
18990preprocessor macros.
18991@end itemize
18992
c906108c
SS
18993
18994@kindex info sources
18995@item info sources
18996Print the names of all source files in your program for which there is
18997debugging information, organized into two lists: files whose symbols
18998have already been read, and files whose symbols will be read when needed.
18999
ae60f04e
PW
19000@item info sources [-dirname | -basename] [--] [@var{regexp}]
19001Like @samp{info sources}, but only print the names of the files
19002matching the provided @var{regexp}.
19003By default, the @var{regexp} is used to match anywhere in the filename.
19004If @code{-dirname}, only files having a dirname matching @var{regexp} are shown.
19005If @code{-basename}, only files having a basename matching @var{regexp}
19006are shown.
19007The matching is case-sensitive, except on operating systems that
19008have case-insensitive filesystem (e.g., MS-Windows).
19009
c906108c 19010@kindex info functions
4acfdd20 19011@item info functions [-q] [-n]
c906108c 19012Print the names and data types of all defined functions.
b744723f
AA
19013Similarly to @samp{info types}, this command groups its output by source
19014files and annotates each function definition with its source line
19015number.
c906108c 19016
20813a0b
PW
19017In programs using different languages, @value{GDBN} chooses the syntax
19018to print the function name and type according to the
19019@samp{set language} value: using @samp{set language auto}
19020(see @ref{Automatically, ,Set Language Automatically}) means to use the
19021language of the function, other values mean to use
19022the manually specified language (see @ref{Manually, ,Set Language Manually}).
19023
4acfdd20
AB
19024The @samp{-n} flag excludes @dfn{non-debugging symbols} from the
19025results. A non-debugging symbol is a symbol that comes from the
19026executable's symbol table, not from the debug information (for
19027example, DWARF) associated with the executable.
19028
d321477b
PW
19029The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19030printing header information and messages explaining why no functions
19031have been printed.
19032
4acfdd20 19033@item info functions [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
d321477b
PW
19034Like @samp{info functions}, but only print the names and data types
19035of the functions selected with the provided regexp(s).
19036
19037If @var{regexp} is provided, print only the functions whose names
19038match the regular expression @var{regexp}.
19039Thus, @samp{info fun step} finds all functions whose
b744723f
AA
19040names include @code{step}; @samp{info fun ^step} finds those whose names
19041start with @code{step}. If a function name contains characters that
19042conflict with the regular expression language (e.g.@:
1c5dfdad 19043@samp{operator*()}), they may be quoted with a backslash.
c906108c 19044
d321477b
PW
19045If @var{type_regexp} is provided, print only the functions whose
19046types, as printed by the @code{whatis} command, match
19047the regular expression @var{type_regexp}.
19048If @var{type_regexp} contains space(s), it should be enclosed in
19049quote characters. If needed, use backslash to escape the meaning
19050of special characters or quotes.
19051Thus, @samp{info fun -t '^int ('} finds the functions that return
19052an integer; @samp{info fun -t '(.*int.*'} finds the functions that
19053have an argument type containing int; @samp{info fun -t '^int (' ^step}
19054finds the functions whose names start with @code{step} and that return
19055int.
19056
19057If both @var{regexp} and @var{type_regexp} are provided, a function
19058is printed only if its name matches @var{regexp} and its type matches
19059@var{type_regexp}.
19060
19061
c906108c 19062@kindex info variables
4acfdd20 19063@item info variables [-q] [-n]
0fe7935b 19064Print the names and data types of all variables that are defined
6ca652b0 19065outside of functions (i.e.@: excluding local variables).
b744723f
AA
19066The printed variables are grouped by source files and annotated with
19067their respective source line numbers.
c906108c 19068
20813a0b
PW
19069In programs using different languages, @value{GDBN} chooses the syntax
19070to print the variable name and type according to the
19071@samp{set language} value: using @samp{set language auto}
19072(see @ref{Automatically, ,Set Language Automatically}) means to use the
19073language of the variable, other values mean to use
19074the manually specified language (see @ref{Manually, ,Set Language Manually}).
19075
4acfdd20
AB
19076The @samp{-n} flag excludes non-debugging symbols from the results.
19077
d321477b
PW
19078The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19079printing header information and messages explaining why no variables
19080have been printed.
19081
4acfdd20 19082@item info variables [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
d321477b
PW
19083Like @kbd{info variables}, but only print the variables selected
19084with the provided regexp(s).
19085
19086If @var{regexp} is provided, print only the variables whose names
19087match the regular expression @var{regexp}.
19088
19089If @var{type_regexp} is provided, print only the variables whose
19090types, as printed by the @code{whatis} command, match
19091the regular expression @var{type_regexp}.
19092If @var{type_regexp} contains space(s), it should be enclosed in
19093quote characters. If needed, use backslash to escape the meaning
19094of special characters or quotes.
19095
19096If both @var{regexp} and @var{type_regexp} are provided, an argument
19097is printed only if its name matches @var{regexp} and its type matches
19098@var{type_regexp}.
c906108c 19099
59c35742
AB
19100@kindex info modules
19101@cindex modules
19102@item info modules @r{[}-q@r{]} @r{[}@var{regexp}@r{]}
19103List all Fortran modules in the program, or all modules matching the
19104optional regular expression @var{regexp}.
19105
19106The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19107printing header information and messages explaining why no modules
19108have been printed.
165f8965
AB
19109
19110@kindex info module
19111@cindex Fortran modules, information about
19112@cindex functions and variables by Fortran module
19113@cindex module functions and variables
19114@item info module functions @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19115@itemx info module variables @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19116List all functions or variables within all Fortran modules. The set
19117of functions or variables listed can be limited by providing some or
19118all of the optional regular expressions. If @var{module-regexp} is
19119provided, then only Fortran modules matching @var{module-regexp} will
19120be searched. Only functions or variables whose type matches the
19121optional regular expression @var{type-regexp} will be listed. And
19122only functions or variables whose name matches the optional regular
19123expression @var{regexp} will be listed.
19124
19125The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19126printing header information and messages explaining why no functions
19127or variables have been printed.
59c35742 19128
b37303ee 19129@kindex info classes
721c2651 19130@cindex Objective-C, classes and selectors
b37303ee
AF
19131@item info classes
19132@itemx info classes @var{regexp}
19133Display all Objective-C classes in your program, or
19134(with the @var{regexp} argument) all those matching a particular regular
19135expression.
19136
19137@kindex info selectors
19138@item info selectors
19139@itemx info selectors @var{regexp}
19140Display all Objective-C selectors in your program, or
19141(with the @var{regexp} argument) all those matching a particular regular
19142expression.
19143
c906108c
SS
19144@ignore
19145This was never implemented.
19146@kindex info methods
19147@item info methods
19148@itemx info methods @var{regexp}
19149The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
19150methods within C@t{++} program, or (with the @var{regexp} argument) a
19151specific set of methods found in the various C@t{++} classes. Many
19152C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
19153from the @code{ptype} command can be overwhelming and hard to use. The
19154@code{info-methods} command filters the methods, printing only those
19155which match the regular-expression @var{regexp}.
19156@end ignore
19157
9c16f35a 19158@cindex opaque data types
c906108c
SS
19159@kindex set opaque-type-resolution
19160@item set opaque-type-resolution on
19161Tell @value{GDBN} to resolve opaque types. An opaque type is a type
19162declared as a pointer to a @code{struct}, @code{class}, or
19163@code{union}---for example, @code{struct MyType *}---that is used in one
19164source file although the full declaration of @code{struct MyType} is in
19165another source file. The default is on.
19166
19167A change in the setting of this subcommand will not take effect until
19168the next time symbols for a file are loaded.
19169
19170@item set opaque-type-resolution off
19171Tell @value{GDBN} not to resolve opaque types. In this case, the type
19172is printed as follows:
19173@smallexample
19174@{<no data fields>@}
19175@end smallexample
19176
19177@kindex show opaque-type-resolution
19178@item show opaque-type-resolution
19179Show whether opaque types are resolved or not.
c906108c 19180
770e7fc7
DE
19181@kindex set print symbol-loading
19182@cindex print messages when symbols are loaded
19183@item set print symbol-loading
19184@itemx set print symbol-loading full
19185@itemx set print symbol-loading brief
19186@itemx set print symbol-loading off
19187The @code{set print symbol-loading} command allows you to control the
19188printing of messages when @value{GDBN} loads symbol information.
19189By default a message is printed for the executable and one for each
19190shared library, and normally this is what you want. However, when
19191debugging apps with large numbers of shared libraries these messages
19192can be annoying.
19193When set to @code{brief} a message is printed for each executable,
19194and when @value{GDBN} loads a collection of shared libraries at once
19195it will only print one message regardless of the number of shared
19196libraries. When set to @code{off} no messages are printed.
19197
19198@kindex show print symbol-loading
19199@item show print symbol-loading
19200Show whether messages will be printed when a @value{GDBN} command
19201entered from the keyboard causes symbol information to be loaded.
19202
c906108c
SS
19203@kindex maint print symbols
19204@cindex symbol dump
19205@kindex maint print psymbols
19206@cindex partial symbol dump
7c57fa1e
YQ
19207@kindex maint print msymbols
19208@cindex minimal symbol dump
34c41c68
DE
19209@item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
19210@itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19211@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19212@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19213@itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19214Write a dump of debugging symbol data into the file @var{filename} or
19215the terminal if @var{filename} is unspecified.
19216If @code{-objfile @var{objfile}} is specified, only dump symbols for
19217that objfile.
19218If @code{-pc @var{address}} is specified, only dump symbols for the file
19219with code at that address. Note that @var{address} may be a symbol like
19220@code{main}.
19221If @code{-source @var{source}} is specified, only dump symbols for that
19222source file.
19223
19224These commands are used to debug the @value{GDBN} symbol-reading code.
19225These commands do not modify internal @value{GDBN} state, therefore
19226@samp{maint print symbols} will only print symbols for already expanded symbol
19227tables.
19228You can use the command @code{info sources} to find out which files these are.
19229If you use @samp{maint print psymbols} instead, the dump shows information
19230about symbols that @value{GDBN} only knows partially---that is, symbols
19231defined in files that @value{GDBN} has skimmed, but not yet read completely.
19232Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
19233``ELF symbols''.
19234
79a6e687 19235@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 19236@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 19237
5e7b2f39
JB
19238@kindex maint info symtabs
19239@kindex maint info psymtabs
44ea7b70
JB
19240@cindex listing @value{GDBN}'s internal symbol tables
19241@cindex symbol tables, listing @value{GDBN}'s internal
19242@cindex full symbol tables, listing @value{GDBN}'s internal
19243@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
19244@item maint info symtabs @r{[} @var{regexp} @r{]}
19245@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
19246
19247List the @code{struct symtab} or @code{struct partial_symtab}
19248structures whose names match @var{regexp}. If @var{regexp} is not
19249given, list them all. The output includes expressions which you can
19250copy into a @value{GDBN} debugging this one to examine a particular
19251structure in more detail. For example:
19252
19253@smallexample
5e7b2f39 19254(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
19255@{ objfile /home/gnu/build/gdb/gdb
19256 ((struct objfile *) 0x82e69d0)
b383017d 19257 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
19258 ((struct partial_symtab *) 0x8474b10)
19259 readin no
19260 fullname (null)
19261 text addresses 0x814d3c8 -- 0x8158074
19262 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
19263 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
19264 dependencies (none)
19265 @}
19266@}
5e7b2f39 19267(@value{GDBP}) maint info symtabs
44ea7b70
JB
19268(@value{GDBP})
19269@end smallexample
19270@noindent
19271We see that there is one partial symbol table whose filename contains
19272the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
19273and we see that @value{GDBN} has not read in any symtabs yet at all.
19274If we set a breakpoint on a function, that will cause @value{GDBN} to
19275read the symtab for the compilation unit containing that function:
19276
19277@smallexample
19278(@value{GDBP}) break dwarf2_psymtab_to_symtab
19279Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
19280line 1574.
5e7b2f39 19281(@value{GDBP}) maint info symtabs
b383017d 19282@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 19283 ((struct objfile *) 0x82e69d0)
b383017d 19284 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
19285 ((struct symtab *) 0x86c1f38)
19286 dirname (null)
19287 fullname (null)
19288 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 19289 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
19290 debugformat DWARF 2
19291 @}
19292@}
b383017d 19293(@value{GDBP})
44ea7b70 19294@end smallexample
44ea7b70 19295
f2403c39
AB
19296@kindex maint info line-table
19297@cindex listing @value{GDBN}'s internal line tables
19298@cindex line tables, listing @value{GDBN}'s internal
19299@item maint info line-table @r{[} @var{regexp} @r{]}
19300
19301List the @code{struct linetable} from all @code{struct symtab}
19302instances whose name matches @var{regexp}. If @var{regexp} is not
19303given, list the @code{struct linetable} from all @code{struct symtab}.
19304
f57d2163
DE
19305@kindex maint set symbol-cache-size
19306@cindex symbol cache size
19307@item maint set symbol-cache-size @var{size}
19308Set the size of the symbol cache to @var{size}.
19309The default size is intended to be good enough for debugging
19310most applications. This option exists to allow for experimenting
19311with different sizes.
19312
19313@kindex maint show symbol-cache-size
19314@item maint show symbol-cache-size
19315Show the size of the symbol cache.
19316
19317@kindex maint print symbol-cache
19318@cindex symbol cache, printing its contents
19319@item maint print symbol-cache
19320Print the contents of the symbol cache.
19321This is useful when debugging symbol cache issues.
19322
19323@kindex maint print symbol-cache-statistics
19324@cindex symbol cache, printing usage statistics
19325@item maint print symbol-cache-statistics
19326Print symbol cache usage statistics.
19327This helps determine how well the cache is being utilized.
19328
19329@kindex maint flush-symbol-cache
19330@cindex symbol cache, flushing
19331@item maint flush-symbol-cache
19332Flush the contents of the symbol cache, all entries are removed.
19333This command is useful when debugging the symbol cache.
19334It is also useful when collecting performance data.
19335
19336@end table
6a3ca067 19337
6d2ebf8b 19338@node Altering
c906108c
SS
19339@chapter Altering Execution
19340
19341Once you think you have found an error in your program, you might want to
19342find out for certain whether correcting the apparent error would lead to
19343correct results in the rest of the run. You can find the answer by
19344experiment, using the @value{GDBN} features for altering execution of the
19345program.
19346
19347For example, you can store new values into variables or memory
7a292a7a
SS
19348locations, give your program a signal, restart it at a different
19349address, or even return prematurely from a function.
c906108c
SS
19350
19351@menu
19352* Assignment:: Assignment to variables
19353* Jumping:: Continuing at a different address
c906108c 19354* Signaling:: Giving your program a signal
c906108c
SS
19355* Returning:: Returning from a function
19356* Calling:: Calling your program's functions
19357* Patching:: Patching your program
bb2ec1b3 19358* Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
c906108c
SS
19359@end menu
19360
6d2ebf8b 19361@node Assignment
79a6e687 19362@section Assignment to Variables
c906108c
SS
19363
19364@cindex assignment
19365@cindex setting variables
19366To alter the value of a variable, evaluate an assignment expression.
19367@xref{Expressions, ,Expressions}. For example,
19368
474c8240 19369@smallexample
c906108c 19370print x=4
474c8240 19371@end smallexample
c906108c
SS
19372
19373@noindent
19374stores the value 4 into the variable @code{x}, and then prints the
5d161b24 19375value of the assignment expression (which is 4).
c906108c
SS
19376@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
19377information on operators in supported languages.
c906108c
SS
19378
19379@kindex set variable
19380@cindex variables, setting
19381If you are not interested in seeing the value of the assignment, use the
19382@code{set} command instead of the @code{print} command. @code{set} is
19383really the same as @code{print} except that the expression's value is
19384not printed and is not put in the value history (@pxref{Value History,
79a6e687 19385,Value History}). The expression is evaluated only for its effects.
c906108c 19386
c906108c
SS
19387If the beginning of the argument string of the @code{set} command
19388appears identical to a @code{set} subcommand, use the @code{set
19389variable} command instead of just @code{set}. This command is identical
19390to @code{set} except for its lack of subcommands. For example, if your
19391program has a variable @code{width}, you get an error if you try to set
19392a new value with just @samp{set width=13}, because @value{GDBN} has the
19393command @code{set width}:
19394
474c8240 19395@smallexample
c906108c
SS
19396(@value{GDBP}) whatis width
19397type = double
19398(@value{GDBP}) p width
19399$4 = 13
19400(@value{GDBP}) set width=47
19401Invalid syntax in expression.
474c8240 19402@end smallexample
c906108c
SS
19403
19404@noindent
19405The invalid expression, of course, is @samp{=47}. In
19406order to actually set the program's variable @code{width}, use
19407
474c8240 19408@smallexample
c906108c 19409(@value{GDBP}) set var width=47
474c8240 19410@end smallexample
53a5351d 19411
c906108c
SS
19412Because the @code{set} command has many subcommands that can conflict
19413with the names of program variables, it is a good idea to use the
19414@code{set variable} command instead of just @code{set}. For example, if
19415your program has a variable @code{g}, you run into problems if you try
19416to set a new value with just @samp{set g=4}, because @value{GDBN} has
19417the command @code{set gnutarget}, abbreviated @code{set g}:
19418
474c8240 19419@smallexample
c906108c
SS
19420@group
19421(@value{GDBP}) whatis g
19422type = double
19423(@value{GDBP}) p g
19424$1 = 1
19425(@value{GDBP}) set g=4
2df3850c 19426(@value{GDBP}) p g
c906108c
SS
19427$2 = 1
19428(@value{GDBP}) r
19429The program being debugged has been started already.
19430Start it from the beginning? (y or n) y
19431Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
19432"/home/smith/cc_progs/a.out": can't open to read symbols:
19433 Invalid bfd target.
c906108c
SS
19434(@value{GDBP}) show g
19435The current BFD target is "=4".
19436@end group
474c8240 19437@end smallexample
c906108c
SS
19438
19439@noindent
19440The program variable @code{g} did not change, and you silently set the
19441@code{gnutarget} to an invalid value. In order to set the variable
19442@code{g}, use
19443
474c8240 19444@smallexample
c906108c 19445(@value{GDBP}) set var g=4
474c8240 19446@end smallexample
c906108c
SS
19447
19448@value{GDBN} allows more implicit conversions in assignments than C; you can
19449freely store an integer value into a pointer variable or vice versa,
19450and you can convert any structure to any other structure that is the
19451same length or shorter.
19452@comment FIXME: how do structs align/pad in these conversions?
19453@comment /doc@cygnus.com 18dec1990
19454
19455To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
19456construct to generate a value of specified type at a specified address
19457(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
19458to memory location @code{0x83040} as an integer (which implies a certain size
19459and representation in memory), and
19460
474c8240 19461@smallexample
c906108c 19462set @{int@}0x83040 = 4
474c8240 19463@end smallexample
c906108c
SS
19464
19465@noindent
19466stores the value 4 into that memory location.
19467
6d2ebf8b 19468@node Jumping
79a6e687 19469@section Continuing at a Different Address
c906108c
SS
19470
19471Ordinarily, when you continue your program, you do so at the place where
19472it stopped, with the @code{continue} command. You can instead continue at
19473an address of your own choosing, with the following commands:
19474
19475@table @code
19476@kindex jump
c1d780c2 19477@kindex j @r{(@code{jump})}
629500fa 19478@item jump @var{location}
c1d780c2 19479@itemx j @var{location}
629500fa
KS
19480Resume execution at @var{location}. Execution stops again immediately
19481if there is a breakpoint there. @xref{Specify Location}, for a description
19482of the different forms of @var{location}. It is common
2a25a5ba
EZ
19483practice to use the @code{tbreak} command in conjunction with
19484@code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
c906108c
SS
19485
19486The @code{jump} command does not change the current stack frame, or
19487the stack pointer, or the contents of any memory location or any
629500fa 19488register other than the program counter. If @var{location} is in
c906108c
SS
19489a different function from the one currently executing, the results may
19490be bizarre if the two functions expect different patterns of arguments or
19491of local variables. For this reason, the @code{jump} command requests
19492confirmation if the specified line is not in the function currently
19493executing. However, even bizarre results are predictable if you are
19494well acquainted with the machine-language code of your program.
c906108c
SS
19495@end table
19496
53a5351d
JM
19497On many systems, you can get much the same effect as the @code{jump}
19498command by storing a new value into the register @code{$pc}. The
19499difference is that this does not start your program running; it only
19500changes the address of where it @emph{will} run when you continue. For
19501example,
c906108c 19502
474c8240 19503@smallexample
c906108c 19504set $pc = 0x485
474c8240 19505@end smallexample
c906108c
SS
19506
19507@noindent
19508makes the next @code{continue} command or stepping command execute at
19509address @code{0x485}, rather than at the address where your program stopped.
79a6e687 19510@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
19511
19512The most common occasion to use the @code{jump} command is to back
19513up---perhaps with more breakpoints set---over a portion of a program
19514that has already executed, in order to examine its execution in more
19515detail.
19516
c906108c 19517@c @group
6d2ebf8b 19518@node Signaling
79a6e687 19519@section Giving your Program a Signal
9c16f35a 19520@cindex deliver a signal to a program
c906108c
SS
19521
19522@table @code
19523@kindex signal
19524@item signal @var{signal}
70509625 19525Resume execution where your program is stopped, but immediately give it the
697aa1b7 19526signal @var{signal}. The @var{signal} can be the name or the number of a
c906108c
SS
19527signal. For example, on many systems @code{signal 2} and @code{signal
19528SIGINT} are both ways of sending an interrupt signal.
19529
19530Alternatively, if @var{signal} is zero, continue execution without
19531giving a signal. This is useful when your program stopped on account of
ae606bee 19532a signal and would ordinarily see the signal when resumed with the
c906108c
SS
19533@code{continue} command; @samp{signal 0} causes it to resume without a
19534signal.
19535
70509625
PA
19536@emph{Note:} When resuming a multi-threaded program, @var{signal} is
19537delivered to the currently selected thread, not the thread that last
19538reported a stop. This includes the situation where a thread was
19539stopped due to a signal. So if you want to continue execution
19540suppressing the signal that stopped a thread, you should select that
19541same thread before issuing the @samp{signal 0} command. If you issue
19542the @samp{signal 0} command with another thread as the selected one,
19543@value{GDBN} detects that and asks for confirmation.
19544
c906108c
SS
19545Invoking the @code{signal} command is not the same as invoking the
19546@code{kill} utility from the shell. Sending a signal with @code{kill}
19547causes @value{GDBN} to decide what to do with the signal depending on
19548the signal handling tables (@pxref{Signals}). The @code{signal} command
19549passes the signal directly to your program.
19550
81219e53
DE
19551@code{signal} does not repeat when you press @key{RET} a second time
19552after executing the command.
19553
19554@kindex queue-signal
19555@item queue-signal @var{signal}
19556Queue @var{signal} to be delivered immediately to the current thread
19557when execution of the thread resumes. The @var{signal} can be the name or
19558the number of a signal. For example, on many systems @code{signal 2} and
19559@code{signal SIGINT} are both ways of sending an interrupt signal.
19560The handling of the signal must be set to pass the signal to the program,
19561otherwise @value{GDBN} will report an error.
19562You can control the handling of signals from @value{GDBN} with the
19563@code{handle} command (@pxref{Signals}).
19564
19565Alternatively, if @var{signal} is zero, any currently queued signal
19566for the current thread is discarded and when execution resumes no signal
19567will be delivered. This is useful when your program stopped on account
19568of a signal and would ordinarily see the signal when resumed with the
19569@code{continue} command.
19570
19571This command differs from the @code{signal} command in that the signal
19572is just queued, execution is not resumed. And @code{queue-signal} cannot
19573be used to pass a signal whose handling state has been set to @code{nopass}
19574(@pxref{Signals}).
19575@end table
19576@c @end group
c906108c 19577
e5f8a7cc
PA
19578@xref{stepping into signal handlers}, for information on how stepping
19579commands behave when the thread has a signal queued.
19580
6d2ebf8b 19581@node Returning
79a6e687 19582@section Returning from a Function
c906108c
SS
19583
19584@table @code
19585@cindex returning from a function
19586@kindex return
19587@item return
19588@itemx return @var{expression}
19589You can cancel execution of a function call with the @code{return}
19590command. If you give an
19591@var{expression} argument, its value is used as the function's return
19592value.
19593@end table
19594
19595When you use @code{return}, @value{GDBN} discards the selected stack frame
19596(and all frames within it). You can think of this as making the
19597discarded frame return prematurely. If you wish to specify a value to
19598be returned, give that value as the argument to @code{return}.
19599
19600This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 19601Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
19602innermost remaining frame. That frame becomes selected. The
19603specified value is stored in the registers used for returning values
19604of functions.
19605
19606The @code{return} command does not resume execution; it leaves the
19607program stopped in the state that would exist if the function had just
19608returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 19609and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
19610selected stack frame returns naturally.
19611
61ff14c6
JK
19612@value{GDBN} needs to know how the @var{expression} argument should be set for
19613the inferior. The concrete registers assignment depends on the OS ABI and the
19614type being returned by the selected stack frame. For example it is common for
19615OS ABI to return floating point values in FPU registers while integer values in
19616CPU registers. Still some ABIs return even floating point values in CPU
19617registers. Larger integer widths (such as @code{long long int}) also have
19618specific placement rules. @value{GDBN} already knows the OS ABI from its
19619current target so it needs to find out also the type being returned to make the
19620assignment into the right register(s).
19621
19622Normally, the selected stack frame has debug info. @value{GDBN} will always
19623use the debug info instead of the implicit type of @var{expression} when the
19624debug info is available. For example, if you type @kbd{return -1}, and the
19625function in the current stack frame is declared to return a @code{long long
19626int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
19627into a @code{long long int}:
19628
19629@smallexample
19630Breakpoint 1, func () at gdb.base/return-nodebug.c:29
1963129 return 31;
19632(@value{GDBP}) return -1
19633Make func return now? (y or n) y
19634#0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
1963543 printf ("result=%lld\n", func ());
19636(@value{GDBP})
19637@end smallexample
19638
19639However, if the selected stack frame does not have a debug info, e.g., if the
19640function was compiled without debug info, @value{GDBN} has to find out the type
19641to return from user. Specifying a different type by mistake may set the value
19642in different inferior registers than the caller code expects. For example,
19643typing @kbd{return -1} with its implicit type @code{int} would set only a part
19644of a @code{long long int} result for a debug info less function (on 32-bit
19645architectures). Therefore the user is required to specify the return type by
19646an appropriate cast explicitly:
19647
19648@smallexample
19649Breakpoint 2, 0x0040050b in func ()
19650(@value{GDBP}) return -1
19651Return value type not available for selected stack frame.
19652Please use an explicit cast of the value to return.
19653(@value{GDBP}) return (long long int) -1
19654Make selected stack frame return now? (y or n) y
19655#0 0x00400526 in main ()
19656(@value{GDBP})
19657@end smallexample
19658
6d2ebf8b 19659@node Calling
79a6e687 19660@section Calling Program Functions
c906108c 19661
f8568604 19662@table @code
c906108c 19663@cindex calling functions
f8568604
EZ
19664@cindex inferior functions, calling
19665@item print @var{expr}
d3e8051b 19666Evaluate the expression @var{expr} and display the resulting value.
697aa1b7 19667The expression may include calls to functions in the program being
f8568604
EZ
19668debugged.
19669
c906108c 19670@kindex call
c906108c
SS
19671@item call @var{expr}
19672Evaluate the expression @var{expr} without displaying @code{void}
19673returned values.
c906108c
SS
19674
19675You can use this variant of the @code{print} command if you want to
f8568604
EZ
19676execute a function from your program that does not return anything
19677(a.k.a.@: @dfn{a void function}), but without cluttering the output
19678with @code{void} returned values that @value{GDBN} will otherwise
19679print. If the result is not void, it is printed and saved in the
19680value history.
19681@end table
19682
9c16f35a
EZ
19683It is possible for the function you call via the @code{print} or
19684@code{call} command to generate a signal (e.g., if there's a bug in
19685the function, or if you passed it incorrect arguments). What happens
19686in that case is controlled by the @code{set unwindonsignal} command.
19687
7cd1089b
PM
19688Similarly, with a C@t{++} program it is possible for the function you
19689call via the @code{print} or @code{call} command to generate an
19690exception that is not handled due to the constraints of the dummy
19691frame. In this case, any exception that is raised in the frame, but has
19692an out-of-frame exception handler will not be found. GDB builds a
19693dummy-frame for the inferior function call, and the unwinder cannot
19694seek for exception handlers outside of this dummy-frame. What happens
19695in that case is controlled by the
19696@code{set unwind-on-terminating-exception} command.
19697
9c16f35a
EZ
19698@table @code
19699@item set unwindonsignal
19700@kindex set unwindonsignal
19701@cindex unwind stack in called functions
19702@cindex call dummy stack unwinding
19703Set unwinding of the stack if a signal is received while in a function
19704that @value{GDBN} called in the program being debugged. If set to on,
19705@value{GDBN} unwinds the stack it created for the call and restores
19706the context to what it was before the call. If set to off (the
19707default), @value{GDBN} stops in the frame where the signal was
19708received.
19709
19710@item show unwindonsignal
19711@kindex show unwindonsignal
19712Show the current setting of stack unwinding in the functions called by
19713@value{GDBN}.
7cd1089b
PM
19714
19715@item set unwind-on-terminating-exception
19716@kindex set unwind-on-terminating-exception
19717@cindex unwind stack in called functions with unhandled exceptions
19718@cindex call dummy stack unwinding on unhandled exception.
19719Set unwinding of the stack if a C@t{++} exception is raised, but left
19720unhandled while in a function that @value{GDBN} called in the program being
19721debugged. If set to on (the default), @value{GDBN} unwinds the stack
19722it created for the call and restores the context to what it was before
19723the call. If set to off, @value{GDBN} the exception is delivered to
19724the default C@t{++} exception handler and the inferior terminated.
19725
19726@item show unwind-on-terminating-exception
19727@kindex show unwind-on-terminating-exception
19728Show the current setting of stack unwinding in the functions called by
19729@value{GDBN}.
19730
136afab8
PW
19731@item set may-call-functions
19732@kindex set may-call-functions
19733@cindex disabling calling functions in the program
19734@cindex calling functions in the program, disabling
19735Set permission to call functions in the program.
19736This controls whether @value{GDBN} will attempt to call functions in
19737the program, such as with expressions in the @code{print} command. It
19738defaults to @code{on}.
19739
19740To call a function in the program, @value{GDBN} has to temporarily
19741modify the state of the inferior. This has potentially undesired side
19742effects. Also, having @value{GDBN} call nested functions is likely to
19743be erroneous and may even crash the program being debugged. You can
19744avoid such hazards by forbidding @value{GDBN} from calling functions
19745in the program being debugged. If calling functions in the program
19746is forbidden, GDB will throw an error when a command (such as printing
19747an expression) starts a function call in the program.
19748
19749@item show may-call-functions
19750@kindex show may-call-functions
19751Show permission to call functions in the program.
19752
9c16f35a
EZ
19753@end table
19754
d69cf9b2
PA
19755@subsection Calling functions with no debug info
19756
19757@cindex no debug info functions
19758Sometimes, a function you wish to call is missing debug information.
19759In such case, @value{GDBN} does not know the type of the function,
19760including the types of the function's parameters. To avoid calling
19761the inferior function incorrectly, which could result in the called
19762function functioning erroneously and even crash, @value{GDBN} refuses
19763to call the function unless you tell it the type of the function.
19764
19765For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
19766to do that. The simplest is to cast the call to the function's
19767declared return type. For example:
19768
19769@smallexample
19770(@value{GDBP}) p getenv ("PATH")
19771'getenv' has unknown return type; cast the call to its declared return type
19772(@value{GDBP}) p (char *) getenv ("PATH")
19773$1 = 0x7fffffffe7ba "/usr/local/bin:/"...
19774@end smallexample
19775
19776Casting the return type of a no-debug function is equivalent to
19777casting the function to a pointer to a prototyped function that has a
19778prototype that matches the types of the passed-in arguments, and
19779calling that. I.e., the call above is equivalent to:
19780
19781@smallexample
19782(@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
19783@end smallexample
19784
19785@noindent
19786and given this prototyped C or C++ function with float parameters:
19787
19788@smallexample
19789float multiply (float v1, float v2) @{ return v1 * v2; @}
19790@end smallexample
19791
19792@noindent
19793these calls are equivalent:
19794
19795@smallexample
19796(@value{GDBP}) p (float) multiply (2.0f, 3.0f)
19797(@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
19798@end smallexample
19799
19800If the function you wish to call is declared as unprototyped (i.e.@:
19801old K&R style), you must use the cast-to-function-pointer syntax, so
19802that @value{GDBN} knows that it needs to apply default argument
19803promotions (promote float arguments to double). @xref{ABI, float
19804promotion}. For example, given this unprototyped C function with
19805float parameters, and no debug info:
19806
19807@smallexample
19808float
19809multiply_noproto (v1, v2)
19810 float v1, v2;
19811@{
19812 return v1 * v2;
19813@}
19814@end smallexample
19815
19816@noindent
19817you call it like this:
19818
19819@smallexample
19820 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
19821@end smallexample
c906108c 19822
6d2ebf8b 19823@node Patching
79a6e687 19824@section Patching Programs
7a292a7a 19825
c906108c
SS
19826@cindex patching binaries
19827@cindex writing into executables
c906108c 19828@cindex writing into corefiles
c906108c 19829
7a292a7a
SS
19830By default, @value{GDBN} opens the file containing your program's
19831executable code (or the corefile) read-only. This prevents accidental
19832alterations to machine code; but it also prevents you from intentionally
19833patching your program's binary.
c906108c
SS
19834
19835If you'd like to be able to patch the binary, you can specify that
19836explicitly with the @code{set write} command. For example, you might
19837want to turn on internal debugging flags, or even to make emergency
19838repairs.
19839
19840@table @code
19841@kindex set write
19842@item set write on
19843@itemx set write off
7a292a7a 19844If you specify @samp{set write on}, @value{GDBN} opens executable and
20924a55 19845core files for both reading and writing; if you specify @kbd{set write
c906108c
SS
19846off} (the default), @value{GDBN} opens them read-only.
19847
19848If you have already loaded a file, you must load it again (using the
7a292a7a
SS
19849@code{exec-file} or @code{core-file} command) after changing @code{set
19850write}, for your new setting to take effect.
c906108c
SS
19851
19852@item show write
19853@kindex show write
7a292a7a
SS
19854Display whether executable files and core files are opened for writing
19855as well as reading.
c906108c
SS
19856@end table
19857
bb2ec1b3
TT
19858@node Compiling and Injecting Code
19859@section Compiling and injecting code in @value{GDBN}
19860@cindex injecting code
19861@cindex writing into executables
19862@cindex compiling code
19863
19864@value{GDBN} supports on-demand compilation and code injection into
19865programs running under @value{GDBN}. GCC 5.0 or higher built with
19866@file{libcc1.so} must be installed for this functionality to be enabled.
19867This functionality is implemented with the following commands.
19868
19869@table @code
19870@kindex compile code
19871@item compile code @var{source-code}
19872@itemx compile code -raw @var{--} @var{source-code}
19873Compile @var{source-code} with the compiler language found as the current
19874language in @value{GDBN} (@pxref{Languages}). If compilation and
19875injection is not supported with the current language specified in
19876@value{GDBN}, or the compiler does not support this feature, an error
19877message will be printed. If @var{source-code} compiles and links
19878successfully, @value{GDBN} will load the object-code emitted,
19879and execute it within the context of the currently selected inferior.
19880It is important to note that the compiled code is executed immediately.
19881After execution, the compiled code is removed from @value{GDBN} and any
19882new types or variables you have defined will be deleted.
19883
19884The command allows you to specify @var{source-code} in two ways.
19885The simplest method is to provide a single line of code to the command.
19886E.g.:
19887
19888@smallexample
19889compile code printf ("hello world\n");
19890@end smallexample
19891
19892If you specify options on the command line as well as source code, they
19893may conflict. The @samp{--} delimiter can be used to separate options
19894from actual source code. E.g.:
19895
19896@smallexample
19897compile code -r -- printf ("hello world\n");
19898@end smallexample
19899
19900Alternatively you can enter source code as multiple lines of text. To
19901enter this mode, invoke the @samp{compile code} command without any text
19902following the command. This will start the multiple-line editor and
19903allow you to type as many lines of source code as required. When you
19904have completed typing, enter @samp{end} on its own line to exit the
19905editor.
19906
19907@smallexample
19908compile code
19909>printf ("hello\n");
19910>printf ("world\n");
19911>end
19912@end smallexample
19913
19914Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
19915provided @var{source-code} in a callable scope. In this case, you must
19916specify the entry point of the code by defining a function named
19917@code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
19918inferior. Using @samp{-raw} option may be needed for example when
19919@var{source-code} requires @samp{#include} lines which may conflict with
19920inferior symbols otherwise.
19921
19922@kindex compile file
19923@item compile file @var{filename}
19924@itemx compile file -raw @var{filename}
19925Like @code{compile code}, but take the source code from @var{filename}.
19926
19927@smallexample
19928compile file /home/user/example.c
19929@end smallexample
19930@end table
19931
36de76f9 19932@table @code
3345721a
PA
19933@item compile print [[@var{options}] --] @var{expr}
19934@itemx compile print [[@var{options}] --] /@var{f} @var{expr}
36de76f9
JK
19935Compile and execute @var{expr} with the compiler language found as the
19936current language in @value{GDBN} (@pxref{Languages}). By default the
19937value of @var{expr} is printed in a format appropriate to its data type;
19938you can choose a different format by specifying @samp{/@var{f}}, where
19939@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
3345721a
PA
19940Formats}. The @code{compile print} command accepts the same options
19941as the @code{print} command; see @ref{print options}.
36de76f9 19942
3345721a
PA
19943@item compile print [[@var{options}] --]
19944@itemx compile print [[@var{options}] --] /@var{f}
36de76f9
JK
19945@cindex reprint the last value
19946Alternatively you can enter the expression (source code producing it) as
19947multiple lines of text. To enter this mode, invoke the @samp{compile print}
19948command without any text following the command. This will start the
19949multiple-line editor.
19950@end table
19951
e7a8570f
JK
19952@noindent
19953The process of compiling and injecting the code can be inspected using:
19954
19955@table @code
19956@anchor{set debug compile}
19957@item set debug compile
19958@cindex compile command debugging info
19959Turns on or off display of @value{GDBN} process of compiling and
19960injecting the code. The default is off.
19961
19962@item show debug compile
19963Displays the current state of displaying @value{GDBN} process of
19964compiling and injecting the code.
078a0207
KS
19965
19966@anchor{set debug compile-cplus-types}
19967@item set debug compile-cplus-types
19968@cindex compile C@t{++} type conversion
19969Turns on or off the display of C@t{++} type conversion debugging information.
19970The default is off.
19971
19972@item show debug compile-cplus-types
19973Displays the current state of displaying debugging information for
19974C@t{++} type conversion.
e7a8570f
JK
19975@end table
19976
19977@subsection Compilation options for the @code{compile} command
19978
19979@value{GDBN} needs to specify the right compilation options for the code
19980to be injected, in part to make its ABI compatible with the inferior
19981and in part to make the injected code compatible with @value{GDBN}'s
19982injecting process.
19983
19984@noindent
19985The options used, in increasing precedence:
19986
19987@table @asis
19988@item target architecture and OS options (@code{gdbarch})
19989These options depend on target processor type and target operating
19990system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
19991(@code{-m64}) compilation option.
19992
19993@item compilation options recorded in the target
19994@value{NGCC} (since version 4.7) stores the options used for compilation
19995into @code{DW_AT_producer} part of DWARF debugging information according
19996to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
19997explicitly specify @code{-g} during inferior compilation otherwise
19998@value{NGCC} produces no DWARF. This feature is only relevant for
19999platforms where @code{-g} produces DWARF by default, otherwise one may
20000try to enforce DWARF by using @code{-gdwarf-4}.
20001
20002@item compilation options set by @code{set compile-args}
20003@end table
20004
20005@noindent
20006You can override compilation options using the following command:
20007
20008@table @code
20009@item set compile-args
20010@cindex compile command options override
20011Set compilation options used for compiling and injecting code with the
20012@code{compile} commands. These options override any conflicting ones
20013from the target architecture and/or options stored during inferior
20014compilation.
20015
20016@item show compile-args
20017Displays the current state of compilation options override.
20018This does not show all the options actually used during compilation,
20019use @ref{set debug compile} for that.
20020@end table
20021
bb2ec1b3
TT
20022@subsection Caveats when using the @code{compile} command
20023
20024There are a few caveats to keep in mind when using the @code{compile}
20025command. As the caveats are different per language, the table below
20026highlights specific issues on a per language basis.
20027
20028@table @asis
20029@item C code examples and caveats
20030When the language in @value{GDBN} is set to @samp{C}, the compiler will
20031attempt to compile the source code with a @samp{C} compiler. The source
20032code provided to the @code{compile} command will have much the same
20033access to variables and types as it normally would if it were part of
20034the program currently being debugged in @value{GDBN}.
20035
20036Below is a sample program that forms the basis of the examples that
20037follow. This program has been compiled and loaded into @value{GDBN},
20038much like any other normal debugging session.
20039
20040@smallexample
20041void function1 (void)
20042@{
20043 int i = 42;
20044 printf ("function 1\n");
20045@}
20046
20047void function2 (void)
20048@{
20049 int j = 12;
20050 function1 ();
20051@}
20052
20053int main(void)
20054@{
20055 int k = 6;
20056 int *p;
20057 function2 ();
20058 return 0;
20059@}
20060@end smallexample
20061
20062For the purposes of the examples in this section, the program above has
20063been compiled, loaded into @value{GDBN}, stopped at the function
20064@code{main}, and @value{GDBN} is awaiting input from the user.
20065
20066To access variables and types for any program in @value{GDBN}, the
20067program must be compiled and packaged with debug information. The
20068@code{compile} command is not an exception to this rule. Without debug
20069information, you can still use the @code{compile} command, but you will
20070be very limited in what variables and types you can access.
20071
20072So with that in mind, the example above has been compiled with debug
20073information enabled. The @code{compile} command will have access to
20074all variables and types (except those that may have been optimized
20075out). Currently, as @value{GDBN} has stopped the program in the
20076@code{main} function, the @code{compile} command would have access to
20077the variable @code{k}. You could invoke the @code{compile} command
20078and type some source code to set the value of @code{k}. You can also
20079read it, or do anything with that variable you would normally do in
20080@code{C}. Be aware that changes to inferior variables in the
20081@code{compile} command are persistent. In the following example:
20082
20083@smallexample
20084compile code k = 3;
20085@end smallexample
20086
20087@noindent
20088the variable @code{k} is now 3. It will retain that value until
20089something else in the example program changes it, or another
20090@code{compile} command changes it.
20091
20092Normal scope and access rules apply to source code compiled and
20093injected by the @code{compile} command. In the example, the variables
20094@code{j} and @code{k} are not accessible yet, because the program is
20095currently stopped in the @code{main} function, where these variables
20096are not in scope. Therefore, the following command
20097
20098@smallexample
20099compile code j = 3;
20100@end smallexample
20101
20102@noindent
20103will result in a compilation error message.
20104
20105Once the program is continued, execution will bring these variables in
20106scope, and they will become accessible; then the code you specify via
20107the @code{compile} command will be able to access them.
20108
20109You can create variables and types with the @code{compile} command as
20110part of your source code. Variables and types that are created as part
20111of the @code{compile} command are not visible to the rest of the program for
20112the duration of its run. This example is valid:
20113
20114@smallexample
20115compile code int ff = 5; printf ("ff is %d\n", ff);
20116@end smallexample
20117
20118However, if you were to type the following into @value{GDBN} after that
20119command has completed:
20120
20121@smallexample
20122compile code printf ("ff is %d\n'', ff);
20123@end smallexample
20124
20125@noindent
20126a compiler error would be raised as the variable @code{ff} no longer
20127exists. Object code generated and injected by the @code{compile}
20128command is removed when its execution ends. Caution is advised
20129when assigning to program variables values of variables created by the
20130code submitted to the @code{compile} command. This example is valid:
20131
20132@smallexample
20133compile code int ff = 5; k = ff;
20134@end smallexample
20135
20136The value of the variable @code{ff} is assigned to @code{k}. The variable
20137@code{k} does not require the existence of @code{ff} to maintain the value
20138it has been assigned. However, pointers require particular care in
20139assignment. If the source code compiled with the @code{compile} command
20140changed the address of a pointer in the example program, perhaps to a
20141variable created in the @code{compile} command, that pointer would point
20142to an invalid location when the command exits. The following example
20143would likely cause issues with your debugged program:
20144
20145@smallexample
20146compile code int ff = 5; p = &ff;
20147@end smallexample
20148
20149In this example, @code{p} would point to @code{ff} when the
20150@code{compile} command is executing the source code provided to it.
20151However, as variables in the (example) program persist with their
20152assigned values, the variable @code{p} would point to an invalid
20153location when the command exists. A general rule should be followed
20154in that you should either assign @code{NULL} to any assigned pointers,
20155or restore a valid location to the pointer before the command exits.
20156
20157Similar caution must be exercised with any structs, unions, and typedefs
20158defined in @code{compile} command. Types defined in the @code{compile}
20159command will no longer be available in the next @code{compile} command.
20160Therefore, if you cast a variable to a type defined in the
20161@code{compile} command, care must be taken to ensure that any future
20162need to resolve the type can be achieved.
20163
20164@smallexample
20165(gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
20166(gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
20167gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
20168Compilation failed.
20169(gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
2017042
20171@end smallexample
20172
20173Variables that have been optimized away by the compiler are not
20174accessible to the code submitted to the @code{compile} command.
20175Access to those variables will generate a compiler error which @value{GDBN}
20176will print to the console.
20177@end table
20178
e7a8570f
JK
20179@subsection Compiler search for the @code{compile} command
20180
6e41ddec
JK
20181@value{GDBN} needs to find @value{NGCC} for the inferior being debugged
20182which may not be obvious for remote targets of different architecture
20183than where @value{GDBN} is running. Environment variable @code{PATH} on
e7a8570f 20184@value{GDBN} host is searched for @value{NGCC} binary matching the
6e41ddec
JK
20185target architecture and operating system. This search can be overriden
20186by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is
20187taken from shell that executed @value{GDBN}, it is not the value set by
20188@value{GDBN} command @code{set environment}). @xref{Environment}.
20189
e7a8570f
JK
20190
20191Specifically @code{PATH} is searched for binaries matching regular expression
20192@code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
20193debugged. @var{arch} is processor name --- multiarch is supported, so for
20194example both @code{i386} and @code{x86_64} targets look for pattern
20195@code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
20196for pattern @code{s390x?}. @var{os} is currently supported only for
20197pattern @code{linux(-gnu)?}.
20198
6e41ddec
JK
20199On Posix hosts the compiler driver @value{GDBN} needs to find also
20200shared library @file{libcc1.so} from the compiler. It is searched in
20201default shared library search path (overridable with usual environment
20202variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set
20203compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
20204according to the installation of the found compiler --- as possibly
20205specified by the @code{set compile-gcc} command.
20206
20207@table @code
20208@item set compile-gcc
20209@cindex compile command driver filename override
20210Set compilation command used for compiling and injecting code with the
20211@code{compile} commands. If this option is not set (it is set to
20212an empty string), the search described above will occur --- that is the
20213default.
20214
20215@item show compile-gcc
20216Displays the current compile command @value{NGCC} driver filename.
20217If set, it is the main command @command{gcc}, found usually for example
20218under name @file{x86_64-linux-gnu-gcc}.
20219@end table
20220
6d2ebf8b 20221@node GDB Files
c906108c
SS
20222@chapter @value{GDBN} Files
20223
7a292a7a
SS
20224@value{GDBN} needs to know the file name of the program to be debugged,
20225both in order to read its symbol table and in order to start your
20226program. To debug a core dump of a previous run, you must also tell
20227@value{GDBN} the name of the core dump file.
c906108c
SS
20228
20229@menu
20230* Files:: Commands to specify files
2b4bf6af 20231* File Caching:: Information about @value{GDBN}'s file caching
5b5d99cf 20232* Separate Debug Files:: Debugging information in separate files
608e2dbb 20233* MiniDebugInfo:: Debugging information in a special section
9291a0cd 20234* Index Files:: Index files speed up GDB
c906108c 20235* Symbol Errors:: Errors reading symbol files
b14b1491 20236* Data Files:: GDB data files
c906108c
SS
20237@end menu
20238
6d2ebf8b 20239@node Files
79a6e687 20240@section Commands to Specify Files
c906108c 20241
7a292a7a 20242@cindex symbol table
c906108c 20243@cindex core dump file
7a292a7a
SS
20244
20245You may want to specify executable and core dump file names. The usual
20246way to do this is at start-up time, using the arguments to
20247@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
20248Out of @value{GDBN}}).
c906108c
SS
20249
20250Occasionally it is necessary to change to a different file during a
397ca115
EZ
20251@value{GDBN} session. Or you may run @value{GDBN} and forget to
20252specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
20253via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
20254Program}). In these situations the @value{GDBN} commands to specify
0869d01b 20255new files are useful.
c906108c
SS
20256
20257@table @code
20258@cindex executable file
20259@kindex file
20260@item file @var{filename}
20261Use @var{filename} as the program to be debugged. It is read for its
20262symbols and for the contents of pure memory. It is also the program
20263executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
20264directory and the file is not found in the @value{GDBN} working directory,
20265@value{GDBN} uses the environment variable @code{PATH} as a list of
20266directories to search, just as the shell does when looking for a program
20267to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
20268and your program, using the @code{path} command.
20269
fc8be69e
EZ
20270@cindex unlinked object files
20271@cindex patching object files
20272You can load unlinked object @file{.o} files into @value{GDBN} using
20273the @code{file} command. You will not be able to ``run'' an object
20274file, but you can disassemble functions and inspect variables. Also,
20275if the underlying BFD functionality supports it, you could use
20276@kbd{gdb -write} to patch object files using this technique. Note
20277that @value{GDBN} can neither interpret nor modify relocations in this
20278case, so branches and some initialized variables will appear to go to
20279the wrong place. But this feature is still handy from time to time.
20280
c906108c
SS
20281@item file
20282@code{file} with no argument makes @value{GDBN} discard any information it
20283has on both executable file and the symbol table.
20284
20285@kindex exec-file
20286@item exec-file @r{[} @var{filename} @r{]}
20287Specify that the program to be run (but not the symbol table) is found
20288in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
20289if necessary to locate your program. Omitting @var{filename} means to
20290discard information on the executable file.
20291
20292@kindex symbol-file
d4d429d5 20293@item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
c906108c
SS
20294Read symbol table information from file @var{filename}. @code{PATH} is
20295searched when necessary. Use the @code{file} command to get both symbol
20296table and program to run from the same file.
20297
d4d429d5
PT
20298If an optional @var{offset} is specified, it is added to the start
20299address of each section in the symbol file. This is useful if the
20300program is relocated at runtime, such as the Linux kernel with kASLR
20301enabled.
20302
c906108c
SS
20303@code{symbol-file} with no argument clears out @value{GDBN} information on your
20304program's symbol table.
20305
ae5a43e0
DJ
20306The @code{symbol-file} command causes @value{GDBN} to forget the contents of
20307some breakpoints and auto-display expressions. This is because they may
20308contain pointers to the internal data recording symbols and data types,
20309which are part of the old symbol table data being discarded inside
20310@value{GDBN}.
c906108c
SS
20311
20312@code{symbol-file} does not repeat if you press @key{RET} again after
20313executing it once.
20314
20315When @value{GDBN} is configured for a particular environment, it
20316understands debugging information in whatever format is the standard
20317generated for that environment; you may use either a @sc{gnu} compiler, or
20318other compilers that adhere to the local conventions.
c906108c 20319Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 20320using @code{@value{NGCC}} you can generate debugging information for
c906108c 20321optimized code.
c906108c
SS
20322
20323For most kinds of object files, with the exception of old SVR3 systems
20324using COFF, the @code{symbol-file} command does not normally read the
20325symbol table in full right away. Instead, it scans the symbol table
20326quickly to find which source files and which symbols are present. The
20327details are read later, one source file at a time, as they are needed.
20328
20329The purpose of this two-stage reading strategy is to make @value{GDBN}
20330start up faster. For the most part, it is invisible except for
20331occasional pauses while the symbol table details for a particular source
20332file are being read. (The @code{set verbose} command can turn these
20333pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 20334Warnings and Messages}.)
c906108c 20335
c906108c
SS
20336We have not implemented the two-stage strategy for COFF yet. When the
20337symbol table is stored in COFF format, @code{symbol-file} reads the
20338symbol table data in full right away. Note that ``stabs-in-COFF''
20339still does the two-stage strategy, since the debug info is actually
20340in stabs format.
20341
20342@kindex readnow
20343@cindex reading symbols immediately
20344@cindex symbols, reading immediately
6ac33a4e
TT
20345@item symbol-file @r{[} -readnow @r{]} @var{filename}
20346@itemx file @r{[} -readnow @r{]} @var{filename}
c906108c
SS
20347You can override the @value{GDBN} two-stage strategy for reading symbol
20348tables by using the @samp{-readnow} option with any of the commands that
20349load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 20350entire symbol table available.
c906108c 20351
97cbe998
SDJ
20352@cindex @code{-readnever}, option for symbol-file command
20353@cindex never read symbols
20354@cindex symbols, never read
20355@item symbol-file @r{[} -readnever @r{]} @var{filename}
20356@itemx file @r{[} -readnever @r{]} @var{filename}
20357You can instruct @value{GDBN} to never read the symbolic information
20358contained in @var{filename} by using the @samp{-readnever} option.
20359@xref{--readnever}.
20360
c906108c
SS
20361@c FIXME: for now no mention of directories, since this seems to be in
20362@c flux. 13mar1992 status is that in theory GDB would look either in
20363@c current dir or in same dir as myprog; but issues like competing
20364@c GDB's, or clutter in system dirs, mean that in practice right now
20365@c only current dir is used. FFish says maybe a special GDB hierarchy
20366@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
20367@c files.
20368
c906108c 20369@kindex core-file
09d4efe1 20370@item core-file @r{[}@var{filename}@r{]}
4644b6e3 20371@itemx core
c906108c
SS
20372Specify the whereabouts of a core dump file to be used as the ``contents
20373of memory''. Traditionally, core files contain only some parts of the
20374address space of the process that generated them; @value{GDBN} can access the
20375executable file itself for other parts.
20376
20377@code{core-file} with no argument specifies that no core file is
20378to be used.
20379
20380Note that the core file is ignored when your program is actually running
7a292a7a
SS
20381under @value{GDBN}. So, if you have been running your program and you
20382wish to debug a core file instead, you must kill the subprocess in which
20383the program is running. To do this, use the @code{kill} command
79a6e687 20384(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 20385
c906108c
SS
20386@kindex add-symbol-file
20387@cindex dynamic linking
291f9a96 20388@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
20389The @code{add-symbol-file} command reads additional symbol table
20390information from the file @var{filename}. You would use this command
20391when @var{filename} has been dynamically loaded (by some other means)
ed6dfe51
PT
20392into the program that is running. The @var{textaddress} parameter gives
20393the memory address at which the file's text section has been loaded.
20394You can additionally specify the base address of other sections using
20395an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
20396If a section is omitted, @value{GDBN} will use its default addresses
20397as found in @var{filename}. Any @var{address} or @var{textaddress}
20398can be given as an expression.
c906108c 20399
291f9a96
PT
20400If an optional @var{offset} is specified, it is added to the start
20401address of each section, except those for which the address was
20402specified explicitly.
20403
c906108c
SS
20404The symbol table of the file @var{filename} is added to the symbol table
20405originally read with the @code{symbol-file} command. You can use the
96a2c332 20406@code{add-symbol-file} command any number of times; the new symbol data
98297bf6
NB
20407thus read is kept in addition to the old.
20408
20409Changes can be reverted using the command @code{remove-symbol-file}.
c906108c 20410
17d9d558
JB
20411@cindex relocatable object files, reading symbols from
20412@cindex object files, relocatable, reading symbols from
20413@cindex reading symbols from relocatable object files
20414@cindex symbols, reading from relocatable object files
20415@cindex @file{.o} files, reading symbols from
20416Although @var{filename} is typically a shared library file, an
20417executable file, or some other object file which has been fully
20418relocated for loading into a process, you can also load symbolic
20419information from relocatable @file{.o} files, as long as:
20420
20421@itemize @bullet
20422@item
20423the file's symbolic information refers only to linker symbols defined in
20424that file, not to symbols defined by other object files,
20425@item
20426every section the file's symbolic information refers to has actually
20427been loaded into the inferior, as it appears in the file, and
20428@item
20429you can determine the address at which every section was loaded, and
20430provide these to the @code{add-symbol-file} command.
20431@end itemize
20432
20433@noindent
20434Some embedded operating systems, like Sun Chorus and VxWorks, can load
20435relocatable files into an already running program; such systems
20436typically make the requirements above easy to meet. However, it's
20437important to recognize that many native systems use complex link
49efadf5 20438procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
20439assembly, for example) that make the requirements difficult to meet. In
20440general, one cannot assume that using @code{add-symbol-file} to read a
20441relocatable object file's symbolic information will have the same effect
20442as linking the relocatable object file into the program in the normal
20443way.
20444
c906108c
SS
20445@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
20446
98297bf6
NB
20447@kindex remove-symbol-file
20448@item remove-symbol-file @var{filename}
20449@item remove-symbol-file -a @var{address}
20450Remove a symbol file added via the @code{add-symbol-file} command. The
20451file to remove can be identified by its @var{filename} or by an @var{address}
20452that lies within the boundaries of this symbol file in memory. Example:
20453
20454@smallexample
20455(gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
20456add symbol table from file "/home/user/gdb/mylib.so" at
20457 .text_addr = 0x7ffff7ff9480
20458(y or n) y
0bab6cf1 20459Reading symbols from /home/user/gdb/mylib.so...
98297bf6
NB
20460(gdb) remove-symbol-file -a 0x7ffff7ff9480
20461Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
20462(gdb)
20463@end smallexample
20464
20465
20466@code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
20467
c45da7e6
EZ
20468@kindex add-symbol-file-from-memory
20469@cindex @code{syscall DSO}
20470@cindex load symbols from memory
20471@item add-symbol-file-from-memory @var{address}
20472Load symbols from the given @var{address} in a dynamically loaded
20473object file whose image is mapped directly into the inferior's memory.
20474For example, the Linux kernel maps a @code{syscall DSO} into each
20475process's address space; this DSO provides kernel-specific code for
20476some system calls. The argument can be any expression whose
20477evaluation yields the address of the file's shared object file header.
20478For this command to work, you must have used @code{symbol-file} or
20479@code{exec-file} commands in advance.
20480
c906108c 20481@kindex section
09d4efe1
EZ
20482@item section @var{section} @var{addr}
20483The @code{section} command changes the base address of the named
20484@var{section} of the exec file to @var{addr}. This can be used if the
20485exec file does not contain section addresses, (such as in the
20486@code{a.out} format), or when the addresses specified in the file
20487itself are wrong. Each section must be changed separately. The
20488@code{info files} command, described below, lists all the sections and
20489their addresses.
c906108c
SS
20490
20491@kindex info files
20492@kindex info target
20493@item info files
20494@itemx info target
7a292a7a
SS
20495@code{info files} and @code{info target} are synonymous; both print the
20496current target (@pxref{Targets, ,Specifying a Debugging Target}),
20497including the names of the executable and core dump files currently in
20498use by @value{GDBN}, and the files from which symbols were loaded. The
20499command @code{help target} lists all possible targets rather than
20500current ones.
20501
fe95c787
MS
20502@kindex maint info sections
20503@item maint info sections
20504Another command that can give you extra information about program sections
20505is @code{maint info sections}. In addition to the section information
20506displayed by @code{info files}, this command displays the flags and file
20507offset of each section in the executable and core dump files. In addition,
20508@code{maint info sections} provides the following command options (which
20509may be arbitrarily combined):
20510
20511@table @code
20512@item ALLOBJ
20513Display sections for all loaded object files, including shared libraries.
20514@item @var{sections}
6600abed 20515Display info only for named @var{sections}.
fe95c787
MS
20516@item @var{section-flags}
20517Display info only for sections for which @var{section-flags} are true.
20518The section flags that @value{GDBN} currently knows about are:
20519@table @code
20520@item ALLOC
20521Section will have space allocated in the process when loaded.
20522Set for all sections except those containing debug information.
20523@item LOAD
20524Section will be loaded from the file into the child process memory.
20525Set for pre-initialized code and data, clear for @code{.bss} sections.
20526@item RELOC
20527Section needs to be relocated before loading.
20528@item READONLY
20529Section cannot be modified by the child process.
20530@item CODE
20531Section contains executable code only.
6600abed 20532@item DATA
fe95c787
MS
20533Section contains data only (no executable code).
20534@item ROM
20535Section will reside in ROM.
20536@item CONSTRUCTOR
20537Section contains data for constructor/destructor lists.
20538@item HAS_CONTENTS
20539Section is not empty.
20540@item NEVER_LOAD
20541An instruction to the linker to not output the section.
20542@item COFF_SHARED_LIBRARY
20543A notification to the linker that the section contains
20544COFF shared library information.
20545@item IS_COMMON
20546Section contains common symbols.
20547@end table
20548@end table
6763aef9 20549@kindex set trust-readonly-sections
9c16f35a 20550@cindex read-only sections
6763aef9
MS
20551@item set trust-readonly-sections on
20552Tell @value{GDBN} that readonly sections in your object file
6ca652b0 20553really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
20554In that case, @value{GDBN} can fetch values from these sections
20555out of the object file, rather than from the target program.
20556For some targets (notably embedded ones), this can be a significant
20557enhancement to debugging performance.
20558
20559The default is off.
20560
20561@item set trust-readonly-sections off
15110bc3 20562Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
20563the contents of the section might change while the program is running,
20564and must therefore be fetched from the target when needed.
9c16f35a
EZ
20565
20566@item show trust-readonly-sections
20567Show the current setting of trusting readonly sections.
c906108c
SS
20568@end table
20569
20570All file-specifying commands allow both absolute and relative file names
20571as arguments. @value{GDBN} always converts the file name to an absolute file
20572name and remembers it that way.
20573
c906108c 20574@cindex shared libraries
9cceb671 20575@anchor{Shared Libraries}
b1236ac3
PA
20576@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
20577Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
20578DSBT (TIC6X) shared libraries.
53a5351d 20579
9cceb671
DJ
20580On MS-Windows @value{GDBN} must be linked with the Expat library to support
20581shared libraries. @xref{Expat}.
20582
c906108c
SS
20583@value{GDBN} automatically loads symbol definitions from shared libraries
20584when you use the @code{run} command, or when you examine a core file.
20585(Before you issue the @code{run} command, @value{GDBN} does not understand
20586references to a function in a shared library, however---unless you are
20587debugging a core file).
53a5351d 20588
c906108c
SS
20589@c FIXME: some @value{GDBN} release may permit some refs to undef
20590@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
20591@c FIXME...lib; check this from time to time when updating manual
20592
b7209cb4
FF
20593There are times, however, when you may wish to not automatically load
20594symbol definitions from shared libraries, such as when they are
20595particularly large or there are many of them.
20596
20597To control the automatic loading of shared library symbols, use the
20598commands:
20599
20600@table @code
20601@kindex set auto-solib-add
20602@item set auto-solib-add @var{mode}
20603If @var{mode} is @code{on}, symbols from all shared object libraries
20604will be loaded automatically when the inferior begins execution, you
20605attach to an independently started inferior, or when the dynamic linker
20606informs @value{GDBN} that a new library has been loaded. If @var{mode}
20607is @code{off}, symbols must be loaded manually, using the
20608@code{sharedlibrary} command. The default value is @code{on}.
20609
dcaf7c2c
EZ
20610@cindex memory used for symbol tables
20611If your program uses lots of shared libraries with debug info that
20612takes large amounts of memory, you can decrease the @value{GDBN}
20613memory footprint by preventing it from automatically loading the
20614symbols from shared libraries. To that end, type @kbd{set
20615auto-solib-add off} before running the inferior, then load each
20616library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 20617@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
20618the libraries whose symbols you want to be loaded.
20619
b7209cb4
FF
20620@kindex show auto-solib-add
20621@item show auto-solib-add
20622Display the current autoloading mode.
20623@end table
20624
c45da7e6 20625@cindex load shared library
b7209cb4
FF
20626To explicitly load shared library symbols, use the @code{sharedlibrary}
20627command:
20628
c906108c
SS
20629@table @code
20630@kindex info sharedlibrary
20631@kindex info share
55333a84
DE
20632@item info share @var{regex}
20633@itemx info sharedlibrary @var{regex}
20634Print the names of the shared libraries which are currently loaded
20635that match @var{regex}. If @var{regex} is omitted then print
20636all shared libraries that are loaded.
c906108c 20637
b30a0bc3
JB
20638@kindex info dll
20639@item info dll @var{regex}
20640This is an alias of @code{info sharedlibrary}.
20641
c906108c
SS
20642@kindex sharedlibrary
20643@kindex share
20644@item sharedlibrary @var{regex}
20645@itemx share @var{regex}
c906108c
SS
20646Load shared object library symbols for files matching a
20647Unix regular expression.
20648As with files loaded automatically, it only loads shared libraries
20649required by your program for a core file or after typing @code{run}. If
20650@var{regex} is omitted all shared libraries required by your program are
20651loaded.
c45da7e6
EZ
20652
20653@item nosharedlibrary
20654@kindex nosharedlibrary
20655@cindex unload symbols from shared libraries
20656Unload all shared object library symbols. This discards all symbols
20657that have been loaded from all shared libraries. Symbols from shared
20658libraries that were loaded by explicit user requests are not
20659discarded.
c906108c
SS
20660@end table
20661
721c2651 20662Sometimes you may wish that @value{GDBN} stops and gives you control
edcc5120
TT
20663when any of shared library events happen. The best way to do this is
20664to use @code{catch load} and @code{catch unload} (@pxref{Set
20665Catchpoints}).
20666
09f2921c 20667@value{GDBN} also supports the @code{set stop-on-solib-events}
edcc5120
TT
20668command for this. This command exists for historical reasons. It is
20669less useful than setting a catchpoint, because it does not allow for
20670conditions or commands as a catchpoint does.
721c2651
EZ
20671
20672@table @code
20673@item set stop-on-solib-events
20674@kindex set stop-on-solib-events
20675This command controls whether @value{GDBN} should give you control
20676when the dynamic linker notifies it about some shared library event.
20677The most common event of interest is loading or unloading of a new
20678shared library.
20679
20680@item show stop-on-solib-events
20681@kindex show stop-on-solib-events
20682Show whether @value{GDBN} stops and gives you control when shared
20683library events happen.
20684@end table
20685
f5ebfba0 20686Shared libraries are also supported in many cross or remote debugging
f1838a98
UW
20687configurations. @value{GDBN} needs to have access to the target's libraries;
20688this can be accomplished either by providing copies of the libraries
20689on the host system, or by asking @value{GDBN} to automatically retrieve the
20690libraries from the target. If copies of the target libraries are
20691provided, they need to be the same as the target libraries, although the
f5ebfba0
DJ
20692copies on the target can be stripped as long as the copies on the host are
20693not.
20694
59b7b46f
EZ
20695@cindex where to look for shared libraries
20696For remote debugging, you need to tell @value{GDBN} where the target
20697libraries are, so that it can load the correct copies---otherwise, it
20698may try to load the host's libraries. @value{GDBN} has two variables
20699to specify the search directories for target libraries.
f5ebfba0
DJ
20700
20701@table @code
a9a5a3d1 20702@cindex prefix for executable and shared library file names
f822c95b 20703@cindex system root, alternate
f5ebfba0 20704@kindex set solib-absolute-prefix
f822c95b
DJ
20705@kindex set sysroot
20706@item set sysroot @var{path}
20707Use @var{path} as the system root for the program being debugged. Any
20708absolute shared library paths will be prefixed with @var{path}; many
20709runtime loaders store the absolute paths to the shared library in the
a9a5a3d1
GB
20710target program's memory. When starting processes remotely, and when
20711attaching to already-running processes (local or remote), their
20712executable filenames will be prefixed with @var{path} if reported to
20713@value{GDBN} as absolute by the operating system. If you use
20714@code{set sysroot} to find executables and shared libraries, they need
20715to be laid out in the same way that they are on the target, with
20716e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
20717@var{path}.
f822c95b 20718
599bd15c
GB
20719If @var{path} starts with the sequence @file{target:} and the target
20720system is remote then @value{GDBN} will retrieve the target binaries
20721from the remote system. This is only supported when using a remote
20722target that supports the @code{remote get} command (@pxref{File
20723Transfer,,Sending files to a remote system}). The part of @var{path}
20724following the initial @file{target:} (if present) is used as system
20725root prefix on the remote file system. If @var{path} starts with the
20726sequence @file{remote:} this is converted to the sequence
20727@file{target:} by @code{set sysroot}@footnote{Historically the
20728functionality to retrieve binaries from the remote system was
20729provided by prefixing @var{path} with @file{remote:}}. If you want
20730to specify a local system root using a directory that happens to be
20731named @file{target:} or @file{remote:}, you need to use some
20732equivalent variant of the name like @file{./target:}.
f1838a98 20733
ab38a727
PA
20734For targets with an MS-DOS based filesystem, such as MS-Windows and
20735SymbianOS, @value{GDBN} tries prefixing a few variants of the target
20736absolute file name with @var{path}. But first, on Unix hosts,
20737@value{GDBN} converts all backslash directory separators into forward
20738slashes, because the backslash is not a directory separator on Unix:
20739
20740@smallexample
20741 c:\foo\bar.dll @result{} c:/foo/bar.dll
20742@end smallexample
20743
20744Then, @value{GDBN} attempts prefixing the target file name with
20745@var{path}, and looks for the resulting file name in the host file
20746system:
20747
20748@smallexample
20749 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
20750@end smallexample
20751
a9a5a3d1 20752If that does not find the binary, @value{GDBN} tries removing
ab38a727
PA
20753the @samp{:} character from the drive spec, both for convenience, and,
20754for the case of the host file system not supporting file names with
20755colons:
20756
20757@smallexample
20758 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
20759@end smallexample
20760
20761This makes it possible to have a system root that mirrors a target
20762with more than one drive. E.g., you may want to setup your local
20763copies of the target system shared libraries like so (note @samp{c} vs
20764@samp{z}):
20765
20766@smallexample
20767 @file{/path/to/sysroot/c/sys/bin/foo.dll}
20768 @file{/path/to/sysroot/c/sys/bin/bar.dll}
20769 @file{/path/to/sysroot/z/sys/bin/bar.dll}
20770@end smallexample
20771
20772@noindent
20773and point the system root at @file{/path/to/sysroot}, so that
20774@value{GDBN} can find the correct copies of both
20775@file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
20776
a9a5a3d1 20777If that still does not find the binary, @value{GDBN} tries
ab38a727
PA
20778removing the whole drive spec from the target file name:
20779
20780@smallexample
20781 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
20782@end smallexample
20783
20784This last lookup makes it possible to not care about the drive name,
20785if you don't want or need to.
20786
f822c95b
DJ
20787The @code{set solib-absolute-prefix} command is an alias for @code{set
20788sysroot}.
20789
20790@cindex default system root
59b7b46f 20791@cindex @samp{--with-sysroot}
f822c95b
DJ
20792You can set the default system root by using the configure-time
20793@samp{--with-sysroot} option. If the system root is inside
20794@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
20795@samp{--exec-prefix}), then the default system root will be updated
20796automatically if the installed @value{GDBN} is moved to a new
20797location.
20798
20799@kindex show sysroot
20800@item show sysroot
a9a5a3d1 20801Display the current executable and shared library prefix.
f5ebfba0
DJ
20802
20803@kindex set solib-search-path
20804@item set solib-search-path @var{path}
f822c95b
DJ
20805If this variable is set, @var{path} is a colon-separated list of
20806directories to search for shared libraries. @samp{solib-search-path}
20807is used after @samp{sysroot} fails to locate the library, or if the
20808path to the library is relative instead of absolute. If you want to
20809use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 20810@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 20811finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 20812it to a nonexistent directory may interfere with automatic loading
f822c95b 20813of shared library symbols.
f5ebfba0
DJ
20814
20815@kindex show solib-search-path
20816@item show solib-search-path
20817Display the current shared library search path.
ab38a727
PA
20818
20819@cindex DOS file-name semantics of file names.
20820@kindex set target-file-system-kind (unix|dos-based|auto)
20821@kindex show target-file-system-kind
20822@item set target-file-system-kind @var{kind}
20823Set assumed file system kind for target reported file names.
20824
20825Shared library file names as reported by the target system may not
20826make sense as is on the system @value{GDBN} is running on. For
20827example, when remote debugging a target that has MS-DOS based file
20828system semantics, from a Unix host, the target may be reporting to
20829@value{GDBN} a list of loaded shared libraries with file names such as
20830@file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
20831drive letters, so the @samp{c:\} prefix is not normally understood as
20832indicating an absolute file name, and neither is the backslash
20833normally considered a directory separator character. In that case,
20834the native file system would interpret this whole absolute file name
20835as a relative file name with no directory components. This would make
20836it impossible to point @value{GDBN} at a copy of the remote target's
20837shared libraries on the host using @code{set sysroot}, and impractical
20838with @code{set solib-search-path}. Setting
20839@code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
20840to interpret such file names similarly to how the target would, and to
20841map them to file names valid on @value{GDBN}'s native file system
20842semantics. The value of @var{kind} can be @code{"auto"}, in addition
20843to one of the supported file system kinds. In that case, @value{GDBN}
20844tries to determine the appropriate file system variant based on the
20845current target's operating system (@pxref{ABI, ,Configuring the
20846Current ABI}). The supported file system settings are:
20847
20848@table @code
20849@item unix
20850Instruct @value{GDBN} to assume the target file system is of Unix
20851kind. Only file names starting the forward slash (@samp{/}) character
20852are considered absolute, and the directory separator character is also
20853the forward slash.
20854
20855@item dos-based
20856Instruct @value{GDBN} to assume the target file system is DOS based.
20857File names starting with either a forward slash, or a drive letter
20858followed by a colon (e.g., @samp{c:}), are considered absolute, and
20859both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
20860considered directory separators.
20861
20862@item auto
20863Instruct @value{GDBN} to use the file system kind associated with the
20864target operating system (@pxref{ABI, ,Configuring the Current ABI}).
20865This is the default.
20866@end table
f5ebfba0
DJ
20867@end table
20868
c011a4f4
DE
20869@cindex file name canonicalization
20870@cindex base name differences
20871When processing file names provided by the user, @value{GDBN}
20872frequently needs to compare them to the file names recorded in the
20873program's debug info. Normally, @value{GDBN} compares just the
20874@dfn{base names} of the files as strings, which is reasonably fast
20875even for very large programs. (The base name of a file is the last
20876portion of its name, after stripping all the leading directories.)
20877This shortcut in comparison is based upon the assumption that files
20878cannot have more than one base name. This is usually true, but
20879references to files that use symlinks or similar filesystem
20880facilities violate that assumption. If your program records files
20881using such facilities, or if you provide file names to @value{GDBN}
20882using symlinks etc., you can set @code{basenames-may-differ} to
20883@code{true} to instruct @value{GDBN} to completely canonicalize each
20884pair of file names it needs to compare. This will make file-name
20885comparisons accurate, but at a price of a significant slowdown.
20886
20887@table @code
20888@item set basenames-may-differ
20889@kindex set basenames-may-differ
20890Set whether a source file may have multiple base names.
20891
20892@item show basenames-may-differ
20893@kindex show basenames-may-differ
20894Show whether a source file may have multiple base names.
20895@end table
5b5d99cf 20896
18989b3c
AB
20897@node File Caching
20898@section File Caching
20899@cindex caching of opened files
20900@cindex caching of bfd objects
20901
20902To speed up file loading, and reduce memory usage, @value{GDBN} will
20903reuse the @code{bfd} objects used to track open files. @xref{Top, ,
20904BFD, bfd, The Binary File Descriptor Library}. The following commands
20905allow visibility and control of the caching behavior.
20906
20907@table @code
20908@kindex maint info bfds
20909@item maint info bfds
20910This prints information about each @code{bfd} object that is known to
20911@value{GDBN}.
20912
20913@kindex maint set bfd-sharing
20914@kindex maint show bfd-sharing
20915@kindex bfd caching
20916@item maint set bfd-sharing
20917@item maint show bfd-sharing
20918Control whether @code{bfd} objects can be shared. When sharing is
20919enabled @value{GDBN} reuses already open @code{bfd} objects rather
20920than reopening the same file. Turning sharing off does not cause
20921already shared @code{bfd} objects to be unshared, but all future files
20922that are opened will create a new @code{bfd} object. Similarly,
20923re-enabling sharing does not cause multiple existing @code{bfd}
20924objects to be collapsed into a single shared @code{bfd} object.
566f5e3b
AB
20925
20926@kindex set debug bfd-cache @var{level}
20927@kindex bfd caching
20928@item set debug bfd-cache @var{level}
20929Turns on debugging of the bfd cache, setting the level to @var{level}.
20930
20931@kindex show debug bfd-cache
20932@kindex bfd caching
20933@item show debug bfd-cache
20934Show the current debugging level of the bfd cache.
18989b3c
AB
20935@end table
20936
5b5d99cf
JB
20937@node Separate Debug Files
20938@section Debugging Information in Separate Files
20939@cindex separate debugging information files
20940@cindex debugging information in separate files
20941@cindex @file{.debug} subdirectories
20942@cindex debugging information directory, global
f307c045 20943@cindex global debugging information directories
c7e83d54
EZ
20944@cindex build ID, and separate debugging files
20945@cindex @file{.build-id} directory
5b5d99cf
JB
20946
20947@value{GDBN} allows you to put a program's debugging information in a
20948file separate from the executable itself, in a way that allows
20949@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
20950Since debugging information can be very large---sometimes larger
20951than the executable code itself---some systems distribute debugging
5b5d99cf
JB
20952information for their executables in separate files, which users can
20953install only when they need to debug a problem.
20954
c7e83d54
EZ
20955@value{GDBN} supports two ways of specifying the separate debug info
20956file:
5b5d99cf
JB
20957
20958@itemize @bullet
20959@item
c7e83d54
EZ
20960The executable contains a @dfn{debug link} that specifies the name of
20961the separate debug info file. The separate debug file's name is
20962usually @file{@var{executable}.debug}, where @var{executable} is the
20963name of the corresponding executable file without leading directories
20964(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
99e008fe
EZ
20965debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
20966checksum for the debug file, which @value{GDBN} uses to validate that
20967the executable and the debug file came from the same build.
c7e83d54
EZ
20968
20969@item
98c59b52 20970@anchor{build ID}
7e27a47a 20971The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 20972also present in the corresponding debug info file. (This is supported
c74f7d1c 20973only on some operating systems, when using the ELF or PE file formats
7e27a47a
EZ
20974for binary files and the @sc{gnu} Binutils.) For more details about
20975this feature, see the description of the @option{--build-id}
f5a476a7 20976command-line option in @ref{Options, , Command Line Options, ld,
7e27a47a
EZ
20977The GNU Linker}. The debug info file's name is not specified
20978explicitly by the build ID, but can be computed from the build ID, see
20979below.
d3750b24
JK
20980@end itemize
20981
c7e83d54
EZ
20982Depending on the way the debug info file is specified, @value{GDBN}
20983uses two different methods of looking for the debug file:
d3750b24
JK
20984
20985@itemize @bullet
20986@item
c7e83d54
EZ
20987For the ``debug link'' method, @value{GDBN} looks up the named file in
20988the directory of the executable file, then in a subdirectory of that
5f2459c2
EZ
20989directory named @file{.debug}, and finally under each one of the
20990global debug directories, in a subdirectory whose name is identical to
20991the leading directories of the executable's absolute file name. (On
20992MS-Windows/MS-DOS, the drive letter of the executable's leading
20993directories is converted to a one-letter subdirectory, i.e.@:
20994@file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
20995filesystems disallow colons in file names.)
c7e83d54
EZ
20996
20997@item
83f83d7f 20998For the ``build ID'' method, @value{GDBN} looks in the
f307c045
JK
20999@file{.build-id} subdirectory of each one of the global debug directories for
21000a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
21001first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
21002are the rest of the bit string. (Real build ID strings are 32 or more
21003hex characters, not 10.)
c7e83d54
EZ
21004@end itemize
21005
21006So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
21007@file{/usr/bin/ls}, which has a debug link that specifies the
21008file @file{ls.debug}, and a build ID whose value in hex is
f307c045 21009@code{abcdef1234}. If the list of the global debug directories includes
c7e83d54
EZ
21010@file{/usr/lib/debug}, then @value{GDBN} will look for the following
21011debug information files, in the indicated order:
21012
21013@itemize @minus
21014@item
21015@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 21016@item
c7e83d54 21017@file{/usr/bin/ls.debug}
5b5d99cf 21018@item
c7e83d54 21019@file{/usr/bin/.debug/ls.debug}
5b5d99cf 21020@item
c7e83d54 21021@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 21022@end itemize
5b5d99cf 21023
1564a261
JK
21024@anchor{debug-file-directory}
21025Global debugging info directories default to what is set by @value{GDBN}
21026configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
21027you can also set the global debugging info directories, and view the list
21028@value{GDBN} is currently using.
5b5d99cf
JB
21029
21030@table @code
21031
21032@kindex set debug-file-directory
24ddea62
JK
21033@item set debug-file-directory @var{directories}
21034Set the directories which @value{GDBN} searches for separate debugging
d9242c17
JK
21035information files to @var{directory}. Multiple path components can be set
21036concatenating them by a path separator.
5b5d99cf
JB
21037
21038@kindex show debug-file-directory
21039@item show debug-file-directory
24ddea62 21040Show the directories @value{GDBN} searches for separate debugging
5b5d99cf
JB
21041information files.
21042
21043@end table
21044
21045@cindex @code{.gnu_debuglink} sections
c7e83d54 21046@cindex debug link sections
5b5d99cf
JB
21047A debug link is a special section of the executable file named
21048@code{.gnu_debuglink}. The section must contain:
21049
21050@itemize
21051@item
21052A filename, with any leading directory components removed, followed by
21053a zero byte,
21054@item
21055zero to three bytes of padding, as needed to reach the next four-byte
21056boundary within the section, and
21057@item
21058a four-byte CRC checksum, stored in the same endianness used for the
21059executable file itself. The checksum is computed on the debugging
21060information file's full contents by the function given below, passing
21061zero as the @var{crc} argument.
21062@end itemize
21063
21064Any executable file format can carry a debug link, as long as it can
21065contain a section named @code{.gnu_debuglink} with the contents
21066described above.
21067
d3750b24 21068@cindex @code{.note.gnu.build-id} sections
c7e83d54 21069@cindex build ID sections
7e27a47a
EZ
21070The build ID is a special section in the executable file (and in other
21071ELF binary files that @value{GDBN} may consider). This section is
21072often named @code{.note.gnu.build-id}, but that name is not mandatory.
21073It contains unique identification for the built files---the ID remains
21074the same across multiple builds of the same build tree. The default
21075algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
21076content for the build ID string. The same section with an identical
21077value is present in the original built binary with symbols, in its
21078stripped variant, and in the separate debugging information file.
d3750b24 21079
5b5d99cf
JB
21080The debugging information file itself should be an ordinary
21081executable, containing a full set of linker symbols, sections, and
21082debugging information. The sections of the debugging information file
c7e83d54
EZ
21083should have the same names, addresses, and sizes as the original file,
21084but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
21085in an ordinary executable.
21086
7e27a47a 21087The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
21088@samp{objcopy} utility that can produce
21089the separated executable / debugging information file pairs using the
21090following commands:
21091
21092@smallexample
21093@kbd{objcopy --only-keep-debug foo foo.debug}
21094@kbd{strip -g foo}
c7e83d54
EZ
21095@end smallexample
21096
21097@noindent
21098These commands remove the debugging
83f83d7f
JK
21099information from the executable file @file{foo} and place it in the file
21100@file{foo.debug}. You can use the first, second or both methods to link the
21101two files:
21102
21103@itemize @bullet
21104@item
21105The debug link method needs the following additional command to also leave
21106behind a debug link in @file{foo}:
21107
21108@smallexample
21109@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
21110@end smallexample
21111
21112Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 21113a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
21114foo.debug} has the same functionality as the two @code{objcopy} commands and
21115the @code{ln -s} command above, together.
21116
21117@item
21118Build ID gets embedded into the main executable using @code{ld --build-id} or
21119the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
21120compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 21121utilities (Binutils) package since version 2.18.
83f83d7f
JK
21122@end itemize
21123
21124@noindent
d3750b24 21125
99e008fe
EZ
21126@cindex CRC algorithm definition
21127The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
21128IEEE 802.3 using the polynomial:
21129
21130@c TexInfo requires naked braces for multi-digit exponents for Tex
21131@c output, but this causes HTML output to barf. HTML has to be set using
21132@c raw commands. So we end up having to specify this equation in 2
21133@c different ways!
21134@ifhtml
21135@display
21136@html
21137 <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>
21138 + <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
21139@end html
21140@end display
21141@end ifhtml
21142@ifnothtml
21143@display
21144 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
21145 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
21146@end display
21147@end ifnothtml
21148
21149The function is computed byte at a time, taking the least
21150significant bit of each byte first. The initial pattern
21151@code{0xffffffff} is used, to ensure leading zeros affect the CRC and
21152the final result is inverted to ensure trailing zeros also affect the
21153CRC.
21154
21155@emph{Note:} This is the same CRC polynomial as used in handling the
936d2992
PA
21156@dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
21157However in the case of the Remote Serial Protocol, the CRC is computed
21158@emph{most} significant bit first, and the result is not inverted, so
21159trailing zeros have no effect on the CRC value.
99e008fe
EZ
21160
21161To complete the description, we show below the code of the function
21162which produces the CRC used in @code{.gnu_debuglink}. Inverting the
21163initially supplied @code{crc} argument means that an initial call to
21164this function passing in zero will start computing the CRC using
21165@code{0xffffffff}.
5b5d99cf 21166
4644b6e3 21167@kindex gnu_debuglink_crc32
5b5d99cf
JB
21168@smallexample
21169unsigned long
21170gnu_debuglink_crc32 (unsigned long crc,
21171 unsigned char *buf, size_t len)
21172@{
21173 static const unsigned long crc32_table[256] =
21174 @{
21175 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
21176 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
21177 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
21178 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
21179 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
21180 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
21181 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
21182 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
21183 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
21184 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
21185 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
21186 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
21187 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
21188 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
21189 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
21190 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
21191 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
21192 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
21193 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
21194 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
21195 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
21196 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
21197 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
21198 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
21199 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
21200 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
21201 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
21202 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
21203 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
21204 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
21205 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
21206 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
21207 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
21208 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
21209 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
21210 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
21211 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
21212 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
21213 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
21214 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
21215 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
21216 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
21217 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
21218 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
21219 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
21220 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
21221 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
21222 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
21223 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
21224 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
21225 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
21226 0x2d02ef8d
21227 @};
21228 unsigned char *end;
21229
21230 crc = ~crc & 0xffffffff;
21231 for (end = buf + len; buf < end; ++buf)
21232 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 21233 return ~crc & 0xffffffff;
5b5d99cf
JB
21234@}
21235@end smallexample
21236
c7e83d54
EZ
21237@noindent
21238This computation does not apply to the ``build ID'' method.
21239
608e2dbb
TT
21240@node MiniDebugInfo
21241@section Debugging information in a special section
21242@cindex separate debug sections
21243@cindex @samp{.gnu_debugdata} section
21244
21245Some systems ship pre-built executables and libraries that have a
21246special @samp{.gnu_debugdata} section. This feature is called
21247@dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
21248is used to supply extra symbols for backtraces.
21249
21250The intent of this section is to provide extra minimal debugging
21251information for use in simple backtraces. It is not intended to be a
21252replacement for full separate debugging information (@pxref{Separate
21253Debug Files}). The example below shows the intended use; however,
21254@value{GDBN} does not currently put restrictions on what sort of
21255debugging information might be included in the section.
21256
21257@value{GDBN} has support for this extension. If the section exists,
21258then it is used provided that no other source of debugging information
21259can be found, and that @value{GDBN} was configured with LZMA support.
21260
21261This section can be easily created using @command{objcopy} and other
21262standard utilities:
21263
21264@smallexample
21265# Extract the dynamic symbols from the main binary, there is no need
5423b017 21266# to also have these in the normal symbol table.
608e2dbb
TT
21267nm -D @var{binary} --format=posix --defined-only \
21268 | awk '@{ print $1 @}' | sort > dynsyms
21269
5423b017 21270# Extract all the text (i.e. function) symbols from the debuginfo.
1d236d23
JK
21271# (Note that we actually also accept "D" symbols, for the benefit
21272# of platforms like PowerPC64 that use function descriptors.)
608e2dbb 21273nm @var{binary} --format=posix --defined-only \
1d236d23 21274 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
608e2dbb
TT
21275 | sort > funcsyms
21276
21277# Keep all the function symbols not already in the dynamic symbol
21278# table.
21279comm -13 dynsyms funcsyms > keep_symbols
21280
edf9f00c
JK
21281# Separate full debug info into debug binary.
21282objcopy --only-keep-debug @var{binary} debug
21283
608e2dbb
TT
21284# Copy the full debuginfo, keeping only a minimal set of symbols and
21285# removing some unnecessary sections.
21286objcopy -S --remove-section .gdb_index --remove-section .comment \
edf9f00c
JK
21287 --keep-symbols=keep_symbols debug mini_debuginfo
21288
21289# Drop the full debug info from the original binary.
21290strip --strip-all -R .comment @var{binary}
608e2dbb
TT
21291
21292# Inject the compressed data into the .gnu_debugdata section of the
21293# original binary.
21294xz mini_debuginfo
21295objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
21296@end smallexample
5b5d99cf 21297
9291a0cd
TT
21298@node Index Files
21299@section Index Files Speed Up @value{GDBN}
21300@cindex index files
21301@cindex @samp{.gdb_index} section
21302
21303When @value{GDBN} finds a symbol file, it scans the symbols in the
21304file in order to construct an internal symbol table. This lets most
21305@value{GDBN} operations work quickly---at the cost of a delay early
21306on. For large programs, this delay can be quite lengthy, so
21307@value{GDBN} provides a way to build an index, which speeds up
21308startup.
21309
ba643918
SDJ
21310For convenience, @value{GDBN} comes with a program,
21311@command{gdb-add-index}, which can be used to add the index to a
21312symbol file. It takes the symbol file as its only argument:
21313
21314@smallexample
21315$ gdb-add-index symfile
21316@end smallexample
21317
21318@xref{gdb-add-index}.
21319
21320It is also possible to do the work manually. Here is what
21321@command{gdb-add-index} does behind the curtains.
21322
9291a0cd
TT
21323The index is stored as a section in the symbol file. @value{GDBN} can
21324write the index to a file, then you can put it into the symbol file
21325using @command{objcopy}.
21326
21327To create an index file, use the @code{save gdb-index} command:
21328
21329@table @code
437afbb8 21330@item save gdb-index [-dwarf-5] @var{directory}
9291a0cd 21331@kindex save gdb-index
437afbb8
JK
21332Create index files for all symbol files currently known by
21333@value{GDBN}. For each known @var{symbol-file}, this command by
21334default creates it produces a single file
21335@file{@var{symbol-file}.gdb-index}. If you invoke this command with
21336the @option{-dwarf-5} option, it produces 2 files:
21337@file{@var{symbol-file}.debug_names} and
21338@file{@var{symbol-file}.debug_str}. The files are created in the
21339given @var{directory}.
9291a0cd
TT
21340@end table
21341
21342Once you have created an index file you can merge it into your symbol
21343file, here named @file{symfile}, using @command{objcopy}:
21344
21345@smallexample
21346$ objcopy --add-section .gdb_index=symfile.gdb-index \
21347 --set-section-flags .gdb_index=readonly symfile symfile
21348@end smallexample
21349
437afbb8
JK
21350Or for @code{-dwarf-5}:
21351
21352@smallexample
21353$ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
21354$ cat symfile.debug_str >>symfile.debug_str.new
21355$ objcopy --add-section .debug_names=symfile.gdb-index \
21356 --set-section-flags .debug_names=readonly \
21357 --update-section .debug_str=symfile.debug_str.new symfile symfile
21358@end smallexample
21359
e615022a
DE
21360@value{GDBN} will normally ignore older versions of @file{.gdb_index}
21361sections that have been deprecated. Usually they are deprecated because
21362they are missing a new feature or have performance issues.
21363To tell @value{GDBN} to use a deprecated index section anyway
21364specify @code{set use-deprecated-index-sections on}.
21365The default is @code{off}.
21366This can speed up startup, but may result in some functionality being lost.
21367@xref{Index Section Format}.
21368
21369@emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
21370must be done before gdb reads the file. The following will not work:
21371
21372@smallexample
21373$ gdb -ex "set use-deprecated-index-sections on" <program>
21374@end smallexample
21375
21376Instead you must do, for example,
21377
21378@smallexample
21379$ gdb -iex "set use-deprecated-index-sections on" <program>
21380@end smallexample
21381
914592f9 21382Indices only work when using DWARF debugging information, not stabs.
9291a0cd 21383
7d11235d
SM
21384@subsection Automatic symbol index cache
21385
a0a3a1e9 21386@cindex automatic symbol index cache
7d11235d
SM
21387It is possible for @value{GDBN} to automatically save a copy of this index in a
21388cache on disk and retrieve it from there when loading the same binary in the
21389future. This feature can be turned on with @kbd{set index-cache on}. The
21390following commands can be used to tweak the behavior of the index cache.
21391
21392@table @code
21393
a0a3a1e9 21394@kindex set index-cache
7d11235d
SM
21395@item set index-cache on
21396@itemx set index-cache off
21397Enable or disable the use of the symbol index cache.
21398
21399@item set index-cache directory @var{directory}
a0a3a1e9 21400@kindex show index-cache
7d11235d 21401@itemx show index-cache directory
e6cd1dc1
TT
21402Set/show the directory where index files will be saved.
21403
21404The default value for this directory depends on the host platform. On
21405most systems, the index is cached in the @file{gdb} subdirectory of
21406the directory pointed to by the @env{XDG_CACHE_HOME} environment
21407variable, if it is defined, else in the @file{.cache/gdb} subdirectory
21408of your home directory. However, on some systems, the default may
21409differ according to local convention.
7d11235d
SM
21410
21411There is no limit on the disk space used by index cache. It is perfectly safe
21412to delete the content of that directory to free up disk space.
21413
21414@item show index-cache stats
21415Print the number of cache hits and misses since the launch of @value{GDBN}.
21416
21417@end table
21418
6d2ebf8b 21419@node Symbol Errors
79a6e687 21420@section Errors Reading Symbol Files
c906108c
SS
21421
21422While reading a symbol file, @value{GDBN} occasionally encounters problems,
21423such as symbol types it does not recognize, or known bugs in compiler
21424output. By default, @value{GDBN} does not notify you of such problems, since
21425they are relatively common and primarily of interest to people
21426debugging compilers. If you are interested in seeing information
21427about ill-constructed symbol tables, you can either ask @value{GDBN} to print
21428only one message about each such type of problem, no matter how many
21429times the problem occurs; or you can ask @value{GDBN} to print more messages,
21430to see how many times the problems occur, with the @code{set
79a6e687
BW
21431complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
21432Messages}).
c906108c
SS
21433
21434The messages currently printed, and their meanings, include:
21435
21436@table @code
21437@item inner block not inside outer block in @var{symbol}
21438
21439The symbol information shows where symbol scopes begin and end
21440(such as at the start of a function or a block of statements). This
21441error indicates that an inner scope block is not fully contained
21442in its outer scope blocks.
21443
21444@value{GDBN} circumvents the problem by treating the inner block as if it had
21445the same scope as the outer block. In the error message, @var{symbol}
21446may be shown as ``@code{(don't know)}'' if the outer block is not a
21447function.
21448
21449@item block at @var{address} out of order
21450
21451The symbol information for symbol scope blocks should occur in
21452order of increasing addresses. This error indicates that it does not
21453do so.
21454
21455@value{GDBN} does not circumvent this problem, and has trouble
21456locating symbols in the source file whose symbols it is reading. (You
21457can often determine what source file is affected by specifying
79a6e687
BW
21458@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
21459Messages}.)
c906108c
SS
21460
21461@item bad block start address patched
21462
21463The symbol information for a symbol scope block has a start address
21464smaller than the address of the preceding source line. This is known
21465to occur in the SunOS 4.1.1 (and earlier) C compiler.
21466
21467@value{GDBN} circumvents the problem by treating the symbol scope block as
21468starting on the previous source line.
21469
21470@item bad string table offset in symbol @var{n}
21471
21472@cindex foo
21473Symbol number @var{n} contains a pointer into the string table which is
21474larger than the size of the string table.
21475
21476@value{GDBN} circumvents the problem by considering the symbol to have the
21477name @code{foo}, which may cause other problems if many symbols end up
21478with this name.
21479
21480@item unknown symbol type @code{0x@var{nn}}
21481
7a292a7a
SS
21482The symbol information contains new data types that @value{GDBN} does
21483not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 21484uncomprehended information, in hexadecimal.
c906108c 21485
7a292a7a
SS
21486@value{GDBN} circumvents the error by ignoring this symbol information.
21487This usually allows you to debug your program, though certain symbols
c906108c 21488are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
21489debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
21490on @code{complain}, then go up to the function @code{read_dbx_symtab}
21491and examine @code{*bufp} to see the symbol.
c906108c
SS
21492
21493@item stub type has NULL name
c906108c 21494
7a292a7a 21495@value{GDBN} could not find the full definition for a struct or class.
c906108c 21496
7a292a7a 21497@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 21498The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
21499information that recent versions of the compiler should have output for
21500it.
c906108c
SS
21501
21502@item info mismatch between compiler and debugger
21503
21504@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 21505
c906108c
SS
21506@end table
21507
b14b1491
TT
21508@node Data Files
21509@section GDB Data Files
21510
21511@cindex prefix for data files
21512@value{GDBN} will sometimes read an auxiliary data file. These files
21513are kept in a directory known as the @dfn{data directory}.
21514
21515You can set the data directory's name, and view the name @value{GDBN}
21516is currently using.
21517
21518@table @code
21519@kindex set data-directory
21520@item set data-directory @var{directory}
21521Set the directory which @value{GDBN} searches for auxiliary data files
21522to @var{directory}.
21523
21524@kindex show data-directory
21525@item show data-directory
21526Show the directory @value{GDBN} searches for auxiliary data files.
21527@end table
21528
21529@cindex default data directory
21530@cindex @samp{--with-gdb-datadir}
21531You can set the default data directory by using the configure-time
21532@samp{--with-gdb-datadir} option. If the data directory is inside
21533@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21534@samp{--exec-prefix}), then the default data directory will be updated
21535automatically if the installed @value{GDBN} is moved to a new
21536location.
21537
aae1c79a
DE
21538The data directory may also be specified with the
21539@code{--data-directory} command line option.
21540@xref{Mode Options}.
21541
6d2ebf8b 21542@node Targets
c906108c 21543@chapter Specifying a Debugging Target
7a292a7a 21544
c906108c 21545@cindex debugging target
c906108c 21546A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
21547
21548Often, @value{GDBN} runs in the same host environment as your program;
21549in that case, the debugging target is specified as a side effect when
21550you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
21551flexibility---for example, running @value{GDBN} on a physically separate
21552host, or controlling a standalone system over a serial port or a
53a5351d
JM
21553realtime system over a TCP/IP connection---you can use the @code{target}
21554command to specify one of the target types configured for @value{GDBN}
79a6e687 21555(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 21556
a8f24a35
EZ
21557@cindex target architecture
21558It is possible to build @value{GDBN} for several different @dfn{target
21559architectures}. When @value{GDBN} is built like that, you can choose
21560one of the available architectures with the @kbd{set architecture}
21561command.
21562
21563@table @code
21564@kindex set architecture
21565@kindex show architecture
21566@item set architecture @var{arch}
21567This command sets the current target architecture to @var{arch}. The
21568value of @var{arch} can be @code{"auto"}, in addition to one of the
21569supported architectures.
21570
21571@item show architecture
21572Show the current target architecture.
9c16f35a
EZ
21573
21574@item set processor
21575@itemx processor
21576@kindex set processor
21577@kindex show processor
21578These are alias commands for, respectively, @code{set architecture}
21579and @code{show architecture}.
a8f24a35
EZ
21580@end table
21581
c906108c
SS
21582@menu
21583* Active Targets:: Active targets
21584* Target Commands:: Commands for managing targets
c906108c 21585* Byte Order:: Choosing target byte order
c906108c
SS
21586@end menu
21587
6d2ebf8b 21588@node Active Targets
79a6e687 21589@section Active Targets
7a292a7a 21590
c906108c
SS
21591@cindex stacking targets
21592@cindex active targets
21593@cindex multiple targets
21594
8ea5bce5 21595There are multiple classes of targets such as: processes, executable files or
c0edd9ed
JK
21596recording sessions. Core files belong to the process class, making core file
21597and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
21598on multiple active targets, one in each class. This allows you to (for
21599example) start a process and inspect its activity, while still having access to
21600the executable file after the process finishes. Or if you start process
21601recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
21602presented a virtual layer of the recording target, while the process target
21603remains stopped at the chronologically last point of the process execution.
21604
21605Use the @code{core-file} and @code{exec-file} commands to select a new core
21606file or executable target (@pxref{Files, ,Commands to Specify Files}). To
21607specify as a target a process that is already running, use the @code{attach}
21608command (@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 21609
6d2ebf8b 21610@node Target Commands
79a6e687 21611@section Commands for Managing Targets
c906108c
SS
21612
21613@table @code
21614@item target @var{type} @var{parameters}
7a292a7a
SS
21615Connects the @value{GDBN} host environment to a target machine or
21616process. A target is typically a protocol for talking to debugging
21617facilities. You use the argument @var{type} to specify the type or
21618protocol of the target machine.
c906108c
SS
21619
21620Further @var{parameters} are interpreted by the target protocol, but
21621typically include things like device names or host names to connect
21622with, process numbers, and baud rates.
c906108c
SS
21623
21624The @code{target} command does not repeat if you press @key{RET} again
21625after executing the command.
21626
21627@kindex help target
21628@item help target
21629Displays the names of all targets available. To display targets
21630currently selected, use either @code{info target} or @code{info files}
79a6e687 21631(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
21632
21633@item help target @var{name}
21634Describe a particular target, including any parameters necessary to
21635select it.
21636
21637@kindex set gnutarget
21638@item set gnutarget @var{args}
5d161b24 21639@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 21640knows whether it is reading an @dfn{executable},
5d161b24
DB
21641a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
21642with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
21643with @code{gnutarget} the @code{target} refers to a program, not a machine.
21644
d4f3574e 21645@quotation
c906108c
SS
21646@emph{Warning:} To specify a file format with @code{set gnutarget},
21647you must know the actual BFD name.
d4f3574e 21648@end quotation
c906108c 21649
d4f3574e 21650@noindent
79a6e687 21651@xref{Files, , Commands to Specify Files}.
c906108c 21652
5d161b24 21653@kindex show gnutarget
c906108c
SS
21654@item show gnutarget
21655Use the @code{show gnutarget} command to display what file format
21656@code{gnutarget} is set to read. If you have not set @code{gnutarget},
21657@value{GDBN} will determine the file format for each file automatically,
c4957902 21658and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
c906108c
SS
21659@end table
21660
4644b6e3 21661@cindex common targets
c906108c
SS
21662Here are some common targets (available, or not, depending on the GDB
21663configuration):
c906108c
SS
21664
21665@table @code
4644b6e3 21666@kindex target
c906108c 21667@item target exec @var{program}
4644b6e3 21668@cindex executable file target
c906108c
SS
21669An executable file. @samp{target exec @var{program}} is the same as
21670@samp{exec-file @var{program}}.
21671
c906108c 21672@item target core @var{filename}
4644b6e3 21673@cindex core dump file target
c906108c
SS
21674A core dump file. @samp{target core @var{filename}} is the same as
21675@samp{core-file @var{filename}}.
c906108c 21676
1a10341b 21677@item target remote @var{medium}
4644b6e3 21678@cindex remote target
1a10341b
JB
21679A remote system connected to @value{GDBN} via a serial line or network
21680connection. This command tells @value{GDBN} to use its own remote
21681protocol over @var{medium} for debugging. @xref{Remote Debugging}.
21682
21683For example, if you have a board connected to @file{/dev/ttya} on the
21684machine running @value{GDBN}, you could say:
21685
21686@smallexample
21687target remote /dev/ttya
21688@end smallexample
21689
21690@code{target remote} supports the @code{load} command. This is only
21691useful if you have some other way of getting the stub to the target
21692system, and you can put it somewhere in memory where it won't get
21693clobbered by the download.
c906108c 21694
ee8e71d4 21695@item target sim @r{[}@var{simargs}@r{]} @dots{}
4644b6e3 21696@cindex built-in simulator target
2df3850c 21697Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 21698In general,
474c8240 21699@smallexample
104c1213
JM
21700 target sim
21701 load
21702 run
474c8240 21703@end smallexample
d4f3574e 21704@noindent
104c1213 21705works; however, you cannot assume that a specific memory map, device
d4f3574e 21706drivers, or even basic I/O is available, although some simulators do
104c1213
JM
21707provide these. For info about any processor-specific simulator details,
21708see the appropriate section in @ref{Embedded Processors, ,Embedded
21709Processors}.
21710
6a3cb8e8
PA
21711@item target native
21712@cindex native target
21713Setup for local/native process debugging. Useful to make the
21714@code{run} command spawn native processes (likewise @code{attach},
21715etc.@:) even when @code{set auto-connect-native-target} is @code{off}
21716(@pxref{set auto-connect-native-target}).
21717
c906108c
SS
21718@end table
21719
5d161b24 21720Different targets are available on different configurations of @value{GDBN};
c906108c 21721your configuration may have more or fewer targets.
c906108c 21722
721c2651
EZ
21723Many remote targets require you to download the executable's code once
21724you've successfully established a connection. You may wish to control
3d00d119
DJ
21725various aspects of this process.
21726
21727@table @code
721c2651
EZ
21728
21729@item set hash
21730@kindex set hash@r{, for remote monitors}
21731@cindex hash mark while downloading
21732This command controls whether a hash mark @samp{#} is displayed while
21733downloading a file to the remote monitor. If on, a hash mark is
21734displayed after each S-record is successfully downloaded to the
21735monitor.
21736
21737@item show hash
21738@kindex show hash@r{, for remote monitors}
21739Show the current status of displaying the hash mark.
21740
21741@item set debug monitor
21742@kindex set debug monitor
21743@cindex display remote monitor communications
21744Enable or disable display of communications messages between
21745@value{GDBN} and the remote monitor.
21746
21747@item show debug monitor
21748@kindex show debug monitor
21749Show the current status of displaying communications between
21750@value{GDBN} and the remote monitor.
a8f24a35 21751@end table
c906108c
SS
21752
21753@table @code
21754
5cf30ebf
LM
21755@kindex load @var{filename} @var{offset}
21756@item load @var{filename} @var{offset}
8edfe269 21757@anchor{load}
c906108c
SS
21758Depending on what remote debugging facilities are configured into
21759@value{GDBN}, the @code{load} command may be available. Where it exists, it
21760is meant to make @var{filename} (an executable) available for debugging
21761on the remote system---by downloading, or dynamic linking, for example.
21762@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
21763the @code{add-symbol-file} command.
21764
21765If your @value{GDBN} does not have a @code{load} command, attempting to
21766execute it gets the error message ``@code{You can't do that when your
21767target is @dots{}}''
c906108c
SS
21768
21769The file is loaded at whatever address is specified in the executable.
21770For some object file formats, you can specify the load address when you
21771link the program; for other formats, like a.out, the object file format
21772specifies a fixed address.
21773@c FIXME! This would be a good place for an xref to the GNU linker doc.
21774
5cf30ebf
LM
21775It is also possible to tell @value{GDBN} to load the executable file at a
21776specific offset described by the optional argument @var{offset}. When
21777@var{offset} is provided, @var{filename} must also be provided.
21778
68437a39
DJ
21779Depending on the remote side capabilities, @value{GDBN} may be able to
21780load programs into flash memory.
21781
c906108c
SS
21782@code{load} does not repeat if you press @key{RET} again after using it.
21783@end table
21784
78cbbba8
LM
21785@table @code
21786
21787@kindex flash-erase
21788@item flash-erase
21789@anchor{flash-erase}
21790
21791Erases all known flash memory regions on the target.
21792
21793@end table
21794
6d2ebf8b 21795@node Byte Order
79a6e687 21796@section Choosing Target Byte Order
7a292a7a 21797
c906108c
SS
21798@cindex choosing target byte order
21799@cindex target byte order
c906108c 21800
eb17f351 21801Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
c906108c
SS
21802offer the ability to run either big-endian or little-endian byte
21803orders. Usually the executable or symbol will include a bit to
21804designate the endian-ness, and you will not need to worry about
21805which to use. However, you may still find it useful to adjust
d4f3574e 21806@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
21807
21808@table @code
4644b6e3 21809@kindex set endian
c906108c
SS
21810@item set endian big
21811Instruct @value{GDBN} to assume the target is big-endian.
21812
c906108c
SS
21813@item set endian little
21814Instruct @value{GDBN} to assume the target is little-endian.
21815
c906108c
SS
21816@item set endian auto
21817Instruct @value{GDBN} to use the byte order associated with the
21818executable.
21819
21820@item show endian
21821Display @value{GDBN}'s current idea of the target byte order.
21822
21823@end table
21824
4b2dfa9d
MR
21825If the @code{set endian auto} mode is in effect and no executable has
21826been selected, then the endianness used is the last one chosen either
21827by one of the @code{set endian big} and @code{set endian little}
21828commands or by inferring from the last executable used. If no
21829endianness has been previously chosen, then the default for this mode
21830is inferred from the target @value{GDBN} has been built for, and is
21831@code{little} if the name of the target CPU has an @code{el} suffix
21832and @code{big} otherwise.
21833
c906108c
SS
21834Note that these commands merely adjust interpretation of symbolic
21835data on the host, and that they have absolutely no effect on the
21836target system.
21837
ea35711c
DJ
21838
21839@node Remote Debugging
21840@chapter Debugging Remote Programs
c906108c
SS
21841@cindex remote debugging
21842
21843If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
21844@value{GDBN} in the usual way, it is often useful to use remote debugging.
21845For example, you might use remote debugging on an operating system kernel,
c906108c
SS
21846or on a small system which does not have a general purpose operating system
21847powerful enough to run a full-featured debugger.
21848
21849Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
21850to make this work with particular debugging targets. In addition,
5d161b24 21851@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
21852but not specific to any particular target system) which you can use if you
21853write the remote stubs---the code that runs on the remote system to
21854communicate with @value{GDBN}.
21855
21856Other remote targets may be available in your
21857configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 21858
6b2f586d 21859@menu
07f31aa6 21860* Connecting:: Connecting to a remote target
a6b151f1 21861* File Transfer:: Sending files to a remote system
6b2f586d 21862* Server:: Using the gdbserver program
79a6e687
BW
21863* Remote Configuration:: Remote configuration
21864* Remote Stub:: Implementing a remote stub
6b2f586d
AC
21865@end menu
21866
07f31aa6 21867@node Connecting
79a6e687 21868@section Connecting to a Remote Target
19d9d4ef
DB
21869@cindex remote debugging, connecting
21870@cindex @code{gdbserver}, connecting
21871@cindex remote debugging, types of connections
21872@cindex @code{gdbserver}, types of connections
21873@cindex @code{gdbserver}, @code{target remote} mode
21874@cindex @code{gdbserver}, @code{target extended-remote} mode
21875
21876This section describes how to connect to a remote target, including the
21877types of connections and their differences, how to set up executable and
21878symbol files on the host and target, and the commands used for
21879connecting to and disconnecting from the remote target.
21880
21881@subsection Types of Remote Connections
21882
21883@value{GDBN} supports two types of remote connections, @code{target remote}
21884mode and @code{target extended-remote} mode. Note that many remote targets
21885support only @code{target remote} mode. There are several major
21886differences between the two types of connections, enumerated here:
21887
21888@table @asis
21889
21890@cindex remote debugging, detach and program exit
21891@item Result of detach or program exit
21892@strong{With target remote mode:} When the debugged program exits or you
21893detach from it, @value{GDBN} disconnects from the target. When using
21894@code{gdbserver}, @code{gdbserver} will exit.
21895
21896@strong{With target extended-remote mode:} When the debugged program exits or
21897you detach from it, @value{GDBN} remains connected to the target, even
21898though no program is running. You can rerun the program, attach to a
21899running program, or use @code{monitor} commands specific to the target.
21900
21901When using @code{gdbserver} in this case, it does not exit unless it was
21902invoked using the @option{--once} option. If the @option{--once} option
21903was not used, you can ask @code{gdbserver} to exit using the
21904@code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
21905
21906@item Specifying the program to debug
21907For both connection types you use the @code{file} command to specify the
21908program on the host system. If you are using @code{gdbserver} there are
21909some differences in how to specify the location of the program on the
21910target.
21911
21912@strong{With target remote mode:} You must either specify the program to debug
21913on the @code{gdbserver} command line or use the @option{--attach} option
21914(@pxref{Attaching to a program,,Attaching to a Running Program}).
21915
21916@cindex @option{--multi}, @code{gdbserver} option
21917@strong{With target extended-remote mode:} You may specify the program to debug
21918on the @code{gdbserver} command line, or you can load the program or attach
21919to it using @value{GDBN} commands after connecting to @code{gdbserver}.
21920
21921@anchor{--multi Option in Types of Remote Connnections}
21922You can start @code{gdbserver} without supplying an initial command to run
21923or process ID to attach. To do this, use the @option{--multi} command line
21924option. Then you can connect using @code{target extended-remote} and start
21925the program you want to debug (see below for details on using the
21926@code{run} command in this scenario). Note that the conditions under which
21927@code{gdbserver} terminates depend on how @value{GDBN} connects to it
21928(@code{target remote} or @code{target extended-remote}). The
21929@option{--multi} option to @code{gdbserver} has no influence on that.
07f31aa6 21930
19d9d4ef
DB
21931@item The @code{run} command
21932@strong{With target remote mode:} The @code{run} command is not
21933supported. Once a connection has been established, you can use all
21934the usual @value{GDBN} commands to examine and change data. The
21935remote program is already running, so you can use commands like
21936@kbd{step} and @kbd{continue}.
21937
21938@strong{With target extended-remote mode:} The @code{run} command is
21939supported. The @code{run} command uses the value set by
21940@code{set remote exec-file} (@pxref{set remote exec-file}) to select
21941the program to run. Command line arguments are supported, except for
21942wildcard expansion and I/O redirection (@pxref{Arguments}).
21943
21944If you specify the program to debug on the command line, then the
21945@code{run} command is not required to start execution, and you can
21946resume using commands like @kbd{step} and @kbd{continue} as with
21947@code{target remote} mode.
21948
21949@anchor{Attaching in Types of Remote Connections}
21950@item Attaching
21951@strong{With target remote mode:} The @value{GDBN} command @code{attach} is
21952not supported. To attach to a running program using @code{gdbserver}, you
21953must use the @option{--attach} option (@pxref{Running gdbserver}).
21954
21955@strong{With target extended-remote mode:} To attach to a running program,
21956you may use the @code{attach} command after the connection has been
21957established. If you are using @code{gdbserver}, you may also invoke
21958@code{gdbserver} using the @option{--attach} option
21959(@pxref{Running gdbserver}).
21960
e47e48f6
PW
21961Some remote targets allow @value{GDBN} to determine the executable file running
21962in the process the debugger is attaching to. In such a case, @value{GDBN}
21963uses the value of @code{exec-file-mismatch} to handle a possible mismatch
21964between the executable file name running in the process and the name of the
21965current exec-file loaded by @value{GDBN} (@pxref{set exec-file-mismatch}).
21966
19d9d4ef
DB
21967@end table
21968
21969@anchor{Host and target files}
21970@subsection Host and Target Files
21971@cindex remote debugging, symbol files
21972@cindex symbol files, remote debugging
21973
21974@value{GDBN}, running on the host, needs access to symbol and debugging
21975information for your program running on the target. This requires
21976access to an unstripped copy of your program, and possibly any associated
21977symbol files. Note that this section applies equally to both @code{target
21978remote} mode and @code{target extended-remote} mode.
21979
21980Some remote targets (@pxref{qXfer executable filename read}, and
21981@pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
21982the same connection used to communicate with @value{GDBN}. With such a
21983target, if the remote program is unstripped, the only command you need is
21984@code{target remote} (or @code{target extended-remote}).
21985
21986If the remote program is stripped, or the target does not support remote
21987program file access, start up @value{GDBN} using the name of the local
1b6e6f5c 21988unstripped copy of your program as the first argument, or use the
19d9d4ef
DB
21989@code{file} command. Use @code{set sysroot} to specify the location (on
21990the host) of target libraries (unless your @value{GDBN} was compiled with
21991the correct sysroot using @code{--with-sysroot}). Alternatively, you
21992may use @code{set solib-search-path} to specify how @value{GDBN} locates
21993target libraries.
21994
21995The symbol file and target libraries must exactly match the executable
21996and libraries on the target, with one exception: the files on the host
21997system should not be stripped, even if the files on the target system
21998are. Mismatched or missing files will lead to confusing results
21999during debugging. On @sc{gnu}/Linux targets, mismatched or missing
22000files may also prevent @code{gdbserver} from debugging multi-threaded
22001programs.
07f31aa6 22002
19d9d4ef
DB
22003@subsection Remote Connection Commands
22004@cindex remote connection commands
c1168a2f
JD
22005@value{GDBN} can communicate with the target over a serial line, a
22006local Unix domain socket, or
86941c27
JB
22007over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
22008each case, @value{GDBN} uses the same protocol for debugging your
22009program; only the medium carrying the debugging packets varies. The
19d9d4ef
DB
22010@code{target remote} and @code{target extended-remote} commands
22011establish a connection to the target. Both commands accept the same
22012arguments, which indicate the medium to use:
86941c27
JB
22013
22014@table @code
22015
22016@item target remote @var{serial-device}
19d9d4ef 22017@itemx target extended-remote @var{serial-device}
07f31aa6 22018@cindex serial line, @code{target remote}
86941c27
JB
22019Use @var{serial-device} to communicate with the target. For example,
22020to use a serial line connected to the device named @file{/dev/ttyb}:
22021
22022@smallexample
22023target remote /dev/ttyb
22024@end smallexample
22025
07f31aa6 22026If you're using a serial line, you may want to give @value{GDBN} the
2446f5ea 22027@samp{--baud} option, or use the @code{set serial baud} command
0d12017b 22028(@pxref{Remote Configuration, set serial baud}) before the
9c16f35a 22029@code{target} command.
07f31aa6 22030
c1168a2f
JD
22031@item target remote @var{local-socket}
22032@itemx target extended-remote @var{local-socket}
22033@cindex local socket, @code{target remote}
22034@cindex Unix domain socket
22035Use @var{local-socket} to communicate with the target. For example,
22036to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
22037
22038@smallexample
22039target remote /tmp/gdb-socket0
22040@end smallexample
22041
22042Note that this command has the same form as the command to connect
22043to a serial line. @value{GDBN} will automatically determine which
22044kind of file you have specified and will make the appropriate kind
22045of connection.
22046This feature is not available if the host system does not support
22047Unix domain sockets.
22048
86941c27 22049@item target remote @code{@var{host}:@var{port}}
0ca4866a 22050@itemx target remote @code{[@var{host}]:@var{port}}
86941c27 22051@itemx target remote @code{tcp:@var{host}:@var{port}}
0ca4866a 22052@itemx target remote @code{tcp:[@var{host}]:@var{port}}
c7ab0aef
SDJ
22053@itemx target remote @code{tcp4:@var{host}:@var{port}}
22054@itemx target remote @code{tcp6:@var{host}:@var{port}}
0ca4866a 22055@itemx target remote @code{tcp6:[@var{host}]:@var{port}}
19d9d4ef 22056@itemx target extended-remote @code{@var{host}:@var{port}}
0ca4866a 22057@itemx target extended-remote @code{[@var{host}]:@var{port}}
19d9d4ef 22058@itemx target extended-remote @code{tcp:@var{host}:@var{port}}
0ca4866a 22059@itemx target extended-remote @code{tcp:[@var{host}]:@var{port}}
c7ab0aef
SDJ
22060@itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
22061@itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
0ca4866a 22062@itemx target extended-remote @code{tcp6:[@var{host}]:@var{port}}
86941c27 22063@cindex @acronym{TCP} port, @code{target remote}
6a0b3457 22064Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
c7ab0aef
SDJ
22065The @var{host} may be either a host name, a numeric @acronym{IPv4}
22066address, or a numeric @acronym{IPv6} address (with or without the
22067square brackets to separate the address from the port); @var{port}
22068must be a decimal number. The @var{host} could be the target machine
22069itself, if it is directly connected to the net, or it might be a
22070terminal server which in turn has a serial line to the target.
07f31aa6 22071
86941c27
JB
22072For example, to connect to port 2828 on a terminal server named
22073@code{manyfarms}:
07f31aa6
DJ
22074
22075@smallexample
22076target remote manyfarms:2828
22077@end smallexample
22078
c7ab0aef
SDJ
22079To connect to port 2828 on a terminal server whose address is
22080@code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
22081square bracket syntax:
22082
22083@smallexample
22084target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
22085@end smallexample
22086
22087@noindent
22088or explicitly specify the @acronym{IPv6} protocol:
22089
22090@smallexample
22091target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
22092@end smallexample
22093
22094This last example may be confusing to the reader, because there is no
22095visible separation between the hostname and the port number.
22096Therefore, we recommend the user to provide @acronym{IPv6} addresses
22097using square brackets for clarity. However, it is important to
22098mention that for @value{GDBN} there is no ambiguity: the number after
22099the last colon is considered to be the port number.
22100
86941c27
JB
22101If your remote target is actually running on the same machine as your
22102debugger session (e.g.@: a simulator for your target running on the
22103same host), you can omit the hostname. For example, to connect to
22104port 1234 on your local machine:
07f31aa6
DJ
22105
22106@smallexample
22107target remote :1234
22108@end smallexample
22109@noindent
22110
22111Note that the colon is still required here.
22112
86941c27 22113@item target remote @code{udp:@var{host}:@var{port}}
0ca4866a 22114@itemx target remote @code{udp:[@var{host}]:@var{port}}
c7ab0aef 22115@itemx target remote @code{udp4:@var{host}:@var{port}}
0ca4866a 22116@itemx target remote @code{udp6:[@var{host}]:@var{port}}
c7ab0aef 22117@itemx target extended-remote @code{udp:@var{host}:@var{port}}
19d9d4ef 22118@itemx target extended-remote @code{udp:@var{host}:@var{port}}
0ca4866a 22119@itemx target extended-remote @code{udp:[@var{host}]:@var{port}}
c7ab0aef
SDJ
22120@itemx target extended-remote @code{udp4:@var{host}:@var{port}}
22121@itemx target extended-remote @code{udp6:@var{host}:@var{port}}
0ca4866a 22122@itemx target extended-remote @code{udp6:[@var{host}]:@var{port}}
86941c27
JB
22123@cindex @acronym{UDP} port, @code{target remote}
22124Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
22125connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
22126
22127@smallexample
22128target remote udp:manyfarms:2828
22129@end smallexample
22130
86941c27
JB
22131When using a @acronym{UDP} connection for remote debugging, you should
22132keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
22133can silently drop packets on busy or unreliable networks, which will
22134cause havoc with your debugging session.
22135
66b8c7f6 22136@item target remote | @var{command}
19d9d4ef 22137@itemx target extended-remote | @var{command}
66b8c7f6
JB
22138@cindex pipe, @code{target remote} to
22139Run @var{command} in the background and communicate with it using a
22140pipe. The @var{command} is a shell command, to be parsed and expanded
22141by the system's command shell, @code{/bin/sh}; it should expect remote
22142protocol packets on its standard input, and send replies on its
22143standard output. You could use this to run a stand-alone simulator
22144that speaks the remote debugging protocol, to make net connections
22145using programs like @code{ssh}, or for other similar tricks.
22146
22147If @var{command} closes its standard output (perhaps by exiting),
22148@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
22149program has already exited, this will have no effect.)
22150
86941c27 22151@end table
07f31aa6 22152
07f31aa6
DJ
22153@cindex interrupting remote programs
22154@cindex remote programs, interrupting
22155Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 22156interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
22157program. This may or may not succeed, depending in part on the hardware
22158and the serial drivers the remote system uses. If you type the
22159interrupt character once again, @value{GDBN} displays this prompt:
22160
22161@smallexample
22162Interrupted while waiting for the program.
22163Give up (and stop debugging it)? (y or n)
22164@end smallexample
22165
19d9d4ef
DB
22166In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
22167the remote debugging session. (If you decide you want to try again later,
22168you can use @kbd{target remote} again to connect once more.) If you type
22169@kbd{n}, @value{GDBN} goes back to waiting.
22170
22171In @code{target extended-remote} mode, typing @kbd{n} will leave
22172@value{GDBN} connected to the target.
07f31aa6
DJ
22173
22174@table @code
22175@kindex detach (remote)
22176@item detach
22177When you have finished debugging the remote program, you can use the
22178@code{detach} command to release it from @value{GDBN} control.
22179Detaching from the target normally resumes its execution, but the results
22180will depend on your particular remote stub. After the @code{detach}
19d9d4ef
DB
22181command in @code{target remote} mode, @value{GDBN} is free to connect to
22182another target. In @code{target extended-remote} mode, @value{GDBN} is
22183still connected to the target.
07f31aa6
DJ
22184
22185@kindex disconnect
22186@item disconnect
19d9d4ef 22187The @code{disconnect} command closes the connection to the target, and
07f31aa6
DJ
22188the target is generally not resumed. It will wait for @value{GDBN}
22189(this instance or another one) to connect and continue debugging. After
22190the @code{disconnect} command, @value{GDBN} is again free to connect to
22191another target.
09d4efe1
EZ
22192
22193@cindex send command to remote monitor
fad38dfa
EZ
22194@cindex extend @value{GDBN} for remote targets
22195@cindex add new commands for external monitor
09d4efe1
EZ
22196@kindex monitor
22197@item monitor @var{cmd}
fad38dfa
EZ
22198This command allows you to send arbitrary commands directly to the
22199remote monitor. Since @value{GDBN} doesn't care about the commands it
22200sends like this, this command is the way to extend @value{GDBN}---you
22201can add new commands that only the external monitor will understand
22202and implement.
07f31aa6
DJ
22203@end table
22204
a6b151f1
DJ
22205@node File Transfer
22206@section Sending files to a remote system
22207@cindex remote target, file transfer
22208@cindex file transfer
22209@cindex sending files to remote systems
22210
22211Some remote targets offer the ability to transfer files over the same
22212connection used to communicate with @value{GDBN}. This is convenient
22213for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
22214running @code{gdbserver} over a network interface. For other targets,
22215e.g.@: embedded devices with only a single serial port, this may be
22216the only way to upload or download files.
22217
22218Not all remote targets support these commands.
22219
22220@table @code
22221@kindex remote put
22222@item remote put @var{hostfile} @var{targetfile}
22223Copy file @var{hostfile} from the host system (the machine running
22224@value{GDBN}) to @var{targetfile} on the target system.
22225
22226@kindex remote get
22227@item remote get @var{targetfile} @var{hostfile}
22228Copy file @var{targetfile} from the target system to @var{hostfile}
22229on the host system.
22230
22231@kindex remote delete
22232@item remote delete @var{targetfile}
22233Delete @var{targetfile} from the target system.
22234
22235@end table
22236
6f05cf9f 22237@node Server
79a6e687 22238@section Using the @code{gdbserver} Program
6f05cf9f
AC
22239
22240@kindex gdbserver
22241@cindex remote connection without stubs
22242@code{gdbserver} is a control program for Unix-like systems, which
22243allows you to connect your program with a remote @value{GDBN} via
19d9d4ef
DB
22244@code{target remote} or @code{target extended-remote}---but without
22245linking in the usual debugging stub.
6f05cf9f
AC
22246
22247@code{gdbserver} is not a complete replacement for the debugging stubs,
22248because it requires essentially the same operating-system facilities
22249that @value{GDBN} itself does. In fact, a system that can run
22250@code{gdbserver} to connect to a remote @value{GDBN} could also run
22251@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
22252because it is a much smaller program than @value{GDBN} itself. It is
22253also easier to port than all of @value{GDBN}, so you may be able to get
22254started more quickly on a new system by using @code{gdbserver}.
22255Finally, if you develop code for real-time systems, you may find that
22256the tradeoffs involved in real-time operation make it more convenient to
22257do as much development work as possible on another system, for example
22258by cross-compiling. You can use @code{gdbserver} to make a similar
22259choice for debugging.
22260
22261@value{GDBN} and @code{gdbserver} communicate via either a serial line
22262or a TCP connection, using the standard @value{GDBN} remote serial
22263protocol.
22264
2d717e4f
DJ
22265@quotation
22266@emph{Warning:} @code{gdbserver} does not have any built-in security.
22267Do not run @code{gdbserver} connected to any public network; a
22268@value{GDBN} connection to @code{gdbserver} provides access to the
22269target system with the same privileges as the user running
22270@code{gdbserver}.
22271@end quotation
22272
19d9d4ef 22273@anchor{Running gdbserver}
2d717e4f
DJ
22274@subsection Running @code{gdbserver}
22275@cindex arguments, to @code{gdbserver}
d9b1a651 22276@cindex @code{gdbserver}, command-line arguments
2d717e4f
DJ
22277
22278Run @code{gdbserver} on the target system. You need a copy of the
22279program you want to debug, including any libraries it requires.
6f05cf9f
AC
22280@code{gdbserver} does not need your program's symbol table, so you can
22281strip the program if necessary to save space. @value{GDBN} on the host
22282system does all the symbol handling.
22283
22284To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 22285the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
22286syntax is:
22287
22288@smallexample
22289target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
22290@end smallexample
22291
6cf36756
SM
22292@var{comm} is either a device name (to use a serial line), or a TCP
22293hostname and portnumber, or @code{-} or @code{stdio} to use
22294stdin/stdout of @code{gdbserver}.
e0f9f062 22295For example, to debug Emacs with the argument
6f05cf9f
AC
22296@samp{foo.txt} and communicate with @value{GDBN} over the serial port
22297@file{/dev/com1}:
22298
22299@smallexample
22300target> gdbserver /dev/com1 emacs foo.txt
22301@end smallexample
22302
6cf36756
SM
22303@code{gdbserver} waits passively for the host @value{GDBN} to communicate
22304with it.
6f05cf9f
AC
22305
22306To use a TCP connection instead of a serial line:
22307
22308@smallexample
22309target> gdbserver host:2345 emacs foo.txt
22310@end smallexample
22311
22312The only difference from the previous example is the first argument,
22313specifying that you are communicating with the host @value{GDBN} via
22314TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
22315expect a TCP connection from machine @samp{host} to local TCP port 2345.
22316(Currently, the @samp{host} part is ignored.) You can choose any number
22317you want for the port number as long as it does not conflict with any
22318TCP ports already in use on the target system (for example, @code{23} is
22319reserved for @code{telnet}).@footnote{If you choose a port number that
22320conflicts with another service, @code{gdbserver} prints an error message
22321and exits.} You must use the same port number with the host @value{GDBN}
22322@code{target remote} command.
22323
6cf36756
SM
22324The @code{stdio} connection is useful when starting @code{gdbserver}
22325with ssh:
e0f9f062
DE
22326
22327@smallexample
6cf36756 22328(gdb) target remote | ssh -T hostname gdbserver - hello
e0f9f062
DE
22329@end smallexample
22330
6cf36756
SM
22331The @samp{-T} option to ssh is provided because we don't need a remote pty,
22332and we don't want escape-character handling. Ssh does this by default when
22333a command is provided, the flag is provided to make it explicit.
22334You could elide it if you want to.
e0f9f062 22335
6cf36756
SM
22336Programs started with stdio-connected gdbserver have @file{/dev/null} for
22337@code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
22338display through a pipe connected to gdbserver.
22339Both @code{stdout} and @code{stderr} use the same pipe.
e0f9f062 22340
19d9d4ef 22341@anchor{Attaching to a program}
2d717e4f 22342@subsubsection Attaching to a Running Program
d9b1a651
EZ
22343@cindex attach to a program, @code{gdbserver}
22344@cindex @option{--attach}, @code{gdbserver} option
2d717e4f 22345
56460a61
DJ
22346On some targets, @code{gdbserver} can also attach to running programs.
22347This is accomplished via the @code{--attach} argument. The syntax is:
22348
22349@smallexample
2d717e4f 22350target> gdbserver --attach @var{comm} @var{pid}
56460a61
DJ
22351@end smallexample
22352
19d9d4ef
DB
22353@var{pid} is the process ID of a currently running process. It isn't
22354necessary to point @code{gdbserver} at a binary for the running process.
22355
22356In @code{target extended-remote} mode, you can also attach using the
22357@value{GDBN} attach command
22358(@pxref{Attaching in Types of Remote Connections}).
56460a61 22359
b1fe9455 22360@pindex pidof
b1fe9455
DJ
22361You can debug processes by name instead of process ID if your target has the
22362@code{pidof} utility:
22363
22364@smallexample
2d717e4f 22365target> gdbserver --attach @var{comm} `pidof @var{program}`
b1fe9455
DJ
22366@end smallexample
22367
f822c95b 22368In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
22369has multiple threads, most versions of @code{pidof} support the
22370@code{-s} option to only return the first process ID.
22371
03f2bd59
JK
22372@subsubsection TCP port allocation lifecycle of @code{gdbserver}
22373
19d9d4ef
DB
22374This section applies only when @code{gdbserver} is run to listen on a TCP
22375port.
03f2bd59
JK
22376
22377@code{gdbserver} normally terminates after all of its debugged processes have
22378terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
22379extended-remote}, @code{gdbserver} stays running even with no processes left.
22380@value{GDBN} normally terminates the spawned debugged process on its exit,
22381which normally also terminates @code{gdbserver} in the @kbd{target remote}
22382mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
22383cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
22384stays running even in the @kbd{target remote} mode.
22385
22386When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
22387Such reconnecting is useful for features like @ref{disconnected tracing}. For
22388completeness, at most one @value{GDBN} can be connected at a time.
22389
22390@cindex @option{--once}, @code{gdbserver} option
22391By default, @code{gdbserver} keeps the listening TCP port open, so that
6e8c5661 22392subsequent connections are possible. However, if you start @code{gdbserver}
03f2bd59
JK
22393with the @option{--once} option, it will stop listening for any further
22394connection attempts after connecting to the first @value{GDBN} session. This
22395means no further connections to @code{gdbserver} will be possible after the
22396first one. It also means @code{gdbserver} will terminate after the first
22397connection with remote @value{GDBN} has closed, even for unexpectedly closed
22398connections and even in the @kbd{target extended-remote} mode. The
22399@option{--once} option allows reusing the same port number for connecting to
22400multiple instances of @code{gdbserver} running on the same host, since each
22401instance closes its port after the first connection.
2d717e4f 22402
87ce2a04 22403@anchor{Other Command-Line Arguments for gdbserver}
2d717e4f
DJ
22404@subsubsection Other Command-Line Arguments for @code{gdbserver}
22405
19d9d4ef
DB
22406You can use the @option{--multi} option to start @code{gdbserver} without
22407specifying a program to debug or a process to attach to. Then you can
22408attach in @code{target extended-remote} mode and run or attach to a
22409program. For more information,
22410@pxref{--multi Option in Types of Remote Connnections}.
22411
d9b1a651 22412@cindex @option{--debug}, @code{gdbserver} option
62709adf 22413The @option{--debug} option tells @code{gdbserver} to display extra
d9b1a651
EZ
22414status information about the debugging process.
22415@cindex @option{--remote-debug}, @code{gdbserver} option
22416The @option{--remote-debug} option tells @code{gdbserver} to display
aeb2e706
AH
22417remote protocol debug output.
22418@cindex @option{--debug-file}, @code{gdbserver} option
22419@cindex @code{gdbserver}, send all debug output to a single file
22420The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
22421write any debug output to the given @var{filename}. These options are intended
22422for @code{gdbserver} development and for bug reports to the developers.
2d717e4f 22423
87ce2a04
DE
22424@cindex @option{--debug-format}, @code{gdbserver} option
22425The @option{--debug-format=option1[,option2,...]} option tells
22426@code{gdbserver} to include additional information in each output.
22427Possible options are:
22428
22429@table @code
22430@item none
22431Turn off all extra information in debugging output.
22432@item all
22433Turn on all extra information in debugging output.
22434@item timestamps
22435Include a timestamp in each line of debugging output.
22436@end table
22437
22438Options are processed in order. Thus, for example, if @option{none}
22439appears last then no additional information is added to debugging output.
22440
d9b1a651 22441@cindex @option{--wrapper}, @code{gdbserver} option
ccd213ac
DJ
22442The @option{--wrapper} option specifies a wrapper to launch programs
22443for debugging. The option should be followed by the name of the
22444wrapper, then any command-line arguments to pass to the wrapper, then
22445@kbd{--} indicating the end of the wrapper arguments.
22446
22447@code{gdbserver} runs the specified wrapper program with a combined
22448command line including the wrapper arguments, then the name of the
22449program to debug, then any arguments to the program. The wrapper
22450runs until it executes your program, and then @value{GDBN} gains control.
22451
22452You can use any program that eventually calls @code{execve} with
22453its arguments as a wrapper. Several standard Unix utilities do
22454this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
22455with @code{exec "$@@"} will also work.
22456
22457For example, you can use @code{env} to pass an environment variable to
22458the debugged program, without setting the variable in @code{gdbserver}'s
22459environment:
22460
22461@smallexample
22462$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
22463@end smallexample
22464
6d580b63
YQ
22465@cindex @option{--selftest}
22466The @option{--selftest} option runs the self tests in @code{gdbserver}:
22467
22468@smallexample
22469$ gdbserver --selftest
22470Ran 2 unit tests, 0 failed
22471@end smallexample
22472
22473These tests are disabled in release.
2d717e4f
DJ
22474@subsection Connecting to @code{gdbserver}
22475
19d9d4ef
DB
22476The basic procedure for connecting to the remote target is:
22477@itemize
2d717e4f 22478
19d9d4ef
DB
22479@item
22480Run @value{GDBN} on the host system.
f822c95b 22481
19d9d4ef
DB
22482@item
22483Make sure you have the necessary symbol files
22484(@pxref{Host and target files}).
22485Load symbols for your application using the @code{file} command before you
22486connect. Use @code{set sysroot} to locate target libraries (unless your
22487@value{GDBN} was compiled with the correct sysroot using
22488@code{--with-sysroot}).
f822c95b 22489
19d9d4ef 22490@item
79a6e687 22491Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f 22492For TCP connections, you must start up @code{gdbserver} prior to using
19d9d4ef 22493the @code{target} command. Otherwise you may get an error whose
6f05cf9f 22494text depends on the host system, but which usually looks something like
2d717e4f 22495@samp{Connection refused}. Don't use the @code{load}
19d9d4ef
DB
22496command in @value{GDBN} when using @code{target remote} mode, since the
22497program is already on the target.
22498
22499@end itemize
07f31aa6 22500
19d9d4ef 22501@anchor{Monitor Commands for gdbserver}
79a6e687 22502@subsection Monitor Commands for @code{gdbserver}
c74d0ad8
DJ
22503@cindex monitor commands, for @code{gdbserver}
22504
22505During a @value{GDBN} session using @code{gdbserver}, you can use the
22506@code{monitor} command to send special requests to @code{gdbserver}.
2d717e4f 22507Here are the available commands.
c74d0ad8
DJ
22508
22509@table @code
22510@item monitor help
22511List the available monitor commands.
22512
22513@item monitor set debug 0
22514@itemx monitor set debug 1
22515Disable or enable general debugging messages.
22516
22517@item monitor set remote-debug 0
22518@itemx monitor set remote-debug 1
22519Disable or enable specific debugging messages associated with the remote
22520protocol (@pxref{Remote Protocol}).
22521
aeb2e706
AH
22522@item monitor set debug-file filename
22523@itemx monitor set debug-file
22524Send any debug output to the given file, or to stderr.
22525
87ce2a04
DE
22526@item monitor set debug-format option1@r{[},option2,...@r{]}
22527Specify additional text to add to debugging messages.
22528Possible options are:
22529
22530@table @code
22531@item none
22532Turn off all extra information in debugging output.
22533@item all
22534Turn on all extra information in debugging output.
22535@item timestamps
22536Include a timestamp in each line of debugging output.
22537@end table
22538
22539Options are processed in order. Thus, for example, if @option{none}
22540appears last then no additional information is added to debugging output.
22541
cdbfd419
PP
22542@item monitor set libthread-db-search-path [PATH]
22543@cindex gdbserver, search path for @code{libthread_db}
22544When this command is issued, @var{path} is a colon-separated list of
22545directories to search for @code{libthread_db} (@pxref{Threads,,set
22546libthread-db-search-path}). If you omit @var{path},
84e578fb 22547@samp{libthread-db-search-path} will be reset to its default value.
cdbfd419 22548
98a5dd13
DE
22549The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
22550not supported in @code{gdbserver}.
22551
2d717e4f
DJ
22552@item monitor exit
22553Tell gdbserver to exit immediately. This command should be followed by
22554@code{disconnect} to close the debugging session. @code{gdbserver} will
22555detach from any attached processes and kill any processes it created.
22556Use @code{monitor exit} to terminate @code{gdbserver} at the end
22557of a multi-process mode debug session.
22558
c74d0ad8
DJ
22559@end table
22560
fa593d66
PA
22561@subsection Tracepoints support in @code{gdbserver}
22562@cindex tracepoints support in @code{gdbserver}
22563
0fb4aa4b
PA
22564On some targets, @code{gdbserver} supports tracepoints, fast
22565tracepoints and static tracepoints.
fa593d66 22566
0fb4aa4b 22567For fast or static tracepoints to work, a special library called the
fa593d66
PA
22568@dfn{in-process agent} (IPA), must be loaded in the inferior process.
22569This library is built and distributed as an integral part of
0fb4aa4b
PA
22570@code{gdbserver}. In addition, support for static tracepoints
22571requires building the in-process agent library with static tracepoints
22572support. At present, the UST (LTTng Userspace Tracer,
22573@url{http://lttng.org/ust}) tracing engine is supported. This support
22574is automatically available if UST development headers are found in the
22575standard include path when @code{gdbserver} is built, or if
22576@code{gdbserver} was explicitly configured using @option{--with-ust}
22577to point at such headers. You can explicitly disable the support
22578using @option{--with-ust=no}.
fa593d66
PA
22579
22580There are several ways to load the in-process agent in your program:
22581
22582@table @code
22583@item Specifying it as dependency at link time
22584
22585You can link your program dynamically with the in-process agent
22586library. On most systems, this is accomplished by adding
22587@code{-linproctrace} to the link command.
22588
22589@item Using the system's preloading mechanisms
22590
22591You can force loading the in-process agent at startup time by using
22592your system's support for preloading shared libraries. Many Unixes
22593support the concept of preloading user defined libraries. In most
22594cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
22595in the environment. See also the description of @code{gdbserver}'s
22596@option{--wrapper} command line option.
22597
22598@item Using @value{GDBN} to force loading the agent at run time
22599
22600On some systems, you can force the inferior to load a shared library,
22601by calling a dynamic loader function in the inferior that takes care
22602of dynamically looking up and loading a shared library. On most Unix
22603systems, the function is @code{dlopen}. You'll use the @code{call}
22604command for that. For example:
22605
22606@smallexample
22607(@value{GDBP}) call dlopen ("libinproctrace.so", ...)
22608@end smallexample
22609
22610Note that on most Unix systems, for the @code{dlopen} function to be
22611available, the program needs to be linked with @code{-ldl}.
22612@end table
22613
22614On systems that have a userspace dynamic loader, like most Unix
22615systems, when you connect to @code{gdbserver} using @code{target
22616remote}, you'll find that the program is stopped at the dynamic
22617loader's entry point, and no shared library has been loaded in the
22618program's address space yet, including the in-process agent. In that
0fb4aa4b
PA
22619case, before being able to use any of the fast or static tracepoints
22620features, you need to let the loader run and load the shared
22621libraries. The simplest way to do that is to run the program to the
22622main procedure. E.g., if debugging a C or C@t{++} program, start
fa593d66
PA
22623@code{gdbserver} like so:
22624
22625@smallexample
22626$ gdbserver :9999 myprogram
22627@end smallexample
22628
22629Start GDB and connect to @code{gdbserver} like so, and run to main:
22630
22631@smallexample
22632$ gdb myprogram
22633(@value{GDBP}) target remote myhost:9999
226340x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
22635(@value{GDBP}) b main
22636(@value{GDBP}) continue
22637@end smallexample
22638
22639The in-process tracing agent library should now be loaded into the
22640process; you can confirm it with the @code{info sharedlibrary}
22641command, which will list @file{libinproctrace.so} as loaded in the
0fb4aa4b
PA
22642process. You are now ready to install fast tracepoints, list static
22643tracepoint markers, probe static tracepoints markers, and start
fa593d66
PA
22644tracing.
22645
79a6e687
BW
22646@node Remote Configuration
22647@section Remote Configuration
501eef12 22648
9c16f35a
EZ
22649@kindex set remote
22650@kindex show remote
22651This section documents the configuration options available when
22652debugging remote programs. For the options related to the File I/O
fc320d37 22653extensions of the remote protocol, see @ref{system,
9c16f35a 22654system-call-allowed}.
501eef12
AC
22655
22656@table @code
9c16f35a 22657@item set remoteaddresssize @var{bits}
d3e8051b 22658@cindex address size for remote targets
9c16f35a
EZ
22659@cindex bits in remote address
22660Set the maximum size of address in a memory packet to the specified
22661number of bits. @value{GDBN} will mask off the address bits above
22662that number, when it passes addresses to the remote target. The
22663default value is the number of bits in the target's address.
22664
22665@item show remoteaddresssize
22666Show the current value of remote address size in bits.
22667
0d12017b 22668@item set serial baud @var{n}
9c16f35a
EZ
22669@cindex baud rate for remote targets
22670Set the baud rate for the remote serial I/O to @var{n} baud. The
22671value is used to set the speed of the serial port used for debugging
22672remote targets.
22673
0d12017b 22674@item show serial baud
9c16f35a
EZ
22675Show the current speed of the remote connection.
22676
236af5e3
YG
22677@item set serial parity @var{parity}
22678Set the parity for the remote serial I/O. Supported values of @var{parity} are:
22679@code{even}, @code{none}, and @code{odd}. The default is @code{none}.
22680
22681@item show serial parity
22682Show the current parity of the serial port.
22683
9c16f35a
EZ
22684@item set remotebreak
22685@cindex interrupt remote programs
22686@cindex BREAK signal instead of Ctrl-C
9a6253be 22687@anchor{set remotebreak}
9c16f35a 22688If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 22689when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 22690on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
22691character instead. The default is off, since most remote systems
22692expect to see @samp{Ctrl-C} as the interrupt signal.
22693
22694@item show remotebreak
22695Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
22696interrupt the remote program.
22697
23776285
MR
22698@item set remoteflow on
22699@itemx set remoteflow off
22700@kindex set remoteflow
22701Enable or disable hardware flow control (@code{RTS}/@code{CTS})
22702on the serial port used to communicate to the remote target.
22703
22704@item show remoteflow
22705@kindex show remoteflow
22706Show the current setting of hardware flow control.
22707
9c16f35a
EZ
22708@item set remotelogbase @var{base}
22709Set the base (a.k.a.@: radix) of logging serial protocol
22710communications to @var{base}. Supported values of @var{base} are:
22711@code{ascii}, @code{octal}, and @code{hex}. The default is
22712@code{ascii}.
22713
22714@item show remotelogbase
22715Show the current setting of the radix for logging remote serial
22716protocol.
22717
22718@item set remotelogfile @var{file}
22719@cindex record serial communications on file
22720Record remote serial communications on the named @var{file}. The
22721default is not to record at all.
22722
2d8b6830 22723@item show remotelogfile
9c16f35a
EZ
22724Show the current setting of the file name on which to record the
22725serial communications.
22726
22727@item set remotetimeout @var{num}
22728@cindex timeout for serial communications
22729@cindex remote timeout
22730Set the timeout limit to wait for the remote target to respond to
22731@var{num} seconds. The default is 2 seconds.
22732
22733@item show remotetimeout
22734Show the current number of seconds to wait for the remote target
22735responses.
22736
22737@cindex limit hardware breakpoints and watchpoints
22738@cindex remote target, limit break- and watchpoints
501eef12
AC
22739@anchor{set remote hardware-watchpoint-limit}
22740@anchor{set remote hardware-breakpoint-limit}
22741@item set remote hardware-watchpoint-limit @var{limit}
22742@itemx set remote hardware-breakpoint-limit @var{limit}
055303e2
AB
22743Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
22744or breakpoints. The @var{limit} can be set to 0 to disable hardware
22745watchpoints or breakpoints, and @code{unlimited} for unlimited
22746watchpoints or breakpoints.
22747
22748@item show remote hardware-watchpoint-limit
22749@itemx show remote hardware-breakpoint-limit
22750Show the current limit for the number of hardware watchpoints or
22751breakpoints that @value{GDBN} can use.
2d717e4f 22752
480a3f21
PW
22753@cindex limit hardware watchpoints length
22754@cindex remote target, limit watchpoints length
22755@anchor{set remote hardware-watchpoint-length-limit}
22756@item set remote hardware-watchpoint-length-limit @var{limit}
055303e2
AB
22757Restrict @value{GDBN} to using @var{limit} bytes for the maximum
22758length of a remote hardware watchpoint. A @var{limit} of 0 disables
22759hardware watchpoints and @code{unlimited} allows watchpoints of any
22760length.
480a3f21
PW
22761
22762@item show remote hardware-watchpoint-length-limit
22763Show the current limit (in bytes) of the maximum length of
22764a remote hardware watchpoint.
22765
2d717e4f
DJ
22766@item set remote exec-file @var{filename}
22767@itemx show remote exec-file
22768@anchor{set remote exec-file}
22769@cindex executable file, for remote target
22770Select the file used for @code{run} with @code{target
22771extended-remote}. This should be set to a filename valid on the
22772target system. If it is not set, the target will use a default
22773filename (e.g.@: the last program run).
84603566 22774
9a7071a8
JB
22775@item set remote interrupt-sequence
22776@cindex interrupt remote programs
22777@cindex select Ctrl-C, BREAK or BREAK-g
22778Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
22779@samp{BREAK-g} as the
22780sequence to the remote target in order to interrupt the execution.
22781@samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
22782is high level of serial line for some certain time.
22783Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
22784It is @code{BREAK} signal followed by character @code{g}.
22785
22786@item show interrupt-sequence
22787Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
22788is sent by @value{GDBN} to interrupt the remote program.
22789@code{BREAK-g} is BREAK signal followed by @code{g} and
22790also known as Magic SysRq g.
22791
22792@item set remote interrupt-on-connect
22793@cindex send interrupt-sequence on start
22794Specify whether interrupt-sequence is sent to remote target when
22795@value{GDBN} connects to it. This is mostly needed when you debug
22796Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
22797which is known as Magic SysRq g in order to connect @value{GDBN}.
22798
22799@item show interrupt-on-connect
22800Show whether interrupt-sequence is sent
22801to remote target when @value{GDBN} connects to it.
22802
84603566
SL
22803@kindex set tcp
22804@kindex show tcp
22805@item set tcp auto-retry on
22806@cindex auto-retry, for remote TCP target
22807Enable auto-retry for remote TCP connections. This is useful if the remote
22808debugging agent is launched in parallel with @value{GDBN}; there is a race
22809condition because the agent may not become ready to accept the connection
22810before @value{GDBN} attempts to connect. When auto-retry is
22811enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
22812to establish the connection using the timeout specified by
22813@code{set tcp connect-timeout}.
22814
22815@item set tcp auto-retry off
22816Do not auto-retry failed TCP connections.
22817
22818@item show tcp auto-retry
22819Show the current auto-retry setting.
22820
22821@item set tcp connect-timeout @var{seconds}
f81d1120 22822@itemx set tcp connect-timeout unlimited
84603566
SL
22823@cindex connection timeout, for remote TCP target
22824@cindex timeout, for remote target connection
22825Set the timeout for establishing a TCP connection to the remote target to
22826@var{seconds}. The timeout affects both polling to retry failed connections
22827(enabled by @code{set tcp auto-retry on}) and waiting for connections
22828that are merely slow to complete, and represents an approximate cumulative
f81d1120
PA
22829value. If @var{seconds} is @code{unlimited}, there is no timeout and
22830@value{GDBN} will keep attempting to establish a connection forever,
22831unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
84603566
SL
22832
22833@item show tcp connect-timeout
22834Show the current connection timeout setting.
501eef12
AC
22835@end table
22836
427c3a89
DJ
22837@cindex remote packets, enabling and disabling
22838The @value{GDBN} remote protocol autodetects the packets supported by
22839your debugging stub. If you need to override the autodetection, you
22840can use these commands to enable or disable individual packets. Each
22841packet can be set to @samp{on} (the remote target supports this
22842packet), @samp{off} (the remote target does not support this packet),
22843or @samp{auto} (detect remote target support for this packet). They
22844all default to @samp{auto}. For more information about each packet,
22845see @ref{Remote Protocol}.
22846
22847During normal use, you should not have to use any of these commands.
22848If you do, that may be a bug in your remote debugging stub, or a bug
22849in @value{GDBN}. You may want to report the problem to the
22850@value{GDBN} developers.
22851
cfa9d6d9
DJ
22852For each packet @var{name}, the command to enable or disable the
22853packet is @code{set remote @var{name}-packet}. The available settings
22854are:
427c3a89 22855
cfa9d6d9 22856@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
22857@item Command Name
22858@tab Remote Packet
22859@tab Related Features
22860
cfa9d6d9 22861@item @code{fetch-register}
427c3a89
DJ
22862@tab @code{p}
22863@tab @code{info registers}
22864
cfa9d6d9 22865@item @code{set-register}
427c3a89
DJ
22866@tab @code{P}
22867@tab @code{set}
22868
cfa9d6d9 22869@item @code{binary-download}
427c3a89
DJ
22870@tab @code{X}
22871@tab @code{load}, @code{set}
22872
cfa9d6d9 22873@item @code{read-aux-vector}
427c3a89
DJ
22874@tab @code{qXfer:auxv:read}
22875@tab @code{info auxv}
22876
cfa9d6d9 22877@item @code{symbol-lookup}
427c3a89
DJ
22878@tab @code{qSymbol}
22879@tab Detecting multiple threads
22880
2d717e4f
DJ
22881@item @code{attach}
22882@tab @code{vAttach}
22883@tab @code{attach}
22884
cfa9d6d9 22885@item @code{verbose-resume}
427c3a89
DJ
22886@tab @code{vCont}
22887@tab Stepping or resuming multiple threads
22888
2d717e4f
DJ
22889@item @code{run}
22890@tab @code{vRun}
22891@tab @code{run}
22892
cfa9d6d9 22893@item @code{software-breakpoint}
427c3a89
DJ
22894@tab @code{Z0}
22895@tab @code{break}
22896
cfa9d6d9 22897@item @code{hardware-breakpoint}
427c3a89
DJ
22898@tab @code{Z1}
22899@tab @code{hbreak}
22900
cfa9d6d9 22901@item @code{write-watchpoint}
427c3a89
DJ
22902@tab @code{Z2}
22903@tab @code{watch}
22904
cfa9d6d9 22905@item @code{read-watchpoint}
427c3a89
DJ
22906@tab @code{Z3}
22907@tab @code{rwatch}
22908
cfa9d6d9 22909@item @code{access-watchpoint}
427c3a89
DJ
22910@tab @code{Z4}
22911@tab @code{awatch}
22912
c78fa86a
GB
22913@item @code{pid-to-exec-file}
22914@tab @code{qXfer:exec-file:read}
22915@tab @code{attach}, @code{run}
22916
cfa9d6d9
DJ
22917@item @code{target-features}
22918@tab @code{qXfer:features:read}
22919@tab @code{set architecture}
22920
22921@item @code{library-info}
22922@tab @code{qXfer:libraries:read}
22923@tab @code{info sharedlibrary}
22924
22925@item @code{memory-map}
22926@tab @code{qXfer:memory-map:read}
22927@tab @code{info mem}
22928
0fb4aa4b
PA
22929@item @code{read-sdata-object}
22930@tab @code{qXfer:sdata:read}
22931@tab @code{print $_sdata}
22932
4aa995e1
PA
22933@item @code{read-siginfo-object}
22934@tab @code{qXfer:siginfo:read}
22935@tab @code{print $_siginfo}
22936
22937@item @code{write-siginfo-object}
22938@tab @code{qXfer:siginfo:write}
22939@tab @code{set $_siginfo}
22940
dc146f7c
VP
22941@item @code{threads}
22942@tab @code{qXfer:threads:read}
22943@tab @code{info threads}
22944
cfa9d6d9 22945@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
22946@tab @code{qGetTLSAddr}
22947@tab Displaying @code{__thread} variables
22948
711e434b
PM
22949@item @code{get-thread-information-block-address}
22950@tab @code{qGetTIBAddr}
22951@tab Display MS-Windows Thread Information Block.
22952
08388c79
DE
22953@item @code{search-memory}
22954@tab @code{qSearch:memory}
22955@tab @code{find}
22956
427c3a89
DJ
22957@item @code{supported-packets}
22958@tab @code{qSupported}
22959@tab Remote communications parameters
22960
82075af2
JS
22961@item @code{catch-syscalls}
22962@tab @code{QCatchSyscalls}
22963@tab @code{catch syscall}
22964
cfa9d6d9 22965@item @code{pass-signals}
89be2091
DJ
22966@tab @code{QPassSignals}
22967@tab @code{handle @var{signal}}
22968
9b224c5e
PA
22969@item @code{program-signals}
22970@tab @code{QProgramSignals}
22971@tab @code{handle @var{signal}}
22972
a6b151f1
DJ
22973@item @code{hostio-close-packet}
22974@tab @code{vFile:close}
22975@tab @code{remote get}, @code{remote put}
22976
22977@item @code{hostio-open-packet}
22978@tab @code{vFile:open}
22979@tab @code{remote get}, @code{remote put}
22980
22981@item @code{hostio-pread-packet}
22982@tab @code{vFile:pread}
22983@tab @code{remote get}, @code{remote put}
22984
22985@item @code{hostio-pwrite-packet}
22986@tab @code{vFile:pwrite}
22987@tab @code{remote get}, @code{remote put}
22988
22989@item @code{hostio-unlink-packet}
22990@tab @code{vFile:unlink}
22991@tab @code{remote delete}
a6f3e723 22992
b9e7b9c3
UW
22993@item @code{hostio-readlink-packet}
22994@tab @code{vFile:readlink}
22995@tab Host I/O
22996
0a93529c
GB
22997@item @code{hostio-fstat-packet}
22998@tab @code{vFile:fstat}
22999@tab Host I/O
23000
15a201c8
GB
23001@item @code{hostio-setfs-packet}
23002@tab @code{vFile:setfs}
23003@tab Host I/O
23004
a6f3e723
SL
23005@item @code{noack-packet}
23006@tab @code{QStartNoAckMode}
23007@tab Packet acknowledgment
07e059b5
VP
23008
23009@item @code{osdata}
23010@tab @code{qXfer:osdata:read}
23011@tab @code{info os}
0b16c5cf
PA
23012
23013@item @code{query-attached}
23014@tab @code{qAttached}
23015@tab Querying remote process attach state.
b3b9301e 23016
a46c1e42
PA
23017@item @code{trace-buffer-size}
23018@tab @code{QTBuffer:size}
23019@tab @code{set trace-buffer-size}
23020
bd3eecc3
PA
23021@item @code{trace-status}
23022@tab @code{qTStatus}
23023@tab @code{tstatus}
23024
b3b9301e
PA
23025@item @code{traceframe-info}
23026@tab @code{qXfer:traceframe-info:read}
23027@tab Traceframe info
03583c20 23028
1e4d1764
YQ
23029@item @code{install-in-trace}
23030@tab @code{InstallInTrace}
23031@tab Install tracepoint in tracing
23032
03583c20
UW
23033@item @code{disable-randomization}
23034@tab @code{QDisableRandomization}
23035@tab @code{set disable-randomization}
83364271 23036
aefd8b33
SDJ
23037@item @code{startup-with-shell}
23038@tab @code{QStartupWithShell}
23039@tab @code{set startup-with-shell}
23040
0a2dde4a
SDJ
23041@item @code{environment-hex-encoded}
23042@tab @code{QEnvironmentHexEncoded}
23043@tab @code{set environment}
23044
23045@item @code{environment-unset}
23046@tab @code{QEnvironmentUnset}
23047@tab @code{unset environment}
23048
23049@item @code{environment-reset}
23050@tab @code{QEnvironmentReset}
23051@tab @code{Reset the inferior environment (i.e., unset user-set variables)}
23052
bc3b087d
SDJ
23053@item @code{set-working-dir}
23054@tab @code{QSetWorkingDir}
23055@tab @code{set cwd}
23056
83364271
LM
23057@item @code{conditional-breakpoints-packet}
23058@tab @code{Z0 and Z1}
23059@tab @code{Support for target-side breakpoint condition evaluation}
f7e6eed5 23060
73b8c1fd
PA
23061@item @code{multiprocess-extensions}
23062@tab @code{multiprocess extensions}
23063@tab Debug multiple processes and remote process PID awareness
23064
f7e6eed5
PA
23065@item @code{swbreak-feature}
23066@tab @code{swbreak stop reason}
23067@tab @code{break}
23068
23069@item @code{hwbreak-feature}
23070@tab @code{hwbreak stop reason}
23071@tab @code{hbreak}
23072
0d71eef5
DB
23073@item @code{fork-event-feature}
23074@tab @code{fork stop reason}
23075@tab @code{fork}
23076
23077@item @code{vfork-event-feature}
23078@tab @code{vfork stop reason}
23079@tab @code{vfork}
23080
b459a59b
DB
23081@item @code{exec-event-feature}
23082@tab @code{exec stop reason}
23083@tab @code{exec}
23084
65706a29
PA
23085@item @code{thread-events}
23086@tab @code{QThreadEvents}
23087@tab Tracking thread lifetime.
23088
f2faf941
PA
23089@item @code{no-resumed-stop-reply}
23090@tab @code{no resumed thread left stop reply}
23091@tab Tracking thread lifetime.
23092
427c3a89
DJ
23093@end multitable
23094
79a6e687
BW
23095@node Remote Stub
23096@section Implementing a Remote Stub
7a292a7a 23097
8e04817f
AC
23098@cindex debugging stub, example
23099@cindex remote stub, example
23100@cindex stub example, remote debugging
23101The stub files provided with @value{GDBN} implement the target side of the
23102communication protocol, and the @value{GDBN} side is implemented in the
23103@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
23104these subroutines to communicate, and ignore the details. (If you're
23105implementing your own stub file, you can still ignore the details: start
23106with one of the existing stub files. @file{sparc-stub.c} is the best
23107organized, and therefore the easiest to read.)
23108
104c1213
JM
23109@cindex remote serial debugging, overview
23110To debug a program running on another machine (the debugging
23111@dfn{target} machine), you must first arrange for all the usual
23112prerequisites for the program to run by itself. For example, for a C
23113program, you need:
c906108c 23114
104c1213
JM
23115@enumerate
23116@item
23117A startup routine to set up the C runtime environment; these usually
23118have a name like @file{crt0}. The startup routine may be supplied by
23119your hardware supplier, or you may have to write your own.
96baa820 23120
5d161b24 23121@item
d4f3574e 23122A C subroutine library to support your program's
104c1213 23123subroutine calls, notably managing input and output.
96baa820 23124
104c1213
JM
23125@item
23126A way of getting your program to the other machine---for example, a
23127download program. These are often supplied by the hardware
23128manufacturer, but you may have to write your own from hardware
23129documentation.
23130@end enumerate
96baa820 23131
104c1213
JM
23132The next step is to arrange for your program to use a serial port to
23133communicate with the machine where @value{GDBN} is running (the @dfn{host}
23134machine). In general terms, the scheme looks like this:
96baa820 23135
104c1213
JM
23136@table @emph
23137@item On the host,
23138@value{GDBN} already understands how to use this protocol; when everything
23139else is set up, you can simply use the @samp{target remote} command
23140(@pxref{Targets,,Specifying a Debugging Target}).
23141
23142@item On the target,
23143you must link with your program a few special-purpose subroutines that
23144implement the @value{GDBN} remote serial protocol. The file containing these
23145subroutines is called a @dfn{debugging stub}.
23146
23147On certain remote targets, you can use an auxiliary program
23148@code{gdbserver} instead of linking a stub into your program.
79a6e687 23149@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 23150@end table
96baa820 23151
104c1213
JM
23152The debugging stub is specific to the architecture of the remote
23153machine; for example, use @file{sparc-stub.c} to debug programs on
23154@sc{sparc} boards.
96baa820 23155
104c1213
JM
23156@cindex remote serial stub list
23157These working remote stubs are distributed with @value{GDBN}:
96baa820 23158
104c1213
JM
23159@table @code
23160
23161@item i386-stub.c
41afff9a 23162@cindex @file{i386-stub.c}
104c1213
JM
23163@cindex Intel
23164@cindex i386
23165For Intel 386 and compatible architectures.
23166
23167@item m68k-stub.c
41afff9a 23168@cindex @file{m68k-stub.c}
104c1213
JM
23169@cindex Motorola 680x0
23170@cindex m680x0
23171For Motorola 680x0 architectures.
23172
23173@item sh-stub.c
41afff9a 23174@cindex @file{sh-stub.c}
172c2a43 23175@cindex Renesas
104c1213 23176@cindex SH
172c2a43 23177For Renesas SH architectures.
104c1213
JM
23178
23179@item sparc-stub.c
41afff9a 23180@cindex @file{sparc-stub.c}
104c1213
JM
23181@cindex Sparc
23182For @sc{sparc} architectures.
23183
23184@item sparcl-stub.c
41afff9a 23185@cindex @file{sparcl-stub.c}
104c1213
JM
23186@cindex Fujitsu
23187@cindex SparcLite
23188For Fujitsu @sc{sparclite} architectures.
23189
23190@end table
23191
23192The @file{README} file in the @value{GDBN} distribution may list other
23193recently added stubs.
23194
23195@menu
23196* Stub Contents:: What the stub can do for you
23197* Bootstrapping:: What you must do for the stub
23198* Debug Session:: Putting it all together
104c1213
JM
23199@end menu
23200
6d2ebf8b 23201@node Stub Contents
79a6e687 23202@subsection What the Stub Can Do for You
104c1213
JM
23203
23204@cindex remote serial stub
23205The debugging stub for your architecture supplies these three
23206subroutines:
23207
23208@table @code
23209@item set_debug_traps
4644b6e3 23210@findex set_debug_traps
104c1213
JM
23211@cindex remote serial stub, initialization
23212This routine arranges for @code{handle_exception} to run when your
2fb860fc
PA
23213program stops. You must call this subroutine explicitly in your
23214program's startup code.
104c1213
JM
23215
23216@item handle_exception
4644b6e3 23217@findex handle_exception
104c1213
JM
23218@cindex remote serial stub, main routine
23219This is the central workhorse, but your program never calls it
23220explicitly---the setup code arranges for @code{handle_exception} to
23221run when a trap is triggered.
23222
23223@code{handle_exception} takes control when your program stops during
23224execution (for example, on a breakpoint), and mediates communications
23225with @value{GDBN} on the host machine. This is where the communications
23226protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 23227representative on the target machine. It begins by sending summary
104c1213
JM
23228information on the state of your program, then continues to execute,
23229retrieving and transmitting any information @value{GDBN} needs, until you
23230execute a @value{GDBN} command that makes your program resume; at that point,
23231@code{handle_exception} returns control to your own code on the target
5d161b24 23232machine.
104c1213
JM
23233
23234@item breakpoint
23235@cindex @code{breakpoint} subroutine, remote
23236Use this auxiliary subroutine to make your program contain a
23237breakpoint. Depending on the particular situation, this may be the only
23238way for @value{GDBN} to get control. For instance, if your target
23239machine has some sort of interrupt button, you won't need to call this;
23240pressing the interrupt button transfers control to
23241@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
23242simply receiving characters on the serial port may also trigger a trap;
23243again, in that situation, you don't need to call @code{breakpoint} from
23244your own program---simply running @samp{target remote} from the host
5d161b24 23245@value{GDBN} session gets control.
104c1213
JM
23246
23247Call @code{breakpoint} if none of these is true, or if you simply want
23248to make certain your program stops at a predetermined point for the
23249start of your debugging session.
23250@end table
23251
6d2ebf8b 23252@node Bootstrapping
79a6e687 23253@subsection What You Must Do for the Stub
104c1213
JM
23254
23255@cindex remote stub, support routines
23256The debugging stubs that come with @value{GDBN} are set up for a particular
23257chip architecture, but they have no information about the rest of your
23258debugging target machine.
23259
23260First of all you need to tell the stub how to communicate with the
23261serial port.
23262
23263@table @code
23264@item int getDebugChar()
4644b6e3 23265@findex getDebugChar
104c1213
JM
23266Write this subroutine to read a single character from the serial port.
23267It may be identical to @code{getchar} for your target system; a
23268different name is used to allow you to distinguish the two if you wish.
23269
23270@item void putDebugChar(int)
4644b6e3 23271@findex putDebugChar
104c1213 23272Write this subroutine to write a single character to the serial port.
5d161b24 23273It may be identical to @code{putchar} for your target system; a
104c1213
JM
23274different name is used to allow you to distinguish the two if you wish.
23275@end table
23276
23277@cindex control C, and remote debugging
23278@cindex interrupting remote targets
23279If you want @value{GDBN} to be able to stop your program while it is
23280running, you need to use an interrupt-driven serial driver, and arrange
23281for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
23282character). That is the character which @value{GDBN} uses to tell the
23283remote system to stop.
23284
23285Getting the debugging target to return the proper status to @value{GDBN}
23286probably requires changes to the standard stub; one quick and dirty way
23287is to just execute a breakpoint instruction (the ``dirty'' part is that
23288@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
23289
23290Other routines you need to supply are:
23291
23292@table @code
23293@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 23294@findex exceptionHandler
104c1213
JM
23295Write this function to install @var{exception_address} in the exception
23296handling tables. You need to do this because the stub does not have any
23297way of knowing what the exception handling tables on your target system
23298are like (for example, the processor's table might be in @sc{rom},
23299containing entries which point to a table in @sc{ram}).
697aa1b7 23300The @var{exception_number} specifies the exception which should be changed;
104c1213
JM
23301its meaning is architecture-dependent (for example, different numbers
23302might represent divide by zero, misaligned access, etc). When this
23303exception occurs, control should be transferred directly to
23304@var{exception_address}, and the processor state (stack, registers,
23305and so on) should be just as it is when a processor exception occurs. So if
23306you want to use a jump instruction to reach @var{exception_address}, it
23307should be a simple jump, not a jump to subroutine.
23308
23309For the 386, @var{exception_address} should be installed as an interrupt
23310gate so that interrupts are masked while the handler runs. The gate
23311should be at privilege level 0 (the most privileged level). The
23312@sc{sparc} and 68k stubs are able to mask interrupts themselves without
23313help from @code{exceptionHandler}.
23314
23315@item void flush_i_cache()
4644b6e3 23316@findex flush_i_cache
d4f3574e 23317On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
23318instruction cache, if any, on your target machine. If there is no
23319instruction cache, this subroutine may be a no-op.
23320
23321On target machines that have instruction caches, @value{GDBN} requires this
23322function to make certain that the state of your program is stable.
23323@end table
23324
23325@noindent
23326You must also make sure this library routine is available:
23327
23328@table @code
23329@item void *memset(void *, int, int)
4644b6e3 23330@findex memset
104c1213
JM
23331This is the standard library function @code{memset} that sets an area of
23332memory to a known value. If you have one of the free versions of
23333@code{libc.a}, @code{memset} can be found there; otherwise, you must
23334either obtain it from your hardware manufacturer, or write your own.
23335@end table
23336
23337If you do not use the GNU C compiler, you may need other standard
23338library subroutines as well; this varies from one stub to another,
23339but in general the stubs are likely to use any of the common library
e22ea452 23340subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
23341
23342
6d2ebf8b 23343@node Debug Session
79a6e687 23344@subsection Putting it All Together
104c1213
JM
23345
23346@cindex remote serial debugging summary
23347In summary, when your program is ready to debug, you must follow these
23348steps.
23349
23350@enumerate
23351@item
6d2ebf8b 23352Make sure you have defined the supporting low-level routines
79a6e687 23353(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
23354@display
23355@code{getDebugChar}, @code{putDebugChar},
23356@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
23357@end display
23358
23359@item
2fb860fc
PA
23360Insert these lines in your program's startup code, before the main
23361procedure is called:
104c1213 23362
474c8240 23363@smallexample
104c1213
JM
23364set_debug_traps();
23365breakpoint();
474c8240 23366@end smallexample
104c1213 23367
2fb860fc
PA
23368On some machines, when a breakpoint trap is raised, the hardware
23369automatically makes the PC point to the instruction after the
23370breakpoint. If your machine doesn't do that, you may need to adjust
23371@code{handle_exception} to arrange for it to return to the instruction
23372after the breakpoint on this first invocation, so that your program
23373doesn't keep hitting the initial breakpoint instead of making
23374progress.
23375
104c1213
JM
23376@item
23377For the 680x0 stub only, you need to provide a variable called
23378@code{exceptionHook}. Normally you just use:
23379
474c8240 23380@smallexample
104c1213 23381void (*exceptionHook)() = 0;
474c8240 23382@end smallexample
104c1213 23383
d4f3574e 23384@noindent
104c1213 23385but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 23386function in your program, that function is called when
104c1213
JM
23387@code{@value{GDBN}} continues after stopping on a trap (for example, bus
23388error). The function indicated by @code{exceptionHook} is called with
23389one parameter: an @code{int} which is the exception number.
23390
23391@item
23392Compile and link together: your program, the @value{GDBN} debugging stub for
23393your target architecture, and the supporting subroutines.
23394
23395@item
23396Make sure you have a serial connection between your target machine and
23397the @value{GDBN} host, and identify the serial port on the host.
23398
23399@item
23400@c The "remote" target now provides a `load' command, so we should
23401@c document that. FIXME.
23402Download your program to your target machine (or get it there by
23403whatever means the manufacturer provides), and start it.
23404
23405@item
07f31aa6 23406Start @value{GDBN} on the host, and connect to the target
79a6e687 23407(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 23408
104c1213
JM
23409@end enumerate
23410
8e04817f
AC
23411@node Configurations
23412@chapter Configuration-Specific Information
104c1213 23413
8e04817f
AC
23414While nearly all @value{GDBN} commands are available for all native and
23415cross versions of the debugger, there are some exceptions. This chapter
23416describes things that are only available in certain configurations.
104c1213 23417
8e04817f
AC
23418There are three major categories of configurations: native
23419configurations, where the host and target are the same, embedded
23420operating system configurations, which are usually the same for several
23421different processor architectures, and bare embedded processors, which
23422are quite different from each other.
104c1213 23423
8e04817f
AC
23424@menu
23425* Native::
23426* Embedded OS::
23427* Embedded Processors::
23428* Architectures::
23429@end menu
104c1213 23430
8e04817f
AC
23431@node Native
23432@section Native
104c1213 23433
8e04817f
AC
23434This section describes details specific to particular native
23435configurations.
6cf7e474 23436
8e04817f 23437@menu
7561d450 23438* BSD libkvm Interface:: Debugging BSD kernel memory images
2d97a5d9 23439* Process Information:: Process information
8e04817f 23440* DJGPP Native:: Features specific to the DJGPP port
78c47bea 23441* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 23442* Hurd Native:: Features specific to @sc{gnu} Hurd
a80b95ba 23443* Darwin:: Features specific to Darwin
e9076973 23444* FreeBSD:: Features specific to FreeBSD
8e04817f 23445@end menu
6cf7e474 23446
7561d450
MK
23447@node BSD libkvm Interface
23448@subsection BSD libkvm Interface
23449
23450@cindex libkvm
23451@cindex kernel memory image
23452@cindex kernel crash dump
23453
23454BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
23455interface that provides a uniform interface for accessing kernel virtual
23456memory images, including live systems and crash dumps. @value{GDBN}
23457uses this interface to allow you to debug live kernels and kernel crash
23458dumps on many native BSD configurations. This is implemented as a
23459special @code{kvm} debugging target. For debugging a live system, load
23460the currently running kernel into @value{GDBN} and connect to the
23461@code{kvm} target:
23462
23463@smallexample
23464(@value{GDBP}) @b{target kvm}
23465@end smallexample
23466
23467For debugging crash dumps, provide the file name of the crash dump as an
23468argument:
23469
23470@smallexample
23471(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
23472@end smallexample
23473
23474Once connected to the @code{kvm} target, the following commands are
23475available:
23476
23477@table @code
23478@kindex kvm
23479@item kvm pcb
721c2651 23480Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
23481
23482@item kvm proc
23483Set current context from proc address. This command isn't available on
23484modern FreeBSD systems.
23485@end table
23486
2d97a5d9
JB
23487@node Process Information
23488@subsection Process Information
60bf7e09
EZ
23489@cindex /proc
23490@cindex examine process image
23491@cindex process info via @file{/proc}
104c1213 23492
2d97a5d9
JB
23493Some operating systems provide interfaces to fetch additional
23494information about running processes beyond memory and per-thread
23495register state. If @value{GDBN} is configured for an operating system
23496with a supported interface, the command @code{info proc} is available
23497to report information about the process running your program, or about
23498any process running on your system.
451b7c33 23499
2d97a5d9
JB
23500One supported interface is a facility called @samp{/proc} that can be
23501used to examine the image of a running process using file-system
23502subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
23503systems.
451b7c33 23504
aa8509b4
KR
23505On FreeBSD and NetBSD systems, system control nodes are used to query
23506process information.
2d97a5d9
JB
23507
23508In addition, some systems may provide additional process information
23509in core files. Note that a core file may include a subset of the
23510information available from a live process. Process information is
6b92c0d3 23511currently available from cores created on @sc{gnu}/Linux and FreeBSD
2d97a5d9 23512systems.
104c1213 23513
8e04817f
AC
23514@table @code
23515@kindex info proc
60bf7e09 23516@cindex process ID
8e04817f 23517@item info proc
60bf7e09 23518@itemx info proc @var{process-id}
73f1bd76 23519Summarize available information about a process. If a
60bf7e09
EZ
23520process ID is specified by @var{process-id}, display information about
23521that process; otherwise display information about the program being
23522debugged. The summary includes the debugged process ID, the command
23523line used to invoke it, its current working directory, and its
23524executable file's absolute file name.
23525
23526On some systems, @var{process-id} can be of the form
23527@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
23528within a process. If the optional @var{pid} part is missing, it means
23529a thread from the process being debugged (the leading @samp{/} still
23530needs to be present, or else @value{GDBN} will interpret the number as
23531a process ID rather than a thread ID).
6cf7e474 23532
0c631110
TT
23533@item info proc cmdline
23534@cindex info proc cmdline
23535Show the original command line of the process. This command is
aa8509b4 23536supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
0c631110
TT
23537
23538@item info proc cwd
23539@cindex info proc cwd
23540Show the current working directory of the process. This command is
aa8509b4 23541supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
0c631110
TT
23542
23543@item info proc exe
23544@cindex info proc exe
2d97a5d9 23545Show the name of executable of the process. This command is supported
aa8509b4 23546on @sc{gnu}/Linux, FreeBSD and NetBSD.
0c631110 23547
8b113111
JB
23548@item info proc files
23549@cindex info proc files
23550Show the file descriptors open by the process. For each open file
23551descriptor, @value{GDBN} shows its number, type (file, directory,
23552character device, socket), file pointer offset, and the name of the
23553resource open on the descriptor. The resource name can be a file name
23554(for files, directories, and devices) or a protocol followed by socket
23555address (for network connections). This command is supported on
23556FreeBSD.
23557
23558This example shows the open file descriptors for a process using a
23559tty for standard input and output as well as two network sockets:
23560
23561@smallexample
23562(gdb) info proc files 22136
23563process 22136
23564Open files:
23565
23566 FD Type Offset Flags Name
23567 text file - r-------- /usr/bin/ssh
23568 ctty chr - rw------- /dev/pts/20
23569 cwd dir - r-------- /usr/home/john
23570 root dir - r-------- /
23571 0 chr 0x32933a4 rw------- /dev/pts/20
23572 1 chr 0x32933a4 rw------- /dev/pts/20
23573 2 chr 0x32933a4 rw------- /dev/pts/20
23574 3 socket 0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
23575 4 socket 0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
23576@end smallexample
23577
8e04817f 23578@item info proc mappings
60bf7e09 23579@cindex memory address space mappings
73f1bd76 23580Report the memory address space ranges accessible in a process. On
aa8509b4
KR
23581Solaris, FreeBSD and NetBSD systems, each memory range includes information
23582on whether the process has read, write, or execute access rights to each
23583range. On @sc{gnu}/Linux, FreeBSD and NetBSD systems, each memory range
2d97a5d9 23584includes the object file which is mapped to that range.
60bf7e09
EZ
23585
23586@item info proc stat
23587@itemx info proc status
23588@cindex process detailed status information
2d97a5d9
JB
23589Show additional process-related information, including the user ID and
23590group ID; virtual memory usage; the signals that are pending, blocked,
23591and ignored; its TTY; its consumption of system and user time; its
23592stack size; its @samp{nice} value; etc. These commands are supported
aa8509b4 23593on @sc{gnu}/Linux, FreeBSD and NetBSD.
2d97a5d9
JB
23594
23595For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
23596information (type @kbd{man 5 proc} from your shell prompt).
23597
aa8509b4
KR
23598For FreeBSD and NetBSD systems, @code{info proc stat} is an alias for
23599@code{info proc status}.
60bf7e09
EZ
23600
23601@item info proc all
23602Show all the information about the process described under all of the
23603above @code{info proc} subcommands.
23604
8e04817f
AC
23605@ignore
23606@comment These sub-options of 'info proc' were not included when
23607@comment procfs.c was re-written. Keep their descriptions around
23608@comment against the day when someone finds the time to put them back in.
23609@kindex info proc times
23610@item info proc times
23611Starting time, user CPU time, and system CPU time for your program and
23612its children.
6cf7e474 23613
8e04817f
AC
23614@kindex info proc id
23615@item info proc id
23616Report on the process IDs related to your program: its own process ID,
23617the ID of its parent, the process group ID, and the session ID.
8e04817f 23618@end ignore
721c2651
EZ
23619
23620@item set procfs-trace
23621@kindex set procfs-trace
23622@cindex @code{procfs} API calls
23623This command enables and disables tracing of @code{procfs} API calls.
23624
23625@item show procfs-trace
23626@kindex show procfs-trace
23627Show the current state of @code{procfs} API call tracing.
23628
23629@item set procfs-file @var{file}
23630@kindex set procfs-file
23631Tell @value{GDBN} to write @code{procfs} API trace to the named
23632@var{file}. @value{GDBN} appends the trace info to the previous
23633contents of the file. The default is to display the trace on the
23634standard output.
23635
23636@item show procfs-file
23637@kindex show procfs-file
23638Show the file to which @code{procfs} API trace is written.
23639
23640@item proc-trace-entry
23641@itemx proc-trace-exit
23642@itemx proc-untrace-entry
23643@itemx proc-untrace-exit
23644@kindex proc-trace-entry
23645@kindex proc-trace-exit
23646@kindex proc-untrace-entry
23647@kindex proc-untrace-exit
23648These commands enable and disable tracing of entries into and exits
23649from the @code{syscall} interface.
23650
23651@item info pidlist
23652@kindex info pidlist
23653@cindex process list, QNX Neutrino
23654For QNX Neutrino only, this command displays the list of all the
23655processes and all the threads within each process.
23656
23657@item info meminfo
23658@kindex info meminfo
23659@cindex mapinfo list, QNX Neutrino
23660For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 23661@end table
104c1213 23662
8e04817f
AC
23663@node DJGPP Native
23664@subsection Features for Debugging @sc{djgpp} Programs
23665@cindex @sc{djgpp} debugging
23666@cindex native @sc{djgpp} debugging
23667@cindex MS-DOS-specific commands
104c1213 23668
514c4d71
EZ
23669@cindex DPMI
23670@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
23671MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
23672that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
23673top of real-mode DOS systems and their emulations.
104c1213 23674
8e04817f
AC
23675@value{GDBN} supports native debugging of @sc{djgpp} programs, and
23676defines a few commands specific to the @sc{djgpp} port. This
23677subsection describes those commands.
104c1213 23678
8e04817f
AC
23679@table @code
23680@kindex info dos
23681@item info dos
23682This is a prefix of @sc{djgpp}-specific commands which print
23683information about the target system and important OS structures.
f1251bdd 23684
8e04817f
AC
23685@kindex sysinfo
23686@cindex MS-DOS system info
23687@cindex free memory information (MS-DOS)
23688@item info dos sysinfo
23689This command displays assorted information about the underlying
23690platform: the CPU type and features, the OS version and flavor, the
23691DPMI version, and the available conventional and DPMI memory.
104c1213 23692
8e04817f
AC
23693@cindex GDT
23694@cindex LDT
23695@cindex IDT
23696@cindex segment descriptor tables
23697@cindex descriptor tables display
23698@item info dos gdt
23699@itemx info dos ldt
23700@itemx info dos idt
23701These 3 commands display entries from, respectively, Global, Local,
23702and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
23703tables are data structures which store a descriptor for each segment
23704that is currently in use. The segment's selector is an index into a
23705descriptor table; the table entry for that index holds the
23706descriptor's base address and limit, and its attributes and access
23707rights.
104c1213 23708
8e04817f
AC
23709A typical @sc{djgpp} program uses 3 segments: a code segment, a data
23710segment (used for both data and the stack), and a DOS segment (which
23711allows access to DOS/BIOS data structures and absolute addresses in
23712conventional memory). However, the DPMI host will usually define
23713additional segments in order to support the DPMI environment.
d4f3574e 23714
8e04817f
AC
23715@cindex garbled pointers
23716These commands allow to display entries from the descriptor tables.
23717Without an argument, all entries from the specified table are
23718displayed. An argument, which should be an integer expression, means
23719display a single entry whose index is given by the argument. For
23720example, here's a convenient way to display information about the
23721debugged program's data segment:
104c1213 23722
8e04817f
AC
23723@smallexample
23724@exdent @code{(@value{GDBP}) info dos ldt $ds}
23725@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
23726@end smallexample
104c1213 23727
8e04817f
AC
23728@noindent
23729This comes in handy when you want to see whether a pointer is outside
23730the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 23731
8e04817f
AC
23732@cindex page tables display (MS-DOS)
23733@item info dos pde
23734@itemx info dos pte
23735These two commands display entries from, respectively, the Page
23736Directory and the Page Tables. Page Directories and Page Tables are
23737data structures which control how virtual memory addresses are mapped
23738into physical addresses. A Page Table includes an entry for every
23739page of memory that is mapped into the program's address space; there
23740may be several Page Tables, each one holding up to 4096 entries. A
23741Page Directory has up to 4096 entries, one each for every Page Table
23742that is currently in use.
104c1213 23743
8e04817f
AC
23744Without an argument, @kbd{info dos pde} displays the entire Page
23745Directory, and @kbd{info dos pte} displays all the entries in all of
23746the Page Tables. An argument, an integer expression, given to the
23747@kbd{info dos pde} command means display only that entry from the Page
23748Directory table. An argument given to the @kbd{info dos pte} command
23749means display entries from a single Page Table, the one pointed to by
23750the specified entry in the Page Directory.
104c1213 23751
8e04817f
AC
23752@cindex direct memory access (DMA) on MS-DOS
23753These commands are useful when your program uses @dfn{DMA} (Direct
23754Memory Access), which needs physical addresses to program the DMA
23755controller.
104c1213 23756
8e04817f 23757These commands are supported only with some DPMI servers.
104c1213 23758
8e04817f
AC
23759@cindex physical address from linear address
23760@item info dos address-pte @var{addr}
23761This command displays the Page Table entry for a specified linear
514c4d71
EZ
23762address. The argument @var{addr} is a linear address which should
23763already have the appropriate segment's base address added to it,
23764because this command accepts addresses which may belong to @emph{any}
23765segment. For example, here's how to display the Page Table entry for
23766the page where a variable @code{i} is stored:
104c1213 23767
b383017d 23768@smallexample
8e04817f
AC
23769@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
23770@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 23771@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 23772@end smallexample
104c1213 23773
8e04817f
AC
23774@noindent
23775This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 23776whose physical base address is @code{0x02698000}, and shows all the
8e04817f 23777attributes of that page.
104c1213 23778
8e04817f
AC
23779Note that you must cast the addresses of variables to a @code{char *},
23780since otherwise the value of @code{__djgpp_base_address}, the base
23781address of all variables and functions in a @sc{djgpp} program, will
23782be added using the rules of C pointer arithmetics: if @code{i} is
23783declared an @code{int}, @value{GDBN} will add 4 times the value of
23784@code{__djgpp_base_address} to the address of @code{i}.
104c1213 23785
8e04817f
AC
23786Here's another example, it displays the Page Table entry for the
23787transfer buffer:
104c1213 23788
8e04817f
AC
23789@smallexample
23790@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
23791@exdent @code{Page Table entry for address 0x29110:}
23792@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
23793@end smallexample
104c1213 23794
8e04817f
AC
23795@noindent
23796(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
237973rd member of the @code{_go32_info_block} structure.) The output
23798clearly shows that this DPMI server maps the addresses in conventional
23799memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
23800linear (@code{0x29110}) addresses are identical.
104c1213 23801
8e04817f
AC
23802This command is supported only with some DPMI servers.
23803@end table
104c1213 23804
c45da7e6 23805@cindex DOS serial data link, remote debugging
a8f24a35
EZ
23806In addition to native debugging, the DJGPP port supports remote
23807debugging via a serial data link. The following commands are specific
23808to remote serial debugging in the DJGPP port of @value{GDBN}.
23809
23810@table @code
23811@kindex set com1base
23812@kindex set com1irq
23813@kindex set com2base
23814@kindex set com2irq
23815@kindex set com3base
23816@kindex set com3irq
23817@kindex set com4base
23818@kindex set com4irq
23819@item set com1base @var{addr}
23820This command sets the base I/O port address of the @file{COM1} serial
23821port.
23822
23823@item set com1irq @var{irq}
23824This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
23825for the @file{COM1} serial port.
23826
23827There are similar commands @samp{set com2base}, @samp{set com3irq},
23828etc.@: for setting the port address and the @code{IRQ} lines for the
23829other 3 COM ports.
23830
23831@kindex show com1base
23832@kindex show com1irq
23833@kindex show com2base
23834@kindex show com2irq
23835@kindex show com3base
23836@kindex show com3irq
23837@kindex show com4base
23838@kindex show com4irq
23839The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
23840display the current settings of the base address and the @code{IRQ}
23841lines used by the COM ports.
c45da7e6
EZ
23842
23843@item info serial
23844@kindex info serial
23845@cindex DOS serial port status
23846This command prints the status of the 4 DOS serial ports. For each
23847port, it prints whether it's active or not, its I/O base address and
23848IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
23849counts of various errors encountered so far.
a8f24a35
EZ
23850@end table
23851
23852
78c47bea 23853@node Cygwin Native
79a6e687 23854@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
23855@cindex MS Windows debugging
23856@cindex native Cygwin debugging
23857@cindex Cygwin-specific commands
23858
be448670 23859@value{GDBN} supports native debugging of MS Windows programs, including
cbb8f428
EZ
23860DLLs with and without symbolic debugging information.
23861
23862@cindex Ctrl-BREAK, MS-Windows
23863@cindex interrupt debuggee on MS-Windows
23864MS-Windows programs that call @code{SetConsoleMode} to switch off the
23865special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
23866by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
23867supports @kbd{C-@key{BREAK}} as an alternative interrupt key
23868sequence, which can be used to interrupt the debuggee even if it
23869ignores @kbd{C-c}.
23870
23871There are various additional Cygwin-specific commands, described in
23872this section. Working with DLLs that have no debugging symbols is
23873described in @ref{Non-debug DLL Symbols}.
78c47bea
PM
23874
23875@table @code
23876@kindex info w32
23877@item info w32
db2e3e2e 23878This is a prefix of MS Windows-specific commands which print
78c47bea
PM
23879information about the target system and important OS structures.
23880
23881@item info w32 selector
23882This command displays information returned by
23883the Win32 API @code{GetThreadSelectorEntry} function.
23884It takes an optional argument that is evaluated to
23885a long value to give the information about this given selector.
23886Without argument, this command displays information
d3e8051b 23887about the six segment registers.
78c47bea 23888
711e434b
PM
23889@item info w32 thread-information-block
23890This command displays thread specific information stored in the
23891Thread Information Block (readable on the X86 CPU family using @code{$fs}
23892selector for 32-bit programs and @code{$gs} for 64-bit programs).
23893
463888ab
РИ
23894@kindex signal-event
23895@item signal-event @var{id}
23896This command signals an event with user-provided @var{id}. Used to resume
23897crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
23898
23899To use it, create or edit the following keys in
23900@code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
23901@code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
23902(for x86_64 versions):
23903
23904@itemize @minus
23905@item
23906@code{Debugger} (REG_SZ) --- a command to launch the debugger.
23907Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
23908"attach %ld" -ex "signal-event %ld" -ex "continue"}.
23909
23910The first @code{%ld} will be replaced by the process ID of the
23911crashing process, the second @code{%ld} will be replaced by the ID of
23912the event that blocks the crashing process, waiting for @value{GDBN}
23913to attach.
23914
23915@item
23916@code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
23917make the system run debugger specified by the Debugger key
23918automatically, @code{0} will cause a dialog box with ``OK'' and
23919``Cancel'' buttons to appear, which allows the user to either
23920terminate the crashing process (OK) or debug it (Cancel).
23921@end itemize
23922
be90c084 23923@kindex set cygwin-exceptions
e16b02ee
EZ
23924@cindex debugging the Cygwin DLL
23925@cindex Cygwin DLL, debugging
be90c084 23926@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
23927If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
23928happen inside the Cygwin DLL. If @var{mode} is @code{off},
23929@value{GDBN} will delay recognition of exceptions, and may ignore some
23930exceptions which seem to be caused by internal Cygwin DLL
23931``bookkeeping''. This option is meant primarily for debugging the
23932Cygwin DLL itself; the default value is @code{off} to avoid annoying
23933@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
23934
23935@kindex show cygwin-exceptions
23936@item show cygwin-exceptions
e16b02ee
EZ
23937Displays whether @value{GDBN} will break on exceptions that happen
23938inside the Cygwin DLL itself.
be90c084 23939
b383017d 23940@kindex set new-console
78c47bea 23941@item set new-console @var{mode}
b383017d 23942If @var{mode} is @code{on} the debuggee will
78c47bea 23943be started in a new console on next start.
e03e5e7b 23944If @var{mode} is @code{off}, the debuggee will
78c47bea
PM
23945be started in the same console as the debugger.
23946
23947@kindex show new-console
23948@item show new-console
23949Displays whether a new console is used
23950when the debuggee is started.
23951
23952@kindex set new-group
23953@item set new-group @var{mode}
23954This boolean value controls whether the debuggee should
23955start a new group or stay in the same group as the debugger.
23956This affects the way the Windows OS handles
c8aa23ab 23957@samp{Ctrl-C}.
78c47bea
PM
23958
23959@kindex show new-group
23960@item show new-group
23961Displays current value of new-group boolean.
23962
23963@kindex set debugevents
23964@item set debugevents
219eec71
EZ
23965This boolean value adds debug output concerning kernel events related
23966to the debuggee seen by the debugger. This includes events that
23967signal thread and process creation and exit, DLL loading and
23968unloading, console interrupts, and debugging messages produced by the
23969Windows @code{OutputDebugString} API call.
78c47bea
PM
23970
23971@kindex set debugexec
23972@item set debugexec
b383017d 23973This boolean value adds debug output concerning execute events
219eec71 23974(such as resume thread) seen by the debugger.
78c47bea
PM
23975
23976@kindex set debugexceptions
23977@item set debugexceptions
219eec71
EZ
23978This boolean value adds debug output concerning exceptions in the
23979debuggee seen by the debugger.
78c47bea
PM
23980
23981@kindex set debugmemory
23982@item set debugmemory
219eec71
EZ
23983This boolean value adds debug output concerning debuggee memory reads
23984and writes by the debugger.
78c47bea
PM
23985
23986@kindex set shell
23987@item set shell
23988This boolean values specifies whether the debuggee is called
23989via a shell or directly (default value is on).
23990
23991@kindex show shell
23992@item show shell
23993Displays if the debuggee will be started with a shell.
23994
23995@end table
23996
be448670 23997@menu
79a6e687 23998* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
23999@end menu
24000
79a6e687
BW
24001@node Non-debug DLL Symbols
24002@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
24003@cindex DLLs with no debugging symbols
24004@cindex Minimal symbols and DLLs
24005
24006Very often on windows, some of the DLLs that your program relies on do
24007not include symbolic debugging information (for example,
db2e3e2e 24008@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 24009symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 24010information contained in the DLL's export table. This section
be448670
CF
24011describes working with such symbols, known internally to @value{GDBN} as
24012``minimal symbols''.
24013
24014Note that before the debugged program has started execution, no DLLs
db2e3e2e 24015will have been loaded. The easiest way around this problem is simply to
be448670 24016start the program --- either by setting a breakpoint or letting the
95060284 24017program run once to completion.
be448670 24018
79a6e687 24019@subsubsection DLL Name Prefixes
be448670
CF
24020
24021In keeping with the naming conventions used by the Microsoft debugging
24022tools, DLL export symbols are made available with a prefix based on the
24023DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
24024also entered into the symbol table, so @code{CreateFileA} is often
99e008fe 24025sufficient. In some cases there will be name clashes within a program
be448670
CF
24026(particularly if the executable itself includes full debugging symbols)
24027necessitating the use of the fully qualified name when referring to the
99e008fe 24028contents of the DLL. Use single-quotes around the name to avoid the
be448670
CF
24029exclamation mark (``!'') being interpreted as a language operator.
24030
24031Note that the internal name of the DLL may be all upper-case, even
99e008fe 24032though the file name of the DLL is lower-case, or vice-versa. Since
be448670
CF
24033symbols within @value{GDBN} are @emph{case-sensitive} this may cause
24034some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
24035@code{info variables} commands or even @code{maint print msymbols}
24036(@pxref{Symbols}). Here's an example:
be448670
CF
24037
24038@smallexample
f7dc1244 24039(@value{GDBP}) info function CreateFileA
be448670
CF
24040All functions matching regular expression "CreateFileA":
24041
24042Non-debugging symbols:
240430x77e885f4 CreateFileA
240440x77e885f4 KERNEL32!CreateFileA
24045@end smallexample
24046
24047@smallexample
f7dc1244 24048(@value{GDBP}) info function !
be448670
CF
24049All functions matching regular expression "!":
24050
24051Non-debugging symbols:
240520x6100114c cygwin1!__assert
240530x61004034 cygwin1!_dll_crt0@@0
240540x61004240 cygwin1!dll_crt0(per_process *)
24055[etc...]
24056@end smallexample
24057
79a6e687 24058@subsubsection Working with Minimal Symbols
be448670
CF
24059
24060Symbols extracted from a DLL's export table do not contain very much
24061type information. All that @value{GDBN} can do is guess whether a symbol
24062refers to a function or variable depending on the linker section that
24063contains the symbol. Also note that the actual contents of the memory
24064contained in a DLL are not available unless the program is running. This
24065means that you cannot examine the contents of a variable or disassemble
24066a function within a DLL without a running program.
24067
24068Variables are generally treated as pointers and dereferenced
24069automatically. For this reason, it is often necessary to prefix a
24070variable name with the address-of operator (``&'') and provide explicit
24071type information in the command. Here's an example of the type of
24072problem:
24073
24074@smallexample
f7dc1244 24075(@value{GDBP}) print 'cygwin1!__argv'
d69cf9b2 24076'cygwin1!__argv' has unknown type; cast it to its declared type
be448670
CF
24077@end smallexample
24078
24079@smallexample
f7dc1244 24080(@value{GDBP}) x 'cygwin1!__argv'
d69cf9b2 24081'cygwin1!__argv' has unknown type; cast it to its declared type
be448670
CF
24082@end smallexample
24083
24084And two possible solutions:
24085
24086@smallexample
f7dc1244 24087(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
24088$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
24089@end smallexample
24090
24091@smallexample
f7dc1244 24092(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 240930x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 24094(@value{GDBP}) x/x 0x10021608
be448670 240950x10021608: 0x0022fd98
f7dc1244 24096(@value{GDBP}) x/s 0x0022fd98
be448670
CF
240970x22fd98: "/cygdrive/c/mydirectory/myprogram"
24098@end smallexample
24099
24100Setting a break point within a DLL is possible even before the program
24101starts execution. However, under these circumstances, @value{GDBN} can't
24102examine the initial instructions of the function in order to skip the
24103function's frame set-up code. You can work around this by using ``*&''
24104to set the breakpoint at a raw memory address:
24105
24106@smallexample
f7dc1244 24107(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
24108Breakpoint 1 at 0x1e04eff0
24109@end smallexample
24110
24111The author of these extensions is not entirely convinced that setting a
24112break point within a shared DLL like @file{kernel32.dll} is completely
24113safe.
24114
14d6dd68 24115@node Hurd Native
79a6e687 24116@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
24117@cindex @sc{gnu} Hurd debugging
24118
24119This subsection describes @value{GDBN} commands specific to the
24120@sc{gnu} Hurd native debugging.
24121
24122@table @code
24123@item set signals
24124@itemx set sigs
24125@kindex set signals@r{, Hurd command}
24126@kindex set sigs@r{, Hurd command}
24127This command toggles the state of inferior signal interception by
24128@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
24129affected by this command. @code{sigs} is a shorthand alias for
24130@code{signals}.
24131
24132@item show signals
24133@itemx show sigs
24134@kindex show signals@r{, Hurd command}
24135@kindex show sigs@r{, Hurd command}
24136Show the current state of intercepting inferior's signals.
24137
24138@item set signal-thread
24139@itemx set sigthread
24140@kindex set signal-thread
24141@kindex set sigthread
24142This command tells @value{GDBN} which thread is the @code{libc} signal
24143thread. That thread is run when a signal is delivered to a running
24144process. @code{set sigthread} is the shorthand alias of @code{set
24145signal-thread}.
24146
24147@item show signal-thread
24148@itemx show sigthread
24149@kindex show signal-thread
24150@kindex show sigthread
24151These two commands show which thread will run when the inferior is
24152delivered a signal.
24153
24154@item set stopped
24155@kindex set stopped@r{, Hurd command}
24156This commands tells @value{GDBN} that the inferior process is stopped,
24157as with the @code{SIGSTOP} signal. The stopped process can be
24158continued by delivering a signal to it.
24159
24160@item show stopped
24161@kindex show stopped@r{, Hurd command}
24162This command shows whether @value{GDBN} thinks the debuggee is
24163stopped.
24164
24165@item set exceptions
24166@kindex set exceptions@r{, Hurd command}
24167Use this command to turn off trapping of exceptions in the inferior.
24168When exception trapping is off, neither breakpoints nor
24169single-stepping will work. To restore the default, set exception
24170trapping on.
24171
24172@item show exceptions
24173@kindex show exceptions@r{, Hurd command}
24174Show the current state of trapping exceptions in the inferior.
24175
24176@item set task pause
24177@kindex set task@r{, Hurd commands}
24178@cindex task attributes (@sc{gnu} Hurd)
24179@cindex pause current task (@sc{gnu} Hurd)
24180This command toggles task suspension when @value{GDBN} has control.
24181Setting it to on takes effect immediately, and the task is suspended
24182whenever @value{GDBN} gets control. Setting it to off will take
24183effect the next time the inferior is continued. If this option is set
24184to off, you can use @code{set thread default pause on} or @code{set
24185thread pause on} (see below) to pause individual threads.
24186
24187@item show task pause
24188@kindex show task@r{, Hurd commands}
24189Show the current state of task suspension.
24190
24191@item set task detach-suspend-count
24192@cindex task suspend count
24193@cindex detach from task, @sc{gnu} Hurd
24194This command sets the suspend count the task will be left with when
24195@value{GDBN} detaches from it.
24196
24197@item show task detach-suspend-count
24198Show the suspend count the task will be left with when detaching.
24199
24200@item set task exception-port
24201@itemx set task excp
24202@cindex task exception port, @sc{gnu} Hurd
24203This command sets the task exception port to which @value{GDBN} will
24204forward exceptions. The argument should be the value of the @dfn{send
24205rights} of the task. @code{set task excp} is a shorthand alias.
24206
24207@item set noninvasive
24208@cindex noninvasive task options
24209This command switches @value{GDBN} to a mode that is the least
24210invasive as far as interfering with the inferior is concerned. This
24211is the same as using @code{set task pause}, @code{set exceptions}, and
24212@code{set signals} to values opposite to the defaults.
24213
24214@item info send-rights
24215@itemx info receive-rights
24216@itemx info port-rights
24217@itemx info port-sets
24218@itemx info dead-names
24219@itemx info ports
24220@itemx info psets
24221@cindex send rights, @sc{gnu} Hurd
24222@cindex receive rights, @sc{gnu} Hurd
24223@cindex port rights, @sc{gnu} Hurd
24224@cindex port sets, @sc{gnu} Hurd
24225@cindex dead names, @sc{gnu} Hurd
24226These commands display information about, respectively, send rights,
24227receive rights, port rights, port sets, and dead names of a task.
24228There are also shorthand aliases: @code{info ports} for @code{info
24229port-rights} and @code{info psets} for @code{info port-sets}.
24230
24231@item set thread pause
24232@kindex set thread@r{, Hurd command}
24233@cindex thread properties, @sc{gnu} Hurd
24234@cindex pause current thread (@sc{gnu} Hurd)
24235This command toggles current thread suspension when @value{GDBN} has
24236control. Setting it to on takes effect immediately, and the current
24237thread is suspended whenever @value{GDBN} gets control. Setting it to
24238off will take effect the next time the inferior is continued.
24239Normally, this command has no effect, since when @value{GDBN} has
24240control, the whole task is suspended. However, if you used @code{set
24241task pause off} (see above), this command comes in handy to suspend
24242only the current thread.
24243
24244@item show thread pause
24245@kindex show thread@r{, Hurd command}
24246This command shows the state of current thread suspension.
24247
24248@item set thread run
d3e8051b 24249This command sets whether the current thread is allowed to run.
14d6dd68
EZ
24250
24251@item show thread run
24252Show whether the current thread is allowed to run.
24253
24254@item set thread detach-suspend-count
24255@cindex thread suspend count, @sc{gnu} Hurd
24256@cindex detach from thread, @sc{gnu} Hurd
24257This command sets the suspend count @value{GDBN} will leave on a
24258thread when detaching. This number is relative to the suspend count
24259found by @value{GDBN} when it notices the thread; use @code{set thread
24260takeover-suspend-count} to force it to an absolute value.
24261
24262@item show thread detach-suspend-count
24263Show the suspend count @value{GDBN} will leave on the thread when
24264detaching.
24265
24266@item set thread exception-port
24267@itemx set thread excp
24268Set the thread exception port to which to forward exceptions. This
24269overrides the port set by @code{set task exception-port} (see above).
24270@code{set thread excp} is the shorthand alias.
24271
24272@item set thread takeover-suspend-count
24273Normally, @value{GDBN}'s thread suspend counts are relative to the
24274value @value{GDBN} finds when it notices each thread. This command
24275changes the suspend counts to be absolute instead.
24276
24277@item set thread default
24278@itemx show thread default
24279@cindex thread default settings, @sc{gnu} Hurd
24280Each of the above @code{set thread} commands has a @code{set thread
24281default} counterpart (e.g., @code{set thread default pause}, @code{set
24282thread default exception-port}, etc.). The @code{thread default}
24283variety of commands sets the default thread properties for all
24284threads; you can then change the properties of individual threads with
24285the non-default commands.
24286@end table
24287
a80b95ba
TG
24288@node Darwin
24289@subsection Darwin
24290@cindex Darwin
24291
24292@value{GDBN} provides the following commands specific to the Darwin target:
24293
24294@table @code
24295@item set debug darwin @var{num}
24296@kindex set debug darwin
24297When set to a non zero value, enables debugging messages specific to
24298the Darwin support. Higher values produce more verbose output.
24299
24300@item show debug darwin
24301@kindex show debug darwin
24302Show the current state of Darwin messages.
24303
24304@item set debug mach-o @var{num}
24305@kindex set debug mach-o
24306When set to a non zero value, enables debugging messages while
24307@value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
24308file format used on Darwin for object and executable files.) Higher
24309values produce more verbose output. This is a command to diagnose
24310problems internal to @value{GDBN} and should not be needed in normal
24311usage.
24312
24313@item show debug mach-o
24314@kindex show debug mach-o
24315Show the current state of Mach-O file messages.
24316
24317@item set mach-exceptions on
24318@itemx set mach-exceptions off
24319@kindex set mach-exceptions
24320On Darwin, faults are first reported as a Mach exception and are then
24321mapped to a Posix signal. Use this command to turn on trapping of
24322Mach exceptions in the inferior. This might be sometimes useful to
24323better understand the cause of a fault. The default is off.
24324
24325@item show mach-exceptions
24326@kindex show mach-exceptions
24327Show the current state of exceptions trapping.
24328@end table
24329
e9076973
JB
24330@node FreeBSD
24331@subsection FreeBSD
24332@cindex FreeBSD
24333
24334When the ABI of a system call is changed in the FreeBSD kernel, this
24335is implemented by leaving a compatibility system call using the old
24336ABI at the existing number and allocating a new system call number for
24337the version using the new ABI. As a convenience, when a system call
24338is caught by name (@pxref{catch syscall}), compatibility system calls
24339are also caught.
24340
24341For example, FreeBSD 12 introduced a new variant of the @code{kevent}
24342system call and catching the @code{kevent} system call by name catches
24343both variants:
24344
24345@smallexample
24346(@value{GDBP}) catch syscall kevent
24347Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
24348(@value{GDBP})
24349@end smallexample
24350
a64548ea 24351
8e04817f
AC
24352@node Embedded OS
24353@section Embedded Operating Systems
104c1213 24354
8e04817f
AC
24355This section describes configurations involving the debugging of
24356embedded operating systems that are available for several different
24357architectures.
d4f3574e 24358
8e04817f
AC
24359@value{GDBN} includes the ability to debug programs running on
24360various real-time operating systems.
104c1213 24361
6d2ebf8b 24362@node Embedded Processors
104c1213
JM
24363@section Embedded Processors
24364
24365This section goes into details specific to particular embedded
24366configurations.
24367
c45da7e6
EZ
24368@cindex send command to simulator
24369Whenever a specific embedded processor has a simulator, @value{GDBN}
24370allows to send an arbitrary command to the simulator.
24371
24372@table @code
24373@item sim @var{command}
24374@kindex sim@r{, a command}
24375Send an arbitrary @var{command} string to the simulator. Consult the
24376documentation for the specific simulator in use for information about
24377acceptable commands.
24378@end table
24379
7d86b5d5 24380
104c1213 24381@menu
ad0a504f 24382* ARC:: Synopsys ARC
bb615428 24383* ARM:: ARM
104c1213 24384* M68K:: Motorola M68K
08be9d71 24385* MicroBlaze:: Xilinx MicroBlaze
104c1213 24386* MIPS Embedded:: MIPS Embedded
a994fec4 24387* OpenRISC 1000:: OpenRISC 1000 (or1k)
4acd40f3 24388* PowerPC Embedded:: PowerPC Embedded
a64548ea
EZ
24389* AVR:: Atmel AVR
24390* CRIS:: CRIS
24391* Super-H:: Renesas Super-H
104c1213
JM
24392@end menu
24393
ad0a504f
AK
24394@node ARC
24395@subsection Synopsys ARC
24396@cindex Synopsys ARC
24397@cindex ARC specific commands
24398@cindex ARC600
24399@cindex ARC700
24400@cindex ARC EM
24401@cindex ARC HS
24402
24403@value{GDBN} provides the following ARC-specific commands:
24404
24405@table @code
24406@item set debug arc
24407@kindex set debug arc
24408Control the level of ARC specific debug messages. Use 0 for no messages (the
fe5f7374 24409default), 1 for debug messages, and 2 for even more debug messages.
ad0a504f
AK
24410
24411@item show debug arc
24412@kindex show debug arc
24413Show the level of ARC specific debugging in operation.
24414
eea78757
AK
24415@item maint print arc arc-instruction @var{address}
24416@kindex maint print arc arc-instruction
24417Print internal disassembler information about instruction at a given address.
24418
ad0a504f
AK
24419@end table
24420
6d2ebf8b 24421@node ARM
104c1213 24422@subsection ARM
8e04817f 24423
e2f4edfd
EZ
24424@value{GDBN} provides the following ARM-specific commands:
24425
24426@table @code
24427@item set arm disassembler
24428@kindex set arm
24429This commands selects from a list of disassembly styles. The
24430@code{"std"} style is the standard style.
24431
24432@item show arm disassembler
24433@kindex show arm
24434Show the current disassembly style.
24435
24436@item set arm apcs32
24437@cindex ARM 32-bit mode
24438This command toggles ARM operation mode between 32-bit and 26-bit.
24439
24440@item show arm apcs32
24441Display the current usage of the ARM 32-bit mode.
24442
24443@item set arm fpu @var{fputype}
24444This command sets the ARM floating-point unit (FPU) type. The
24445argument @var{fputype} can be one of these:
24446
24447@table @code
24448@item auto
24449Determine the FPU type by querying the OS ABI.
24450@item softfpa
24451Software FPU, with mixed-endian doubles on little-endian ARM
24452processors.
24453@item fpa
24454GCC-compiled FPA co-processor.
24455@item softvfp
24456Software FPU with pure-endian doubles.
24457@item vfp
24458VFP co-processor.
24459@end table
24460
24461@item show arm fpu
24462Show the current type of the FPU.
24463
24464@item set arm abi
24465This command forces @value{GDBN} to use the specified ABI.
24466
24467@item show arm abi
24468Show the currently used ABI.
24469
0428b8f5
DJ
24470@item set arm fallback-mode (arm|thumb|auto)
24471@value{GDBN} uses the symbol table, when available, to determine
24472whether instructions are ARM or Thumb. This command controls
24473@value{GDBN}'s default behavior when the symbol table is not
24474available. The default is @samp{auto}, which causes @value{GDBN} to
24475use the current execution mode (from the @code{T} bit in the @code{CPSR}
24476register).
24477
24478@item show arm fallback-mode
24479Show the current fallback instruction mode.
24480
24481@item set arm force-mode (arm|thumb|auto)
24482This command overrides use of the symbol table to determine whether
24483instructions are ARM or Thumb. The default is @samp{auto}, which
24484causes @value{GDBN} to use the symbol table and then the setting
24485of @samp{set arm fallback-mode}.
24486
24487@item show arm force-mode
24488Show the current forced instruction mode.
24489
e2f4edfd
EZ
24490@item set debug arm
24491Toggle whether to display ARM-specific debugging messages from the ARM
24492target support subsystem.
24493
24494@item show debug arm
24495Show whether ARM-specific debugging messages are enabled.
24496@end table
24497
ee8e71d4
EZ
24498@table @code
24499@item target sim @r{[}@var{simargs}@r{]} @dots{}
24500The @value{GDBN} ARM simulator accepts the following optional arguments.
24501
24502@table @code
24503@item --swi-support=@var{type}
697aa1b7 24504Tell the simulator which SWI interfaces to support. The argument
ee8e71d4
EZ
24505@var{type} may be a comma separated list of the following values.
24506The default value is @code{all}.
24507
24508@table @code
24509@item none
24510@item demon
24511@item angel
24512@item redboot
24513@item all
24514@end table
24515@end table
24516@end table
e2f4edfd 24517
8e04817f
AC
24518@node M68K
24519@subsection M68k
24520
bb615428 24521The Motorola m68k configuration includes ColdFire support.
8e04817f 24522
08be9d71
ME
24523@node MicroBlaze
24524@subsection MicroBlaze
24525@cindex Xilinx MicroBlaze
24526@cindex XMD, Xilinx Microprocessor Debugger
24527
24528The MicroBlaze is a soft-core processor supported on various Xilinx
24529FPGAs, such as Spartan or Virtex series. Boards with these processors
24530usually have JTAG ports which connect to a host system running the Xilinx
24531Embedded Development Kit (EDK) or Software Development Kit (SDK).
24532This host system is used to download the configuration bitstream to
24533the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
24534communicates with the target board using the JTAG interface and
24535presents a @code{gdbserver} interface to the board. By default
24536@code{xmd} uses port @code{1234}. (While it is possible to change
24537this default port, it requires the use of undocumented @code{xmd}
24538commands. Contact Xilinx support if you need to do this.)
24539
24540Use these GDB commands to connect to the MicroBlaze target processor.
24541
24542@table @code
24543@item target remote :1234
24544Use this command to connect to the target if you are running @value{GDBN}
24545on the same system as @code{xmd}.
24546
24547@item target remote @var{xmd-host}:1234
24548Use this command to connect to the target if it is connected to @code{xmd}
24549running on a different system named @var{xmd-host}.
24550
24551@item load
24552Use this command to download a program to the MicroBlaze target.
24553
24554@item set debug microblaze @var{n}
24555Enable MicroBlaze-specific debugging messages if non-zero.
24556
24557@item show debug microblaze @var{n}
24558Show MicroBlaze-specific debugging level.
24559@end table
24560
8e04817f 24561@node MIPS Embedded
eb17f351 24562@subsection @acronym{MIPS} Embedded
8e04817f 24563
8e04817f 24564@noindent
f7c38292 24565@value{GDBN} supports these special commands for @acronym{MIPS} targets:
104c1213 24566
8e04817f 24567@table @code
8e04817f
AC
24568@item set mipsfpu double
24569@itemx set mipsfpu single
24570@itemx set mipsfpu none
a64548ea 24571@itemx set mipsfpu auto
8e04817f
AC
24572@itemx show mipsfpu
24573@kindex set mipsfpu
24574@kindex show mipsfpu
eb17f351
EZ
24575@cindex @acronym{MIPS} remote floating point
24576@cindex floating point, @acronym{MIPS} remote
24577If your target board does not support the @acronym{MIPS} floating point
8e04817f
AC
24578coprocessor, you should use the command @samp{set mipsfpu none} (if you
24579need this, you may wish to put the command in your @value{GDBN} init
24580file). This tells @value{GDBN} how to find the return value of
24581functions which return floating point values. It also allows
24582@value{GDBN} to avoid saving the floating point registers when calling
24583functions on the board. If you are using a floating point coprocessor
24584with only single precision floating point support, as on the @sc{r4650}
24585processor, use the command @samp{set mipsfpu single}. The default
24586double precision floating point coprocessor may be selected using
24587@samp{set mipsfpu double}.
104c1213 24588
8e04817f
AC
24589In previous versions the only choices were double precision or no
24590floating point, so @samp{set mipsfpu on} will select double precision
24591and @samp{set mipsfpu off} will select no floating point.
104c1213 24592
8e04817f
AC
24593As usual, you can inquire about the @code{mipsfpu} variable with
24594@samp{show mipsfpu}.
8e04817f 24595@end table
104c1213 24596
a994fec4
FJ
24597@node OpenRISC 1000
24598@subsection OpenRISC 1000
24599@cindex OpenRISC 1000
24600
24601@noindent
24602The OpenRISC 1000 provides a free RISC instruction set architecture. It is
24603mainly provided as a soft-core which can run on Xilinx, Altera and other
24604FPGA's.
24605
24606@value{GDBN} for OpenRISC supports the below commands when connecting to
24607a target:
24608
24609@table @code
24610
24611@kindex target sim
24612@item target sim
24613
24614Runs the builtin CPU simulator which can run very basic
24615programs but does not support most hardware functions like MMU.
24616For more complex use cases the user is advised to run an external
24617target, and connect using @samp{target remote}.
24618
24619Example: @code{target sim}
24620
24621@item set debug or1k
24622Toggle whether to display OpenRISC-specific debugging messages from the
24623OpenRISC target support subsystem.
24624
24625@item show debug or1k
24626Show whether OpenRISC-specific debugging messages are enabled.
24627@end table
24628
4acd40f3
TJB
24629@node PowerPC Embedded
24630@subsection PowerPC Embedded
104c1213 24631
66b73624
TJB
24632@cindex DVC register
24633@value{GDBN} supports using the DVC (Data Value Compare) register to
24634implement in hardware simple hardware watchpoint conditions of the form:
24635
24636@smallexample
24637(@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
24638 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
24639@end smallexample
24640
e09342b5
TJB
24641The DVC register will be automatically used when @value{GDBN} detects
24642such pattern in a condition expression, and the created watchpoint uses one
24643debug register (either the @code{exact-watchpoints} option is on and the
24644variable is scalar, or the variable has a length of one byte). This feature
24645is available in native @value{GDBN} running on a Linux kernel version 2.6.34
24646or newer.
24647
24648When running on PowerPC embedded processors, @value{GDBN} automatically uses
24649ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
24650in which case watchpoints using only one debug register are created when
24651watching variables of scalar types.
24652
24653You can create an artificial array to watch an arbitrary memory
24654region using one of the following commands (@pxref{Expressions}):
24655
24656@smallexample
24657(@value{GDBP}) watch *((char *) @var{address})@@@var{length}
24658(@value{GDBP}) watch @{char[@var{length}]@} @var{address}
24659@end smallexample
66b73624 24660
9c06b0b4
TJB
24661PowerPC embedded processors support masked watchpoints. See the discussion
24662about the @code{mask} argument in @ref{Set Watchpoints}.
24663
f1310107
TJB
24664@cindex ranged breakpoint
24665PowerPC embedded processors support hardware accelerated
24666@dfn{ranged breakpoints}. A ranged breakpoint stops execution of
24667the inferior whenever it executes an instruction at any address within
24668the range it specifies. To set a ranged breakpoint in @value{GDBN},
24669use the @code{break-range} command.
24670
55eddb0f
DJ
24671@value{GDBN} provides the following PowerPC-specific commands:
24672
104c1213 24673@table @code
f1310107
TJB
24674@kindex break-range
24675@item break-range @var{start-location}, @var{end-location}
697aa1b7
EZ
24676Set a breakpoint for an address range given by
24677@var{start-location} and @var{end-location}, which can specify a function name,
f1310107
TJB
24678a line number, an offset of lines from the current line or from the start
24679location, or an address of an instruction (see @ref{Specify Location},
24680for a list of all the possible ways to specify a @var{location}.)
24681The breakpoint will stop execution of the inferior whenever it
24682executes an instruction at any address within the specified range,
24683(including @var{start-location} and @var{end-location}.)
24684
55eddb0f
DJ
24685@kindex set powerpc
24686@item set powerpc soft-float
24687@itemx show powerpc soft-float
24688Force @value{GDBN} to use (or not use) a software floating point calling
24689convention. By default, @value{GDBN} selects the calling convention based
24690on the selected architecture and the provided executable file.
24691
24692@item set powerpc vector-abi
24693@itemx show powerpc vector-abi
24694Force @value{GDBN} to use the specified calling convention for vector
24695arguments and return values. The valid options are @samp{auto};
24696@samp{generic}, to avoid vector registers even if they are present;
24697@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
24698registers. By default, @value{GDBN} selects the calling convention
24699based on the selected architecture and the provided executable file.
24700
e09342b5
TJB
24701@item set powerpc exact-watchpoints
24702@itemx show powerpc exact-watchpoints
24703Allow @value{GDBN} to use only one debug register when watching a variable
24704of scalar type, thus assuming that the variable is accessed through the
24705address of its first byte.
24706
104c1213
JM
24707@end table
24708
a64548ea
EZ
24709@node AVR
24710@subsection Atmel AVR
24711@cindex AVR
24712
24713When configured for debugging the Atmel AVR, @value{GDBN} supports the
24714following AVR-specific commands:
24715
24716@table @code
24717@item info io_registers
24718@kindex info io_registers@r{, AVR}
24719@cindex I/O registers (Atmel AVR)
24720This command displays information about the AVR I/O registers. For
24721each register, @value{GDBN} prints its number and value.
24722@end table
24723
24724@node CRIS
24725@subsection CRIS
24726@cindex CRIS
24727
24728When configured for debugging CRIS, @value{GDBN} provides the
24729following CRIS-specific commands:
24730
24731@table @code
24732@item set cris-version @var{ver}
24733@cindex CRIS version
e22e55c9
OF
24734Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
24735The CRIS version affects register names and sizes. This command is useful in
24736case autodetection of the CRIS version fails.
a64548ea
EZ
24737
24738@item show cris-version
24739Show the current CRIS version.
24740
24741@item set cris-dwarf2-cfi
24742@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
24743Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
24744Change to @samp{off} when using @code{gcc-cris} whose version is below
24745@code{R59}.
a64548ea
EZ
24746
24747@item show cris-dwarf2-cfi
24748Show the current state of using DWARF-2 CFI.
e22e55c9
OF
24749
24750@item set cris-mode @var{mode}
24751@cindex CRIS mode
24752Set the current CRIS mode to @var{mode}. It should only be changed when
24753debugging in guru mode, in which case it should be set to
24754@samp{guru} (the default is @samp{normal}).
24755
24756@item show cris-mode
24757Show the current CRIS mode.
a64548ea
EZ
24758@end table
24759
24760@node Super-H
24761@subsection Renesas Super-H
24762@cindex Super-H
24763
24764For the Renesas Super-H processor, @value{GDBN} provides these
24765commands:
24766
24767@table @code
c055b101
CV
24768@item set sh calling-convention @var{convention}
24769@kindex set sh calling-convention
24770Set the calling-convention used when calling functions from @value{GDBN}.
24771Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
24772With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
24773convention. If the DWARF-2 information of the called function specifies
24774that the function follows the Renesas calling convention, the function
24775is called using the Renesas calling convention. If the calling convention
24776is set to @samp{renesas}, the Renesas calling convention is always used,
24777regardless of the DWARF-2 information. This can be used to override the
24778default of @samp{gcc} if debug information is missing, or the compiler
24779does not emit the DWARF-2 calling convention entry for a function.
24780
24781@item show sh calling-convention
24782@kindex show sh calling-convention
24783Show the current calling convention setting.
24784
a64548ea
EZ
24785@end table
24786
24787
8e04817f
AC
24788@node Architectures
24789@section Architectures
104c1213 24790
8e04817f
AC
24791This section describes characteristics of architectures that affect
24792all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 24793
8e04817f 24794@menu
430ed3f0 24795* AArch64::
9c16f35a 24796* i386::
8e04817f
AC
24797* Alpha::
24798* MIPS::
a64548ea 24799* HPPA:: HP PA architecture
4acd40f3 24800* PowerPC::
a1217d97 24801* Nios II::
58afddc6 24802* Sparc64::
51d21d60 24803* S12Z::
8e04817f 24804@end menu
104c1213 24805
430ed3f0
MS
24806@node AArch64
24807@subsection AArch64
24808@cindex AArch64 support
24809
24810When @value{GDBN} is debugging the AArch64 architecture, it provides the
24811following special commands:
24812
24813@table @code
24814@item set debug aarch64
24815@kindex set debug aarch64
24816This command determines whether AArch64 architecture-specific debugging
24817messages are to be displayed.
24818
24819@item show debug aarch64
24820Show whether AArch64 debugging messages are displayed.
24821
24822@end table
24823
1461bdac
AH
24824@subsubsection AArch64 SVE.
24825@cindex AArch64 SVE.
24826
24827When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
24828Extension (SVE) is present, then @value{GDBN} will provide the vector registers
24829@code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
24830@code{$p15}, and the @code{$ffr} register. In addition, the pseudo register
24831@code{$vg} will be provided. This is the vector granule for the current thread
24832and represents the number of 64-bit chunks in an SVE @code{z} register.
24833
24834If the vector length changes, then the @code{$vg} register will be updated,
24835but the lengths of the @code{z} and @code{p} registers will not change. This
24836is a known limitation of @value{GDBN} and does not affect the execution of the
24837target process.
24838
3d31bc39
AH
24839@subsubsection AArch64 Pointer Authentication.
24840@cindex AArch64 Pointer Authentication.
24841
24842When @value{GDBN} is debugging the AArch64 architecture, and the program is
24843using the v8.3-A feature Pointer Authentication (PAC), then whenever the link
1ba7cdcd 24844register @code{$lr} is pointing to an PAC function its value will be masked.
3d31bc39 24845When GDB prints a backtrace, any addresses that required unmasking will be
aa7ca1bb
AH
24846postfixed with the marker [PAC]. When using the MI, this is printed as part
24847of the @code{addr_flags} field.
1461bdac 24848
9c16f35a 24849@node i386
db2e3e2e 24850@subsection x86 Architecture-specific Issues
9c16f35a
EZ
24851
24852@table @code
24853@item set struct-convention @var{mode}
24854@kindex set struct-convention
24855@cindex struct return convention
24856@cindex struct/union returned in registers
24857Set the convention used by the inferior to return @code{struct}s and
24858@code{union}s from functions to @var{mode}. Possible values of
24859@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
24860default). @code{"default"} or @code{"pcc"} means that @code{struct}s
24861are returned on the stack, while @code{"reg"} means that a
24862@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
24863be returned in a register.
24864
24865@item show struct-convention
24866@kindex show struct-convention
24867Show the current setting of the convention to return @code{struct}s
24868from functions.
966f0aef 24869@end table
29c1c244 24870
ca8941bb 24871
bc504a31
PA
24872@subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
24873@cindex Intel Memory Protection Extensions (MPX).
ca8941bb 24874
ca8941bb
WT
24875Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
24876@footnote{The register named with capital letters represent the architecture
24877registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
24878which are the lower bound and upper bound. Bounds are effective addresses or
24879memory locations. The upper bounds are architecturally represented in 1's
24880complement form. A bound having lower bound = 0, and upper bound = 0
24881(1's complement of all bits set) will allow access to the entire address space.
24882
24883@samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
24884through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
24885display the upper bound performing the complement of one operation on the
24886upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
24887@value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
24888can also be noted that the upper bounds are inclusive.
24889
24890As an example, assume that the register BND0 holds bounds for a pointer having
24891access allowed for the range between 0x32 and 0x71. The values present on
24892bnd0raw and bnd registers are presented as follows:
24893
24894@smallexample
24895 bnd0raw = @{0x32, 0xffffffff8e@}
24896 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
24897@end smallexample
24898
22f25c9d
EZ
24899This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
24900change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
24901counterpart. When the bnd0@dots{}bnd3 registers are displayed via
24902Python, the display includes the memory size, in bits, accessible to
24903the pointer.
9c16f35a 24904
29c1c244
WT
24905Bounds can also be stored in bounds tables, which are stored in
24906application memory. These tables store bounds for pointers by specifying
24907the bounds pointer's value along with its bounds. Evaluating and changing
24908bounds located in bound tables is therefore interesting while investigating
24909bugs on MPX context. @value{GDBN} provides commands for this purpose:
24910
966f0aef 24911@table @code
29c1c244
WT
24912@item show mpx bound @var{pointer}
24913@kindex show mpx bound
24914Display bounds of the given @var{pointer}.
24915
24916@item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
24917@kindex set mpx bound
24918Set the bounds of a pointer in the bound table.
24919This command takes three parameters: @var{pointer} is the pointers
24920whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
24921for lower and upper bounds respectively.
24922@end table
24923
4a612d6f
WT
24924When you call an inferior function on an Intel MPX enabled program,
24925GDB sets the inferior's bound registers to the init (disabled) state
24926before calling the function. As a consequence, bounds checks for the
24927pointer arguments passed to the function will always pass.
24928
24929This is necessary because when you call an inferior function, the
24930program is usually in the middle of the execution of other function.
24931Since at that point bound registers are in an arbitrary state, not
24932clearing them would lead to random bound violations in the called
24933function.
24934
24935You can still examine the influence of the bound registers on the
24936execution of the called function by stopping the execution of the
24937called function at its prologue, setting bound registers, and
24938continuing the execution. For example:
24939
24940@smallexample
24941 $ break *upper
24942 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
24943 $ print upper (a, b, c, d, 1)
24944 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
24945 $ print $bnd0
5cf70512 24946 @{lbound = 0x0, ubound = ffffffff@} : size -1
4a612d6f
WT
24947@end smallexample
24948
24949At this last step the value of bnd0 can be changed for investigation of bound
24950violations caused along the execution of the call. In order to know how to
24951set the bound registers or bound table for the call consult the ABI.
24952
8e04817f
AC
24953@node Alpha
24954@subsection Alpha
104c1213 24955
8e04817f 24956See the following section.
104c1213 24957
8e04817f 24958@node MIPS
eb17f351 24959@subsection @acronym{MIPS}
104c1213 24960
8e04817f 24961@cindex stack on Alpha
eb17f351 24962@cindex stack on @acronym{MIPS}
8e04817f 24963@cindex Alpha stack
eb17f351
EZ
24964@cindex @acronym{MIPS} stack
24965Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
8e04817f
AC
24966sometimes requires @value{GDBN} to search backward in the object code to
24967find the beginning of a function.
104c1213 24968
eb17f351 24969@cindex response time, @acronym{MIPS} debugging
8e04817f
AC
24970To improve response time (especially for embedded applications, where
24971@value{GDBN} may be restricted to a slow serial line for this search)
24972you may want to limit the size of this search, using one of these
24973commands:
104c1213 24974
8e04817f 24975@table @code
eb17f351 24976@cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
8e04817f
AC
24977@item set heuristic-fence-post @var{limit}
24978Restrict @value{GDBN} to examining at most @var{limit} bytes in its
24979search for the beginning of a function. A value of @var{0} (the
24980default) means there is no limit. However, except for @var{0}, the
24981larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
24982and therefore the longer it takes to run. You should only need to use
24983this command when debugging a stripped executable.
104c1213 24984
8e04817f
AC
24985@item show heuristic-fence-post
24986Display the current limit.
24987@end table
104c1213
JM
24988
24989@noindent
8e04817f 24990These commands are available @emph{only} when @value{GDBN} is configured
eb17f351 24991for debugging programs on Alpha or @acronym{MIPS} processors.
104c1213 24992
eb17f351 24993Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
a64548ea
EZ
24994programs:
24995
24996@table @code
a64548ea
EZ
24997@item set mips abi @var{arg}
24998@kindex set mips abi
eb17f351
EZ
24999@cindex set ABI for @acronym{MIPS}
25000Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
a64548ea
EZ
25001values of @var{arg} are:
25002
25003@table @samp
25004@item auto
25005The default ABI associated with the current binary (this is the
25006default).
25007@item o32
25008@item o64
25009@item n32
25010@item n64
25011@item eabi32
25012@item eabi64
a64548ea
EZ
25013@end table
25014
25015@item show mips abi
25016@kindex show mips abi
eb17f351 25017Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
a64548ea 25018
4cc0665f
MR
25019@item set mips compression @var{arg}
25020@kindex set mips compression
25021@cindex code compression, @acronym{MIPS}
25022Tell @value{GDBN} which @acronym{MIPS} compressed
25023@acronym{ISA, Instruction Set Architecture} encoding is used by the
25024inferior. @value{GDBN} uses this for code disassembly and other
25025internal interpretation purposes. This setting is only referred to
25026when no executable has been associated with the debugging session or
25027the executable does not provide information about the encoding it uses.
25028Otherwise this setting is automatically updated from information
25029provided by the executable.
25030
25031Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
25032The default compressed @acronym{ISA} encoding is @samp{mips16}, as
25033executables containing @acronym{MIPS16} code frequently are not
25034identified as such.
25035
25036This setting is ``sticky''; that is, it retains its value across
25037debugging sessions until reset either explicitly with this command or
25038implicitly from an executable.
25039
25040The compiler and/or assembler typically add symbol table annotations to
25041identify functions compiled for the @acronym{MIPS16} or
25042@acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
25043are present, @value{GDBN} uses them in preference to the global
25044compressed @acronym{ISA} encoding setting.
25045
25046@item show mips compression
25047@kindex show mips compression
25048Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
25049@value{GDBN} to debug the inferior.
25050
a64548ea
EZ
25051@item set mipsfpu
25052@itemx show mipsfpu
25053@xref{MIPS Embedded, set mipsfpu}.
25054
25055@item set mips mask-address @var{arg}
25056@kindex set mips mask-address
eb17f351 25057@cindex @acronym{MIPS} addresses, masking
a64548ea 25058This command determines whether the most-significant 32 bits of 64-bit
eb17f351 25059@acronym{MIPS} addresses are masked off. The argument @var{arg} can be
a64548ea
EZ
25060@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
25061setting, which lets @value{GDBN} determine the correct value.
25062
25063@item show mips mask-address
25064@kindex show mips mask-address
eb17f351 25065Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
a64548ea
EZ
25066not.
25067
25068@item set remote-mips64-transfers-32bit-regs
25069@kindex set remote-mips64-transfers-32bit-regs
eb17f351
EZ
25070This command controls compatibility with 64-bit @acronym{MIPS} targets that
25071transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
a64548ea
EZ
25072that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
25073and 64 bits for other registers, set this option to @samp{on}.
25074
25075@item show remote-mips64-transfers-32bit-regs
25076@kindex show remote-mips64-transfers-32bit-regs
eb17f351 25077Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
a64548ea
EZ
25078
25079@item set debug mips
25080@kindex set debug mips
eb17f351 25081This command turns on and off debugging messages for the @acronym{MIPS}-specific
a64548ea
EZ
25082target code in @value{GDBN}.
25083
25084@item show debug mips
25085@kindex show debug mips
eb17f351 25086Show the current setting of @acronym{MIPS} debugging messages.
a64548ea
EZ
25087@end table
25088
25089
25090@node HPPA
25091@subsection HPPA
25092@cindex HPPA support
25093
d3e8051b 25094When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
25095following special commands:
25096
25097@table @code
25098@item set debug hppa
25099@kindex set debug hppa
db2e3e2e 25100This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
25101messages are to be displayed.
25102
25103@item show debug hppa
25104Show whether HPPA debugging messages are displayed.
25105
25106@item maint print unwind @var{address}
25107@kindex maint print unwind@r{, HPPA}
25108This command displays the contents of the unwind table entry at the
25109given @var{address}.
25110
25111@end table
25112
104c1213 25113
4acd40f3
TJB
25114@node PowerPC
25115@subsection PowerPC
25116@cindex PowerPC architecture
25117
25118When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
25119pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
25120numbers stored in the floating point registers. These values must be stored
25121in two consecutive registers, always starting at an even register like
25122@code{f0} or @code{f2}.
25123
25124The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
25125by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
25126@code{f2} and @code{f3} for @code{$dl1} and so on.
25127
aeac0ff9 25128For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
677c5bb1
LM
25129wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
25130
a1217d97
SL
25131@node Nios II
25132@subsection Nios II
25133@cindex Nios II architecture
25134
25135When @value{GDBN} is debugging the Nios II architecture,
25136it provides the following special commands:
25137
25138@table @code
25139
25140@item set debug nios2
25141@kindex set debug nios2
25142This command turns on and off debugging messages for the Nios II
25143target code in @value{GDBN}.
25144
25145@item show debug nios2
25146@kindex show debug nios2
25147Show the current setting of Nios II debugging messages.
25148@end table
23d964e7 25149
58afddc6
WP
25150@node Sparc64
25151@subsection Sparc64
25152@cindex Sparc64 support
25153@cindex Application Data Integrity
25154@subsubsection ADI Support
25155
25156The M7 processor supports an Application Data Integrity (ADI) feature that
25157detects invalid data accesses. When software allocates memory and enables
25158ADI on the allocated memory, it chooses a 4-bit version number, sets the
25159version in the upper 4 bits of the 64-bit pointer to that data, and stores
25160the 4-bit version in every cacheline of that data. Hardware saves the latter
25161in spare bits in the cache and memory hierarchy. On each load and store,
25162the processor compares the upper 4 VA (virtual address) bits to the
25163cacheline's version. If there is a mismatch, the processor generates a
25164version mismatch trap which can be either precise or disrupting. The trap
25165is an error condition which the kernel delivers to the process as a SIGSEGV
25166signal.
25167
25168Note that only 64-bit applications can use ADI and need to be built with
25169ADI-enabled.
25170
25171Values of the ADI version tags, which are in granularity of a
25172cacheline (64 bytes), can be viewed or modified.
25173
25174
25175@table @code
25176@kindex adi examine
25177@item adi (examine | x) [ / @var{n} ] @var{addr}
25178
25179The @code{adi examine} command displays the value of one ADI version tag per
25180cacheline.
25181
25182@var{n} is a decimal integer specifying the number in bytes; the default
25183is 1. It specifies how much ADI version information, at the ratio of 1:ADI
25184block size, to display.
25185
25186@var{addr} is the address in user address space where you want @value{GDBN}
25187to begin displaying the ADI version tags.
25188
25189Below is an example of displaying ADI versions of variable "shmaddr".
25190
25191@smallexample
25192(@value{GDBP}) adi x/100 shmaddr
25193 0xfff800010002c000: 0 0
25194@end smallexample
25195
25196@kindex adi assign
25197@item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
25198
25199The @code{adi assign} command is used to assign new ADI version tag
25200to an address.
25201
25202@var{n} is a decimal integer specifying the number in bytes;
25203the default is 1. It specifies how much ADI version information, at the
25204ratio of 1:ADI block size, to modify.
25205
25206@var{addr} is the address in user address space where you want @value{GDBN}
25207to begin modifying the ADI version tags.
25208
25209@var{tag} is the new ADI version tag.
25210
25211For example, do the following to modify then verify ADI versions of
25212variable "shmaddr":
25213
25214@smallexample
25215(@value{GDBP}) adi a/100 shmaddr = 7
25216(@value{GDBP}) adi x/100 shmaddr
25217 0xfff800010002c000: 7 7
25218@end smallexample
25219
25220@end table
25221
51d21d60
JD
25222@node S12Z
25223@subsection S12Z
25224@cindex S12Z support
25225
25226When @value{GDBN} is debugging the S12Z architecture,
25227it provides the following special command:
25228
25229@table @code
25230@item maint info bdccsr
25231@kindex maint info bdccsr@r{, S12Z}
25232This command displays the current value of the microprocessor's
25233BDCCSR register.
25234@end table
25235
25236
8e04817f
AC
25237@node Controlling GDB
25238@chapter Controlling @value{GDBN}
25239
25240You can alter the way @value{GDBN} interacts with you by using the
25241@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 25242data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
25243described here.
25244
25245@menu
25246* Prompt:: Prompt
25247* Editing:: Command editing
d620b259 25248* Command History:: Command history
8e04817f 25249* Screen Size:: Screen size
140a4bc0 25250* Output Styling:: Output styling
8e04817f 25251* Numbers:: Numbers
1e698235 25252* ABI:: Configuring the current ABI
bf88dd68 25253* Auto-loading:: Automatically loading associated files
8e04817f
AC
25254* Messages/Warnings:: Optional warnings and messages
25255* Debugging Output:: Optional messages about internal happenings
14fb1bac 25256* Other Misc Settings:: Other Miscellaneous Settings
8e04817f
AC
25257@end menu
25258
25259@node Prompt
25260@section Prompt
104c1213 25261
8e04817f 25262@cindex prompt
104c1213 25263
8e04817f
AC
25264@value{GDBN} indicates its readiness to read a command by printing a string
25265called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
25266can change the prompt string with the @code{set prompt} command. For
25267instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
25268the prompt in one of the @value{GDBN} sessions so that you can always tell
25269which one you are talking to.
104c1213 25270
8e04817f
AC
25271@emph{Note:} @code{set prompt} does not add a space for you after the
25272prompt you set. This allows you to set a prompt which ends in a space
25273or a prompt that does not.
104c1213 25274
8e04817f
AC
25275@table @code
25276@kindex set prompt
25277@item set prompt @var{newprompt}
25278Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 25279
8e04817f
AC
25280@kindex show prompt
25281@item show prompt
25282Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
25283@end table
25284
fa3a4f15
PM
25285Versions of @value{GDBN} that ship with Python scripting enabled have
25286prompt extensions. The commands for interacting with these extensions
25287are:
25288
25289@table @code
25290@kindex set extended-prompt
25291@item set extended-prompt @var{prompt}
25292Set an extended prompt that allows for substitutions.
25293@xref{gdb.prompt}, for a list of escape sequences that can be used for
25294substitution. Any escape sequences specified as part of the prompt
25295string are replaced with the corresponding strings each time the prompt
25296is displayed.
25297
25298For example:
25299
25300@smallexample
25301set extended-prompt Current working directory: \w (gdb)
25302@end smallexample
25303
25304Note that when an extended-prompt is set, it takes control of the
25305@var{prompt_hook} hook. @xref{prompt_hook}, for further information.
25306
25307@kindex show extended-prompt
25308@item show extended-prompt
25309Prints the extended prompt. Any escape sequences specified as part of
25310the prompt string with @code{set extended-prompt}, are replaced with the
25311corresponding strings each time the prompt is displayed.
25312@end table
25313
8e04817f 25314@node Editing
79a6e687 25315@section Command Editing
8e04817f
AC
25316@cindex readline
25317@cindex command line editing
104c1213 25318
703663ab 25319@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
25320@sc{gnu} library provides consistent behavior for programs which provide a
25321command line interface to the user. Advantages are @sc{gnu} Emacs-style
25322or @dfn{vi}-style inline editing of commands, @code{csh}-like history
25323substitution, and a storage and recall of command history across
25324debugging sessions.
104c1213 25325
8e04817f
AC
25326You may control the behavior of command line editing in @value{GDBN} with the
25327command @code{set}.
104c1213 25328
8e04817f
AC
25329@table @code
25330@kindex set editing
25331@cindex editing
25332@item set editing
25333@itemx set editing on
25334Enable command line editing (enabled by default).
104c1213 25335
8e04817f
AC
25336@item set editing off
25337Disable command line editing.
104c1213 25338
8e04817f
AC
25339@kindex show editing
25340@item show editing
25341Show whether command line editing is enabled.
104c1213
JM
25342@end table
25343
39037522
TT
25344@ifset SYSTEM_READLINE
25345@xref{Command Line Editing, , , rluserman, GNU Readline Library},
25346@end ifset
25347@ifclear SYSTEM_READLINE
25348@xref{Command Line Editing},
25349@end ifclear
25350for more details about the Readline
703663ab
EZ
25351interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
25352encouraged to read that chapter.
25353
11061048
TT
25354@cindex Readline application name
25355@value{GDBN} sets the Readline application name to @samp{gdb}. This
25356is useful for conditions in @file{.inputrc}.
25357
c71acd15
TT
25358@cindex operate-and-get-next
25359@value{GDBN} defines a bindable Readline command,
25360@code{operate-and-get-next}. This is bound to @kbd{C-o} by default.
25361This command accepts the current line for execution and fetches the
25362next line relative to the current line from the history for editing.
25363Any argument is ignored.
25364
d620b259 25365@node Command History
79a6e687 25366@section Command History
703663ab 25367@cindex command history
8e04817f
AC
25368
25369@value{GDBN} can keep track of the commands you type during your
25370debugging sessions, so that you can be certain of precisely what
25371happened. Use these commands to manage the @value{GDBN} command
25372history facility.
104c1213 25373
703663ab 25374@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
39037522
TT
25375package, to provide the history facility.
25376@ifset SYSTEM_READLINE
25377@xref{Using History Interactively, , , history, GNU History Library},
25378@end ifset
25379@ifclear SYSTEM_READLINE
25380@xref{Using History Interactively},
25381@end ifclear
25382for the detailed description of the History library.
703663ab 25383
d620b259 25384To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
25385the state which is seen by users, prefix it with @samp{server }
25386(@pxref{Server Prefix}). This
d620b259
NR
25387means that this command will not affect the command history, nor will it
25388affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
25389pressed on a line by itself.
25390
25391@cindex @code{server}, command prefix
25392The server prefix does not affect the recording of values into the value
25393history; to print a value without recording it into the value history,
25394use the @code{output} command instead of the @code{print} command.
25395
703663ab
EZ
25396Here is the description of @value{GDBN} commands related to command
25397history.
25398
104c1213 25399@table @code
8e04817f
AC
25400@cindex history substitution
25401@cindex history file
25402@kindex set history filename
4644b6e3 25403@cindex @env{GDBHISTFILE}, environment variable
63e163f2 25404@item set history filename @r{[}@var{fname}@r{]}
8e04817f
AC
25405Set the name of the @value{GDBN} command history file to @var{fname}.
25406This is the file where @value{GDBN} reads an initial command history
25407list, and where it writes the command history from this session when it
25408exits. You can access this list through history expansion or through
25409the history command editing characters listed below. This file defaults
25410to the value of the environment variable @code{GDBHISTFILE}, or to
25411@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
25412is not set.
104c1213 25413
63e163f2
AB
25414The @code{GDBHISTFILE} environment variable is read after processing
25415any @value{GDBN} initialization files (@pxref{Startup}) and after
25416processing any commands passed using command line options (for
25417example, @code{-ex}).
25418
25419If the @var{fname} argument is not given, or if the @code{GDBHISTFILE}
25420is the empty string then @value{GDBN} will neither try to load an
25421existing history file, nor will it try to save the history on exit.
25422
9c16f35a
EZ
25423@cindex save command history
25424@kindex set history save
8e04817f
AC
25425@item set history save
25426@itemx set history save on
25427Record command history in a file, whose name may be specified with the
63e163f2
AB
25428@code{set history filename} command. By default, this option is
25429disabled. The command history will be recorded when @value{GDBN}
25430exits. If @code{set history filename} is set to the empty string then
25431history saving is disabled, even when @code{set history save} is
25432@code{on}.
104c1213 25433
8e04817f 25434@item set history save off
63e163f2
AB
25435Don't record the command history into the file specified by @code{set
25436history filename} when @value{GDBN} exits.
104c1213 25437
8e04817f 25438@cindex history size
9c16f35a 25439@kindex set history size
b58c513b 25440@cindex @env{GDBHISTSIZE}, environment variable
8e04817f 25441@item set history size @var{size}
f81d1120 25442@itemx set history size unlimited
8e04817f 25443Set the number of commands which @value{GDBN} keeps in its history list.
bc460514
PP
25444This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
25445to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
0eacb298
PP
25446are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
25447either a negative number or the empty string, then the number of commands
25448@value{GDBN} keeps in the history list is unlimited.
fc637f04 25449
63e163f2
AB
25450The @code{GDBHISTSIZE} environment variable is read after processing
25451any @value{GDBN} initialization files (@pxref{Startup}) and after
25452processing any commands passed using command line options (for
25453example, @code{-ex}).
25454
fc637f04
PP
25455@cindex remove duplicate history
25456@kindex set history remove-duplicates
25457@item set history remove-duplicates @var{count}
25458@itemx set history remove-duplicates unlimited
25459Control the removal of duplicate history entries in the command history list.
25460If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
25461history entries and remove the first entry that is a duplicate of the current
25462entry being added to the command history list. If @var{count} is
25463@code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
25464removal of duplicate history entries is disabled.
25465
25466Only history entries added during the current session are considered for
25467removal. This option is set to 0 by default.
25468
104c1213
JM
25469@end table
25470
8e04817f 25471History expansion assigns special meaning to the character @kbd{!}.
39037522
TT
25472@ifset SYSTEM_READLINE
25473@xref{Event Designators, , , history, GNU History Library},
25474@end ifset
25475@ifclear SYSTEM_READLINE
25476@xref{Event Designators},
25477@end ifclear
25478for more details.
8e04817f 25479
703663ab 25480@cindex history expansion, turn on/off
8e04817f
AC
25481Since @kbd{!} is also the logical not operator in C, history expansion
25482is off by default. If you decide to enable history expansion with the
25483@code{set history expansion on} command, you may sometimes need to
25484follow @kbd{!} (when it is used as logical not, in an expression) with
25485a space or a tab to prevent it from being expanded. The readline
25486history facilities do not attempt substitution on the strings
25487@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
25488
25489The commands to control history expansion are:
104c1213
JM
25490
25491@table @code
8e04817f
AC
25492@item set history expansion on
25493@itemx set history expansion
703663ab 25494@kindex set history expansion
8e04817f 25495Enable history expansion. History expansion is off by default.
104c1213 25496
8e04817f
AC
25497@item set history expansion off
25498Disable history expansion.
104c1213 25499
8e04817f
AC
25500@c @group
25501@kindex show history
25502@item show history
25503@itemx show history filename
25504@itemx show history save
25505@itemx show history size
25506@itemx show history expansion
25507These commands display the state of the @value{GDBN} history parameters.
25508@code{show history} by itself displays all four states.
25509@c @end group
25510@end table
25511
25512@table @code
9c16f35a
EZ
25513@kindex show commands
25514@cindex show last commands
25515@cindex display command history
8e04817f
AC
25516@item show commands
25517Display the last ten commands in the command history.
104c1213 25518
8e04817f
AC
25519@item show commands @var{n}
25520Print ten commands centered on command number @var{n}.
25521
25522@item show commands +
25523Print ten commands just after the commands last printed.
104c1213
JM
25524@end table
25525
8e04817f 25526@node Screen Size
79a6e687 25527@section Screen Size
8e04817f 25528@cindex size of screen
f179cf97
EZ
25529@cindex screen size
25530@cindex pagination
25531@cindex page size
8e04817f 25532@cindex pauses in output
104c1213 25533
8e04817f
AC
25534Certain commands to @value{GDBN} may produce large amounts of
25535information output to the screen. To help you read all of it,
25536@value{GDBN} pauses and asks you for input at the end of each page of
eb6af809
TT
25537output. Type @key{RET} when you want to see one more page of output,
25538@kbd{q} to discard the remaining output, or @kbd{c} to continue
25539without paging for the rest of the current command. Also, the screen
25540width setting determines when to wrap lines of output. Depending on
25541what is being printed, @value{GDBN} tries to break the line at a
25542readable place, rather than simply letting it overflow onto the
25543following line.
8e04817f
AC
25544
25545Normally @value{GDBN} knows the size of the screen from the terminal
25546driver software. For example, on Unix @value{GDBN} uses the termcap data base
25547together with the value of the @code{TERM} environment variable and the
25548@code{stty rows} and @code{stty cols} settings. If this is not correct,
25549you can override it with the @code{set height} and @code{set
25550width} commands:
25551
25552@table @code
25553@kindex set height
25554@kindex set width
25555@kindex show width
25556@kindex show height
25557@item set height @var{lpp}
f81d1120 25558@itemx set height unlimited
8e04817f
AC
25559@itemx show height
25560@itemx set width @var{cpl}
f81d1120 25561@itemx set width unlimited
8e04817f
AC
25562@itemx show width
25563These @code{set} commands specify a screen height of @var{lpp} lines and
25564a screen width of @var{cpl} characters. The associated @code{show}
25565commands display the current settings.
104c1213 25566
f81d1120
PA
25567If you specify a height of either @code{unlimited} or zero lines,
25568@value{GDBN} does not pause during output no matter how long the
25569output is. This is useful if output is to a file or to an editor
25570buffer.
104c1213 25571
f81d1120
PA
25572Likewise, you can specify @samp{set width unlimited} or @samp{set
25573width 0} to prevent @value{GDBN} from wrapping its output.
9c16f35a
EZ
25574
25575@item set pagination on
25576@itemx set pagination off
25577@kindex set pagination
25578Turn the output pagination on or off; the default is on. Turning
f81d1120 25579pagination off is the alternative to @code{set height unlimited}. Note that
7c953934
TT
25580running @value{GDBN} with the @option{--batch} option (@pxref{Mode
25581Options, -batch}) also automatically disables pagination.
9c16f35a
EZ
25582
25583@item show pagination
25584@kindex show pagination
25585Show the current pagination mode.
104c1213
JM
25586@end table
25587
140a4bc0
TT
25588@node Output Styling
25589@section Output Styling
25590@cindex styling
25591@cindex colors
25592
25593@kindex set style
25594@kindex show style
25595@value{GDBN} can style its output on a capable terminal. This is
7557a514
AH
25596enabled by default on most systems, but disabled by default when in
25597batch mode (@pxref{Mode Options}). Various style settings are available;
25598and styles can also be disabled entirely.
140a4bc0
TT
25599
25600@table @code
25601@item set style enabled @samp{on|off}
25602Enable or disable all styling. The default is host-dependent, with
25603most hosts defaulting to @samp{on}.
25604
25605@item show style enabled
25606Show the current state of styling.
d085f989
TT
25607
25608@item set style sources @samp{on|off}
25609Enable or disable source code styling. This affects whether source
25610code, such as the output of the @code{list} command, is styled. Note
25611that source styling only works if styling in general is enabled, and
25612if @value{GDBN} was linked with the GNU Source Highlight library. The
25613default is @samp{on}.
25614
25615@item show style sources
25616Show the current state of source code styling.
140a4bc0
TT
25617@end table
25618
25619Subcommands of @code{set style} control specific forms of styling.
25620These subcommands all follow the same pattern: each style-able object
25621can be styled with a foreground color, a background color, and an
25622intensity.
25623
25624For example, the style of file names can be controlled using the
25625@code{set style filename} group of commands:
25626
25627@table @code
25628@item set style filename background @var{color}
25629Set the background to @var{color}. Valid colors are @samp{none}
25630(meaning the terminal's default color), @samp{black}, @samp{red},
e3624a40 25631@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
140a4bc0
TT
25632and@samp{white}.
25633
25634@item set style filename foreground @var{color}
25635Set the foreground to @var{color}. Valid colors are @samp{none}
25636(meaning the terminal's default color), @samp{black}, @samp{red},
e3624a40 25637@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
140a4bc0
TT
25638and@samp{white}.
25639
25640@item set style filename intensity @var{value}
25641Set the intensity to @var{value}. Valid intensities are @samp{normal}
25642(the default), @samp{bold}, and @samp{dim}.
25643@end table
25644
e664d728
PW
25645The @code{show style} command and its subcommands are styling
25646a style name in their output using its own style.
25647So, use @command{show style} to see the complete list of styles,
25648their characteristics and the visual aspect of each style.
25649
140a4bc0
TT
25650The style-able objects are:
25651@table @code
25652@item filename
e3624a40
EZ
25653Control the styling of file names. By default, this style's
25654foreground color is green.
140a4bc0
TT
25655
25656@item function
25657Control the styling of function names. These are managed with the
e3624a40
EZ
25658@code{set style function} family of commands. By default, this
25659style's foreground color is yellow.
140a4bc0
TT
25660
25661@item variable
25662Control the styling of variable names. These are managed with the
e3624a40
EZ
25663@code{set style variable} family of commands. By default, this style's
25664foreground color is cyan.
140a4bc0
TT
25665
25666@item address
25667Control the styling of addresses. These are managed with the
e3624a40
EZ
25668@code{set style address} family of commands. By default, this style's
25669foreground color is blue.
e664d728
PW
25670
25671@item title
25672Control the styling of titles. These are managed with the
25673@code{set style title} family of commands. By default, this style's
25674intensity is bold. Commands are using the title style to improve
6b92c0d3 25675the readability of large output. For example, the commands
e664d728
PW
25676@command{apropos} and @command{help} are using the title style
25677for the command names.
25678
25679@item highlight
25680Control the styling of highlightings. These are managed with the
25681@code{set style highlight} family of commands. By default, this style's
25682foreground color is red. Commands are using the highlight style to draw
25683the user attention to some specific parts of their output. For example,
25684the command @command{apropos -v REGEXP} uses the highlight style to
25685mark the documentation parts matching @var{regexp}.
25686
a2a7af0c
TT
25687@item tui-border
25688Control the styling of the TUI border. Note that, unlike other
25689styling options, only the color of the border can be controlled via
25690@code{set style}. This was done for compatibility reasons, as TUI
25691controls to set the border's intensity predated the addition of
25692general styling to @value{GDBN}. @xref{TUI Configuration}.
25693
25694@item tui-active-border
25695Control the styling of the active TUI border; that is, the TUI window
25696that has the focus.
25697
140a4bc0
TT
25698@end table
25699
8e04817f
AC
25700@node Numbers
25701@section Numbers
25702@cindex number representation
25703@cindex entering numbers
104c1213 25704
8e04817f
AC
25705You can always enter numbers in octal, decimal, or hexadecimal in
25706@value{GDBN} by the usual conventions: octal numbers begin with
25707@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
25708begin with @samp{0x}. Numbers that neither begin with @samp{0} or
25709@samp{0x}, nor end with a @samp{.} are, by default, entered in base
2571010; likewise, the default display for numbers---when no particular
25711format is specified---is base 10. You can change the default base for
25712both input and output with the commands described below.
104c1213 25713
8e04817f
AC
25714@table @code
25715@kindex set input-radix
25716@item set input-radix @var{base}
25717Set the default base for numeric input. Supported choices
697aa1b7 25718for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 25719specified either unambiguously or using the current input radix; for
8e04817f 25720example, any of
104c1213 25721
8e04817f 25722@smallexample
9c16f35a
EZ
25723set input-radix 012
25724set input-radix 10.
25725set input-radix 0xa
8e04817f 25726@end smallexample
104c1213 25727
8e04817f 25728@noindent
9c16f35a 25729sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
25730leaves the input radix unchanged, no matter what it was, since
25731@samp{10}, being without any leading or trailing signs of its base, is
25732interpreted in the current radix. Thus, if the current radix is 16,
25733@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
25734change the radix.
104c1213 25735
8e04817f
AC
25736@kindex set output-radix
25737@item set output-radix @var{base}
25738Set the default base for numeric display. Supported choices
697aa1b7 25739for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 25740specified either unambiguously or using the current input radix.
104c1213 25741
8e04817f
AC
25742@kindex show input-radix
25743@item show input-radix
25744Display the current default base for numeric input.
104c1213 25745
8e04817f
AC
25746@kindex show output-radix
25747@item show output-radix
25748Display the current default base for numeric display.
9c16f35a
EZ
25749
25750@item set radix @r{[}@var{base}@r{]}
25751@itemx show radix
25752@kindex set radix
25753@kindex show radix
25754These commands set and show the default base for both input and output
25755of numbers. @code{set radix} sets the radix of input and output to
25756the same base; without an argument, it resets the radix back to its
25757default value of 10.
25758
8e04817f 25759@end table
104c1213 25760
1e698235 25761@node ABI
79a6e687 25762@section Configuring the Current ABI
1e698235
DJ
25763
25764@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
25765application automatically. However, sometimes you need to override its
25766conclusions. Use these commands to manage @value{GDBN}'s view of the
25767current ABI.
25768
98b45e30
DJ
25769@cindex OS ABI
25770@kindex set osabi
b4e9345d 25771@kindex show osabi
430ed3f0 25772@cindex Newlib OS ABI and its influence on the longjmp handling
98b45e30
DJ
25773
25774One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 25775system targets, either via remote debugging or native emulation.
98b45e30
DJ
25776@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
25777but you can override its conclusion using the @code{set osabi} command.
25778One example where this is useful is in debugging of binaries which use
25779an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
25780not have the same identifying marks that the standard C library for your
25781platform provides.
25782
430ed3f0
MS
25783When @value{GDBN} is debugging the AArch64 architecture, it provides a
25784``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
25785@code{longjmp} when debugging binaries that use the @sc{newlib} C library.
25786The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
25787
98b45e30
DJ
25788@table @code
25789@item show osabi
25790Show the OS ABI currently in use.
25791
25792@item set osabi
25793With no argument, show the list of registered available OS ABI's.
25794
25795@item set osabi @var{abi}
25796Set the current OS ABI to @var{abi}.
25797@end table
25798
1e698235 25799@cindex float promotion
1e698235
DJ
25800
25801Generally, the way that an argument of type @code{float} is passed to a
25802function depends on whether the function is prototyped. For a prototyped
25803(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
25804according to the architecture's convention for @code{float}. For unprototyped
25805(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
25806@code{double} and then passed.
25807
25808Unfortunately, some forms of debug information do not reliably indicate whether
25809a function is prototyped. If @value{GDBN} calls a function that is not marked
25810as prototyped, it consults @kbd{set coerce-float-to-double}.
25811
25812@table @code
a8f24a35 25813@kindex set coerce-float-to-double
1e698235
DJ
25814@item set coerce-float-to-double
25815@itemx set coerce-float-to-double on
25816Arguments of type @code{float} will be promoted to @code{double} when passed
25817to an unprototyped function. This is the default setting.
25818
25819@item set coerce-float-to-double off
25820Arguments of type @code{float} will be passed directly to unprototyped
25821functions.
9c16f35a
EZ
25822
25823@kindex show coerce-float-to-double
25824@item show coerce-float-to-double
25825Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
25826@end table
25827
f1212245
DJ
25828@kindex set cp-abi
25829@kindex show cp-abi
25830@value{GDBN} needs to know the ABI used for your program's C@t{++}
25831objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
25832used to build your application. @value{GDBN} only fully supports
25833programs with a single C@t{++} ABI; if your program contains code using
25834multiple C@t{++} ABI's or if @value{GDBN} can not identify your
25835program's ABI correctly, you can tell @value{GDBN} which ABI to use.
25836Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
25837before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
25838``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
25839use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
25840``auto''.
25841
25842@table @code
25843@item show cp-abi
25844Show the C@t{++} ABI currently in use.
25845
25846@item set cp-abi
25847With no argument, show the list of supported C@t{++} ABI's.
25848
25849@item set cp-abi @var{abi}
25850@itemx set cp-abi auto
25851Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
25852@end table
25853
bf88dd68
JK
25854@node Auto-loading
25855@section Automatically loading associated files
25856@cindex auto-loading
25857
25858@value{GDBN} sometimes reads files with commands and settings automatically,
25859without being explicitly told so by the user. We call this feature
25860@dfn{auto-loading}. While auto-loading is useful for automatically adapting
25861@value{GDBN} to the needs of your project, it can sometimes produce unexpected
25862results or introduce security risks (e.g., if the file comes from untrusted
25863sources).
25864
71b8c845
DE
25865@menu
25866* Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
25867* libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
25868
25869* Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
25870* Auto-loading verbose mode:: @samp{set/show debug auto-load}
25871@end menu
25872
25873There are various kinds of files @value{GDBN} can automatically load.
25874In addition to these files, @value{GDBN} supports auto-loading code written
25875in various extension languages. @xref{Auto-loading extensions}.
25876
c1668e4e
JK
25877Note that loading of these associated files (including the local @file{.gdbinit}
25878file) requires accordingly configured @code{auto-load safe-path}
25879(@pxref{Auto-loading safe path}).
25880
bf88dd68
JK
25881For these reasons, @value{GDBN} includes commands and options to let you
25882control when to auto-load files and which files should be auto-loaded.
25883
25884@table @code
25885@anchor{set auto-load off}
25886@kindex set auto-load off
25887@item set auto-load off
25888Globally disable loading of all auto-loaded files.
25889You may want to use this command with the @samp{-iex} option
25890(@pxref{Option -init-eval-command}) such as:
25891@smallexample
25892$ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
25893@end smallexample
25894
25895Be aware that system init file (@pxref{System-wide configuration})
25896and init files from your home directory (@pxref{Home Directory Init File})
25897still get read (as they come from generally trusted directories).
25898To prevent @value{GDBN} from auto-loading even those init files, use the
25899@option{-nx} option (@pxref{Mode Options}), in addition to
25900@code{set auto-load no}.
25901
25902@anchor{show auto-load}
25903@kindex show auto-load
25904@item show auto-load
25905Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
25906or disabled.
25907
25908@smallexample
25909(gdb) show auto-load
25910gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
25911libthread-db: Auto-loading of inferior specific libthread_db is on.
1ccacbcd
JK
25912local-gdbinit: Auto-loading of .gdbinit script from current directory
25913 is on.
bf88dd68 25914python-scripts: Auto-loading of Python scripts is on.
bccbefd2 25915safe-path: List of directories from which it is safe to auto-load files
1564a261 25916 is $debugdir:$datadir/auto-load.
7349ff92 25917scripts-directory: List of directories from which to load auto-loaded scripts
1564a261 25918 is $debugdir:$datadir/auto-load.
bf88dd68
JK
25919@end smallexample
25920
25921@anchor{info auto-load}
25922@kindex info auto-load
25923@item info auto-load
25924Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
25925not.
25926
25927@smallexample
25928(gdb) info auto-load
25929gdb-scripts:
25930Loaded Script
25931Yes /home/user/gdb/gdb-gdb.gdb
25932libthread-db: No auto-loaded libthread-db.
1ccacbcd
JK
25933local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
25934 loaded.
bf88dd68
JK
25935python-scripts:
25936Loaded Script
25937Yes /home/user/gdb/gdb-gdb.py
25938@end smallexample
25939@end table
25940
bf88dd68
JK
25941These are @value{GDBN} control commands for the auto-loading:
25942
25943@multitable @columnfractions .5 .5
25944@item @xref{set auto-load off}.
25945@tab Disable auto-loading globally.
25946@item @xref{show auto-load}.
25947@tab Show setting of all kinds of files.
25948@item @xref{info auto-load}.
25949@tab Show state of all kinds of files.
25950@item @xref{set auto-load gdb-scripts}.
25951@tab Control for @value{GDBN} command scripts.
25952@item @xref{show auto-load gdb-scripts}.
25953@tab Show setting of @value{GDBN} command scripts.
25954@item @xref{info auto-load gdb-scripts}.
25955@tab Show state of @value{GDBN} command scripts.
25956@item @xref{set auto-load python-scripts}.
25957@tab Control for @value{GDBN} Python scripts.
25958@item @xref{show auto-load python-scripts}.
25959@tab Show setting of @value{GDBN} Python scripts.
25960@item @xref{info auto-load python-scripts}.
25961@tab Show state of @value{GDBN} Python scripts.
ed3ef339
DE
25962@item @xref{set auto-load guile-scripts}.
25963@tab Control for @value{GDBN} Guile scripts.
25964@item @xref{show auto-load guile-scripts}.
25965@tab Show setting of @value{GDBN} Guile scripts.
25966@item @xref{info auto-load guile-scripts}.
25967@tab Show state of @value{GDBN} Guile scripts.
7349ff92
JK
25968@item @xref{set auto-load scripts-directory}.
25969@tab Control for @value{GDBN} auto-loaded scripts location.
25970@item @xref{show auto-load scripts-directory}.
25971@tab Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
25972@item @xref{add-auto-load-scripts-directory}.
25973@tab Add directory for auto-loaded scripts location list.
bf88dd68
JK
25974@item @xref{set auto-load local-gdbinit}.
25975@tab Control for init file in the current directory.
25976@item @xref{show auto-load local-gdbinit}.
25977@tab Show setting of init file in the current directory.
25978@item @xref{info auto-load local-gdbinit}.
25979@tab Show state of init file in the current directory.
25980@item @xref{set auto-load libthread-db}.
25981@tab Control for thread debugging library.
25982@item @xref{show auto-load libthread-db}.
25983@tab Show setting of thread debugging library.
25984@item @xref{info auto-load libthread-db}.
25985@tab Show state of thread debugging library.
bccbefd2
JK
25986@item @xref{set auto-load safe-path}.
25987@tab Control directories trusted for automatic loading.
25988@item @xref{show auto-load safe-path}.
25989@tab Show directories trusted for automatic loading.
25990@item @xref{add-auto-load-safe-path}.
25991@tab Add directory trusted for automatic loading.
bf88dd68
JK
25992@end multitable
25993
bf88dd68
JK
25994@node Init File in the Current Directory
25995@subsection Automatically loading init file in the current directory
25996@cindex auto-loading init file in the current directory
25997
25998By default, @value{GDBN} reads and executes the canned sequences of commands
25999from init file (if any) in the current working directory,
26000see @ref{Init File in the Current Directory during Startup}.
26001
c1668e4e
JK
26002Note that loading of this local @file{.gdbinit} file also requires accordingly
26003configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26004
bf88dd68
JK
26005@table @code
26006@anchor{set auto-load local-gdbinit}
26007@kindex set auto-load local-gdbinit
26008@item set auto-load local-gdbinit [on|off]
26009Enable or disable the auto-loading of canned sequences of commands
26010(@pxref{Sequences}) found in init file in the current directory.
26011
26012@anchor{show auto-load local-gdbinit}
26013@kindex show auto-load local-gdbinit
26014@item show auto-load local-gdbinit
26015Show whether auto-loading of canned sequences of commands from init file in the
26016current directory is enabled or disabled.
26017
26018@anchor{info auto-load local-gdbinit}
26019@kindex info auto-load local-gdbinit
26020@item info auto-load local-gdbinit
26021Print whether canned sequences of commands from init file in the
26022current directory have been auto-loaded.
26023@end table
26024
26025@node libthread_db.so.1 file
26026@subsection Automatically loading thread debugging library
26027@cindex auto-loading libthread_db.so.1
26028
26029This feature is currently present only on @sc{gnu}/Linux native hosts.
26030
26031@value{GDBN} reads in some cases thread debugging library from places specific
26032to the inferior (@pxref{set libthread-db-search-path}).
26033
26034The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
26035without checking this @samp{set auto-load libthread-db} switch as system
26036libraries have to be trusted in general. In all other cases of
26037@samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
26038auto-load libthread-db} is enabled before trying to open such thread debugging
26039library.
26040
c1668e4e
JK
26041Note that loading of this debugging library also requires accordingly configured
26042@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26043
bf88dd68
JK
26044@table @code
26045@anchor{set auto-load libthread-db}
26046@kindex set auto-load libthread-db
26047@item set auto-load libthread-db [on|off]
26048Enable or disable the auto-loading of inferior specific thread debugging library.
26049
26050@anchor{show auto-load libthread-db}
26051@kindex show auto-load libthread-db
26052@item show auto-load libthread-db
26053Show whether auto-loading of inferior specific thread debugging library is
26054enabled or disabled.
26055
26056@anchor{info auto-load libthread-db}
26057@kindex info auto-load libthread-db
26058@item info auto-load libthread-db
26059Print the list of all loaded inferior specific thread debugging libraries and
26060for each such library print list of inferior @var{pid}s using it.
26061@end table
26062
bccbefd2
JK
26063@node Auto-loading safe path
26064@subsection Security restriction for auto-loading
26065@cindex auto-loading safe-path
26066
26067As the files of inferior can come from untrusted source (such as submitted by
26068an application user) @value{GDBN} does not always load any files automatically.
26069@value{GDBN} provides the @samp{set auto-load safe-path} setting to list
26070directories trusted for loading files not explicitly requested by user.
202cbf1c 26071Each directory can also be a shell wildcard pattern.
bccbefd2
JK
26072
26073If the path is not set properly you will see a warning and the file will not
26074get loaded:
26075
26076@smallexample
26077$ ./gdb -q ./gdb
0bab6cf1 26078Reading symbols from /home/user/gdb/gdb...
bccbefd2 26079warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
1564a261
JK
26080 declined by your `auto-load safe-path' set
26081 to "$debugdir:$datadir/auto-load".
bccbefd2 26082warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
1564a261
JK
26083 declined by your `auto-load safe-path' set
26084 to "$debugdir:$datadir/auto-load".
bccbefd2
JK
26085@end smallexample
26086
2c91021c
JK
26087@noindent
26088To instruct @value{GDBN} to go ahead and use the init files anyway,
26089invoke @value{GDBN} like this:
26090
26091@smallexample
26092$ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
26093@end smallexample
26094
bccbefd2
JK
26095The list of trusted directories is controlled by the following commands:
26096
26097@table @code
26098@anchor{set auto-load safe-path}
26099@kindex set auto-load safe-path
af2c1515 26100@item set auto-load safe-path @r{[}@var{directories}@r{]}
bccbefd2
JK
26101Set the list of directories (and their subdirectories) trusted for automatic
26102loading and execution of scripts. You can also enter a specific trusted file.
202cbf1c
JK
26103Each directory can also be a shell wildcard pattern; wildcards do not match
26104directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
26105(@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
af2c1515
JK
26106If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
26107its default value as specified during @value{GDBN} compilation.
26108
d9242c17 26109The list of directories uses path separator (@samp{:} on GNU and Unix
bccbefd2
JK
26110systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26111to the @env{PATH} environment variable.
26112
26113@anchor{show auto-load safe-path}
26114@kindex show auto-load safe-path
26115@item show auto-load safe-path
26116Show the list of directories trusted for automatic loading and execution of
26117scripts.
26118
26119@anchor{add-auto-load-safe-path}
26120@kindex add-auto-load-safe-path
26121@item add-auto-load-safe-path
413b59ae
JK
26122Add an entry (or list of entries) to the list of directories trusted for
26123automatic loading and execution of scripts. Multiple entries may be delimited
26124by the host platform path separator in use.
bccbefd2
JK
26125@end table
26126
7349ff92 26127This variable defaults to what @code{--with-auto-load-dir} has been configured
1564a261
JK
26128to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
26129substitution applies the same as for @ref{set auto-load scripts-directory}.
26130The default @code{set auto-load safe-path} value can be also overriden by
26131@value{GDBN} configuration option @option{--with-auto-load-safe-path}.
6dea1fbd 26132
6dea1fbd
JK
26133Setting this variable to @file{/} disables this security protection,
26134corresponding @value{GDBN} configuration option is
26135@option{--without-auto-load-safe-path}.
bccbefd2
JK
26136This variable is supposed to be set to the system directories writable by the
26137system superuser only. Users can add their source directories in init files in
26138their home directories (@pxref{Home Directory Init File}). See also deprecated
26139init file in the current directory
26140(@pxref{Init File in the Current Directory during Startup}).
26141
26142To force @value{GDBN} to load the files it declined to load in the previous
26143example, you could use one of the following ways:
26144
0511cc75
JK
26145@table @asis
26146@item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
bccbefd2
JK
26147Specify this trusted directory (or a file) as additional component of the list.
26148You have to specify also any existing directories displayed by
26149by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
26150
174bb630 26151@item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
bccbefd2
JK
26152Specify this directory as in the previous case but just for a single
26153@value{GDBN} session.
26154
af2c1515 26155@item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
bccbefd2
JK
26156Disable auto-loading safety for a single @value{GDBN} session.
26157This assumes all the files you debug during this @value{GDBN} session will come
26158from trusted sources.
26159
26160@item @kbd{./configure --without-auto-load-safe-path}
26161During compilation of @value{GDBN} you may disable any auto-loading safety.
26162This assumes all the files you will ever debug with this @value{GDBN} come from
26163trusted sources.
0511cc75 26164@end table
bccbefd2
JK
26165
26166On the other hand you can also explicitly forbid automatic files loading which
26167also suppresses any such warning messages:
26168
0511cc75 26169@table @asis
174bb630 26170@item @kbd{gdb -iex "set auto-load no" @dots{}}
bccbefd2
JK
26171You can use @value{GDBN} command-line option for a single @value{GDBN} session.
26172
0511cc75 26173@item @file{~/.gdbinit}: @samp{set auto-load no}
bccbefd2
JK
26174Disable auto-loading globally for the user
26175(@pxref{Home Directory Init File}). While it is improbable, you could also
26176use system init file instead (@pxref{System-wide configuration}).
0511cc75 26177@end table
bccbefd2
JK
26178
26179This setting applies to the file names as entered by user. If no entry matches
26180@value{GDBN} tries as a last resort to also resolve all the file names into
26181their canonical form (typically resolving symbolic links) and compare the
26182entries again. @value{GDBN} already canonicalizes most of the filenames on its
26183own before starting the comparison so a canonical form of directories is
26184recommended to be entered.
26185
4dc84fd1
JK
26186@node Auto-loading verbose mode
26187@subsection Displaying files tried for auto-load
26188@cindex auto-loading verbose mode
26189
26190For better visibility of all the file locations where you can place scripts to
26191be auto-loaded with inferior --- or to protect yourself against accidental
26192execution of untrusted scripts --- @value{GDBN} provides a feature for printing
26193all the files attempted to be loaded. Both existing and non-existing files may
26194be printed.
26195
26196For example the list of directories from which it is safe to auto-load files
26197(@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
26198may not be too obvious while setting it up.
26199
26200@smallexample
0070f25a 26201(gdb) set debug auto-load on
4dc84fd1
JK
26202(gdb) file ~/src/t/true
26203auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
26204 for objfile "/tmp/true".
26205auto-load: Updating directories of "/usr:/opt".
26206auto-load: Using directory "/usr".
26207auto-load: Using directory "/opt".
26208warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
26209 by your `auto-load safe-path' set to "/usr:/opt".
26210@end smallexample
26211
26212@table @code
26213@anchor{set debug auto-load}
26214@kindex set debug auto-load
26215@item set debug auto-load [on|off]
26216Set whether to print the filenames attempted to be auto-loaded.
26217
26218@anchor{show debug auto-load}
26219@kindex show debug auto-load
26220@item show debug auto-load
26221Show whether printing of the filenames attempted to be auto-loaded is turned
26222on or off.
26223@end table
26224
8e04817f 26225@node Messages/Warnings
79a6e687 26226@section Optional Warnings and Messages
104c1213 26227
9c16f35a
EZ
26228@cindex verbose operation
26229@cindex optional warnings
8e04817f
AC
26230By default, @value{GDBN} is silent about its inner workings. If you are
26231running on a slow machine, you may want to use the @code{set verbose}
26232command. This makes @value{GDBN} tell you when it does a lengthy
26233internal operation, so you will not think it has crashed.
104c1213 26234
8e04817f
AC
26235Currently, the messages controlled by @code{set verbose} are those
26236which announce that the symbol table for a source file is being read;
79a6e687 26237see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 26238
8e04817f
AC
26239@table @code
26240@kindex set verbose
26241@item set verbose on
26242Enables @value{GDBN} output of certain informational messages.
104c1213 26243
8e04817f
AC
26244@item set verbose off
26245Disables @value{GDBN} output of certain informational messages.
104c1213 26246
8e04817f
AC
26247@kindex show verbose
26248@item show verbose
26249Displays whether @code{set verbose} is on or off.
26250@end table
104c1213 26251
8e04817f
AC
26252By default, if @value{GDBN} encounters bugs in the symbol table of an
26253object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
26254find this information useful (@pxref{Symbol Errors, ,Errors Reading
26255Symbol Files}).
104c1213 26256
8e04817f 26257@table @code
104c1213 26258
8e04817f
AC
26259@kindex set complaints
26260@item set complaints @var{limit}
26261Permits @value{GDBN} to output @var{limit} complaints about each type of
26262unusual symbols before becoming silent about the problem. Set
26263@var{limit} to zero to suppress all complaints; set it to a large number
26264to prevent complaints from being suppressed.
104c1213 26265
8e04817f
AC
26266@kindex show complaints
26267@item show complaints
26268Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 26269
8e04817f 26270@end table
104c1213 26271
d837706a 26272@anchor{confirmation requests}
8e04817f
AC
26273By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
26274lot of stupid questions to confirm certain commands. For example, if
26275you try to run a program which is already running:
104c1213 26276
474c8240 26277@smallexample
8e04817f
AC
26278(@value{GDBP}) run
26279The program being debugged has been started already.
26280Start it from the beginning? (y or n)
474c8240 26281@end smallexample
104c1213 26282
8e04817f
AC
26283If you are willing to unflinchingly face the consequences of your own
26284commands, you can disable this ``feature'':
104c1213 26285
8e04817f 26286@table @code
104c1213 26287
8e04817f
AC
26288@kindex set confirm
26289@cindex flinching
26290@cindex confirmation
26291@cindex stupid questions
26292@item set confirm off
7c953934
TT
26293Disables confirmation requests. Note that running @value{GDBN} with
26294the @option{--batch} option (@pxref{Mode Options, -batch}) also
26295automatically disables confirmation requests.
104c1213 26296
8e04817f
AC
26297@item set confirm on
26298Enables confirmation requests (the default).
104c1213 26299
8e04817f
AC
26300@kindex show confirm
26301@item show confirm
26302Displays state of confirmation requests.
26303
26304@end table
104c1213 26305
16026cd7
AS
26306@cindex command tracing
26307If you need to debug user-defined commands or sourced files you may find it
26308useful to enable @dfn{command tracing}. In this mode each command will be
26309printed as it is executed, prefixed with one or more @samp{+} symbols, the
26310quantity denoting the call depth of each command.
26311
26312@table @code
26313@kindex set trace-commands
26314@cindex command scripts, debugging
26315@item set trace-commands on
26316Enable command tracing.
26317@item set trace-commands off
26318Disable command tracing.
26319@item show trace-commands
26320Display the current state of command tracing.
26321@end table
26322
8e04817f 26323@node Debugging Output
79a6e687 26324@section Optional Messages about Internal Happenings
4644b6e3
EZ
26325@cindex optional debugging messages
26326
da316a69
EZ
26327@value{GDBN} has commands that enable optional debugging messages from
26328various @value{GDBN} subsystems; normally these commands are of
26329interest to @value{GDBN} maintainers, or when reporting a bug. This
26330section documents those commands.
26331
104c1213 26332@table @code
a8f24a35
EZ
26333@kindex set exec-done-display
26334@item set exec-done-display
26335Turns on or off the notification of asynchronous commands'
26336completion. When on, @value{GDBN} will print a message when an
26337asynchronous command finishes its execution. The default is off.
26338@kindex show exec-done-display
26339@item show exec-done-display
26340Displays the current setting of asynchronous command completion
26341notification.
4644b6e3 26342@kindex set debug
be9a8770
PA
26343@cindex ARM AArch64
26344@item set debug aarch64
26345Turns on or off display of debugging messages related to ARM AArch64.
26346The default is off.
26347@kindex show debug
26348@item show debug aarch64
26349Displays the current state of displaying debugging messages related to
26350ARM AArch64.
4644b6e3 26351@cindex gdbarch debugging info
a8f24a35 26352@cindex architecture debugging info
8e04817f 26353@item set debug arch
a8f24a35 26354Turns on or off display of gdbarch debugging info. The default is off
8e04817f
AC
26355@item show debug arch
26356Displays the current state of displaying gdbarch debugging info.
9a005eb9
JB
26357@item set debug aix-solib
26358@cindex AIX shared library debugging
26359Control display of debugging messages from the AIX shared library
26360support module. The default is off.
26361@item show debug aix-thread
26362Show the current state of displaying AIX shared library debugging messages.
721c2651
EZ
26363@item set debug aix-thread
26364@cindex AIX threads
26365Display debugging messages about inner workings of the AIX thread
26366module.
26367@item show debug aix-thread
26368Show the current state of AIX thread debugging info display.
900e11f9
JK
26369@item set debug check-physname
26370@cindex physname
26371Check the results of the ``physname'' computation. When reading DWARF
26372debugging information for C@t{++}, @value{GDBN} attempts to compute
26373each entity's name. @value{GDBN} can do this computation in two
26374different ways, depending on exactly what information is present.
26375When enabled, this setting causes @value{GDBN} to compute the names
26376both ways and display any discrepancies.
26377@item show debug check-physname
26378Show the current state of ``physname'' checking.
be9a8770
PA
26379@item set debug coff-pe-read
26380@cindex COFF/PE exported symbols
26381Control display of debugging messages related to reading of COFF/PE
26382exported symbols. The default is off.
26383@item show debug coff-pe-read
26384Displays the current state of displaying debugging messages related to
26385reading of COFF/PE exported symbols.
b4f54984
DE
26386@item set debug dwarf-die
26387@cindex DWARF DIEs
26388Dump DWARF DIEs after they are read in.
d97bc12b
DE
26389The value is the number of nesting levels to print.
26390A value of zero turns off the display.
b4f54984
DE
26391@item show debug dwarf-die
26392Show the current state of DWARF DIE debugging.
27e0867f
DE
26393@item set debug dwarf-line
26394@cindex DWARF Line Tables
26395Turns on or off display of debugging messages related to reading
26396DWARF line tables. The default is 0 (off).
26397A value of 1 provides basic information.
26398A value greater than 1 provides more verbose information.
26399@item show debug dwarf-line
26400Show the current state of DWARF line table debugging.
b4f54984
DE
26401@item set debug dwarf-read
26402@cindex DWARF Reading
45cfd468 26403Turns on or off display of debugging messages related to reading
73be47f5
DE
26404DWARF debug info. The default is 0 (off).
26405A value of 1 provides basic information.
26406A value greater than 1 provides more verbose information.
b4f54984
DE
26407@item show debug dwarf-read
26408Show the current state of DWARF reader debugging.
237fc4c9
PA
26409@item set debug displaced
26410@cindex displaced stepping debugging info
26411Turns on or off display of @value{GDBN} debugging info for the
26412displaced stepping support. The default is off.
26413@item show debug displaced
26414Displays the current state of displaying @value{GDBN} debugging info
26415related to displaced stepping.
8e04817f 26416@item set debug event
4644b6e3 26417@cindex event debugging info
a8f24a35 26418Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 26419default is off.
8e04817f
AC
26420@item show debug event
26421Displays the current state of displaying @value{GDBN} event debugging
26422info.
8e04817f 26423@item set debug expression
4644b6e3 26424@cindex expression debugging info
721c2651
EZ
26425Turns on or off display of debugging info about @value{GDBN}
26426expression parsing. The default is off.
8e04817f 26427@item show debug expression
721c2651
EZ
26428Displays the current state of displaying debugging info about
26429@value{GDBN} expression parsing.
6e9567fe
JB
26430@item set debug fbsd-lwp
26431@cindex FreeBSD LWP debug messages
26432Turns on or off debugging messages from the FreeBSD LWP debug support.
26433@item show debug fbsd-lwp
26434Show the current state of FreeBSD LWP debugging messages.
386a8676
JB
26435@item set debug fbsd-nat
26436@cindex FreeBSD native target debug messages
26437Turns on or off debugging messages from the FreeBSD native target.
26438@item show debug fbsd-nat
26439Show the current state of FreeBSD native target debugging messages.
7453dc06 26440@item set debug frame
4644b6e3 26441@cindex frame debugging info
7453dc06
AC
26442Turns on or off display of @value{GDBN} frame debugging info. The
26443default is off.
7453dc06
AC
26444@item show debug frame
26445Displays the current state of displaying @value{GDBN} frame debugging
26446info.
cbe54154
PA
26447@item set debug gnu-nat
26448@cindex @sc{gnu}/Hurd debug messages
67ebd9cb 26449Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
cbe54154
PA
26450@item show debug gnu-nat
26451Show the current state of @sc{gnu}/Hurd debugging messages.
30e91e0b
RC
26452@item set debug infrun
26453@cindex inferior debugging info
26454Turns on or off display of @value{GDBN} debugging info for running the inferior.
26455The default is off. @file{infrun.c} contains GDB's runtime state machine used
26456for implementing operations such as single-stepping the inferior.
26457@item show debug infrun
26458Displays the current state of @value{GDBN} inferior debugging.
a255712f
PP
26459@item set debug jit
26460@cindex just-in-time compilation, debugging messages
67ebd9cb 26461Turn on or off debugging messages from JIT debug support.
a255712f
PP
26462@item show debug jit
26463Displays the current state of @value{GDBN} JIT debugging.
da316a69
EZ
26464@item set debug lin-lwp
26465@cindex @sc{gnu}/Linux LWP debug messages
26466@cindex Linux lightweight processes
67ebd9cb 26467Turn on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
26468@item show debug lin-lwp
26469Show the current state of Linux LWP debugging messages.
7a6a1731
GB
26470@item set debug linux-namespaces
26471@cindex @sc{gnu}/Linux namespaces debug messages
67ebd9cb 26472Turn on or off debugging messages from the Linux namespaces debug support.
7a6a1731
GB
26473@item show debug linux-namespaces
26474Show the current state of Linux namespaces debugging messages.
be9a8770
PA
26475@item set debug mach-o
26476@cindex Mach-O symbols processing
26477Control display of debugging messages related to Mach-O symbols
26478processing. The default is off.
26479@item show debug mach-o
26480Displays the current state of displaying debugging messages related to
26481reading of COFF/PE exported symbols.
c9b6281a
YQ
26482@item set debug notification
26483@cindex remote async notification debugging info
67ebd9cb 26484Turn on or off debugging messages about remote async notification.
c9b6281a
YQ
26485The default is off.
26486@item show debug notification
26487Displays the current state of remote async notification debugging messages.
2b4855ab 26488@item set debug observer
4644b6e3 26489@cindex observer debugging info
2b4855ab
AC
26490Turns on or off display of @value{GDBN} observer debugging. This
26491includes info such as the notification of observable events.
2b4855ab
AC
26492@item show debug observer
26493Displays the current state of observer debugging.
8e04817f 26494@item set debug overload
4644b6e3 26495@cindex C@t{++} overload debugging info
8e04817f 26496Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 26497info. This includes info such as ranking of functions, etc. The default
8e04817f 26498is off.
8e04817f
AC
26499@item show debug overload
26500Displays the current state of displaying @value{GDBN} C@t{++} overload
26501debugging info.
92981e24
TT
26502@cindex expression parser, debugging info
26503@cindex debug expression parser
26504@item set debug parser
26505Turns on or off the display of expression parser debugging output.
26506Internally, this sets the @code{yydebug} variable in the expression
26507parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
26508details. The default is off.
26509@item show debug parser
26510Show the current state of expression parser debugging.
8e04817f
AC
26511@cindex packets, reporting on stdout
26512@cindex serial connections, debugging
605a56cb
DJ
26513@cindex debug remote protocol
26514@cindex remote protocol debugging
26515@cindex display remote packets
8e04817f
AC
26516@item set debug remote
26517Turns on or off display of reports on all packets sent back and forth across
26518the serial line to the remote machine. The info is printed on the
26519@value{GDBN} standard output stream. The default is off.
8e04817f
AC
26520@item show debug remote
26521Displays the state of display of remote packets.
c4dcb155 26522
6cc8564b
LM
26523@item set debug remote-packet-max-chars
26524Sets the maximum number of characters to display for each remote packet when
26525@code{set debug remote} is on. This is useful to prevent @value{GDBN} from
26526displaying lengthy remote packets and polluting the console.
26527
26528The default value is @code{512}, which means @value{GDBN} will truncate each
26529remote packet after 512 bytes.
26530
26531Setting this option to @code{unlimited} will disable truncation and will output
26532the full length of the remote packets.
26533@item show debug remote-packet-max-chars
26534Displays the number of bytes to output for remote packet debugging.
26535
c4dcb155
SM
26536@item set debug separate-debug-file
26537Turns on or off display of debug output about separate debug file search.
26538@item show debug separate-debug-file
26539Displays the state of separate debug file search debug output.
26540
8e04817f
AC
26541@item set debug serial
26542Turns on or off display of @value{GDBN} serial debugging info. The
26543default is off.
8e04817f
AC
26544@item show debug serial
26545Displays the current state of displaying @value{GDBN} serial debugging
26546info.
c45da7e6
EZ
26547@item set debug solib-frv
26548@cindex FR-V shared-library debugging
67ebd9cb 26549Turn on or off debugging messages for FR-V shared-library code.
c45da7e6
EZ
26550@item show debug solib-frv
26551Display the current state of FR-V shared-library code debugging
26552messages.
cc485e62
DE
26553@item set debug symbol-lookup
26554@cindex symbol lookup
26555Turns on or off display of debugging messages related to symbol lookup.
26556The default is 0 (off).
26557A value of 1 provides basic information.
26558A value greater than 1 provides more verbose information.
26559@item show debug symbol-lookup
26560Show the current state of symbol lookup debugging messages.
8fb8eb5c
DE
26561@item set debug symfile
26562@cindex symbol file functions
26563Turns on or off display of debugging messages related to symbol file functions.
26564The default is off. @xref{Files}.
26565@item show debug symfile
26566Show the current state of symbol file debugging messages.
45cfd468
DE
26567@item set debug symtab-create
26568@cindex symbol table creation
26569Turns on or off display of debugging messages related to symbol table creation.
db0fec5c
DE
26570The default is 0 (off).
26571A value of 1 provides basic information.
26572A value greater than 1 provides more verbose information.
45cfd468
DE
26573@item show debug symtab-create
26574Show the current state of symbol table creation debugging.
8e04817f 26575@item set debug target
4644b6e3 26576@cindex target debugging info
8e04817f
AC
26577Turns on or off display of @value{GDBN} target debugging info. This info
26578includes what is going on at the target level of GDB, as it happens. The
701b08bb 26579default is 0. Set it to 1 to track events, and to 2 to also track the
3cecbbbe 26580value of large memory transfers.
8e04817f
AC
26581@item show debug target
26582Displays the current state of displaying @value{GDBN} target debugging
26583info.
75feb17d 26584@item set debug timestamp
6b92c0d3 26585@cindex timestamping debugging info
75feb17d
DJ
26586Turns on or off display of timestamps with @value{GDBN} debugging info.
26587When enabled, seconds and microseconds are displayed before each debugging
26588message.
26589@item show debug timestamp
26590Displays the current state of displaying timestamps with @value{GDBN}
26591debugging info.
f989a1c8 26592@item set debug varobj
4644b6e3 26593@cindex variable object debugging info
8e04817f
AC
26594Turns on or off display of @value{GDBN} variable object debugging
26595info. The default is off.
f989a1c8 26596@item show debug varobj
8e04817f
AC
26597Displays the current state of displaying @value{GDBN} variable object
26598debugging info.
e776119f
DJ
26599@item set debug xml
26600@cindex XML parser debugging
67ebd9cb 26601Turn on or off debugging messages for built-in XML parsers.
e776119f
DJ
26602@item show debug xml
26603Displays the current state of XML debugging messages.
8e04817f 26604@end table
104c1213 26605
14fb1bac
JB
26606@node Other Misc Settings
26607@section Other Miscellaneous Settings
26608@cindex miscellaneous settings
26609
26610@table @code
26611@kindex set interactive-mode
26612@item set interactive-mode
7bfc9434
JB
26613If @code{on}, forces @value{GDBN} to assume that GDB was started
26614in a terminal. In practice, this means that @value{GDBN} should wait
26615for the user to answer queries generated by commands entered at
26616the command prompt. If @code{off}, forces @value{GDBN} to operate
26617in the opposite mode, and it uses the default answers to all queries.
26618If @code{auto} (the default), @value{GDBN} tries to determine whether
26619its standard input is a terminal, and works in interactive-mode if it
26620is, non-interactively otherwise.
14fb1bac
JB
26621
26622In the vast majority of cases, the debugger should be able to guess
26623correctly which mode should be used. But this setting can be useful
26624in certain specific cases, such as running a MinGW @value{GDBN}
26625inside a cygwin window.
26626
26627@kindex show interactive-mode
26628@item show interactive-mode
26629Displays whether the debugger is operating in interactive mode or not.
26630@end table
26631
d57a3c85
TJB
26632@node Extending GDB
26633@chapter Extending @value{GDBN}
26634@cindex extending GDB
26635
71b8c845
DE
26636@value{GDBN} provides several mechanisms for extension.
26637@value{GDBN} also provides the ability to automatically load
26638extensions when it reads a file for debugging. This allows the
26639user to automatically customize @value{GDBN} for the program
26640being debugged.
d57a3c85 26641
71b8c845
DE
26642@menu
26643* Sequences:: Canned Sequences of @value{GDBN} Commands
26644* Python:: Extending @value{GDBN} using Python
ed3ef339 26645* Guile:: Extending @value{GDBN} using Guile
71b8c845 26646* Auto-loading extensions:: Automatically loading extensions
ed3ef339 26647* Multiple Extension Languages:: Working with multiple extension languages
71b8c845
DE
26648* Aliases:: Creating new spellings of existing commands
26649@end menu
26650
26651To facilitate the use of extension languages, @value{GDBN} is capable
95433b34 26652of evaluating the contents of a file. When doing so, @value{GDBN}
71b8c845 26653can recognize which extension language is being used by looking at
95433b34
JB
26654the filename extension. Files with an unrecognized filename extension
26655are always treated as a @value{GDBN} Command Files.
26656@xref{Command Files,, Command files}.
26657
26658You can control how @value{GDBN} evaluates these files with the following
26659setting:
26660
26661@table @code
26662@kindex set script-extension
26663@kindex show script-extension
26664@item set script-extension off
26665All scripts are always evaluated as @value{GDBN} Command Files.
26666
26667@item set script-extension soft
26668The debugger determines the scripting language based on filename
26669extension. If this scripting language is supported, @value{GDBN}
26670evaluates the script using that language. Otherwise, it evaluates
26671the file as a @value{GDBN} Command File.
26672
26673@item set script-extension strict
26674The debugger determines the scripting language based on filename
26675extension, and evaluates the script using that language. If the
26676language is not supported, then the evaluation fails.
26677
26678@item show script-extension
26679Display the current value of the @code{script-extension} option.
26680
26681@end table
26682
ed2a2229
CB
26683@ifset SYSTEM_GDBINIT_DIR
26684This setting is not used for files in the system-wide gdbinit directory.
26685Files in that directory must have an extension matching their language,
26686or have a @file{.gdb} extension to be interpreted as regular @value{GDBN}
26687commands. @xref{Startup}.
26688@end ifset
26689
8e04817f 26690@node Sequences
d57a3c85 26691@section Canned Sequences of Commands
104c1213 26692
8e04817f 26693Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 26694Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
26695commands for execution as a unit: user-defined commands and command
26696files.
104c1213 26697
8e04817f 26698@menu
fcc73fe3
EZ
26699* Define:: How to define your own commands
26700* Hooks:: Hooks for user-defined commands
26701* Command Files:: How to write scripts of commands to be stored in a file
26702* Output:: Commands for controlled output
71b8c845 26703* Auto-loading sequences:: Controlling auto-loaded command files
8e04817f 26704@end menu
104c1213 26705
8e04817f 26706@node Define
d57a3c85 26707@subsection User-defined Commands
104c1213 26708
8e04817f 26709@cindex user-defined command
fcc73fe3 26710@cindex arguments, to user-defined commands
8e04817f
AC
26711A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
26712which you assign a new name as a command. This is done with the
df3ee9ca 26713@code{define} command. User commands may accept an unlimited number of arguments
8e04817f 26714separated by whitespace. Arguments are accessed within the user command
df3ee9ca 26715via @code{$arg0@dots{}$argN}. A trivial example:
104c1213 26716
8e04817f
AC
26717@smallexample
26718define adder
26719 print $arg0 + $arg1 + $arg2
c03c782f 26720end
8e04817f 26721@end smallexample
104c1213
JM
26722
26723@noindent
8e04817f 26724To execute the command use:
104c1213 26725
8e04817f
AC
26726@smallexample
26727adder 1 2 3
26728@end smallexample
104c1213 26729
8e04817f
AC
26730@noindent
26731This defines the command @code{adder}, which prints the sum of
26732its three arguments. Note the arguments are text substitutions, so they may
26733reference variables, use complex expressions, or even perform inferior
26734functions calls.
104c1213 26735
fcc73fe3
EZ
26736@cindex argument count in user-defined commands
26737@cindex how many arguments (user-defined commands)
c03c782f 26738In addition, @code{$argc} may be used to find out how many arguments have
df3ee9ca 26739been passed.
c03c782f
AS
26740
26741@smallexample
26742define adder
26743 if $argc == 2
26744 print $arg0 + $arg1
26745 end
26746 if $argc == 3
26747 print $arg0 + $arg1 + $arg2
26748 end
26749end
26750@end smallexample
26751
01770bbd
PA
26752Combining with the @code{eval} command (@pxref{eval}) makes it easier
26753to process a variable number of arguments:
26754
26755@smallexample
26756define adder
26757 set $i = 0
26758 set $sum = 0
26759 while $i < $argc
26760 eval "set $sum = $sum + $arg%d", $i
26761 set $i = $i + 1
26762 end
26763 print $sum
26764end
26765@end smallexample
26766
104c1213 26767@table @code
104c1213 26768
8e04817f
AC
26769@kindex define
26770@item define @var{commandname}
26771Define a command named @var{commandname}. If there is already a command
26772by that name, you are asked to confirm that you want to redefine it.
697aa1b7 26773The argument @var{commandname} may be a bare command name consisting of letters,
bf498525
PW
26774numbers, dashes, dots, and underscores. It may also start with any
26775predefined or user-defined prefix command.
26776For example, @samp{define target my-target} creates
adb483fe 26777a user-defined @samp{target my-target} command.
104c1213 26778
8e04817f
AC
26779The definition of the command is made up of other @value{GDBN} command lines,
26780which are given following the @code{define} command. The end of these
26781commands is marked by a line containing @code{end}.
104c1213 26782
8e04817f 26783@kindex document
ca91424e 26784@kindex end@r{ (user-defined commands)}
8e04817f
AC
26785@item document @var{commandname}
26786Document the user-defined command @var{commandname}, so that it can be
26787accessed by @code{help}. The command @var{commandname} must already be
26788defined. This command reads lines of documentation just as @code{define}
26789reads the lines of the command definition, ending with @code{end}.
26790After the @code{document} command is finished, @code{help} on command
26791@var{commandname} displays the documentation you have written.
104c1213 26792
8e04817f
AC
26793You may use the @code{document} command again to change the
26794documentation of a command. Redefining the command with @code{define}
26795does not change the documentation.
104c1213 26796
bf498525
PW
26797@kindex define-prefix
26798@item define-prefix @var{commandname}
26799Define or mark the command @var{commandname} as a user-defined prefix
26800command. Once marked, @var{commandname} can be used as prefix command
26801by the @code{define} command.
26802Note that @code{define-prefix} can be used with a not yet defined
26803@var{commandname}. In such a case, @var{commandname} is defined as
26804an empty user-defined command.
26805In case you redefine a command that was marked as a user-defined
26806prefix command, the subcommands of the redefined command are kept
26807(and @value{GDBN} indicates so to the user).
26808
26809Example:
26810@example
26811(gdb) define-prefix abc
26812(gdb) define-prefix abc def
26813(gdb) define abc def
26814Type commands for definition of "abc def".
26815End with a line saying just "end".
26816>echo command initial def\n
26817>end
26818(gdb) define abc def ghi
26819Type commands for definition of "abc def ghi".
26820End with a line saying just "end".
26821>echo command ghi\n
26822>end
26823(gdb) define abc def
26824Keeping subcommands of prefix command "def".
26825Redefine command "def"? (y or n) y
26826Type commands for definition of "abc def".
26827End with a line saying just "end".
26828>echo command def\n
26829>end
26830(gdb) abc def ghi
26831command ghi
26832(gdb) abc def
26833command def
26834(gdb)
26835@end example
26836
c45da7e6
EZ
26837@kindex dont-repeat
26838@cindex don't repeat command
26839@item dont-repeat
26840Used inside a user-defined command, this tells @value{GDBN} that this
26841command should not be repeated when the user hits @key{RET}
26842(@pxref{Command Syntax, repeat last command}).
26843
8e04817f
AC
26844@kindex help user-defined
26845@item help user-defined
7d74f244 26846List all user-defined commands and all python commands defined in class
6b92c0d3 26847COMMAND_USER. The first line of the documentation or docstring is
7d74f244 26848included (if any).
104c1213 26849
8e04817f
AC
26850@kindex show user
26851@item show user
26852@itemx show user @var{commandname}
26853Display the @value{GDBN} commands used to define @var{commandname} (but
26854not its documentation). If no @var{commandname} is given, display the
26855definitions for all user-defined commands.
7d74f244 26856This does not work for user-defined python commands.
104c1213 26857
fcc73fe3 26858@cindex infinite recursion in user-defined commands
20f01a46
DH
26859@kindex show max-user-call-depth
26860@kindex set max-user-call-depth
26861@item show max-user-call-depth
5ca0cb28
DH
26862@itemx set max-user-call-depth
26863The value of @code{max-user-call-depth} controls how many recursion
3f94c067 26864levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 26865infinite recursion and aborts the command.
7d74f244 26866This does not apply to user-defined python commands.
104c1213
JM
26867@end table
26868
fcc73fe3
EZ
26869In addition to the above commands, user-defined commands frequently
26870use control flow commands, described in @ref{Command Files}.
26871
8e04817f
AC
26872When user-defined commands are executed, the
26873commands of the definition are not printed. An error in any command
26874stops execution of the user-defined command.
104c1213 26875
8e04817f
AC
26876If used interactively, commands that would ask for confirmation proceed
26877without asking when used inside a user-defined command. Many @value{GDBN}
26878commands that normally print messages to say what they are doing omit the
26879messages when used in a user-defined command.
104c1213 26880
8e04817f 26881@node Hooks
d57a3c85 26882@subsection User-defined Command Hooks
8e04817f
AC
26883@cindex command hooks
26884@cindex hooks, for commands
26885@cindex hooks, pre-command
104c1213 26886
8e04817f 26887@kindex hook
8e04817f
AC
26888You may define @dfn{hooks}, which are a special kind of user-defined
26889command. Whenever you run the command @samp{foo}, if the user-defined
26890command @samp{hook-foo} exists, it is executed (with no arguments)
26891before that command.
104c1213 26892
8e04817f
AC
26893@cindex hooks, post-command
26894@kindex hookpost
8e04817f
AC
26895A hook may also be defined which is run after the command you executed.
26896Whenever you run the command @samp{foo}, if the user-defined command
26897@samp{hookpost-foo} exists, it is executed (with no arguments) after
26898that command. Post-execution hooks may exist simultaneously with
26899pre-execution hooks, for the same command.
104c1213 26900
8e04817f 26901It is valid for a hook to call the command which it hooks. If this
9f1c6395 26902occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 26903
8e04817f
AC
26904@c It would be nice if hookpost could be passed a parameter indicating
26905@c if the command it hooks executed properly or not. FIXME!
104c1213 26906
8e04817f
AC
26907@kindex stop@r{, a pseudo-command}
26908In addition, a pseudo-command, @samp{stop} exists. Defining
26909(@samp{hook-stop}) makes the associated commands execute every time
26910execution stops in your program: before breakpoint commands are run,
26911displays are printed, or the stack frame is printed.
104c1213 26912
8e04817f
AC
26913For example, to ignore @code{SIGALRM} signals while
26914single-stepping, but treat them normally during normal execution,
26915you could define:
104c1213 26916
474c8240 26917@smallexample
8e04817f
AC
26918define hook-stop
26919handle SIGALRM nopass
26920end
104c1213 26921
8e04817f
AC
26922define hook-run
26923handle SIGALRM pass
26924end
104c1213 26925
8e04817f 26926define hook-continue
d3e8051b 26927handle SIGALRM pass
8e04817f 26928end
474c8240 26929@end smallexample
104c1213 26930
d3e8051b 26931As a further example, to hook at the beginning and end of the @code{echo}
b383017d 26932command, and to add extra text to the beginning and end of the message,
8e04817f 26933you could define:
104c1213 26934
474c8240 26935@smallexample
8e04817f
AC
26936define hook-echo
26937echo <<<---
26938end
104c1213 26939
8e04817f
AC
26940define hookpost-echo
26941echo --->>>\n
26942end
104c1213 26943
8e04817f
AC
26944(@value{GDBP}) echo Hello World
26945<<<---Hello World--->>>
26946(@value{GDBP})
104c1213 26947
474c8240 26948@end smallexample
104c1213 26949
8e04817f
AC
26950You can define a hook for any single-word command in @value{GDBN}, but
26951not for command aliases; you should define a hook for the basic command
c1468174 26952name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
26953@c FIXME! So how does Joe User discover whether a command is an alias
26954@c or not?
adb483fe
DJ
26955You can hook a multi-word command by adding @code{hook-} or
26956@code{hookpost-} to the last word of the command, e.g.@:
26957@samp{define target hook-remote} to add a hook to @samp{target remote}.
26958
8e04817f
AC
26959If an error occurs during the execution of your hook, execution of
26960@value{GDBN} commands stops and @value{GDBN} issues a prompt
26961(before the command that you actually typed had a chance to run).
104c1213 26962
8e04817f
AC
26963If you try to define a hook which does not match any known command, you
26964get a warning from the @code{define} command.
c906108c 26965
8e04817f 26966@node Command Files
d57a3c85 26967@subsection Command Files
c906108c 26968
8e04817f 26969@cindex command files
fcc73fe3 26970@cindex scripting commands
6fc08d32
EZ
26971A command file for @value{GDBN} is a text file made of lines that are
26972@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
26973also be included. An empty line in a command file does nothing; it
26974does not mean to repeat the last command, as it would from the
26975terminal.
c906108c 26976
6fc08d32 26977You can request the execution of a command file with the @code{source}
95433b34
JB
26978command. Note that the @code{source} command is also used to evaluate
26979scripts that are not Command Files. The exact behavior can be configured
26980using the @code{script-extension} setting.
26981@xref{Extending GDB,, Extending GDB}.
c906108c 26982
8e04817f
AC
26983@table @code
26984@kindex source
ca91424e 26985@cindex execute commands from a file
3f7b2faa 26986@item source [-s] [-v] @var{filename}
8e04817f 26987Execute the command file @var{filename}.
c906108c
SS
26988@end table
26989
fcc73fe3
EZ
26990The lines in a command file are generally executed sequentially,
26991unless the order of execution is changed by one of the
26992@emph{flow-control commands} described below. The commands are not
a71ec265
DH
26993printed as they are executed. An error in any command terminates
26994execution of the command file and control is returned to the console.
c906108c 26995
08001717
DE
26996@value{GDBN} first searches for @var{filename} in the current directory.
26997If the file is not found there, and @var{filename} does not specify a
26998directory, then @value{GDBN} also looks for the file on the source search path
26999(specified with the @samp{directory} command);
27000except that @file{$cdir} is not searched because the compilation directory
27001is not relevant to scripts.
4b505b12 27002
3f7b2faa
DE
27003If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
27004on the search path even if @var{filename} specifies a directory.
27005The search is done by appending @var{filename} to each element of the
27006search path. So, for example, if @var{filename} is @file{mylib/myscript}
27007and the search path contains @file{/home/user} then @value{GDBN} will
27008look for the script @file{/home/user/mylib/myscript}.
27009The search is also done if @var{filename} is an absolute path.
27010For example, if @var{filename} is @file{/tmp/myscript} and
27011the search path contains @file{/home/user} then @value{GDBN} will
27012look for the script @file{/home/user/tmp/myscript}.
27013For DOS-like systems, if @var{filename} contains a drive specification,
27014it is stripped before concatenation. For example, if @var{filename} is
27015@file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
27016will look for the script @file{c:/tmp/myscript}.
27017
16026cd7
AS
27018If @code{-v}, for verbose mode, is given then @value{GDBN} displays
27019each command as it is executed. The option must be given before
27020@var{filename}, and is interpreted as part of the filename anywhere else.
27021
8e04817f
AC
27022Commands that would ask for confirmation if used interactively proceed
27023without asking when used in a command file. Many @value{GDBN} commands that
27024normally print messages to say what they are doing omit the messages
27025when called from command files.
c906108c 27026
8e04817f
AC
27027@value{GDBN} also accepts command input from standard input. In this
27028mode, normal output goes to standard output and error output goes to
27029standard error. Errors in a command file supplied on standard input do
6fc08d32 27030not terminate execution of the command file---execution continues with
8e04817f 27031the next command.
c906108c 27032
474c8240 27033@smallexample
8e04817f 27034gdb < cmds > log 2>&1
474c8240 27035@end smallexample
c906108c 27036
8e04817f
AC
27037(The syntax above will vary depending on the shell used.) This example
27038will execute commands from the file @file{cmds}. All output and errors
27039would be directed to @file{log}.
c906108c 27040
fcc73fe3
EZ
27041Since commands stored on command files tend to be more general than
27042commands typed interactively, they frequently need to deal with
27043complicated situations, such as different or unexpected values of
27044variables and symbols, changes in how the program being debugged is
27045built, etc. @value{GDBN} provides a set of flow-control commands to
27046deal with these complexities. Using these commands, you can write
27047complex scripts that loop over data structures, execute commands
27048conditionally, etc.
27049
27050@table @code
27051@kindex if
27052@kindex else
27053@item if
27054@itemx else
27055This command allows to include in your script conditionally executed
27056commands. The @code{if} command takes a single argument, which is an
27057expression to evaluate. It is followed by a series of commands that
27058are executed only if the expression is true (its value is nonzero).
27059There can then optionally be an @code{else} line, followed by a series
27060of commands that are only executed if the expression was false. The
27061end of the list is marked by a line containing @code{end}.
27062
27063@kindex while
27064@item while
27065This command allows to write loops. Its syntax is similar to
27066@code{if}: the command takes a single argument, which is an expression
27067to evaluate, and must be followed by the commands to execute, one per
27068line, terminated by an @code{end}. These commands are called the
27069@dfn{body} of the loop. The commands in the body of @code{while} are
27070executed repeatedly as long as the expression evaluates to true.
27071
27072@kindex loop_break
27073@item loop_break
27074This command exits the @code{while} loop in whose body it is included.
27075Execution of the script continues after that @code{while}s @code{end}
27076line.
27077
27078@kindex loop_continue
27079@item loop_continue
27080This command skips the execution of the rest of the body of commands
27081in the @code{while} loop in whose body it is included. Execution
27082branches to the beginning of the @code{while} loop, where it evaluates
27083the controlling expression.
ca91424e
EZ
27084
27085@kindex end@r{ (if/else/while commands)}
27086@item end
27087Terminate the block of commands that are the body of @code{if},
27088@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
27089@end table
27090
27091
8e04817f 27092@node Output
d57a3c85 27093@subsection Commands for Controlled Output
c906108c 27094
8e04817f
AC
27095During the execution of a command file or a user-defined command, normal
27096@value{GDBN} output is suppressed; the only output that appears is what is
27097explicitly printed by the commands in the definition. This section
27098describes three commands useful for generating exactly the output you
27099want.
c906108c
SS
27100
27101@table @code
8e04817f
AC
27102@kindex echo
27103@item echo @var{text}
27104@c I do not consider backslash-space a standard C escape sequence
27105@c because it is not in ANSI.
27106Print @var{text}. Nonprinting characters can be included in
27107@var{text} using C escape sequences, such as @samp{\n} to print a
27108newline. @strong{No newline is printed unless you specify one.}
27109In addition to the standard C escape sequences, a backslash followed
27110by a space stands for a space. This is useful for displaying a
27111string with spaces at the beginning or the end, since leading and
27112trailing spaces are otherwise trimmed from all arguments.
27113To print @samp{@w{ }and foo =@w{ }}, use the command
27114@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 27115
8e04817f
AC
27116A backslash at the end of @var{text} can be used, as in C, to continue
27117the command onto subsequent lines. For example,
c906108c 27118
474c8240 27119@smallexample
8e04817f
AC
27120echo This is some text\n\
27121which is continued\n\
27122onto several lines.\n
474c8240 27123@end smallexample
c906108c 27124
8e04817f 27125produces the same output as
c906108c 27126
474c8240 27127@smallexample
8e04817f
AC
27128echo This is some text\n
27129echo which is continued\n
27130echo onto several lines.\n
474c8240 27131@end smallexample
c906108c 27132
8e04817f
AC
27133@kindex output
27134@item output @var{expression}
27135Print the value of @var{expression} and nothing but that value: no
27136newlines, no @samp{$@var{nn} = }. The value is not entered in the
27137value history either. @xref{Expressions, ,Expressions}, for more information
27138on expressions.
c906108c 27139
8e04817f
AC
27140@item output/@var{fmt} @var{expression}
27141Print the value of @var{expression} in format @var{fmt}. You can use
27142the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 27143Formats}, for more information.
c906108c 27144
8e04817f 27145@kindex printf
82160952
EZ
27146@item printf @var{template}, @var{expressions}@dots{}
27147Print the values of one or more @var{expressions} under the control of
27148the string @var{template}. To print several values, make
27149@var{expressions} be a comma-separated list of individual expressions,
27150which may be either numbers or pointers. Their values are printed as
27151specified by @var{template}, exactly as a C program would do by
27152executing the code below:
c906108c 27153
474c8240 27154@smallexample
82160952 27155printf (@var{template}, @var{expressions}@dots{});
474c8240 27156@end smallexample
c906108c 27157
82160952
EZ
27158As in @code{C} @code{printf}, ordinary characters in @var{template}
27159are printed verbatim, while @dfn{conversion specification} introduced
27160by the @samp{%} character cause subsequent @var{expressions} to be
27161evaluated, their values converted and formatted according to type and
27162style information encoded in the conversion specifications, and then
27163printed.
27164
8e04817f 27165For example, you can print two values in hex like this:
c906108c 27166
8e04817f
AC
27167@smallexample
27168printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
27169@end smallexample
c906108c 27170
82160952
EZ
27171@code{printf} supports all the standard @code{C} conversion
27172specifications, including the flags and modifiers between the @samp{%}
27173character and the conversion letter, with the following exceptions:
27174
27175@itemize @bullet
27176@item
27177The argument-ordering modifiers, such as @samp{2$}, are not supported.
27178
27179@item
27180The modifier @samp{*} is not supported for specifying precision or
27181width.
27182
27183@item
27184The @samp{'} flag (for separation of digits into groups according to
27185@code{LC_NUMERIC'}) is not supported.
27186
27187@item
27188The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
27189supported.
27190
27191@item
27192The conversion letter @samp{n} (as in @samp{%n}) is not supported.
27193
27194@item
27195The conversion letters @samp{a} and @samp{A} are not supported.
27196@end itemize
27197
27198@noindent
27199Note that the @samp{ll} type modifier is supported only if the
27200underlying @code{C} implementation used to build @value{GDBN} supports
27201the @code{long long int} type, and the @samp{L} type modifier is
27202supported only if @code{long double} type is available.
27203
27204As in @code{C}, @code{printf} supports simple backslash-escape
27205sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
27206@samp{\a}, and @samp{\f}, that consist of backslash followed by a
27207single character. Octal and hexadecimal escape sequences are not
27208supported.
1a619819
LM
27209
27210Additionally, @code{printf} supports conversion specifications for DFP
0aea4bf3
LM
27211(@dfn{Decimal Floating Point}) types using the following length modifiers
27212together with a floating point specifier.
1a619819
LM
27213letters:
27214
27215@itemize @bullet
27216@item
27217@samp{H} for printing @code{Decimal32} types.
27218
27219@item
27220@samp{D} for printing @code{Decimal64} types.
27221
27222@item
27223@samp{DD} for printing @code{Decimal128} types.
27224@end itemize
27225
27226If the underlying @code{C} implementation used to build @value{GDBN} has
0aea4bf3 27227support for the three length modifiers for DFP types, other modifiers
3b784c4f 27228such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
27229
27230In case there is no such @code{C} support, no additional modifiers will be
27231available and the value will be printed in the standard way.
27232
27233Here's an example of printing DFP types using the above conversion letters:
27234@smallexample
0aea4bf3 27235printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
1a619819
LM
27236@end smallexample
27237
01770bbd 27238@anchor{eval}
f1421989
HZ
27239@kindex eval
27240@item eval @var{template}, @var{expressions}@dots{}
27241Convert the values of one or more @var{expressions} under the control of
27242the string @var{template} to a command line, and call it.
27243
c906108c
SS
27244@end table
27245
71b8c845
DE
27246@node Auto-loading sequences
27247@subsection Controlling auto-loading native @value{GDBN} scripts
27248@cindex native script auto-loading
27249
27250When a new object file is read (for example, due to the @code{file}
27251command, or because the inferior has loaded a shared library),
27252@value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
27253@xref{Auto-loading extensions}.
27254
27255Auto-loading can be enabled or disabled,
27256and the list of auto-loaded scripts can be printed.
27257
27258@table @code
27259@anchor{set auto-load gdb-scripts}
27260@kindex set auto-load gdb-scripts
27261@item set auto-load gdb-scripts [on|off]
27262Enable or disable the auto-loading of canned sequences of commands scripts.
27263
27264@anchor{show auto-load gdb-scripts}
27265@kindex show auto-load gdb-scripts
27266@item show auto-load gdb-scripts
27267Show whether auto-loading of canned sequences of commands scripts is enabled or
27268disabled.
27269
27270@anchor{info auto-load gdb-scripts}
27271@kindex info auto-load gdb-scripts
27272@cindex print list of auto-loaded canned sequences of commands scripts
27273@item info auto-load gdb-scripts [@var{regexp}]
27274Print the list of all canned sequences of commands scripts that @value{GDBN}
27275auto-loaded.
27276@end table
27277
27278If @var{regexp} is supplied only canned sequences of commands scripts with
27279matching names are printed.
27280
329baa95
DE
27281@c Python docs live in a separate file.
27282@include python.texi
0e3509db 27283
ed3ef339
DE
27284@c Guile docs live in a separate file.
27285@include guile.texi
27286
71b8c845
DE
27287@node Auto-loading extensions
27288@section Auto-loading extensions
27289@cindex auto-loading extensions
27290
27291@value{GDBN} provides two mechanisms for automatically loading extensions
27292when a new object file is read (for example, due to the @code{file}
27293command, or because the inferior has loaded a shared library):
27294@file{@var{objfile}-gdb.@var{ext}} and the @code{.debug_gdb_scripts}
27295section of modern file formats like ELF.
27296
27297@menu
27298* objfile-gdb.ext file: objfile-gdbdotext file. The @file{@var{objfile}-gdb.@var{ext}} file
27299* .debug_gdb_scripts section: dotdebug_gdb_scripts section. The @code{.debug_gdb_scripts} section
27300* Which flavor to choose?::
27301@end menu
27302
27303The auto-loading feature is useful for supplying application-specific
27304debugging commands and features.
27305
27306Auto-loading can be enabled or disabled,
27307and the list of auto-loaded scripts can be printed.
27308See the @samp{auto-loading} section of each extension language
27309for more information.
27310For @value{GDBN} command files see @ref{Auto-loading sequences}.
27311For Python files see @ref{Python Auto-loading}.
27312
27313Note that loading of this script file also requires accordingly configured
27314@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27315
27316@node objfile-gdbdotext file
27317@subsection The @file{@var{objfile}-gdb.@var{ext}} file
27318@cindex @file{@var{objfile}-gdb.gdb}
27319@cindex @file{@var{objfile}-gdb.py}
27320@cindex @file{@var{objfile}-gdb.scm}
27321
27322When a new object file is read, @value{GDBN} looks for a file named
27323@file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
27324where @var{objfile} is the object file's name and
27325where @var{ext} is the file extension for the extension language:
27326
27327@table @code
27328@item @file{@var{objfile}-gdb.gdb}
27329GDB's own command language
27330@item @file{@var{objfile}-gdb.py}
27331Python
ed3ef339
DE
27332@item @file{@var{objfile}-gdb.scm}
27333Guile
71b8c845
DE
27334@end table
27335
27336@var{script-name} is formed by ensuring that the file name of @var{objfile}
27337is absolute, following all symlinks, and resolving @code{.} and @code{..}
27338components, and appending the @file{-gdb.@var{ext}} suffix.
27339If this file exists and is readable, @value{GDBN} will evaluate it as a
27340script in the specified extension language.
27341
27342If this file does not exist, then @value{GDBN} will look for
27343@var{script-name} file in all of the directories as specified below.
6e2469ff
HD
27344(On MS-Windows/MS-DOS, the drive letter of the executable's leading
27345directories is converted to a one-letter subdirectory, i.e.@:
27346@file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
27347filesystems disallow colons in file names.)
71b8c845
DE
27348
27349Note that loading of these files requires an accordingly configured
27350@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27351
27352For object files using @file{.exe} suffix @value{GDBN} tries to load first the
27353scripts normally according to its @file{.exe} filename. But if no scripts are
27354found @value{GDBN} also tries script filenames matching the object file without
27355its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
27356is attempted on any platform. This makes the script filenames compatible
27357between Unix and MS-Windows hosts.
27358
27359@table @code
27360@anchor{set auto-load scripts-directory}
27361@kindex set auto-load scripts-directory
27362@item set auto-load scripts-directory @r{[}@var{directories}@r{]}
27363Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
27364may be delimited by the host platform path separator in use
27365(@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
27366
27367Each entry here needs to be covered also by the security setting
27368@code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
27369
27370@anchor{with-auto-load-dir}
27371This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
27372@code{set auto-load safe-path} value can be also overriden by @value{GDBN}
27373configuration option @option{--with-auto-load-dir}.
27374
27375Any reference to @file{$debugdir} will get replaced by
27376@var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
27377reference to @file{$datadir} will get replaced by @var{data-directory} which is
27378determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
27379@file{$datadir} must be placed as a directory component --- either alone or
27380delimited by @file{/} or @file{\} directory separators, depending on the host
27381platform.
27382
27383The list of directories uses path separator (@samp{:} on GNU and Unix
27384systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
27385to the @env{PATH} environment variable.
27386
27387@anchor{show auto-load scripts-directory}
27388@kindex show auto-load scripts-directory
27389@item show auto-load scripts-directory
27390Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
27391
27392@anchor{add-auto-load-scripts-directory}
27393@kindex add-auto-load-scripts-directory
27394@item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
27395Add an entry (or list of entries) to the list of auto-loaded scripts locations.
27396Multiple entries may be delimited by the host platform path separator in use.
71b8c845
DE
27397@end table
27398
27399@value{GDBN} does not track which files it has already auto-loaded this way.
27400@value{GDBN} will load the associated script every time the corresponding
27401@var{objfile} is opened.
27402So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
27403is evaluated more than once.
27404
27405@node dotdebug_gdb_scripts section
27406@subsection The @code{.debug_gdb_scripts} section
27407@cindex @code{.debug_gdb_scripts} section
27408
27409For systems using file formats like ELF and COFF,
27410when @value{GDBN} loads a new object file
27411it will look for a special section named @code{.debug_gdb_scripts}.
9f050062
DE
27412If this section exists, its contents is a list of null-terminated entries
27413specifying scripts to load. Each entry begins with a non-null prefix byte that
27414specifies the kind of entry, typically the extension language and whether the
27415script is in a file or inlined in @code{.debug_gdb_scripts}.
71b8c845 27416
9f050062
DE
27417The following entries are supported:
27418
27419@table @code
27420@item SECTION_SCRIPT_ID_PYTHON_FILE = 1
27421@item SECTION_SCRIPT_ID_SCHEME_FILE = 3
27422@item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
27423@item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
27424@end table
27425
27426@subsubsection Script File Entries
27427
27428If the entry specifies a file, @value{GDBN} will look for the file first
27429in the current directory and then along the source search path
71b8c845
DE
27430(@pxref{Source Path, ,Specifying Source Directories}),
27431except that @file{$cdir} is not searched, since the compilation
27432directory is not relevant to scripts.
27433
9f050062 27434File entries can be placed in section @code{.debug_gdb_scripts} with,
71b8c845
DE
27435for example, this GCC macro for Python scripts.
27436
27437@example
27438/* Note: The "MS" section flags are to remove duplicates. */
27439#define DEFINE_GDB_PY_SCRIPT(script_name) \
27440 asm("\
27441.pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
27442.byte 1 /* Python */\n\
27443.asciz \"" script_name "\"\n\
27444.popsection \n\
27445");
27446@end example
27447
27448@noindent
ed3ef339 27449For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
71b8c845
DE
27450Then one can reference the macro in a header or source file like this:
27451
27452@example
27453DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
27454@end example
27455
27456The script name may include directories if desired.
27457
27458Note that loading of this script file also requires accordingly configured
27459@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27460
27461If the macro invocation is put in a header, any application or library
27462using this header will get a reference to the specified script,
27463and with the use of @code{"MS"} attributes on the section, the linker
27464will remove duplicates.
27465
9f050062
DE
27466@subsubsection Script Text Entries
27467
27468Script text entries allow to put the executable script in the entry
27469itself instead of loading it from a file.
27470The first line of the entry, everything after the prefix byte and up to
27471the first newline (@code{0xa}) character, is the script name, and must not
27472contain any kind of space character, e.g., spaces or tabs.
27473The rest of the entry, up to the trailing null byte, is the script to
27474execute in the specified language. The name needs to be unique among
27475all script names, as @value{GDBN} executes each script only once based
27476on its name.
27477
27478Here is an example from file @file{py-section-script.c} in the @value{GDBN}
27479testsuite.
27480
27481@example
27482#include "symcat.h"
27483#include "gdb/section-scripts.h"
27484asm(
27485".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
27486".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
27487".ascii \"gdb.inlined-script\\n\"\n"
27488".ascii \"class test_cmd (gdb.Command):\\n\"\n"
27489".ascii \" def __init__ (self):\\n\"\n"
27490".ascii \" super (test_cmd, self).__init__ ("
27491 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
27492".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
27493".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
27494".ascii \"test_cmd ()\\n\"\n"
27495".byte 0\n"
27496".popsection\n"
27497);
27498@end example
27499
27500Loading of inlined scripts requires a properly configured
27501@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27502The path to specify in @code{auto-load safe-path} is the path of the file
27503containing the @code{.debug_gdb_scripts} section.
27504
71b8c845
DE
27505@node Which flavor to choose?
27506@subsection Which flavor to choose?
27507
27508Given the multiple ways of auto-loading extensions, it might not always
27509be clear which one to choose. This section provides some guidance.
27510
27511@noindent
27512Benefits of the @file{-gdb.@var{ext}} way:
27513
27514@itemize @bullet
27515@item
27516Can be used with file formats that don't support multiple sections.
27517
27518@item
27519Ease of finding scripts for public libraries.
27520
27521Scripts specified in the @code{.debug_gdb_scripts} section are searched for
27522in the source search path.
27523For publicly installed libraries, e.g., @file{libstdc++}, there typically
27524isn't a source directory in which to find the script.
27525
27526@item
27527Doesn't require source code additions.
27528@end itemize
27529
27530@noindent
27531Benefits of the @code{.debug_gdb_scripts} way:
27532
27533@itemize @bullet
27534@item
27535Works with static linking.
27536
27537Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
27538trigger their loading. When an application is statically linked the only
27539objfile available is the executable, and it is cumbersome to attach all the
27540scripts from all the input libraries to the executable's
27541@file{-gdb.@var{ext}} script.
27542
27543@item
27544Works with classes that are entirely inlined.
27545
27546Some classes can be entirely inlined, and thus there may not be an associated
27547shared library to attach a @file{-gdb.@var{ext}} script to.
27548
27549@item
27550Scripts needn't be copied out of the source tree.
27551
27552In some circumstances, apps can be built out of large collections of internal
27553libraries, and the build infrastructure necessary to install the
27554@file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
27555cumbersome. It may be easier to specify the scripts in the
27556@code{.debug_gdb_scripts} section as relative paths, and add a path to the
27557top of the source tree to the source search path.
27558@end itemize
27559
ed3ef339
DE
27560@node Multiple Extension Languages
27561@section Multiple Extension Languages
27562
27563The Guile and Python extension languages do not share any state,
27564and generally do not interfere with each other.
27565There are some things to be aware of, however.
27566
27567@subsection Python comes first
27568
27569Python was @value{GDBN}'s first extension language, and to avoid breaking
27570existing behaviour Python comes first. This is generally solved by the
27571``first one wins'' principle. @value{GDBN} maintains a list of enabled
27572extension languages, and when it makes a call to an extension language,
27573(say to pretty-print a value), it tries each in turn until an extension
27574language indicates it has performed the request (e.g., has returned the
27575pretty-printed form of a value).
27576This extends to errors while performing such requests: If an error happens
27577while, for example, trying to pretty-print an object then the error is
27578reported and any following extension languages are not tried.
27579
5a56e9c5
DE
27580@node Aliases
27581@section Creating new spellings of existing commands
27582@cindex aliases for commands
27583
27584It is often useful to define alternate spellings of existing commands.
27585For example, if a new @value{GDBN} command defined in Python has
27586a long name to type, it is handy to have an abbreviated version of it
27587that involves less typing.
27588
27589@value{GDBN} itself uses aliases. For example @samp{s} is an alias
27590of the @samp{step} command even though it is otherwise an ambiguous
27591abbreviation of other commands like @samp{set} and @samp{show}.
27592
27593Aliases are also used to provide shortened or more common versions
27594of multi-word commands. For example, @value{GDBN} provides the
27595@samp{tty} alias of the @samp{set inferior-tty} command.
27596
27597You can define a new alias with the @samp{alias} command.
27598
27599@table @code
27600
27601@kindex alias
5b860c93 27602@item alias [-a] [--] @var{ALIAS} = @var{COMMAND} [DEFAULT-ARGS...]
5a56e9c5
DE
27603
27604@end table
27605
27606@var{ALIAS} specifies the name of the new alias.
27607Each word of @var{ALIAS} must consist of letters, numbers, dashes and
27608underscores.
27609
27610@var{COMMAND} specifies the name of an existing command
27611that is being aliased.
27612
5b860c93
PW
27613@var{COMMAND} can also be the name of an existing alias. In this case,
27614@var{COMMAND} cannot be an alias that has default arguments.
27615
5a56e9c5 27616The @samp{-a} option specifies that the new alias is an abbreviation
5b4a1a8d 27617of the command. Abbreviations are not used in command completion.
5a56e9c5
DE
27618
27619The @samp{--} option specifies the end of options,
27620and is useful when @var{ALIAS} begins with a dash.
27621
5b860c93
PW
27622You can specify @var{default-args} for your alias.
27623These @var{default-args} will be automatically added before the alias
27624arguments typed explicitly on the command line.
27625
27626For example, the below defines an alias @code{btfullall} that shows all local
27627variables and all frame arguments:
27628@smallexample
27629(@value{GDBP}) alias btfullall = backtrace -full -frame-arguments all
27630@end smallexample
27631
27632For more information about @var{default-args}, see @ref{Command aliases default args,
27633,Automatically prepend default arguments to user-defined aliases}.
27634
5a56e9c5
DE
27635Here is a simple example showing how to make an abbreviation
27636of a command so that there is less to type.
27637Suppose you were tired of typing @samp{disas}, the current
27638shortest unambiguous abbreviation of the @samp{disassemble} command
27639and you wanted an even shorter version named @samp{di}.
27640The following will accomplish this.
27641
27642@smallexample
27643(gdb) alias -a di = disas
27644@end smallexample
27645
27646Note that aliases are different from user-defined commands.
27647With a user-defined command, you also need to write documentation
27648for it with the @samp{document} command.
27649An alias automatically picks up the documentation of the existing command.
27650
27651Here is an example where we make @samp{elms} an abbreviation of
27652@samp{elements} in the @samp{set print elements} command.
27653This is to show that you can make an abbreviation of any part
27654of a command.
27655
27656@smallexample
27657(gdb) alias -a set print elms = set print elements
27658(gdb) alias -a show print elms = show print elements
27659(gdb) set p elms 20
27660(gdb) show p elms
27661Limit on string chars or array elements to print is 200.
27662@end smallexample
27663
27664Note that if you are defining an alias of a @samp{set} command,
27665and you want to have an alias for the corresponding @samp{show}
27666command, then you need to define the latter separately.
27667
27668Unambiguously abbreviated commands are allowed in @var{COMMAND} and
27669@var{ALIAS}, just as they are normally.
27670
27671@smallexample
27672(gdb) alias -a set pr elms = set p ele
27673@end smallexample
27674
27675Finally, here is an example showing the creation of a one word
27676alias for a more complex command.
27677This creates alias @samp{spe} of the command @samp{set print elements}.
27678
27679@smallexample
27680(gdb) alias spe = set print elements
27681(gdb) spe 20
27682@end smallexample
27683
21c294e6
AC
27684@node Interpreters
27685@chapter Command Interpreters
27686@cindex command interpreters
27687
27688@value{GDBN} supports multiple command interpreters, and some command
27689infrastructure to allow users or user interface writers to switch
27690between interpreters or run commands in other interpreters.
27691
27692@value{GDBN} currently supports two command interpreters, the console
27693interpreter (sometimes called the command-line interpreter or @sc{cli})
27694and the machine interface interpreter (or @sc{gdb/mi}). This manual
27695describes both of these interfaces in great detail.
27696
27697By default, @value{GDBN} will start with the console interpreter.
27698However, the user may choose to start @value{GDBN} with another
27699interpreter by specifying the @option{-i} or @option{--interpreter}
27700startup options. Defined interpreters include:
27701
27702@table @code
27703@item console
27704@cindex console interpreter
27705The traditional console or command-line interpreter. This is the most often
27706used interpreter with @value{GDBN}. With no interpreter specified at runtime,
27707@value{GDBN} will use this interpreter.
27708
27709@item mi
27710@cindex mi interpreter
b4be1b06 27711The newest @sc{gdb/mi} interface (currently @code{mi3}). Used primarily
21c294e6
AC
27712by programs wishing to use @value{GDBN} as a backend for a debugger GUI
27713or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
27714Interface}.
27715
b4be1b06
SM
27716@item mi3
27717@cindex mi3 interpreter
27718The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
27719
21c294e6
AC
27720@item mi2
27721@cindex mi2 interpreter
b4be1b06 27722The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
21c294e6
AC
27723
27724@item mi1
27725@cindex mi1 interpreter
b4be1b06 27726The @sc{gdb/mi} interface introduced in @value{GDBN} 5.1.
21c294e6
AC
27727
27728@end table
27729
27730@cindex invoke another interpreter
21c294e6
AC
27731
27732@kindex interpreter-exec
86f78169
PA
27733You may execute commands in any interpreter from the current
27734interpreter using the appropriate command. If you are running the
27735console interpreter, simply use the @code{interpreter-exec} command:
21c294e6
AC
27736
27737@smallexample
27738interpreter-exec mi "-data-list-register-names"
27739@end smallexample
27740
27741@sc{gdb/mi} has a similar command, although it is only available in versions of
27742@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
27743
86f78169
PA
27744Note that @code{interpreter-exec} only changes the interpreter for the
27745duration of the specified command. It does not change the interpreter
27746permanently.
27747
27748@cindex start a new independent interpreter
27749
27750Although you may only choose a single interpreter at startup, it is
27751possible to run an independent interpreter on a specified input/output
27752device (usually a tty).
27753
27754For example, consider a debugger GUI or IDE that wants to provide a
27755@value{GDBN} console view. It may do so by embedding a terminal
27756emulator widget in its GUI, starting @value{GDBN} in the traditional
27757command-line mode with stdin/stdout/stderr redirected to that
27758terminal, and then creating an MI interpreter running on a specified
27759input/output device. The console interpreter created by @value{GDBN}
27760at startup handles commands the user types in the terminal widget,
27761while the GUI controls and synchronizes state with @value{GDBN} using
27762the separate MI interpreter.
27763
27764To start a new secondary @dfn{user interface} running MI, use the
27765@code{new-ui} command:
27766
27767@kindex new-ui
27768@cindex new user interface
27769@smallexample
27770new-ui @var{interpreter} @var{tty}
27771@end smallexample
27772
27773The @var{interpreter} parameter specifies the interpreter to run.
27774This accepts the same values as the @code{interpreter-exec} command.
27775For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
27776@var{tty} parameter specifies the name of the bidirectional file the
27777interpreter uses for input/output, usually the name of a
27778pseudoterminal slave on Unix systems. For example:
27779
27780@smallexample
27781(@value{GDBP}) new-ui mi /dev/pts/9
27782@end smallexample
27783
27784@noindent
27785runs an MI interpreter on @file{/dev/pts/9}.
27786
8e04817f
AC
27787@node TUI
27788@chapter @value{GDBN} Text User Interface
27789@cindex TUI
d0d5df6f 27790@cindex Text User Interface
c906108c 27791
8e04817f
AC
27792@menu
27793* TUI Overview:: TUI overview
27794* TUI Keys:: TUI key bindings
7cf36c78 27795* TUI Single Key Mode:: TUI single key mode
db2e3e2e 27796* TUI Commands:: TUI-specific commands
8e04817f
AC
27797* TUI Configuration:: TUI configuration variables
27798@end menu
c906108c 27799
46ba6afa 27800The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
27801interface which uses the @code{curses} library to show the source
27802file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
27803commands in separate text windows. The TUI mode is supported only
27804on platforms where a suitable version of the @code{curses} library
27805is available.
d0d5df6f 27806
46ba6afa 27807The TUI mode is enabled by default when you invoke @value{GDBN} as
217bff3e 27808@samp{@value{GDBP} -tui}.
46ba6afa 27809You can also switch in and out of TUI mode while @value{GDBN} runs by
a4ea0946 27810using various TUI commands and key bindings, such as @command{tui
bcd8537c 27811enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
a4ea0946 27812@ref{TUI Keys, ,TUI Key Bindings}.
c906108c 27813
8e04817f 27814@node TUI Overview
79a6e687 27815@section TUI Overview
c906108c 27816
46ba6afa 27817In TUI mode, @value{GDBN} can display several text windows:
c906108c 27818
8e04817f
AC
27819@table @emph
27820@item command
27821This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
27822prompt and the @value{GDBN} output. The @value{GDBN} input is still
27823managed using readline.
c906108c 27824
8e04817f
AC
27825@item source
27826The source window shows the source file of the program. The current
46ba6afa 27827line and active breakpoints are displayed in this window.
c906108c 27828
8e04817f
AC
27829@item assembly
27830The assembly window shows the disassembly output of the program.
c906108c 27831
8e04817f 27832@item register
46ba6afa
BW
27833This window shows the processor registers. Registers are highlighted
27834when their values change.
c906108c
SS
27835@end table
27836
269c21fe 27837The source and assembly windows show the current program position
46ba6afa
BW
27838by highlighting the current line and marking it with a @samp{>} marker.
27839Breakpoints are indicated with two markers. The first marker
269c21fe
SC
27840indicates the breakpoint type:
27841
27842@table @code
27843@item B
27844Breakpoint which was hit at least once.
27845
27846@item b
27847Breakpoint which was never hit.
27848
27849@item H
27850Hardware breakpoint which was hit at least once.
27851
27852@item h
27853Hardware breakpoint which was never hit.
269c21fe
SC
27854@end table
27855
27856The second marker indicates whether the breakpoint is enabled or not:
27857
27858@table @code
27859@item +
27860Breakpoint is enabled.
27861
27862@item -
27863Breakpoint is disabled.
269c21fe
SC
27864@end table
27865
46ba6afa
BW
27866The source, assembly and register windows are updated when the current
27867thread changes, when the frame changes, or when the program counter
27868changes.
27869
27870These windows are not all visible at the same time. The command
27871window is always visible. The others can be arranged in several
27872layouts:
c906108c 27873
8e04817f
AC
27874@itemize @bullet
27875@item
46ba6afa 27876source only,
2df3850c 27877
8e04817f 27878@item
46ba6afa 27879assembly only,
8e04817f
AC
27880
27881@item
46ba6afa 27882source and assembly,
8e04817f
AC
27883
27884@item
46ba6afa 27885source and registers, or
c906108c 27886
8e04817f 27887@item
46ba6afa 27888assembly and registers.
8e04817f 27889@end itemize
c906108c 27890
ee325b61
TT
27891These are the standard layouts, but other layouts can be defined.
27892
46ba6afa 27893A status line above the command window shows the following information:
b7bb15bc
SC
27894
27895@table @emph
27896@item target
46ba6afa 27897Indicates the current @value{GDBN} target.
b7bb15bc
SC
27898(@pxref{Targets, ,Specifying a Debugging Target}).
27899
27900@item process
46ba6afa 27901Gives the current process or thread number.
b7bb15bc
SC
27902When no process is being debugged, this field is set to @code{No process}.
27903
27904@item function
27905Gives the current function name for the selected frame.
27906The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 27907When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
27908the string @code{??} is displayed.
27909
27910@item line
27911Indicates the current line number for the selected frame.
46ba6afa 27912When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
27913
27914@item pc
27915Indicates the current program counter address.
b7bb15bc
SC
27916@end table
27917
8e04817f
AC
27918@node TUI Keys
27919@section TUI Key Bindings
27920@cindex TUI key bindings
c906108c 27921
8e04817f 27922The TUI installs several key bindings in the readline keymaps
39037522
TT
27923@ifset SYSTEM_READLINE
27924(@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
27925@end ifset
27926@ifclear SYSTEM_READLINE
27927(@pxref{Command Line Editing}).
27928@end ifclear
27929The following key bindings are installed for both TUI mode and the
27930@value{GDBN} standard mode.
c906108c 27931
8e04817f
AC
27932@table @kbd
27933@kindex C-x C-a
27934@item C-x C-a
27935@kindex C-x a
27936@itemx C-x a
27937@kindex C-x A
27938@itemx C-x A
46ba6afa
BW
27939Enter or leave the TUI mode. When leaving the TUI mode,
27940the curses window management stops and @value{GDBN} operates using
27941its standard mode, writing on the terminal directly. When reentering
27942the TUI mode, control is given back to the curses windows.
8e04817f 27943The screen is then refreshed.
c906108c 27944
c86d74cc
TT
27945This key binding uses the bindable Readline function
27946@code{tui-switch-mode}.
27947
8e04817f
AC
27948@kindex C-x 1
27949@item C-x 1
27950Use a TUI layout with only one window. The layout will
27951either be @samp{source} or @samp{assembly}. When the TUI mode
27952is not active, it will switch to the TUI mode.
2df3850c 27953
8e04817f 27954Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 27955
c86d74cc
TT
27956This key binding uses the bindable Readline function
27957@code{tui-delete-other-windows}.
27958
8e04817f
AC
27959@kindex C-x 2
27960@item C-x 2
27961Use a TUI layout with at least two windows. When the current
46ba6afa 27962layout already has two windows, the next layout with two windows is used.
8e04817f
AC
27963When a new layout is chosen, one window will always be common to the
27964previous layout and the new one.
c906108c 27965
8e04817f 27966Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 27967
c86d74cc
TT
27968This key binding uses the bindable Readline function
27969@code{tui-change-windows}.
27970
72ffddc9
SC
27971@kindex C-x o
27972@item C-x o
27973Change the active window. The TUI associates several key bindings
46ba6afa 27974(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
27975gives the focus to the next TUI window.
27976
27977Think of it as the Emacs @kbd{C-x o} binding.
27978
c86d74cc
TT
27979This key binding uses the bindable Readline function
27980@code{tui-other-window}.
27981
7cf36c78
SC
27982@kindex C-x s
27983@item C-x s
46ba6afa
BW
27984Switch in and out of the TUI SingleKey mode that binds single
27985keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c86d74cc
TT
27986
27987This key binding uses the bindable Readline function
27988@code{next-keymap}.
c906108c
SS
27989@end table
27990
46ba6afa 27991The following key bindings only work in the TUI mode:
5d161b24 27992
46ba6afa 27993@table @asis
8e04817f 27994@kindex PgUp
46ba6afa 27995@item @key{PgUp}
8e04817f 27996Scroll the active window one page up.
c906108c 27997
8e04817f 27998@kindex PgDn
46ba6afa 27999@item @key{PgDn}
8e04817f 28000Scroll the active window one page down.
c906108c 28001
8e04817f 28002@kindex Up
46ba6afa 28003@item @key{Up}
8e04817f 28004Scroll the active window one line up.
c906108c 28005
8e04817f 28006@kindex Down
46ba6afa 28007@item @key{Down}
8e04817f 28008Scroll the active window one line down.
c906108c 28009
8e04817f 28010@kindex Left
46ba6afa 28011@item @key{Left}
8e04817f 28012Scroll the active window one column left.
c906108c 28013
8e04817f 28014@kindex Right
46ba6afa 28015@item @key{Right}
8e04817f 28016Scroll the active window one column right.
c906108c 28017
8e04817f 28018@kindex C-L
46ba6afa 28019@item @kbd{C-L}
8e04817f 28020Refresh the screen.
8e04817f 28021@end table
c906108c 28022
46ba6afa
BW
28023Because the arrow keys scroll the active window in the TUI mode, they
28024are not available for their normal use by readline unless the command
28025window has the focus. When another window is active, you must use
28026other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
28027and @kbd{C-f} to control the command window.
8e04817f 28028
7cf36c78
SC
28029@node TUI Single Key Mode
28030@section TUI Single Key Mode
28031@cindex TUI single key mode
28032
46ba6afa
BW
28033The TUI also provides a @dfn{SingleKey} mode, which binds several
28034frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
28035switch into this mode, where the following key bindings are used:
7cf36c78
SC
28036
28037@table @kbd
28038@kindex c @r{(SingleKey TUI key)}
28039@item c
28040continue
28041
28042@kindex d @r{(SingleKey TUI key)}
28043@item d
28044down
28045
28046@kindex f @r{(SingleKey TUI key)}
28047@item f
28048finish
28049
28050@kindex n @r{(SingleKey TUI key)}
28051@item n
28052next
28053
a5afdb16
RK
28054@kindex o @r{(SingleKey TUI key)}
28055@item o
28056nexti. The shortcut letter @samp{o} stands for ``step Over''.
28057
7cf36c78
SC
28058@kindex q @r{(SingleKey TUI key)}
28059@item q
46ba6afa 28060exit the SingleKey mode.
7cf36c78
SC
28061
28062@kindex r @r{(SingleKey TUI key)}
28063@item r
28064run
28065
28066@kindex s @r{(SingleKey TUI key)}
28067@item s
28068step
28069
a5afdb16
RK
28070@kindex i @r{(SingleKey TUI key)}
28071@item i
28072stepi. The shortcut letter @samp{i} stands for ``step Into''.
28073
7cf36c78
SC
28074@kindex u @r{(SingleKey TUI key)}
28075@item u
28076up
28077
28078@kindex v @r{(SingleKey TUI key)}
28079@item v
28080info locals
28081
28082@kindex w @r{(SingleKey TUI key)}
28083@item w
28084where
7cf36c78
SC
28085@end table
28086
28087Other keys temporarily switch to the @value{GDBN} command prompt.
28088The key that was pressed is inserted in the editing buffer so that
28089it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
28090with the TUI SingleKey mode. Once the command is entered the TUI
28091SingleKey mode is restored. The only way to permanently leave
7f9087cb 28092this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78 28093
11061048
TT
28094@cindex SingleKey keymap name
28095If @value{GDBN} was built with Readline 8.0 or later, the TUI
28096SingleKey keymap will be named @samp{SingleKey}. This can be used in
28097@file{.inputrc} to add additional bindings to this keymap.
7cf36c78 28098
8e04817f 28099@node TUI Commands
db2e3e2e 28100@section TUI-specific Commands
8e04817f
AC
28101@cindex TUI commands
28102
28103The TUI has specific commands to control the text windows.
46ba6afa
BW
28104These commands are always available, even when @value{GDBN} is not in
28105the TUI mode. When @value{GDBN} is in the standard mode, most
28106of these commands will automatically switch to the TUI mode.
c906108c 28107
ff12863f
PA
28108Note that if @value{GDBN}'s @code{stdout} is not connected to a
28109terminal, or @value{GDBN} has been started with the machine interface
28110interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
28111these commands will fail with an error, because it would not be
28112possible or desirable to enable curses window management.
28113
c906108c 28114@table @code
a4ea0946
AB
28115@item tui enable
28116@kindex tui enable
28117Activate TUI mode. The last active TUI window layout will be used if
760f7560 28118TUI mode has previously been used in the current debugging session,
a4ea0946
AB
28119otherwise a default layout is used.
28120
28121@item tui disable
28122@kindex tui disable
28123Disable TUI mode, returning to the console interpreter.
28124
3d757584
SC
28125@item info win
28126@kindex info win
28127List and give the size of all displayed windows.
28128
ee325b61
TT
28129@item tui new-layout @var{name} @var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}
28130@kindex tui new-layout
28131Create a new TUI layout. The new layout will be named @var{name}, and
28132can be accessed using the @code{layout} command (see below).
28133
7c043ba6
TT
28134Each @var{window} parameter is either the name of a window to display,
28135or a window description. The windows will be displayed from top to
28136bottom in the order listed.
28137
28138The names of the windows are the same as the ones given to the
ee325b61 28139@code{focus} command (see below); additional, the @code{status}
7c043ba6
TT
28140window can be specified. Note that, because it is of fixed height,
28141the weight assigned to the status window is of no importance. It is
28142conventional to use @samp{0} here.
28143
28144A window description looks a bit like an invocation of @code{tui
28145new-layout}, and is of the form
28146@{@r{[}@code{-horizontal}@r{]}@var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}@}.
28147
28148This specifies a sub-layout. If @code{-horizontal} is given, the
28149windows in this description will be arranged side-by-side, rather than
28150top-to-bottom.
ee325b61
TT
28151
28152Each @var{weight} is an integer. It is the weight of this window
28153relative to all the other windows in the layout. These numbers are
28154used to calculate how much of the screen is given to each window.
28155
28156For example:
28157
28158@example
28159(gdb) tui new-layout example src 1 regs 1 status 0 cmd 1
28160@end example
28161
28162Here, the new layout is called @samp{example}. It shows the source
28163and register windows, followed by the status window, and then finally
28164the command window. The non-status windows all have the same weight,
28165so the terminal will be split into three roughly equal sections.
28166
7c043ba6
TT
28167Here is a more complex example, showing a horizontal layout:
28168
28169@example
28170(gdb) tui new-layout example @{-horizontal src 1 asm 1@} 2 status 0 cmd 1
28171@end example
28172
28173This will result in side-by-side source and assembly windows; with the
28174status and command window being beneath these, filling the entire
28175width of the terminal. Because they have weight 2, the source and
28176assembly windows will be twice the height of the command window.
28177
6008fc5f 28178@item layout @var{name}
4644b6e3 28179@kindex layout
ee325b61
TT
28180Changes which TUI windows are displayed. The @var{name} parameter
28181controls which layout is shown. It can be either one of the built-in
28182layout names, or the name of a layout defined by the user using
28183@code{tui new-layout}.
28184
28185The built-in layouts are as follows:
6008fc5f
AB
28186
28187@table @code
28188@item next
8e04817f 28189Display the next layout.
2df3850c 28190
6008fc5f 28191@item prev
8e04817f 28192Display the previous layout.
c906108c 28193
6008fc5f
AB
28194@item src
28195Display the source and command windows.
c906108c 28196
6008fc5f
AB
28197@item asm
28198Display the assembly and command windows.
c906108c 28199
6008fc5f
AB
28200@item split
28201Display the source, assembly, and command windows.
c906108c 28202
6008fc5f
AB
28203@item regs
28204When in @code{src} layout display the register, source, and command
28205windows. When in @code{asm} or @code{split} layout display the
28206register, assembler, and command windows.
28207@end table
8e04817f 28208
6008fc5f 28209@item focus @var{name}
8e04817f 28210@kindex focus
6008fc5f
AB
28211Changes which TUI window is currently active for scrolling. The
28212@var{name} parameter can be any of the following:
28213
28214@table @code
28215@item next
46ba6afa
BW
28216Make the next window active for scrolling.
28217
6008fc5f 28218@item prev
46ba6afa
BW
28219Make the previous window active for scrolling.
28220
6008fc5f 28221@item src
46ba6afa
BW
28222Make the source window active for scrolling.
28223
6008fc5f 28224@item asm
46ba6afa
BW
28225Make the assembly window active for scrolling.
28226
6008fc5f 28227@item regs
46ba6afa
BW
28228Make the register window active for scrolling.
28229
6008fc5f 28230@item cmd
46ba6afa 28231Make the command window active for scrolling.
6008fc5f 28232@end table
c906108c 28233
8e04817f
AC
28234@item refresh
28235@kindex refresh
7f9087cb 28236Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 28237
51f0e40d 28238@item tui reg @var{group}
6a1b180d 28239@kindex tui reg
51f0e40d
AB
28240Changes the register group displayed in the tui register window to
28241@var{group}. If the register window is not currently displayed this
28242command will cause the register window to be displayed. The list of
28243register groups, as well as their order is target specific. The
28244following groups are available on most targets:
28245@table @code
28246@item next
28247Repeatedly selecting this group will cause the display to cycle
28248through all of the available register groups.
28249
28250@item prev
28251Repeatedly selecting this group will cause the display to cycle
28252through all of the available register groups in the reverse order to
28253@var{next}.
28254
28255@item general
28256Display the general registers.
28257@item float
28258Display the floating point registers.
28259@item system
28260Display the system registers.
28261@item vector
28262Display the vector registers.
28263@item all
28264Display all registers.
28265@end table
6a1b180d 28266
8e04817f
AC
28267@item update
28268@kindex update
28269Update the source window and the current execution point.
c906108c 28270
8e04817f
AC
28271@item winheight @var{name} +@var{count}
28272@itemx winheight @var{name} -@var{count}
28273@kindex winheight
28274Change the height of the window @var{name} by @var{count}
28275lines. Positive counts increase the height, while negative counts
bf555842
EZ
28276decrease it. The @var{name} parameter can be one of @code{src} (the
28277source window), @code{cmd} (the command window), @code{asm} (the
28278disassembly window), or @code{regs} (the register display window).
d6677607 28279@end table
2df3850c 28280
8e04817f 28281@node TUI Configuration
79a6e687 28282@section TUI Configuration Variables
8e04817f 28283@cindex TUI configuration variables
c906108c 28284
46ba6afa 28285Several configuration variables control the appearance of TUI windows.
c906108c 28286
8e04817f
AC
28287@table @code
28288@item set tui border-kind @var{kind}
28289@kindex set tui border-kind
28290Select the border appearance for the source, assembly and register windows.
28291The possible values are the following:
28292@table @code
28293@item space
28294Use a space character to draw the border.
c906108c 28295
8e04817f 28296@item ascii
46ba6afa 28297Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 28298
8e04817f
AC
28299@item acs
28300Use the Alternate Character Set to draw the border. The border is
28301drawn using character line graphics if the terminal supports them.
8e04817f 28302@end table
c78b4128 28303
8e04817f
AC
28304@item set tui border-mode @var{mode}
28305@kindex set tui border-mode
46ba6afa
BW
28306@itemx set tui active-border-mode @var{mode}
28307@kindex set tui active-border-mode
28308Select the display attributes for the borders of the inactive windows
28309or the active window. The @var{mode} can be one of the following:
8e04817f
AC
28310@table @code
28311@item normal
28312Use normal attributes to display the border.
c906108c 28313
8e04817f
AC
28314@item standout
28315Use standout mode.
c906108c 28316
8e04817f
AC
28317@item reverse
28318Use reverse video mode.
c906108c 28319
8e04817f
AC
28320@item half
28321Use half bright mode.
c906108c 28322
8e04817f
AC
28323@item half-standout
28324Use half bright and standout mode.
c906108c 28325
8e04817f
AC
28326@item bold
28327Use extra bright or bold mode.
c78b4128 28328
8e04817f
AC
28329@item bold-standout
28330Use extra bright or bold and standout mode.
8e04817f 28331@end table
7806cea7
TT
28332
28333@item set tui tab-width @var{nchars}
28334@kindex set tui tab-width
28335@kindex tabset
28336Set the width of tab stops to be @var{nchars} characters. This
28337setting affects the display of TAB characters in the source and
28338assembly windows.
d1da6b01
TT
28339
28340@item set tui compact-source @r{[}on@r{|}off@r{]}
28341@kindex set tui compact-source
28342Set whether the TUI source window is displayed in ``compact'' form.
28343The default display uses more space for line numbers and starts the
28344source text at the next tab stop; the compact display uses only as
28345much space as is needed for the line numbers in the current file, and
28346only a single space to separate the line numbers from the source.
7806cea7 28347@end table
c78b4128 28348
a2a7af0c
TT
28349Note that the colors of the TUI borders can be controlled using the
28350appropriate @code{set style} commands. @xref{Output Styling}.
28351
8e04817f
AC
28352@node Emacs
28353@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 28354
8e04817f
AC
28355@cindex Emacs
28356@cindex @sc{gnu} Emacs
28357A special interface allows you to use @sc{gnu} Emacs to view (and
28358edit) the source files for the program you are debugging with
28359@value{GDBN}.
c906108c 28360
8e04817f
AC
28361To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
28362executable file you want to debug as an argument. This command starts
28363@value{GDBN} as a subprocess of Emacs, with input and output through a newly
28364created Emacs buffer.
28365@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 28366
5e252a2e 28367Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 28368things:
c906108c 28369
8e04817f
AC
28370@itemize @bullet
28371@item
5e252a2e
NR
28372All ``terminal'' input and output goes through an Emacs buffer, called
28373the GUD buffer.
c906108c 28374
8e04817f
AC
28375This applies both to @value{GDBN} commands and their output, and to the input
28376and output done by the program you are debugging.
bf0184be 28377
8e04817f
AC
28378This is useful because it means that you can copy the text of previous
28379commands and input them again; you can even use parts of the output
28380in this way.
bf0184be 28381
8e04817f
AC
28382All the facilities of Emacs' Shell mode are available for interacting
28383with your program. In particular, you can send signals the usual
28384way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
28385stop.
bf0184be
ND
28386
28387@item
8e04817f 28388@value{GDBN} displays source code through Emacs.
bf0184be 28389
8e04817f
AC
28390Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
28391source file for that frame and puts an arrow (@samp{=>}) at the
28392left margin of the current line. Emacs uses a separate buffer for
28393source display, and splits the screen to show both your @value{GDBN} session
28394and the source.
bf0184be 28395
8e04817f
AC
28396Explicit @value{GDBN} @code{list} or search commands still produce output as
28397usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
28398@end itemize
28399
28400We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
28401a graphical mode, enabled by default, which provides further buffers
28402that can control the execution and describe the state of your program.
28403@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 28404
64fabec2
AC
28405If you specify an absolute file name when prompted for the @kbd{M-x
28406gdb} argument, then Emacs sets your current working directory to where
28407your program resides. If you only specify the file name, then Emacs
7a9dd1b2 28408sets your current working directory to the directory associated
64fabec2
AC
28409with the previous buffer. In this case, @value{GDBN} may find your
28410program by searching your environment's @code{PATH} variable, but on
28411some operating systems it might not find the source. So, although the
28412@value{GDBN} input and output session proceeds normally, the auxiliary
28413buffer does not display the current source and line of execution.
28414
28415The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
28416line of the GUD buffer and this serves as a default for the commands
28417that specify files for @value{GDBN} to operate on. @xref{Files,
28418,Commands to Specify Files}.
64fabec2
AC
28419
28420By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
28421need to call @value{GDBN} by a different name (for example, if you
28422keep several configurations around, with different names) you can
28423customize the Emacs variable @code{gud-gdb-command-name} to run the
28424one you want.
8e04817f 28425
5e252a2e 28426In the GUD buffer, you can use these special Emacs commands in
8e04817f 28427addition to the standard Shell mode commands:
c906108c 28428
8e04817f
AC
28429@table @kbd
28430@item C-h m
5e252a2e 28431Describe the features of Emacs' GUD Mode.
c906108c 28432
64fabec2 28433@item C-c C-s
8e04817f
AC
28434Execute to another source line, like the @value{GDBN} @code{step} command; also
28435update the display window to show the current file and location.
c906108c 28436
64fabec2 28437@item C-c C-n
8e04817f
AC
28438Execute to next source line in this function, skipping all function
28439calls, like the @value{GDBN} @code{next} command. Then update the display window
28440to show the current file and location.
c906108c 28441
64fabec2 28442@item C-c C-i
8e04817f
AC
28443Execute one instruction, like the @value{GDBN} @code{stepi} command; update
28444display window accordingly.
c906108c 28445
8e04817f
AC
28446@item C-c C-f
28447Execute until exit from the selected stack frame, like the @value{GDBN}
28448@code{finish} command.
c906108c 28449
64fabec2 28450@item C-c C-r
8e04817f
AC
28451Continue execution of your program, like the @value{GDBN} @code{continue}
28452command.
b433d00b 28453
64fabec2 28454@item C-c <
8e04817f
AC
28455Go up the number of frames indicated by the numeric argument
28456(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
28457like the @value{GDBN} @code{up} command.
b433d00b 28458
64fabec2 28459@item C-c >
8e04817f
AC
28460Go down the number of frames indicated by the numeric argument, like the
28461@value{GDBN} @code{down} command.
8e04817f 28462@end table
c906108c 28463
7f9087cb 28464In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 28465tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 28466
5e252a2e
NR
28467In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
28468separate frame which shows a backtrace when the GUD buffer is current.
28469Move point to any frame in the stack and type @key{RET} to make it
28470become the current frame and display the associated source in the
28471source buffer. Alternatively, click @kbd{Mouse-2} to make the
28472selected frame become the current one. In graphical mode, the
28473speedbar displays watch expressions.
64fabec2 28474
8e04817f
AC
28475If you accidentally delete the source-display buffer, an easy way to get
28476it back is to type the command @code{f} in the @value{GDBN} buffer, to
28477request a frame display; when you run under Emacs, this recreates
28478the source buffer if necessary to show you the context of the current
28479frame.
c906108c 28480
8e04817f
AC
28481The source files displayed in Emacs are in ordinary Emacs buffers
28482which are visiting the source files in the usual way. You can edit
28483the files with these buffers if you wish; but keep in mind that @value{GDBN}
28484communicates with Emacs in terms of line numbers. If you add or
28485delete lines from the text, the line numbers that @value{GDBN} knows cease
28486to correspond properly with the code.
b383017d 28487
5e252a2e
NR
28488A more detailed description of Emacs' interaction with @value{GDBN} is
28489given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
28490Emacs Manual}).
c906108c 28491
922fbb7b
AC
28492@node GDB/MI
28493@chapter The @sc{gdb/mi} Interface
28494
28495@unnumberedsec Function and Purpose
28496
28497@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
28498@sc{gdb/mi} is a line based machine oriented text interface to
28499@value{GDBN} and is activated by specifying using the
28500@option{--interpreter} command line option (@pxref{Mode Options}). It
28501is specifically intended to support the development of systems which
28502use the debugger as just one small component of a larger system.
922fbb7b
AC
28503
28504This chapter is a specification of the @sc{gdb/mi} interface. It is written
28505in the form of a reference manual.
28506
28507Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
28508features described below are incomplete and subject to change
28509(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
28510
28511@unnumberedsec Notation and Terminology
28512
28513@cindex notational conventions, for @sc{gdb/mi}
28514This chapter uses the following notation:
28515
28516@itemize @bullet
28517@item
28518@code{|} separates two alternatives.
28519
28520@item
28521@code{[ @var{something} ]} indicates that @var{something} is optional:
28522it may or may not be given.
28523
28524@item
28525@code{( @var{group} )*} means that @var{group} inside the parentheses
28526may repeat zero or more times.
28527
28528@item
28529@code{( @var{group} )+} means that @var{group} inside the parentheses
28530may repeat one or more times.
28531
28532@item
28533@code{"@var{string}"} means a literal @var{string}.
28534@end itemize
28535
28536@ignore
28537@heading Dependencies
28538@end ignore
28539
922fbb7b 28540@menu
c3b108f7 28541* GDB/MI General Design::
922fbb7b
AC
28542* GDB/MI Command Syntax::
28543* GDB/MI Compatibility with CLI::
af6eff6f 28544* GDB/MI Development and Front Ends::
922fbb7b 28545* GDB/MI Output Records::
ef21caaf 28546* GDB/MI Simple Examples::
922fbb7b 28547* GDB/MI Command Description Format::
ef21caaf 28548* GDB/MI Breakpoint Commands::
3fa7bf06 28549* GDB/MI Catchpoint Commands::
a2c02241
NR
28550* GDB/MI Program Context::
28551* GDB/MI Thread Commands::
5d77fe44 28552* GDB/MI Ada Tasking Commands::
a2c02241
NR
28553* GDB/MI Program Execution::
28554* GDB/MI Stack Manipulation::
28555* GDB/MI Variable Objects::
922fbb7b 28556* GDB/MI Data Manipulation::
a2c02241
NR
28557* GDB/MI Tracepoint Commands::
28558* GDB/MI Symbol Query::
351ff01a 28559* GDB/MI File Commands::
922fbb7b
AC
28560@ignore
28561* GDB/MI Kod Commands::
28562* GDB/MI Memory Overlay Commands::
28563* GDB/MI Signal Handling Commands::
28564@end ignore
922fbb7b 28565* GDB/MI Target Manipulation::
a6b151f1 28566* GDB/MI File Transfer Commands::
58d06528 28567* GDB/MI Ada Exceptions Commands::
d192b373 28568* GDB/MI Support Commands::
ef21caaf 28569* GDB/MI Miscellaneous Commands::
922fbb7b
AC
28570@end menu
28571
c3b108f7
VP
28572@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28573@node GDB/MI General Design
28574@section @sc{gdb/mi} General Design
28575@cindex GDB/MI General Design
28576
28577Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
28578parts---commands sent to @value{GDBN}, responses to those commands
28579and notifications. Each command results in exactly one response,
28580indicating either successful completion of the command, or an error.
28581For the commands that do not resume the target, the response contains the
28582requested information. For the commands that resume the target, the
28583response only indicates whether the target was successfully resumed.
28584Notifications is the mechanism for reporting changes in the state of the
28585target, or in @value{GDBN} state, that cannot conveniently be associated with
28586a command and reported as part of that command response.
28587
28588The important examples of notifications are:
28589@itemize @bullet
28590
28591@item
28592Exec notifications. These are used to report changes in
28593target state---when a target is resumed, or stopped. It would not
28594be feasible to include this information in response of resuming
28595commands, because one resume commands can result in multiple events in
28596different threads. Also, quite some time may pass before any event
28597happens in the target, while a frontend needs to know whether the resuming
28598command itself was successfully executed.
28599
28600@item
28601Console output, and status notifications. Console output
28602notifications are used to report output of CLI commands, as well as
28603diagnostics for other commands. Status notifications are used to
28604report the progress of a long-running operation. Naturally, including
28605this information in command response would mean no output is produced
28606until the command is finished, which is undesirable.
28607
28608@item
28609General notifications. Commands may have various side effects on
28610the @value{GDBN} or target state beyond their official purpose. For example,
28611a command may change the selected thread. Although such changes can
28612be included in command response, using notification allows for more
28613orthogonal frontend design.
28614
28615@end itemize
28616
28617There's no guarantee that whenever an MI command reports an error,
28618@value{GDBN} or the target are in any specific state, and especially,
28619the state is not reverted to the state before the MI command was
28620processed. Therefore, whenever an MI command results in an error,
28621we recommend that the frontend refreshes all the information shown in
28622the user interface.
28623
508094de
NR
28624
28625@menu
28626* Context management::
28627* Asynchronous and non-stop modes::
28628* Thread groups::
28629@end menu
28630
28631@node Context management
c3b108f7
VP
28632@subsection Context management
28633
403cb6b1
JB
28634@subsubsection Threads and Frames
28635
c3b108f7
VP
28636In most cases when @value{GDBN} accesses the target, this access is
28637done in context of a specific thread and frame (@pxref{Frames}).
28638Often, even when accessing global data, the target requires that a thread
28639be specified. The CLI interface maintains the selected thread and frame,
28640and supplies them to target on each command. This is convenient,
28641because a command line user would not want to specify that information
28642explicitly on each command, and because user interacts with
28643@value{GDBN} via a single terminal, so no confusion is possible as
28644to what thread and frame are the current ones.
28645
28646In the case of MI, the concept of selected thread and frame is less
28647useful. First, a frontend can easily remember this information
28648itself. Second, a graphical frontend can have more than one window,
28649each one used for debugging a different thread, and the frontend might
28650want to access additional threads for internal purposes. This
28651increases the risk that by relying on implicitly selected thread, the
28652frontend may be operating on a wrong one. Therefore, each MI command
28653should explicitly specify which thread and frame to operate on. To
28654make it possible, each MI command accepts the @samp{--thread} and
5d5658a1
PA
28655@samp{--frame} options, the value to each is @value{GDBN} global
28656identifier for thread and frame to operate on.
c3b108f7
VP
28657
28658Usually, each top-level window in a frontend allows the user to select
28659a thread and a frame, and remembers the user selection for further
28660operations. However, in some cases @value{GDBN} may suggest that the
4034d0ff
AT
28661current thread or frame be changed. For example, when stopping on a
28662breakpoint it is reasonable to switch to the thread where breakpoint is
28663hit. For another example, if the user issues the CLI @samp{thread} or
28664@samp{frame} commands via the frontend, it is desirable to change the
28665frontend's selection to the one specified by user. @value{GDBN}
28666communicates the suggestion to change current thread and frame using the
28667@samp{=thread-selected} notification.
c3b108f7
VP
28668
28669Note that historically, MI shares the selected thread with CLI, so
28670frontends used the @code{-thread-select} to execute commands in the
28671right context. However, getting this to work right is cumbersome. The
28672simplest way is for frontend to emit @code{-thread-select} command
28673before every command. This doubles the number of commands that need
28674to be sent. The alternative approach is to suppress @code{-thread-select}
28675if the selected thread in @value{GDBN} is supposed to be identical to the
28676thread the frontend wants to operate on. However, getting this
28677optimization right can be tricky. In particular, if the frontend
28678sends several commands to @value{GDBN}, and one of the commands changes the
28679selected thread, then the behaviour of subsequent commands will
28680change. So, a frontend should either wait for response from such
28681problematic commands, or explicitly add @code{-thread-select} for
28682all subsequent commands. No frontend is known to do this exactly
28683right, so it is suggested to just always pass the @samp{--thread} and
28684@samp{--frame} options.
28685
403cb6b1
JB
28686@subsubsection Language
28687
28688The execution of several commands depends on which language is selected.
28689By default, the current language (@pxref{show language}) is used.
28690But for commands known to be language-sensitive, it is recommended
28691to use the @samp{--language} option. This option takes one argument,
28692which is the name of the language to use while executing the command.
28693For instance:
28694
28695@smallexample
28696-data-evaluate-expression --language c "sizeof (void*)"
28697^done,value="4"
28698(gdb)
28699@end smallexample
28700
28701The valid language names are the same names accepted by the
28702@samp{set language} command (@pxref{Manually}), excluding @samp{auto},
28703@samp{local} or @samp{unknown}.
28704
508094de 28705@node Asynchronous and non-stop modes
c3b108f7
VP
28706@subsection Asynchronous command execution and non-stop mode
28707
28708On some targets, @value{GDBN} is capable of processing MI commands
28709even while the target is running. This is called @dfn{asynchronous
28710command execution} (@pxref{Background Execution}). The frontend may
6b92c0d3 28711specify a preference for asynchronous execution using the
329ea579 28712@code{-gdb-set mi-async 1} command, which should be emitted before
c3b108f7
VP
28713either running the executable or attaching to the target. After the
28714frontend has started the executable or attached to the target, it can
28715find if asynchronous execution is enabled using the
28716@code{-list-target-features} command.
28717
329ea579
PA
28718@table @code
28719@item -gdb-set mi-async on
28720@item -gdb-set mi-async off
28721Set whether MI is in asynchronous mode.
28722
28723When @code{off}, which is the default, MI execution commands (e.g.,
28724@code{-exec-continue}) are foreground commands, and @value{GDBN} waits
28725for the program to stop before processing further commands.
28726
28727When @code{on}, MI execution commands are background execution
28728commands (e.g., @code{-exec-continue} becomes the equivalent of the
28729@code{c&} CLI command), and so @value{GDBN} is capable of processing
28730MI commands even while the target is running.
28731
28732@item -gdb-show mi-async
28733Show whether MI asynchronous mode is enabled.
28734@end table
28735
28736Note: In @value{GDBN} version 7.7 and earlier, this option was called
28737@code{target-async} instead of @code{mi-async}, and it had the effect
28738of both putting MI in asynchronous mode and making CLI background
28739commands possible. CLI background commands are now always possible
28740``out of the box'' if the target supports them. The old spelling is
28741kept as a deprecated alias for backwards compatibility.
28742
c3b108f7
VP
28743Even if @value{GDBN} can accept a command while target is running,
28744many commands that access the target do not work when the target is
28745running. Therefore, asynchronous command execution is most useful
28746when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
28747it is possible to examine the state of one thread, while other threads
28748are running.
28749
28750When a given thread is running, MI commands that try to access the
28751target in the context of that thread may not work, or may work only on
28752some targets. In particular, commands that try to operate on thread's
28753stack will not work, on any target. Commands that read memory, or
28754modify breakpoints, may work or not work, depending on the target. Note
28755that even commands that operate on global state, such as @code{print},
28756@code{set}, and breakpoint commands, still access the target in the
28757context of a specific thread, so frontend should try to find a
28758stopped thread and perform the operation on that thread (using the
28759@samp{--thread} option).
28760
28761Which commands will work in the context of a running thread is
28762highly target dependent. However, the two commands
28763@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
28764to find the state of a thread, will always work.
28765
508094de 28766@node Thread groups
c3b108f7
VP
28767@subsection Thread groups
28768@value{GDBN} may be used to debug several processes at the same time.
6b92c0d3 28769On some platforms, @value{GDBN} may support debugging of several
c3b108f7
VP
28770hardware systems, each one having several cores with several different
28771processes running on each core. This section describes the MI
28772mechanism to support such debugging scenarios.
28773
28774The key observation is that regardless of the structure of the
28775target, MI can have a global list of threads, because most commands that
28776accept the @samp{--thread} option do not need to know what process that
28777thread belongs to. Therefore, it is not necessary to introduce
28778neither additional @samp{--process} option, nor an notion of the
28779current process in the MI interface. The only strictly new feature
28780that is required is the ability to find how the threads are grouped
28781into processes.
28782
28783To allow the user to discover such grouping, and to support arbitrary
28784hierarchy of machines/cores/processes, MI introduces the concept of a
28785@dfn{thread group}. Thread group is a collection of threads and other
28786thread groups. A thread group always has a string identifier, a type,
28787and may have additional attributes specific to the type. A new
28788command, @code{-list-thread-groups}, returns the list of top-level
28789thread groups, which correspond to processes that @value{GDBN} is
28790debugging at the moment. By passing an identifier of a thread group
28791to the @code{-list-thread-groups} command, it is possible to obtain
28792the members of specific thread group.
28793
28794To allow the user to easily discover processes, and other objects, he
28795wishes to debug, a concept of @dfn{available thread group} is
28796introduced. Available thread group is an thread group that
28797@value{GDBN} is not debugging, but that can be attached to, using the
28798@code{-target-attach} command. The list of available top-level thread
28799groups can be obtained using @samp{-list-thread-groups --available}.
28800In general, the content of a thread group may be only retrieved only
28801after attaching to that thread group.
28802
65c574f6 28803Thread groups are related to inferiors (@pxref{Inferiors Connections and
a79b8f6e
VP
28804Programs}). Each inferior corresponds to a thread group of a special
28805type @samp{process}, and some additional operations are permitted on
28806such thread groups.
28807
922fbb7b
AC
28808@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28809@node GDB/MI Command Syntax
28810@section @sc{gdb/mi} Command Syntax
28811
28812@menu
28813* GDB/MI Input Syntax::
28814* GDB/MI Output Syntax::
922fbb7b
AC
28815@end menu
28816
28817@node GDB/MI Input Syntax
28818@subsection @sc{gdb/mi} Input Syntax
28819
28820@cindex input syntax for @sc{gdb/mi}
28821@cindex @sc{gdb/mi}, input syntax
28822@table @code
28823@item @var{command} @expansion{}
28824@code{@var{cli-command} | @var{mi-command}}
28825
28826@item @var{cli-command} @expansion{}
28827@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
28828@var{cli-command} is any existing @value{GDBN} CLI command.
28829
28830@item @var{mi-command} @expansion{}
28831@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
28832@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
28833
28834@item @var{token} @expansion{}
28835"any sequence of digits"
28836
28837@item @var{option} @expansion{}
28838@code{"-" @var{parameter} [ " " @var{parameter} ]}
28839
28840@item @var{parameter} @expansion{}
28841@code{@var{non-blank-sequence} | @var{c-string}}
28842
28843@item @var{operation} @expansion{}
28844@emph{any of the operations described in this chapter}
28845
28846@item @var{non-blank-sequence} @expansion{}
28847@emph{anything, provided it doesn't contain special characters such as
28848"-", @var{nl}, """ and of course " "}
28849
28850@item @var{c-string} @expansion{}
28851@code{""" @var{seven-bit-iso-c-string-content} """}
28852
28853@item @var{nl} @expansion{}
28854@code{CR | CR-LF}
28855@end table
28856
28857@noindent
28858Notes:
28859
28860@itemize @bullet
28861@item
28862The CLI commands are still handled by the @sc{mi} interpreter; their
28863output is described below.
28864
28865@item
28866The @code{@var{token}}, when present, is passed back when the command
28867finishes.
28868
28869@item
28870Some @sc{mi} commands accept optional arguments as part of the parameter
28871list. Each option is identified by a leading @samp{-} (dash) and may be
28872followed by an optional argument parameter. Options occur first in the
28873parameter list and can be delimited from normal parameters using
28874@samp{--} (this is useful when some parameters begin with a dash).
28875@end itemize
28876
28877Pragmatics:
28878
28879@itemize @bullet
28880@item
28881We want easy access to the existing CLI syntax (for debugging).
28882
28883@item
28884We want it to be easy to spot a @sc{mi} operation.
28885@end itemize
28886
28887@node GDB/MI Output Syntax
28888@subsection @sc{gdb/mi} Output Syntax
28889
28890@cindex output syntax of @sc{gdb/mi}
28891@cindex @sc{gdb/mi}, output syntax
28892The output from @sc{gdb/mi} consists of zero or more out-of-band records
28893followed, optionally, by a single result record. This result record
28894is for the most recent command. The sequence of output records is
594fe323 28895terminated by @samp{(gdb)}.
922fbb7b
AC
28896
28897If an input command was prefixed with a @code{@var{token}} then the
28898corresponding output for that command will also be prefixed by that same
28899@var{token}.
28900
28901@table @code
28902@item @var{output} @expansion{}
594fe323 28903@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
28904
28905@item @var{result-record} @expansion{}
28906@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
28907
28908@item @var{out-of-band-record} @expansion{}
28909@code{@var{async-record} | @var{stream-record}}
28910
28911@item @var{async-record} @expansion{}
28912@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
28913
28914@item @var{exec-async-output} @expansion{}
dcf106f3 28915@code{[ @var{token} ] "*" @var{async-output nl}}
922fbb7b
AC
28916
28917@item @var{status-async-output} @expansion{}
dcf106f3 28918@code{[ @var{token} ] "+" @var{async-output nl}}
922fbb7b
AC
28919
28920@item @var{notify-async-output} @expansion{}
dcf106f3 28921@code{[ @var{token} ] "=" @var{async-output nl}}
922fbb7b
AC
28922
28923@item @var{async-output} @expansion{}
dcf106f3 28924@code{@var{async-class} ( "," @var{result} )*}
922fbb7b
AC
28925
28926@item @var{result-class} @expansion{}
28927@code{"done" | "running" | "connected" | "error" | "exit"}
28928
28929@item @var{async-class} @expansion{}
28930@code{"stopped" | @var{others}} (where @var{others} will be added
28931depending on the needs---this is still in development).
28932
28933@item @var{result} @expansion{}
28934@code{ @var{variable} "=" @var{value}}
28935
28936@item @var{variable} @expansion{}
28937@code{ @var{string} }
28938
28939@item @var{value} @expansion{}
28940@code{ @var{const} | @var{tuple} | @var{list} }
28941
28942@item @var{const} @expansion{}
28943@code{@var{c-string}}
28944
28945@item @var{tuple} @expansion{}
28946@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
28947
28948@item @var{list} @expansion{}
28949@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
28950@var{result} ( "," @var{result} )* "]" }
28951
28952@item @var{stream-record} @expansion{}
28953@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
28954
28955@item @var{console-stream-output} @expansion{}
dcf106f3 28956@code{"~" @var{c-string nl}}
922fbb7b
AC
28957
28958@item @var{target-stream-output} @expansion{}
dcf106f3 28959@code{"@@" @var{c-string nl}}
922fbb7b
AC
28960
28961@item @var{log-stream-output} @expansion{}
dcf106f3 28962@code{"&" @var{c-string nl}}
922fbb7b
AC
28963
28964@item @var{nl} @expansion{}
28965@code{CR | CR-LF}
28966
28967@item @var{token} @expansion{}
28968@emph{any sequence of digits}.
28969@end table
28970
28971@noindent
28972Notes:
28973
28974@itemize @bullet
28975@item
28976All output sequences end in a single line containing a period.
28977
28978@item
721c02de
VP
28979The @code{@var{token}} is from the corresponding request. Note that
28980for all async output, while the token is allowed by the grammar and
28981may be output by future versions of @value{GDBN} for select async
28982output messages, it is generally omitted. Frontends should treat
28983all async output as reporting general changes in the state of the
28984target and there should be no need to associate async output to any
28985prior command.
922fbb7b
AC
28986
28987@item
28988@cindex status output in @sc{gdb/mi}
28989@var{status-async-output} contains on-going status information about the
28990progress of a slow operation. It can be discarded. All status output is
28991prefixed by @samp{+}.
28992
28993@item
28994@cindex async output in @sc{gdb/mi}
28995@var{exec-async-output} contains asynchronous state change on the target
28996(stopped, started, disappeared). All async output is prefixed by
28997@samp{*}.
28998
28999@item
29000@cindex notify output in @sc{gdb/mi}
29001@var{notify-async-output} contains supplementary information that the
29002client should handle (e.g., a new breakpoint information). All notify
29003output is prefixed by @samp{=}.
29004
29005@item
29006@cindex console output in @sc{gdb/mi}
29007@var{console-stream-output} is output that should be displayed as is in the
29008console. It is the textual response to a CLI command. All the console
29009output is prefixed by @samp{~}.
29010
29011@item
29012@cindex target output in @sc{gdb/mi}
29013@var{target-stream-output} is the output produced by the target program.
29014All the target output is prefixed by @samp{@@}.
29015
29016@item
29017@cindex log output in @sc{gdb/mi}
29018@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
29019instance messages that should be displayed as part of an error log. All
29020the log output is prefixed by @samp{&}.
29021
29022@item
29023@cindex list output in @sc{gdb/mi}
29024New @sc{gdb/mi} commands should only output @var{lists} containing
29025@var{values}.
29026
29027
29028@end itemize
29029
29030@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
29031details about the various output records.
29032
922fbb7b
AC
29033@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29034@node GDB/MI Compatibility with CLI
29035@section @sc{gdb/mi} Compatibility with CLI
29036
29037@cindex compatibility, @sc{gdb/mi} and CLI
29038@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 29039
a2c02241
NR
29040For the developers convenience CLI commands can be entered directly,
29041but there may be some unexpected behaviour. For example, commands
29042that query the user will behave as if the user replied yes, breakpoint
29043command lists are not executed and some CLI commands, such as
29044@code{if}, @code{when} and @code{define}, prompt for further input with
29045@samp{>}, which is not valid MI output.
ef21caaf
NR
29046
29047This feature may be removed at some stage in the future and it is
a2c02241
NR
29048recommended that front ends use the @code{-interpreter-exec} command
29049(@pxref{-interpreter-exec}).
922fbb7b 29050
af6eff6f
NR
29051@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29052@node GDB/MI Development and Front Ends
29053@section @sc{gdb/mi} Development and Front Ends
29054@cindex @sc{gdb/mi} development
29055
29056The application which takes the MI output and presents the state of the
29057program being debugged to the user is called a @dfn{front end}.
29058
1fea0d53
SM
29059Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
29060to the MI interface may break existing usage. This section describes how the
29061protocol changes and how to request previous version of the protocol when it
29062does.
af6eff6f
NR
29063
29064Some changes in MI need not break a carefully designed front end, and
29065for these the MI version will remain unchanged. The following is a
29066list of changes that may occur within one level, so front ends should
29067parse MI output in a way that can handle them:
29068
29069@itemize @bullet
29070@item
29071New MI commands may be added.
29072
29073@item
29074New fields may be added to the output of any MI command.
29075
36ece8b3
NR
29076@item
29077The range of values for fields with specified values, e.g.,
9f708cb2 29078@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 29079
af6eff6f
NR
29080@c The format of field's content e.g type prefix, may change so parse it
29081@c at your own risk. Yes, in general?
29082
29083@c The order of fields may change? Shouldn't really matter but it might
29084@c resolve inconsistencies.
29085@end itemize
29086
29087If the changes are likely to break front ends, the MI version level
1fea0d53
SM
29088will be increased by one. The new versions of the MI protocol are not compatible
29089with the old versions. Old versions of MI remain available, allowing front ends
29090to keep using them until they are modified to use the latest MI version.
af6eff6f 29091
1fea0d53
SM
29092Since @code{--interpreter=mi} always points to the latest MI version, it is
29093recommended that front ends request a specific version of MI when launching
29094@value{GDBN} (e.g. @code{--interpreter=mi2}) to make sure they get an
29095interpreter with the MI version they expect.
29096
09f2921c 29097The following table gives a summary of the released versions of the MI
1fea0d53
SM
29098interface: the version number, the version of GDB in which it first appeared
29099and the breaking changes compared to the previous version.
29100
29101@multitable @columnfractions .05 .05 .9
29102@headitem MI version @tab GDB version @tab Breaking changes
29103
29104@item
29105@center 1
29106@tab
29107@center 5.1
29108@tab
29109None
29110
29111@item
29112@center 2
29113@tab
29114@center 6.0
29115@tab
29116
29117@itemize
29118@item
29119The @code{-environment-pwd}, @code{-environment-directory} and
29120@code{-environment-path} commands now returns values using the MI output
29121syntax, rather than CLI output syntax.
29122
29123@item
29124@code{-var-list-children}'s @code{children} result field is now a list, rather
29125than a tuple.
29126
29127@item
29128@code{-var-update}'s @code{changelist} result field is now a list, rather than
29129a tuple.
29130@end itemize
29131
b4be1b06
SM
29132@item
29133@center 3
29134@tab
29135@center 9.1
29136@tab
29137
29138@itemize
29139@item
29140The output of information about multi-location breakpoints has changed in the
29141responses to the @code{-break-insert} and @code{-break-info} commands, as well
29142as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
29143The multiple locations are now placed in a @code{locations} field, whose value
29144is a list.
29145@end itemize
29146
1fea0d53 29147@end multitable
af6eff6f 29148
b4be1b06
SM
29149If your front end cannot yet migrate to a more recent version of the
29150MI protocol, you can nevertheless selectively enable specific features
29151available in those recent MI versions, using the following commands:
29152
29153@table @code
29154
29155@item -fix-multi-location-breakpoint-output
29156Use the output for multi-location breakpoints which was introduced by
29157MI 3, even when using MI versions 2 or 1. This command has no
29158effect when using MI version 3 or later.
29159
5c85e20d 29160@end table
b4be1b06 29161
af6eff6f
NR
29162The best way to avoid unexpected changes in MI that might break your front
29163end is to make your project known to @value{GDBN} developers and
7a9a6b69 29164follow development on @email{gdb@@sourceware.org} and
fa0f268d 29165@email{gdb-patches@@sourceware.org}.
af6eff6f
NR
29166@cindex mailing lists
29167
922fbb7b
AC
29168@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29169@node GDB/MI Output Records
29170@section @sc{gdb/mi} Output Records
29171
29172@menu
29173* GDB/MI Result Records::
29174* GDB/MI Stream Records::
82f68b1c 29175* GDB/MI Async Records::
54516a0b 29176* GDB/MI Breakpoint Information::
c3b108f7 29177* GDB/MI Frame Information::
dc146f7c 29178* GDB/MI Thread Information::
4368ebeb 29179* GDB/MI Ada Exception Information::
922fbb7b
AC
29180@end menu
29181
29182@node GDB/MI Result Records
29183@subsection @sc{gdb/mi} Result Records
29184
29185@cindex result records in @sc{gdb/mi}
29186@cindex @sc{gdb/mi}, result records
29187In addition to a number of out-of-band notifications, the response to a
29188@sc{gdb/mi} command includes one of the following result indications:
29189
29190@table @code
29191@findex ^done
29192@item "^done" [ "," @var{results} ]
29193The synchronous operation was successful, @code{@var{results}} are the return
29194values.
29195
29196@item "^running"
29197@findex ^running
8e9c5e02
VP
29198This result record is equivalent to @samp{^done}. Historically, it
29199was output instead of @samp{^done} if the command has resumed the
29200target. This behaviour is maintained for backward compatibility, but
29201all frontends should treat @samp{^done} and @samp{^running}
29202identically and rely on the @samp{*running} output record to determine
29203which threads are resumed.
922fbb7b 29204
ef21caaf
NR
29205@item "^connected"
29206@findex ^connected
3f94c067 29207@value{GDBN} has connected to a remote target.
ef21caaf 29208
2ea126fa 29209@item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
922fbb7b 29210@findex ^error
2ea126fa
JB
29211The operation failed. The @code{msg=@var{c-string}} variable contains
29212the corresponding error message.
29213
29214If present, the @code{code=@var{c-string}} variable provides an error
29215code on which consumers can rely on to detect the corresponding
29216error condition. At present, only one error code is defined:
29217
29218@table @samp
29219@item "undefined-command"
29220Indicates that the command causing the error does not exist.
29221@end table
ef21caaf
NR
29222
29223@item "^exit"
29224@findex ^exit
3f94c067 29225@value{GDBN} has terminated.
ef21caaf 29226
922fbb7b
AC
29227@end table
29228
29229@node GDB/MI Stream Records
29230@subsection @sc{gdb/mi} Stream Records
29231
29232@cindex @sc{gdb/mi}, stream records
29233@cindex stream records in @sc{gdb/mi}
29234@value{GDBN} internally maintains a number of output streams: the console, the
29235target, and the log. The output intended for each of these streams is
29236funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
29237
29238Each stream record begins with a unique @dfn{prefix character} which
29239identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
29240Syntax}). In addition to the prefix, each stream record contains a
29241@code{@var{string-output}}. This is either raw text (with an implicit new
29242line) or a quoted C string (which does not contain an implicit newline).
29243
29244@table @code
29245@item "~" @var{string-output}
29246The console output stream contains text that should be displayed in the
29247CLI console window. It contains the textual responses to CLI commands.
29248
29249@item "@@" @var{string-output}
29250The target output stream contains any textual output from the running
ef21caaf
NR
29251target. This is only present when GDB's event loop is truly
29252asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
29253
29254@item "&" @var{string-output}
29255The log stream contains debugging messages being produced by @value{GDBN}'s
29256internals.
29257@end table
29258
82f68b1c
VP
29259@node GDB/MI Async Records
29260@subsection @sc{gdb/mi} Async Records
922fbb7b 29261
82f68b1c
VP
29262@cindex async records in @sc{gdb/mi}
29263@cindex @sc{gdb/mi}, async records
29264@dfn{Async} records are used to notify the @sc{gdb/mi} client of
922fbb7b 29265additional changes that have occurred. Those changes can either be a
82f68b1c 29266consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
922fbb7b
AC
29267target activity (e.g., target stopped).
29268
8eb41542 29269The following is the list of possible async records:
922fbb7b
AC
29270
29271@table @code
034dad6f 29272
e1ac3328 29273@item *running,thread-id="@var{thread}"
5d5658a1 29274The target is now running. The @var{thread} field can be the global
09f2921c 29275thread ID of the thread that is now running, and it can be
5d5658a1
PA
29276@samp{all} if all threads are running. The frontend should assume
29277that no interaction with a running thread is possible after this
29278notification is produced. The frontend should not assume that this
29279notification is output only once for any command. @value{GDBN} may
29280emit this notification several times, either for different threads,
29281because it cannot resume all threads together, or even for a single
29282thread, if the thread must be stepped though some code before letting
29283it run freely.
e1ac3328 29284
dc146f7c 29285@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
82f68b1c
VP
29286The target has stopped. The @var{reason} field can have one of the
29287following values:
034dad6f
BR
29288
29289@table @code
29290@item breakpoint-hit
29291A breakpoint was reached.
29292@item watchpoint-trigger
29293A watchpoint was triggered.
29294@item read-watchpoint-trigger
29295A read watchpoint was triggered.
29296@item access-watchpoint-trigger
29297An access watchpoint was triggered.
29298@item function-finished
29299An -exec-finish or similar CLI command was accomplished.
29300@item location-reached
29301An -exec-until or similar CLI command was accomplished.
29302@item watchpoint-scope
29303A watchpoint has gone out of scope.
29304@item end-stepping-range
29305An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
29306similar CLI command was accomplished.
29307@item exited-signalled
29308The inferior exited because of a signal.
29309@item exited
29310The inferior exited.
29311@item exited-normally
29312The inferior exited normally.
29313@item signal-received
29314A signal was received by the inferior.
36dfb11c
TT
29315@item solib-event
29316The inferior has stopped due to a library being loaded or unloaded.
edcc5120
TT
29317This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
29318set or when a @code{catch load} or @code{catch unload} catchpoint is
29319in use (@pxref{Set Catchpoints}).
36dfb11c
TT
29320@item fork
29321The inferior has forked. This is reported when @code{catch fork}
29322(@pxref{Set Catchpoints}) has been used.
29323@item vfork
29324The inferior has vforked. This is reported in when @code{catch vfork}
29325(@pxref{Set Catchpoints}) has been used.
29326@item syscall-entry
29327The inferior entered a system call. This is reported when @code{catch
29328syscall} (@pxref{Set Catchpoints}) has been used.
a64c9f7b 29329@item syscall-return
36dfb11c
TT
29330The inferior returned from a system call. This is reported when
29331@code{catch syscall} (@pxref{Set Catchpoints}) has been used.
29332@item exec
29333The inferior called @code{exec}. This is reported when @code{catch exec}
29334(@pxref{Set Catchpoints}) has been used.
922fbb7b
AC
29335@end table
29336
5d5658a1
PA
29337The @var{id} field identifies the global thread ID of the thread
29338that directly caused the stop -- for example by hitting a breakpoint.
29339Depending on whether all-stop
c3b108f7
VP
29340mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
29341stop all threads, or only the thread that directly triggered the stop.
29342If all threads are stopped, the @var{stopped} field will have the
29343value of @code{"all"}. Otherwise, the value of the @var{stopped}
29344field will be a list of thread identifiers. Presently, this list will
29345always include a single thread, but frontend should be prepared to see
dc146f7c
VP
29346several threads in the list. The @var{core} field reports the
29347processor core on which the stop event has happened. This field may be absent
29348if such information is not available.
c3b108f7 29349
a79b8f6e
VP
29350@item =thread-group-added,id="@var{id}"
29351@itemx =thread-group-removed,id="@var{id}"
29352A thread group was either added or removed. The @var{id} field
29353contains the @value{GDBN} identifier of the thread group. When a thread
29354group is added, it generally might not be associated with a running
29355process. When a thread group is removed, its id becomes invalid and
29356cannot be used in any way.
29357
29358@item =thread-group-started,id="@var{id}",pid="@var{pid}"
29359A thread group became associated with a running program,
29360either because the program was just started or the thread group
29361was attached to a program. The @var{id} field contains the
29362@value{GDBN} identifier of the thread group. The @var{pid} field
29363contains process identifier, specific to the operating system.
29364
8cf64490 29365@item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
a79b8f6e
VP
29366A thread group is no longer associated with a running program,
29367either because the program has exited, or because it was detached
c3b108f7 29368from. The @var{id} field contains the @value{GDBN} identifier of the
697aa1b7 29369thread group. The @var{code} field is the exit code of the inferior; it exists
8cf64490 29370only when the inferior exited with some code.
c3b108f7
VP
29371
29372@item =thread-created,id="@var{id}",group-id="@var{gid}"
29373@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
82f68b1c 29374A thread either was created, or has exited. The @var{id} field
5d5658a1 29375contains the global @value{GDBN} identifier of the thread. The @var{gid}
c3b108f7 29376field identifies the thread group this thread belongs to.
66bb093b 29377
4034d0ff
AT
29378@item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
29379Informs that the selected thread or frame were changed. This notification
29380is not emitted as result of the @code{-thread-select} or
29381@code{-stack-select-frame} commands, but is emitted whenever an MI command
29382that is not documented to change the selected thread and frame actually
29383changes them. In particular, invoking, directly or indirectly
29384(via user-defined command), the CLI @code{thread} or @code{frame} commands,
29385will generate this notification. Changing the thread or frame from another
29386user interface (see @ref{Interpreters}) will also generate this notification.
29387
29388The @var{frame} field is only present if the newly selected thread is
29389stopped. See @ref{GDB/MI Frame Information} for the format of its value.
66bb093b
VP
29390
29391We suggest that in response to this notification, front ends
29392highlight the selected thread and cause subsequent commands to apply to
29393that thread.
29394
c86cf029
VP
29395@item =library-loaded,...
29396Reports that a new library file was loaded by the program. This
51457a05
MAL
29397notification has 5 fields---@var{id}, @var{target-name},
29398@var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
c86cf029
VP
29399opaque identifier of the library. For remote debugging case,
29400@var{target-name} and @var{host-name} fields give the name of the
134eb42c
VP
29401library file on the target, and on the host respectively. For native
29402debugging, both those fields have the same value. The
f1cbe1d3
TT
29403@var{symbols-loaded} field is emitted only for backward compatibility
29404and should not be relied on to convey any useful information. The
29405@var{thread-group} field, if present, specifies the id of the thread
29406group in whose context the library was loaded. If the field is
29407absent, it means the library was loaded in the context of all present
51457a05
MAL
29408thread groups. The @var{ranges} field specifies the ranges of addresses belonging
29409to this library.
c86cf029
VP
29410
29411@item =library-unloaded,...
134eb42c 29412Reports that a library was unloaded by the program. This notification
c86cf029 29413has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
a79b8f6e
VP
29414the same meaning as for the @code{=library-loaded} notification.
29415The @var{thread-group} field, if present, specifies the id of the
29416thread group in whose context the library was unloaded. If the field is
29417absent, it means the library was unloaded in the context of all present
29418thread groups.
c86cf029 29419
201b4506
YQ
29420@item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
29421@itemx =traceframe-changed,end
29422Reports that the trace frame was changed and its new number is
29423@var{tfnum}. The number of the tracepoint associated with this trace
29424frame is @var{tpnum}.
29425
134a2066 29426@item =tsv-created,name=@var{name},initial=@var{initial}
bb25a15c 29427Reports that the new trace state variable @var{name} is created with
134a2066 29428initial value @var{initial}.
bb25a15c
YQ
29429
29430@item =tsv-deleted,name=@var{name}
29431@itemx =tsv-deleted
29432Reports that the trace state variable @var{name} is deleted or all
29433trace state variables are deleted.
29434
134a2066
YQ
29435@item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
29436Reports that the trace state variable @var{name} is modified with
29437the initial value @var{initial}. The current value @var{current} of
29438trace state variable is optional and is reported if the current
29439value of trace state variable is known.
29440
8d3788bd
VP
29441@item =breakpoint-created,bkpt=@{...@}
29442@itemx =breakpoint-modified,bkpt=@{...@}
d9f08f52 29443@itemx =breakpoint-deleted,id=@var{number}
8d3788bd
VP
29444Reports that a breakpoint was created, modified, or deleted,
29445respectively. Only user-visible breakpoints are reported to the MI
29446user.
29447
29448The @var{bkpt} argument is of the same form as returned by the various
d9f08f52
YQ
29449breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
29450@var{number} is the ordinal number of the breakpoint.
8d3788bd
VP
29451
29452Note that if a breakpoint is emitted in the result record of a
29453command, then it will not also be emitted in an async record.
29454
38b022b4 29455@item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
82a90ccf
YQ
29456@itemx =record-stopped,thread-group="@var{id}"
29457Execution log recording was either started or stopped on an
29458inferior. The @var{id} is the @value{GDBN} identifier of the thread
29459group corresponding to the affected inferior.
29460
38b022b4
SM
29461The @var{method} field indicates the method used to record execution. If the
29462method in use supports multiple recording formats, @var{format} will be present
8504e097 29463and contain the currently used format. @xref{Process Record and Replay},
38b022b4
SM
29464for existing method and format values.
29465
5b9afe8a
YQ
29466@item =cmd-param-changed,param=@var{param},value=@var{value}
29467Reports that a parameter of the command @code{set @var{param}} is
29468changed to @var{value}. In the multi-word @code{set} command,
29469the @var{param} is the whole parameter list to @code{set} command.
29470For example, In command @code{set check type on}, @var{param}
29471is @code{check type} and @var{value} is @code{on}.
8de0566d
YQ
29472
29473@item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
29474Reports that bytes from @var{addr} to @var{data} + @var{len} were
29475written in an inferior. The @var{id} is the identifier of the
29476thread group corresponding to the affected inferior. The optional
29477@code{type="code"} part is reported if the memory written to holds
29478executable code.
82f68b1c
VP
29479@end table
29480
54516a0b
TT
29481@node GDB/MI Breakpoint Information
29482@subsection @sc{gdb/mi} Breakpoint Information
29483
29484When @value{GDBN} reports information about a breakpoint, a
29485tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
29486following fields:
29487
29488@table @code
29489@item number
b4be1b06 29490The breakpoint number.
54516a0b
TT
29491
29492@item type
29493The type of the breakpoint. For ordinary breakpoints this will be
29494@samp{breakpoint}, but many values are possible.
29495
8ac3646f
TT
29496@item catch-type
29497If the type of the breakpoint is @samp{catchpoint}, then this
29498indicates the exact type of catchpoint.
29499
54516a0b
TT
29500@item disp
29501This is the breakpoint disposition---either @samp{del}, meaning that
29502the breakpoint will be deleted at the next stop, or @samp{keep},
29503meaning that the breakpoint will not be deleted.
29504
29505@item enabled
29506This indicates whether the breakpoint is enabled, in which case the
29507value is @samp{y}, or disabled, in which case the value is @samp{n}.
29508Note that this is not the same as the field @code{enable}.
29509
29510@item addr
29511The address of the breakpoint. This may be a hexidecimal number,
29512giving the address; or the string @samp{<PENDING>}, for a pending
29513breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
29514multiple locations. This field will not be present if no address can
29515be determined. For example, a watchpoint does not have an address.
29516
aa7ca1bb
AH
29517@item addr_flags
29518Optional field containing any flags related to the address. These flags are
29519architecture-dependent; see @ref{Architectures} for their meaning for a
29520particular CPU.
29521
54516a0b
TT
29522@item func
29523If known, the function in which the breakpoint appears.
29524If not known, this field is not present.
29525
29526@item filename
29527The name of the source file which contains this function, if known.
29528If not known, this field is not present.
29529
29530@item fullname
29531The full file name of the source file which contains this function, if
29532known. If not known, this field is not present.
29533
29534@item line
29535The line number at which this breakpoint appears, if known.
29536If not known, this field is not present.
29537
29538@item at
29539If the source file is not known, this field may be provided. If
29540provided, this holds the address of the breakpoint, possibly followed
29541by a symbol name.
29542
29543@item pending
29544If this breakpoint is pending, this field is present and holds the
29545text used to set the breakpoint, as entered by the user.
29546
29547@item evaluated-by
29548Where this breakpoint's condition is evaluated, either @samp{host} or
29549@samp{target}.
29550
29551@item thread
29552If this is a thread-specific breakpoint, then this identifies the
29553thread in which the breakpoint can trigger.
29554
29555@item task
29556If this breakpoint is restricted to a particular Ada task, then this
29557field will hold the task identifier.
29558
29559@item cond
29560If the breakpoint is conditional, this is the condition expression.
29561
29562@item ignore
29563The ignore count of the breakpoint.
29564
29565@item enable
29566The enable count of the breakpoint.
29567
29568@item traceframe-usage
29569FIXME.
29570
29571@item static-tracepoint-marker-string-id
29572For a static tracepoint, the name of the static tracepoint marker.
29573
29574@item mask
29575For a masked watchpoint, this is the mask.
29576
29577@item pass
29578A tracepoint's pass count.
29579
29580@item original-location
29581The location of the breakpoint as originally specified by the user.
29582This field is optional.
29583
29584@item times
29585The number of times the breakpoint has been hit.
29586
29587@item installed
29588This field is only given for tracepoints. This is either @samp{y},
29589meaning that the tracepoint is installed, or @samp{n}, meaning that it
29590is not.
29591
29592@item what
29593Some extra data, the exact contents of which are type-dependent.
29594
b4be1b06
SM
29595@item locations
29596This field is present if the breakpoint has multiple locations. It is also
29597exceptionally present if the breakpoint is enabled and has a single, disabled
29598location.
29599
6b92c0d3 29600The value is a list of locations. The format of a location is described below.
b4be1b06
SM
29601
29602@end table
29603
29604A location in a multi-location breakpoint is represented as a tuple with the
29605following fields:
29606
29607@table @code
29608
29609@item number
29610The location number as a dotted pair, like @samp{1.2}. The first digit is the
29611number of the parent breakpoint. The second digit is the number of the
29612location within that breakpoint.
29613
29614@item enabled
29615This indicates whether the location is enabled, in which case the
29616value is @samp{y}, or disabled, in which case the value is @samp{n}.
29617Note that this is not the same as the field @code{enable}.
29618
29619@item addr
29620The address of this location as an hexidecimal number.
29621
aa7ca1bb
AH
29622@item addr_flags
29623Optional field containing any flags related to the address. These flags are
29624architecture-dependent; see @ref{Architectures} for their meaning for a
29625particular CPU.
29626
b4be1b06
SM
29627@item func
29628If known, the function in which the location appears.
29629If not known, this field is not present.
29630
29631@item file
29632The name of the source file which contains this location, if known.
29633If not known, this field is not present.
29634
29635@item fullname
29636The full file name of the source file which contains this location, if
29637known. If not known, this field is not present.
29638
29639@item line
29640The line number at which this location appears, if known.
29641If not known, this field is not present.
29642
29643@item thread-groups
29644The thread groups this location is in.
29645
54516a0b
TT
29646@end table
29647
29648For example, here is what the output of @code{-break-insert}
29649(@pxref{GDB/MI Breakpoint Commands}) might be:
29650
29651@smallexample
29652-> -break-insert main
29653<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29654 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
29655 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29656 times="0"@}
54516a0b
TT
29657<- (gdb)
29658@end smallexample
29659
c3b108f7
VP
29660@node GDB/MI Frame Information
29661@subsection @sc{gdb/mi} Frame Information
29662
29663Response from many MI commands includes an information about stack
29664frame. This information is a tuple that may have the following
29665fields:
29666
29667@table @code
29668@item level
29669The level of the stack frame. The innermost frame has the level of
29670zero. This field is always present.
29671
29672@item func
29673The name of the function corresponding to the frame. This field may
29674be absent if @value{GDBN} is unable to determine the function name.
29675
29676@item addr
29677The code address for the frame. This field is always present.
29678
aa7ca1bb
AH
29679@item addr_flags
29680Optional field containing any flags related to the address. These flags are
29681architecture-dependent; see @ref{Architectures} for their meaning for a
29682particular CPU.
29683
c3b108f7
VP
29684@item file
29685The name of the source files that correspond to the frame's code
29686address. This field may be absent.
29687
29688@item line
29689The source line corresponding to the frames' code address. This field
29690may be absent.
29691
29692@item from
29693The name of the binary file (either executable or shared library) the
29694corresponds to the frame's code address. This field may be absent.
29695
29696@end table
82f68b1c 29697
dc146f7c
VP
29698@node GDB/MI Thread Information
29699@subsection @sc{gdb/mi} Thread Information
29700
29701Whenever @value{GDBN} has to report an information about a thread, it
ebe553db
SM
29702uses a tuple with the following fields. The fields are always present unless
29703stated otherwise.
dc146f7c
VP
29704
29705@table @code
29706@item id
ebe553db 29707The global numeric id assigned to the thread by @value{GDBN}.
dc146f7c
VP
29708
29709@item target-id
ebe553db 29710The target-specific string identifying the thread.
dc146f7c
VP
29711
29712@item details
29713Additional information about the thread provided by the target.
29714It is supposed to be human-readable and not interpreted by the
29715frontend. This field is optional.
29716
ebe553db
SM
29717@item name
29718The name of the thread. If the user specified a name using the
29719@code{thread name} command, then this name is given. Otherwise, if
29720@value{GDBN} can extract the thread name from the target, then that
29721name is given. If @value{GDBN} cannot find the thread name, then this
29722field is omitted.
29723
dc146f7c 29724@item state
ebe553db
SM
29725The execution state of the thread, either @samp{stopped} or @samp{running},
29726depending on whether the thread is presently running.
29727
29728@item frame
29729The stack frame currently executing in the thread. This field is only present
29730if the thread is stopped. Its format is documented in
29731@ref{GDB/MI Frame Information}.
dc146f7c
VP
29732
29733@item core
29734The value of this field is an integer number of the processor core the
29735thread was last seen on. This field is optional.
29736@end table
29737
956a9fb9
JB
29738@node GDB/MI Ada Exception Information
29739@subsection @sc{gdb/mi} Ada Exception Information
29740
29741Whenever a @code{*stopped} record is emitted because the program
29742stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
29743@value{GDBN} provides the name of the exception that was raised via
e547c119
JB
29744the @code{exception-name} field. Also, for exceptions that were raised
29745with an exception message, @value{GDBN} provides that message via
29746the @code{exception-message} field.
922fbb7b 29747
ef21caaf
NR
29748@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29749@node GDB/MI Simple Examples
29750@section Simple Examples of @sc{gdb/mi} Interaction
29751@cindex @sc{gdb/mi}, simple examples
29752
29753This subsection presents several simple examples of interaction using
29754the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
29755following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
29756the output received from @sc{gdb/mi}.
29757
d3e8051b 29758Note the line breaks shown in the examples are here only for
ef21caaf
NR
29759readability, they don't appear in the real output.
29760
79a6e687 29761@subheading Setting a Breakpoint
ef21caaf
NR
29762
29763Setting a breakpoint generates synchronous output which contains detailed
29764information of the breakpoint.
29765
29766@smallexample
29767-> -break-insert main
29768<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29769 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
29770 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29771 times="0"@}
ef21caaf
NR
29772<- (gdb)
29773@end smallexample
29774
29775@subheading Program Execution
29776
29777Program execution generates asynchronous records and MI gives the
29778reason that execution stopped.
29779
29780@smallexample
29781-> -exec-run
29782<- ^running
29783<- (gdb)
a47ec5fe 29784<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
ef21caaf
NR
29785 frame=@{addr="0x08048564",func="main",
29786 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
6d52907e
JV
29787 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
29788 arch="i386:x86_64"@}
ef21caaf
NR
29789<- (gdb)
29790-> -exec-continue
29791<- ^running
29792<- (gdb)
29793<- *stopped,reason="exited-normally"
29794<- (gdb)
29795@end smallexample
29796
3f94c067 29797@subheading Quitting @value{GDBN}
ef21caaf 29798
3f94c067 29799Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
29800
29801@smallexample
29802-> (gdb)
29803<- -gdb-exit
29804<- ^exit
29805@end smallexample
29806
a6b29f87
VP
29807Please note that @samp{^exit} is printed immediately, but it might
29808take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
29809performs necessary cleanups, including killing programs being debugged
29810or disconnecting from debug hardware, so the frontend should wait till
29811@value{GDBN} exits and should only forcibly kill @value{GDBN} if it
29812fails to exit in reasonable time.
29813
a2c02241 29814@subheading A Bad Command
ef21caaf
NR
29815
29816Here's what happens if you pass a non-existent command:
29817
29818@smallexample
29819-> -rubbish
29820<- ^error,msg="Undefined MI command: rubbish"
594fe323 29821<- (gdb)
ef21caaf
NR
29822@end smallexample
29823
29824
922fbb7b
AC
29825@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29826@node GDB/MI Command Description Format
29827@section @sc{gdb/mi} Command Description Format
29828
29829The remaining sections describe blocks of commands. Each block of
29830commands is laid out in a fashion similar to this section.
29831
922fbb7b
AC
29832@subheading Motivation
29833
29834The motivation for this collection of commands.
29835
29836@subheading Introduction
29837
29838A brief introduction to this collection of commands as a whole.
29839
29840@subheading Commands
29841
29842For each command in the block, the following is described:
29843
29844@subsubheading Synopsis
29845
29846@smallexample
29847 -command @var{args}@dots{}
29848@end smallexample
29849
922fbb7b
AC
29850@subsubheading Result
29851
265eeb58 29852@subsubheading @value{GDBN} Command
922fbb7b 29853
265eeb58 29854The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
29855
29856@subsubheading Example
29857
ef21caaf
NR
29858Example(s) formatted for readability. Some of the described commands have
29859not been implemented yet and these are labeled N.A.@: (not available).
29860
29861
922fbb7b 29862@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
29863@node GDB/MI Breakpoint Commands
29864@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
29865
29866@cindex breakpoint commands for @sc{gdb/mi}
29867@cindex @sc{gdb/mi}, breakpoint commands
29868This section documents @sc{gdb/mi} commands for manipulating
29869breakpoints.
29870
29871@subheading The @code{-break-after} Command
29872@findex -break-after
29873
29874@subsubheading Synopsis
29875
29876@smallexample
29877 -break-after @var{number} @var{count}
29878@end smallexample
29879
29880The breakpoint number @var{number} is not in effect until it has been
29881hit @var{count} times. To see how this is reflected in the output of
29882the @samp{-break-list} command, see the description of the
29883@samp{-break-list} command below.
29884
29885@subsubheading @value{GDBN} Command
29886
29887The corresponding @value{GDBN} command is @samp{ignore}.
29888
29889@subsubheading Example
29890
29891@smallexample
594fe323 29892(gdb)
922fbb7b 29893-break-insert main
a47ec5fe
AR
29894^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29895enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
29896fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29897times="0"@}
594fe323 29898(gdb)
922fbb7b
AC
29899-break-after 1 3
29900~
29901^done
594fe323 29902(gdb)
922fbb7b
AC
29903-break-list
29904^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29905hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29906@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29907@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29908@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29909@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29910@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29911body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 29912addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 29913line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 29914(gdb)
922fbb7b
AC
29915@end smallexample
29916
29917@ignore
29918@subheading The @code{-break-catch} Command
29919@findex -break-catch
48cb2d85 29920@end ignore
922fbb7b
AC
29921
29922@subheading The @code{-break-commands} Command
29923@findex -break-commands
922fbb7b 29924
48cb2d85
VP
29925@subsubheading Synopsis
29926
29927@smallexample
29928 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
29929@end smallexample
29930
29931Specifies the CLI commands that should be executed when breakpoint
29932@var{number} is hit. The parameters @var{command1} to @var{commandN}
29933are the commands. If no command is specified, any previously-set
29934commands are cleared. @xref{Break Commands}. Typical use of this
29935functionality is tracing a program, that is, printing of values of
29936some variables whenever breakpoint is hit and then continuing.
29937
29938@subsubheading @value{GDBN} Command
29939
29940The corresponding @value{GDBN} command is @samp{commands}.
29941
29942@subsubheading Example
29943
29944@smallexample
29945(gdb)
29946-break-insert main
29947^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29948enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
29949fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29950times="0"@}
48cb2d85
VP
29951(gdb)
29952-break-commands 1 "print v" "continue"
29953^done
29954(gdb)
29955@end smallexample
922fbb7b
AC
29956
29957@subheading The @code{-break-condition} Command
29958@findex -break-condition
29959
29960@subsubheading Synopsis
29961
29962@smallexample
29963 -break-condition @var{number} @var{expr}
29964@end smallexample
29965
29966Breakpoint @var{number} will stop the program only if the condition in
29967@var{expr} is true. The condition becomes part of the
29968@samp{-break-list} output (see the description of the @samp{-break-list}
29969command below).
29970
29971@subsubheading @value{GDBN} Command
29972
29973The corresponding @value{GDBN} command is @samp{condition}.
29974
29975@subsubheading Example
29976
29977@smallexample
594fe323 29978(gdb)
922fbb7b
AC
29979-break-condition 1 1
29980^done
594fe323 29981(gdb)
922fbb7b
AC
29982-break-list
29983^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29984hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29985@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29986@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29987@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29988@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29989@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29990body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 29991addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 29992line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 29993(gdb)
922fbb7b
AC
29994@end smallexample
29995
29996@subheading The @code{-break-delete} Command
29997@findex -break-delete
29998
29999@subsubheading Synopsis
30000
30001@smallexample
30002 -break-delete ( @var{breakpoint} )+
30003@end smallexample
30004
30005Delete the breakpoint(s) whose number(s) are specified in the argument
30006list. This is obviously reflected in the breakpoint list.
30007
79a6e687 30008@subsubheading @value{GDBN} Command
922fbb7b
AC
30009
30010The corresponding @value{GDBN} command is @samp{delete}.
30011
30012@subsubheading Example
30013
30014@smallexample
594fe323 30015(gdb)
922fbb7b
AC
30016-break-delete 1
30017^done
594fe323 30018(gdb)
922fbb7b
AC
30019-break-list
30020^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30021hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30022@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30023@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30024@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30025@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30026@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30027body=[]@}
594fe323 30028(gdb)
922fbb7b
AC
30029@end smallexample
30030
30031@subheading The @code{-break-disable} Command
30032@findex -break-disable
30033
30034@subsubheading Synopsis
30035
30036@smallexample
30037 -break-disable ( @var{breakpoint} )+
30038@end smallexample
30039
30040Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
30041break list is now set to @samp{n} for the named @var{breakpoint}(s).
30042
30043@subsubheading @value{GDBN} Command
30044
30045The corresponding @value{GDBN} command is @samp{disable}.
30046
30047@subsubheading Example
30048
30049@smallexample
594fe323 30050(gdb)
922fbb7b
AC
30051-break-disable 2
30052^done
594fe323 30053(gdb)
922fbb7b
AC
30054-break-list
30055^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30056hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30057@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30058@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30059@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30060@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30061@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30062body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102 30063addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30064line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 30065(gdb)
922fbb7b
AC
30066@end smallexample
30067
30068@subheading The @code{-break-enable} Command
30069@findex -break-enable
30070
30071@subsubheading Synopsis
30072
30073@smallexample
30074 -break-enable ( @var{breakpoint} )+
30075@end smallexample
30076
30077Enable (previously disabled) @var{breakpoint}(s).
30078
30079@subsubheading @value{GDBN} Command
30080
30081The corresponding @value{GDBN} command is @samp{enable}.
30082
30083@subsubheading Example
30084
30085@smallexample
594fe323 30086(gdb)
922fbb7b
AC
30087-break-enable 2
30088^done
594fe323 30089(gdb)
922fbb7b
AC
30090-break-list
30091^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30092hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30093@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30094@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30095@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30096@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30097@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30098body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 30099addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30100line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 30101(gdb)
922fbb7b
AC
30102@end smallexample
30103
30104@subheading The @code{-break-info} Command
30105@findex -break-info
30106
30107@subsubheading Synopsis
30108
30109@smallexample
30110 -break-info @var{breakpoint}
30111@end smallexample
30112
30113@c REDUNDANT???
30114Get information about a single breakpoint.
30115
54516a0b
TT
30116The result is a table of breakpoints. @xref{GDB/MI Breakpoint
30117Information}, for details on the format of each breakpoint in the
30118table.
30119
79a6e687 30120@subsubheading @value{GDBN} Command
922fbb7b
AC
30121
30122The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
30123
30124@subsubheading Example
30125N.A.
30126
30127@subheading The @code{-break-insert} Command
30128@findex -break-insert
629500fa 30129@anchor{-break-insert}
922fbb7b
AC
30130
30131@subsubheading Synopsis
30132
30133@smallexample
18148017 30134 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
922fbb7b 30135 [ -c @var{condition} ] [ -i @var{ignore-count} ]
472a2379 30136 [ -p @var{thread-id} ] [ @var{location} ]
922fbb7b
AC
30137@end smallexample
30138
30139@noindent
afe8ab22 30140If specified, @var{location}, can be one of:
922fbb7b 30141
629500fa
KS
30142@table @var
30143@item linespec location
30144A linespec location. @xref{Linespec Locations}.
30145
30146@item explicit location
30147An explicit location. @sc{gdb/mi} explicit locations are
30148analogous to the CLI's explicit locations using the option names
30149listed below. @xref{Explicit Locations}.
30150
30151@table @samp
30152@item --source @var{filename}
30153The source file name of the location. This option requires the use
30154of either @samp{--function} or @samp{--line}.
30155
30156@item --function @var{function}
30157The name of a function or method.
922fbb7b 30158
629500fa
KS
30159@item --label @var{label}
30160The name of a label.
30161
30162@item --line @var{lineoffset}
30163An absolute or relative line offset from the start of the location.
30164@end table
30165
30166@item address location
30167An address location, *@var{address}. @xref{Address Locations}.
30168@end table
30169
30170@noindent
922fbb7b
AC
30171The possible optional parameters of this command are:
30172
30173@table @samp
30174@item -t
948d5102 30175Insert a temporary breakpoint.
922fbb7b
AC
30176@item -h
30177Insert a hardware breakpoint.
afe8ab22
VP
30178@item -f
30179If @var{location} cannot be parsed (for example if it
30180refers to unknown files or functions), create a pending
30181breakpoint. Without this flag, @value{GDBN} will report
30182an error, and won't create a breakpoint, if @var{location}
30183cannot be parsed.
41447f92
VP
30184@item -d
30185Create a disabled breakpoint.
18148017
VP
30186@item -a
30187Create a tracepoint. @xref{Tracepoints}. When this parameter
30188is used together with @samp{-h}, a fast tracepoint is created.
472a2379
KS
30189@item -c @var{condition}
30190Make the breakpoint conditional on @var{condition}.
30191@item -i @var{ignore-count}
30192Initialize the @var{ignore-count}.
30193@item -p @var{thread-id}
5d5658a1
PA
30194Restrict the breakpoint to the thread with the specified global
30195@var{thread-id}.
922fbb7b
AC
30196@end table
30197
30198@subsubheading Result
30199
54516a0b
TT
30200@xref{GDB/MI Breakpoint Information}, for details on the format of the
30201resulting breakpoint.
922fbb7b
AC
30202
30203Note: this format is open to change.
30204@c An out-of-band breakpoint instead of part of the result?
30205
30206@subsubheading @value{GDBN} Command
30207
30208The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
496ee73e 30209@samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
922fbb7b
AC
30210
30211@subsubheading Example
30212
30213@smallexample
594fe323 30214(gdb)
922fbb7b 30215-break-insert main
948d5102 30216^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
998580f1
MK
30217fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
30218times="0"@}
594fe323 30219(gdb)
922fbb7b 30220-break-insert -t foo
948d5102 30221^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
998580f1
MK
30222fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
30223times="0"@}
594fe323 30224(gdb)
922fbb7b
AC
30225-break-list
30226^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30227hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30228@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30229@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30230@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30231@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30232@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30233body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 30234addr="0x0001072c", func="main",file="recursive2.c",
998580f1
MK
30235fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
30236times="0"@},
922fbb7b 30237bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102 30238addr="0x00010774",func="foo",file="recursive2.c",
998580f1
MK
30239fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30240times="0"@}]@}
594fe323 30241(gdb)
496ee73e
KS
30242@c -break-insert -r foo.*
30243@c ~int foo(int, int);
30244@c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
998580f1
MK
30245@c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30246@c times="0"@}
496ee73e 30247@c (gdb)
922fbb7b
AC
30248@end smallexample
30249
c5867ab6
HZ
30250@subheading The @code{-dprintf-insert} Command
30251@findex -dprintf-insert
30252
30253@subsubheading Synopsis
30254
30255@smallexample
30256 -dprintf-insert [ -t ] [ -f ] [ -d ]
30257 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30258 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
30259 [ @var{argument} ]
30260@end smallexample
30261
30262@noindent
629500fa
KS
30263If supplied, @var{location} may be specified the same way as for
30264the @code{-break-insert} command. @xref{-break-insert}.
c5867ab6
HZ
30265
30266The possible optional parameters of this command are:
30267
30268@table @samp
30269@item -t
30270Insert a temporary breakpoint.
30271@item -f
30272If @var{location} cannot be parsed (for example, if it
30273refers to unknown files or functions), create a pending
30274breakpoint. Without this flag, @value{GDBN} will report
30275an error, and won't create a breakpoint, if @var{location}
30276cannot be parsed.
30277@item -d
30278Create a disabled breakpoint.
30279@item -c @var{condition}
30280Make the breakpoint conditional on @var{condition}.
30281@item -i @var{ignore-count}
30282Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
30283to @var{ignore-count}.
30284@item -p @var{thread-id}
5d5658a1
PA
30285Restrict the breakpoint to the thread with the specified global
30286@var{thread-id}.
c5867ab6
HZ
30287@end table
30288
30289@subsubheading Result
30290
30291@xref{GDB/MI Breakpoint Information}, for details on the format of the
30292resulting breakpoint.
30293
30294@c An out-of-band breakpoint instead of part of the result?
30295
30296@subsubheading @value{GDBN} Command
30297
30298The corresponding @value{GDBN} command is @samp{dprintf}.
30299
30300@subsubheading Example
30301
30302@smallexample
30303(gdb)
303044-dprintf-insert foo "At foo entry\n"
303054^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
30306addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
30307fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
30308times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
30309original-location="foo"@}
30310(gdb)
303115-dprintf-insert 26 "arg=%d, g=%d\n" arg g
303125^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
30313addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
30314fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
30315times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
30316original-location="mi-dprintf.c:26"@}
30317(gdb)
30318@end smallexample
30319
922fbb7b
AC
30320@subheading The @code{-break-list} Command
30321@findex -break-list
30322
30323@subsubheading Synopsis
30324
30325@smallexample
30326 -break-list
30327@end smallexample
30328
30329Displays the list of inserted breakpoints, showing the following fields:
30330
30331@table @samp
30332@item Number
30333number of the breakpoint
30334@item Type
30335type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
30336@item Disposition
30337should the breakpoint be deleted or disabled when it is hit: @samp{keep}
30338or @samp{nokeep}
30339@item Enabled
30340is the breakpoint enabled or no: @samp{y} or @samp{n}
30341@item Address
30342memory location at which the breakpoint is set
30343@item What
30344logical location of the breakpoint, expressed by function name, file
30345name, line number
998580f1
MK
30346@item Thread-groups
30347list of thread groups to which this breakpoint applies
922fbb7b
AC
30348@item Times
30349number of times the breakpoint has been hit
30350@end table
30351
30352If there are no breakpoints or watchpoints, the @code{BreakpointTable}
30353@code{body} field is an empty list.
30354
30355@subsubheading @value{GDBN} Command
30356
30357The corresponding @value{GDBN} command is @samp{info break}.
30358
30359@subsubheading Example
30360
30361@smallexample
594fe323 30362(gdb)
922fbb7b
AC
30363-break-list
30364^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30365hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30366@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30367@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30368@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30369@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30370@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30371body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
998580f1
MK
30372addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
30373times="0"@},
922fbb7b 30374bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 30375addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30376line="13",thread-groups=["i1"],times="0"@}]@}
594fe323 30377(gdb)
922fbb7b
AC
30378@end smallexample
30379
30380Here's an example of the result when there are no breakpoints:
30381
30382@smallexample
594fe323 30383(gdb)
922fbb7b
AC
30384-break-list
30385^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30386hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30387@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30388@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30389@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30390@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30391@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30392body=[]@}
594fe323 30393(gdb)
922fbb7b
AC
30394@end smallexample
30395
18148017
VP
30396@subheading The @code{-break-passcount} Command
30397@findex -break-passcount
30398
30399@subsubheading Synopsis
30400
30401@smallexample
30402 -break-passcount @var{tracepoint-number} @var{passcount}
30403@end smallexample
30404
30405Set the passcount for tracepoint @var{tracepoint-number} to
30406@var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
30407is not a tracepoint, error is emitted. This corresponds to CLI
30408command @samp{passcount}.
30409
922fbb7b
AC
30410@subheading The @code{-break-watch} Command
30411@findex -break-watch
30412
30413@subsubheading Synopsis
30414
30415@smallexample
30416 -break-watch [ -a | -r ]
30417@end smallexample
30418
30419Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 30420@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 30421read from or on a write to the memory location. With the @samp{-r}
d3e8051b 30422option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
30423trigger only when the memory location is accessed for reading. Without
30424either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 30425i.e., it will trigger when the memory location is accessed for writing.
79a6e687 30426@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
30427
30428Note that @samp{-break-list} will report a single list of watchpoints and
30429breakpoints inserted.
30430
30431@subsubheading @value{GDBN} Command
30432
30433The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
30434@samp{rwatch}.
30435
30436@subsubheading Example
30437
30438Setting a watchpoint on a variable in the @code{main} function:
30439
30440@smallexample
594fe323 30441(gdb)
922fbb7b
AC
30442-break-watch x
30443^done,wpt=@{number="2",exp="x"@}
594fe323 30444(gdb)
922fbb7b
AC
30445-exec-continue
30446^running
0869d01b
NR
30447(gdb)
30448*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 30449value=@{old="-268439212",new="55"@},
76ff342d 30450frame=@{func="main",args=[],file="recursive2.c",
6d52907e 30451fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
594fe323 30452(gdb)
922fbb7b
AC
30453@end smallexample
30454
30455Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
30456the program execution twice: first for the variable changing value, then
30457for the watchpoint going out of scope.
30458
30459@smallexample
594fe323 30460(gdb)
922fbb7b
AC
30461-break-watch C
30462^done,wpt=@{number="5",exp="C"@}
594fe323 30463(gdb)
922fbb7b
AC
30464-exec-continue
30465^running
0869d01b
NR
30466(gdb)
30467*stopped,reason="watchpoint-trigger",
922fbb7b
AC
30468wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
30469frame=@{func="callee4",args=[],
76ff342d 30470file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30471fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30472arch="i386:x86_64"@}
594fe323 30473(gdb)
922fbb7b
AC
30474-exec-continue
30475^running
0869d01b
NR
30476(gdb)
30477*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
30478frame=@{func="callee3",args=[@{name="strarg",
30479value="0x11940 \"A string argument.\""@}],
76ff342d 30480file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30481fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30482arch="i386:x86_64"@}
594fe323 30483(gdb)
922fbb7b
AC
30484@end smallexample
30485
30486Listing breakpoints and watchpoints, at different points in the program
30487execution. Note that once the watchpoint goes out of scope, it is
30488deleted.
30489
30490@smallexample
594fe323 30491(gdb)
922fbb7b
AC
30492-break-watch C
30493^done,wpt=@{number="2",exp="C"@}
594fe323 30494(gdb)
922fbb7b
AC
30495-break-list
30496^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30497hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30498@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30499@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30500@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30501@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30502@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30503body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30504addr="0x00010734",func="callee4",
948d5102 30505file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
30506fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
30507times="1"@},
922fbb7b 30508bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 30509enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
594fe323 30510(gdb)
922fbb7b
AC
30511-exec-continue
30512^running
0869d01b
NR
30513(gdb)
30514*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
30515value=@{old="-276895068",new="3"@},
30516frame=@{func="callee4",args=[],
76ff342d 30517file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30518fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30519arch="i386:x86_64"@}
594fe323 30520(gdb)
922fbb7b
AC
30521-break-list
30522^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30523hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30524@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30525@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30526@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30527@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30528@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30529body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30530addr="0x00010734",func="callee4",
948d5102 30531file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
30532fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
30533times="1"@},
922fbb7b 30534bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 30535enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
594fe323 30536(gdb)
922fbb7b
AC
30537-exec-continue
30538^running
30539^done,reason="watchpoint-scope",wpnum="2",
30540frame=@{func="callee3",args=[@{name="strarg",
30541value="0x11940 \"A string argument.\""@}],
76ff342d 30542file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30543fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30544arch="i386:x86_64"@}
594fe323 30545(gdb)
922fbb7b
AC
30546-break-list
30547^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30548hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30549@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30550@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30551@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30552@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30553@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30554body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30555addr="0x00010734",func="callee4",
948d5102
NR
30556file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30557fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
998580f1 30558thread-groups=["i1"],times="1"@}]@}
594fe323 30559(gdb)
922fbb7b
AC
30560@end smallexample
30561
3fa7bf06
MG
30562
30563@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30564@node GDB/MI Catchpoint Commands
30565@section @sc{gdb/mi} Catchpoint Commands
30566
30567This section documents @sc{gdb/mi} commands for manipulating
30568catchpoints.
30569
40555925
JB
30570@menu
30571* Shared Library GDB/MI Catchpoint Commands::
30572* Ada Exception GDB/MI Catchpoint Commands::
30056ea0 30573* C++ Exception GDB/MI Catchpoint Commands::
40555925
JB
30574@end menu
30575
30576@node Shared Library GDB/MI Catchpoint Commands
30577@subsection Shared Library @sc{gdb/mi} Catchpoints
30578
3fa7bf06
MG
30579@subheading The @code{-catch-load} Command
30580@findex -catch-load
30581
30582@subsubheading Synopsis
30583
30584@smallexample
30585 -catch-load [ -t ] [ -d ] @var{regexp}
30586@end smallexample
30587
30588Add a catchpoint for library load events. If the @samp{-t} option is used,
30589the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30590Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
30591in a disabled state. The @samp{regexp} argument is a regular
30592expression used to match the name of the loaded library.
30593
30594
30595@subsubheading @value{GDBN} Command
30596
30597The corresponding @value{GDBN} command is @samp{catch load}.
30598
30599@subsubheading Example
30600
30601@smallexample
30602-catch-load -t foo.so
30603^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
8ac3646f 30604what="load of library matching foo.so",catch-type="load",times="0"@}
3fa7bf06
MG
30605(gdb)
30606@end smallexample
30607
30608
30609@subheading The @code{-catch-unload} Command
30610@findex -catch-unload
30611
30612@subsubheading Synopsis
30613
30614@smallexample
30615 -catch-unload [ -t ] [ -d ] @var{regexp}
30616@end smallexample
30617
30618Add a catchpoint for library unload events. If the @samp{-t} option is
30619used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30620Breakpoints}). If the @samp{-d} option is used, the catchpoint is
30621created in a disabled state. The @samp{regexp} argument is a regular
30622expression used to match the name of the unloaded library.
30623
30624@subsubheading @value{GDBN} Command
30625
30626The corresponding @value{GDBN} command is @samp{catch unload}.
30627
30628@subsubheading Example
30629
30630@smallexample
30631-catch-unload -d bar.so
30632^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
8ac3646f 30633what="load of library matching bar.so",catch-type="unload",times="0"@}
3fa7bf06
MG
30634(gdb)
30635@end smallexample
30636
40555925
JB
30637@node Ada Exception GDB/MI Catchpoint Commands
30638@subsection Ada Exception @sc{gdb/mi} Catchpoints
30639
30640The following @sc{gdb/mi} commands can be used to create catchpoints
30641that stop the execution when Ada exceptions are being raised.
30642
30643@subheading The @code{-catch-assert} Command
30644@findex -catch-assert
30645
30646@subsubheading Synopsis
30647
30648@smallexample
30649 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
30650@end smallexample
30651
30652Add a catchpoint for failed Ada assertions.
30653
30654The possible optional parameters for this command are:
30655
30656@table @samp
30657@item -c @var{condition}
30658Make the catchpoint conditional on @var{condition}.
30659@item -d
30660Create a disabled catchpoint.
30661@item -t
30662Create a temporary catchpoint.
30663@end table
30664
30665@subsubheading @value{GDBN} Command
30666
30667The corresponding @value{GDBN} command is @samp{catch assert}.
30668
30669@subsubheading Example
30670
30671@smallexample
30672-catch-assert
30673^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
30674enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
30675thread-groups=["i1"],times="0",
30676original-location="__gnat_debug_raise_assert_failure"@}
30677(gdb)
30678@end smallexample
30679
30680@subheading The @code{-catch-exception} Command
30681@findex -catch-exception
30682
30683@subsubheading Synopsis
30684
30685@smallexample
30686 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30687 [ -t ] [ -u ]
30688@end smallexample
30689
30690Add a catchpoint stopping when Ada exceptions are raised.
30691By default, the command stops the program when any Ada exception
30692gets raised. But it is also possible, by using some of the
30693optional parameters described below, to create more selective
30694catchpoints.
30695
30696The possible optional parameters for this command are:
30697
30698@table @samp
30699@item -c @var{condition}
30700Make the catchpoint conditional on @var{condition}.
30701@item -d
30702Create a disabled catchpoint.
30703@item -e @var{exception-name}
30704Only stop when @var{exception-name} is raised. This option cannot
30705be used combined with @samp{-u}.
30706@item -t
30707Create a temporary catchpoint.
30708@item -u
30709Stop only when an unhandled exception gets raised. This option
30710cannot be used combined with @samp{-e}.
30711@end table
30712
30713@subsubheading @value{GDBN} Command
30714
30715The corresponding @value{GDBN} commands are @samp{catch exception}
30716and @samp{catch exception unhandled}.
30717
30718@subsubheading Example
30719
30720@smallexample
30721-catch-exception -e Program_Error
30722^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30723enabled="y",addr="0x0000000000404874",
30724what="`Program_Error' Ada exception", thread-groups=["i1"],
30725times="0",original-location="__gnat_debug_raise_exception"@}
30726(gdb)
30727@end smallexample
3fa7bf06 30728
bea298f9
XR
30729@subheading The @code{-catch-handlers} Command
30730@findex -catch-handlers
30731
30732@subsubheading Synopsis
30733
30734@smallexample
30735 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30736 [ -t ]
30737@end smallexample
30738
30739Add a catchpoint stopping when Ada exceptions are handled.
30740By default, the command stops the program when any Ada exception
30741gets handled. But it is also possible, by using some of the
30742optional parameters described below, to create more selective
30743catchpoints.
30744
30745The possible optional parameters for this command are:
30746
30747@table @samp
30748@item -c @var{condition}
30749Make the catchpoint conditional on @var{condition}.
30750@item -d
30751Create a disabled catchpoint.
30752@item -e @var{exception-name}
30753Only stop when @var{exception-name} is handled.
30754@item -t
30755Create a temporary catchpoint.
30756@end table
30757
30758@subsubheading @value{GDBN} Command
30759
30760The corresponding @value{GDBN} command is @samp{catch handlers}.
30761
30762@subsubheading Example
30763
30764@smallexample
30765-catch-handlers -e Constraint_Error
30766^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30767enabled="y",addr="0x0000000000402f68",
30768what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
30769times="0",original-location="__gnat_begin_handler"@}
30770(gdb)
30771@end smallexample
30772
30056ea0
AB
30773@node C++ Exception GDB/MI Catchpoint Commands
30774@subsection C@t{++} Exception @sc{gdb/mi} Catchpoints
30775
30776The following @sc{gdb/mi} commands can be used to create catchpoints
30777that stop the execution when C@t{++} exceptions are being throw, rethrown,
30778or caught.
30779
30780@subheading The @code{-catch-throw} Command
30781@findex -catch-throw
30782
30783@subsubheading Synopsis
30784
30785@smallexample
30786 -catch-throw [ -t ] [ -r @var{regexp}]
30787@end smallexample
30788
30789Stop when the debuggee throws a C@t{++} exception. If @var{regexp} is
30790given, then only exceptions whose type matches the regular expression
30791will be caught.
30792
30793If @samp{-t} is given, then the catchpoint is enabled only for one
30794stop, the catchpoint is automatically deleted after stopping once for
30795the event.
30796
30797@subsubheading @value{GDBN} Command
30798
30799The corresponding @value{GDBN} commands are @samp{catch throw}
30800and @samp{tcatch throw} (@pxref{Set Catchpoints}).
30801
30802@subsubheading Example
30803
30804@smallexample
30805-catch-throw -r exception_type
cb1e4e32
PA
30806^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30807 what="exception throw",catch-type="throw",
30808 thread-groups=["i1"],
30056ea0
AB
30809 regexp="exception_type",times="0"@}
30810(gdb)
30811-exec-run
30812^running
30813(gdb)
30814~"\n"
30815~"Catchpoint 1 (exception thrown), 0x00007ffff7ae00ed
30816 in __cxa_throw () from /lib64/libstdc++.so.6\n"
30817*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30818 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_throw",
30819 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30820 thread-id="1",stopped-threads="all",core="6"
30821(gdb)
30822@end smallexample
30823
30824@subheading The @code{-catch-rethrow} Command
30825@findex -catch-rethrow
30826
30827@subsubheading Synopsis
30828
30829@smallexample
30830 -catch-rethrow [ -t ] [ -r @var{regexp}]
30831@end smallexample
30832
30833Stop when a C@t{++} exception is re-thrown. If @var{regexp} is given,
30834then only exceptions whose type matches the regular expression will be
30835caught.
30836
30837If @samp{-t} is given, then the catchpoint is enabled only for one
30838stop, the catchpoint is automatically deleted after the first event is
30839caught.
30840
30841@subsubheading @value{GDBN} Command
30842
30843The corresponding @value{GDBN} commands are @samp{catch rethrow}
30844and @samp{tcatch rethrow} (@pxref{Set Catchpoints}).
30845
30846@subsubheading Example
30847
30848@smallexample
30849-catch-rethrow -r exception_type
cb1e4e32
PA
30850^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30851 what="exception rethrow",catch-type="rethrow",
30852 thread-groups=["i1"],
30056ea0
AB
30853 regexp="exception_type",times="0"@}
30854(gdb)
30855-exec-run
30856^running
30857(gdb)
30858~"\n"
30859~"Catchpoint 1 (exception rethrown), 0x00007ffff7ae00ed
30860 in __cxa_rethrow () from /lib64/libstdc++.so.6\n"
30861*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30862 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_rethrow",
30863 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30864 thread-id="1",stopped-threads="all",core="6"
30865(gdb)
30866@end smallexample
30867
30868@subheading The @code{-catch-catch} Command
30869@findex -catch-catch
30870
30871@subsubheading Synopsis
30872
30873@smallexample
30874 -catch-catch [ -t ] [ -r @var{regexp}]
30875@end smallexample
30876
30877Stop when the debuggee catches a C@t{++} exception. If @var{regexp}
30878is given, then only exceptions whose type matches the regular
30879expression will be caught.
30880
30881If @samp{-t} is given, then the catchpoint is enabled only for one
30882stop, the catchpoint is automatically deleted after the first event is
30883caught.
30884
30885@subsubheading @value{GDBN} Command
30886
30887The corresponding @value{GDBN} commands are @samp{catch catch}
30888and @samp{tcatch catch} (@pxref{Set Catchpoints}).
30889
30890@subsubheading Example
30891
30892@smallexample
30893-catch-catch -r exception_type
cb1e4e32
PA
30894^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30895 what="exception catch",catch-type="catch",
30896 thread-groups=["i1"],
30056ea0
AB
30897 regexp="exception_type",times="0"@}
30898(gdb)
30899-exec-run
30900^running
30901(gdb)
30902~"\n"
30903~"Catchpoint 1 (exception caught), 0x00007ffff7ae00ed
30904 in __cxa_begin_catch () from /lib64/libstdc++.so.6\n"
30905*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30906 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_begin_catch",
30907 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30908 thread-id="1",stopped-threads="all",core="6"
30909(gdb)
30910@end smallexample
30911
922fbb7b 30912@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
30913@node GDB/MI Program Context
30914@section @sc{gdb/mi} Program Context
922fbb7b 30915
a2c02241
NR
30916@subheading The @code{-exec-arguments} Command
30917@findex -exec-arguments
922fbb7b 30918
922fbb7b
AC
30919
30920@subsubheading Synopsis
30921
30922@smallexample
a2c02241 30923 -exec-arguments @var{args}
922fbb7b
AC
30924@end smallexample
30925
a2c02241
NR
30926Set the inferior program arguments, to be used in the next
30927@samp{-exec-run}.
922fbb7b 30928
a2c02241 30929@subsubheading @value{GDBN} Command
922fbb7b 30930
a2c02241 30931The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 30932
a2c02241 30933@subsubheading Example
922fbb7b 30934
fbc5282e
MK
30935@smallexample
30936(gdb)
30937-exec-arguments -v word
30938^done
30939(gdb)
30940@end smallexample
922fbb7b 30941
a2c02241 30942
9901a55b 30943@ignore
a2c02241
NR
30944@subheading The @code{-exec-show-arguments} Command
30945@findex -exec-show-arguments
30946
30947@subsubheading Synopsis
30948
30949@smallexample
30950 -exec-show-arguments
30951@end smallexample
30952
30953Print the arguments of the program.
922fbb7b
AC
30954
30955@subsubheading @value{GDBN} Command
30956
a2c02241 30957The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
30958
30959@subsubheading Example
a2c02241 30960N.A.
9901a55b 30961@end ignore
922fbb7b 30962
922fbb7b 30963
a2c02241
NR
30964@subheading The @code{-environment-cd} Command
30965@findex -environment-cd
922fbb7b 30966
a2c02241 30967@subsubheading Synopsis
922fbb7b
AC
30968
30969@smallexample
a2c02241 30970 -environment-cd @var{pathdir}
922fbb7b
AC
30971@end smallexample
30972
a2c02241 30973Set @value{GDBN}'s working directory.
922fbb7b 30974
a2c02241 30975@subsubheading @value{GDBN} Command
922fbb7b 30976
a2c02241
NR
30977The corresponding @value{GDBN} command is @samp{cd}.
30978
30979@subsubheading Example
922fbb7b
AC
30980
30981@smallexample
594fe323 30982(gdb)
a2c02241
NR
30983-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
30984^done
594fe323 30985(gdb)
922fbb7b
AC
30986@end smallexample
30987
30988
a2c02241
NR
30989@subheading The @code{-environment-directory} Command
30990@findex -environment-directory
922fbb7b
AC
30991
30992@subsubheading Synopsis
30993
30994@smallexample
a2c02241 30995 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
30996@end smallexample
30997
a2c02241
NR
30998Add directories @var{pathdir} to beginning of search path for source files.
30999If the @samp{-r} option is used, the search path is reset to the default
31000search path. If directories @var{pathdir} are supplied in addition to the
31001@samp{-r} option, the search path is first reset and then addition
31002occurs as normal.
31003Multiple directories may be specified, separated by blanks. Specifying
31004multiple directories in a single command
31005results in the directories added to the beginning of the
31006search path in the same order they were presented in the command.
31007If blanks are needed as
31008part of a directory name, double-quotes should be used around
31009the name. In the command output, the path will show up separated
d3e8051b 31010by the system directory-separator character. The directory-separator
a2c02241
NR
31011character must not be used
31012in any directory name.
31013If no directories are specified, the current search path is displayed.
922fbb7b
AC
31014
31015@subsubheading @value{GDBN} Command
31016
a2c02241 31017The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
31018
31019@subsubheading Example
31020
922fbb7b 31021@smallexample
594fe323 31022(gdb)
a2c02241
NR
31023-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31024^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 31025(gdb)
a2c02241
NR
31026-environment-directory ""
31027^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 31028(gdb)
a2c02241
NR
31029-environment-directory -r /home/jjohnstn/src/gdb /usr/src
31030^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 31031(gdb)
a2c02241
NR
31032-environment-directory -r
31033^done,source-path="$cdir:$cwd"
594fe323 31034(gdb)
922fbb7b
AC
31035@end smallexample
31036
31037
a2c02241
NR
31038@subheading The @code{-environment-path} Command
31039@findex -environment-path
922fbb7b
AC
31040
31041@subsubheading Synopsis
31042
31043@smallexample
a2c02241 31044 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
31045@end smallexample
31046
a2c02241
NR
31047Add directories @var{pathdir} to beginning of search path for object files.
31048If the @samp{-r} option is used, the search path is reset to the original
31049search path that existed at gdb start-up. If directories @var{pathdir} are
31050supplied in addition to the
31051@samp{-r} option, the search path is first reset and then addition
31052occurs as normal.
31053Multiple directories may be specified, separated by blanks. Specifying
31054multiple directories in a single command
31055results in the directories added to the beginning of the
31056search path in the same order they were presented in the command.
31057If blanks are needed as
31058part of a directory name, double-quotes should be used around
31059the name. In the command output, the path will show up separated
d3e8051b 31060by the system directory-separator character. The directory-separator
a2c02241
NR
31061character must not be used
31062in any directory name.
31063If no directories are specified, the current path is displayed.
31064
922fbb7b
AC
31065
31066@subsubheading @value{GDBN} Command
31067
a2c02241 31068The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
31069
31070@subsubheading Example
31071
922fbb7b 31072@smallexample
594fe323 31073(gdb)
a2c02241
NR
31074-environment-path
31075^done,path="/usr/bin"
594fe323 31076(gdb)
a2c02241
NR
31077-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
31078^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 31079(gdb)
a2c02241
NR
31080-environment-path -r /usr/local/bin
31081^done,path="/usr/local/bin:/usr/bin"
594fe323 31082(gdb)
922fbb7b
AC
31083@end smallexample
31084
31085
a2c02241
NR
31086@subheading The @code{-environment-pwd} Command
31087@findex -environment-pwd
922fbb7b
AC
31088
31089@subsubheading Synopsis
31090
31091@smallexample
a2c02241 31092 -environment-pwd
922fbb7b
AC
31093@end smallexample
31094
a2c02241 31095Show the current working directory.
922fbb7b 31096
79a6e687 31097@subsubheading @value{GDBN} Command
922fbb7b 31098
a2c02241 31099The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
31100
31101@subsubheading Example
31102
922fbb7b 31103@smallexample
594fe323 31104(gdb)
a2c02241
NR
31105-environment-pwd
31106^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 31107(gdb)
922fbb7b
AC
31108@end smallexample
31109
a2c02241
NR
31110@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31111@node GDB/MI Thread Commands
31112@section @sc{gdb/mi} Thread Commands
31113
31114
31115@subheading The @code{-thread-info} Command
31116@findex -thread-info
922fbb7b
AC
31117
31118@subsubheading Synopsis
31119
31120@smallexample
8e8901c5 31121 -thread-info [ @var{thread-id} ]
922fbb7b
AC
31122@end smallexample
31123
5d5658a1
PA
31124Reports information about either a specific thread, if the
31125@var{thread-id} parameter is present, or about all threads.
31126@var{thread-id} is the thread's global thread ID. When printing
31127information about all threads, also reports the global ID of the
31128current thread.
8e8901c5 31129
79a6e687 31130@subsubheading @value{GDBN} Command
922fbb7b 31131
8e8901c5
VP
31132The @samp{info thread} command prints the same information
31133about all threads.
922fbb7b 31134
4694da01 31135@subsubheading Result
922fbb7b 31136
ebe553db 31137The result contains the following attributes:
4694da01
TT
31138
31139@table @samp
ebe553db
SM
31140@item threads
31141A list of threads. The format of the elements of the list is described in
31142@ref{GDB/MI Thread Information}.
31143
31144@item current-thread-id
31145The global id of the currently selected thread. This field is omitted if there
31146is no selected thread (for example, when the selected inferior is not running,
31147and therefore has no threads) or if a @var{thread-id} argument was passed to
31148the command.
4694da01
TT
31149
31150@end table
31151
31152@subsubheading Example
31153
31154@smallexample
31155-thread-info
31156^done,threads=[
31157@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
31158 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
31159 args=[]@},state="running"@},
31160@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
31161 frame=@{level="0",addr="0x0804891f",func="foo",
31162 args=[@{name="i",value="10"@}],
6d52907e 31163 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
4694da01
TT
31164 state="running"@}],
31165current-thread-id="1"
31166(gdb)
31167@end smallexample
31168
a2c02241
NR
31169@subheading The @code{-thread-list-ids} Command
31170@findex -thread-list-ids
922fbb7b 31171
a2c02241 31172@subsubheading Synopsis
922fbb7b 31173
a2c02241
NR
31174@smallexample
31175 -thread-list-ids
31176@end smallexample
922fbb7b 31177
5d5658a1
PA
31178Produces a list of the currently known global @value{GDBN} thread ids.
31179At the end of the list it also prints the total number of such
31180threads.
922fbb7b 31181
c3b108f7
VP
31182This command is retained for historical reasons, the
31183@code{-thread-info} command should be used instead.
31184
922fbb7b
AC
31185@subsubheading @value{GDBN} Command
31186
a2c02241 31187Part of @samp{info threads} supplies the same information.
922fbb7b
AC
31188
31189@subsubheading Example
31190
922fbb7b 31191@smallexample
594fe323 31192(gdb)
a2c02241
NR
31193-thread-list-ids
31194^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
592375cd 31195current-thread-id="1",number-of-threads="3"
594fe323 31196(gdb)
922fbb7b
AC
31197@end smallexample
31198
a2c02241
NR
31199
31200@subheading The @code{-thread-select} Command
31201@findex -thread-select
922fbb7b
AC
31202
31203@subsubheading Synopsis
31204
31205@smallexample
5d5658a1 31206 -thread-select @var{thread-id}
922fbb7b
AC
31207@end smallexample
31208
5d5658a1
PA
31209Make thread with global thread number @var{thread-id} the current
31210thread. It prints the number of the new current thread, and the
31211topmost frame for that thread.
922fbb7b 31212
c3b108f7
VP
31213This command is deprecated in favor of explicitly using the
31214@samp{--thread} option to each command.
31215
922fbb7b
AC
31216@subsubheading @value{GDBN} Command
31217
a2c02241 31218The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
31219
31220@subsubheading Example
922fbb7b
AC
31221
31222@smallexample
594fe323 31223(gdb)
a2c02241
NR
31224-exec-next
31225^running
594fe323 31226(gdb)
a2c02241
NR
31227*stopped,reason="end-stepping-range",thread-id="2",line="187",
31228file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 31229(gdb)
a2c02241
NR
31230-thread-list-ids
31231^done,
31232thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31233number-of-threads="3"
594fe323 31234(gdb)
a2c02241
NR
31235-thread-select 3
31236^done,new-thread-id="3",
31237frame=@{level="0",func="vprintf",
31238args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
6d52907e 31239@{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
594fe323 31240(gdb)
922fbb7b
AC
31241@end smallexample
31242
5d77fe44
JB
31243@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31244@node GDB/MI Ada Tasking Commands
31245@section @sc{gdb/mi} Ada Tasking Commands
31246
31247@subheading The @code{-ada-task-info} Command
31248@findex -ada-task-info
31249
31250@subsubheading Synopsis
31251
31252@smallexample
31253 -ada-task-info [ @var{task-id} ]
31254@end smallexample
31255
31256Reports information about either a specific Ada task, if the
31257@var{task-id} parameter is present, or about all Ada tasks.
31258
31259@subsubheading @value{GDBN} Command
31260
31261The @samp{info tasks} command prints the same information
31262about all Ada tasks (@pxref{Ada Tasks}).
31263
31264@subsubheading Result
31265
31266The result is a table of Ada tasks. The following columns are
31267defined for each Ada task:
31268
31269@table @samp
31270@item current
31271This field exists only for the current thread. It has the value @samp{*}.
31272
31273@item id
31274The identifier that @value{GDBN} uses to refer to the Ada task.
31275
31276@item task-id
31277The identifier that the target uses to refer to the Ada task.
31278
31279@item thread-id
5d5658a1
PA
31280The global thread identifier of the thread corresponding to the Ada
31281task.
5d77fe44
JB
31282
31283This field should always exist, as Ada tasks are always implemented
31284on top of a thread. But if @value{GDBN} cannot find this corresponding
31285thread for any reason, the field is omitted.
31286
31287@item parent-id
31288This field exists only when the task was created by another task.
31289In this case, it provides the ID of the parent task.
31290
31291@item priority
31292The base priority of the task.
31293
31294@item state
31295The current state of the task. For a detailed description of the
31296possible states, see @ref{Ada Tasks}.
31297
31298@item name
31299The name of the task.
31300
31301@end table
31302
31303@subsubheading Example
31304
31305@smallexample
31306-ada-task-info
31307^done,tasks=@{nr_rows="3",nr_cols="8",
31308hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
31309@{width="3",alignment="1",col_name="id",colhdr="ID"@},
31310@{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
31311@{width="4",alignment="1",col_name="thread-id",colhdr=""@},
31312@{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
31313@{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
31314@{width="22",alignment="-1",col_name="state",colhdr="State"@},
31315@{width="1",alignment="2",col_name="name",colhdr="Name"@}],
31316body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
31317state="Child Termination Wait",name="main_task"@}]@}
31318(gdb)
31319@end smallexample
31320
a2c02241
NR
31321@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31322@node GDB/MI Program Execution
31323@section @sc{gdb/mi} Program Execution
922fbb7b 31324
ef21caaf 31325These are the asynchronous commands which generate the out-of-band
3f94c067 31326record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
31327asynchronously with remote targets and this interaction is mimicked in
31328other cases.
922fbb7b 31329
922fbb7b
AC
31330@subheading The @code{-exec-continue} Command
31331@findex -exec-continue
31332
31333@subsubheading Synopsis
31334
31335@smallexample
540aa8e7 31336 -exec-continue [--reverse] [--all|--thread-group N]
922fbb7b
AC
31337@end smallexample
31338
540aa8e7
MS
31339Resumes the execution of the inferior program, which will continue
31340to execute until it reaches a debugger stop event. If the
31341@samp{--reverse} option is specified, execution resumes in reverse until
31342it reaches a stop event. Stop events may include
31343@itemize @bullet
31344@item
31345breakpoints or watchpoints
31346@item
31347signals or exceptions
31348@item
31349the end of the process (or its beginning under @samp{--reverse})
31350@item
31351the end or beginning of a replay log if one is being used.
31352@end itemize
31353In all-stop mode (@pxref{All-Stop
31354Mode}), may resume only one thread, or all threads, depending on the
31355value of the @samp{scheduler-locking} variable. If @samp{--all} is
a79b8f6e 31356specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
540aa8e7
MS
31357ignored in all-stop mode. If the @samp{--thread-group} options is
31358specified, then all threads in that thread group are resumed.
922fbb7b
AC
31359
31360@subsubheading @value{GDBN} Command
31361
31362The corresponding @value{GDBN} corresponding is @samp{continue}.
31363
31364@subsubheading Example
31365
31366@smallexample
31367-exec-continue
31368^running
594fe323 31369(gdb)
922fbb7b 31370@@Hello world
a47ec5fe
AR
31371*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
31372func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
6d52907e 31373line="13",arch="i386:x86_64"@}
594fe323 31374(gdb)
922fbb7b
AC
31375@end smallexample
31376
31377
31378@subheading The @code{-exec-finish} Command
31379@findex -exec-finish
31380
31381@subsubheading Synopsis
31382
31383@smallexample
540aa8e7 31384 -exec-finish [--reverse]
922fbb7b
AC
31385@end smallexample
31386
ef21caaf
NR
31387Resumes the execution of the inferior program until the current
31388function is exited. Displays the results returned by the function.
540aa8e7
MS
31389If the @samp{--reverse} option is specified, resumes the reverse
31390execution of the inferior program until the point where current
31391function was called.
922fbb7b
AC
31392
31393@subsubheading @value{GDBN} Command
31394
31395The corresponding @value{GDBN} command is @samp{finish}.
31396
31397@subsubheading Example
31398
31399Function returning @code{void}.
31400
31401@smallexample
31402-exec-finish
31403^running
594fe323 31404(gdb)
922fbb7b
AC
31405@@hello from foo
31406*stopped,reason="function-finished",frame=@{func="main",args=[],
6d52907e 31407file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
594fe323 31408(gdb)
922fbb7b
AC
31409@end smallexample
31410
31411Function returning other than @code{void}. The name of the internal
31412@value{GDBN} variable storing the result is printed, together with the
31413value itself.
31414
31415@smallexample
31416-exec-finish
31417^running
594fe323 31418(gdb)
922fbb7b
AC
31419*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
31420args=[@{name="a",value="1"],@{name="b",value="9"@}@},
6d52907e
JV
31421file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31422arch="i386:x86_64"@},
922fbb7b 31423gdb-result-var="$1",return-value="0"
594fe323 31424(gdb)
922fbb7b
AC
31425@end smallexample
31426
31427
31428@subheading The @code{-exec-interrupt} Command
31429@findex -exec-interrupt
31430
31431@subsubheading Synopsis
31432
31433@smallexample
c3b108f7 31434 -exec-interrupt [--all|--thread-group N]
922fbb7b
AC
31435@end smallexample
31436
ef21caaf
NR
31437Interrupts the background execution of the target. Note how the token
31438associated with the stop message is the one for the execution command
31439that has been interrupted. The token for the interrupt itself only
31440appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
31441interrupt a non-running program, an error message will be printed.
31442
c3b108f7
VP
31443Note that when asynchronous execution is enabled, this command is
31444asynchronous just like other execution commands. That is, first the
31445@samp{^done} response will be printed, and the target stop will be
31446reported after that using the @samp{*stopped} notification.
31447
31448In non-stop mode, only the context thread is interrupted by default.
a79b8f6e
VP
31449All threads (in all inferiors) will be interrupted if the
31450@samp{--all} option is specified. If the @samp{--thread-group}
31451option is specified, all threads in that group will be interrupted.
c3b108f7 31452
922fbb7b
AC
31453@subsubheading @value{GDBN} Command
31454
31455The corresponding @value{GDBN} command is @samp{interrupt}.
31456
31457@subsubheading Example
31458
31459@smallexample
594fe323 31460(gdb)
922fbb7b
AC
31461111-exec-continue
31462111^running
31463
594fe323 31464(gdb)
922fbb7b
AC
31465222-exec-interrupt
31466222^done
594fe323 31467(gdb)
922fbb7b 31468111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 31469frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
6d52907e 31470fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
594fe323 31471(gdb)
922fbb7b 31472
594fe323 31473(gdb)
922fbb7b
AC
31474-exec-interrupt
31475^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 31476(gdb)
922fbb7b
AC
31477@end smallexample
31478
83eba9b7
VP
31479@subheading The @code{-exec-jump} Command
31480@findex -exec-jump
31481
31482@subsubheading Synopsis
31483
31484@smallexample
31485 -exec-jump @var{location}
31486@end smallexample
31487
31488Resumes execution of the inferior program at the location specified by
31489parameter. @xref{Specify Location}, for a description of the
31490different forms of @var{location}.
31491
31492@subsubheading @value{GDBN} Command
31493
31494The corresponding @value{GDBN} command is @samp{jump}.
31495
31496@subsubheading Example
31497
31498@smallexample
31499-exec-jump foo.c:10
31500*running,thread-id="all"
31501^running
31502@end smallexample
31503
922fbb7b
AC
31504
31505@subheading The @code{-exec-next} Command
31506@findex -exec-next
31507
31508@subsubheading Synopsis
31509
31510@smallexample
540aa8e7 31511 -exec-next [--reverse]
922fbb7b
AC
31512@end smallexample
31513
ef21caaf
NR
31514Resumes execution of the inferior program, stopping when the beginning
31515of the next source line is reached.
922fbb7b 31516
540aa8e7
MS
31517If the @samp{--reverse} option is specified, resumes reverse execution
31518of the inferior program, stopping at the beginning of the previous
31519source line. If you issue this command on the first line of a
31520function, it will take you back to the caller of that function, to the
31521source line where the function was called.
31522
31523
922fbb7b
AC
31524@subsubheading @value{GDBN} Command
31525
31526The corresponding @value{GDBN} command is @samp{next}.
31527
31528@subsubheading Example
31529
31530@smallexample
31531-exec-next
31532^running
594fe323 31533(gdb)
922fbb7b 31534*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 31535(gdb)
922fbb7b
AC
31536@end smallexample
31537
31538
31539@subheading The @code{-exec-next-instruction} Command
31540@findex -exec-next-instruction
31541
31542@subsubheading Synopsis
31543
31544@smallexample
540aa8e7 31545 -exec-next-instruction [--reverse]
922fbb7b
AC
31546@end smallexample
31547
ef21caaf
NR
31548Executes one machine instruction. If the instruction is a function
31549call, continues until the function returns. If the program stops at an
31550instruction in the middle of a source line, the address will be
31551printed as well.
922fbb7b 31552
540aa8e7
MS
31553If the @samp{--reverse} option is specified, resumes reverse execution
31554of the inferior program, stopping at the previous instruction. If the
31555previously executed instruction was a return from another function,
31556it will continue to execute in reverse until the call to that function
31557(from the current stack frame) is reached.
31558
922fbb7b
AC
31559@subsubheading @value{GDBN} Command
31560
31561The corresponding @value{GDBN} command is @samp{nexti}.
31562
31563@subsubheading Example
31564
31565@smallexample
594fe323 31566(gdb)
922fbb7b
AC
31567-exec-next-instruction
31568^running
31569
594fe323 31570(gdb)
922fbb7b
AC
31571*stopped,reason="end-stepping-range",
31572addr="0x000100d4",line="5",file="hello.c"
594fe323 31573(gdb)
922fbb7b
AC
31574@end smallexample
31575
31576
31577@subheading The @code{-exec-return} Command
31578@findex -exec-return
31579
31580@subsubheading Synopsis
31581
31582@smallexample
31583 -exec-return
31584@end smallexample
31585
31586Makes current function return immediately. Doesn't execute the inferior.
31587Displays the new current frame.
31588
31589@subsubheading @value{GDBN} Command
31590
31591The corresponding @value{GDBN} command is @samp{return}.
31592
31593@subsubheading Example
31594
31595@smallexample
594fe323 31596(gdb)
922fbb7b
AC
31597200-break-insert callee4
31598200^done,bkpt=@{number="1",addr="0x00010734",
31599file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 31600(gdb)
922fbb7b
AC
31601000-exec-run
31602000^running
594fe323 31603(gdb)
a47ec5fe 31604000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
922fbb7b 31605frame=@{func="callee4",args=[],
76ff342d 31606file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31607fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31608arch="i386:x86_64"@}
594fe323 31609(gdb)
922fbb7b
AC
31610205-break-delete
31611205^done
594fe323 31612(gdb)
922fbb7b
AC
31613111-exec-return
31614111^done,frame=@{level="0",func="callee3",
31615args=[@{name="strarg",
31616value="0x11940 \"A string argument.\""@}],
76ff342d 31617file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31618fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31619arch="i386:x86_64"@}
594fe323 31620(gdb)
922fbb7b
AC
31621@end smallexample
31622
31623
31624@subheading The @code{-exec-run} Command
31625@findex -exec-run
31626
31627@subsubheading Synopsis
31628
31629@smallexample
5713b9b5 31630 -exec-run [ --all | --thread-group N ] [ --start ]
922fbb7b
AC
31631@end smallexample
31632
ef21caaf
NR
31633Starts execution of the inferior from the beginning. The inferior
31634executes until either a breakpoint is encountered or the program
31635exits. In the latter case the output will include an exit code, if
31636the program has exited exceptionally.
922fbb7b 31637
5713b9b5
JB
31638When neither the @samp{--all} nor the @samp{--thread-group} option
31639is specified, the current inferior is started. If the
a79b8f6e
VP
31640@samp{--thread-group} option is specified, it should refer to a thread
31641group of type @samp{process}, and that thread group will be started.
31642If the @samp{--all} option is specified, then all inferiors will be started.
31643
5713b9b5
JB
31644Using the @samp{--start} option instructs the debugger to stop
31645the execution at the start of the inferior's main subprogram,
31646following the same behavior as the @code{start} command
31647(@pxref{Starting}).
31648
922fbb7b
AC
31649@subsubheading @value{GDBN} Command
31650
31651The corresponding @value{GDBN} command is @samp{run}.
31652
ef21caaf 31653@subsubheading Examples
922fbb7b
AC
31654
31655@smallexample
594fe323 31656(gdb)
922fbb7b
AC
31657-break-insert main
31658^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 31659(gdb)
922fbb7b
AC
31660-exec-run
31661^running
594fe323 31662(gdb)
a47ec5fe 31663*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
76ff342d 31664frame=@{func="main",args=[],file="recursive2.c",
6d52907e 31665fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
594fe323 31666(gdb)
922fbb7b
AC
31667@end smallexample
31668
ef21caaf
NR
31669@noindent
31670Program exited normally:
31671
31672@smallexample
594fe323 31673(gdb)
ef21caaf
NR
31674-exec-run
31675^running
594fe323 31676(gdb)
ef21caaf
NR
31677x = 55
31678*stopped,reason="exited-normally"
594fe323 31679(gdb)
ef21caaf
NR
31680@end smallexample
31681
31682@noindent
31683Program exited exceptionally:
31684
31685@smallexample
594fe323 31686(gdb)
ef21caaf
NR
31687-exec-run
31688^running
594fe323 31689(gdb)
ef21caaf
NR
31690x = 55
31691*stopped,reason="exited",exit-code="01"
594fe323 31692(gdb)
ef21caaf
NR
31693@end smallexample
31694
31695Another way the program can terminate is if it receives a signal such as
31696@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
31697
31698@smallexample
594fe323 31699(gdb)
ef21caaf
NR
31700*stopped,reason="exited-signalled",signal-name="SIGINT",
31701signal-meaning="Interrupt"
31702@end smallexample
31703
922fbb7b 31704
a2c02241
NR
31705@c @subheading -exec-signal
31706
31707
31708@subheading The @code{-exec-step} Command
31709@findex -exec-step
922fbb7b
AC
31710
31711@subsubheading Synopsis
31712
31713@smallexample
540aa8e7 31714 -exec-step [--reverse]
922fbb7b
AC
31715@end smallexample
31716
a2c02241
NR
31717Resumes execution of the inferior program, stopping when the beginning
31718of the next source line is reached, if the next source line is not a
31719function call. If it is, stop at the first instruction of the called
540aa8e7
MS
31720function. If the @samp{--reverse} option is specified, resumes reverse
31721execution of the inferior program, stopping at the beginning of the
31722previously executed source line.
922fbb7b
AC
31723
31724@subsubheading @value{GDBN} Command
31725
a2c02241 31726The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
31727
31728@subsubheading Example
31729
31730Stepping into a function:
31731
31732@smallexample
31733-exec-step
31734^running
594fe323 31735(gdb)
922fbb7b
AC
31736*stopped,reason="end-stepping-range",
31737frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 31738@{name="b",value="0"@}],file="recursive2.c",
6d52907e 31739fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
594fe323 31740(gdb)
922fbb7b
AC
31741@end smallexample
31742
31743Regular stepping:
31744
31745@smallexample
31746-exec-step
31747^running
594fe323 31748(gdb)
922fbb7b 31749*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 31750(gdb)
922fbb7b
AC
31751@end smallexample
31752
31753
31754@subheading The @code{-exec-step-instruction} Command
31755@findex -exec-step-instruction
31756
31757@subsubheading Synopsis
31758
31759@smallexample
540aa8e7 31760 -exec-step-instruction [--reverse]
922fbb7b
AC
31761@end smallexample
31762
540aa8e7
MS
31763Resumes the inferior which executes one machine instruction. If the
31764@samp{--reverse} option is specified, resumes reverse execution of the
31765inferior program, stopping at the previously executed instruction.
31766The output, once @value{GDBN} has stopped, will vary depending on
31767whether we have stopped in the middle of a source line or not. In the
31768former case, the address at which the program stopped will be printed
31769as well.
922fbb7b
AC
31770
31771@subsubheading @value{GDBN} Command
31772
31773The corresponding @value{GDBN} command is @samp{stepi}.
31774
31775@subsubheading Example
31776
31777@smallexample
594fe323 31778(gdb)
922fbb7b
AC
31779-exec-step-instruction
31780^running
31781
594fe323 31782(gdb)
922fbb7b 31783*stopped,reason="end-stepping-range",
76ff342d 31784frame=@{func="foo",args=[],file="try.c",
6d52907e 31785fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
594fe323 31786(gdb)
922fbb7b
AC
31787-exec-step-instruction
31788^running
31789
594fe323 31790(gdb)
922fbb7b 31791*stopped,reason="end-stepping-range",
76ff342d 31792frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
6d52907e 31793fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
594fe323 31794(gdb)
922fbb7b
AC
31795@end smallexample
31796
31797
31798@subheading The @code{-exec-until} Command
31799@findex -exec-until
31800
31801@subsubheading Synopsis
31802
31803@smallexample
31804 -exec-until [ @var{location} ]
31805@end smallexample
31806
ef21caaf
NR
31807Executes the inferior until the @var{location} specified in the
31808argument is reached. If there is no argument, the inferior executes
31809until a source line greater than the current one is reached. The
31810reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
31811
31812@subsubheading @value{GDBN} Command
31813
31814The corresponding @value{GDBN} command is @samp{until}.
31815
31816@subsubheading Example
31817
31818@smallexample
594fe323 31819(gdb)
922fbb7b
AC
31820-exec-until recursive2.c:6
31821^running
594fe323 31822(gdb)
922fbb7b
AC
31823x = 55
31824*stopped,reason="location-reached",frame=@{func="main",args=[],
6d52907e
JV
31825file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
31826arch="i386:x86_64"@}
594fe323 31827(gdb)
922fbb7b
AC
31828@end smallexample
31829
31830@ignore
31831@subheading -file-clear
31832Is this going away????
31833@end ignore
31834
351ff01a 31835@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
31836@node GDB/MI Stack Manipulation
31837@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 31838
1e611234
PM
31839@subheading The @code{-enable-frame-filters} Command
31840@findex -enable-frame-filters
31841
31842@smallexample
31843-enable-frame-filters
31844@end smallexample
31845
31846@value{GDBN} allows Python-based frame filters to affect the output of
31847the MI commands relating to stack traces. As there is no way to
31848implement this in a fully backward-compatible way, a front end must
31849request that this functionality be enabled.
31850
31851Once enabled, this feature cannot be disabled.
31852
31853Note that if Python support has not been compiled into @value{GDBN},
31854this command will still succeed (and do nothing).
922fbb7b 31855
a2c02241
NR
31856@subheading The @code{-stack-info-frame} Command
31857@findex -stack-info-frame
922fbb7b
AC
31858
31859@subsubheading Synopsis
31860
31861@smallexample
a2c02241 31862 -stack-info-frame
922fbb7b
AC
31863@end smallexample
31864
a2c02241 31865Get info on the selected frame.
922fbb7b
AC
31866
31867@subsubheading @value{GDBN} Command
31868
a2c02241
NR
31869The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
31870(without arguments).
922fbb7b
AC
31871
31872@subsubheading Example
31873
31874@smallexample
594fe323 31875(gdb)
a2c02241
NR
31876-stack-info-frame
31877^done,frame=@{level="1",addr="0x0001076c",func="callee3",
31878file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31879fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
31880arch="i386:x86_64"@}
594fe323 31881(gdb)
922fbb7b
AC
31882@end smallexample
31883
a2c02241
NR
31884@subheading The @code{-stack-info-depth} Command
31885@findex -stack-info-depth
922fbb7b
AC
31886
31887@subsubheading Synopsis
31888
31889@smallexample
a2c02241 31890 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
31891@end smallexample
31892
a2c02241
NR
31893Return the depth of the stack. If the integer argument @var{max-depth}
31894is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
31895
31896@subsubheading @value{GDBN} Command
31897
a2c02241 31898There's no equivalent @value{GDBN} command.
922fbb7b
AC
31899
31900@subsubheading Example
31901
a2c02241
NR
31902For a stack with frame levels 0 through 11:
31903
922fbb7b 31904@smallexample
594fe323 31905(gdb)
a2c02241
NR
31906-stack-info-depth
31907^done,depth="12"
594fe323 31908(gdb)
a2c02241
NR
31909-stack-info-depth 4
31910^done,depth="4"
594fe323 31911(gdb)
a2c02241
NR
31912-stack-info-depth 12
31913^done,depth="12"
594fe323 31914(gdb)
a2c02241
NR
31915-stack-info-depth 11
31916^done,depth="11"
594fe323 31917(gdb)
a2c02241
NR
31918-stack-info-depth 13
31919^done,depth="12"
594fe323 31920(gdb)
922fbb7b
AC
31921@end smallexample
31922
1e611234 31923@anchor{-stack-list-arguments}
a2c02241
NR
31924@subheading The @code{-stack-list-arguments} Command
31925@findex -stack-list-arguments
922fbb7b
AC
31926
31927@subsubheading Synopsis
31928
31929@smallexample
6211c335 31930 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
a2c02241 31931 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
31932@end smallexample
31933
a2c02241
NR
31934Display a list of the arguments for the frames between @var{low-frame}
31935and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
31936@var{high-frame} are not provided, list the arguments for the whole
31937call stack. If the two arguments are equal, show the single frame
31938at the corresponding level. It is an error if @var{low-frame} is
31939larger than the actual number of frames. On the other hand,
31940@var{high-frame} may be larger than the actual number of frames, in
31941which case only existing frames will be returned.
a2c02241 31942
3afae151
VP
31943If @var{print-values} is 0 or @code{--no-values}, print only the names of
31944the variables; if it is 1 or @code{--all-values}, print also their
31945values; and if it is 2 or @code{--simple-values}, print the name,
31946type and value for simple data types, and the name and type for arrays,
1e611234
PM
31947structures and unions. If the option @code{--no-frame-filters} is
31948supplied, then Python frame filters will not be executed.
31949
6211c335
YQ
31950If the @code{--skip-unavailable} option is specified, arguments that
31951are not available are not listed. Partially available arguments
31952are still displayed, however.
922fbb7b 31953
b3372f91
VP
31954Use of this command to obtain arguments in a single frame is
31955deprecated in favor of the @samp{-stack-list-variables} command.
31956
922fbb7b
AC
31957@subsubheading @value{GDBN} Command
31958
a2c02241
NR
31959@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
31960@samp{gdb_get_args} command which partially overlaps with the
31961functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
31962
31963@subsubheading Example
922fbb7b 31964
a2c02241 31965@smallexample
594fe323 31966(gdb)
a2c02241
NR
31967-stack-list-frames
31968^done,
31969stack=[
31970frame=@{level="0",addr="0x00010734",func="callee4",
31971file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31972fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31973arch="i386:x86_64"@},
a2c02241
NR
31974frame=@{level="1",addr="0x0001076c",func="callee3",
31975file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31976fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
31977arch="i386:x86_64"@},
a2c02241
NR
31978frame=@{level="2",addr="0x0001078c",func="callee2",
31979file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31980fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
31981arch="i386:x86_64"@},
a2c02241
NR
31982frame=@{level="3",addr="0x000107b4",func="callee1",
31983file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31984fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
31985arch="i386:x86_64"@},
a2c02241
NR
31986frame=@{level="4",addr="0x000107e0",func="main",
31987file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31988fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
31989arch="i386:x86_64"@}]
594fe323 31990(gdb)
a2c02241
NR
31991-stack-list-arguments 0
31992^done,
31993stack-args=[
31994frame=@{level="0",args=[]@},
31995frame=@{level="1",args=[name="strarg"]@},
31996frame=@{level="2",args=[name="intarg",name="strarg"]@},
31997frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
31998frame=@{level="4",args=[]@}]
594fe323 31999(gdb)
a2c02241
NR
32000-stack-list-arguments 1
32001^done,
32002stack-args=[
32003frame=@{level="0",args=[]@},
32004frame=@{level="1",
32005 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32006frame=@{level="2",args=[
32007@{name="intarg",value="2"@},
32008@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32009@{frame=@{level="3",args=[
32010@{name="intarg",value="2"@},
32011@{name="strarg",value="0x11940 \"A string argument.\""@},
32012@{name="fltarg",value="3.5"@}]@},
32013frame=@{level="4",args=[]@}]
594fe323 32014(gdb)
a2c02241
NR
32015-stack-list-arguments 0 2 2
32016^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 32017(gdb)
a2c02241
NR
32018-stack-list-arguments 1 2 2
32019^done,stack-args=[frame=@{level="2",
32020args=[@{name="intarg",value="2"@},
32021@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 32022(gdb)
a2c02241
NR
32023@end smallexample
32024
32025@c @subheading -stack-list-exception-handlers
922fbb7b 32026
a2c02241 32027
1e611234 32028@anchor{-stack-list-frames}
a2c02241
NR
32029@subheading The @code{-stack-list-frames} Command
32030@findex -stack-list-frames
1abaf70c
BR
32031
32032@subsubheading Synopsis
32033
32034@smallexample
1e611234 32035 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
1abaf70c
BR
32036@end smallexample
32037
a2c02241
NR
32038List the frames currently on the stack. For each frame it displays the
32039following info:
32040
32041@table @samp
32042@item @var{level}
d3e8051b 32043The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
32044@item @var{addr}
32045The @code{$pc} value for that frame.
32046@item @var{func}
32047Function name.
32048@item @var{file}
32049File name of the source file where the function lives.
7d288aaa
TT
32050@item @var{fullname}
32051The full file name of the source file where the function lives.
a2c02241
NR
32052@item @var{line}
32053Line number corresponding to the @code{$pc}.
7d288aaa
TT
32054@item @var{from}
32055The shared library where this function is defined. This is only given
32056if the frame's function is not known.
6d52907e
JV
32057@item @var{arch}
32058Frame's architecture.
a2c02241
NR
32059@end table
32060
32061If invoked without arguments, this command prints a backtrace for the
32062whole stack. If given two integer arguments, it shows the frames whose
32063levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
32064are equal, it shows the single frame at the corresponding level. It is
32065an error if @var{low-frame} is larger than the actual number of
a5451f4e 32066frames. On the other hand, @var{high-frame} may be larger than the
1e611234
PM
32067actual number of frames, in which case only existing frames will be
32068returned. If the option @code{--no-frame-filters} is supplied, then
32069Python frame filters will not be executed.
1abaf70c
BR
32070
32071@subsubheading @value{GDBN} Command
32072
a2c02241 32073The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
32074
32075@subsubheading Example
32076
a2c02241
NR
32077Full stack backtrace:
32078
1abaf70c 32079@smallexample
594fe323 32080(gdb)
a2c02241
NR
32081-stack-list-frames
32082^done,stack=
32083[frame=@{level="0",addr="0x0001076c",func="foo",
6d52907e
JV
32084 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
32085 arch="i386:x86_64"@},
a2c02241 32086frame=@{level="1",addr="0x000107a4",func="foo",
6d52907e
JV
32087 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32088 arch="i386:x86_64"@},
a2c02241 32089frame=@{level="2",addr="0x000107a4",func="foo",
6d52907e
JV
32090 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32091 arch="i386:x86_64"@},
a2c02241 32092frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
32093 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32094 arch="i386:x86_64"@},
a2c02241 32095frame=@{level="4",addr="0x000107a4",func="foo",
6d52907e
JV
32096 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32097 arch="i386:x86_64"@},
a2c02241 32098frame=@{level="5",addr="0x000107a4",func="foo",
6d52907e
JV
32099 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32100 arch="i386:x86_64"@},
a2c02241 32101frame=@{level="6",addr="0x000107a4",func="foo",
6d52907e
JV
32102 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32103 arch="i386:x86_64"@},
a2c02241 32104frame=@{level="7",addr="0x000107a4",func="foo",
6d52907e
JV
32105 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32106 arch="i386:x86_64"@},
a2c02241 32107frame=@{level="8",addr="0x000107a4",func="foo",
6d52907e
JV
32108 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32109 arch="i386:x86_64"@},
a2c02241 32110frame=@{level="9",addr="0x000107a4",func="foo",
6d52907e
JV
32111 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32112 arch="i386:x86_64"@},
a2c02241 32113frame=@{level="10",addr="0x000107a4",func="foo",
6d52907e
JV
32114 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32115 arch="i386:x86_64"@},
a2c02241 32116frame=@{level="11",addr="0x00010738",func="main",
6d52907e
JV
32117 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
32118 arch="i386:x86_64"@}]
594fe323 32119(gdb)
1abaf70c
BR
32120@end smallexample
32121
a2c02241 32122Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 32123
a2c02241 32124@smallexample
594fe323 32125(gdb)
a2c02241
NR
32126-stack-list-frames 3 5
32127^done,stack=
32128[frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
32129 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32130 arch="i386:x86_64"@},
a2c02241 32131frame=@{level="4",addr="0x000107a4",func="foo",
6d52907e
JV
32132 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32133 arch="i386:x86_64"@},
a2c02241 32134frame=@{level="5",addr="0x000107a4",func="foo",
6d52907e
JV
32135 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32136 arch="i386:x86_64"@}]
594fe323 32137(gdb)
a2c02241 32138@end smallexample
922fbb7b 32139
a2c02241 32140Show a single frame:
922fbb7b
AC
32141
32142@smallexample
594fe323 32143(gdb)
a2c02241
NR
32144-stack-list-frames 3 3
32145^done,stack=
32146[frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
32147 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32148 arch="i386:x86_64"@}]
594fe323 32149(gdb)
922fbb7b
AC
32150@end smallexample
32151
922fbb7b 32152
a2c02241
NR
32153@subheading The @code{-stack-list-locals} Command
32154@findex -stack-list-locals
1e611234 32155@anchor{-stack-list-locals}
57c22c6c 32156
a2c02241 32157@subsubheading Synopsis
922fbb7b
AC
32158
32159@smallexample
6211c335 32160 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
922fbb7b
AC
32161@end smallexample
32162
a2c02241
NR
32163Display the local variable names for the selected frame. If
32164@var{print-values} is 0 or @code{--no-values}, print only the names of
32165the variables; if it is 1 or @code{--all-values}, print also their
32166values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 32167type and value for simple data types, and the name and type for arrays,
a2c02241
NR
32168structures and unions. In this last case, a frontend can immediately
32169display the value of simple data types and create variable objects for
d3e8051b 32170other data types when the user wishes to explore their values in
1e611234
PM
32171more detail. If the option @code{--no-frame-filters} is supplied, then
32172Python frame filters will not be executed.
922fbb7b 32173
6211c335
YQ
32174If the @code{--skip-unavailable} option is specified, local variables
32175that are not available are not listed. Partially available local
32176variables are still displayed, however.
32177
b3372f91
VP
32178This command is deprecated in favor of the
32179@samp{-stack-list-variables} command.
32180
922fbb7b
AC
32181@subsubheading @value{GDBN} Command
32182
a2c02241 32183@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
32184
32185@subsubheading Example
922fbb7b
AC
32186
32187@smallexample
594fe323 32188(gdb)
a2c02241
NR
32189-stack-list-locals 0
32190^done,locals=[name="A",name="B",name="C"]
594fe323 32191(gdb)
a2c02241
NR
32192-stack-list-locals --all-values
32193^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
32194 @{name="C",value="@{1, 2, 3@}"@}]
32195-stack-list-locals --simple-values
32196^done,locals=[@{name="A",type="int",value="1"@},
32197 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 32198(gdb)
922fbb7b
AC
32199@end smallexample
32200
1e611234 32201@anchor{-stack-list-variables}
b3372f91
VP
32202@subheading The @code{-stack-list-variables} Command
32203@findex -stack-list-variables
32204
32205@subsubheading Synopsis
32206
32207@smallexample
6211c335 32208 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
b3372f91
VP
32209@end smallexample
32210
32211Display the names of local variables and function arguments for the selected frame. If
32212@var{print-values} is 0 or @code{--no-values}, print only the names of
32213the variables; if it is 1 or @code{--all-values}, print also their
32214values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 32215type and value for simple data types, and the name and type for arrays,
1e611234
PM
32216structures and unions. If the option @code{--no-frame-filters} is
32217supplied, then Python frame filters will not be executed.
b3372f91 32218
6211c335
YQ
32219If the @code{--skip-unavailable} option is specified, local variables
32220and arguments that are not available are not listed. Partially
32221available arguments and local variables are still displayed, however.
32222
b3372f91
VP
32223@subsubheading Example
32224
32225@smallexample
32226(gdb)
32227-stack-list-variables --thread 1 --frame 0 --all-values
4f412fd0 32228^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
b3372f91
VP
32229(gdb)
32230@end smallexample
32231
922fbb7b 32232
a2c02241
NR
32233@subheading The @code{-stack-select-frame} Command
32234@findex -stack-select-frame
922fbb7b
AC
32235
32236@subsubheading Synopsis
32237
32238@smallexample
a2c02241 32239 -stack-select-frame @var{framenum}
922fbb7b
AC
32240@end smallexample
32241
a2c02241
NR
32242Change the selected frame. Select a different frame @var{framenum} on
32243the stack.
922fbb7b 32244
c3b108f7
VP
32245This command in deprecated in favor of passing the @samp{--frame}
32246option to every command.
32247
922fbb7b
AC
32248@subsubheading @value{GDBN} Command
32249
a2c02241
NR
32250The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
32251@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
32252
32253@subsubheading Example
32254
32255@smallexample
594fe323 32256(gdb)
a2c02241 32257-stack-select-frame 2
922fbb7b 32258^done
594fe323 32259(gdb)
922fbb7b
AC
32260@end smallexample
32261
32262@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
32263@node GDB/MI Variable Objects
32264@section @sc{gdb/mi} Variable Objects
922fbb7b 32265
a1b5960f 32266@ignore
922fbb7b 32267
a2c02241 32268@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 32269
a2c02241
NR
32270For the implementation of a variable debugger window (locals, watched
32271expressions, etc.), we are proposing the adaptation of the existing code
32272used by @code{Insight}.
922fbb7b 32273
a2c02241 32274The two main reasons for that are:
922fbb7b 32275
a2c02241
NR
32276@enumerate 1
32277@item
32278It has been proven in practice (it is already on its second generation).
922fbb7b 32279
a2c02241
NR
32280@item
32281It will shorten development time (needless to say how important it is
32282now).
32283@end enumerate
922fbb7b 32284
a2c02241
NR
32285The original interface was designed to be used by Tcl code, so it was
32286slightly changed so it could be used through @sc{gdb/mi}. This section
32287describes the @sc{gdb/mi} operations that will be available and gives some
32288hints about their use.
922fbb7b 32289
a2c02241
NR
32290@emph{Note}: In addition to the set of operations described here, we
32291expect the @sc{gui} implementation of a variable window to require, at
32292least, the following operations:
922fbb7b 32293
a2c02241
NR
32294@itemize @bullet
32295@item @code{-gdb-show} @code{output-radix}
32296@item @code{-stack-list-arguments}
32297@item @code{-stack-list-locals}
32298@item @code{-stack-select-frame}
32299@end itemize
922fbb7b 32300
a1b5960f
VP
32301@end ignore
32302
c8b2f53c 32303@subheading Introduction to Variable Objects
922fbb7b 32304
a2c02241 32305@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
32306
32307Variable objects are "object-oriented" MI interface for examining and
32308changing values of expressions. Unlike some other MI interfaces that
32309work with expressions, variable objects are specifically designed for
32310simple and efficient presentation in the frontend. A variable object
32311is identified by string name. When a variable object is created, the
32312frontend specifies the expression for that variable object. The
32313expression can be a simple variable, or it can be an arbitrary complex
32314expression, and can even involve CPU registers. After creating a
32315variable object, the frontend can invoke other variable object
32316operations---for example to obtain or change the value of a variable
32317object, or to change display format.
32318
32319Variable objects have hierarchical tree structure. Any variable object
32320that corresponds to a composite type, such as structure in C, has
32321a number of child variable objects, for example corresponding to each
32322element of a structure. A child variable object can itself have
32323children, recursively. Recursion ends when we reach
25d5ea92
VP
32324leaf variable objects, which always have built-in types. Child variable
32325objects are created only by explicit request, so if a frontend
32326is not interested in the children of a particular variable object, no
32327child will be created.
c8b2f53c
VP
32328
32329For a leaf variable object it is possible to obtain its value as a
32330string, or set the value from a string. String value can be also
32331obtained for a non-leaf variable object, but it's generally a string
32332that only indicates the type of the object, and does not list its
32333contents. Assignment to a non-leaf variable object is not allowed.
32334
32335A frontend does not need to read the values of all variable objects each time
32336the program stops. Instead, MI provides an update command that lists all
32337variable objects whose values has changed since the last update
32338operation. This considerably reduces the amount of data that must
25d5ea92
VP
32339be transferred to the frontend. As noted above, children variable
32340objects are created on demand, and only leaf variable objects have a
32341real value. As result, gdb will read target memory only for leaf
32342variables that frontend has created.
32343
32344The automatic update is not always desirable. For example, a frontend
32345might want to keep a value of some expression for future reference,
32346and never update it. For another example, fetching memory is
32347relatively slow for embedded targets, so a frontend might want
32348to disable automatic update for the variables that are either not
32349visible on the screen, or ``closed''. This is possible using so
32350called ``frozen variable objects''. Such variable objects are never
32351implicitly updated.
922fbb7b 32352
c3b108f7
VP
32353Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
32354fixed variable object, the expression is parsed when the variable
32355object is created, including associating identifiers to specific
32356variables. The meaning of expression never changes. For a floating
32357variable object the values of variables whose names appear in the
32358expressions are re-evaluated every time in the context of the current
32359frame. Consider this example:
32360
32361@smallexample
32362void do_work(...)
32363@{
32364 struct work_state state;
32365
32366 if (...)
32367 do_work(...);
32368@}
32369@end smallexample
32370
32371If a fixed variable object for the @code{state} variable is created in
7a9dd1b2 32372this function, and we enter the recursive call, the variable
c3b108f7
VP
32373object will report the value of @code{state} in the top-level
32374@code{do_work} invocation. On the other hand, a floating variable
32375object will report the value of @code{state} in the current frame.
32376
32377If an expression specified when creating a fixed variable object
32378refers to a local variable, the variable object becomes bound to the
32379thread and frame in which the variable object is created. When such
32380variable object is updated, @value{GDBN} makes sure that the
32381thread/frame combination the variable object is bound to still exists,
32382and re-evaluates the variable object in context of that thread/frame.
32383
a2c02241
NR
32384The following is the complete set of @sc{gdb/mi} operations defined to
32385access this functionality:
922fbb7b 32386
a2c02241
NR
32387@multitable @columnfractions .4 .6
32388@item @strong{Operation}
32389@tab @strong{Description}
922fbb7b 32390
0cc7d26f
TT
32391@item @code{-enable-pretty-printing}
32392@tab enable Python-based pretty-printing
a2c02241
NR
32393@item @code{-var-create}
32394@tab create a variable object
32395@item @code{-var-delete}
22d8a470 32396@tab delete the variable object and/or its children
a2c02241
NR
32397@item @code{-var-set-format}
32398@tab set the display format of this variable
32399@item @code{-var-show-format}
32400@tab show the display format of this variable
32401@item @code{-var-info-num-children}
32402@tab tells how many children this object has
32403@item @code{-var-list-children}
32404@tab return a list of the object's children
32405@item @code{-var-info-type}
32406@tab show the type of this variable object
32407@item @code{-var-info-expression}
02142340
VP
32408@tab print parent-relative expression that this variable object represents
32409@item @code{-var-info-path-expression}
32410@tab print full expression that this variable object represents
a2c02241
NR
32411@item @code{-var-show-attributes}
32412@tab is this variable editable? does it exist here?
32413@item @code{-var-evaluate-expression}
32414@tab get the value of this variable
32415@item @code{-var-assign}
32416@tab set the value of this variable
32417@item @code{-var-update}
32418@tab update the variable and its children
25d5ea92 32419@item @code{-var-set-frozen}
6b92c0d3 32420@tab set frozenness attribute
0cc7d26f
TT
32421@item @code{-var-set-update-range}
32422@tab set range of children to display on update
a2c02241 32423@end multitable
922fbb7b 32424
a2c02241
NR
32425In the next subsection we describe each operation in detail and suggest
32426how it can be used.
922fbb7b 32427
a2c02241 32428@subheading Description And Use of Operations on Variable Objects
922fbb7b 32429
0cc7d26f
TT
32430@subheading The @code{-enable-pretty-printing} Command
32431@findex -enable-pretty-printing
32432
32433@smallexample
32434-enable-pretty-printing
32435@end smallexample
32436
32437@value{GDBN} allows Python-based visualizers to affect the output of the
32438MI variable object commands. However, because there was no way to
32439implement this in a fully backward-compatible way, a front end must
32440request that this functionality be enabled.
32441
32442Once enabled, this feature cannot be disabled.
32443
32444Note that if Python support has not been compiled into @value{GDBN},
32445this command will still succeed (and do nothing).
32446
f43030c4
TT
32447This feature is currently (as of @value{GDBN} 7.0) experimental, and
32448may work differently in future versions of @value{GDBN}.
32449
a2c02241
NR
32450@subheading The @code{-var-create} Command
32451@findex -var-create
ef21caaf 32452
a2c02241 32453@subsubheading Synopsis
ef21caaf 32454
a2c02241
NR
32455@smallexample
32456 -var-create @{@var{name} | "-"@}
c3b108f7 32457 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
a2c02241
NR
32458@end smallexample
32459
32460This operation creates a variable object, which allows the monitoring of
32461a variable, the result of an expression, a memory cell or a CPU
32462register.
ef21caaf 32463
a2c02241
NR
32464The @var{name} parameter is the string by which the object can be
32465referenced. It must be unique. If @samp{-} is specified, the varobj
32466system will generate a string ``varNNNNNN'' automatically. It will be
c3b108f7 32467unique provided that one does not specify @var{name} of that format.
a2c02241 32468The command fails if a duplicate name is found.
ef21caaf 32469
a2c02241
NR
32470The frame under which the expression should be evaluated can be
32471specified by @var{frame-addr}. A @samp{*} indicates that the current
c3b108f7
VP
32472frame should be used. A @samp{@@} indicates that a floating variable
32473object must be created.
922fbb7b 32474
a2c02241
NR
32475@var{expression} is any expression valid on the current language set (must not
32476begin with a @samp{*}), or one of the following:
922fbb7b 32477
a2c02241
NR
32478@itemize @bullet
32479@item
32480@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 32481
a2c02241
NR
32482@item
32483@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 32484
a2c02241
NR
32485@item
32486@samp{$@var{regname}} --- a CPU register name
32487@end itemize
922fbb7b 32488
0cc7d26f
TT
32489@cindex dynamic varobj
32490A varobj's contents may be provided by a Python-based pretty-printer. In this
32491case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
32492have slightly different semantics in some cases. If the
32493@code{-enable-pretty-printing} command is not sent, then @value{GDBN}
32494will never create a dynamic varobj. This ensures backward
32495compatibility for existing clients.
32496
a2c02241 32497@subsubheading Result
922fbb7b 32498
0cc7d26f
TT
32499This operation returns attributes of the newly-created varobj. These
32500are:
32501
32502@table @samp
32503@item name
32504The name of the varobj.
32505
32506@item numchild
32507The number of children of the varobj. This number is not necessarily
32508reliable for a dynamic varobj. Instead, you must examine the
32509@samp{has_more} attribute.
32510
32511@item value
32512The varobj's scalar value. For a varobj whose type is some sort of
32513aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
32514will not be interesting.
32515
32516@item type
32517The varobj's type. This is a string representation of the type, as
8264ba82
AG
32518would be printed by the @value{GDBN} CLI. If @samp{print object}
32519(@pxref{Print Settings, set print object}) is set to @code{on}, the
32520@emph{actual} (derived) type of the object is shown rather than the
32521@emph{declared} one.
0cc7d26f
TT
32522
32523@item thread-id
32524If a variable object is bound to a specific thread, then this is the
5d5658a1 32525thread's global identifier.
0cc7d26f
TT
32526
32527@item has_more
32528For a dynamic varobj, this indicates whether there appear to be any
32529children available. For a non-dynamic varobj, this will be 0.
32530
32531@item dynamic
32532This attribute will be present and have the value @samp{1} if the
32533varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32534then this attribute will not be present.
32535
32536@item displayhint
32537A dynamic varobj can supply a display hint to the front end. The
32538value comes directly from the Python pretty-printer object's
4c374409 32539@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
32540@end table
32541
32542Typical output will look like this:
922fbb7b
AC
32543
32544@smallexample
0cc7d26f
TT
32545 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
32546 has_more="@var{has_more}"
dcaaae04
NR
32547@end smallexample
32548
a2c02241
NR
32549
32550@subheading The @code{-var-delete} Command
32551@findex -var-delete
922fbb7b
AC
32552
32553@subsubheading Synopsis
32554
32555@smallexample
22d8a470 32556 -var-delete [ -c ] @var{name}
922fbb7b
AC
32557@end smallexample
32558
a2c02241 32559Deletes a previously created variable object and all of its children.
22d8a470 32560With the @samp{-c} option, just deletes the children.
922fbb7b 32561
a2c02241 32562Returns an error if the object @var{name} is not found.
922fbb7b 32563
922fbb7b 32564
a2c02241
NR
32565@subheading The @code{-var-set-format} Command
32566@findex -var-set-format
922fbb7b 32567
a2c02241 32568@subsubheading Synopsis
922fbb7b
AC
32569
32570@smallexample
a2c02241 32571 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
32572@end smallexample
32573
a2c02241
NR
32574Sets the output format for the value of the object @var{name} to be
32575@var{format-spec}.
32576
de051565 32577@anchor{-var-set-format}
a2c02241
NR
32578The syntax for the @var{format-spec} is as follows:
32579
32580@smallexample
32581 @var{format-spec} @expansion{}
1c35a88f 32582 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
a2c02241
NR
32583@end smallexample
32584
c8b2f53c
VP
32585The natural format is the default format choosen automatically
32586based on the variable type (like decimal for an @code{int}, hex
32587for pointers, etc.).
32588
1c35a88f
LM
32589The zero-hexadecimal format has a representation similar to hexadecimal
32590but with padding zeroes to the left of the value. For example, a 32-bit
32591hexadecimal value of 0x1234 would be represented as 0x00001234 in the
32592zero-hexadecimal format.
32593
c8b2f53c
VP
32594For a variable with children, the format is set only on the
32595variable itself, and the children are not affected.
a2c02241
NR
32596
32597@subheading The @code{-var-show-format} Command
32598@findex -var-show-format
922fbb7b
AC
32599
32600@subsubheading Synopsis
32601
32602@smallexample
a2c02241 32603 -var-show-format @var{name}
922fbb7b
AC
32604@end smallexample
32605
a2c02241 32606Returns the format used to display the value of the object @var{name}.
922fbb7b 32607
a2c02241
NR
32608@smallexample
32609 @var{format} @expansion{}
32610 @var{format-spec}
32611@end smallexample
922fbb7b 32612
922fbb7b 32613
a2c02241
NR
32614@subheading The @code{-var-info-num-children} Command
32615@findex -var-info-num-children
32616
32617@subsubheading Synopsis
32618
32619@smallexample
32620 -var-info-num-children @var{name}
32621@end smallexample
32622
32623Returns the number of children of a variable object @var{name}:
32624
32625@smallexample
32626 numchild=@var{n}
32627@end smallexample
32628
0cc7d26f
TT
32629Note that this number is not completely reliable for a dynamic varobj.
32630It will return the current number of children, but more children may
32631be available.
32632
a2c02241
NR
32633
32634@subheading The @code{-var-list-children} Command
32635@findex -var-list-children
32636
32637@subsubheading Synopsis
32638
32639@smallexample
0cc7d26f 32640 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
a2c02241 32641@end smallexample
b569d230 32642@anchor{-var-list-children}
a2c02241
NR
32643
32644Return a list of the children of the specified variable object and
32645create variable objects for them, if they do not already exist. With
f5011d11 32646a single argument or if @var{print-values} has a value of 0 or
a2c02241
NR
32647@code{--no-values}, print only the names of the variables; if
32648@var{print-values} is 1 or @code{--all-values}, also print their
32649values; and if it is 2 or @code{--simple-values} print the name and
32650value for simple data types and just the name for arrays, structures
32651and unions.
922fbb7b 32652
0cc7d26f
TT
32653@var{from} and @var{to}, if specified, indicate the range of children
32654to report. If @var{from} or @var{to} is less than zero, the range is
32655reset and all children will be reported. Otherwise, children starting
32656at @var{from} (zero-based) and up to and excluding @var{to} will be
32657reported.
32658
32659If a child range is requested, it will only affect the current call to
32660@code{-var-list-children}, but not future calls to @code{-var-update}.
32661For this, you must instead use @code{-var-set-update-range}. The
32662intent of this approach is to enable a front end to implement any
32663update approach it likes; for example, scrolling a view may cause the
32664front end to request more children with @code{-var-list-children}, and
32665then the front end could call @code{-var-set-update-range} with a
32666different range to ensure that future updates are restricted to just
32667the visible items.
32668
b569d230
EZ
32669For each child the following results are returned:
32670
32671@table @var
32672
32673@item name
32674Name of the variable object created for this child.
32675
32676@item exp
32677The expression to be shown to the user by the front end to designate this child.
32678For example this may be the name of a structure member.
32679
0cc7d26f
TT
32680For a dynamic varobj, this value cannot be used to form an
32681expression. There is no way to do this at all with a dynamic varobj.
32682
b569d230
EZ
32683For C/C@t{++} structures there are several pseudo children returned to
32684designate access qualifiers. For these pseudo children @var{exp} is
32685@samp{public}, @samp{private}, or @samp{protected}. In this case the
32686type and value are not present.
32687
0cc7d26f
TT
32688A dynamic varobj will not report the access qualifying
32689pseudo-children, regardless of the language. This information is not
32690available at all with a dynamic varobj.
32691
b569d230 32692@item numchild
0cc7d26f
TT
32693Number of children this child has. For a dynamic varobj, this will be
326940.
b569d230
EZ
32695
32696@item type
8264ba82
AG
32697The type of the child. If @samp{print object}
32698(@pxref{Print Settings, set print object}) is set to @code{on}, the
32699@emph{actual} (derived) type of the object is shown rather than the
32700@emph{declared} one.
b569d230
EZ
32701
32702@item value
32703If values were requested, this is the value.
32704
32705@item thread-id
5d5658a1
PA
32706If this variable object is associated with a thread, this is the
32707thread's global thread id. Otherwise this result is not present.
b569d230
EZ
32708
32709@item frozen
32710If the variable object is frozen, this variable will be present with a value of 1.
c78feb39 32711
9df9dbe0
YQ
32712@item displayhint
32713A dynamic varobj can supply a display hint to the front end. The
32714value comes directly from the Python pretty-printer object's
32715@code{display_hint} method. @xref{Pretty Printing API}.
32716
c78feb39
YQ
32717@item dynamic
32718This attribute will be present and have the value @samp{1} if the
32719varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32720then this attribute will not be present.
32721
b569d230
EZ
32722@end table
32723
0cc7d26f
TT
32724The result may have its own attributes:
32725
32726@table @samp
32727@item displayhint
32728A dynamic varobj can supply a display hint to the front end. The
32729value comes directly from the Python pretty-printer object's
4c374409 32730@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
32731
32732@item has_more
32733This is an integer attribute which is nonzero if there are children
32734remaining after the end of the selected range.
32735@end table
32736
922fbb7b
AC
32737@subsubheading Example
32738
32739@smallexample
594fe323 32740(gdb)
a2c02241 32741 -var-list-children n
b569d230 32742 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 32743 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 32744(gdb)
a2c02241 32745 -var-list-children --all-values n
b569d230 32746 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 32747 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
32748@end smallexample
32749
922fbb7b 32750
a2c02241
NR
32751@subheading The @code{-var-info-type} Command
32752@findex -var-info-type
922fbb7b 32753
a2c02241
NR
32754@subsubheading Synopsis
32755
32756@smallexample
32757 -var-info-type @var{name}
32758@end smallexample
32759
32760Returns the type of the specified variable @var{name}. The type is
32761returned as a string in the same format as it is output by the
32762@value{GDBN} CLI:
32763
32764@smallexample
32765 type=@var{typename}
32766@end smallexample
32767
32768
32769@subheading The @code{-var-info-expression} Command
32770@findex -var-info-expression
922fbb7b
AC
32771
32772@subsubheading Synopsis
32773
32774@smallexample
a2c02241 32775 -var-info-expression @var{name}
922fbb7b
AC
32776@end smallexample
32777
02142340
VP
32778Returns a string that is suitable for presenting this
32779variable object in user interface. The string is generally
32780not valid expression in the current language, and cannot be evaluated.
32781
32782For example, if @code{a} is an array, and variable object
32783@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 32784
a2c02241 32785@smallexample
02142340
VP
32786(gdb) -var-info-expression A.1
32787^done,lang="C",exp="1"
a2c02241 32788@end smallexample
922fbb7b 32789
a2c02241 32790@noindent
fa4d0c40
YQ
32791Here, the value of @code{lang} is the language name, which can be
32792found in @ref{Supported Languages}.
02142340
VP
32793
32794Note that the output of the @code{-var-list-children} command also
32795includes those expressions, so the @code{-var-info-expression} command
32796is of limited use.
32797
32798@subheading The @code{-var-info-path-expression} Command
32799@findex -var-info-path-expression
32800
32801@subsubheading Synopsis
32802
32803@smallexample
32804 -var-info-path-expression @var{name}
32805@end smallexample
32806
32807Returns an expression that can be evaluated in the current
32808context and will yield the same value that a variable object has.
32809Compare this with the @code{-var-info-expression} command, which
32810result can be used only for UI presentation. Typical use of
32811the @code{-var-info-path-expression} command is creating a
32812watchpoint from a variable object.
32813
0cc7d26f
TT
32814This command is currently not valid for children of a dynamic varobj,
32815and will give an error when invoked on one.
32816
02142340
VP
32817For example, suppose @code{C} is a C@t{++} class, derived from class
32818@code{Base}, and that the @code{Base} class has a member called
32819@code{m_size}. Assume a variable @code{c} is has the type of
32820@code{C} and a variable object @code{C} was created for variable
32821@code{c}. Then, we'll get this output:
32822@smallexample
32823(gdb) -var-info-path-expression C.Base.public.m_size
32824^done,path_expr=((Base)c).m_size)
32825@end smallexample
922fbb7b 32826
a2c02241
NR
32827@subheading The @code{-var-show-attributes} Command
32828@findex -var-show-attributes
922fbb7b 32829
a2c02241 32830@subsubheading Synopsis
922fbb7b 32831
a2c02241
NR
32832@smallexample
32833 -var-show-attributes @var{name}
32834@end smallexample
922fbb7b 32835
a2c02241 32836List attributes of the specified variable object @var{name}:
922fbb7b
AC
32837
32838@smallexample
a2c02241 32839 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
32840@end smallexample
32841
a2c02241
NR
32842@noindent
32843where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
32844
32845@subheading The @code{-var-evaluate-expression} Command
32846@findex -var-evaluate-expression
32847
32848@subsubheading Synopsis
32849
32850@smallexample
de051565 32851 -var-evaluate-expression [-f @var{format-spec}] @var{name}
a2c02241
NR
32852@end smallexample
32853
32854Evaluates the expression that is represented by the specified variable
de051565
MK
32855object and returns its value as a string. The format of the string
32856can be specified with the @samp{-f} option. The possible values of
32857this option are the same as for @code{-var-set-format}
32858(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
32859the current display format will be used. The current display format
32860can be changed using the @code{-var-set-format} command.
a2c02241
NR
32861
32862@smallexample
32863 value=@var{value}
32864@end smallexample
32865
32866Note that one must invoke @code{-var-list-children} for a variable
32867before the value of a child variable can be evaluated.
32868
32869@subheading The @code{-var-assign} Command
32870@findex -var-assign
32871
32872@subsubheading Synopsis
32873
32874@smallexample
32875 -var-assign @var{name} @var{expression}
32876@end smallexample
32877
32878Assigns the value of @var{expression} to the variable object specified
32879by @var{name}. The object must be @samp{editable}. If the variable's
32880value is altered by the assign, the variable will show up in any
32881subsequent @code{-var-update} list.
32882
32883@subsubheading Example
922fbb7b
AC
32884
32885@smallexample
594fe323 32886(gdb)
a2c02241
NR
32887-var-assign var1 3
32888^done,value="3"
594fe323 32889(gdb)
a2c02241
NR
32890-var-update *
32891^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 32892(gdb)
922fbb7b
AC
32893@end smallexample
32894
a2c02241
NR
32895@subheading The @code{-var-update} Command
32896@findex -var-update
32897
32898@subsubheading Synopsis
32899
32900@smallexample
32901 -var-update [@var{print-values}] @{@var{name} | "*"@}
32902@end smallexample
32903
c8b2f53c
VP
32904Reevaluate the expressions corresponding to the variable object
32905@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
32906list of variable objects whose values have changed; @var{name} must
32907be a root variable object. Here, ``changed'' means that the result of
32908@code{-var-evaluate-expression} before and after the
32909@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
32910object names, all existing variable objects are updated, except
32911for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3 32912@var{print-values} determines whether both names and values, or just
de051565 32913names are printed. The possible values of this option are the same
36ece8b3
NR
32914as for @code{-var-list-children} (@pxref{-var-list-children}). It is
32915recommended to use the @samp{--all-values} option, to reduce the
32916number of MI commands needed on each program stop.
c8b2f53c 32917
c3b108f7
VP
32918With the @samp{*} parameter, if a variable object is bound to a
32919currently running thread, it will not be updated, without any
32920diagnostic.
a2c02241 32921
0cc7d26f
TT
32922If @code{-var-set-update-range} was previously used on a varobj, then
32923only the selected range of children will be reported.
922fbb7b 32924
0cc7d26f
TT
32925@code{-var-update} reports all the changed varobjs in a tuple named
32926@samp{changelist}.
32927
32928Each item in the change list is itself a tuple holding:
32929
32930@table @samp
32931@item name
32932The name of the varobj.
32933
32934@item value
32935If values were requested for this update, then this field will be
32936present and will hold the value of the varobj.
922fbb7b 32937
0cc7d26f 32938@item in_scope
9f708cb2 32939@anchor{-var-update}
0cc7d26f 32940This field is a string which may take one of three values:
36ece8b3
NR
32941
32942@table @code
32943@item "true"
32944The variable object's current value is valid.
32945
32946@item "false"
32947The variable object does not currently hold a valid value but it may
32948hold one in the future if its associated expression comes back into
32949scope.
32950
32951@item "invalid"
32952The variable object no longer holds a valid value.
32953This can occur when the executable file being debugged has changed,
32954either through recompilation or by using the @value{GDBN} @code{file}
32955command. The front end should normally choose to delete these variable
32956objects.
32957@end table
32958
32959In the future new values may be added to this list so the front should
32960be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
32961
0cc7d26f
TT
32962@item type_changed
32963This is only present if the varobj is still valid. If the type
32964changed, then this will be the string @samp{true}; otherwise it will
32965be @samp{false}.
32966
7191c139
JB
32967When a varobj's type changes, its children are also likely to have
32968become incorrect. Therefore, the varobj's children are automatically
32969deleted when this attribute is @samp{true}. Also, the varobj's update
32970range, when set using the @code{-var-set-update-range} command, is
32971unset.
32972
0cc7d26f
TT
32973@item new_type
32974If the varobj's type changed, then this field will be present and will
32975hold the new type.
32976
32977@item new_num_children
32978For a dynamic varobj, if the number of children changed, or if the
32979type changed, this will be the new number of children.
32980
32981The @samp{numchild} field in other varobj responses is generally not
32982valid for a dynamic varobj -- it will show the number of children that
32983@value{GDBN} knows about, but because dynamic varobjs lazily
32984instantiate their children, this will not reflect the number of
32985children which may be available.
32986
32987The @samp{new_num_children} attribute only reports changes to the
32988number of children known by @value{GDBN}. This is the only way to
32989detect whether an update has removed children (which necessarily can
32990only happen at the end of the update range).
32991
32992@item displayhint
32993The display hint, if any.
32994
32995@item has_more
32996This is an integer value, which will be 1 if there are more children
32997available outside the varobj's update range.
32998
32999@item dynamic
33000This attribute will be present and have the value @samp{1} if the
33001varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33002then this attribute will not be present.
33003
33004@item new_children
33005If new children were added to a dynamic varobj within the selected
33006update range (as set by @code{-var-set-update-range}), then they will
33007be listed in this attribute.
33008@end table
33009
33010@subsubheading Example
33011
33012@smallexample
33013(gdb)
33014-var-assign var1 3
33015^done,value="3"
33016(gdb)
33017-var-update --all-values var1
33018^done,changelist=[@{name="var1",value="3",in_scope="true",
33019type_changed="false"@}]
33020(gdb)
33021@end smallexample
33022
25d5ea92
VP
33023@subheading The @code{-var-set-frozen} Command
33024@findex -var-set-frozen
9f708cb2 33025@anchor{-var-set-frozen}
25d5ea92
VP
33026
33027@subsubheading Synopsis
33028
33029@smallexample
9f708cb2 33030 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
33031@end smallexample
33032
9f708cb2 33033Set the frozenness flag on the variable object @var{name}. The
25d5ea92 33034@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 33035frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 33036frozen, then neither itself, nor any of its children, are
9f708cb2 33037implicitly updated by @code{-var-update} of
25d5ea92
VP
33038a parent variable or by @code{-var-update *}. Only
33039@code{-var-update} of the variable itself will update its value and
33040values of its children. After a variable object is unfrozen, it is
33041implicitly updated by all subsequent @code{-var-update} operations.
33042Unfreezing a variable does not update it, only subsequent
33043@code{-var-update} does.
33044
33045@subsubheading Example
33046
33047@smallexample
33048(gdb)
33049-var-set-frozen V 1
33050^done
33051(gdb)
33052@end smallexample
33053
0cc7d26f
TT
33054@subheading The @code{-var-set-update-range} command
33055@findex -var-set-update-range
33056@anchor{-var-set-update-range}
33057
33058@subsubheading Synopsis
33059
33060@smallexample
33061 -var-set-update-range @var{name} @var{from} @var{to}
33062@end smallexample
33063
33064Set the range of children to be returned by future invocations of
33065@code{-var-update}.
33066
33067@var{from} and @var{to} indicate the range of children to report. If
33068@var{from} or @var{to} is less than zero, the range is reset and all
33069children will be reported. Otherwise, children starting at @var{from}
33070(zero-based) and up to and excluding @var{to} will be reported.
33071
33072@subsubheading Example
33073
33074@smallexample
33075(gdb)
33076-var-set-update-range V 1 2
33077^done
33078@end smallexample
33079
b6313243
TT
33080@subheading The @code{-var-set-visualizer} command
33081@findex -var-set-visualizer
33082@anchor{-var-set-visualizer}
33083
33084@subsubheading Synopsis
33085
33086@smallexample
33087 -var-set-visualizer @var{name} @var{visualizer}
33088@end smallexample
33089
33090Set a visualizer for the variable object @var{name}.
33091
33092@var{visualizer} is the visualizer to use. The special value
33093@samp{None} means to disable any visualizer in use.
33094
33095If not @samp{None}, @var{visualizer} must be a Python expression.
33096This expression must evaluate to a callable object which accepts a
33097single argument. @value{GDBN} will call this object with the value of
33098the varobj @var{name} as an argument (this is done so that the same
33099Python pretty-printing code can be used for both the CLI and MI).
33100When called, this object must return an object which conforms to the
4c374409 33101pretty-printing interface (@pxref{Pretty Printing API}).
b6313243
TT
33102
33103The pre-defined function @code{gdb.default_visualizer} may be used to
33104select a visualizer by following the built-in process
33105(@pxref{Selecting Pretty-Printers}). This is done automatically when
33106a varobj is created, and so ordinarily is not needed.
33107
33108This feature is only available if Python support is enabled. The MI
d192b373 33109command @code{-list-features} (@pxref{GDB/MI Support Commands})
b6313243
TT
33110can be used to check this.
33111
33112@subsubheading Example
33113
33114Resetting the visualizer:
33115
33116@smallexample
33117(gdb)
33118-var-set-visualizer V None
33119^done
33120@end smallexample
33121
33122Reselecting the default (type-based) visualizer:
33123
33124@smallexample
33125(gdb)
33126-var-set-visualizer V gdb.default_visualizer
33127^done
33128@end smallexample
33129
33130Suppose @code{SomeClass} is a visualizer class. A lambda expression
33131can be used to instantiate this class for a varobj:
33132
33133@smallexample
33134(gdb)
33135-var-set-visualizer V "lambda val: SomeClass()"
33136^done
33137@end smallexample
25d5ea92 33138
a2c02241
NR
33139@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33140@node GDB/MI Data Manipulation
33141@section @sc{gdb/mi} Data Manipulation
922fbb7b 33142
a2c02241
NR
33143@cindex data manipulation, in @sc{gdb/mi}
33144@cindex @sc{gdb/mi}, data manipulation
33145This section describes the @sc{gdb/mi} commands that manipulate data:
33146examine memory and registers, evaluate expressions, etc.
33147
a86c90e6
SM
33148For details about what an addressable memory unit is,
33149@pxref{addressable memory unit}.
33150
a2c02241
NR
33151@c REMOVED FROM THE INTERFACE.
33152@c @subheading -data-assign
33153@c Change the value of a program variable. Plenty of side effects.
79a6e687 33154@c @subsubheading GDB Command
a2c02241
NR
33155@c set variable
33156@c @subsubheading Example
33157@c N.A.
33158
33159@subheading The @code{-data-disassemble} Command
33160@findex -data-disassemble
922fbb7b
AC
33161
33162@subsubheading Synopsis
33163
33164@smallexample
a2c02241
NR
33165 -data-disassemble
33166 [ -s @var{start-addr} -e @var{end-addr} ]
26fb3983 33167 | [ -a @var{addr} ]
a2c02241
NR
33168 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
33169 -- @var{mode}
922fbb7b
AC
33170@end smallexample
33171
a2c02241
NR
33172@noindent
33173Where:
33174
33175@table @samp
33176@item @var{start-addr}
33177is the beginning address (or @code{$pc})
33178@item @var{end-addr}
33179is the end address
26fb3983
JV
33180@item @var{addr}
33181is an address anywhere within (or the name of) the function to
33182disassemble. If an address is specified, the whole function
33183surrounding that address will be disassembled. If a name is
33184specified, the whole function with that name will be disassembled.
a2c02241
NR
33185@item @var{filename}
33186is the name of the file to disassemble
33187@item @var{linenum}
33188is the line number to disassemble around
33189@item @var{lines}
d3e8051b 33190is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
33191the whole function will be disassembled, in case no @var{end-addr} is
33192specified. If @var{end-addr} is specified as a non-zero value, and
33193@var{lines} is lower than the number of disassembly lines between
33194@var{start-addr} and @var{end-addr}, only @var{lines} lines are
33195displayed; if @var{lines} is higher than the number of lines between
33196@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
33197are displayed.
33198@item @var{mode}
6ff0ba5f
DE
33199is one of:
33200@itemize @bullet
33201@item 0 disassembly only
33202@item 1 mixed source and disassembly (deprecated)
33203@item 2 disassembly with raw opcodes
33204@item 3 mixed source and disassembly with raw opcodes (deprecated)
33205@item 4 mixed source and disassembly
33206@item 5 mixed source and disassembly with raw opcodes
33207@end itemize
33208
33209Modes 1 and 3 are deprecated. The output is ``source centric''
33210which hasn't proved useful in practice.
33211@xref{Machine Code}, for a discussion of the difference between
33212@code{/m} and @code{/s} output of the @code{disassemble} command.
a2c02241
NR
33213@end table
33214
33215@subsubheading Result
33216
ed8a1c2d
AB
33217The result of the @code{-data-disassemble} command will be a list named
33218@samp{asm_insns}, the contents of this list depend on the @var{mode}
33219used with the @code{-data-disassemble} command.
a2c02241 33220
ed8a1c2d
AB
33221For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
33222following fields:
33223
33224@table @code
33225@item address
33226The address at which this instruction was disassembled.
33227
33228@item func-name
33229The name of the function this instruction is within.
33230
33231@item offset
33232The decimal offset in bytes from the start of @samp{func-name}.
33233
33234@item inst
33235The text disassembly for this @samp{address}.
33236
33237@item opcodes
6ff0ba5f 33238This field is only present for modes 2, 3 and 5. This contains the raw opcode
ed8a1c2d
AB
33239bytes for the @samp{inst} field.
33240
33241@end table
33242
6ff0ba5f 33243For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
ed8a1c2d 33244@samp{src_and_asm_line}, each of which has the following fields:
a2c02241 33245
ed8a1c2d
AB
33246@table @code
33247@item line
33248The line number within @samp{file}.
33249
33250@item file
33251The file name from the compilation unit. This might be an absolute
33252file name or a relative file name depending on the compile command
33253used.
33254
33255@item fullname
f35a17b5
JK
33256Absolute file name of @samp{file}. It is converted to a canonical form
33257using the source file search path
33258(@pxref{Source Path, ,Specifying Source Directories})
33259and after resolving all the symbolic links.
33260
33261If the source file is not found this field will contain the path as
33262present in the debug information.
ed8a1c2d
AB
33263
33264@item line_asm_insn
33265This is a list of tuples containing the disassembly for @samp{line} in
33266@samp{file}. The fields of each tuple are the same as for
33267@code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
33268@samp{func-name}, @samp{offset}, @samp{inst}, and optionally
33269@samp{opcodes}.
33270
33271@end table
33272
33273Note that whatever included in the @samp{inst} field, is not
33274manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
33275adjust its format.
922fbb7b
AC
33276
33277@subsubheading @value{GDBN} Command
33278
ed8a1c2d 33279The corresponding @value{GDBN} command is @samp{disassemble}.
922fbb7b
AC
33280
33281@subsubheading Example
33282
a2c02241
NR
33283Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
33284
922fbb7b 33285@smallexample
594fe323 33286(gdb)
a2c02241
NR
33287-data-disassemble -s $pc -e "$pc + 20" -- 0
33288^done,
33289asm_insns=[
33290@{address="0x000107c0",func-name="main",offset="4",
33291inst="mov 2, %o0"@},
33292@{address="0x000107c4",func-name="main",offset="8",
33293inst="sethi %hi(0x11800), %o2"@},
33294@{address="0x000107c8",func-name="main",offset="12",
33295inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
33296@{address="0x000107cc",func-name="main",offset="16",
33297inst="sethi %hi(0x11800), %o2"@},
33298@{address="0x000107d0",func-name="main",offset="20",
33299inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 33300(gdb)
a2c02241
NR
33301@end smallexample
33302
33303Disassemble the whole @code{main} function. Line 32 is part of
33304@code{main}.
33305
33306@smallexample
33307-data-disassemble -f basics.c -l 32 -- 0
33308^done,asm_insns=[
33309@{address="0x000107bc",func-name="main",offset="0",
33310inst="save %sp, -112, %sp"@},
33311@{address="0x000107c0",func-name="main",offset="4",
33312inst="mov 2, %o0"@},
33313@{address="0x000107c4",func-name="main",offset="8",
33314inst="sethi %hi(0x11800), %o2"@},
33315[@dots{}]
33316@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
33317@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 33318(gdb)
922fbb7b
AC
33319@end smallexample
33320
a2c02241 33321Disassemble 3 instructions from the start of @code{main}:
922fbb7b 33322
a2c02241 33323@smallexample
594fe323 33324(gdb)
a2c02241
NR
33325-data-disassemble -f basics.c -l 32 -n 3 -- 0
33326^done,asm_insns=[
33327@{address="0x000107bc",func-name="main",offset="0",
33328inst="save %sp, -112, %sp"@},
33329@{address="0x000107c0",func-name="main",offset="4",
33330inst="mov 2, %o0"@},
33331@{address="0x000107c4",func-name="main",offset="8",
33332inst="sethi %hi(0x11800), %o2"@}]
594fe323 33333(gdb)
a2c02241
NR
33334@end smallexample
33335
33336Disassemble 3 instructions from the start of @code{main} in mixed mode:
33337
33338@smallexample
594fe323 33339(gdb)
a2c02241
NR
33340-data-disassemble -f basics.c -l 32 -n 3 -- 1
33341^done,asm_insns=[
33342src_and_asm_line=@{line="31",
ed8a1c2d
AB
33343file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33344fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33345line_asm_insn=[@{address="0x000107bc",
33346func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
a2c02241 33347src_and_asm_line=@{line="32",
ed8a1c2d
AB
33348file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33349fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33350line_asm_insn=[@{address="0x000107c0",
33351func-name="main",offset="4",inst="mov 2, %o0"@},
a2c02241
NR
33352@{address="0x000107c4",func-name="main",offset="8",
33353inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 33354(gdb)
a2c02241
NR
33355@end smallexample
33356
33357
33358@subheading The @code{-data-evaluate-expression} Command
33359@findex -data-evaluate-expression
922fbb7b
AC
33360
33361@subsubheading Synopsis
33362
33363@smallexample
a2c02241 33364 -data-evaluate-expression @var{expr}
922fbb7b
AC
33365@end smallexample
33366
a2c02241
NR
33367Evaluate @var{expr} as an expression. The expression could contain an
33368inferior function call. The function call will execute synchronously.
33369If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
33370
33371@subsubheading @value{GDBN} Command
33372
a2c02241
NR
33373The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
33374@samp{call}. In @code{gdbtk} only, there's a corresponding
33375@samp{gdb_eval} command.
922fbb7b
AC
33376
33377@subsubheading Example
33378
a2c02241
NR
33379In the following example, the numbers that precede the commands are the
33380@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
33381Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
33382output.
33383
922fbb7b 33384@smallexample
a2c02241
NR
33385211-data-evaluate-expression A
33386211^done,value="1"
594fe323 33387(gdb)
a2c02241
NR
33388311-data-evaluate-expression &A
33389311^done,value="0xefffeb7c"
594fe323 33390(gdb)
a2c02241
NR
33391411-data-evaluate-expression A+3
33392411^done,value="4"
594fe323 33393(gdb)
a2c02241
NR
33394511-data-evaluate-expression "A + 3"
33395511^done,value="4"
594fe323 33396(gdb)
a2c02241 33397@end smallexample
922fbb7b
AC
33398
33399
a2c02241
NR
33400@subheading The @code{-data-list-changed-registers} Command
33401@findex -data-list-changed-registers
922fbb7b
AC
33402
33403@subsubheading Synopsis
33404
33405@smallexample
a2c02241 33406 -data-list-changed-registers
922fbb7b
AC
33407@end smallexample
33408
a2c02241 33409Display a list of the registers that have changed.
922fbb7b
AC
33410
33411@subsubheading @value{GDBN} Command
33412
a2c02241
NR
33413@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
33414has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
33415
33416@subsubheading Example
922fbb7b 33417
a2c02241 33418On a PPC MBX board:
922fbb7b
AC
33419
33420@smallexample
594fe323 33421(gdb)
a2c02241
NR
33422-exec-continue
33423^running
922fbb7b 33424
594fe323 33425(gdb)
a47ec5fe
AR
33426*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
33427func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
6d52907e 33428line="5",arch="powerpc"@}
594fe323 33429(gdb)
a2c02241
NR
33430-data-list-changed-registers
33431^done,changed-registers=["0","1","2","4","5","6","7","8","9",
33432"10","11","13","14","15","16","17","18","19","20","21","22","23",
33433"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 33434(gdb)
a2c02241 33435@end smallexample
922fbb7b
AC
33436
33437
a2c02241
NR
33438@subheading The @code{-data-list-register-names} Command
33439@findex -data-list-register-names
922fbb7b
AC
33440
33441@subsubheading Synopsis
33442
33443@smallexample
a2c02241 33444 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
33445@end smallexample
33446
a2c02241
NR
33447Show a list of register names for the current target. If no arguments
33448are given, it shows a list of the names of all the registers. If
33449integer numbers are given as arguments, it will print a list of the
33450names of the registers corresponding to the arguments. To ensure
33451consistency between a register name and its number, the output list may
33452include empty register names.
922fbb7b
AC
33453
33454@subsubheading @value{GDBN} Command
33455
a2c02241
NR
33456@value{GDBN} does not have a command which corresponds to
33457@samp{-data-list-register-names}. In @code{gdbtk} there is a
33458corresponding command @samp{gdb_regnames}.
922fbb7b
AC
33459
33460@subsubheading Example
922fbb7b 33461
a2c02241
NR
33462For the PPC MBX board:
33463@smallexample
594fe323 33464(gdb)
a2c02241
NR
33465-data-list-register-names
33466^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
33467"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
33468"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
33469"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
33470"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
33471"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
33472"", "pc","ps","cr","lr","ctr","xer"]
594fe323 33473(gdb)
a2c02241
NR
33474-data-list-register-names 1 2 3
33475^done,register-names=["r1","r2","r3"]
594fe323 33476(gdb)
a2c02241 33477@end smallexample
922fbb7b 33478
a2c02241
NR
33479@subheading The @code{-data-list-register-values} Command
33480@findex -data-list-register-values
922fbb7b
AC
33481
33482@subsubheading Synopsis
33483
33484@smallexample
c898adb7
YQ
33485 -data-list-register-values
33486 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
33487@end smallexample
33488
697aa1b7
EZ
33489Display the registers' contents. The format according to which the
33490registers' contents are to be returned is given by @var{fmt}, followed
33491by an optional list of numbers specifying the registers to display. A
33492missing list of numbers indicates that the contents of all the
33493registers must be returned. The @code{--skip-unavailable} option
33494indicates that only the available registers are to be returned.
a2c02241
NR
33495
33496Allowed formats for @var{fmt} are:
33497
33498@table @code
33499@item x
33500Hexadecimal
33501@item o
33502Octal
33503@item t
33504Binary
33505@item d
33506Decimal
33507@item r
33508Raw
33509@item N
33510Natural
33511@end table
922fbb7b
AC
33512
33513@subsubheading @value{GDBN} Command
33514
a2c02241
NR
33515The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
33516all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
33517
33518@subsubheading Example
922fbb7b 33519
a2c02241
NR
33520For a PPC MBX board (note: line breaks are for readability only, they
33521don't appear in the actual output):
33522
33523@smallexample
594fe323 33524(gdb)
a2c02241
NR
33525-data-list-register-values r 64 65
33526^done,register-values=[@{number="64",value="0xfe00a300"@},
33527@{number="65",value="0x00029002"@}]
594fe323 33528(gdb)
a2c02241
NR
33529-data-list-register-values x
33530^done,register-values=[@{number="0",value="0xfe0043c8"@},
33531@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
33532@{number="3",value="0x0"@},@{number="4",value="0xa"@},
33533@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
33534@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
33535@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
33536@{number="11",value="0x1"@},@{number="12",value="0x0"@},
33537@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
33538@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
33539@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
33540@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
33541@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
33542@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
33543@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
33544@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
33545@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
33546@{number="31",value="0x0"@},@{number="32",value="0x0"@},
33547@{number="33",value="0x0"@},@{number="34",value="0x0"@},
33548@{number="35",value="0x0"@},@{number="36",value="0x0"@},
33549@{number="37",value="0x0"@},@{number="38",value="0x0"@},
33550@{number="39",value="0x0"@},@{number="40",value="0x0"@},
33551@{number="41",value="0x0"@},@{number="42",value="0x0"@},
33552@{number="43",value="0x0"@},@{number="44",value="0x0"@},
33553@{number="45",value="0x0"@},@{number="46",value="0x0"@},
33554@{number="47",value="0x0"@},@{number="48",value="0x0"@},
33555@{number="49",value="0x0"@},@{number="50",value="0x0"@},
33556@{number="51",value="0x0"@},@{number="52",value="0x0"@},
33557@{number="53",value="0x0"@},@{number="54",value="0x0"@},
33558@{number="55",value="0x0"@},@{number="56",value="0x0"@},
33559@{number="57",value="0x0"@},@{number="58",value="0x0"@},
33560@{number="59",value="0x0"@},@{number="60",value="0x0"@},
33561@{number="61",value="0x0"@},@{number="62",value="0x0"@},
33562@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
33563@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
33564@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
33565@{number="69",value="0x20002b03"@}]
594fe323 33566(gdb)
a2c02241 33567@end smallexample
922fbb7b 33568
a2c02241
NR
33569
33570@subheading The @code{-data-read-memory} Command
33571@findex -data-read-memory
922fbb7b 33572
8dedea02
VP
33573This command is deprecated, use @code{-data-read-memory-bytes} instead.
33574
922fbb7b
AC
33575@subsubheading Synopsis
33576
33577@smallexample
a2c02241
NR
33578 -data-read-memory [ -o @var{byte-offset} ]
33579 @var{address} @var{word-format} @var{word-size}
33580 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
33581@end smallexample
33582
a2c02241
NR
33583@noindent
33584where:
922fbb7b 33585
a2c02241
NR
33586@table @samp
33587@item @var{address}
33588An expression specifying the address of the first memory word to be
33589read. Complex expressions containing embedded white space should be
33590quoted using the C convention.
922fbb7b 33591
a2c02241
NR
33592@item @var{word-format}
33593The format to be used to print the memory words. The notation is the
33594same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 33595,Output Formats}).
922fbb7b 33596
a2c02241
NR
33597@item @var{word-size}
33598The size of each memory word in bytes.
922fbb7b 33599
a2c02241
NR
33600@item @var{nr-rows}
33601The number of rows in the output table.
922fbb7b 33602
a2c02241
NR
33603@item @var{nr-cols}
33604The number of columns in the output table.
922fbb7b 33605
a2c02241
NR
33606@item @var{aschar}
33607If present, indicates that each row should include an @sc{ascii} dump. The
33608value of @var{aschar} is used as a padding character when a byte is not a
33609member of the printable @sc{ascii} character set (printable @sc{ascii}
33610characters are those whose code is between 32 and 126, inclusively).
922fbb7b 33611
a2c02241
NR
33612@item @var{byte-offset}
33613An offset to add to the @var{address} before fetching memory.
33614@end table
922fbb7b 33615
a2c02241
NR
33616This command displays memory contents as a table of @var{nr-rows} by
33617@var{nr-cols} words, each word being @var{word-size} bytes. In total,
33618@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
33619(returned as @samp{total-bytes}). Should less than the requested number
33620of bytes be returned by the target, the missing words are identified
33621using @samp{N/A}. The number of bytes read from the target is returned
33622in @samp{nr-bytes} and the starting address used to read memory in
33623@samp{addr}.
33624
33625The address of the next/previous row or page is available in
33626@samp{next-row} and @samp{prev-row}, @samp{next-page} and
33627@samp{prev-page}.
922fbb7b
AC
33628
33629@subsubheading @value{GDBN} Command
33630
a2c02241
NR
33631The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
33632@samp{gdb_get_mem} memory read command.
922fbb7b
AC
33633
33634@subsubheading Example
32e7087d 33635
a2c02241
NR
33636Read six bytes of memory starting at @code{bytes+6} but then offset by
33637@code{-6} bytes. Format as three rows of two columns. One byte per
33638word. Display each word in hex.
32e7087d
JB
33639
33640@smallexample
594fe323 33641(gdb)
a2c02241
NR
336429-data-read-memory -o -6 -- bytes+6 x 1 3 2
336439^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
33644next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
33645prev-page="0x0000138a",memory=[
33646@{addr="0x00001390",data=["0x00","0x01"]@},
33647@{addr="0x00001392",data=["0x02","0x03"]@},
33648@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 33649(gdb)
32e7087d
JB
33650@end smallexample
33651
a2c02241
NR
33652Read two bytes of memory starting at address @code{shorts + 64} and
33653display as a single word formatted in decimal.
32e7087d 33654
32e7087d 33655@smallexample
594fe323 33656(gdb)
a2c02241
NR
336575-data-read-memory shorts+64 d 2 1 1
336585^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
33659next-row="0x00001512",prev-row="0x0000150e",
33660next-page="0x00001512",prev-page="0x0000150e",memory=[
33661@{addr="0x00001510",data=["128"]@}]
594fe323 33662(gdb)
32e7087d
JB
33663@end smallexample
33664
a2c02241
NR
33665Read thirty two bytes of memory starting at @code{bytes+16} and format
33666as eight rows of four columns. Include a string encoding with @samp{x}
33667used as the non-printable character.
922fbb7b
AC
33668
33669@smallexample
594fe323 33670(gdb)
a2c02241
NR
336714-data-read-memory bytes+16 x 1 8 4 x
336724^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
33673next-row="0x000013c0",prev-row="0x0000139c",
33674next-page="0x000013c0",prev-page="0x00001380",memory=[
33675@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
33676@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
33677@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
33678@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
33679@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
33680@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
33681@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
33682@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 33683(gdb)
922fbb7b
AC
33684@end smallexample
33685
8dedea02
VP
33686@subheading The @code{-data-read-memory-bytes} Command
33687@findex -data-read-memory-bytes
33688
33689@subsubheading Synopsis
33690
33691@smallexample
a86c90e6 33692 -data-read-memory-bytes [ -o @var{offset} ]
8dedea02
VP
33693 @var{address} @var{count}
33694@end smallexample
33695
33696@noindent
33697where:
33698
33699@table @samp
33700@item @var{address}
a86c90e6
SM
33701An expression specifying the address of the first addressable memory unit
33702to be read. Complex expressions containing embedded white space should be
8dedea02
VP
33703quoted using the C convention.
33704
33705@item @var{count}
a86c90e6
SM
33706The number of addressable memory units to read. This should be an integer
33707literal.
8dedea02 33708
a86c90e6
SM
33709@item @var{offset}
33710The offset relative to @var{address} at which to start reading. This
33711should be an integer literal. This option is provided so that a frontend
33712is not required to first evaluate address and then perform address
33713arithmetics itself.
8dedea02
VP
33714
33715@end table
33716
33717This command attempts to read all accessible memory regions in the
33718specified range. First, all regions marked as unreadable in the memory
33719map (if one is defined) will be skipped. @xref{Memory Region
33720Attributes}. Second, @value{GDBN} will attempt to read the remaining
33721regions. For each one, if reading full region results in an errors,
33722@value{GDBN} will try to read a subset of the region.
33723
a86c90e6
SM
33724In general, every single memory unit in the region may be readable or not,
33725and the only way to read every readable unit is to try a read at
8dedea02 33726every address, which is not practical. Therefore, @value{GDBN} will
a86c90e6 33727attempt to read all accessible memory units at either beginning or the end
8dedea02 33728of the region, using a binary division scheme. This heuristic works
6b92c0d3 33729well for reading across a memory map boundary. Note that if a region
8dedea02
VP
33730has a readable range that is neither at the beginning or the end,
33731@value{GDBN} will not read it.
33732
33733The result record (@pxref{GDB/MI Result Records}) that is output of
33734the command includes a field named @samp{memory} whose content is a
33735list of tuples. Each tuple represent a successfully read memory block
33736and has the following fields:
33737
33738@table @code
33739@item begin
33740The start address of the memory block, as hexadecimal literal.
33741
33742@item end
33743The end address of the memory block, as hexadecimal literal.
33744
33745@item offset
33746The offset of the memory block, as hexadecimal literal, relative to
33747the start address passed to @code{-data-read-memory-bytes}.
33748
33749@item contents
33750The contents of the memory block, in hex.
33751
33752@end table
33753
33754
33755
33756@subsubheading @value{GDBN} Command
33757
33758The corresponding @value{GDBN} command is @samp{x}.
33759
33760@subsubheading Example
33761
33762@smallexample
33763(gdb)
33764-data-read-memory-bytes &a 10
33765^done,memory=[@{begin="0xbffff154",offset="0x00000000",
33766 end="0xbffff15e",
33767 contents="01000000020000000300"@}]
33768(gdb)
33769@end smallexample
33770
33771
33772@subheading The @code{-data-write-memory-bytes} Command
33773@findex -data-write-memory-bytes
33774
33775@subsubheading Synopsis
33776
33777@smallexample
33778 -data-write-memory-bytes @var{address} @var{contents}
62747a60 33779 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
8dedea02
VP
33780@end smallexample
33781
33782@noindent
33783where:
33784
33785@table @samp
33786@item @var{address}
a86c90e6
SM
33787An expression specifying the address of the first addressable memory unit
33788to be written. Complex expressions containing embedded white space should
33789be quoted using the C convention.
8dedea02
VP
33790
33791@item @var{contents}
a86c90e6
SM
33792The hex-encoded data to write. It is an error if @var{contents} does
33793not represent an integral number of addressable memory units.
8dedea02 33794
62747a60 33795@item @var{count}
a86c90e6
SM
33796Optional argument indicating the number of addressable memory units to be
33797written. If @var{count} is greater than @var{contents}' length,
33798@value{GDBN} will repeatedly write @var{contents} until it fills
33799@var{count} memory units.
62747a60 33800
8dedea02
VP
33801@end table
33802
33803@subsubheading @value{GDBN} Command
33804
33805There's no corresponding @value{GDBN} command.
33806
33807@subsubheading Example
33808
33809@smallexample
33810(gdb)
33811-data-write-memory-bytes &a "aabbccdd"
33812^done
33813(gdb)
33814@end smallexample
33815
62747a60
TT
33816@smallexample
33817(gdb)
33818-data-write-memory-bytes &a "aabbccdd" 16e
33819^done
33820(gdb)
33821@end smallexample
8dedea02 33822
a2c02241
NR
33823@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33824@node GDB/MI Tracepoint Commands
33825@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 33826
18148017
VP
33827The commands defined in this section implement MI support for
33828tracepoints. For detailed introduction, see @ref{Tracepoints}.
33829
33830@subheading The @code{-trace-find} Command
33831@findex -trace-find
33832
33833@subsubheading Synopsis
33834
33835@smallexample
33836 -trace-find @var{mode} [@var{parameters}@dots{}]
33837@end smallexample
33838
33839Find a trace frame using criteria defined by @var{mode} and
33840@var{parameters}. The following table lists permissible
33841modes and their parameters. For details of operation, see @ref{tfind}.
33842
33843@table @samp
33844
33845@item none
33846No parameters are required. Stops examining trace frames.
33847
33848@item frame-number
33849An integer is required as parameter. Selects tracepoint frame with
33850that index.
33851
33852@item tracepoint-number
33853An integer is required as parameter. Finds next
33854trace frame that corresponds to tracepoint with the specified number.
33855
33856@item pc
33857An address is required as parameter. Finds
33858next trace frame that corresponds to any tracepoint at the specified
33859address.
33860
33861@item pc-inside-range
33862Two addresses are required as parameters. Finds next trace
33863frame that corresponds to a tracepoint at an address inside the
33864specified range. Both bounds are considered to be inside the range.
33865
33866@item pc-outside-range
33867Two addresses are required as parameters. Finds
33868next trace frame that corresponds to a tracepoint at an address outside
33869the specified range. Both bounds are considered to be inside the range.
33870
33871@item line
33872Line specification is required as parameter. @xref{Specify Location}.
33873Finds next trace frame that corresponds to a tracepoint at
33874the specified location.
33875
33876@end table
33877
33878If @samp{none} was passed as @var{mode}, the response does not
33879have fields. Otherwise, the response may have the following fields:
33880
33881@table @samp
33882@item found
33883This field has either @samp{0} or @samp{1} as the value, depending
33884on whether a matching tracepoint was found.
33885
33886@item traceframe
33887The index of the found traceframe. This field is present iff
33888the @samp{found} field has value of @samp{1}.
33889
33890@item tracepoint
33891The index of the found tracepoint. This field is present iff
33892the @samp{found} field has value of @samp{1}.
33893
33894@item frame
33895The information about the frame corresponding to the found trace
33896frame. This field is present only if a trace frame was found.
cd64ee31 33897@xref{GDB/MI Frame Information}, for description of this field.
18148017
VP
33898
33899@end table
33900
7d13fe92
SS
33901@subsubheading @value{GDBN} Command
33902
33903The corresponding @value{GDBN} command is @samp{tfind}.
33904
18148017
VP
33905@subheading -trace-define-variable
33906@findex -trace-define-variable
33907
33908@subsubheading Synopsis
33909
33910@smallexample
33911 -trace-define-variable @var{name} [ @var{value} ]
33912@end smallexample
33913
33914Create trace variable @var{name} if it does not exist. If
33915@var{value} is specified, sets the initial value of the specified
33916trace variable to that value. Note that the @var{name} should start
33917with the @samp{$} character.
33918
7d13fe92
SS
33919@subsubheading @value{GDBN} Command
33920
33921The corresponding @value{GDBN} command is @samp{tvariable}.
33922
dc673c81
YQ
33923@subheading The @code{-trace-frame-collected} Command
33924@findex -trace-frame-collected
33925
33926@subsubheading Synopsis
33927
33928@smallexample
33929 -trace-frame-collected
33930 [--var-print-values @var{var_pval}]
33931 [--comp-print-values @var{comp_pval}]
33932 [--registers-format @var{regformat}]
33933 [--memory-contents]
33934@end smallexample
33935
33936This command returns the set of collected objects, register names,
33937trace state variable names, memory ranges and computed expressions
33938that have been collected at a particular trace frame. The optional
33939parameters to the command affect the output format in different ways.
33940See the output description table below for more details.
33941
33942The reported names can be used in the normal manner to create
33943varobjs and inspect the objects themselves. The items returned by
33944this command are categorized so that it is clear which is a variable,
33945which is a register, which is a trace state variable, which is a
33946memory range and which is a computed expression.
33947
33948For instance, if the actions were
33949@smallexample
33950collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
33951collect *(int*)0xaf02bef0@@40
33952@end smallexample
33953
33954@noindent
33955the object collected in its entirety would be @code{myVar}. The
33956object @code{myArray} would be partially collected, because only the
33957element at index @code{myIndex} would be collected. The remaining
33958objects would be computed expressions.
33959
33960An example output would be:
33961
33962@smallexample
33963(gdb)
33964-trace-frame-collected
33965^done,
33966 explicit-variables=[@{name="myVar",value="1"@}],
33967 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
33968 @{name="myObj.field",value="0"@},
33969 @{name="myPtr->field",value="1"@},
33970 @{name="myCount + 2",value="3"@},
33971 @{name="$tvar1 + 1",value="43970027"@}],
33972 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
33973 @{number="1",value="0x0"@},
33974 @{number="2",value="0x4"@},
33975 ...
33976 @{number="125",value="0x0"@}],
33977 tvars=[@{name="$tvar1",current="43970026"@}],
33978 memory=[@{address="0x0000000000602264",length="4"@},
33979 @{address="0x0000000000615bc0",length="4"@}]
33980(gdb)
33981@end smallexample
33982
33983Where:
33984
33985@table @code
33986@item explicit-variables
33987The set of objects that have been collected in their entirety (as
33988opposed to collecting just a few elements of an array or a few struct
33989members). For each object, its name and value are printed.
33990The @code{--var-print-values} option affects how or whether the value
33991field is output. If @var{var_pval} is 0, then print only the names;
33992if it is 1, print also their values; and if it is 2, print the name,
33993type and value for simple data types, and the name and type for
33994arrays, structures and unions.
33995
33996@item computed-expressions
33997The set of computed expressions that have been collected at the
33998current trace frame. The @code{--comp-print-values} option affects
33999this set like the @code{--var-print-values} option affects the
34000@code{explicit-variables} set. See above.
34001
34002@item registers
34003The registers that have been collected at the current trace frame.
34004For each register collected, the name and current value are returned.
34005The value is formatted according to the @code{--registers-format}
34006option. See the @command{-data-list-register-values} command for a
34007list of the allowed formats. The default is @samp{x}.
34008
34009@item tvars
34010The trace state variables that have been collected at the current
34011trace frame. For each trace state variable collected, the name and
34012current value are returned.
34013
34014@item memory
34015The set of memory ranges that have been collected at the current trace
34016frame. Its content is a list of tuples. Each tuple represents a
34017collected memory range and has the following fields:
34018
34019@table @code
34020@item address
34021The start address of the memory range, as hexadecimal literal.
34022
34023@item length
34024The length of the memory range, as decimal literal.
34025
34026@item contents
34027The contents of the memory block, in hex. This field is only present
34028if the @code{--memory-contents} option is specified.
34029
34030@end table
34031
34032@end table
34033
34034@subsubheading @value{GDBN} Command
34035
34036There is no corresponding @value{GDBN} command.
34037
34038@subsubheading Example
34039
18148017
VP
34040@subheading -trace-list-variables
34041@findex -trace-list-variables
922fbb7b 34042
18148017 34043@subsubheading Synopsis
922fbb7b 34044
18148017
VP
34045@smallexample
34046 -trace-list-variables
34047@end smallexample
922fbb7b 34048
18148017
VP
34049Return a table of all defined trace variables. Each element of the
34050table has the following fields:
922fbb7b 34051
18148017
VP
34052@table @samp
34053@item name
34054The name of the trace variable. This field is always present.
922fbb7b 34055
18148017
VP
34056@item initial
34057The initial value. This is a 64-bit signed integer. This
34058field is always present.
922fbb7b 34059
18148017
VP
34060@item current
34061The value the trace variable has at the moment. This is a 64-bit
34062signed integer. This field is absent iff current value is
34063not defined, for example if the trace was never run, or is
34064presently running.
922fbb7b 34065
18148017 34066@end table
922fbb7b 34067
7d13fe92
SS
34068@subsubheading @value{GDBN} Command
34069
34070The corresponding @value{GDBN} command is @samp{tvariables}.
34071
18148017 34072@subsubheading Example
922fbb7b 34073
18148017
VP
34074@smallexample
34075(gdb)
34076-trace-list-variables
34077^done,trace-variables=@{nr_rows="1",nr_cols="3",
34078hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
34079 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
34080 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
34081body=[variable=@{name="$trace_timestamp",initial="0"@}
34082 variable=@{name="$foo",initial="10",current="15"@}]@}
34083(gdb)
34084@end smallexample
922fbb7b 34085
18148017
VP
34086@subheading -trace-save
34087@findex -trace-save
922fbb7b 34088
18148017
VP
34089@subsubheading Synopsis
34090
34091@smallexample
99e61eda 34092 -trace-save [ -r ] [ -ctf ] @var{filename}
18148017
VP
34093@end smallexample
34094
34095Saves the collected trace data to @var{filename}. Without the
34096@samp{-r} option, the data is downloaded from the target and saved
34097in a local file. With the @samp{-r} option the target is asked
34098to perform the save.
34099
99e61eda
SM
34100By default, this command will save the trace in the tfile format. You can
34101supply the optional @samp{-ctf} argument to save it the CTF format. See
34102@ref{Trace Files} for more information about CTF.
34103
7d13fe92
SS
34104@subsubheading @value{GDBN} Command
34105
34106The corresponding @value{GDBN} command is @samp{tsave}.
34107
18148017
VP
34108
34109@subheading -trace-start
34110@findex -trace-start
34111
34112@subsubheading Synopsis
34113
34114@smallexample
34115 -trace-start
34116@end smallexample
922fbb7b 34117
be06ba8c 34118Starts a tracing experiment. The result of this command does not
18148017 34119have any fields.
922fbb7b 34120
7d13fe92
SS
34121@subsubheading @value{GDBN} Command
34122
34123The corresponding @value{GDBN} command is @samp{tstart}.
34124
18148017
VP
34125@subheading -trace-status
34126@findex -trace-status
922fbb7b 34127
18148017
VP
34128@subsubheading Synopsis
34129
34130@smallexample
34131 -trace-status
34132@end smallexample
34133
a97153c7 34134Obtains the status of a tracing experiment. The result may include
18148017
VP
34135the following fields:
34136
34137@table @samp
34138
34139@item supported
34140May have a value of either @samp{0}, when no tracing operations are
34141supported, @samp{1}, when all tracing operations are supported, or
34142@samp{file} when examining trace file. In the latter case, examining
34143of trace frame is possible but new tracing experiement cannot be
34144started. This field is always present.
34145
34146@item running
34147May have a value of either @samp{0} or @samp{1} depending on whether
34148tracing experiement is in progress on target. This field is present
34149if @samp{supported} field is not @samp{0}.
34150
34151@item stop-reason
34152Report the reason why the tracing was stopped last time. This field
34153may be absent iff tracing was never stopped on target yet. The
34154value of @samp{request} means the tracing was stopped as result of
34155the @code{-trace-stop} command. The value of @samp{overflow} means
34156the tracing buffer is full. The value of @samp{disconnection} means
34157tracing was automatically stopped when @value{GDBN} has disconnected.
34158The value of @samp{passcount} means tracing was stopped when a
34159tracepoint was passed a maximal number of times for that tracepoint.
34160This field is present if @samp{supported} field is not @samp{0}.
34161
34162@item stopping-tracepoint
34163The number of tracepoint whose passcount as exceeded. This field is
34164present iff the @samp{stop-reason} field has the value of
34165@samp{passcount}.
34166
34167@item frames
87290684
SS
34168@itemx frames-created
34169The @samp{frames} field is a count of the total number of trace frames
34170in the trace buffer, while @samp{frames-created} is the total created
34171during the run, including ones that were discarded, such as when a
34172circular trace buffer filled up. Both fields are optional.
18148017
VP
34173
34174@item buffer-size
34175@itemx buffer-free
34176These fields tell the current size of the tracing buffer and the
87290684 34177remaining space. These fields are optional.
18148017 34178
a97153c7
PA
34179@item circular
34180The value of the circular trace buffer flag. @code{1} means that the
34181trace buffer is circular and old trace frames will be discarded if
34182necessary to make room, @code{0} means that the trace buffer is linear
34183and may fill up.
34184
34185@item disconnected
34186The value of the disconnected tracing flag. @code{1} means that
34187tracing will continue after @value{GDBN} disconnects, @code{0} means
34188that the trace run will stop.
34189
f5911ea1
HAQ
34190@item trace-file
34191The filename of the trace file being examined. This field is
34192optional, and only present when examining a trace file.
34193
18148017
VP
34194@end table
34195
7d13fe92
SS
34196@subsubheading @value{GDBN} Command
34197
34198The corresponding @value{GDBN} command is @samp{tstatus}.
34199
18148017
VP
34200@subheading -trace-stop
34201@findex -trace-stop
34202
34203@subsubheading Synopsis
34204
34205@smallexample
34206 -trace-stop
34207@end smallexample
922fbb7b 34208
18148017
VP
34209Stops a tracing experiment. The result of this command has the same
34210fields as @code{-trace-status}, except that the @samp{supported} and
34211@samp{running} fields are not output.
922fbb7b 34212
7d13fe92
SS
34213@subsubheading @value{GDBN} Command
34214
34215The corresponding @value{GDBN} command is @samp{tstop}.
34216
922fbb7b 34217
a2c02241
NR
34218@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34219@node GDB/MI Symbol Query
34220@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
34221
34222
9901a55b 34223@ignore
a2c02241
NR
34224@subheading The @code{-symbol-info-address} Command
34225@findex -symbol-info-address
922fbb7b
AC
34226
34227@subsubheading Synopsis
34228
34229@smallexample
a2c02241 34230 -symbol-info-address @var{symbol}
922fbb7b
AC
34231@end smallexample
34232
a2c02241 34233Describe where @var{symbol} is stored.
922fbb7b
AC
34234
34235@subsubheading @value{GDBN} Command
34236
a2c02241 34237The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
34238
34239@subsubheading Example
34240N.A.
34241
34242
a2c02241
NR
34243@subheading The @code{-symbol-info-file} Command
34244@findex -symbol-info-file
922fbb7b
AC
34245
34246@subsubheading Synopsis
34247
34248@smallexample
a2c02241 34249 -symbol-info-file
922fbb7b
AC
34250@end smallexample
34251
a2c02241 34252Show the file for the symbol.
922fbb7b 34253
a2c02241 34254@subsubheading @value{GDBN} Command
922fbb7b 34255
a2c02241
NR
34256There's no equivalent @value{GDBN} command. @code{gdbtk} has
34257@samp{gdb_find_file}.
922fbb7b
AC
34258
34259@subsubheading Example
34260N.A.
7dc42066
AB
34261@end ignore
34262
34263@subheading The @code{-symbol-info-functions} Command
34264@findex -symbol-info-functions
34265@anchor{-symbol-info-functions}
34266
34267@subsubheading Synopsis
34268
34269@smallexample
34270 -symbol-info-functions [--include-nondebug]
34271 [--type @var{type_regexp}]
34272 [--name @var{name_regexp}]
c2512106 34273 [--max-results @var{limit}]
7dc42066
AB
34274@end smallexample
34275
34276@noindent
34277Return a list containing the names and types for all global functions
34278taken from the debug information. The functions are grouped by source
34279file, and shown with the line number on which each function is
34280defined.
922fbb7b 34281
7dc42066
AB
34282The @code{--include-nondebug} option causes the output to include
34283code symbols from the symbol table.
922fbb7b 34284
7dc42066
AB
34285The options @code{--type} and @code{--name} allow the symbols returned
34286to be filtered based on either the name of the function, or the type
34287signature of the function.
34288
c2512106
AB
34289The option @code{--max-results} restricts the command to return no
34290more than @var{limit} results. If exactly @var{limit} results are
34291returned then there might be additional results available if a higher
34292limit is used.
34293
7dc42066
AB
34294@subsubheading @value{GDBN} Command
34295
34296The corresponding @value{GDBN} command is @samp{info functions}.
34297
34298@subsubheading Example
34299@smallexample
34300@group
34301(gdb)
34302-symbol-info-functions
34303^done,symbols=
34304 @{debug=
34305 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34306 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34307 symbols=[@{line="36", name="f4", type="void (int *)",
34308 description="void f4(int *);"@},
34309 @{line="42", name="main", type="int ()",
34310 description="int main();"@},
34311 @{line="30", name="f1", type="my_int_t (int, int)",
34312 description="static my_int_t f1(int, int);"@}]@},
34313 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34314 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34315 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34316 description="float f2(another_float_t);"@},
34317 @{line="39", name="f3", type="int (another_int_t)",
34318 description="int f3(another_int_t);"@},
34319 @{line="27", name="f1", type="another_float_t (int)",
34320 description="static another_float_t f1(int);"@}]@}]@}
34321@end group
34322@group
34323(gdb)
34324-symbol-info-functions --name f1
34325^done,symbols=
34326 @{debug=
34327 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34328 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34329 symbols=[@{line="30", name="f1", type="my_int_t (int, int)",
34330 description="static my_int_t f1(int, int);"@}]@},
34331 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34332 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34333 symbols=[@{line="27", name="f1", type="another_float_t (int)",
34334 description="static another_float_t f1(int);"@}]@}]@}
34335@end group
34336@group
34337(gdb)
34338-symbol-info-functions --type void
34339^done,symbols=
34340 @{debug=
34341 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34342 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34343 symbols=[@{line="36", name="f4", type="void (int *)",
34344 description="void f4(int *);"@}]@}]@}
34345@end group
34346@group
34347(gdb)
34348-symbol-info-functions --include-nondebug
34349^done,symbols=
34350 @{debug=
34351 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34352 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34353 symbols=[@{line="36", name="f4", type="void (int *)",
34354 description="void f4(int *);"@},
34355 @{line="42", name="main", type="int ()",
34356 description="int main();"@},
34357 @{line="30", name="f1", type="my_int_t (int, int)",
34358 description="static my_int_t f1(int, int);"@}]@},
34359 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34360 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34361 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34362 description="float f2(another_float_t);"@},
34363 @{line="39", name="f3", type="int (another_int_t)",
34364 description="int f3(another_int_t);"@},
34365 @{line="27", name="f1", type="another_float_t (int)",
34366 description="static another_float_t f1(int);"@}]@}],
34367 nondebug=
34368 [@{address="0x0000000000400398",name="_init"@},
34369 @{address="0x00000000004003b0",name="_start"@},
34370 ...
34371 ]@}
34372@end group
34373@end smallexample
34374
293b38d6
AB
34375@subheading The @code{-symbol-info-module-functions} Command
34376@findex -symbol-info-module-functions
34377@anchor{-symbol-info-module-functions}
34378
34379@subsubheading Synopsis
34380
34381@smallexample
34382 -symbol-info-module-functions [--module @var{module_regexp}]
34383 [--name @var{name_regexp}]
34384 [--type @var{type_regexp}]
34385@end smallexample
34386
34387@noindent
34388Return a list containing the names of all known functions within all
34389know Fortran modules. The functions are grouped by source file and
34390containing module, and shown with the line number on which each
34391function is defined.
34392
34393The option @code{--module} only returns results for modules matching
34394@var{module_regexp}. The option @code{--name} only returns functions
34395whose name matches @var{name_regexp}, and @code{--type} only returns
34396functions whose type matches @var{type_regexp}.
34397
34398@subsubheading @value{GDBN} Command
34399
34400The corresponding @value{GDBN} command is @samp{info module functions}.
34401
34402@subsubheading Example
34403
34404@smallexample
34405@group
34406(gdb)
34407-symbol-info-module-functions
34408^done,symbols=
34409 [@{module="mod1",
34410 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34411 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34412 symbols=[@{line="21",name="mod1::check_all",type="void (void)",
34413 description="void mod1::check_all(void);"@}]@}]@},
34414 @{module="mod2",
34415 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34416 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34417 symbols=[@{line="30",name="mod2::check_var_i",type="void (void)",
34418 description="void mod2::check_var_i(void);"@}]@}]@},
34419 @{module="mod3",
34420 files=[@{filename="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34421 fullname="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34422 symbols=[@{line="21",name="mod3::check_all",type="void (void)",
34423 description="void mod3::check_all(void);"@},
34424 @{line="27",name="mod3::check_mod2",type="void (void)",
34425 description="void mod3::check_mod2(void);"@}]@}]@},
34426 @{module="modmany",
34427 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34428 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34429 symbols=[@{line="35",name="modmany::check_some",type="void (void)",
34430 description="void modmany::check_some(void);"@}]@}]@},
34431 @{module="moduse",
34432 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34433 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34434 symbols=[@{line="44",name="moduse::check_all",type="void (void)",
34435 description="void moduse::check_all(void);"@},
34436 @{line="49",name="moduse::check_var_x",type="void (void)",
34437 description="void moduse::check_var_x(void);"@}]@}]@}]
34438@end group
34439@end smallexample
34440
34441@subheading The @code{-symbol-info-module-variables} Command
34442@findex -symbol-info-module-variables
34443@anchor{-symbol-info-module-variables}
34444
34445@subsubheading Synopsis
34446
34447@smallexample
34448 -symbol-info-module-variables [--module @var{module_regexp}]
34449 [--name @var{name_regexp}]
34450 [--type @var{type_regexp}]
34451@end smallexample
34452
34453@noindent
34454Return a list containing the names of all known variables within all
34455know Fortran modules. The variables are grouped by source file and
34456containing module, and shown with the line number on which each
34457variable is defined.
34458
34459The option @code{--module} only returns results for modules matching
34460@var{module_regexp}. The option @code{--name} only returns variables
34461whose name matches @var{name_regexp}, and @code{--type} only returns
34462variables whose type matches @var{type_regexp}.
34463
34464@subsubheading @value{GDBN} Command
34465
34466The corresponding @value{GDBN} command is @samp{info module variables}.
34467
34468@subsubheading Example
34469
34470@smallexample
34471@group
34472(gdb)
34473-symbol-info-module-variables
34474^done,symbols=
34475 [@{module="mod1",
34476 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34477 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34478 symbols=[@{line="18",name="mod1::var_const",type="integer(kind=4)",
34479 description="integer(kind=4) mod1::var_const;"@},
34480 @{line="17",name="mod1::var_i",type="integer(kind=4)",
34481 description="integer(kind=4) mod1::var_i;"@}]@}]@},
34482 @{module="mod2",
34483 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34484 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34485 symbols=[@{line="28",name="mod2::var_i",type="integer(kind=4)",
34486 description="integer(kind=4) mod2::var_i;"@}]@}]@},
34487 @{module="mod3",
34488 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34489 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34490 symbols=[@{line="18",name="mod3::mod1",type="integer(kind=4)",
34491 description="integer(kind=4) mod3::mod1;"@},
34492 @{line="17",name="mod3::mod2",type="integer(kind=4)",
34493 description="integer(kind=4) mod3::mod2;"@},
34494 @{line="19",name="mod3::var_i",type="integer(kind=4)",
34495 description="integer(kind=4) mod3::var_i;"@}]@}]@},
34496 @{module="modmany",
34497 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34498 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34499 symbols=[@{line="33",name="modmany::var_a",type="integer(kind=4)",
34500 description="integer(kind=4) modmany::var_a;"@},
34501 @{line="33",name="modmany::var_b",type="integer(kind=4)",
34502 description="integer(kind=4) modmany::var_b;"@},
34503 @{line="33",name="modmany::var_c",type="integer(kind=4)",
34504 description="integer(kind=4) modmany::var_c;"@},
34505 @{line="33",name="modmany::var_i",type="integer(kind=4)",
34506 description="integer(kind=4) modmany::var_i;"@}]@}]@},
34507 @{module="moduse",
34508 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34509 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34510 symbols=[@{line="42",name="moduse::var_x",type="integer(kind=4)",
34511 description="integer(kind=4) moduse::var_x;"@},
34512 @{line="42",name="moduse::var_y",type="integer(kind=4)",
34513 description="integer(kind=4) moduse::var_y;"@}]@}]@}]
34514@end group
34515@end smallexample
34516
db5960b4
AB
34517@subheading The @code{-symbol-info-modules} Command
34518@findex -symbol-info-modules
34519@anchor{-symbol-info-modules}
34520
34521@subsubheading Synopsis
34522
34523@smallexample
34524 -symbol-info-modules [--name @var{name_regexp}]
c2512106
AB
34525 [--max-results @var{limit}]
34526
db5960b4
AB
34527@end smallexample
34528
34529@noindent
34530Return a list containing the names of all known Fortran modules. The
34531modules are grouped by source file, and shown with the line number on
34532which each modules is defined.
34533
34534The option @code{--name} allows the modules returned to be filtered
34535based the name of the module.
34536
c2512106
AB
34537The option @code{--max-results} restricts the command to return no
34538more than @var{limit} results. If exactly @var{limit} results are
34539returned then there might be additional results available if a higher
34540limit is used.
34541
db5960b4
AB
34542@subsubheading @value{GDBN} Command
34543
34544The corresponding @value{GDBN} command is @samp{info modules}.
34545
34546@subsubheading Example
34547@smallexample
34548@group
34549(gdb)
34550-symbol-info-modules
34551^done,symbols=
34552 @{debug=
34553 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34554 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34555 symbols=[@{line="16",name="mod1"@},
34556 @{line="22",name="mod2"@}]@},
34557 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34558 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34559 symbols=[@{line="16",name="mod3"@},
34560 @{line="22",name="modmany"@},
34561 @{line="26",name="moduse"@}]@}]@}
34562@end group
34563@group
34564(gdb)
34565-symbol-info-modules --name mod[123]
34566^done,symbols=
34567 @{debug=
34568 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34569 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34570 symbols=[@{line="16",name="mod1"@},
34571 @{line="22",name="mod2"@}]@},
34572 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34573 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34574 symbols=[@{line="16",name="mod3"@}]@}]@}
34575@end group
34576@end smallexample
34577
7dc42066
AB
34578@subheading The @code{-symbol-info-types} Command
34579@findex -symbol-info-types
34580@anchor{-symbol-info-types}
922fbb7b
AC
34581
34582@subsubheading Synopsis
34583
34584@smallexample
7dc42066 34585 -symbol-info-types [--name @var{name_regexp}]
c2512106
AB
34586 [--max-results @var{limit}]
34587
922fbb7b
AC
34588@end smallexample
34589
7dc42066
AB
34590@noindent
34591Return a list of all defined types. The types are grouped by source
34592file, and shown with the line number on which each user defined type
34593is defined. Some base types are not defined in the source code but
34594are added to the debug information by the compiler, for example
34595@code{int}, @code{float}, etc.; these types do not have an associated
34596line number.
34597
34598The option @code{--name} allows the list of types returned to be
34599filtered by name.
922fbb7b 34600
c2512106
AB
34601The option @code{--max-results} restricts the command to return no
34602more than @var{limit} results. If exactly @var{limit} results are
34603returned then there might be additional results available if a higher
34604limit is used.
34605
922fbb7b
AC
34606@subsubheading @value{GDBN} Command
34607
7dc42066 34608The corresponding @value{GDBN} command is @samp{info types}.
922fbb7b
AC
34609
34610@subsubheading Example
7dc42066
AB
34611@smallexample
34612@group
34613(gdb)
34614-symbol-info-types
34615^done,symbols=
34616 @{debug=
34617 [@{filename="gdb.mi/mi-sym-info-1.c",
34618 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34619 symbols=[@{name="float"@},
34620 @{name="int"@},
34621 @{line="27",name="typedef int my_int_t;"@}]@},
34622 @{filename="gdb.mi/mi-sym-info-2.c",
34623 fullname="/project/gdb.mi/mi-sym-info-2.c",
34624 symbols=[@{line="24",name="typedef float another_float_t;"@},
34625 @{line="23",name="typedef int another_int_t;"@},
34626 @{name="float"@},
34627 @{name="int"@}]@}]@}
34628@end group
34629@group
34630(gdb)
34631-symbol-info-types --name _int_
34632^done,symbols=
34633 @{debug=
34634 [@{filename="gdb.mi/mi-sym-info-1.c",
34635 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34636 symbols=[@{line="27",name="typedef int my_int_t;"@}]@},
34637 @{filename="gdb.mi/mi-sym-info-2.c",
34638 fullname="/project/gdb.mi/mi-sym-info-2.c",
34639 symbols=[@{line="23",name="typedef int another_int_t;"@}]@}]@}
34640@end group
34641@end smallexample
34642
34643@subheading The @code{-symbol-info-variables} Command
34644@findex -symbol-info-variables
34645@anchor{-symbol-info-variables}
34646
34647@subsubheading Synopsis
34648
34649@smallexample
34650 -symbol-info-variables [--include-nondebug]
34651 [--type @var{type_regexp}]
34652 [--name @var{name_regexp}]
c2512106
AB
34653 [--max-results @var{limit}]
34654
7dc42066
AB
34655@end smallexample
34656
34657@noindent
34658Return a list containing the names and types for all global variables
34659taken from the debug information. The variables are grouped by source
34660file, and shown with the line number on which each variable is
34661defined.
34662
34663The @code{--include-nondebug} option causes the output to include
34664data symbols from the symbol table.
34665
34666The options @code{--type} and @code{--name} allow the symbols returned
34667to be filtered based on either the name of the variable, or the type
34668of the variable.
34669
c2512106
AB
34670The option @code{--max-results} restricts the command to return no
34671more than @var{limit} results. If exactly @var{limit} results are
34672returned then there might be additional results available if a higher
34673limit is used.
34674
7dc42066 34675@subsubheading @value{GDBN} Command
922fbb7b 34676
7dc42066 34677The corresponding @value{GDBN} command is @samp{info variables}.
922fbb7b 34678
7dc42066
AB
34679@subsubheading Example
34680@smallexample
34681@group
34682(gdb)
34683-symbol-info-variables
34684^done,symbols=
34685 @{debug=
34686 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34687 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34688 symbols=[@{line="25",name="global_f1",type="float",
34689 description="static float global_f1;"@},
34690 @{line="24",name="global_i1",type="int",
34691 description="static int global_i1;"@}]@},
34692 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34693 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34694 symbols=[@{line="21",name="global_f2",type="int",
34695 description="int global_f2;"@},
34696 @{line="20",name="global_i2",type="int",
34697 description="int global_i2;"@},
34698 @{line="19",name="global_f1",type="float",
34699 description="static float global_f1;"@},
34700 @{line="18",name="global_i1",type="int",
34701 description="static int global_i1;"@}]@}]@}
34702@end group
34703@group
34704(gdb)
34705-symbol-info-variables --name f1
34706^done,symbols=
34707 @{debug=
34708 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34709 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34710 symbols=[@{line="25",name="global_f1",type="float",
34711 description="static float global_f1;"@}]@},
34712 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34713 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34714 symbols=[@{line="19",name="global_f1",type="float",
34715 description="static float global_f1;"@}]@}]@}
34716@end group
34717@group
34718(gdb)
34719-symbol-info-variables --type float
34720^done,symbols=
34721 @{debug=
34722 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34723 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34724 symbols=[@{line="25",name="global_f1",type="float",
34725 description="static float global_f1;"@}]@},
34726 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34727 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34728 symbols=[@{line="19",name="global_f1",type="float",
34729 description="static float global_f1;"@}]@}]@}
34730@end group
34731@group
34732(gdb)
34733-symbol-info-variables --include-nondebug
34734^done,symbols=
34735 @{debug=
34736 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34737 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34738 symbols=[@{line="25",name="global_f1",type="float",
34739 description="static float global_f1;"@},
34740 @{line="24",name="global_i1",type="int",
34741 description="static int global_i1;"@}]@},
34742 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34743 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34744 symbols=[@{line="21",name="global_f2",type="int",
34745 description="int global_f2;"@},
34746 @{line="20",name="global_i2",type="int",
34747 description="int global_i2;"@},
34748 @{line="19",name="global_f1",type="float",
34749 description="static float global_f1;"@},
34750 @{line="18",name="global_i1",type="int",
34751 description="static int global_i1;"@}]@}],
34752 nondebug=
34753 [@{address="0x00000000004005d0",name="_IO_stdin_used"@},
34754 @{address="0x00000000004005d8",name="__dso_handle"@}
34755 ...
34756 ]@}
34757@end group
34758@end smallexample
34759
34760@ignore
a2c02241
NR
34761@subheading The @code{-symbol-info-line} Command
34762@findex -symbol-info-line
922fbb7b
AC
34763
34764@subsubheading Synopsis
34765
34766@smallexample
a2c02241 34767 -symbol-info-line
922fbb7b
AC
34768@end smallexample
34769
a2c02241 34770Show the core addresses of the code for a source line.
922fbb7b 34771
a2c02241 34772@subsubheading @value{GDBN} Command
922fbb7b 34773
a2c02241
NR
34774The corresponding @value{GDBN} command is @samp{info line}.
34775@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
34776
34777@subsubheading Example
a2c02241 34778N.A.
922fbb7b
AC
34779
34780
a2c02241
NR
34781@subheading The @code{-symbol-info-symbol} Command
34782@findex -symbol-info-symbol
07f31aa6
DJ
34783
34784@subsubheading Synopsis
34785
a2c02241
NR
34786@smallexample
34787 -symbol-info-symbol @var{addr}
34788@end smallexample
07f31aa6 34789
a2c02241 34790Describe what symbol is at location @var{addr}.
07f31aa6 34791
a2c02241 34792@subsubheading @value{GDBN} Command
07f31aa6 34793
a2c02241 34794The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
34795
34796@subsubheading Example
a2c02241 34797N.A.
07f31aa6
DJ
34798
34799
a2c02241
NR
34800@subheading The @code{-symbol-list-functions} Command
34801@findex -symbol-list-functions
922fbb7b
AC
34802
34803@subsubheading Synopsis
34804
34805@smallexample
a2c02241 34806 -symbol-list-functions
922fbb7b
AC
34807@end smallexample
34808
a2c02241 34809List the functions in the executable.
922fbb7b
AC
34810
34811@subsubheading @value{GDBN} Command
34812
a2c02241
NR
34813@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
34814@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
34815
34816@subsubheading Example
a2c02241 34817N.A.
9901a55b 34818@end ignore
922fbb7b
AC
34819
34820
a2c02241
NR
34821@subheading The @code{-symbol-list-lines} Command
34822@findex -symbol-list-lines
922fbb7b
AC
34823
34824@subsubheading Synopsis
34825
34826@smallexample
a2c02241 34827 -symbol-list-lines @var{filename}
922fbb7b
AC
34828@end smallexample
34829
a2c02241
NR
34830Print the list of lines that contain code and their associated program
34831addresses for the given source filename. The entries are sorted in
34832ascending PC order.
922fbb7b
AC
34833
34834@subsubheading @value{GDBN} Command
34835
a2c02241 34836There is no corresponding @value{GDBN} command.
922fbb7b
AC
34837
34838@subsubheading Example
a2c02241 34839@smallexample
594fe323 34840(gdb)
a2c02241
NR
34841-symbol-list-lines basics.c
34842^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 34843(gdb)
a2c02241 34844@end smallexample
922fbb7b
AC
34845
34846
9901a55b 34847@ignore
a2c02241
NR
34848@subheading The @code{-symbol-list-types} Command
34849@findex -symbol-list-types
922fbb7b
AC
34850
34851@subsubheading Synopsis
34852
34853@smallexample
a2c02241 34854 -symbol-list-types
922fbb7b
AC
34855@end smallexample
34856
a2c02241 34857List all the type names.
922fbb7b
AC
34858
34859@subsubheading @value{GDBN} Command
34860
a2c02241
NR
34861The corresponding commands are @samp{info types} in @value{GDBN},
34862@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
34863
34864@subsubheading Example
34865N.A.
34866
34867
a2c02241
NR
34868@subheading The @code{-symbol-list-variables} Command
34869@findex -symbol-list-variables
922fbb7b
AC
34870
34871@subsubheading Synopsis
34872
34873@smallexample
a2c02241 34874 -symbol-list-variables
922fbb7b
AC
34875@end smallexample
34876
a2c02241 34877List all the global and static variable names.
922fbb7b
AC
34878
34879@subsubheading @value{GDBN} Command
34880
a2c02241 34881@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
34882
34883@subsubheading Example
34884N.A.
34885
34886
a2c02241
NR
34887@subheading The @code{-symbol-locate} Command
34888@findex -symbol-locate
922fbb7b
AC
34889
34890@subsubheading Synopsis
34891
34892@smallexample
a2c02241 34893 -symbol-locate
922fbb7b
AC
34894@end smallexample
34895
922fbb7b
AC
34896@subsubheading @value{GDBN} Command
34897
a2c02241 34898@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
34899
34900@subsubheading Example
34901N.A.
34902
34903
a2c02241
NR
34904@subheading The @code{-symbol-type} Command
34905@findex -symbol-type
922fbb7b
AC
34906
34907@subsubheading Synopsis
34908
34909@smallexample
a2c02241 34910 -symbol-type @var{variable}
922fbb7b
AC
34911@end smallexample
34912
a2c02241 34913Show type of @var{variable}.
922fbb7b 34914
a2c02241 34915@subsubheading @value{GDBN} Command
922fbb7b 34916
a2c02241
NR
34917The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
34918@samp{gdb_obj_variable}.
34919
34920@subsubheading Example
34921N.A.
9901a55b 34922@end ignore
a2c02241
NR
34923
34924
34925@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34926@node GDB/MI File Commands
34927@section @sc{gdb/mi} File Commands
34928
34929This section describes the GDB/MI commands to specify executable file names
34930and to read in and obtain symbol table information.
34931
34932@subheading The @code{-file-exec-and-symbols} Command
34933@findex -file-exec-and-symbols
34934
34935@subsubheading Synopsis
922fbb7b
AC
34936
34937@smallexample
a2c02241 34938 -file-exec-and-symbols @var{file}
922fbb7b
AC
34939@end smallexample
34940
a2c02241
NR
34941Specify the executable file to be debugged. This file is the one from
34942which the symbol table is also read. If no file is specified, the
34943command clears the executable and symbol information. If breakpoints
34944are set when using this command with no arguments, @value{GDBN} will produce
34945error messages. Otherwise, no output is produced, except a completion
34946notification.
34947
922fbb7b
AC
34948@subsubheading @value{GDBN} Command
34949
a2c02241 34950The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
34951
34952@subsubheading Example
34953
34954@smallexample
594fe323 34955(gdb)
a2c02241
NR
34956-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
34957^done
594fe323 34958(gdb)
922fbb7b
AC
34959@end smallexample
34960
922fbb7b 34961
a2c02241
NR
34962@subheading The @code{-file-exec-file} Command
34963@findex -file-exec-file
922fbb7b
AC
34964
34965@subsubheading Synopsis
34966
34967@smallexample
a2c02241 34968 -file-exec-file @var{file}
922fbb7b
AC
34969@end smallexample
34970
a2c02241
NR
34971Specify the executable file to be debugged. Unlike
34972@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
34973from this file. If used without argument, @value{GDBN} clears the information
34974about the executable file. No output is produced, except a completion
34975notification.
922fbb7b 34976
a2c02241
NR
34977@subsubheading @value{GDBN} Command
34978
34979The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
34980
34981@subsubheading Example
a2c02241
NR
34982
34983@smallexample
594fe323 34984(gdb)
a2c02241
NR
34985-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
34986^done
594fe323 34987(gdb)
a2c02241 34988@end smallexample
922fbb7b
AC
34989
34990
9901a55b 34991@ignore
a2c02241
NR
34992@subheading The @code{-file-list-exec-sections} Command
34993@findex -file-list-exec-sections
922fbb7b
AC
34994
34995@subsubheading Synopsis
34996
34997@smallexample
a2c02241 34998 -file-list-exec-sections
922fbb7b
AC
34999@end smallexample
35000
a2c02241
NR
35001List the sections of the current executable file.
35002
922fbb7b
AC
35003@subsubheading @value{GDBN} Command
35004
a2c02241
NR
35005The @value{GDBN} command @samp{info file} shows, among the rest, the same
35006information as this command. @code{gdbtk} has a corresponding command
35007@samp{gdb_load_info}.
922fbb7b
AC
35008
35009@subsubheading Example
35010N.A.
9901a55b 35011@end ignore
922fbb7b
AC
35012
35013
a2c02241
NR
35014@subheading The @code{-file-list-exec-source-file} Command
35015@findex -file-list-exec-source-file
922fbb7b
AC
35016
35017@subsubheading Synopsis
35018
35019@smallexample
a2c02241 35020 -file-list-exec-source-file
922fbb7b
AC
35021@end smallexample
35022
a2c02241 35023List the line number, the current source file, and the absolute path
44288b44
NR
35024to the current source file for the current executable. The macro
35025information field has a value of @samp{1} or @samp{0} depending on
35026whether or not the file includes preprocessor macro information.
922fbb7b
AC
35027
35028@subsubheading @value{GDBN} Command
35029
a2c02241 35030The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
35031
35032@subsubheading Example
35033
922fbb7b 35034@smallexample
594fe323 35035(gdb)
a2c02241 35036123-file-list-exec-source-file
44288b44 35037123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
594fe323 35038(gdb)
922fbb7b
AC
35039@end smallexample
35040
35041
a2c02241
NR
35042@subheading The @code{-file-list-exec-source-files} Command
35043@findex -file-list-exec-source-files
922fbb7b
AC
35044
35045@subsubheading Synopsis
35046
35047@smallexample
a2c02241 35048 -file-list-exec-source-files
922fbb7b
AC
35049@end smallexample
35050
a2c02241
NR
35051List the source files for the current executable.
35052
f35a17b5
JK
35053It will always output both the filename and fullname (absolute file
35054name) of a source file.
922fbb7b
AC
35055
35056@subsubheading @value{GDBN} Command
35057
a2c02241
NR
35058The @value{GDBN} equivalent is @samp{info sources}.
35059@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
35060
35061@subsubheading Example
922fbb7b 35062@smallexample
594fe323 35063(gdb)
a2c02241
NR
35064-file-list-exec-source-files
35065^done,files=[
35066@{file=foo.c,fullname=/home/foo.c@},
35067@{file=/home/bar.c,fullname=/home/bar.c@},
35068@{file=gdb_could_not_find_fullpath.c@}]
594fe323 35069(gdb)
922fbb7b
AC
35070@end smallexample
35071
a2c02241
NR
35072@subheading The @code{-file-list-shared-libraries} Command
35073@findex -file-list-shared-libraries
922fbb7b 35074
a2c02241 35075@subsubheading Synopsis
922fbb7b 35076
a2c02241 35077@smallexample
51457a05 35078 -file-list-shared-libraries [ @var{regexp} ]
a2c02241 35079@end smallexample
922fbb7b 35080
a2c02241 35081List the shared libraries in the program.
51457a05
MAL
35082With a regular expression @var{regexp}, only those libraries whose
35083names match @var{regexp} are listed.
922fbb7b 35084
a2c02241 35085@subsubheading @value{GDBN} Command
922fbb7b 35086
51457a05
MAL
35087The corresponding @value{GDBN} command is @samp{info shared}. The fields
35088have a similar meaning to the @code{=library-loaded} notification.
35089The @code{ranges} field specifies the multiple segments belonging to this
35090library. Each range has the following fields:
35091
35092@table @samp
35093@item from
35094The address defining the inclusive lower bound of the segment.
35095@item to
35096The address defining the exclusive upper bound of the segment.
35097@end table
922fbb7b 35098
a2c02241 35099@subsubheading Example
51457a05
MAL
35100@smallexample
35101(gdb)
35102-file-list-exec-source-files
35103^done,shared-libraries=[
35104@{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"@}]@},
35105@{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"@}]@}]
35106(gdb)
35107@end smallexample
922fbb7b
AC
35108
35109
51457a05 35110@ignore
a2c02241
NR
35111@subheading The @code{-file-list-symbol-files} Command
35112@findex -file-list-symbol-files
922fbb7b 35113
a2c02241 35114@subsubheading Synopsis
922fbb7b 35115
a2c02241
NR
35116@smallexample
35117 -file-list-symbol-files
35118@end smallexample
922fbb7b 35119
a2c02241 35120List symbol files.
922fbb7b 35121
a2c02241 35122@subsubheading @value{GDBN} Command
922fbb7b 35123
a2c02241 35124The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 35125
a2c02241
NR
35126@subsubheading Example
35127N.A.
9901a55b 35128@end ignore
922fbb7b 35129
922fbb7b 35130
a2c02241
NR
35131@subheading The @code{-file-symbol-file} Command
35132@findex -file-symbol-file
922fbb7b 35133
a2c02241 35134@subsubheading Synopsis
922fbb7b 35135
a2c02241
NR
35136@smallexample
35137 -file-symbol-file @var{file}
35138@end smallexample
922fbb7b 35139
a2c02241
NR
35140Read symbol table info from the specified @var{file} argument. When
35141used without arguments, clears @value{GDBN}'s symbol table info. No output is
35142produced, except for a completion notification.
922fbb7b 35143
a2c02241 35144@subsubheading @value{GDBN} Command
922fbb7b 35145
a2c02241 35146The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 35147
a2c02241 35148@subsubheading Example
922fbb7b 35149
a2c02241 35150@smallexample
594fe323 35151(gdb)
a2c02241
NR
35152-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35153^done
594fe323 35154(gdb)
a2c02241 35155@end smallexample
922fbb7b 35156
a2c02241 35157@ignore
a2c02241
NR
35158@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35159@node GDB/MI Memory Overlay Commands
35160@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 35161
a2c02241 35162The memory overlay commands are not implemented.
922fbb7b 35163
a2c02241 35164@c @subheading -overlay-auto
922fbb7b 35165
a2c02241 35166@c @subheading -overlay-list-mapping-state
922fbb7b 35167
a2c02241 35168@c @subheading -overlay-list-overlays
922fbb7b 35169
a2c02241 35170@c @subheading -overlay-map
922fbb7b 35171
a2c02241 35172@c @subheading -overlay-off
922fbb7b 35173
a2c02241 35174@c @subheading -overlay-on
922fbb7b 35175
a2c02241 35176@c @subheading -overlay-unmap
922fbb7b 35177
a2c02241
NR
35178@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35179@node GDB/MI Signal Handling Commands
35180@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 35181
a2c02241 35182Signal handling commands are not implemented.
922fbb7b 35183
a2c02241 35184@c @subheading -signal-handle
922fbb7b 35185
a2c02241 35186@c @subheading -signal-list-handle-actions
922fbb7b 35187
a2c02241
NR
35188@c @subheading -signal-list-signal-types
35189@end ignore
922fbb7b 35190
922fbb7b 35191
a2c02241
NR
35192@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35193@node GDB/MI Target Manipulation
35194@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
35195
35196
a2c02241
NR
35197@subheading The @code{-target-attach} Command
35198@findex -target-attach
922fbb7b
AC
35199
35200@subsubheading Synopsis
35201
35202@smallexample
c3b108f7 35203 -target-attach @var{pid} | @var{gid} | @var{file}
922fbb7b
AC
35204@end smallexample
35205
c3b108f7
VP
35206Attach to a process @var{pid} or a file @var{file} outside of
35207@value{GDBN}, or a thread group @var{gid}. If attaching to a thread
35208group, the id previously returned by
35209@samp{-list-thread-groups --available} must be used.
922fbb7b 35210
79a6e687 35211@subsubheading @value{GDBN} Command
922fbb7b 35212
a2c02241 35213The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 35214
a2c02241 35215@subsubheading Example
b56e7235
VP
35216@smallexample
35217(gdb)
35218-target-attach 34
35219=thread-created,id="1"
5ae4183a 35220*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
b56e7235
VP
35221^done
35222(gdb)
35223@end smallexample
a2c02241 35224
9901a55b 35225@ignore
a2c02241
NR
35226@subheading The @code{-target-compare-sections} Command
35227@findex -target-compare-sections
922fbb7b
AC
35228
35229@subsubheading Synopsis
35230
35231@smallexample
a2c02241 35232 -target-compare-sections [ @var{section} ]
922fbb7b
AC
35233@end smallexample
35234
a2c02241
NR
35235Compare data of section @var{section} on target to the exec file.
35236Without the argument, all sections are compared.
922fbb7b 35237
a2c02241 35238@subsubheading @value{GDBN} Command
922fbb7b 35239
a2c02241 35240The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 35241
a2c02241
NR
35242@subsubheading Example
35243N.A.
9901a55b 35244@end ignore
a2c02241
NR
35245
35246
35247@subheading The @code{-target-detach} Command
35248@findex -target-detach
922fbb7b
AC
35249
35250@subsubheading Synopsis
35251
35252@smallexample
c3b108f7 35253 -target-detach [ @var{pid} | @var{gid} ]
922fbb7b
AC
35254@end smallexample
35255
a2c02241 35256Detach from the remote target which normally resumes its execution.
c3b108f7
VP
35257If either @var{pid} or @var{gid} is specified, detaches from either
35258the specified process, or specified thread group. There's no output.
a2c02241 35259
79a6e687 35260@subsubheading @value{GDBN} Command
a2c02241
NR
35261
35262The corresponding @value{GDBN} command is @samp{detach}.
35263
35264@subsubheading Example
922fbb7b
AC
35265
35266@smallexample
594fe323 35267(gdb)
a2c02241
NR
35268-target-detach
35269^done
594fe323 35270(gdb)
922fbb7b
AC
35271@end smallexample
35272
35273
a2c02241
NR
35274@subheading The @code{-target-disconnect} Command
35275@findex -target-disconnect
922fbb7b
AC
35276
35277@subsubheading Synopsis
35278
123dc839 35279@smallexample
a2c02241 35280 -target-disconnect
123dc839 35281@end smallexample
922fbb7b 35282
a2c02241
NR
35283Disconnect from the remote target. There's no output and the target is
35284generally not resumed.
35285
79a6e687 35286@subsubheading @value{GDBN} Command
a2c02241
NR
35287
35288The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
35289
35290@subsubheading Example
922fbb7b
AC
35291
35292@smallexample
594fe323 35293(gdb)
a2c02241
NR
35294-target-disconnect
35295^done
594fe323 35296(gdb)
922fbb7b
AC
35297@end smallexample
35298
35299
a2c02241
NR
35300@subheading The @code{-target-download} Command
35301@findex -target-download
922fbb7b
AC
35302
35303@subsubheading Synopsis
35304
35305@smallexample
a2c02241 35306 -target-download
922fbb7b
AC
35307@end smallexample
35308
a2c02241
NR
35309Loads the executable onto the remote target.
35310It prints out an update message every half second, which includes the fields:
35311
35312@table @samp
35313@item section
35314The name of the section.
35315@item section-sent
35316The size of what has been sent so far for that section.
35317@item section-size
35318The size of the section.
35319@item total-sent
35320The total size of what was sent so far (the current and the previous sections).
35321@item total-size
35322The size of the overall executable to download.
35323@end table
35324
35325@noindent
35326Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
35327@sc{gdb/mi} Output Syntax}).
35328
35329In addition, it prints the name and size of the sections, as they are
35330downloaded. These messages include the following fields:
35331
35332@table @samp
35333@item section
35334The name of the section.
35335@item section-size
35336The size of the section.
35337@item total-size
35338The size of the overall executable to download.
35339@end table
35340
35341@noindent
35342At the end, a summary is printed.
35343
35344@subsubheading @value{GDBN} Command
35345
35346The corresponding @value{GDBN} command is @samp{load}.
35347
35348@subsubheading Example
35349
35350Note: each status message appears on a single line. Here the messages
35351have been broken down so that they can fit onto a page.
922fbb7b
AC
35352
35353@smallexample
594fe323 35354(gdb)
a2c02241
NR
35355-target-download
35356+download,@{section=".text",section-size="6668",total-size="9880"@}
35357+download,@{section=".text",section-sent="512",section-size="6668",
35358total-sent="512",total-size="9880"@}
35359+download,@{section=".text",section-sent="1024",section-size="6668",
35360total-sent="1024",total-size="9880"@}
35361+download,@{section=".text",section-sent="1536",section-size="6668",
35362total-sent="1536",total-size="9880"@}
35363+download,@{section=".text",section-sent="2048",section-size="6668",
35364total-sent="2048",total-size="9880"@}
35365+download,@{section=".text",section-sent="2560",section-size="6668",
35366total-sent="2560",total-size="9880"@}
35367+download,@{section=".text",section-sent="3072",section-size="6668",
35368total-sent="3072",total-size="9880"@}
35369+download,@{section=".text",section-sent="3584",section-size="6668",
35370total-sent="3584",total-size="9880"@}
35371+download,@{section=".text",section-sent="4096",section-size="6668",
35372total-sent="4096",total-size="9880"@}
35373+download,@{section=".text",section-sent="4608",section-size="6668",
35374total-sent="4608",total-size="9880"@}
35375+download,@{section=".text",section-sent="5120",section-size="6668",
35376total-sent="5120",total-size="9880"@}
35377+download,@{section=".text",section-sent="5632",section-size="6668",
35378total-sent="5632",total-size="9880"@}
35379+download,@{section=".text",section-sent="6144",section-size="6668",
35380total-sent="6144",total-size="9880"@}
35381+download,@{section=".text",section-sent="6656",section-size="6668",
35382total-sent="6656",total-size="9880"@}
35383+download,@{section=".init",section-size="28",total-size="9880"@}
35384+download,@{section=".fini",section-size="28",total-size="9880"@}
35385+download,@{section=".data",section-size="3156",total-size="9880"@}
35386+download,@{section=".data",section-sent="512",section-size="3156",
35387total-sent="7236",total-size="9880"@}
35388+download,@{section=".data",section-sent="1024",section-size="3156",
35389total-sent="7748",total-size="9880"@}
35390+download,@{section=".data",section-sent="1536",section-size="3156",
35391total-sent="8260",total-size="9880"@}
35392+download,@{section=".data",section-sent="2048",section-size="3156",
35393total-sent="8772",total-size="9880"@}
35394+download,@{section=".data",section-sent="2560",section-size="3156",
35395total-sent="9284",total-size="9880"@}
35396+download,@{section=".data",section-sent="3072",section-size="3156",
35397total-sent="9796",total-size="9880"@}
35398^done,address="0x10004",load-size="9880",transfer-rate="6586",
35399write-rate="429"
594fe323 35400(gdb)
922fbb7b
AC
35401@end smallexample
35402
35403
9901a55b 35404@ignore
a2c02241
NR
35405@subheading The @code{-target-exec-status} Command
35406@findex -target-exec-status
922fbb7b
AC
35407
35408@subsubheading Synopsis
35409
35410@smallexample
a2c02241 35411 -target-exec-status
922fbb7b
AC
35412@end smallexample
35413
a2c02241
NR
35414Provide information on the state of the target (whether it is running or
35415not, for instance).
922fbb7b 35416
a2c02241 35417@subsubheading @value{GDBN} Command
922fbb7b 35418
a2c02241
NR
35419There's no equivalent @value{GDBN} command.
35420
35421@subsubheading Example
35422N.A.
922fbb7b 35423
a2c02241
NR
35424
35425@subheading The @code{-target-list-available-targets} Command
35426@findex -target-list-available-targets
922fbb7b
AC
35427
35428@subsubheading Synopsis
35429
35430@smallexample
a2c02241 35431 -target-list-available-targets
922fbb7b
AC
35432@end smallexample
35433
a2c02241 35434List the possible targets to connect to.
922fbb7b 35435
a2c02241 35436@subsubheading @value{GDBN} Command
922fbb7b 35437
a2c02241 35438The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 35439
a2c02241
NR
35440@subsubheading Example
35441N.A.
35442
35443
35444@subheading The @code{-target-list-current-targets} Command
35445@findex -target-list-current-targets
922fbb7b
AC
35446
35447@subsubheading Synopsis
35448
35449@smallexample
a2c02241 35450 -target-list-current-targets
922fbb7b
AC
35451@end smallexample
35452
a2c02241 35453Describe the current target.
922fbb7b 35454
a2c02241 35455@subsubheading @value{GDBN} Command
922fbb7b 35456
a2c02241
NR
35457The corresponding information is printed by @samp{info file} (among
35458other things).
922fbb7b 35459
a2c02241
NR
35460@subsubheading Example
35461N.A.
35462
35463
35464@subheading The @code{-target-list-parameters} Command
35465@findex -target-list-parameters
922fbb7b
AC
35466
35467@subsubheading Synopsis
35468
35469@smallexample
a2c02241 35470 -target-list-parameters
922fbb7b
AC
35471@end smallexample
35472
a2c02241 35473@c ????
9901a55b 35474@end ignore
a2c02241
NR
35475
35476@subsubheading @value{GDBN} Command
35477
35478No equivalent.
922fbb7b
AC
35479
35480@subsubheading Example
a2c02241
NR
35481N.A.
35482
78cbbba8
LM
35483@subheading The @code{-target-flash-erase} Command
35484@findex -target-flash-erase
35485
35486@subsubheading Synopsis
35487
35488@smallexample
35489 -target-flash-erase
35490@end smallexample
35491
35492Erases all known flash memory regions on the target.
35493
35494The corresponding @value{GDBN} command is @samp{flash-erase}.
35495
35496The output is a list of flash regions that have been erased, with starting
35497addresses and memory region sizes.
35498
35499@smallexample
35500(gdb)
35501-target-flash-erase
35502^done,erased-regions=@{address="0x0",size="0x40000"@}
35503(gdb)
35504@end smallexample
a2c02241
NR
35505
35506@subheading The @code{-target-select} Command
35507@findex -target-select
35508
35509@subsubheading Synopsis
922fbb7b
AC
35510
35511@smallexample
a2c02241 35512 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
35513@end smallexample
35514
a2c02241 35515Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 35516
a2c02241
NR
35517@table @samp
35518@item @var{type}
75c99385 35519The type of target, for instance @samp{remote}, etc.
a2c02241
NR
35520@item @var{parameters}
35521Device names, host names and the like. @xref{Target Commands, ,
79a6e687 35522Commands for Managing Targets}, for more details.
a2c02241
NR
35523@end table
35524
35525The output is a connection notification, followed by the address at
35526which the target program is, in the following form:
922fbb7b
AC
35527
35528@smallexample
a2c02241
NR
35529^connected,addr="@var{address}",func="@var{function name}",
35530 args=[@var{arg list}]
922fbb7b
AC
35531@end smallexample
35532
a2c02241
NR
35533@subsubheading @value{GDBN} Command
35534
35535The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
35536
35537@subsubheading Example
922fbb7b 35538
265eeb58 35539@smallexample
594fe323 35540(gdb)
75c99385 35541-target-select remote /dev/ttya
a2c02241 35542^connected,addr="0xfe00a300",func="??",args=[]
594fe323 35543(gdb)
265eeb58 35544@end smallexample
ef21caaf 35545
a6b151f1
DJ
35546@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35547@node GDB/MI File Transfer Commands
35548@section @sc{gdb/mi} File Transfer Commands
35549
35550
35551@subheading The @code{-target-file-put} Command
35552@findex -target-file-put
35553
35554@subsubheading Synopsis
35555
35556@smallexample
35557 -target-file-put @var{hostfile} @var{targetfile}
35558@end smallexample
35559
35560Copy file @var{hostfile} from the host system (the machine running
35561@value{GDBN}) to @var{targetfile} on the target system.
35562
35563@subsubheading @value{GDBN} Command
35564
35565The corresponding @value{GDBN} command is @samp{remote put}.
35566
35567@subsubheading Example
35568
35569@smallexample
35570(gdb)
35571-target-file-put localfile remotefile
35572^done
35573(gdb)
35574@end smallexample
35575
35576
1763a388 35577@subheading The @code{-target-file-get} Command
a6b151f1
DJ
35578@findex -target-file-get
35579
35580@subsubheading Synopsis
35581
35582@smallexample
35583 -target-file-get @var{targetfile} @var{hostfile}
35584@end smallexample
35585
35586Copy file @var{targetfile} from the target system to @var{hostfile}
35587on the host system.
35588
35589@subsubheading @value{GDBN} Command
35590
35591The corresponding @value{GDBN} command is @samp{remote get}.
35592
35593@subsubheading Example
35594
35595@smallexample
35596(gdb)
35597-target-file-get remotefile localfile
35598^done
35599(gdb)
35600@end smallexample
35601
35602
35603@subheading The @code{-target-file-delete} Command
35604@findex -target-file-delete
35605
35606@subsubheading Synopsis
35607
35608@smallexample
35609 -target-file-delete @var{targetfile}
35610@end smallexample
35611
35612Delete @var{targetfile} from the target system.
35613
35614@subsubheading @value{GDBN} Command
35615
35616The corresponding @value{GDBN} command is @samp{remote delete}.
35617
35618@subsubheading Example
35619
35620@smallexample
35621(gdb)
35622-target-file-delete remotefile
35623^done
35624(gdb)
35625@end smallexample
35626
35627
58d06528
JB
35628@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35629@node GDB/MI Ada Exceptions Commands
35630@section Ada Exceptions @sc{gdb/mi} Commands
35631
35632@subheading The @code{-info-ada-exceptions} Command
35633@findex -info-ada-exceptions
35634
35635@subsubheading Synopsis
35636
35637@smallexample
35638 -info-ada-exceptions [ @var{regexp}]
35639@end smallexample
35640
35641List all Ada exceptions defined within the program being debugged.
35642With a regular expression @var{regexp}, only those exceptions whose
35643names match @var{regexp} are listed.
35644
35645@subsubheading @value{GDBN} Command
35646
35647The corresponding @value{GDBN} command is @samp{info exceptions}.
35648
35649@subsubheading Result
35650
35651The result is a table of Ada exceptions. The following columns are
35652defined for each exception:
35653
35654@table @samp
35655@item name
35656The name of the exception.
35657
35658@item address
35659The address of the exception.
35660
35661@end table
35662
35663@subsubheading Example
35664
35665@smallexample
35666-info-ada-exceptions aint
35667^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
35668hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
35669@{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
35670body=[@{name="constraint_error",address="0x0000000000613da0"@},
35671@{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
35672@end smallexample
35673
35674@subheading Catching Ada Exceptions
35675
35676The commands describing how to ask @value{GDBN} to stop when a program
35677raises an exception are described at @ref{Ada Exception GDB/MI
35678Catchpoint Commands}.
35679
35680
ef21caaf 35681@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d192b373
JB
35682@node GDB/MI Support Commands
35683@section @sc{gdb/mi} Support Commands
ef21caaf 35684
d192b373
JB
35685Since new commands and features get regularly added to @sc{gdb/mi},
35686some commands are available to help front-ends query the debugger
35687about support for these capabilities. Similarly, it is also possible
35688to query @value{GDBN} about target support of certain features.
ef21caaf 35689
6b7cbff1
JB
35690@subheading The @code{-info-gdb-mi-command} Command
35691@cindex @code{-info-gdb-mi-command}
35692@findex -info-gdb-mi-command
35693
35694@subsubheading Synopsis
35695
35696@smallexample
35697 -info-gdb-mi-command @var{cmd_name}
35698@end smallexample
35699
35700Query support for the @sc{gdb/mi} command named @var{cmd_name}.
35701
35702Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
35703is technically not part of the command name (@pxref{GDB/MI Input
35704Syntax}), and thus should be omitted in @var{cmd_name}. However,
35705for ease of use, this command also accepts the form with the leading
35706dash.
35707
35708@subsubheading @value{GDBN} Command
35709
35710There is no corresponding @value{GDBN} command.
35711
35712@subsubheading Result
35713
35714The result is a tuple. There is currently only one field:
35715
35716@table @samp
35717@item exists
35718This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
35719@code{"false"} otherwise.
35720
35721@end table
35722
35723@subsubheading Example
35724
35725Here is an example where the @sc{gdb/mi} command does not exist:
35726
35727@smallexample
35728-info-gdb-mi-command unsupported-command
35729^done,command=@{exists="false"@}
35730@end smallexample
35731
35732@noindent
35733And here is an example where the @sc{gdb/mi} command is known
35734to the debugger:
35735
35736@smallexample
35737-info-gdb-mi-command symbol-list-lines
35738^done,command=@{exists="true"@}
35739@end smallexample
35740
084344da
VP
35741@subheading The @code{-list-features} Command
35742@findex -list-features
9b26f0fb 35743@cindex supported @sc{gdb/mi} features, list
084344da
VP
35744
35745Returns a list of particular features of the MI protocol that
35746this version of gdb implements. A feature can be a command,
35747or a new field in an output of some command, or even an
35748important bugfix. While a frontend can sometimes detect presence
35749of a feature at runtime, it is easier to perform detection at debugger
d192b373 35750startup.
084344da
VP
35751
35752The command returns a list of strings, with each string naming an
35753available feature. Each returned string is just a name, it does not
d192b373 35754have any internal structure. The list of possible feature names
084344da
VP
35755is given below.
35756
35757Example output:
35758
35759@smallexample
35760(gdb) -list-features
35761^done,result=["feature1","feature2"]
35762@end smallexample
35763
35764The current list of features is:
35765
edef6000 35766@ftable @samp
30e026bb 35767@item frozen-varobjs
a05336a1 35768Indicates support for the @code{-var-set-frozen} command, as well
6b92c0d3 35769as possible presence of the @code{frozen} field in the output
30e026bb
VP
35770of @code{-varobj-create}.
35771@item pending-breakpoints
a05336a1
JB
35772Indicates support for the @option{-f} option to the @code{-break-insert}
35773command.
b6313243 35774@item python
a05336a1 35775Indicates Python scripting support, Python-based
b6313243
TT
35776pretty-printing commands, and possible presence of the
35777@samp{display_hint} field in the output of @code{-var-list-children}
30e026bb 35778@item thread-info
a05336a1 35779Indicates support for the @code{-thread-info} command.
8dedea02 35780@item data-read-memory-bytes
a05336a1 35781Indicates support for the @code{-data-read-memory-bytes} and the
8dedea02 35782@code{-data-write-memory-bytes} commands.
39c4d40a
TT
35783@item breakpoint-notifications
35784Indicates that changes to breakpoints and breakpoints created via the
35785CLI will be announced via async records.
5d77fe44 35786@item ada-task-info
6adcee18 35787Indicates support for the @code{-ada-task-info} command.
422ad5c2
JB
35788@item language-option
35789Indicates that all @sc{gdb/mi} commands accept the @option{--language}
35790option (@pxref{Context management}).
6b7cbff1
JB
35791@item info-gdb-mi-command
35792Indicates support for the @code{-info-gdb-mi-command} command.
2ea126fa
JB
35793@item undefined-command-error-code
35794Indicates support for the "undefined-command" error code in error result
35795records, produced when trying to execute an undefined @sc{gdb/mi} command
35796(@pxref{GDB/MI Result Records}).
72bfa06c
JB
35797@item exec-run-start-option
35798Indicates that the @code{-exec-run} command supports the @option{--start}
35799option (@pxref{GDB/MI Program Execution}).
26fb3983
JV
35800@item data-disassemble-a-option
35801Indicates that the @code{-data-disassemble} command supports the @option{-a}
35802option (@pxref{GDB/MI Data Manipulation}).
edef6000 35803@end ftable
084344da 35804
c6ebd6cf
VP
35805@subheading The @code{-list-target-features} Command
35806@findex -list-target-features
35807
35808Returns a list of particular features that are supported by the
35809target. Those features affect the permitted MI commands, but
35810unlike the features reported by the @code{-list-features} command, the
35811features depend on which target GDB is using at the moment. Whenever
35812a target can change, due to commands such as @code{-target-select},
35813@code{-target-attach} or @code{-exec-run}, the list of target features
35814may change, and the frontend should obtain it again.
35815Example output:
35816
35817@smallexample
b3d3b4bd 35818(gdb) -list-target-features
c6ebd6cf
VP
35819^done,result=["async"]
35820@end smallexample
35821
35822The current list of features is:
35823
35824@table @samp
35825@item async
35826Indicates that the target is capable of asynchronous command
35827execution, which means that @value{GDBN} will accept further commands
35828while the target is running.
35829
f75d858b
MK
35830@item reverse
35831Indicates that the target is capable of reverse execution.
35832@xref{Reverse Execution}, for more information.
35833
c6ebd6cf
VP
35834@end table
35835
d192b373
JB
35836@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35837@node GDB/MI Miscellaneous Commands
35838@section Miscellaneous @sc{gdb/mi} Commands
35839
35840@c @subheading -gdb-complete
35841
35842@subheading The @code{-gdb-exit} Command
35843@findex -gdb-exit
35844
35845@subsubheading Synopsis
35846
35847@smallexample
35848 -gdb-exit
35849@end smallexample
35850
35851Exit @value{GDBN} immediately.
35852
35853@subsubheading @value{GDBN} Command
35854
35855Approximately corresponds to @samp{quit}.
35856
35857@subsubheading Example
35858
35859@smallexample
35860(gdb)
35861-gdb-exit
35862^exit
35863@end smallexample
35864
35865
35866@ignore
35867@subheading The @code{-exec-abort} Command
35868@findex -exec-abort
35869
35870@subsubheading Synopsis
35871
35872@smallexample
35873 -exec-abort
35874@end smallexample
35875
35876Kill the inferior running program.
35877
35878@subsubheading @value{GDBN} Command
35879
35880The corresponding @value{GDBN} command is @samp{kill}.
35881
35882@subsubheading Example
35883N.A.
35884@end ignore
35885
35886
35887@subheading The @code{-gdb-set} Command
35888@findex -gdb-set
35889
35890@subsubheading Synopsis
35891
35892@smallexample
35893 -gdb-set
35894@end smallexample
35895
35896Set an internal @value{GDBN} variable.
35897@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
35898
35899@subsubheading @value{GDBN} Command
35900
35901The corresponding @value{GDBN} command is @samp{set}.
35902
35903@subsubheading Example
35904
35905@smallexample
35906(gdb)
35907-gdb-set $foo=3
35908^done
35909(gdb)
35910@end smallexample
35911
35912
35913@subheading The @code{-gdb-show} Command
35914@findex -gdb-show
35915
35916@subsubheading Synopsis
35917
35918@smallexample
35919 -gdb-show
35920@end smallexample
35921
35922Show the current value of a @value{GDBN} variable.
35923
35924@subsubheading @value{GDBN} Command
35925
35926The corresponding @value{GDBN} command is @samp{show}.
35927
35928@subsubheading Example
35929
35930@smallexample
35931(gdb)
35932-gdb-show annotate
35933^done,value="0"
35934(gdb)
35935@end smallexample
35936
35937@c @subheading -gdb-source
35938
35939
35940@subheading The @code{-gdb-version} Command
35941@findex -gdb-version
35942
35943@subsubheading Synopsis
35944
35945@smallexample
35946 -gdb-version
35947@end smallexample
35948
35949Show version information for @value{GDBN}. Used mostly in testing.
35950
35951@subsubheading @value{GDBN} Command
35952
35953The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
35954default shows this information when you start an interactive session.
35955
35956@subsubheading Example
35957
35958@c This example modifies the actual output from GDB to avoid overfull
35959@c box in TeX.
35960@smallexample
35961(gdb)
35962-gdb-version
35963~GNU gdb 5.2.1
35964~Copyright 2000 Free Software Foundation, Inc.
35965~GDB is free software, covered by the GNU General Public License, and
35966~you are welcome to change it and/or distribute copies of it under
35967~ certain conditions.
35968~Type "show copying" to see the conditions.
35969~There is absolutely no warranty for GDB. Type "show warranty" for
35970~ details.
35971~This GDB was configured as
35972 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
35973^done
35974(gdb)
35975@end smallexample
35976
c3b108f7
VP
35977@subheading The @code{-list-thread-groups} Command
35978@findex -list-thread-groups
35979
35980@subheading Synopsis
35981
35982@smallexample
dc146f7c 35983-list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
c3b108f7
VP
35984@end smallexample
35985
dc146f7c
VP
35986Lists thread groups (@pxref{Thread groups}). When a single thread
35987group is passed as the argument, lists the children of that group.
35988When several thread group are passed, lists information about those
35989thread groups. Without any parameters, lists information about all
35990top-level thread groups.
35991
35992Normally, thread groups that are being debugged are reported.
35993With the @samp{--available} option, @value{GDBN} reports thread groups
35994available on the target.
35995
35996The output of this command may have either a @samp{threads} result or
35997a @samp{groups} result. The @samp{thread} result has a list of tuples
35998as value, with each tuple describing a thread (@pxref{GDB/MI Thread
35999Information}). The @samp{groups} result has a list of tuples as value,
36000each tuple describing a thread group. If top-level groups are
36001requested (that is, no parameter is passed), or when several groups
36002are passed, the output always has a @samp{groups} result. The format
36003of the @samp{group} result is described below.
36004
36005To reduce the number of roundtrips it's possible to list thread groups
36006together with their children, by passing the @samp{--recurse} option
36007and the recursion depth. Presently, only recursion depth of 1 is
36008permitted. If this option is present, then every reported thread group
36009will also include its children, either as @samp{group} or
36010@samp{threads} field.
36011
36012In general, any combination of option and parameters is permitted, with
36013the following caveats:
36014
36015@itemize @bullet
36016@item
36017When a single thread group is passed, the output will typically
36018be the @samp{threads} result. Because threads may not contain
36019anything, the @samp{recurse} option will be ignored.
36020
36021@item
36022When the @samp{--available} option is passed, limited information may
36023be available. In particular, the list of threads of a process might
36024be inaccessible. Further, specifying specific thread groups might
36025not give any performance advantage over listing all thread groups.
36026The frontend should assume that @samp{-list-thread-groups --available}
36027is always an expensive operation and cache the results.
36028
36029@end itemize
36030
36031The @samp{groups} result is a list of tuples, where each tuple may
36032have the following fields:
36033
36034@table @code
36035@item id
36036Identifier of the thread group. This field is always present.
a79b8f6e
VP
36037The identifier is an opaque string; frontends should not try to
36038convert it to an integer, even though it might look like one.
dc146f7c
VP
36039
36040@item type
36041The type of the thread group. At present, only @samp{process} is a
36042valid type.
36043
36044@item pid
36045The target-specific process identifier. This field is only present
a79b8f6e 36046for thread groups of type @samp{process} and only if the process exists.
c3b108f7 36047
2ddf4301
SM
36048@item exit-code
36049The exit code of this group's last exited thread, formatted in octal.
36050This field is only present for thread groups of type @samp{process} and
36051only if the process is not running.
36052
dc146f7c
VP
36053@item num_children
36054The number of children this thread group has. This field may be
36055absent for an available thread group.
36056
36057@item threads
36058This field has a list of tuples as value, each tuple describing a
36059thread. It may be present if the @samp{--recurse} option is
36060specified, and it's actually possible to obtain the threads.
36061
36062@item cores
36063This field is a list of integers, each identifying a core that one
36064thread of the group is running on. This field may be absent if
36065such information is not available.
36066
a79b8f6e
VP
36067@item executable
36068The name of the executable file that corresponds to this thread group.
36069The field is only present for thread groups of type @samp{process},
36070and only if there is a corresponding executable file.
36071
dc146f7c 36072@end table
c3b108f7
VP
36073
36074@subheading Example
36075
36076@smallexample
36077@value{GDBP}
36078-list-thread-groups
36079^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
36080-list-thread-groups 17
36081^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
36082 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
36083@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
36084 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
6d52907e 36085 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
dc146f7c
VP
36086-list-thread-groups --available
36087^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
36088-list-thread-groups --available --recurse 1
36089 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36090 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36091 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
36092-list-thread-groups --available --recurse 1 17 18
36093^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36094 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36095 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
c3b108f7 36096@end smallexample
c6ebd6cf 36097
f3e0e960
SS
36098@subheading The @code{-info-os} Command
36099@findex -info-os
36100
36101@subsubheading Synopsis
36102
36103@smallexample
36104-info-os [ @var{type} ]
36105@end smallexample
36106
36107If no argument is supplied, the command returns a table of available
36108operating-system-specific information types. If one of these types is
36109supplied as an argument @var{type}, then the command returns a table
36110of data of that type.
36111
36112The types of information available depend on the target operating
36113system.
36114
36115@subsubheading @value{GDBN} Command
36116
36117The corresponding @value{GDBN} command is @samp{info os}.
36118
36119@subsubheading Example
36120
36121When run on a @sc{gnu}/Linux system, the output will look something
36122like this:
36123
36124@smallexample
36125@value{GDBP}
36126-info-os
d33279b3 36127^done,OSDataTable=@{nr_rows="10",nr_cols="3",
f3e0e960 36128hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
71caed83
SS
36129 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
36130 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
d33279b3
AT
36131body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
36132 col2="CPUs"@},
36133 item=@{col0="files",col1="Listing of all file descriptors",
36134 col2="File descriptors"@},
36135 item=@{col0="modules",col1="Listing of all loaded kernel modules",
36136 col2="Kernel modules"@},
36137 item=@{col0="msg",col1="Listing of all message queues",
36138 col2="Message queues"@},
36139 item=@{col0="processes",col1="Listing of all processes",
71caed83
SS
36140 col2="Processes"@},
36141 item=@{col0="procgroups",col1="Listing of all process groups",
36142 col2="Process groups"@},
71caed83
SS
36143 item=@{col0="semaphores",col1="Listing of all semaphores",
36144 col2="Semaphores"@},
d33279b3
AT
36145 item=@{col0="shm",col1="Listing of all shared-memory regions",
36146 col2="Shared-memory regions"@},
36147 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
36148 col2="Sockets"@},
36149 item=@{col0="threads",col1="Listing of all threads",
36150 col2="Threads"@}]
f3e0e960
SS
36151@value{GDBP}
36152-info-os processes
36153^done,OSDataTable=@{nr_rows="190",nr_cols="4",
36154hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
36155 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
36156 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
36157 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
36158body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
36159 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
36160 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
36161 ...
36162 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
36163 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
36164(gdb)
36165@end smallexample
a79b8f6e 36166
71caed83
SS
36167(Note that the MI output here includes a @code{"Title"} column that
36168does not appear in command-line @code{info os}; this column is useful
36169for MI clients that want to enumerate the types of data, such as in a
36170popup menu, but is needless clutter on the command line, and
36171@code{info os} omits it.)
36172
a79b8f6e
VP
36173@subheading The @code{-add-inferior} Command
36174@findex -add-inferior
36175
36176@subheading Synopsis
36177
36178@smallexample
36179-add-inferior
36180@end smallexample
36181
65c574f6 36182Creates a new inferior (@pxref{Inferiors Connections and Programs}). The created
a79b8f6e
VP
36183inferior is not associated with any executable. Such association may
36184be established with the @samp{-file-exec-and-symbols} command
36185(@pxref{GDB/MI File Commands}). The command response has a single
b7742092 36186field, @samp{inferior}, whose value is the identifier of the
a79b8f6e
VP
36187thread group corresponding to the new inferior.
36188
36189@subheading Example
36190
36191@smallexample
36192@value{GDBP}
36193-add-inferior
b7742092 36194^done,inferior="i3"
a79b8f6e
VP
36195@end smallexample
36196
ef21caaf
NR
36197@subheading The @code{-interpreter-exec} Command
36198@findex -interpreter-exec
36199
36200@subheading Synopsis
36201
36202@smallexample
36203-interpreter-exec @var{interpreter} @var{command}
36204@end smallexample
a2c02241 36205@anchor{-interpreter-exec}
ef21caaf
NR
36206
36207Execute the specified @var{command} in the given @var{interpreter}.
36208
36209@subheading @value{GDBN} Command
36210
36211The corresponding @value{GDBN} command is @samp{interpreter-exec}.
36212
36213@subheading Example
36214
36215@smallexample
594fe323 36216(gdb)
ef21caaf
NR
36217-interpreter-exec console "break main"
36218&"During symbol reading, couldn't parse type; debugger out of date?.\n"
36219&"During symbol reading, bad structure-type format.\n"
36220~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
36221^done
594fe323 36222(gdb)
ef21caaf
NR
36223@end smallexample
36224
36225@subheading The @code{-inferior-tty-set} Command
36226@findex -inferior-tty-set
36227
36228@subheading Synopsis
36229
36230@smallexample
36231-inferior-tty-set /dev/pts/1
36232@end smallexample
36233
36234Set terminal for future runs of the program being debugged.
36235
36236@subheading @value{GDBN} Command
36237
36238The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
36239
36240@subheading Example
36241
36242@smallexample
594fe323 36243(gdb)
ef21caaf
NR
36244-inferior-tty-set /dev/pts/1
36245^done
594fe323 36246(gdb)
ef21caaf
NR
36247@end smallexample
36248
36249@subheading The @code{-inferior-tty-show} Command
36250@findex -inferior-tty-show
36251
36252@subheading Synopsis
36253
36254@smallexample
36255-inferior-tty-show
36256@end smallexample
36257
36258Show terminal for future runs of program being debugged.
36259
36260@subheading @value{GDBN} Command
36261
36262The corresponding @value{GDBN} command is @samp{show inferior-tty}.
36263
36264@subheading Example
36265
36266@smallexample
594fe323 36267(gdb)
ef21caaf
NR
36268-inferior-tty-set /dev/pts/1
36269^done
594fe323 36270(gdb)
ef21caaf
NR
36271-inferior-tty-show
36272^done,inferior_tty_terminal="/dev/pts/1"
594fe323 36273(gdb)
ef21caaf 36274@end smallexample
922fbb7b 36275
a4eefcd8
NR
36276@subheading The @code{-enable-timings} Command
36277@findex -enable-timings
36278
36279@subheading Synopsis
36280
36281@smallexample
36282-enable-timings [yes | no]
36283@end smallexample
36284
36285Toggle the printing of the wallclock, user and system times for an MI
36286command as a field in its output. This command is to help frontend
36287developers optimize the performance of their code. No argument is
36288equivalent to @samp{yes}.
36289
36290@subheading @value{GDBN} Command
36291
36292No equivalent.
36293
36294@subheading Example
36295
36296@smallexample
36297(gdb)
36298-enable-timings
36299^done
36300(gdb)
36301-break-insert main
36302^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
36303addr="0x080484ed",func="main",file="myprog.c",
998580f1
MK
36304fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
36305times="0"@},
a4eefcd8
NR
36306time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
36307(gdb)
36308-enable-timings no
36309^done
36310(gdb)
36311-exec-run
36312^running
36313(gdb)
a47ec5fe 36314*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
a4eefcd8
NR
36315frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
36316@{name="argv",value="0xbfb60364"@}],file="myprog.c",
6d52907e 36317fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
a4eefcd8
NR
36318(gdb)
36319@end smallexample
36320
26648588
JV
36321@subheading The @code{-complete} Command
36322@findex -complete
36323
36324@subheading Synopsis
36325
36326@smallexample
36327-complete @var{command}
36328@end smallexample
36329
36330Show a list of completions for partially typed CLI @var{command}.
36331
36332This command is intended for @sc{gdb/mi} frontends that cannot use two separate
7166f90a 36333CLI and MI channels --- for example: because of lack of PTYs like on Windows or
26648588
JV
36334because @value{GDBN} is used remotely via a SSH connection.
36335
36336@subheading Result
36337
36338The result consists of two or three fields:
36339
36340@table @samp
36341@item completion
36342This field contains the completed @var{command}. If @var{command}
36343has no known completions, this field is omitted.
36344
36345@item matches
36346This field contains a (possibly empty) array of matches. It is always present.
36347
36348@item max_completions_reached
36349This field contains @code{1} if number of known completions is above
7166f90a 36350@code{max-completions} limit (@pxref{Completion}), otherwise it contains
26648588
JV
36351@code{0}. It is always present.
36352
36353@end table
36354
36355@subheading @value{GDBN} Command
36356
36357The corresponding @value{GDBN} command is @samp{complete}.
36358
36359@subheading Example
36360
36361@smallexample
36362(gdb)
36363-complete br
36364^done,completion="break",
36365 matches=["break","break-range"],
36366 max_completions_reached="0"
36367(gdb)
36368-complete "b ma"
36369^done,completion="b ma",
36370 matches=["b madvise","b main"],max_completions_reached="0"
36371(gdb)
36372-complete "b push_b"
36373^done,completion="b push_back(",
36374 matches=[
36375 "b A::push_back(void*)",
36376 "b std::string::push_back(char)",
36377 "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
36378 max_completions_reached="0"
36379(gdb)
36380-complete "nonexist"
36381^done,matches=[],max_completions_reached="0"
36382(gdb)
36383
36384@end smallexample
36385
922fbb7b
AC
36386@node Annotations
36387@chapter @value{GDBN} Annotations
36388
086432e2
AC
36389This chapter describes annotations in @value{GDBN}. Annotations were
36390designed to interface @value{GDBN} to graphical user interfaces or other
36391similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
36392relatively high level.
36393
d3e8051b 36394The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
36395(@pxref{GDB/MI}).
36396
922fbb7b
AC
36397@ignore
36398This is Edition @value{EDITION}, @value{DATE}.
36399@end ignore
36400
36401@menu
36402* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 36403* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
36404* Prompting:: Annotations marking @value{GDBN}'s need for input.
36405* Errors:: Annotations for error messages.
922fbb7b
AC
36406* Invalidation:: Some annotations describe things now invalid.
36407* Annotations for Running::
36408 Whether the program is running, how it stopped, etc.
36409* Source Annotations:: Annotations describing source code.
922fbb7b
AC
36410@end menu
36411
36412@node Annotations Overview
36413@section What is an Annotation?
36414@cindex annotations
36415
922fbb7b
AC
36416Annotations start with a newline character, two @samp{control-z}
36417characters, and the name of the annotation. If there is no additional
36418information associated with this annotation, the name of the annotation
36419is followed immediately by a newline. If there is additional
36420information, the name of the annotation is followed by a space, the
36421additional information, and a newline. The additional information
36422cannot contain newline characters.
36423
36424Any output not beginning with a newline and two @samp{control-z}
36425characters denotes literal output from @value{GDBN}. Currently there is
36426no need for @value{GDBN} to output a newline followed by two
36427@samp{control-z} characters, but if there was such a need, the
36428annotations could be extended with an @samp{escape} annotation which
36429means those three characters as output.
36430
086432e2
AC
36431The annotation @var{level}, which is specified using the
36432@option{--annotate} command line option (@pxref{Mode Options}), controls
36433how much information @value{GDBN} prints together with its prompt,
36434values of expressions, source lines, and other types of output. Level 0
d3e8051b 36435is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
36436subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
36437for programs that control @value{GDBN}, and level 2 annotations have
36438been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
36439Interface, annotate, GDB's Obsolete Annotations}).
36440
36441@table @code
36442@kindex set annotate
36443@item set annotate @var{level}
e09f16f9 36444The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 36445annotations to the specified @var{level}.
9c16f35a
EZ
36446
36447@item show annotate
36448@kindex show annotate
36449Show the current annotation level.
09d4efe1
EZ
36450@end table
36451
36452This chapter describes level 3 annotations.
086432e2 36453
922fbb7b
AC
36454A simple example of starting up @value{GDBN} with annotations is:
36455
36456@smallexample
086432e2
AC
36457$ @kbd{gdb --annotate=3}
36458GNU gdb 6.0
36459Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
36460GDB is free software, covered by the GNU General Public License,
36461and you are welcome to change it and/or distribute copies of it
36462under certain conditions.
36463Type "show copying" to see the conditions.
36464There is absolutely no warranty for GDB. Type "show warranty"
36465for details.
086432e2 36466This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
36467
36468^Z^Zpre-prompt
f7dc1244 36469(@value{GDBP})
922fbb7b 36470^Z^Zprompt
086432e2 36471@kbd{quit}
922fbb7b
AC
36472
36473^Z^Zpost-prompt
b383017d 36474$
922fbb7b
AC
36475@end smallexample
36476
36477Here @samp{quit} is input to @value{GDBN}; the rest is output from
36478@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
36479denotes a @samp{control-z} character) are annotations; the rest is
36480output from @value{GDBN}.
36481
9e6c4bd5
NR
36482@node Server Prefix
36483@section The Server Prefix
36484@cindex server prefix
36485
36486If you prefix a command with @samp{server } then it will not affect
36487the command history, nor will it affect @value{GDBN}'s notion of which
36488command to repeat if @key{RET} is pressed on a line by itself. This
36489means that commands can be run behind a user's back by a front-end in
36490a transparent manner.
36491
d837706a
NR
36492The @code{server } prefix does not affect the recording of values into
36493the value history; to print a value without recording it into the
36494value history, use the @code{output} command instead of the
36495@code{print} command.
36496
36497Using this prefix also disables confirmation requests
36498(@pxref{confirmation requests}).
9e6c4bd5 36499
922fbb7b
AC
36500@node Prompting
36501@section Annotation for @value{GDBN} Input
36502
36503@cindex annotations for prompts
36504When @value{GDBN} prompts for input, it annotates this fact so it is possible
36505to know when to send output, when the output from a given command is
36506over, etc.
36507
36508Different kinds of input each have a different @dfn{input type}. Each
36509input type has three annotations: a @code{pre-} annotation, which
36510denotes the beginning of any prompt which is being output, a plain
36511annotation, which denotes the end of the prompt, and then a @code{post-}
36512annotation which denotes the end of any echo which may (or may not) be
36513associated with the input. For example, the @code{prompt} input type
36514features the following annotations:
36515
36516@smallexample
36517^Z^Zpre-prompt
36518^Z^Zprompt
36519^Z^Zpost-prompt
36520@end smallexample
36521
36522The input types are
36523
36524@table @code
e5ac9b53
EZ
36525@findex pre-prompt annotation
36526@findex prompt annotation
36527@findex post-prompt annotation
922fbb7b
AC
36528@item prompt
36529When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
36530
e5ac9b53
EZ
36531@findex pre-commands annotation
36532@findex commands annotation
36533@findex post-commands annotation
922fbb7b
AC
36534@item commands
36535When @value{GDBN} prompts for a set of commands, like in the @code{commands}
36536command. The annotations are repeated for each command which is input.
36537
e5ac9b53
EZ
36538@findex pre-overload-choice annotation
36539@findex overload-choice annotation
36540@findex post-overload-choice annotation
922fbb7b
AC
36541@item overload-choice
36542When @value{GDBN} wants the user to select between various overloaded functions.
36543
e5ac9b53
EZ
36544@findex pre-query annotation
36545@findex query annotation
36546@findex post-query annotation
922fbb7b
AC
36547@item query
36548When @value{GDBN} wants the user to confirm a potentially dangerous operation.
36549
e5ac9b53
EZ
36550@findex pre-prompt-for-continue annotation
36551@findex prompt-for-continue annotation
36552@findex post-prompt-for-continue annotation
922fbb7b
AC
36553@item prompt-for-continue
36554When @value{GDBN} is asking the user to press return to continue. Note: Don't
36555expect this to work well; instead use @code{set height 0} to disable
36556prompting. This is because the counting of lines is buggy in the
36557presence of annotations.
36558@end table
36559
36560@node Errors
36561@section Errors
36562@cindex annotations for errors, warnings and interrupts
36563
e5ac9b53 36564@findex quit annotation
922fbb7b
AC
36565@smallexample
36566^Z^Zquit
36567@end smallexample
36568
36569This annotation occurs right before @value{GDBN} responds to an interrupt.
36570
e5ac9b53 36571@findex error annotation
922fbb7b
AC
36572@smallexample
36573^Z^Zerror
36574@end smallexample
36575
36576This annotation occurs right before @value{GDBN} responds to an error.
36577
36578Quit and error annotations indicate that any annotations which @value{GDBN} was
36579in the middle of may end abruptly. For example, if a
36580@code{value-history-begin} annotation is followed by a @code{error}, one
36581cannot expect to receive the matching @code{value-history-end}. One
36582cannot expect not to receive it either, however; an error annotation
36583does not necessarily mean that @value{GDBN} is immediately returning all the way
36584to the top level.
36585
e5ac9b53 36586@findex error-begin annotation
922fbb7b
AC
36587A quit or error annotation may be preceded by
36588
36589@smallexample
36590^Z^Zerror-begin
36591@end smallexample
36592
36593Any output between that and the quit or error annotation is the error
36594message.
36595
36596Warning messages are not yet annotated.
36597@c If we want to change that, need to fix warning(), type_error(),
36598@c range_error(), and possibly other places.
36599
922fbb7b
AC
36600@node Invalidation
36601@section Invalidation Notices
36602
36603@cindex annotations for invalidation messages
36604The following annotations say that certain pieces of state may have
36605changed.
36606
36607@table @code
e5ac9b53 36608@findex frames-invalid annotation
922fbb7b
AC
36609@item ^Z^Zframes-invalid
36610
36611The frames (for example, output from the @code{backtrace} command) may
36612have changed.
36613
e5ac9b53 36614@findex breakpoints-invalid annotation
922fbb7b
AC
36615@item ^Z^Zbreakpoints-invalid
36616
36617The breakpoints may have changed. For example, the user just added or
36618deleted a breakpoint.
36619@end table
36620
36621@node Annotations for Running
36622@section Running the Program
36623@cindex annotations for running programs
36624
e5ac9b53
EZ
36625@findex starting annotation
36626@findex stopping annotation
922fbb7b 36627When the program starts executing due to a @value{GDBN} command such as
b383017d 36628@code{step} or @code{continue},
922fbb7b
AC
36629
36630@smallexample
36631^Z^Zstarting
36632@end smallexample
36633
b383017d 36634is output. When the program stops,
922fbb7b
AC
36635
36636@smallexample
36637^Z^Zstopped
36638@end smallexample
36639
36640is output. Before the @code{stopped} annotation, a variety of
36641annotations describe how the program stopped.
36642
36643@table @code
e5ac9b53 36644@findex exited annotation
922fbb7b
AC
36645@item ^Z^Zexited @var{exit-status}
36646The program exited, and @var{exit-status} is the exit status (zero for
36647successful exit, otherwise nonzero).
36648
e5ac9b53
EZ
36649@findex signalled annotation
36650@findex signal-name annotation
36651@findex signal-name-end annotation
36652@findex signal-string annotation
36653@findex signal-string-end annotation
922fbb7b
AC
36654@item ^Z^Zsignalled
36655The program exited with a signal. After the @code{^Z^Zsignalled}, the
36656annotation continues:
36657
36658@smallexample
36659@var{intro-text}
36660^Z^Zsignal-name
36661@var{name}
36662^Z^Zsignal-name-end
36663@var{middle-text}
36664^Z^Zsignal-string
36665@var{string}
36666^Z^Zsignal-string-end
36667@var{end-text}
36668@end smallexample
36669
36670@noindent
36671where @var{name} is the name of the signal, such as @code{SIGILL} or
36672@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
697aa1b7 36673as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
922fbb7b
AC
36674@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
36675user's benefit and have no particular format.
36676
e5ac9b53 36677@findex signal annotation
922fbb7b
AC
36678@item ^Z^Zsignal
36679The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
36680just saying that the program received the signal, not that it was
36681terminated with it.
36682
e5ac9b53 36683@findex breakpoint annotation
922fbb7b
AC
36684@item ^Z^Zbreakpoint @var{number}
36685The program hit breakpoint number @var{number}.
36686
e5ac9b53 36687@findex watchpoint annotation
922fbb7b
AC
36688@item ^Z^Zwatchpoint @var{number}
36689The program hit watchpoint number @var{number}.
36690@end table
36691
36692@node Source Annotations
36693@section Displaying Source
36694@cindex annotations for source display
36695
e5ac9b53 36696@findex source annotation
922fbb7b
AC
36697The following annotation is used instead of displaying source code:
36698
36699@smallexample
36700^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
36701@end smallexample
36702
36703where @var{filename} is an absolute file name indicating which source
36704file, @var{line} is the line number within that file (where 1 is the
36705first line in the file), @var{character} is the character position
36706within the file (where 0 is the first character in the file) (for most
36707debug formats this will necessarily point to the beginning of a line),
36708@var{middle} is @samp{middle} if @var{addr} is in the middle of the
36709line, or @samp{beg} if @var{addr} is at the beginning of the line, and
36710@var{addr} is the address in the target program associated with the
697aa1b7 36711source which is being displayed. The @var{addr} is in the form @samp{0x}
922fbb7b
AC
36712followed by one or more lowercase hex digits (note that this does not
36713depend on the language).
36714
4efc6507
DE
36715@node JIT Interface
36716@chapter JIT Compilation Interface
36717@cindex just-in-time compilation
36718@cindex JIT compilation interface
36719
36720This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
36721interface. A JIT compiler is a program or library that generates native
36722executable code at runtime and executes it, usually in order to achieve good
36723performance while maintaining platform independence.
36724
36725Programs that use JIT compilation are normally difficult to debug because
36726portions of their code are generated at runtime, instead of being loaded from
36727object files, which is where @value{GDBN} normally finds the program's symbols
36728and debug information. In order to debug programs that use JIT compilation,
36729@value{GDBN} has an interface that allows the program to register in-memory
36730symbol files with @value{GDBN} at runtime.
36731
36732If you are using @value{GDBN} to debug a program that uses this interface, then
36733it should work transparently so long as you have not stripped the binary. If
36734you are developing a JIT compiler, then the interface is documented in the rest
36735of this chapter. At this time, the only known client of this interface is the
36736LLVM JIT.
36737
36738Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
36739JIT compiler communicates with @value{GDBN} by writing data into a global
6b92c0d3 36740variable and calling a function at a well-known symbol. When @value{GDBN}
4efc6507
DE
36741attaches, it reads a linked list of symbol files from the global variable to
36742find existing code, and puts a breakpoint in the function so that it can find
36743out about additional code.
36744
36745@menu
36746* Declarations:: Relevant C struct declarations
36747* Registering Code:: Steps to register code
36748* Unregistering Code:: Steps to unregister code
f85b53f8 36749* Custom Debug Info:: Emit debug information in a custom format
4efc6507
DE
36750@end menu
36751
36752@node Declarations
36753@section JIT Declarations
36754
36755These are the relevant struct declarations that a C program should include to
36756implement the interface:
36757
36758@smallexample
36759typedef enum
36760@{
36761 JIT_NOACTION = 0,
36762 JIT_REGISTER_FN,
36763 JIT_UNREGISTER_FN
36764@} jit_actions_t;
36765
36766struct jit_code_entry
36767@{
36768 struct jit_code_entry *next_entry;
36769 struct jit_code_entry *prev_entry;
36770 const char *symfile_addr;
36771 uint64_t symfile_size;
36772@};
36773
36774struct jit_descriptor
36775@{
36776 uint32_t version;
36777 /* This type should be jit_actions_t, but we use uint32_t
36778 to be explicit about the bitwidth. */
36779 uint32_t action_flag;
36780 struct jit_code_entry *relevant_entry;
36781 struct jit_code_entry *first_entry;
36782@};
36783
36784/* GDB puts a breakpoint in this function. */
36785void __attribute__((noinline)) __jit_debug_register_code() @{ @};
36786
36787/* Make sure to specify the version statically, because the
36788 debugger may check the version before we can set it. */
36789struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
36790@end smallexample
36791
36792If the JIT is multi-threaded, then it is important that the JIT synchronize any
36793modifications to this global data properly, which can easily be done by putting
36794a global mutex around modifications to these structures.
36795
36796@node Registering Code
36797@section Registering Code
36798
36799To register code with @value{GDBN}, the JIT should follow this protocol:
36800
36801@itemize @bullet
36802@item
36803Generate an object file in memory with symbols and other desired debug
36804information. The file must include the virtual addresses of the sections.
36805
36806@item
36807Create a code entry for the file, which gives the start and size of the symbol
36808file.
36809
36810@item
36811Add it to the linked list in the JIT descriptor.
36812
36813@item
36814Point the relevant_entry field of the descriptor at the entry.
36815
36816@item
36817Set @code{action_flag} to @code{JIT_REGISTER} and call
36818@code{__jit_debug_register_code}.
36819@end itemize
36820
36821When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
36822@code{relevant_entry} pointer so it doesn't have to walk the list looking for
36823new code. However, the linked list must still be maintained in order to allow
36824@value{GDBN} to attach to a running process and still find the symbol files.
36825
36826@node Unregistering Code
36827@section Unregistering Code
36828
36829If code is freed, then the JIT should use the following protocol:
36830
36831@itemize @bullet
36832@item
36833Remove the code entry corresponding to the code from the linked list.
36834
36835@item
36836Point the @code{relevant_entry} field of the descriptor at the code entry.
36837
36838@item
36839Set @code{action_flag} to @code{JIT_UNREGISTER} and call
36840@code{__jit_debug_register_code}.
36841@end itemize
36842
36843If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
36844and the JIT will leak the memory used for the associated symbol files.
36845
f85b53f8
SD
36846@node Custom Debug Info
36847@section Custom Debug Info
36848@cindex custom JIT debug info
36849@cindex JIT debug info reader
36850
36851Generating debug information in platform-native file formats (like ELF
36852or COFF) may be an overkill for JIT compilers; especially if all the
36853debug info is used for is displaying a meaningful backtrace. The
36854issue can be resolved by having the JIT writers decide on a debug info
36855format and also provide a reader that parses the debug info generated
36856by the JIT compiler. This section gives a brief overview on writing
36857such a parser. More specific details can be found in the source file
36858@file{gdb/jit-reader.in}, which is also installed as a header at
36859@file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
36860
36861The reader is implemented as a shared object (so this functionality is
36862not available on platforms which don't allow loading shared objects at
36863runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
36864@code{jit-reader-unload} are provided, to be used to load and unload
36865the readers from a preconfigured directory. Once loaded, the shared
36866object is used the parse the debug information emitted by the JIT
36867compiler.
36868
36869@menu
36870* Using JIT Debug Info Readers:: How to use supplied readers correctly
36871* Writing JIT Debug Info Readers:: Creating a debug-info reader
36872@end menu
36873
36874@node Using JIT Debug Info Readers
36875@subsection Using JIT Debug Info Readers
36876@kindex jit-reader-load
36877@kindex jit-reader-unload
36878
36879Readers can be loaded and unloaded using the @code{jit-reader-load}
36880and @code{jit-reader-unload} commands.
36881
36882@table @code
c9fb1240 36883@item jit-reader-load @var{reader}
697aa1b7 36884Load the JIT reader named @var{reader}, which is a shared
c9fb1240
SD
36885object specified as either an absolute or a relative file name. In
36886the latter case, @value{GDBN} will try to load the reader from a
36887pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
36888system (here @var{libdir} is the system library directory, often
36889@file{/usr/local/lib}).
36890
36891Only one reader can be active at a time; trying to load a second
36892reader when one is already loaded will result in @value{GDBN}
36893reporting an error. A new JIT reader can be loaded by first unloading
36894the current one using @code{jit-reader-unload} and then invoking
36895@code{jit-reader-load}.
f85b53f8
SD
36896
36897@item jit-reader-unload
36898Unload the currently loaded JIT reader.
36899
36900@end table
36901
36902@node Writing JIT Debug Info Readers
36903@subsection Writing JIT Debug Info Readers
36904@cindex writing JIT debug info readers
36905
36906As mentioned, a reader is essentially a shared object conforming to a
36907certain ABI. This ABI is described in @file{jit-reader.h}.
36908
36909@file{jit-reader.h} defines the structures, macros and functions
36910required to write a reader. It is installed (along with
36911@value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
36912the system include directory.
36913
36914Readers need to be released under a GPL compatible license. A reader
36915can be declared as released under such a license by placing the macro
36916@code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
36917
36918The entry point for readers is the symbol @code{gdb_init_reader},
36919which is expected to be a function with the prototype
36920
36921@findex gdb_init_reader
36922@smallexample
36923extern struct gdb_reader_funcs *gdb_init_reader (void);
36924@end smallexample
36925
36926@cindex @code{struct gdb_reader_funcs}
36927
36928@code{struct gdb_reader_funcs} contains a set of pointers to callback
36929functions. These functions are executed to read the debug info
36930generated by the JIT compiler (@code{read}), to unwind stack frames
36931(@code{unwind}) and to create canonical frame IDs
27f7b2f6 36932(@code{get_frame_id}). It also has a callback that is called when the
f85b53f8
SD
36933reader is being unloaded (@code{destroy}). The struct looks like this
36934
36935@smallexample
36936struct gdb_reader_funcs
36937@{
36938 /* Must be set to GDB_READER_INTERFACE_VERSION. */
36939 int reader_version;
36940
36941 /* For use by the reader. */
36942 void *priv_data;
36943
36944 gdb_read_debug_info *read;
36945 gdb_unwind_frame *unwind;
36946 gdb_get_frame_id *get_frame_id;
36947 gdb_destroy_reader *destroy;
36948@};
36949@end smallexample
36950
36951@cindex @code{struct gdb_symbol_callbacks}
36952@cindex @code{struct gdb_unwind_callbacks}
36953
36954The callbacks are provided with another set of callbacks by
36955@value{GDBN} to do their job. For @code{read}, these callbacks are
36956passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
36957and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
36958@code{struct gdb_symbol_callbacks} has callbacks to create new object
36959files and new symbol tables inside those object files. @code{struct
36960gdb_unwind_callbacks} has callbacks to read registers off the current
36961frame and to write out the values of the registers in the previous
36962frame. Both have a callback (@code{target_read}) to read bytes off the
36963target's address space.
36964
d1feda86
YQ
36965@node In-Process Agent
36966@chapter In-Process Agent
36967@cindex debugging agent
36968The traditional debugging model is conceptually low-speed, but works fine,
36969because most bugs can be reproduced in debugging-mode execution. However,
36970as multi-core or many-core processors are becoming mainstream, and
36971multi-threaded programs become more and more popular, there should be more
36972and more bugs that only manifest themselves at normal-mode execution, for
36973example, thread races, because debugger's interference with the program's
36974timing may conceal the bugs. On the other hand, in some applications,
36975it is not feasible for the debugger to interrupt the program's execution
36976long enough for the developer to learn anything helpful about its behavior.
36977If the program's correctness depends on its real-time behavior, delays
36978introduced by a debugger might cause the program to fail, even when the
36979code itself is correct. It is useful to be able to observe the program's
36980behavior without interrupting it.
36981
36982Therefore, traditional debugging model is too intrusive to reproduce
36983some bugs. In order to reduce the interference with the program, we can
36984reduce the number of operations performed by debugger. The
36985@dfn{In-Process Agent}, a shared library, is running within the same
36986process with inferior, and is able to perform some debugging operations
36987itself. As a result, debugger is only involved when necessary, and
36988performance of debugging can be improved accordingly. Note that
36989interference with program can be reduced but can't be removed completely,
36990because the in-process agent will still stop or slow down the program.
36991
36992The in-process agent can interpret and execute Agent Expressions
36993(@pxref{Agent Expressions}) during performing debugging operations. The
36994agent expressions can be used for different purposes, such as collecting
36995data in tracepoints, and condition evaluation in breakpoints.
36996
36997@anchor{Control Agent}
36998You can control whether the in-process agent is used as an aid for
36999debugging with the following commands:
37000
37001@table @code
37002@kindex set agent on
37003@item set agent on
37004Causes the in-process agent to perform some operations on behalf of the
37005debugger. Just which operations requested by the user will be done
37006by the in-process agent depends on the its capabilities. For example,
37007if you request to evaluate breakpoint conditions in the in-process agent,
37008and the in-process agent has such capability as well, then breakpoint
37009conditions will be evaluated in the in-process agent.
37010
37011@kindex set agent off
37012@item set agent off
37013Disables execution of debugging operations by the in-process agent. All
37014of the operations will be performed by @value{GDBN}.
37015
37016@kindex show agent
37017@item show agent
37018Display the current setting of execution of debugging operations by
37019the in-process agent.
37020@end table
37021
16bdd41f
YQ
37022@menu
37023* In-Process Agent Protocol::
37024@end menu
37025
37026@node In-Process Agent Protocol
37027@section In-Process Agent Protocol
37028@cindex in-process agent protocol
37029
37030The in-process agent is able to communicate with both @value{GDBN} and
37031GDBserver (@pxref{In-Process Agent}). This section documents the protocol
37032used for communications between @value{GDBN} or GDBserver and the IPA.
37033In general, @value{GDBN} or GDBserver sends commands
37034(@pxref{IPA Protocol Commands}) and data to in-process agent, and then
37035in-process agent replies back with the return result of the command, or
37036some other information. The data sent to in-process agent is composed
37037of primitive data types, such as 4-byte or 8-byte type, and composite
37038types, which are called objects (@pxref{IPA Protocol Objects}).
37039
37040@menu
37041* IPA Protocol Objects::
37042* IPA Protocol Commands::
37043@end menu
37044
37045@node IPA Protocol Objects
37046@subsection IPA Protocol Objects
37047@cindex ipa protocol objects
37048
37049The commands sent to and results received from agent may contain some
37050complex data types called @dfn{objects}.
37051
37052The in-process agent is running on the same machine with @value{GDBN}
37053or GDBserver, so it doesn't have to handle as much differences between
37054two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
37055However, there are still some differences of two ends in two processes:
37056
37057@enumerate
37058@item
37059word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
37060compiled as a 64-bit executable, while in-process agent is a 32-bit one.
37061@item
37062ABI. Some machines may have multiple types of ABI, @value{GDBN} or
37063GDBserver is compiled with one, and in-process agent is compiled with
37064the other one.
37065@end enumerate
37066
37067Here are the IPA Protocol Objects:
37068
37069@enumerate
37070@item
37071agent expression object. It represents an agent expression
37072(@pxref{Agent Expressions}).
37073@anchor{agent expression object}
37074@item
37075tracepoint action object. It represents a tracepoint action
37076(@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
37077memory, static trace data and to evaluate expression.
37078@anchor{tracepoint action object}
37079@item
37080tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
37081@anchor{tracepoint object}
37082
37083@end enumerate
37084
37085The following table describes important attributes of each IPA protocol
37086object:
37087
37088@multitable @columnfractions .30 .20 .50
37089@headitem Name @tab Size @tab Description
37090@item @emph{agent expression object} @tab @tab
37091@item length @tab 4 @tab length of bytes code
37092@item byte code @tab @var{length} @tab contents of byte code
37093@item @emph{tracepoint action for collecting memory} @tab @tab
37094@item 'M' @tab 1 @tab type of tracepoint action
37095@item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
37096address of the lowest byte to collect, otherwise @var{addr} is the offset
37097of @var{basereg} for memory collecting.
37098@item len @tab 8 @tab length of memory for collecting
37099@item basereg @tab 4 @tab the register number containing the starting
37100memory address for collecting.
37101@item @emph{tracepoint action for collecting registers} @tab @tab
37102@item 'R' @tab 1 @tab type of tracepoint action
37103@item @emph{tracepoint action for collecting static trace data} @tab @tab
37104@item 'L' @tab 1 @tab type of tracepoint action
37105@item @emph{tracepoint action for expression evaluation} @tab @tab
37106@item 'X' @tab 1 @tab type of tracepoint action
37107@item agent expression @tab length of @tab @ref{agent expression object}
37108@item @emph{tracepoint object} @tab @tab
37109@item number @tab 4 @tab number of tracepoint
37110@item address @tab 8 @tab address of tracepoint inserted on
37111@item type @tab 4 @tab type of tracepoint
37112@item enabled @tab 1 @tab enable or disable of tracepoint
37113@item step_count @tab 8 @tab step
37114@item pass_count @tab 8 @tab pass
37115@item numactions @tab 4 @tab number of tracepoint actions
37116@item hit count @tab 8 @tab hit count
37117@item trace frame usage @tab 8 @tab trace frame usage
37118@item compiled_cond @tab 8 @tab compiled condition
37119@item orig_size @tab 8 @tab orig size
37120@item condition @tab 4 if condition is NULL otherwise length of
37121@ref{agent expression object}
37122@tab zero if condition is NULL, otherwise is
37123@ref{agent expression object}
37124@item actions @tab variable
37125@tab numactions number of @ref{tracepoint action object}
37126@end multitable
37127
37128@node IPA Protocol Commands
37129@subsection IPA Protocol Commands
37130@cindex ipa protocol commands
37131
37132The spaces in each command are delimiters to ease reading this commands
37133specification. They don't exist in real commands.
37134
37135@table @samp
37136
37137@item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
37138Installs a new fast tracepoint described by @var{tracepoint_object}
697aa1b7 37139(@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
16bdd41f
YQ
37140head of @dfn{jumppad}, which is used to jump to data collection routine
37141in IPA finally.
37142
37143Replies:
37144@table @samp
37145@item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
37146@var{target_address} is address of tracepoint in the inferior.
697aa1b7 37147The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
16bdd41f 37148@var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
697aa1b7
EZ
37149The @var{fjump} contains a sequence of instructions jump to jumppad entry.
37150The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
16bdd41f
YQ
37151@item E @var{NN}
37152for an error
37153
37154@end table
37155
7255706c
YQ
37156@item close
37157Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
37158is about to kill inferiors.
37159
16bdd41f
YQ
37160@item qTfSTM
37161@xref{qTfSTM}.
37162@item qTsSTM
37163@xref{qTsSTM}.
37164@item qTSTMat
37165@xref{qTSTMat}.
37166@item probe_marker_at:@var{address}
37167Asks in-process agent to probe the marker at @var{address}.
37168
37169Replies:
37170@table @samp
37171@item E @var{NN}
37172for an error
37173@end table
37174@item unprobe_marker_at:@var{address}
37175Asks in-process agent to unprobe the marker at @var{address}.
37176@end table
37177
8e04817f
AC
37178@node GDB Bugs
37179@chapter Reporting Bugs in @value{GDBN}
37180@cindex bugs in @value{GDBN}
37181@cindex reporting bugs in @value{GDBN}
c906108c 37182
8e04817f 37183Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 37184
8e04817f
AC
37185Reporting a bug may help you by bringing a solution to your problem, or it
37186may not. But in any case the principal function of a bug report is to help
37187the entire community by making the next version of @value{GDBN} work better. Bug
37188reports are your contribution to the maintenance of @value{GDBN}.
c906108c 37189
8e04817f
AC
37190In order for a bug report to serve its purpose, you must include the
37191information that enables us to fix the bug.
c4555f82
SC
37192
37193@menu
8e04817f
AC
37194* Bug Criteria:: Have you found a bug?
37195* Bug Reporting:: How to report bugs
c4555f82
SC
37196@end menu
37197
8e04817f 37198@node Bug Criteria
79a6e687 37199@section Have You Found a Bug?
8e04817f 37200@cindex bug criteria
c4555f82 37201
8e04817f 37202If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
37203
37204@itemize @bullet
8e04817f
AC
37205@cindex fatal signal
37206@cindex debugger crash
37207@cindex crash of debugger
c4555f82 37208@item
8e04817f
AC
37209If the debugger gets a fatal signal, for any input whatever, that is a
37210@value{GDBN} bug. Reliable debuggers never crash.
37211
37212@cindex error on valid input
37213@item
37214If @value{GDBN} produces an error message for valid input, that is a
37215bug. (Note that if you're cross debugging, the problem may also be
37216somewhere in the connection to the target.)
c4555f82 37217
8e04817f 37218@cindex invalid input
c4555f82 37219@item
8e04817f
AC
37220If @value{GDBN} does not produce an error message for invalid input,
37221that is a bug. However, you should note that your idea of
37222``invalid input'' might be our idea of ``an extension'' or ``support
37223for traditional practice''.
37224
37225@item
37226If you are an experienced user of debugging tools, your suggestions
37227for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
37228@end itemize
37229
8e04817f 37230@node Bug Reporting
79a6e687 37231@section How to Report Bugs
8e04817f
AC
37232@cindex bug reports
37233@cindex @value{GDBN} bugs, reporting
37234
37235A number of companies and individuals offer support for @sc{gnu} products.
37236If you obtained @value{GDBN} from a support organization, we recommend you
37237contact that organization first.
37238
37239You can find contact information for many support companies and
37240individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
37241distribution.
37242@c should add a web page ref...
37243
c16158bc
JM
37244@ifset BUGURL
37245@ifset BUGURL_DEFAULT
129188f6 37246In any event, we also recommend that you submit bug reports for
d3e8051b 37247@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
37248@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
37249page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
37250be used.
8e04817f
AC
37251
37252@strong{Do not send bug reports to @samp{info-gdb}, or to
37253@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
37254not want to receive bug reports. Those that do have arranged to receive
37255@samp{bug-gdb}.
37256
37257The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
37258serves as a repeater. The mailing list and the newsgroup carry exactly
37259the same messages. Often people think of posting bug reports to the
37260newsgroup instead of mailing them. This appears to work, but it has one
37261problem which can be crucial: a newsgroup posting often lacks a mail
37262path back to the sender. Thus, if we need to ask for more information,
37263we may be unable to reach you. For this reason, it is better to send
37264bug reports to the mailing list.
c16158bc
JM
37265@end ifset
37266@ifclear BUGURL_DEFAULT
37267In any event, we also recommend that you submit bug reports for
37268@value{GDBN} to @value{BUGURL}.
37269@end ifclear
37270@end ifset
c4555f82 37271
8e04817f
AC
37272The fundamental principle of reporting bugs usefully is this:
37273@strong{report all the facts}. If you are not sure whether to state a
37274fact or leave it out, state it!
c4555f82 37275
8e04817f
AC
37276Often people omit facts because they think they know what causes the
37277problem and assume that some details do not matter. Thus, you might
37278assume that the name of the variable you use in an example does not matter.
37279Well, probably it does not, but one cannot be sure. Perhaps the bug is a
37280stray memory reference which happens to fetch from the location where that
37281name is stored in memory; perhaps, if the name were different, the contents
37282of that location would fool the debugger into doing the right thing despite
37283the bug. Play it safe and give a specific, complete example. That is the
37284easiest thing for you to do, and the most helpful.
c4555f82 37285
8e04817f
AC
37286Keep in mind that the purpose of a bug report is to enable us to fix the
37287bug. It may be that the bug has been reported previously, but neither
37288you nor we can know that unless your bug report is complete and
37289self-contained.
c4555f82 37290
8e04817f
AC
37291Sometimes people give a few sketchy facts and ask, ``Does this ring a
37292bell?'' Those bug reports are useless, and we urge everyone to
37293@emph{refuse to respond to them} except to chide the sender to report
37294bugs properly.
37295
37296To enable us to fix the bug, you should include all these things:
c4555f82
SC
37297
37298@itemize @bullet
37299@item
8e04817f
AC
37300The version of @value{GDBN}. @value{GDBN} announces it if you start
37301with no arguments; you can also print it at any time using @code{show
37302version}.
c4555f82 37303
8e04817f
AC
37304Without this, we will not know whether there is any point in looking for
37305the bug in the current version of @value{GDBN}.
c4555f82
SC
37306
37307@item
8e04817f
AC
37308The type of machine you are using, and the operating system name and
37309version number.
c4555f82 37310
6eaaf48b
EZ
37311@item
37312The details of the @value{GDBN} build-time configuration.
37313@value{GDBN} shows these details if you invoke it with the
37314@option{--configuration} command-line option, or if you type
37315@code{show configuration} at @value{GDBN}'s prompt.
37316
c4555f82 37317@item
c1468174 37318What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 37319``@value{GCC}--2.8.1''.
c4555f82
SC
37320
37321@item
8e04817f 37322What compiler (and its version) was used to compile the program you are
c1468174 37323debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
37324C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
37325to get this information; for other compilers, see the documentation for
37326those compilers.
c4555f82 37327
8e04817f
AC
37328@item
37329The command arguments you gave the compiler to compile your example and
37330observe the bug. For example, did you use @samp{-O}? To guarantee
37331you will not omit something important, list them all. A copy of the
37332Makefile (or the output from make) is sufficient.
c4555f82 37333
8e04817f
AC
37334If we were to try to guess the arguments, we would probably guess wrong
37335and then we might not encounter the bug.
c4555f82 37336
8e04817f
AC
37337@item
37338A complete input script, and all necessary source files, that will
37339reproduce the bug.
c4555f82 37340
8e04817f
AC
37341@item
37342A description of what behavior you observe that you believe is
37343incorrect. For example, ``It gets a fatal signal.''
c4555f82 37344
8e04817f
AC
37345Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
37346will certainly notice it. But if the bug is incorrect output, we might
37347not notice unless it is glaringly wrong. You might as well not give us
37348a chance to make a mistake.
c4555f82 37349
8e04817f
AC
37350Even if the problem you experience is a fatal signal, you should still
37351say so explicitly. Suppose something strange is going on, such as, your
37352copy of @value{GDBN} is out of synch, or you have encountered a bug in
37353the C library on your system. (This has happened!) Your copy might
37354crash and ours would not. If you told us to expect a crash, then when
37355ours fails to crash, we would know that the bug was not happening for
37356us. If you had not told us to expect a crash, then we would not be able
37357to draw any conclusion from our observations.
c4555f82 37358
e0c07bf0
MC
37359@pindex script
37360@cindex recording a session script
37361To collect all this information, you can use a session recording program
37362such as @command{script}, which is available on many Unix systems.
37363Just run your @value{GDBN} session inside @command{script} and then
37364include the @file{typescript} file with your bug report.
37365
37366Another way to record a @value{GDBN} session is to run @value{GDBN}
37367inside Emacs and then save the entire buffer to a file.
37368
8e04817f
AC
37369@item
37370If you wish to suggest changes to the @value{GDBN} source, send us context
37371diffs. If you even discuss something in the @value{GDBN} source, refer to
37372it by context, not by line number.
c4555f82 37373
8e04817f
AC
37374The line numbers in our development sources will not match those in your
37375sources. Your line numbers would convey no useful information to us.
c4555f82 37376
8e04817f 37377@end itemize
c4555f82 37378
8e04817f 37379Here are some things that are not necessary:
c4555f82 37380
8e04817f
AC
37381@itemize @bullet
37382@item
37383A description of the envelope of the bug.
c4555f82 37384
8e04817f
AC
37385Often people who encounter a bug spend a lot of time investigating
37386which changes to the input file will make the bug go away and which
37387changes will not affect it.
c4555f82 37388
8e04817f
AC
37389This is often time consuming and not very useful, because the way we
37390will find the bug is by running a single example under the debugger
37391with breakpoints, not by pure deduction from a series of examples.
37392We recommend that you save your time for something else.
c4555f82 37393
8e04817f
AC
37394Of course, if you can find a simpler example to report @emph{instead}
37395of the original one, that is a convenience for us. Errors in the
37396output will be easier to spot, running under the debugger will take
37397less time, and so on.
c4555f82 37398
8e04817f
AC
37399However, simplification is not vital; if you do not want to do this,
37400report the bug anyway and send us the entire test case you used.
c4555f82 37401
8e04817f
AC
37402@item
37403A patch for the bug.
c4555f82 37404
8e04817f
AC
37405A patch for the bug does help us if it is a good one. But do not omit
37406the necessary information, such as the test case, on the assumption that
37407a patch is all we need. We might see problems with your patch and decide
37408to fix the problem another way, or we might not understand it at all.
c4555f82 37409
8e04817f
AC
37410Sometimes with a program as complicated as @value{GDBN} it is very hard to
37411construct an example that will make the program follow a certain path
37412through the code. If you do not send us the example, we will not be able
37413to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 37414
8e04817f
AC
37415And if we cannot understand what bug you are trying to fix, or why your
37416patch should be an improvement, we will not install it. A test case will
37417help us to understand.
c4555f82 37418
8e04817f
AC
37419@item
37420A guess about what the bug is or what it depends on.
c4555f82 37421
8e04817f
AC
37422Such guesses are usually wrong. Even we cannot guess right about such
37423things without first using the debugger to find the facts.
37424@end itemize
c4555f82 37425
8e04817f
AC
37426@c The readline documentation is distributed with the readline code
37427@c and consists of the two following files:
cc88a640
JK
37428@c rluser.texi
37429@c hsuser.texi
8e04817f
AC
37430@c Use -I with makeinfo to point to the appropriate directory,
37431@c environment var TEXINPUTS with TeX.
39037522 37432@ifclear SYSTEM_READLINE
5bdf8622 37433@include rluser.texi
cc88a640 37434@include hsuser.texi
39037522 37435@end ifclear
c4555f82 37436
4ceed123
JB
37437@node In Memoriam
37438@appendix In Memoriam
37439
9ed350ad
JB
37440The @value{GDBN} project mourns the loss of the following long-time
37441contributors:
4ceed123
JB
37442
37443@table @code
37444@item Fred Fish
9ed350ad
JB
37445Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
37446to Free Software in general. Outside of @value{GDBN}, he was known in
37447the Amiga world for his series of Fish Disks, and the GeekGadget project.
4ceed123
JB
37448
37449@item Michael Snyder
9ed350ad
JB
37450Michael was one of the Global Maintainers of the @value{GDBN} project,
37451with contributions recorded as early as 1996, until 2011. In addition
37452to his day to day participation, he was a large driving force behind
37453adding Reverse Debugging to @value{GDBN}.
4ceed123
JB
37454@end table
37455
37456Beyond their technical contributions to the project, they were also
37457enjoyable members of the Free Software Community. We will miss them.
c4555f82 37458
8e04817f
AC
37459@node Formatting Documentation
37460@appendix Formatting Documentation
c4555f82 37461
8e04817f
AC
37462@cindex @value{GDBN} reference card
37463@cindex reference card
37464The @value{GDBN} 4 release includes an already-formatted reference card, ready
37465for printing with PostScript or Ghostscript, in the @file{gdb}
37466subdirectory of the main source directory@footnote{In
37467@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
37468release.}. If you can use PostScript or Ghostscript with your printer,
37469you can print the reference card immediately with @file{refcard.ps}.
c4555f82 37470
8e04817f
AC
37471The release also includes the source for the reference card. You
37472can format it, using @TeX{}, by typing:
c4555f82 37473
474c8240 37474@smallexample
8e04817f 37475make refcard.dvi
474c8240 37476@end smallexample
c4555f82 37477
8e04817f
AC
37478The @value{GDBN} reference card is designed to print in @dfn{landscape}
37479mode on US ``letter'' size paper;
37480that is, on a sheet 11 inches wide by 8.5 inches
37481high. You will need to specify this form of printing as an option to
37482your @sc{dvi} output program.
c4555f82 37483
8e04817f 37484@cindex documentation
c4555f82 37485
8e04817f
AC
37486All the documentation for @value{GDBN} comes as part of the machine-readable
37487distribution. The documentation is written in Texinfo format, which is
37488a documentation system that uses a single source file to produce both
37489on-line information and a printed manual. You can use one of the Info
37490formatting commands to create the on-line version of the documentation
37491and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 37492
8e04817f
AC
37493@value{GDBN} includes an already formatted copy of the on-line Info
37494version of this manual in the @file{gdb} subdirectory. The main Info
37495file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
37496subordinate files matching @samp{gdb.info*} in the same directory. If
37497necessary, you can print out these files, or read them with any editor;
37498but they are easier to read using the @code{info} subsystem in @sc{gnu}
37499Emacs or the standalone @code{info} program, available as part of the
37500@sc{gnu} Texinfo distribution.
c4555f82 37501
8e04817f
AC
37502If you want to format these Info files yourself, you need one of the
37503Info formatting programs, such as @code{texinfo-format-buffer} or
37504@code{makeinfo}.
c4555f82 37505
8e04817f
AC
37506If you have @code{makeinfo} installed, and are in the top level
37507@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
37508version @value{GDBVN}), you can make the Info file by typing:
c4555f82 37509
474c8240 37510@smallexample
8e04817f
AC
37511cd gdb
37512make gdb.info
474c8240 37513@end smallexample
c4555f82 37514
8e04817f
AC
37515If you want to typeset and print copies of this manual, you need @TeX{},
37516a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
37517Texinfo definitions file.
c4555f82 37518
8e04817f
AC
37519@TeX{} is a typesetting program; it does not print files directly, but
37520produces output files called @sc{dvi} files. To print a typeset
37521document, you need a program to print @sc{dvi} files. If your system
37522has @TeX{} installed, chances are it has such a program. The precise
37523command to use depends on your system; @kbd{lpr -d} is common; another
37524(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
37525require a file name without any extension or a @samp{.dvi} extension.
c4555f82 37526
8e04817f
AC
37527@TeX{} also requires a macro definitions file called
37528@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
37529written in Texinfo format. On its own, @TeX{} cannot either read or
37530typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
37531and is located in the @file{gdb-@var{version-number}/texinfo}
37532directory.
c4555f82 37533
8e04817f 37534If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 37535typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
37536subdirectory of the main source directory (for example, to
37537@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 37538
474c8240 37539@smallexample
8e04817f 37540make gdb.dvi
474c8240 37541@end smallexample
c4555f82 37542
8e04817f 37543Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 37544
8e04817f
AC
37545@node Installing GDB
37546@appendix Installing @value{GDBN}
8e04817f 37547@cindex installation
c4555f82 37548
7fa2210b
DJ
37549@menu
37550* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 37551* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
37552* Separate Objdir:: Compiling @value{GDBN} in another directory
37553* Config Names:: Specifying names for hosts and targets
37554* Configure Options:: Summary of options for configure
098b41a6 37555* System-wide configuration:: Having a system-wide init file
7fa2210b
DJ
37556@end menu
37557
37558@node Requirements
79a6e687 37559@section Requirements for Building @value{GDBN}
7fa2210b
DJ
37560@cindex building @value{GDBN}, requirements for
37561
37562Building @value{GDBN} requires various tools and packages to be available.
37563Other packages will be used only if they are found.
37564
79a6e687 37565@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b 37566@table @asis
7f0bd420
TT
37567@item C@t{++}11 compiler
37568@value{GDBN} is written in C@t{++}11. It should be buildable with any
37569recent C@t{++}11 compiler, e.g.@: GCC.
7fa2210b 37570
7f0bd420
TT
37571@item GNU make
37572@value{GDBN}'s build system relies on features only found in the GNU
37573make program. Other variants of @code{make} will not work.
7fa2210b
DJ
37574@end table
37575
79a6e687 37576@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
37577@table @asis
37578@item Expat
123dc839 37579@anchor{Expat}
7fa2210b
DJ
37580@value{GDBN} can use the Expat XML parsing library. This library may be
37581included with your operating system distribution; if it is not, you
37582can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 37583The @file{configure} script will search for this library in several
7fa2210b
DJ
37584standard locations; if it is installed in an unusual path, you can
37585use the @option{--with-libexpat-prefix} option to specify its location.
37586
9cceb671
DJ
37587Expat is used for:
37588
37589@itemize @bullet
37590@item
37591Remote protocol memory maps (@pxref{Memory Map Format})
37592@item
37593Target descriptions (@pxref{Target Descriptions})
37594@item
2268b414
JK
37595Remote shared library lists (@xref{Library List Format},
37596or alternatively @pxref{Library List Format for SVR4 Targets})
9cceb671
DJ
37597@item
37598MS-Windows shared libraries (@pxref{Shared Libraries})
b3b9301e
PA
37599@item
37600Traceframe info (@pxref{Traceframe Info Format})
2ae8c8e7 37601@item
f4abbc16
MM
37602Branch trace (@pxref{Branch Trace Format},
37603@pxref{Branch Trace Configuration Format})
9cceb671 37604@end itemize
7fa2210b 37605
7f0bd420
TT
37606@item Guile
37607@value{GDBN} can be scripted using GNU Guile. @xref{Guile}. By
37608default, @value{GDBN} will be compiled if the Guile libraries are
37609installed and are found by @file{configure}. You can use the
37610@code{--with-guile} option to request Guile, and pass either the Guile
37611version number or the file name of the relevant @code{pkg-config}
37612program to choose a particular version of Guile.
37613
37614@item iconv
37615@value{GDBN}'s features related to character sets (@pxref{Character
37616Sets}) require a functioning @code{iconv} implementation. If you are
37617on a GNU system, then this is provided by the GNU C Library. Some
37618other systems also provide a working @code{iconv}.
37619
37620If @value{GDBN} is using the @code{iconv} program which is installed
37621in a non-standard place, you will need to tell @value{GDBN} where to
37622find it. This is done with @option{--with-iconv-bin} which specifies
37623the directory that contains the @code{iconv} program. This program is
37624run in order to make a list of the available character sets.
37625
37626On systems without @code{iconv}, you can install GNU Libiconv. If
37627Libiconv is installed in a standard place, @value{GDBN} will
37628automatically use it if it is needed. If you have previously
37629installed Libiconv in a non-standard place, you can use the
37630@option{--with-libiconv-prefix} option to @file{configure}.
37631
37632@value{GDBN}'s top-level @file{configure} and @file{Makefile} will
37633arrange to build Libiconv if a directory named @file{libiconv} appears
37634in the top-most source directory. If Libiconv is built this way, and
37635if the operating system does not provide a suitable @code{iconv}
37636implementation, then the just-built library will automatically be used
37637by @value{GDBN}. One easy way to set this up is to download GNU
37638Libiconv, unpack it inside the top-level directory of the @value{GDBN}
37639source tree, and then rename the directory holding the Libiconv source
37640code to @samp{libiconv}.
37641
37642@item lzma
37643@value{GDBN} can support debugging sections that are compressed with
37644the LZMA library. @xref{MiniDebugInfo}. If this library is not
37645included with your operating system, you can find it in the xz package
37646at @url{http://tukaani.org/xz/}. If the LZMA library is available in
37647the usual place, then the @file{configure} script will use it
37648automatically. If it is installed in an unusual path, you can use the
37649@option{--with-lzma-prefix} option to specify its location.
37650
2400729e
UW
37651@item MPFR
37652@anchor{MPFR}
37653@value{GDBN} can use the GNU MPFR multiple-precision floating-point
37654library. This library may be included with your operating system
37655distribution; if it is not, you can get the latest version from
37656@url{http://www.mpfr.org}. The @file{configure} script will search
37657for this library in several standard locations; if it is installed
37658in an unusual path, you can use the @option{--with-libmpfr-prefix}
37659option to specify its location.
37660
37661GNU MPFR is used to emulate target floating-point arithmetic during
37662expression evaluation when the target uses different floating-point
37663formats than the host. If GNU MPFR it is not available, @value{GDBN}
37664will fall back to using host floating-point arithmetic.
37665
7f0bd420
TT
37666@item Python
37667@value{GDBN} can be scripted using Python language. @xref{Python}.
37668By default, @value{GDBN} will be compiled if the Python libraries are
37669installed and are found by @file{configure}. You can use the
37670@code{--with-python} option to request Python, and pass either the
37671file name of the relevant @code{python} executable, or the name of the
37672directory in which Python is installed, to choose a particular
37673installation of Python.
37674
31fffb02
CS
37675@item zlib
37676@cindex compressed debug sections
37677@value{GDBN} will use the @samp{zlib} library, if available, to read
37678compressed debug sections. Some linkers, such as GNU gold, are capable
37679of producing binaries with compressed debug sections. If @value{GDBN}
37680is compiled with @samp{zlib}, it will be able to read the debug
37681information in such binaries.
37682
37683The @samp{zlib} library is likely included with your operating system
37684distribution; if it is not, you can get the latest version from
37685@url{http://zlib.net}.
7fa2210b
DJ
37686@end table
37687
37688@node Running Configure
db2e3e2e 37689@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 37690@cindex configuring @value{GDBN}
db2e3e2e 37691@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
37692of preparing @value{GDBN} for installation; you can then use @code{make} to
37693build the @code{gdb} program.
37694@iftex
37695@c irrelevant in info file; it's as current as the code it lives with.
37696@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
37697look at the @file{README} file in the sources; we may have improved the
37698installation procedures since publishing this manual.}
37699@end iftex
c4555f82 37700
8e04817f
AC
37701The @value{GDBN} distribution includes all the source code you need for
37702@value{GDBN} in a single directory, whose name is usually composed by
37703appending the version number to @samp{gdb}.
c4555f82 37704
8e04817f
AC
37705For example, the @value{GDBN} version @value{GDBVN} distribution is in the
37706@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 37707
8e04817f
AC
37708@table @code
37709@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
37710script for configuring @value{GDBN} and all its supporting libraries
c4555f82 37711
8e04817f
AC
37712@item gdb-@value{GDBVN}/gdb
37713the source specific to @value{GDBN} itself
c4555f82 37714
8e04817f
AC
37715@item gdb-@value{GDBVN}/bfd
37716source for the Binary File Descriptor library
c906108c 37717
8e04817f
AC
37718@item gdb-@value{GDBVN}/include
37719@sc{gnu} include files
c906108c 37720
8e04817f
AC
37721@item gdb-@value{GDBVN}/libiberty
37722source for the @samp{-liberty} free software library
c906108c 37723
8e04817f
AC
37724@item gdb-@value{GDBVN}/opcodes
37725source for the library of opcode tables and disassemblers
c906108c 37726
8e04817f
AC
37727@item gdb-@value{GDBVN}/readline
37728source for the @sc{gnu} command-line interface
8e04817f 37729@end table
c906108c 37730
7f0bd420
TT
37731There may be other subdirectories as well.
37732
db2e3e2e 37733The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
37734from the @file{gdb-@var{version-number}} source directory, which in
37735this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 37736
8e04817f 37737First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 37738if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
37739identifier for the platform on which @value{GDBN} will run as an
37740argument.
c906108c 37741
8e04817f 37742For example:
c906108c 37743
474c8240 37744@smallexample
8e04817f 37745cd gdb-@value{GDBVN}
7f0bd420 37746./configure
8e04817f 37747make
474c8240 37748@end smallexample
c906108c 37749
7f0bd420
TT
37750Running @samp{configure} and then running @code{make} builds the
37751included supporting libraries, then @code{gdb} itself. The configured
37752source files, and the binaries, are left in the corresponding source
37753directories.
c906108c 37754
8e04817f 37755@need 750
db2e3e2e 37756@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
37757system does not recognize this automatically when you run a different
37758shell, you may need to run @code{sh} on it explicitly:
c906108c 37759
474c8240 37760@smallexample
7f0bd420 37761sh configure
474c8240 37762@end smallexample
c906108c 37763
db2e3e2e 37764You should run the @file{configure} script from the top directory in the
94e91d6d 37765source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 37766@file{configure} from one of the subdirectories, you will configure only
94e91d6d 37767that subdirectory. That is usually not what you want. In particular,
db2e3e2e 37768if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
37769of the @file{gdb-@var{version-number}} directory, you will omit the
37770configuration of @file{bfd}, @file{readline}, and other sibling
37771directories of the @file{gdb} subdirectory. This leads to build errors
37772about missing include files such as @file{bfd/bfd.h}.
c906108c 37773
7f0bd420
TT
37774You can install @code{@value{GDBN}} anywhere. The best way to do this
37775is to pass the @code{--prefix} option to @code{configure}, and then
37776install it with @code{make install}.
c906108c 37777
8e04817f 37778@node Separate Objdir
79a6e687 37779@section Compiling @value{GDBN} in Another Directory
c906108c 37780
8e04817f
AC
37781If you want to run @value{GDBN} versions for several host or target machines,
37782you need a different @code{gdb} compiled for each combination of
db2e3e2e 37783host and target. @file{configure} is designed to make this easy by
8e04817f
AC
37784allowing you to generate each configuration in a separate subdirectory,
37785rather than in the source directory. If your @code{make} program
37786handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
37787@code{make} in each of these directories builds the @code{gdb}
37788program specified there.
c906108c 37789
db2e3e2e 37790To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 37791with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
37792(You also need to specify a path to find @file{configure}
37793itself from your working directory. If the path to @file{configure}
8e04817f
AC
37794would be the same as the argument to @samp{--srcdir}, you can leave out
37795the @samp{--srcdir} option; it is assumed.)
c906108c 37796
8e04817f
AC
37797For example, with version @value{GDBVN}, you can build @value{GDBN} in a
37798separate directory for a Sun 4 like this:
c906108c 37799
474c8240 37800@smallexample
8e04817f
AC
37801@group
37802cd gdb-@value{GDBVN}
37803mkdir ../gdb-sun4
37804cd ../gdb-sun4
7f0bd420 37805../gdb-@value{GDBVN}/configure
8e04817f
AC
37806make
37807@end group
474c8240 37808@end smallexample
c906108c 37809
db2e3e2e 37810When @file{configure} builds a configuration using a remote source
8e04817f
AC
37811directory, it creates a tree for the binaries with the same structure
37812(and using the same names) as the tree under the source directory. In
37813the example, you'd find the Sun 4 library @file{libiberty.a} in the
37814directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
37815@file{gdb-sun4/gdb}.
c906108c 37816
94e91d6d
MC
37817Make sure that your path to the @file{configure} script has just one
37818instance of @file{gdb} in it. If your path to @file{configure} looks
37819like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
37820one subdirectory of @value{GDBN}, not the whole package. This leads to
37821build errors about missing include files such as @file{bfd/bfd.h}.
37822
8e04817f
AC
37823One popular reason to build several @value{GDBN} configurations in separate
37824directories is to configure @value{GDBN} for cross-compiling (where
37825@value{GDBN} runs on one machine---the @dfn{host}---while debugging
37826programs that run on another machine---the @dfn{target}).
37827You specify a cross-debugging target by
db2e3e2e 37828giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 37829
8e04817f
AC
37830When you run @code{make} to build a program or library, you must run
37831it in a configured directory---whatever directory you were in when you
db2e3e2e 37832called @file{configure} (or one of its subdirectories).
c906108c 37833
db2e3e2e 37834The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
37835directory also runs recursively. If you type @code{make} in a source
37836directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
37837directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
37838will build all the required libraries, and then build GDB.
c906108c 37839
8e04817f
AC
37840When you have multiple hosts or targets configured in separate
37841directories, you can run @code{make} on them in parallel (for example,
37842if they are NFS-mounted on each of the hosts); they will not interfere
37843with each other.
c906108c 37844
8e04817f 37845@node Config Names
79a6e687 37846@section Specifying Names for Hosts and Targets
c906108c 37847
db2e3e2e 37848The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
37849script are based on a three-part naming scheme, but some short predefined
37850aliases are also supported. The full naming scheme encodes three pieces
37851of information in the following pattern:
c906108c 37852
474c8240 37853@smallexample
8e04817f 37854@var{architecture}-@var{vendor}-@var{os}
474c8240 37855@end smallexample
c906108c 37856
8e04817f
AC
37857For example, you can use the alias @code{sun4} as a @var{host} argument,
37858or as the value for @var{target} in a @code{--target=@var{target}}
37859option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 37860
db2e3e2e 37861The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 37862any query facility to list all supported host and target names or
db2e3e2e 37863aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
37864@code{config.sub} to map abbreviations to full names; you can read the
37865script, if you wish, or you can use it to test your guesses on
37866abbreviations---for example:
c906108c 37867
8e04817f
AC
37868@smallexample
37869% sh config.sub i386-linux
37870i386-pc-linux-gnu
37871% sh config.sub alpha-linux
37872alpha-unknown-linux-gnu
37873% sh config.sub hp9k700
37874hppa1.1-hp-hpux
37875% sh config.sub sun4
37876sparc-sun-sunos4.1.1
37877% sh config.sub sun3
37878m68k-sun-sunos4.1.1
37879% sh config.sub i986v
37880Invalid configuration `i986v': machine `i986v' not recognized
37881@end smallexample
c906108c 37882
8e04817f
AC
37883@noindent
37884@code{config.sub} is also distributed in the @value{GDBN} source
37885directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 37886
8e04817f 37887@node Configure Options
db2e3e2e 37888@section @file{configure} Options
c906108c 37889
db2e3e2e 37890Here is a summary of the @file{configure} options and arguments that
7f0bd420
TT
37891are most often useful for building @value{GDBN}. @file{configure}
37892also has several other options not listed here. @inforef{Running
37893configure scripts,,autoconf.info}, for a full
37894explanation of @file{configure}.
c906108c 37895
474c8240 37896@smallexample
8e04817f
AC
37897configure @r{[}--help@r{]}
37898 @r{[}--prefix=@var{dir}@r{]}
37899 @r{[}--exec-prefix=@var{dir}@r{]}
37900 @r{[}--srcdir=@var{dirname}@r{]}
8e04817f 37901 @r{[}--target=@var{target}@r{]}
474c8240 37902@end smallexample
c906108c 37903
8e04817f
AC
37904@noindent
37905You may introduce options with a single @samp{-} rather than
37906@samp{--} if you prefer; but you may abbreviate option names if you use
37907@samp{--}.
c906108c 37908
8e04817f
AC
37909@table @code
37910@item --help
db2e3e2e 37911Display a quick summary of how to invoke @file{configure}.
c906108c 37912
8e04817f
AC
37913@item --prefix=@var{dir}
37914Configure the source to install programs and files under directory
37915@file{@var{dir}}.
c906108c 37916
8e04817f
AC
37917@item --exec-prefix=@var{dir}
37918Configure the source to install programs under directory
37919@file{@var{dir}}.
c906108c 37920
8e04817f
AC
37921@c avoid splitting the warning from the explanation:
37922@need 2000
37923@item --srcdir=@var{dirname}
8e04817f
AC
37924Use this option to make configurations in directories separate from the
37925@value{GDBN} source directories. Among other things, you can use this to
37926build (or maintain) several configurations simultaneously, in separate
db2e3e2e 37927directories. @file{configure} writes configuration-specific files in
8e04817f 37928the current directory, but arranges for them to use the source in the
db2e3e2e 37929directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
37930the working directory in parallel to the source directories below
37931@var{dirname}.
c906108c 37932
8e04817f
AC
37933@item --target=@var{target}
37934Configure @value{GDBN} for cross-debugging programs running on the specified
37935@var{target}. Without this option, @value{GDBN} is configured to debug
37936programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 37937
a95746f9
TT
37938There is no convenient way to generate a list of all available
37939targets. Also see the @code{--enable-targets} option, below.
8e04817f 37940@end table
c906108c 37941
a95746f9
TT
37942There are many other options that are specific to @value{GDBN}. This
37943lists just the most common ones; there are some very specialized
37944options not described here.
37945
37946@table @code
37947@item --enable-targets=@r{[}@var{target}@r{]}@dots{}
37948@itemx --enable-targets=all
37949Configure @value{GDBN} for cross-debugging programs running on the
37950specified list of targets. The special value @samp{all} configures
37951@value{GDBN} for debugging programs running on any target it supports.
37952
37953@item --with-gdb-datadir=@var{path}
37954Set the @value{GDBN}-specific data directory. @value{GDBN} will look
37955here for certain supporting files or scripts. This defaults to the
6b92c0d3 37956@file{gdb} subdirectory of @samp{datadir} (which can be set using
a95746f9
TT
37957@code{--datadir}).
37958
37959@item --with-relocated-sources=@var{dir}
37960Sets up the default source path substitution rule so that directory
37961names recorded in debug information will be automatically adjusted for
37962any directory under @var{dir}. @var{dir} should be a subdirectory of
37963@value{GDBN}'s configured prefix, the one mentioned in the
37964@code{--prefix} or @code{--exec-prefix} options to configure. This
37965option is useful if GDB is supposed to be moved to a different place
37966after it is built.
37967
37968@item --enable-64-bit-bfd
37969Enable 64-bit support in BFD on 32-bit hosts.
37970
37971@item --disable-gdbmi
37972Build @value{GDBN} without the GDB/MI machine interface
37973(@pxref{GDB/MI}).
37974
37975@item --enable-tui
37976Build @value{GDBN} with the text-mode full-screen user interface
37977(TUI). Requires a curses library (ncurses and cursesX are also
37978supported).
37979
37980@item --with-curses
37981Use the curses library instead of the termcap library, for text-mode
37982terminal operations.
37983
0d79cdc4
AM
37984@item --with-debuginfod
37985Build @value{GDBN} with libdebuginfod, the debuginfod client library.
37986Used to automatically fetch source files and separate debug files from
37987debuginfod servers using the associated executable's build ID. Enabled
37988by default if libdebuginfod is installed and found at configure time.
37989debuginfod is packaged with elfutils, starting with version 0.178. You
37990can get the latest version from `https://sourceware.org/elfutils/'.
37991
a95746f9
TT
37992@item --with-libunwind-ia64
37993Use the libunwind library for unwinding function call stack on ia64
37994target platforms. See http://www.nongnu.org/libunwind/index.html for
37995details.
37996
37997@item --with-system-readline
37998Use the readline library installed on the host, rather than the
86c6b807
TT
37999library supplied as part of @value{GDBN}. Readline 7 or newer is
38000required; this is enforced by the build system.
a95746f9
TT
38001
38002@item --with-system-zlib
38003Use the zlib library installed on the host, rather than the library
38004supplied as part of @value{GDBN}.
38005
38006@item --with-expat
38007Build @value{GDBN} with Expat, a library for XML parsing. (Done by
38008default if libexpat is installed and found at configure time.) This
38009library is used to read XML files supplied with @value{GDBN}. If it
38010is unavailable, some features, such as remote protocol memory maps,
38011target descriptions, and shared library lists, that are based on XML
38012files, will not be available in @value{GDBN}. If your host does not
38013have libexpat installed, you can get the latest version from
38014`http://expat.sourceforge.net'.
38015
38016@item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
38017
38018Build @value{GDBN} with GNU libiconv, a character set encoding
38019conversion library. This is not done by default, as on GNU systems
38020the @code{iconv} that is built in to the C library is sufficient. If
38021your host does not have a working @code{iconv}, you can get the latest
38022version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
38023
38024@value{GDBN}'s build system also supports building GNU libiconv as
38025part of the overall build. @xref{Requirements}.
38026
38027@item --with-lzma
38028Build @value{GDBN} with LZMA, a compression library. (Done by default
38029if liblzma is installed and found at configure time.) LZMA is used by
38030@value{GDBN}'s "mini debuginfo" feature, which is only useful on
38031platforms using the ELF object file format. If your host does not
38032have liblzma installed, you can get the latest version from
38033`https://tukaani.org/xz/'.
38034
38035@item --with-mpfr
38036Build @value{GDBN} with GNU MPFR, a library for multiple-precision
38037floating-point computation with correct rounding. (Done by default if
38038GNU MPFR is installed and found at configure time.) This library is
38039used to emulate target floating-point arithmetic during expression
38040evaluation when the target uses different floating-point formats than
38041the host. If GNU MPFR is not available, @value{GDBN} will fall back
38042to using host floating-point arithmetic. If your host does not have
38043GNU MPFR installed, you can get the latest version from
38044`http://www.mpfr.org'.
38045
38046@item --with-python@r{[}=@var{python}@r{]}
38047Build @value{GDBN} with Python scripting support. (Done by default if
38048libpython is present and found at configure time.) Python makes
38049@value{GDBN} scripting much more powerful than the restricted CLI
38050scripting language. If your host does not have Python installed, you
38051can find it on `http://www.python.org/download/'. The oldest version
2c3fc25d 38052of Python supported by GDB is 2.6. The optional argument @var{python}
a95746f9
TT
38053is used to find the Python headers and libraries. It can be either
38054the name of a Python executable, or the name of the directory in which
38055Python is installed.
38056
38057@item --with-guile[=GUILE]'
38058Build @value{GDBN} with GNU Guile scripting support. (Done by default
38059if libguile is present and found at configure time.) If your host
38060does not have Guile installed, you can find it at
38061`https://www.gnu.org/software/guile/'. The optional argument GUILE
38062can be a version number, which will cause @code{configure} to try to
38063use that version of Guile; or the file name of a @code{pkg-config}
38064executable, which will be queried to find the information needed to
38065compile and link against Guile.
38066
38067@item --without-included-regex
38068Don't use the regex library included with @value{GDBN} (as part of the
38069libiberty library). This is the default on hosts with version 2 of
38070the GNU C library.
38071
38072@item --with-sysroot=@var{dir}
38073Use @var{dir} as the default system root directory for libraries whose
38074file names begin with @file{/lib}' or @file{/usr/lib'}. (The value of
38075@var{dir} can be modified at run time by using the @command{set
38076sysroot} command.) If @var{dir} is under the @value{GDBN} configured
38077prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
38078default system root will be automatically adjusted if and when
38079@value{GDBN} is moved to a different location.
38080
38081@item --with-system-gdbinit=@var{file}
38082Configure @value{GDBN} to automatically load a system-wide init file.
38083@var{file} should be an absolute file name. If @var{file} is in a
38084directory under the configured prefix, and @value{GDBN} is moved to
38085another location after being built, the location of the system-wide
38086init file will be adjusted accordingly.
38087
ed2a2229
CB
38088@item --with-system-gdbinit-dir=@var{directory}
38089Configure @value{GDBN} to automatically load init files from a
38090system-wide directory. @var{directory} should be an absolute directory
38091name. If @var{directory} is in a directory under the configured
38092prefix, and @value{GDBN} is moved to another location after being
38093built, the location of the system-wide init directory will be
38094adjusted accordingly.
38095
a95746f9
TT
38096@item --enable-build-warnings
38097When building the @value{GDBN} sources, ask the compiler to warn about
38098any code which looks even vaguely suspicious. It passes many
38099different warning flags, depending on the exact version of the
38100compiler you are using.
38101
38102@item --enable-werror
38103Treat compiler warnings as werrors. It adds the @code{-Werror} flag
38104to the compiler, which will fail the compilation if the compiler
38105outputs any warning messages.
f35d5ade
TT
38106
38107@item --enable-ubsan
eff98030
TT
38108Enable the GCC undefined behavior sanitizer. This is disabled by
38109default, but passing @code{--enable-ubsan=yes} or
38110@code{--enable-ubsan=auto} to @code{configure} will enable it. The
38111undefined behavior sanitizer checks for C@t{++} undefined behavior.
38112It has a performance cost, so if you are looking at @value{GDBN}'s
38113performance, you should disable it. The undefined behavior sanitizer
38114was first introduced in GCC 4.9.
a95746f9 38115@end table
c906108c 38116
098b41a6
JG
38117@node System-wide configuration
38118@section System-wide configuration and settings
38119@cindex system-wide init file
38120
ed2a2229
CB
38121@value{GDBN} can be configured to have a system-wide init file and a
38122system-wide init file directory; this file and files in that directory
38123(if they have a recognized file extension) will be read and executed at
38124startup (@pxref{Startup, , What @value{GDBN} does during startup}).
098b41a6 38125
ed2a2229 38126Here are the corresponding configure options:
098b41a6
JG
38127
38128@table @code
38129@item --with-system-gdbinit=@var{file}
38130Specify that the default location of the system-wide init file is
38131@var{file}.
ed2a2229
CB
38132@item --with-system-gdbinit-dir=@var{directory}
38133Specify that the default location of the system-wide init file directory
38134is @var{directory}.
098b41a6
JG
38135@end table
38136
38137If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
ed2a2229 38138they may be subject to relocation. Two possible cases:
098b41a6
JG
38139
38140@itemize @bullet
38141@item
ed2a2229 38142If the default location of this init file/directory contains @file{$prefix},
098b41a6
JG
38143it will be subject to relocation. Suppose that the configure options
38144are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
38145if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
38146init file is looked for as @file{$install/etc/gdbinit} instead of
38147@file{$prefix/etc/gdbinit}.
38148
38149@item
38150By contrast, if the default location does not contain the prefix,
38151it will not be relocated. E.g.@: if @value{GDBN} has been configured with
38152@option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
38153then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
38154wherever @value{GDBN} is installed.
38155@end itemize
38156
e64e0392
DE
38157If the configured location of the system-wide init file (as given by the
38158@option{--with-system-gdbinit} option at configure time) is in the
38159data-directory (as specified by @option{--with-gdb-datadir} at configure
38160time) or in one of its subdirectories, then @value{GDBN} will look for the
38161system-wide init file in the directory specified by the
38162@option{--data-directory} command-line option.
38163Note that the system-wide init file is only read once, during @value{GDBN}
38164initialization. If the data-directory is changed after @value{GDBN} has
38165started with the @code{set data-directory} command, the file will not be
38166reread.
38167
ed2a2229
CB
38168This applies similarly to the system-wide directory specified in
38169@option{--with-system-gdbinit-dir}.
38170
38171Any supported scripting language can be used for these init files, as long
38172as the file extension matches the scripting language. To be interpreted
38173as regular @value{GDBN} commands, the files needs to have a @file{.gdb}
38174extension.
38175
5901af59
JB
38176@menu
38177* System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
38178@end menu
38179
38180@node System-wide Configuration Scripts
0201faac
JB
38181@subsection Installed System-wide Configuration Scripts
38182@cindex system-wide configuration scripts
38183
38184The @file{system-gdbinit} directory, located inside the data-directory
38185(as specified by @option{--with-gdb-datadir} at configure time) contains
38186a number of scripts which can be used as system-wide init files. To
38187automatically source those scripts at startup, @value{GDBN} should be
38188configured with @option{--with-system-gdbinit}. Otherwise, any user
38189should be able to source them by hand as needed.
38190
38191The following scripts are currently available:
38192@itemize @bullet
38193
38194@item @file{elinos.py}
38195@pindex elinos.py
38196@cindex ELinOS system-wide configuration script
38197This script is useful when debugging a program on an ELinOS target.
38198It takes advantage of the environment variables defined in a standard
38199ELinOS environment in order to determine the location of the system
38200shared libraries, and then sets the @samp{solib-absolute-prefix}
38201and @samp{solib-search-path} variables appropriately.
38202
38203@item @file{wrs-linux.py}
38204@pindex wrs-linux.py
38205@cindex Wind River Linux system-wide configuration script
38206This script is useful when debugging a program on a target running
38207Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
38208the host-side sysroot used by the target system.
38209
38210@end itemize
38211
8e04817f
AC
38212@node Maintenance Commands
38213@appendix Maintenance Commands
38214@cindex maintenance commands
38215@cindex internal commands
c906108c 38216
8e04817f 38217In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
38218includes a number of commands intended for @value{GDBN} developers,
38219that are not documented elsewhere in this manual. These commands are
da316a69
EZ
38220provided here for reference. (For commands that turn on debugging
38221messages, see @ref{Debugging Output}.)
c906108c 38222
8e04817f 38223@table @code
09d4efe1 38224@kindex maint agent
782b2b07 38225@kindex maint agent-eval
f77cc5f0
HZ
38226@item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38227@itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
09d4efe1
EZ
38228Translate the given @var{expression} into remote agent bytecodes.
38229This command is useful for debugging the Agent Expression mechanism
782b2b07
SS
38230(@pxref{Agent Expressions}). The @samp{agent} version produces an
38231expression useful for data collection, such as by tracepoints, while
38232@samp{maint agent-eval} produces an expression that evaluates directly
38233to a result. For instance, a collection expression for @code{globa +
38234globb} will include bytecodes to record four bytes of memory at each
38235of the addresses of @code{globa} and @code{globb}, while discarding
38236the result of the addition, while an evaluation expression will do the
38237addition and return the sum.
f77cc5f0
HZ
38238If @code{-at} is given, generate remote agent bytecode for @var{location}.
38239If not, generate remote agent bytecode for current frame PC address.
09d4efe1 38240
d3ce09f5
SS
38241@kindex maint agent-printf
38242@item maint agent-printf @var{format},@var{expr},...
38243Translate the given format string and list of argument expressions
38244into remote agent bytecodes and display them as a disassembled list.
38245This command is useful for debugging the agent version of dynamic
6dd24dfa 38246printf (@pxref{Dynamic Printf}).
d3ce09f5 38247
8e04817f
AC
38248@kindex maint info breakpoints
38249@item @anchor{maint info breakpoints}maint info breakpoints
38250Using the same format as @samp{info breakpoints}, display both the
38251breakpoints you've set explicitly, and those @value{GDBN} is using for
38252internal purposes. Internal breakpoints are shown with negative
38253breakpoint numbers. The type column identifies what kind of breakpoint
38254is shown:
c906108c 38255
8e04817f
AC
38256@table @code
38257@item breakpoint
38258Normal, explicitly set breakpoint.
c906108c 38259
8e04817f
AC
38260@item watchpoint
38261Normal, explicitly set watchpoint.
c906108c 38262
8e04817f
AC
38263@item longjmp
38264Internal breakpoint, used to handle correctly stepping through
38265@code{longjmp} calls.
c906108c 38266
8e04817f
AC
38267@item longjmp resume
38268Internal breakpoint at the target of a @code{longjmp}.
c906108c 38269
8e04817f
AC
38270@item until
38271Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 38272
8e04817f
AC
38273@item finish
38274Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 38275
8e04817f
AC
38276@item shlib events
38277Shared library events.
c906108c 38278
8e04817f 38279@end table
c906108c 38280
b0627500
MM
38281@kindex maint info btrace
38282@item maint info btrace
38283Pint information about raw branch tracing data.
38284
38285@kindex maint btrace packet-history
38286@item maint btrace packet-history
38287Print the raw branch trace packets that are used to compute the
38288execution history for the @samp{record btrace} command. Both the
38289information and the format in which it is printed depend on the btrace
38290recording format.
38291
38292@table @code
38293@item bts
38294For the BTS recording format, print a list of blocks of sequential
38295code. For each block, the following information is printed:
38296
38297@table @asis
38298@item Block number
38299Newer blocks have higher numbers. The oldest block has number zero.
38300@item Lowest @samp{PC}
38301@item Highest @samp{PC}
38302@end table
38303
38304@item pt
bc504a31
PA
38305For the Intel Processor Trace recording format, print a list of
38306Intel Processor Trace packets. For each packet, the following
b0627500
MM
38307information is printed:
38308
38309@table @asis
38310@item Packet number
38311Newer packets have higher numbers. The oldest packet has number zero.
38312@item Trace offset
38313The packet's offset in the trace stream.
38314@item Packet opcode and payload
38315@end table
38316@end table
38317
38318@kindex maint btrace clear-packet-history
38319@item maint btrace clear-packet-history
38320Discards the cached packet history printed by the @samp{maint btrace
38321packet-history} command. The history will be computed again when
38322needed.
38323
38324@kindex maint btrace clear
38325@item maint btrace clear
38326Discard the branch trace data. The data will be fetched anew and the
38327branch trace will be recomputed when needed.
38328
38329This implicitly truncates the branch trace to a single branch trace
38330buffer. When updating branch trace incrementally, the branch trace
38331available to @value{GDBN} may be bigger than a single branch trace
38332buffer.
38333
38334@kindex maint set btrace pt skip-pad
38335@item maint set btrace pt skip-pad
38336@kindex maint show btrace pt skip-pad
38337@item maint show btrace pt skip-pad
38338Control whether @value{GDBN} will skip PAD packets when computing the
38339packet history.
38340
fff08868
HZ
38341@kindex set displaced-stepping
38342@kindex show displaced-stepping
237fc4c9
PA
38343@cindex displaced stepping support
38344@cindex out-of-line single-stepping
fff08868
HZ
38345@item set displaced-stepping
38346@itemx show displaced-stepping
237fc4c9 38347Control whether or not @value{GDBN} will do @dfn{displaced stepping}
fff08868
HZ
38348if the target supports it. Displaced stepping is a way to single-step
38349over breakpoints without removing them from the inferior, by executing
38350an out-of-line copy of the instruction that was originally at the
38351breakpoint location. It is also known as out-of-line single-stepping.
38352
38353@table @code
38354@item set displaced-stepping on
38355If the target architecture supports it, @value{GDBN} will use
38356displaced stepping to step over breakpoints.
38357
38358@item set displaced-stepping off
38359@value{GDBN} will not use displaced stepping to step over breakpoints,
38360even if such is supported by the target architecture.
38361
38362@cindex non-stop mode, and @samp{set displaced-stepping}
38363@item set displaced-stepping auto
38364This is the default mode. @value{GDBN} will use displaced stepping
38365only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
38366architecture supports displaced stepping.
38367@end table
237fc4c9 38368
7d0c9981
DE
38369@kindex maint check-psymtabs
38370@item maint check-psymtabs
38371Check the consistency of currently expanded psymtabs versus symtabs.
38372Use this to check, for example, whether a symbol is in one but not the other.
38373
09d4efe1
EZ
38374@kindex maint check-symtabs
38375@item maint check-symtabs
7d0c9981
DE
38376Check the consistency of currently expanded symtabs.
38377
38378@kindex maint expand-symtabs
38379@item maint expand-symtabs [@var{regexp}]
38380Expand symbol tables.
38381If @var{regexp} is specified, only expand symbol tables for file
38382names matching @var{regexp}.
09d4efe1 38383
992c7d70
GB
38384@kindex maint set catch-demangler-crashes
38385@kindex maint show catch-demangler-crashes
38386@cindex demangler crashes
38387@item maint set catch-demangler-crashes [on|off]
38388@itemx maint show catch-demangler-crashes
38389Control whether @value{GDBN} should attempt to catch crashes in the
38390symbol name demangler. The default is to attempt to catch crashes.
38391If enabled, the first time a crash is caught, a core file is created,
38392the offending symbol is displayed and the user is presented with the
38393option to terminate the current session.
38394
09d4efe1
EZ
38395@kindex maint cplus first_component
38396@item maint cplus first_component @var{name}
38397Print the first C@t{++} class/namespace component of @var{name}.
38398
38399@kindex maint cplus namespace
38400@item maint cplus namespace
38401Print the list of possible C@t{++} namespaces.
38402
09d4efe1
EZ
38403@kindex maint deprecate
38404@kindex maint undeprecate
38405@cindex deprecated commands
38406@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
38407@itemx maint undeprecate @var{command}
38408Deprecate or undeprecate the named @var{command}. Deprecated commands
38409cause @value{GDBN} to issue a warning when you use them. The optional
38410argument @var{replacement} says which newer command should be used in
38411favor of the deprecated one; if it is given, @value{GDBN} will mention
38412the replacement as part of the warning.
38413
38414@kindex maint dump-me
38415@item maint dump-me
721c2651 38416@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 38417Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
38418This is supported only on systems which support aborting a program
38419with the @code{SIGQUIT} signal.
09d4efe1 38420
8d30a00d
AC
38421@kindex maint internal-error
38422@kindex maint internal-warning
57fcfb1b
GB
38423@kindex maint demangler-warning
38424@cindex demangler crashes
09d4efe1
EZ
38425@item maint internal-error @r{[}@var{message-text}@r{]}
38426@itemx maint internal-warning @r{[}@var{message-text}@r{]}
57fcfb1b
GB
38427@itemx maint demangler-warning @r{[}@var{message-text}@r{]}
38428
38429Cause @value{GDBN} to call the internal function @code{internal_error},
38430@code{internal_warning} or @code{demangler_warning} and hence behave
7ee67ee4 38431as though an internal problem has been detected. In addition to
57fcfb1b
GB
38432reporting the internal problem, these functions give the user the
38433opportunity to either quit @value{GDBN} or (for @code{internal_error}
38434and @code{internal_warning}) create a core file of the current
8d30a00d
AC
38435@value{GDBN} session.
38436
09d4efe1
EZ
38437These commands take an optional parameter @var{message-text} that is
38438used as the text of the error or warning message.
38439
d3e8051b 38440Here's an example of using @code{internal-error}:
09d4efe1 38441
8d30a00d 38442@smallexample
f7dc1244 38443(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
38444@dots{}/maint.c:121: internal-error: testing, 1, 2
38445A problem internal to GDB has been detected. Further
38446debugging may prove unreliable.
38447Quit this debugging session? (y or n) @kbd{n}
38448Create a core file? (y or n) @kbd{n}
f7dc1244 38449(@value{GDBP})
8d30a00d
AC
38450@end smallexample
38451
3c16cced
PA
38452@cindex @value{GDBN} internal error
38453@cindex internal errors, control of @value{GDBN} behavior
57fcfb1b 38454@cindex demangler crashes
3c16cced
PA
38455
38456@kindex maint set internal-error
38457@kindex maint show internal-error
38458@kindex maint set internal-warning
38459@kindex maint show internal-warning
57fcfb1b
GB
38460@kindex maint set demangler-warning
38461@kindex maint show demangler-warning
3c16cced
PA
38462@item maint set internal-error @var{action} [ask|yes|no]
38463@itemx maint show internal-error @var{action}
38464@itemx maint set internal-warning @var{action} [ask|yes|no]
38465@itemx maint show internal-warning @var{action}
57fcfb1b
GB
38466@itemx maint set demangler-warning @var{action} [ask|yes|no]
38467@itemx maint show demangler-warning @var{action}
3c16cced
PA
38468When @value{GDBN} reports an internal problem (error or warning) it
38469gives the user the opportunity to both quit @value{GDBN} and create a
38470core file of the current @value{GDBN} session. These commands let you
38471override the default behaviour for each particular @var{action},
38472described in the table below.
38473
38474@table @samp
38475@item quit
38476You can specify that @value{GDBN} should always (yes) or never (no)
38477quit. The default is to ask the user what to do.
38478
38479@item corefile
38480You can specify that @value{GDBN} should always (yes) or never (no)
57fcfb1b
GB
38481create a core file. The default is to ask the user what to do. Note
38482that there is no @code{corefile} option for @code{demangler-warning}:
38483demangler warnings always create a core file and this cannot be
38484disabled.
3c16cced
PA
38485@end table
38486
09d4efe1
EZ
38487@kindex maint packet
38488@item maint packet @var{text}
38489If @value{GDBN} is talking to an inferior via the serial protocol,
38490then this command sends the string @var{text} to the inferior, and
38491displays the response packet. @value{GDBN} supplies the initial
38492@samp{$} character, the terminating @samp{#} character, and the
38493checksum.
38494
38495@kindex maint print architecture
38496@item maint print architecture @r{[}@var{file}@r{]}
38497Print the entire architecture configuration. The optional argument
38498@var{file} names the file where the output goes.
8d30a00d 38499
8e2141c6 38500@kindex maint print c-tdesc @r{[}@var{file}@r{]}
81adfced 38501@item maint print c-tdesc
8e2141c6
YQ
38502Print the target description (@pxref{Target Descriptions}) as
38503a C source file. By default, the target description is for the current
38504target, but if the optional argument @var{file} is provided, that file
38505is used to produce the description. The @var{file} should be an XML
38506document, of the form described in @ref{Target Description Format}.
38507The created source file is built into @value{GDBN} when @value{GDBN} is
38508built again. This command is used by developers after they add or
38509modify XML target descriptions.
81adfced 38510
caa7fd04
AB
38511@kindex maint print xml-tdesc
38512@item maint print xml-tdesc @r{[}@var{file}@r{]}
38513Print the target description (@pxref{Target Descriptions}) as an XML
38514file. By default print the target description for the current target,
38515but if the optional argument @var{file} is provided, then that file is
38516read in by GDB and then used to produce the description. The
38517@var{file} should be an XML document, of the form described in
38518@ref{Target Description Format}.
38519
27d41eac
YQ
38520@kindex maint check xml-descriptions
38521@item maint check xml-descriptions @var{dir}
38522Check that the target descriptions dynamically created by @value{GDBN}
38523equal the descriptions created from XML files found in @var{dir}.
38524
41fc26a2 38525@anchor{maint check libthread-db}
5045b3d7
GB
38526@kindex maint check libthread-db
38527@item maint check libthread-db
38528Run integrity checks on the current inferior's thread debugging
38529library. This exercises all @code{libthread_db} functionality used by
38530@value{GDBN} on GNU/Linux systems, and by extension also exercises the
38531@code{proc_service} functions provided by @value{GDBN} that
38532@code{libthread_db} uses. Note that parts of the test may be skipped
38533on some platforms when debugging core files.
38534
00905d52
AC
38535@kindex maint print dummy-frames
38536@item maint print dummy-frames
00905d52
AC
38537Prints the contents of @value{GDBN}'s internal dummy-frame stack.
38538
38539@smallexample
f7dc1244 38540(@value{GDBP}) @kbd{b add}
00905d52 38541@dots{}
f7dc1244 38542(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
38543Breakpoint 2, add (a=2, b=3) at @dots{}
3854458 return (a + b);
38545The program being debugged stopped while in a function called from GDB.
38546@dots{}
f7dc1244 38547(@value{GDBP}) @kbd{maint print dummy-frames}
b67a2c6f 385480xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
f7dc1244 38549(@value{GDBP})
00905d52
AC
38550@end smallexample
38551
38552Takes an optional file parameter.
38553
0680b120
AC
38554@kindex maint print registers
38555@kindex maint print raw-registers
38556@kindex maint print cooked-registers
617073a9 38557@kindex maint print register-groups
c21236dc 38558@kindex maint print remote-registers
09d4efe1
EZ
38559@item maint print registers @r{[}@var{file}@r{]}
38560@itemx maint print raw-registers @r{[}@var{file}@r{]}
38561@itemx maint print cooked-registers @r{[}@var{file}@r{]}
38562@itemx maint print register-groups @r{[}@var{file}@r{]}
c21236dc 38563@itemx maint print remote-registers @r{[}@var{file}@r{]}
0680b120
AC
38564Print @value{GDBN}'s internal register data structures.
38565
617073a9 38566The command @code{maint print raw-registers} includes the contents of
c21236dc
PA
38567the raw register cache; the command @code{maint print
38568cooked-registers} includes the (cooked) value of all registers,
38569including registers which aren't available on the target nor visible
38570to user; the command @code{maint print register-groups} includes the
38571groups that each register is a member of; and the command @code{maint
38572print remote-registers} includes the remote target's register numbers
0a7cfe2c 38573and offsets in the `G' packets.
0680b120 38574
09d4efe1
EZ
38575These commands take an optional parameter, a file name to which to
38576write the information.
0680b120 38577
617073a9 38578@kindex maint print reggroups
09d4efe1
EZ
38579@item maint print reggroups @r{[}@var{file}@r{]}
38580Print @value{GDBN}'s internal register group data structures. The
38581optional argument @var{file} tells to what file to write the
38582information.
617073a9 38583
09d4efe1 38584The register groups info looks like this:
617073a9
AC
38585
38586@smallexample
f7dc1244 38587(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
38588 Group Type
38589 general user
38590 float user
38591 all user
38592 vector user
38593 system user
38594 save internal
38595 restore internal
617073a9
AC
38596@end smallexample
38597
09d4efe1
EZ
38598@kindex flushregs
38599@item flushregs
38600This command forces @value{GDBN} to flush its internal register cache.
38601
38602@kindex maint print objfiles
38603@cindex info for known object files
52e260a3
DE
38604@item maint print objfiles @r{[}@var{regexp}@r{]}
38605Print a dump of all known object files.
38606If @var{regexp} is specified, only print object files whose names
38607match @var{regexp}. For each object file, this command prints its name,
38608address in memory, and all of its psymtabs and symtabs.
09d4efe1 38609
f5b95c01
AA
38610@kindex maint print user-registers
38611@cindex user registers
38612@item maint print user-registers
38613List all currently available @dfn{user registers}. User registers
38614typically provide alternate names for actual hardware registers. They
38615include the four ``standard'' registers @code{$fp}, @code{$pc},
38616@code{$sp}, and @code{$ps}. @xref{standard registers}. User
38617registers can be used in expressions in the same way as the canonical
38618register names, but only the latter are listed by the @code{info
38619registers} and @code{maint print registers} commands.
38620
8a1ea21f
DE
38621@kindex maint print section-scripts
38622@cindex info for known .debug_gdb_scripts-loaded scripts
38623@item maint print section-scripts [@var{regexp}]
38624Print a dump of scripts specified in the @code{.debug_gdb_section} section.
38625If @var{regexp} is specified, only print scripts loaded by object files
38626matching @var{regexp}.
38627For each script, this command prints its name as specified in the objfile,
38628and the full path if known.
8e0583c8 38629@xref{dotdebug_gdb_scripts section}.
8a1ea21f 38630
09d4efe1
EZ
38631@kindex maint print statistics
38632@cindex bcache statistics
38633@item maint print statistics
38634This command prints, for each object file in the program, various data
38635about that object file followed by the byte cache (@dfn{bcache})
38636statistics for the object file. The objfile data includes the number
d3e8051b 38637of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
38638defined by the objfile, the number of as yet unexpanded psym tables,
38639the number of line tables and string tables, and the amount of memory
38640used by the various tables. The bcache statistics include the counts,
38641sizes, and counts of duplicates of all and unique objects, max,
38642average, and median entry size, total memory used and its overhead and
38643savings, and various measures of the hash table size and chain
38644lengths.
38645
c7ba131e
JB
38646@kindex maint print target-stack
38647@cindex target stack description
38648@item maint print target-stack
38649A @dfn{target} is an interface between the debugger and a particular
38650kind of file or process. Targets can be stacked in @dfn{strata},
38651so that more than one target can potentially respond to a request.
38652In particular, memory accesses will walk down the stack of targets
38653until they find a target that is interested in handling that particular
38654address.
38655
38656This command prints a short description of each layer that was pushed on
38657the @dfn{target stack}, starting from the top layer down to the bottom one.
38658
09d4efe1
EZ
38659@kindex maint print type
38660@cindex type chain of a data type
38661@item maint print type @var{expr}
38662Print the type chain for a type specified by @var{expr}. The argument
38663can be either a type name or a symbol. If it is a symbol, the type of
38664that symbol is described. The type chain produced by this command is
38665a recursive definition of the data type as stored in @value{GDBN}'s
38666data structures, including its flags and contained types.
38667
dcd1f979
TT
38668@kindex maint selftest
38669@cindex self tests
1526853e 38670@item maint selftest @r{[}@var{filter}@r{]}
dcd1f979
TT
38671Run any self tests that were compiled in to @value{GDBN}. This will
38672print a message showing how many tests were run, and how many failed.
1526853e
SM
38673If a @var{filter} is passed, only the tests with @var{filter} in their
38674name will by ran.
38675
3c2fcaf9 38676@kindex maint info selftests
1526853e
SM
38677@cindex self tests
38678@item maint info selftests
38679List the selftests compiled in to @value{GDBN}.
dcd1f979 38680
b4f54984
DE
38681@kindex maint set dwarf always-disassemble
38682@kindex maint show dwarf always-disassemble
38683@item maint set dwarf always-disassemble
38684@item maint show dwarf always-disassemble
9eae7c52
TT
38685Control the behavior of @code{info address} when using DWARF debugging
38686information.
38687
38688The default is @code{off}, which means that @value{GDBN} should try to
38689describe a variable's location in an easily readable format. When
38690@code{on}, @value{GDBN} will instead display the DWARF location
38691expression in an assembly-like format. Note that some locations are
38692too complex for @value{GDBN} to describe simply; in this case you will
38693always see the disassembly form.
38694
38695Here is an example of the resulting disassembly:
38696
38697@smallexample
38698(gdb) info addr argc
38699Symbol "argc" is a complex DWARF expression:
38700 1: DW_OP_fbreg 0
38701@end smallexample
38702
38703For more information on these expressions, see
38704@uref{http://www.dwarfstd.org/, the DWARF standard}.
38705
b4f54984
DE
38706@kindex maint set dwarf max-cache-age
38707@kindex maint show dwarf max-cache-age
38708@item maint set dwarf max-cache-age
38709@itemx maint show dwarf max-cache-age
38710Control the DWARF compilation unit cache.
09d4efe1 38711
b4f54984 38712@cindex DWARF compilation units cache
09d4efe1 38713In object files with inter-compilation-unit references, such as those
b4f54984 38714produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
09d4efe1
EZ
38715reader needs to frequently refer to previously read compilation units.
38716This setting controls how long a compilation unit will remain in the
38717cache if it is not referenced. A higher limit means that cached
38718compilation units will be stored in memory longer, and more total
38719memory will be used. Setting it to zero disables caching, which will
38720slow down @value{GDBN} startup, but reduce memory consumption.
38721
3c3bb058
AB
38722@kindex maint set dwarf unwinders
38723@kindex maint show dwarf unwinders
38724@item maint set dwarf unwinders
38725@itemx maint show dwarf unwinders
38726Control use of the DWARF frame unwinders.
38727
38728@cindex DWARF frame unwinders
38729Many targets that support DWARF debugging use @value{GDBN}'s DWARF
38730frame unwinders to build the backtrace. Many of these targets will
38731also have a second mechanism for building the backtrace for use in
38732cases where DWARF information is not available, this second mechanism
38733is often an analysis of a function's prologue.
38734
38735In order to extend testing coverage of the second level stack
38736unwinding mechanisms it is helpful to be able to disable the DWARF
38737stack unwinders, this can be done with this switch.
38738
38739In normal use of @value{GDBN} disabling the DWARF unwinders is not
38740advisable, there are cases that are better handled through DWARF than
38741prologue analysis, and the debug experience is likely to be better
38742with the DWARF frame unwinders enabled.
38743
38744If DWARF frame unwinders are not supported for a particular target
38745architecture, then enabling this flag does not cause them to be used.
22138db6
TT
38746
38747@kindex maint set worker-threads
38748@kindex maint show worker-threads
38749@item maint set worker-threads
38750@item maint show worker-threads
38751Control the number of worker threads that may be used by @value{GDBN}.
38752On capable hosts, @value{GDBN} may use multiple threads to speed up
38753certain CPU-intensive operations, such as demangling symbol names.
38754While the number of threads used by @value{GDBN} may vary, this
38755command can be used to set an upper bound on this number. The default
38756is @code{unlimited}, which lets @value{GDBN} choose a reasonable
38757number. Note that this only controls worker threads started by
38758@value{GDBN} itself; libraries used by @value{GDBN} may start threads
38759of their own.
38760
e7ba9c65
DJ
38761@kindex maint set profile
38762@kindex maint show profile
38763@cindex profiling GDB
38764@item maint set profile
38765@itemx maint show profile
38766Control profiling of @value{GDBN}.
38767
38768Profiling will be disabled until you use the @samp{maint set profile}
38769command to enable it. When you enable profiling, the system will begin
38770collecting timing and execution count data; when you disable profiling or
38771exit @value{GDBN}, the results will be written to a log file. Remember that
38772if you use profiling, @value{GDBN} will overwrite the profiling log file
38773(often called @file{gmon.out}). If you have a record of important profiling
38774data in a @file{gmon.out} file, be sure to move it to a safe location.
38775
38776Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 38777compiled with the @samp{-pg} compiler option.
e7ba9c65 38778
cbe54154
PA
38779@kindex maint set show-debug-regs
38780@kindex maint show show-debug-regs
eac35c4e 38781@cindex hardware debug registers
cbe54154
PA
38782@item maint set show-debug-regs
38783@itemx maint show show-debug-regs
eac35c4e 38784Control whether to show variables that mirror the hardware debug
6dd315ba 38785registers. Use @code{on} to enable, @code{off} to disable. If
3f94c067 38786enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
38787removes a hardware breakpoint or watchpoint, and when the inferior
38788triggers a hardware-assisted breakpoint or watchpoint.
38789
711e434b
PM
38790@kindex maint set show-all-tib
38791@kindex maint show show-all-tib
38792@item maint set show-all-tib
38793@itemx maint show show-all-tib
38794Control whether to show all non zero areas within a 1k block starting
38795at thread local base, when using the @samp{info w32 thread-information-block}
38796command.
38797
329ea579
PA
38798@kindex maint set target-async
38799@kindex maint show target-async
38800@item maint set target-async
38801@itemx maint show target-async
38802This controls whether @value{GDBN} targets operate in synchronous or
38803asynchronous mode (@pxref{Background Execution}). Normally the
38804default is asynchronous, if it is available; but this can be changed
38805to more easily debug problems occurring only in synchronous mode.
38806
fbea99ea
PA
38807@kindex maint set target-non-stop @var{mode} [on|off|auto]
38808@kindex maint show target-non-stop
38809@item maint set target-non-stop
38810@itemx maint show target-non-stop
38811
38812This controls whether @value{GDBN} targets always operate in non-stop
38813mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
38814Mode}). The default is @code{auto}, meaning non-stop mode is enabled
38815if supported by the target.
38816
38817@table @code
38818@item maint set target-non-stop auto
38819This is the default mode. @value{GDBN} controls the target in
38820non-stop mode if the target supports it.
38821
38822@item maint set target-non-stop on
38823@value{GDBN} controls the target in non-stop mode even if the target
38824does not indicate support.
38825
38826@item maint set target-non-stop off
38827@value{GDBN} does not control the target in non-stop mode even if the
38828target supports it.
38829@end table
38830
45e42163
TT
38831@kindex maint set tui-resize-message
38832@kindex maint show tui-resize-message
38833@item maint set tui-resize-message
38834@item maint show tui-resize-message
38835Control whether @value{GDBN} displays a message each time the terminal
38836is resized when in TUI mode. The default is @code{off}, which means
38837that @value{GDBN} is silent during resizes. When @code{on},
38838@value{GDBN} will display a message after a resize is completed; the
38839message will include a number indicating how many times the terminal
38840has been resized. This setting is intended for use by the test suite,
38841where it would otherwise be difficult to determine when a resize and
38842refresh has been completed.
38843
bd712aed
DE
38844@kindex maint set per-command
38845@kindex maint show per-command
38846@item maint set per-command
38847@itemx maint show per-command
38848@cindex resources used by commands
09d4efe1 38849
bd712aed
DE
38850@value{GDBN} can display the resources used by each command.
38851This is useful in debugging performance problems.
38852
38853@table @code
38854@item maint set per-command space [on|off]
38855@itemx maint show per-command space
38856Enable or disable the printing of the memory used by GDB for each command.
38857If enabled, @value{GDBN} will display how much memory each command
38858took, following the command's own output.
38859This can also be requested by invoking @value{GDBN} with the
38860@option{--statistics} command-line switch (@pxref{Mode Options}).
38861
38862@item maint set per-command time [on|off]
38863@itemx maint show per-command time
38864Enable or disable the printing of the execution time of @value{GDBN}
38865for each command.
38866If enabled, @value{GDBN} will display how much time it
09d4efe1 38867took to execute each command, following the command's own output.
0a1c4d10
DE
38868Both CPU time and wallclock time are printed.
38869Printing both is useful when trying to determine whether the cost is
bd712aed 38870CPU or, e.g., disk/network latency.
0a1c4d10
DE
38871Note that the CPU time printed is for @value{GDBN} only, it does not include
38872the execution time of the inferior because there's no mechanism currently
38873to compute how much time was spent by @value{GDBN} and how much time was
38874spent by the program been debugged.
09d4efe1
EZ
38875This can also be requested by invoking @value{GDBN} with the
38876@option{--statistics} command-line switch (@pxref{Mode Options}).
38877
bd712aed
DE
38878@item maint set per-command symtab [on|off]
38879@itemx maint show per-command symtab
38880Enable or disable the printing of basic symbol table statistics
38881for each command.
38882If enabled, @value{GDBN} will display the following information:
38883
215b9f98
EZ
38884@enumerate a
38885@item
38886number of symbol tables
38887@item
38888number of primary symbol tables
38889@item
38890number of blocks in the blockvector
38891@end enumerate
bd712aed
DE
38892@end table
38893
5045b3d7
GB
38894@kindex maint set check-libthread-db
38895@kindex maint show check-libthread-db
38896@item maint set check-libthread-db [on|off]
38897@itemx maint show check-libthread-db
38898Control whether @value{GDBN} should run integrity checks on inferior
38899specific thread debugging libraries as they are loaded. The default
38900is not to perform such checks. If any check fails @value{GDBN} will
38901unload the library and continue searching for a suitable candidate as
38902described in @ref{set libthread-db-search-path}. For more information
38903about the tests, see @ref{maint check libthread-db}.
38904
bd712aed
DE
38905@kindex maint space
38906@cindex memory used by commands
38907@item maint space @var{value}
38908An alias for @code{maint set per-command space}.
38909A non-zero value enables it, zero disables it.
38910
38911@kindex maint time
38912@cindex time of command execution
38913@item maint time @var{value}
38914An alias for @code{maint set per-command time}.
38915A non-zero value enables it, zero disables it.
38916
09d4efe1
EZ
38917@kindex maint translate-address
38918@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
38919Find the symbol stored at the location specified by the address
38920@var{addr} and an optional section name @var{section}. If found,
38921@value{GDBN} prints the name of the closest symbol and an offset from
38922the symbol's location to the specified address. This is similar to
38923the @code{info address} command (@pxref{Symbols}), except that this
38924command also allows to find symbols in other sections.
ae038cb0 38925
c14c28ba
PP
38926If section was not specified, the section in which the symbol was found
38927is also printed. For dynamically linked executables, the name of
38928executable or shared library containing the symbol is printed as well.
38929
3345721a
PA
38930@kindex maint test-options
38931@item maint test-options require-delimiter
38932@itemx maint test-options unknown-is-error
38933@itemx maint test-options unknown-is-operand
38934These commands are used by the testsuite to validate the command
38935options framework. The @code{require-delimiter} variant requires a
38936double-dash delimiter to indicate end of options. The
38937@code{unknown-is-error} and @code{unknown-is-operand} do not. The
38938@code{unknown-is-error} variant throws an error on unknown option,
38939while @code{unknown-is-operand} treats unknown options as the start of
38940the command's operands. When run, the commands output the result of
38941the processed options. When completed, the commands store the
38942internal result of completion in a variable exposed by the @code{maint
38943show test-options-completion-result} command.
38944
38945@kindex maint show test-options-completion-result
38946@item maint show test-options-completion-result
38947Shows the result of completing the @code{maint test-options}
38948subcommands. This is used by the testsuite to validate completion
38949support in the command options framework.
38950
c6ac8931
PA
38951@kindex maint set test-settings
38952@kindex maint show test-settings
38953@item maint set test-settings @var{kind}
38954@itemx maint show test-settings @var{kind}
dca0f6c0
PA
38955These are representative commands for each @var{kind} of setting type
38956@value{GDBN} supports. They are used by the testsuite for exercising
38957the settings infrastructure.
fdbc9870
PA
38958
38959@kindex maint with
38960@item maint with @var{setting} [@var{value}] [-- @var{command}]
38961Like the @code{with} command, but works with @code{maintenance set}
38962variables. This is used by the testsuite to exercise the @code{with}
38963command's infrastructure.
38964
8e04817f 38965@end table
c906108c 38966
9c16f35a
EZ
38967The following command is useful for non-interactive invocations of
38968@value{GDBN}, such as in the test suite.
38969
38970@table @code
38971@item set watchdog @var{nsec}
38972@kindex set watchdog
38973@cindex watchdog timer
38974@cindex timeout for commands
38975Set the maximum number of seconds @value{GDBN} will wait for the
38976target operation to finish. If this time expires, @value{GDBN}
38977reports and error and the command is aborted.
38978
38979@item show watchdog
38980Show the current setting of the target wait timeout.
38981@end table
c906108c 38982
e0ce93ac 38983@node Remote Protocol
8e04817f 38984@appendix @value{GDBN} Remote Serial Protocol
c906108c 38985
ee2d5c50
AC
38986@menu
38987* Overview::
38988* Packets::
38989* Stop Reply Packets::
38990* General Query Packets::
a1dcb23a 38991* Architecture-Specific Protocol Details::
9d29849a 38992* Tracepoint Packets::
a6b151f1 38993* Host I/O Packets::
9a6253be 38994* Interrupts::
8b23ecc4
SL
38995* Notification Packets::
38996* Remote Non-Stop::
a6f3e723 38997* Packet Acknowledgment::
ee2d5c50 38998* Examples::
79a6e687 38999* File-I/O Remote Protocol Extension::
cfa9d6d9 39000* Library List Format::
2268b414 39001* Library List Format for SVR4 Targets::
79a6e687 39002* Memory Map Format::
dc146f7c 39003* Thread List Format::
b3b9301e 39004* Traceframe Info Format::
2ae8c8e7 39005* Branch Trace Format::
f4abbc16 39006* Branch Trace Configuration Format::
ee2d5c50
AC
39007@end menu
39008
39009@node Overview
39010@section Overview
39011
8e04817f
AC
39012There may be occasions when you need to know something about the
39013protocol---for example, if there is only one serial port to your target
39014machine, you might want your program to do something special if it
39015recognizes a packet meant for @value{GDBN}.
c906108c 39016
d2c6833e 39017In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 39018transmitted and received data, respectively.
c906108c 39019
8e04817f
AC
39020@cindex protocol, @value{GDBN} remote serial
39021@cindex serial protocol, @value{GDBN} remote
39022@cindex remote serial protocol
8b23ecc4
SL
39023All @value{GDBN} commands and responses (other than acknowledgments
39024and notifications, see @ref{Notification Packets}) are sent as a
39025@var{packet}. A @var{packet} is introduced with the character
8e04817f
AC
39026@samp{$}, the actual @var{packet-data}, and the terminating character
39027@samp{#} followed by a two-digit @var{checksum}:
c906108c 39028
474c8240 39029@smallexample
8e04817f 39030@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 39031@end smallexample
8e04817f 39032@noindent
c906108c 39033
8e04817f
AC
39034@cindex checksum, for @value{GDBN} remote
39035@noindent
39036The two-digit @var{checksum} is computed as the modulo 256 sum of all
39037characters between the leading @samp{$} and the trailing @samp{#} (an
39038eight bit unsigned checksum).
c906108c 39039
8e04817f
AC
39040Implementors should note that prior to @value{GDBN} 5.0 the protocol
39041specification also included an optional two-digit @var{sequence-id}:
c906108c 39042
474c8240 39043@smallexample
8e04817f 39044@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 39045@end smallexample
c906108c 39046
8e04817f
AC
39047@cindex sequence-id, for @value{GDBN} remote
39048@noindent
39049That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
39050has never output @var{sequence-id}s. Stubs that handle packets added
39051since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 39052
8e04817f
AC
39053When either the host or the target machine receives a packet, the first
39054response expected is an acknowledgment: either @samp{+} (to indicate
39055the package was received correctly) or @samp{-} (to request
39056retransmission):
c906108c 39057
474c8240 39058@smallexample
d2c6833e
AC
39059-> @code{$}@var{packet-data}@code{#}@var{checksum}
39060<- @code{+}
474c8240 39061@end smallexample
8e04817f 39062@noindent
53a5351d 39063
a6f3e723
SL
39064The @samp{+}/@samp{-} acknowledgments can be disabled
39065once a connection is established.
39066@xref{Packet Acknowledgment}, for details.
39067
8e04817f
AC
39068The host (@value{GDBN}) sends @var{command}s, and the target (the
39069debugging stub incorporated in your program) sends a @var{response}. In
39070the case of step and continue @var{command}s, the response is only sent
8b23ecc4
SL
39071when the operation has completed, and the target has again stopped all
39072threads in all attached processes. This is the default all-stop mode
39073behavior, but the remote protocol also supports @value{GDBN}'s non-stop
39074execution mode; see @ref{Remote Non-Stop}, for details.
c906108c 39075
8e04817f
AC
39076@var{packet-data} consists of a sequence of characters with the
39077exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
39078exceptions).
c906108c 39079
ee2d5c50 39080@cindex remote protocol, field separator
0876f84a 39081Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 39082@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 39083@sc{hex} with leading zeros suppressed.
c906108c 39084
8e04817f
AC
39085Implementors should note that prior to @value{GDBN} 5.0, the character
39086@samp{:} could not appear as the third character in a packet (as it
39087would potentially conflict with the @var{sequence-id}).
c906108c 39088
0876f84a
DJ
39089@cindex remote protocol, binary data
39090@anchor{Binary Data}
39091Binary data in most packets is encoded either as two hexadecimal
39092digits per byte of binary data. This allowed the traditional remote
39093protocol to work over connections which were only seven-bit clean.
39094Some packets designed more recently assume an eight-bit clean
39095connection, and use a more efficient encoding to send and receive
39096binary data.
39097
39098The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
39099as an escape character. Any escaped byte is transmitted as the escape
39100character followed by the original character XORed with @code{0x20}.
39101For example, the byte @code{0x7d} would be transmitted as the two
39102bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
39103@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
39104@samp{@}}) must always be escaped. Responses sent by the stub
39105must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
39106is not interpreted as the start of a run-length encoded sequence
39107(described next).
39108
1d3811f6
DJ
39109Response @var{data} can be run-length encoded to save space.
39110Run-length encoding replaces runs of identical characters with one
39111instance of the repeated character, followed by a @samp{*} and a
39112repeat count. The repeat count is itself sent encoded, to avoid
39113binary characters in @var{data}: a value of @var{n} is sent as
39114@code{@var{n}+29}. For a repeat count greater or equal to 3, this
39115produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
39116code 32) for a repeat count of 3. (This is because run-length
39117encoding starts to win for counts 3 or more.) Thus, for example,
39118@samp{0* } is a run-length encoding of ``0000'': the space character
39119after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
391203}} more times.
39121
39122The printable characters @samp{#} and @samp{$} or with a numeric value
39123greater than 126 must not be used. Runs of six repeats (@samp{#}) or
39124seven repeats (@samp{$}) can be expanded using a repeat count of only
39125five (@samp{"}). For example, @samp{00000000} can be encoded as
39126@samp{0*"00}.
c906108c 39127
8e04817f
AC
39128The error response returned for some packets includes a two character
39129error number. That number is not well defined.
c906108c 39130
f8da2bff 39131@cindex empty response, for unsupported packets
8e04817f
AC
39132For any @var{command} not supported by the stub, an empty response
39133(@samp{$#00}) should be returned. That way it is possible to extend the
39134protocol. A newer @value{GDBN} can tell if a packet is supported based
39135on that response.
c906108c 39136
c9fe1b58
RT
39137At a minimum, a stub is required to support the @samp{?} command to
39138tell @value{GDBN} the reason for halting, @samp{g} and @samp{G}
393eab54
PA
39139commands for register access, and the @samp{m} and @samp{M} commands
39140for memory access. Stubs that only control single-threaded targets
c9fe1b58
RT
39141can implement run control with the @samp{c} (continue) command, and if
39142the target architecture supports hardware-assisted single-stepping,
39143the @samp{s} (step) command. Stubs that support multi-threading
39144targets should support the @samp{vCont} command. All other commands
39145are optional.
c906108c 39146
ee2d5c50
AC
39147@node Packets
39148@section Packets
39149
39150The following table provides a complete list of all currently defined
39151@var{command}s and their corresponding response @var{data}.
79a6e687 39152@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 39153I/O extension of the remote protocol.
ee2d5c50 39154
b8ff78ce
JB
39155Each packet's description has a template showing the packet's overall
39156syntax, followed by an explanation of the packet's meaning. We
39157include spaces in some of the templates for clarity; these are not
39158part of the packet's syntax. No @value{GDBN} packet uses spaces to
39159separate its components. For example, a template like @samp{foo
39160@var{bar} @var{baz}} describes a packet beginning with the three ASCII
39161bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 39162@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
39163@samp{foo} and the @var{bar}, or between the @var{bar} and the
39164@var{baz}.
39165
b90a069a
SL
39166@cindex @var{thread-id}, in remote protocol
39167@anchor{thread-id syntax}
39168Several packets and replies include a @var{thread-id} field to identify
39169a thread. Normally these are positive numbers with a target-specific
39170interpretation, formatted as big-endian hex strings. A @var{thread-id}
39171can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
39172pick any thread.
39173
39174In addition, the remote protocol supports a multiprocess feature in
39175which the @var{thread-id} syntax is extended to optionally include both
39176process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
39177The @var{pid} (process) and @var{tid} (thread) components each have the
39178format described above: a positive number with target-specific
39179interpretation formatted as a big-endian hex string, literal @samp{-1}
39180to indicate all processes or threads (respectively), or @samp{0} to
39181indicate an arbitrary process or thread. Specifying just a process, as
39182@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
39183error to specify all processes but a specific thread, such as
39184@samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
39185for those packets and replies explicitly documented to include a process
39186ID, rather than a @var{thread-id}.
39187
39188The multiprocess @var{thread-id} syntax extensions are only used if both
39189@value{GDBN} and the stub report support for the @samp{multiprocess}
39190feature using @samp{qSupported}. @xref{multiprocess extensions}, for
39191more information.
39192
8ffe2530
JB
39193Note that all packet forms beginning with an upper- or lower-case
39194letter, other than those described here, are reserved for future use.
39195
b8ff78ce 39196Here are the packet descriptions.
ee2d5c50 39197
b8ff78ce 39198@table @samp
ee2d5c50 39199
b8ff78ce
JB
39200@item !
39201@cindex @samp{!} packet
2d717e4f 39202@anchor{extended mode}
8e04817f
AC
39203Enable extended mode. In extended mode, the remote server is made
39204persistent. The @samp{R} packet is used to restart the program being
39205debugged.
ee2d5c50
AC
39206
39207Reply:
39208@table @samp
39209@item OK
8e04817f 39210The remote target both supports and has enabled extended mode.
ee2d5c50 39211@end table
c906108c 39212
b8ff78ce
JB
39213@item ?
39214@cindex @samp{?} packet
36cb1214 39215@anchor{? packet}
ee2d5c50 39216Indicate the reason the target halted. The reply is the same as for
8b23ecc4
SL
39217step and continue. This packet has a special interpretation when the
39218target is in non-stop mode; see @ref{Remote Non-Stop}.
c906108c 39219
ee2d5c50
AC
39220Reply:
39221@xref{Stop Reply Packets}, for the reply specifications.
39222
b8ff78ce
JB
39223@item A @var{arglen},@var{argnum},@var{arg},@dots{}
39224@cindex @samp{A} packet
39225Initialized @code{argv[]} array passed into program. @var{arglen}
39226specifies the number of bytes in the hex encoded byte stream
39227@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
39228
39229Reply:
39230@table @samp
39231@item OK
b8ff78ce
JB
39232The arguments were set.
39233@item E @var{NN}
39234An error occurred.
ee2d5c50
AC
39235@end table
39236
b8ff78ce
JB
39237@item b @var{baud}
39238@cindex @samp{b} packet
39239(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
39240Change the serial line speed to @var{baud}.
39241
39242JTC: @emph{When does the transport layer state change? When it's
39243received, or after the ACK is transmitted. In either case, there are
39244problems if the command or the acknowledgment packet is dropped.}
39245
39246Stan: @emph{If people really wanted to add something like this, and get
39247it working for the first time, they ought to modify ser-unix.c to send
39248some kind of out-of-band message to a specially-setup stub and have the
39249switch happen "in between" packets, so that from remote protocol's point
39250of view, nothing actually happened.}
39251
b8ff78ce
JB
39252@item B @var{addr},@var{mode}
39253@cindex @samp{B} packet
8e04817f 39254Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
39255breakpoint at @var{addr}.
39256
b8ff78ce 39257Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 39258(@pxref{insert breakpoint or watchpoint packet}).
c906108c 39259
bacec72f 39260@cindex @samp{bc} packet
0d772ac9
MS
39261@anchor{bc}
39262@item bc
bacec72f
MS
39263Backward continue. Execute the target system in reverse. No parameter.
39264@xref{Reverse Execution}, for more information.
39265
39266Reply:
39267@xref{Stop Reply Packets}, for the reply specifications.
39268
bacec72f 39269@cindex @samp{bs} packet
0d772ac9
MS
39270@anchor{bs}
39271@item bs
bacec72f
MS
39272Backward single step. Execute one instruction in reverse. No parameter.
39273@xref{Reverse Execution}, for more information.
39274
39275Reply:
39276@xref{Stop Reply Packets}, for the reply specifications.
39277
4f553f88 39278@item c @r{[}@var{addr}@r{]}
b8ff78ce 39279@cindex @samp{c} packet
697aa1b7
EZ
39280Continue at @var{addr}, which is the address to resume. If @var{addr}
39281is omitted, resume at current address.
c906108c 39282
393eab54
PA
39283This packet is deprecated for multi-threading support. @xref{vCont
39284packet}.
39285
ee2d5c50
AC
39286Reply:
39287@xref{Stop Reply Packets}, for the reply specifications.
39288
4f553f88 39289@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 39290@cindex @samp{C} packet
8e04817f 39291Continue with signal @var{sig} (hex signal number). If
b8ff78ce 39292@samp{;@var{addr}} is omitted, resume at same address.
c906108c 39293
393eab54
PA
39294This packet is deprecated for multi-threading support. @xref{vCont
39295packet}.
39296
ee2d5c50
AC
39297Reply:
39298@xref{Stop Reply Packets}, for the reply specifications.
c906108c 39299
b8ff78ce
JB
39300@item d
39301@cindex @samp{d} packet
ee2d5c50
AC
39302Toggle debug flag.
39303
b8ff78ce
JB
39304Don't use this packet; instead, define a general set packet
39305(@pxref{General Query Packets}).
ee2d5c50 39306
b8ff78ce 39307@item D
b90a069a 39308@itemx D;@var{pid}
b8ff78ce 39309@cindex @samp{D} packet
b90a069a
SL
39310The first form of the packet is used to detach @value{GDBN} from the
39311remote system. It is sent to the remote target
07f31aa6 39312before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50 39313
b90a069a
SL
39314The second form, including a process ID, is used when multiprocess
39315protocol extensions are enabled (@pxref{multiprocess extensions}), to
39316detach only a specific process. The @var{pid} is specified as a
39317big-endian hex string.
39318
ee2d5c50
AC
39319Reply:
39320@table @samp
10fac096
NW
39321@item OK
39322for success
b8ff78ce 39323@item E @var{NN}
10fac096 39324for an error
ee2d5c50 39325@end table
c906108c 39326
b8ff78ce
JB
39327@item F @var{RC},@var{EE},@var{CF};@var{XX}
39328@cindex @samp{F} packet
39329A reply from @value{GDBN} to an @samp{F} packet sent by the target.
39330This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 39331Remote Protocol Extension}, for the specification.
ee2d5c50 39332
b8ff78ce 39333@item g
ee2d5c50 39334@anchor{read registers packet}
b8ff78ce 39335@cindex @samp{g} packet
ee2d5c50
AC
39336Read general registers.
39337
39338Reply:
39339@table @samp
39340@item @var{XX@dots{}}
8e04817f
AC
39341Each byte of register data is described by two hex digits. The bytes
39342with the register are transmitted in target byte order. The size of
b8ff78ce 39343each register and their position within the @samp{g} packet are
4a9bb1df 39344determined by the @value{GDBN} internal gdbarch functions
4435e1cc 39345@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
ad196637
PA
39346
39347When reading registers from a trace frame (@pxref{Analyze Collected
39348Data,,Using the Collected Data}), the stub may also return a string of
39349literal @samp{x}'s in place of the register data digits, to indicate
39350that the corresponding register has not been collected, thus its value
39351is unavailable. For example, for an architecture with 4 registers of
393524 bytes each, the following reply indicates to @value{GDBN} that
39353registers 0 and 2 have not been collected, while registers 1 and 3
39354have been collected, and both have zero value:
39355
39356@smallexample
39357-> @code{g}
39358<- @code{xxxxxxxx00000000xxxxxxxx00000000}
39359@end smallexample
39360
b8ff78ce 39361@item E @var{NN}
ee2d5c50
AC
39362for an error.
39363@end table
c906108c 39364
b8ff78ce
JB
39365@item G @var{XX@dots{}}
39366@cindex @samp{G} packet
39367Write general registers. @xref{read registers packet}, for a
39368description of the @var{XX@dots{}} data.
ee2d5c50
AC
39369
39370Reply:
39371@table @samp
39372@item OK
39373for success
b8ff78ce 39374@item E @var{NN}
ee2d5c50
AC
39375for an error
39376@end table
39377
393eab54 39378@item H @var{op} @var{thread-id}
b8ff78ce 39379@cindex @samp{H} packet
8e04817f 39380Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
697aa1b7
EZ
39381@samp{G}, et.al.). Depending on the operation to be performed, @var{op}
39382should be @samp{c} for step and continue operations (note that this
393eab54 39383is deprecated, supporting the @samp{vCont} command is a better
697aa1b7 39384option), and @samp{g} for other operations. The thread designator
393eab54
PA
39385@var{thread-id} has the format and interpretation described in
39386@ref{thread-id syntax}.
ee2d5c50
AC
39387
39388Reply:
39389@table @samp
39390@item OK
39391for success
b8ff78ce 39392@item E @var{NN}
ee2d5c50
AC
39393for an error
39394@end table
c906108c 39395
8e04817f
AC
39396@c FIXME: JTC:
39397@c 'H': How restrictive (or permissive) is the thread model. If a
39398@c thread is selected and stopped, are other threads allowed
39399@c to continue to execute? As I mentioned above, I think the
39400@c semantics of each command when a thread is selected must be
39401@c described. For example:
39402@c
39403@c 'g': If the stub supports threads and a specific thread is
39404@c selected, returns the register block from that thread;
39405@c otherwise returns current registers.
39406@c
39407@c 'G' If the stub supports threads and a specific thread is
39408@c selected, sets the registers of the register block of
39409@c that thread; otherwise sets current registers.
c906108c 39410
b8ff78ce 39411@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 39412@anchor{cycle step packet}
b8ff78ce
JB
39413@cindex @samp{i} packet
39414Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
39415present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
39416step starting at that address.
c906108c 39417
b8ff78ce
JB
39418@item I
39419@cindex @samp{I} packet
39420Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
39421step packet}.
ee2d5c50 39422
b8ff78ce
JB
39423@item k
39424@cindex @samp{k} packet
39425Kill request.
c906108c 39426
36cb1214
HZ
39427The exact effect of this packet is not specified.
39428
39429For a bare-metal target, it may power cycle or reset the target
39430system. For that reason, the @samp{k} packet has no reply.
39431
39432For a single-process target, it may kill that process if possible.
39433
39434A multiple-process target may choose to kill just one process, or all
39435that are under @value{GDBN}'s control. For more precise control, use
39436the vKill packet (@pxref{vKill packet}).
39437
39438If the target system immediately closes the connection in response to
39439@samp{k}, @value{GDBN} does not consider the lack of packet
39440acknowledgment to be an error, and assumes the kill was successful.
39441
39442If connected using @kbd{target extended-remote}, and the target does
39443not close the connection in response to a kill request, @value{GDBN}
39444probes the target state as if a new connection was opened
39445(@pxref{? packet}).
c906108c 39446
b8ff78ce
JB
39447@item m @var{addr},@var{length}
39448@cindex @samp{m} packet
a86c90e6
SM
39449Read @var{length} addressable memory units starting at address @var{addr}
39450(@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
39451any particular boundary.
fb031cdf
JB
39452
39453The stub need not use any particular size or alignment when gathering
39454data from memory for the response; even if @var{addr} is word-aligned
39455and @var{length} is a multiple of the word size, the stub is free to
39456use byte accesses, or not. For this reason, this packet may not be
39457suitable for accessing memory-mapped I/O devices.
c43c5473
JB
39458@cindex alignment of remote memory accesses
39459@cindex size of remote memory accesses
39460@cindex memory, alignment and size of remote accesses
c906108c 39461
ee2d5c50
AC
39462Reply:
39463@table @samp
39464@item @var{XX@dots{}}
a86c90e6
SM
39465Memory contents; each byte is transmitted as a two-digit hexadecimal number.
39466The reply may contain fewer addressable memory units than requested if the
b8ff78ce
JB
39467server was able to read only part of the region of memory.
39468@item E @var{NN}
ee2d5c50
AC
39469@var{NN} is errno
39470@end table
39471
b8ff78ce
JB
39472@item M @var{addr},@var{length}:@var{XX@dots{}}
39473@cindex @samp{M} packet
a86c90e6
SM
39474Write @var{length} addressable memory units starting at address @var{addr}
39475(@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
39476byte is transmitted as a two-digit hexadecimal number.
ee2d5c50
AC
39477
39478Reply:
39479@table @samp
39480@item OK
39481for success
b8ff78ce 39482@item E @var{NN}
8e04817f
AC
39483for an error (this includes the case where only part of the data was
39484written).
ee2d5c50 39485@end table
c906108c 39486
b8ff78ce
JB
39487@item p @var{n}
39488@cindex @samp{p} packet
39489Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
39490@xref{read registers packet}, for a description of how the returned
39491register value is encoded.
ee2d5c50
AC
39492
39493Reply:
39494@table @samp
2e868123
AC
39495@item @var{XX@dots{}}
39496the register's value
b8ff78ce 39497@item E @var{NN}
2e868123 39498for an error
d57350ea 39499@item @w{}
2e868123 39500Indicating an unrecognized @var{query}.
ee2d5c50
AC
39501@end table
39502
b8ff78ce 39503@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 39504@anchor{write register packet}
b8ff78ce
JB
39505@cindex @samp{P} packet
39506Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 39507number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 39508digits for each byte in the register (target byte order).
c906108c 39509
ee2d5c50
AC
39510Reply:
39511@table @samp
39512@item OK
39513for success
b8ff78ce 39514@item E @var{NN}
ee2d5c50
AC
39515for an error
39516@end table
39517
5f3bebba
JB
39518@item q @var{name} @var{params}@dots{}
39519@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 39520@cindex @samp{q} packet
b8ff78ce 39521@cindex @samp{Q} packet
5f3bebba
JB
39522General query (@samp{q}) and set (@samp{Q}). These packets are
39523described fully in @ref{General Query Packets}.
c906108c 39524
b8ff78ce
JB
39525@item r
39526@cindex @samp{r} packet
8e04817f 39527Reset the entire system.
c906108c 39528
b8ff78ce 39529Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 39530
b8ff78ce
JB
39531@item R @var{XX}
39532@cindex @samp{R} packet
697aa1b7 39533Restart the program being debugged. The @var{XX}, while needed, is ignored.
2d717e4f 39534This packet is only available in extended mode (@pxref{extended mode}).
ee2d5c50 39535
8e04817f 39536The @samp{R} packet has no reply.
ee2d5c50 39537
4f553f88 39538@item s @r{[}@var{addr}@r{]}
b8ff78ce 39539@cindex @samp{s} packet
697aa1b7 39540Single step, resuming at @var{addr}. If
b8ff78ce 39541@var{addr} is omitted, resume at same address.
c906108c 39542
393eab54
PA
39543This packet is deprecated for multi-threading support. @xref{vCont
39544packet}.
39545
ee2d5c50
AC
39546Reply:
39547@xref{Stop Reply Packets}, for the reply specifications.
39548
4f553f88 39549@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 39550@anchor{step with signal packet}
b8ff78ce
JB
39551@cindex @samp{S} packet
39552Step with signal. This is analogous to the @samp{C} packet, but
39553requests a single-step, rather than a normal resumption of execution.
c906108c 39554
393eab54
PA
39555This packet is deprecated for multi-threading support. @xref{vCont
39556packet}.
39557
ee2d5c50
AC
39558Reply:
39559@xref{Stop Reply Packets}, for the reply specifications.
39560
b8ff78ce
JB
39561@item t @var{addr}:@var{PP},@var{MM}
39562@cindex @samp{t} packet
8e04817f 39563Search backwards starting at address @var{addr} for a match with pattern
697aa1b7
EZ
39564@var{PP} and mask @var{MM}, both of which are are 4 byte long.
39565There must be at least 3 digits in @var{addr}.
c906108c 39566
b90a069a 39567@item T @var{thread-id}
b8ff78ce 39568@cindex @samp{T} packet
b90a069a 39569Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
c906108c 39570
ee2d5c50
AC
39571Reply:
39572@table @samp
39573@item OK
39574thread is still alive
b8ff78ce 39575@item E @var{NN}
ee2d5c50
AC
39576thread is dead
39577@end table
39578
b8ff78ce
JB
39579@item v
39580Packets starting with @samp{v} are identified by a multi-letter name,
39581up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 39582
2d717e4f
DJ
39583@item vAttach;@var{pid}
39584@cindex @samp{vAttach} packet
8b23ecc4
SL
39585Attach to a new process with the specified process ID @var{pid}.
39586The process ID is a
39587hexadecimal integer identifying the process. In all-stop mode, all
39588threads in the attached process are stopped; in non-stop mode, it may be
39589attached without being stopped if that is supported by the target.
39590
39591@c In non-stop mode, on a successful vAttach, the stub should set the
39592@c current thread to a thread of the newly-attached process. After
39593@c attaching, GDB queries for the attached process's thread ID with qC.
39594@c Also note that, from a user perspective, whether or not the
39595@c target is stopped on attach in non-stop mode depends on whether you
39596@c use the foreground or background version of the attach command, not
39597@c on what vAttach does; GDB does the right thing with respect to either
39598@c stopping or restarting threads.
2d717e4f
DJ
39599
39600This packet is only available in extended mode (@pxref{extended mode}).
39601
39602Reply:
39603@table @samp
39604@item E @var{nn}
39605for an error
39606@item @r{Any stop packet}
8b23ecc4
SL
39607for success in all-stop mode (@pxref{Stop Reply Packets})
39608@item OK
39609for success in non-stop mode (@pxref{Remote Non-Stop})
2d717e4f
DJ
39610@end table
39611
b90a069a 39612@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
b8ff78ce 39613@cindex @samp{vCont} packet
393eab54 39614@anchor{vCont packet}
b8ff78ce 39615Resume the inferior, specifying different actions for each thread.
ca6eff59
PA
39616
39617For each inferior thread, the leftmost action with a matching
39618@var{thread-id} is applied. Threads that don't match any action
39619remain in their current state. Thread IDs are specified using the
39620syntax described in @ref{thread-id syntax}. If multiprocess
39621extensions (@pxref{multiprocess extensions}) are supported, actions
39622can be specified to match all threads in a process by using the
39623@samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
39402e6c
PA
39624@var{thread-id} matches all threads. Specifying no actions is an
39625error.
b90a069a
SL
39626
39627Currently supported actions are:
86d30acc 39628
b8ff78ce 39629@table @samp
86d30acc
DJ
39630@item c
39631Continue.
b8ff78ce 39632@item C @var{sig}
8b23ecc4 39633Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
39634@item s
39635Step.
b8ff78ce 39636@item S @var{sig}
8b23ecc4
SL
39637Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
39638@item t
39639Stop.
c1e36e3e
PA
39640@item r @var{start},@var{end}
39641Step once, and then keep stepping as long as the thread stops at
39642addresses between @var{start} (inclusive) and @var{end} (exclusive).
39643The remote stub reports a stop reply when either the thread goes out
39644of the range or is stopped due to an unrelated reason, such as hitting
39645a breakpoint. @xref{range stepping}.
39646
39647If the range is empty (@var{start} == @var{end}), then the action
39648becomes equivalent to the @samp{s} action. In other words,
39649single-step once, and report the stop (even if the stepped instruction
39650jumps to @var{start}).
39651
39652(A stop reply may be sent at any point even if the PC is still within
39653the stepping range; for example, it is valid to implement this packet
39654in a degenerate way as a single instruction step operation.)
39655
86d30acc
DJ
39656@end table
39657
8b23ecc4
SL
39658The optional argument @var{addr} normally associated with the
39659@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
b8ff78ce 39660not supported in @samp{vCont}.
86d30acc 39661
08a0efd0
PA
39662The @samp{t} action is only relevant in non-stop mode
39663(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
8b23ecc4
SL
39664A stop reply should be generated for any affected thread not already stopped.
39665When a thread is stopped by means of a @samp{t} action,
39666the corresponding stop reply should indicate that the thread has stopped with
39667signal @samp{0}, regardless of whether the target uses some other signal
39668as an implementation detail.
39669
ca6eff59
PA
39670The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
39671@samp{r} actions for threads that are already running. Conversely,
39672the server must ignore @samp{t} actions for threads that are already
39673stopped.
39674
39675@emph{Note:} In non-stop mode, a thread is considered running until
6b92c0d3 39676@value{GDBN} acknowledges an asynchronous stop notification for it with
ca6eff59
PA
39677the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
39678
4220b2f8 39679The stub must support @samp{vCont} if it reports support for
ca6eff59 39680multiprocess extensions (@pxref{multiprocess extensions}).
4220b2f8 39681
86d30acc
DJ
39682Reply:
39683@xref{Stop Reply Packets}, for the reply specifications.
39684
b8ff78ce
JB
39685@item vCont?
39686@cindex @samp{vCont?} packet
d3e8051b 39687Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
39688
39689Reply:
39690@table @samp
b8ff78ce
JB
39691@item vCont@r{[};@var{action}@dots{}@r{]}
39692The @samp{vCont} packet is supported. Each @var{action} is a supported
39693command in the @samp{vCont} packet.
d57350ea 39694@item @w{}
b8ff78ce 39695The @samp{vCont} packet is not supported.
86d30acc 39696@end table
ee2d5c50 39697
de979965
PA
39698@anchor{vCtrlC packet}
39699@item vCtrlC
39700@cindex @samp{vCtrlC} packet
39701Interrupt remote target as if a control-C was pressed on the remote
39702terminal. This is the equivalent to reacting to the @code{^C}
39703(@samp{\003}, the control-C character) character in all-stop mode
39704while the target is running, except this works in non-stop mode.
39705@xref{interrupting remote targets}, for more info on the all-stop
39706variant.
39707
39708Reply:
39709@table @samp
39710@item E @var{nn}
39711for an error
39712@item OK
39713for success
39714@end table
39715
a6b151f1
DJ
39716@item vFile:@var{operation}:@var{parameter}@dots{}
39717@cindex @samp{vFile} packet
39718Perform a file operation on the target system. For details,
39719see @ref{Host I/O Packets}.
39720
68437a39
DJ
39721@item vFlashErase:@var{addr},@var{length}
39722@cindex @samp{vFlashErase} packet
39723Direct the stub to erase @var{length} bytes of flash starting at
39724@var{addr}. The region may enclose any number of flash blocks, but
39725its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
39726flash block size appearing in the memory map (@pxref{Memory Map
39727Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
39728together, and sends a @samp{vFlashDone} request after each group; the
39729stub is allowed to delay erase operation until the @samp{vFlashDone}
39730packet is received.
39731
39732Reply:
39733@table @samp
39734@item OK
39735for success
39736@item E @var{NN}
39737for an error
39738@end table
39739
39740@item vFlashWrite:@var{addr}:@var{XX@dots{}}
39741@cindex @samp{vFlashWrite} packet
39742Direct the stub to write data to flash address @var{addr}. The data
39743is passed in binary form using the same encoding as for the @samp{X}
39744packet (@pxref{Binary Data}). The memory ranges specified by
39745@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
39746not overlap, and must appear in order of increasing addresses
39747(although @samp{vFlashErase} packets for higher addresses may already
39748have been received; the ordering is guaranteed only between
39749@samp{vFlashWrite} packets). If a packet writes to an address that was
39750neither erased by a preceding @samp{vFlashErase} packet nor by some other
39751target-specific method, the results are unpredictable.
39752
39753
39754Reply:
39755@table @samp
39756@item OK
39757for success
39758@item E.memtype
39759for vFlashWrite addressing non-flash memory
39760@item E @var{NN}
39761for an error
39762@end table
39763
39764@item vFlashDone
39765@cindex @samp{vFlashDone} packet
39766Indicate to the stub that flash programming operation is finished.
39767The stub is permitted to delay or batch the effects of a group of
39768@samp{vFlashErase} and @samp{vFlashWrite} packets until a
39769@samp{vFlashDone} packet is received. The contents of the affected
39770regions of flash memory are unpredictable until the @samp{vFlashDone}
39771request is completed.
39772
b90a069a
SL
39773@item vKill;@var{pid}
39774@cindex @samp{vKill} packet
36cb1214 39775@anchor{vKill packet}
697aa1b7 39776Kill the process with the specified process ID @var{pid}, which is a
b90a069a
SL
39777hexadecimal integer identifying the process. This packet is used in
39778preference to @samp{k} when multiprocess protocol extensions are
39779supported; see @ref{multiprocess extensions}.
39780
39781Reply:
39782@table @samp
39783@item E @var{nn}
39784for an error
39785@item OK
39786for success
39787@end table
39788
176efed1
AB
39789@item vMustReplyEmpty
39790@cindex @samp{vMustReplyEmpty} packet
39791The correct reply to an unknown @samp{v} packet is to return the empty
39792string, however, some older versions of @command{gdbserver} would
39793incorrectly return @samp{OK} for unknown @samp{v} packets.
39794
39795The @samp{vMustReplyEmpty} is used as a feature test to check how
39796@command{gdbserver} handles unknown packets, it is important that this
39797packet be handled in the same way as other unknown @samp{v} packets.
39798If this packet is handled differently to other unknown @samp{v}
6b92c0d3 39799packets then it is possible that @value{GDBN} may run into problems in
176efed1
AB
39800other areas, specifically around use of @samp{vFile:setfs:}.
39801
2d717e4f
DJ
39802@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
39803@cindex @samp{vRun} packet
39804Run the program @var{filename}, passing it each @var{argument} on its
39805command line. The file and arguments are hex-encoded strings. If
39806@var{filename} is an empty string, the stub may use a default program
39807(e.g.@: the last program run). The program is created in the stopped
9b562ab8 39808state.
2d717e4f 39809
8b23ecc4
SL
39810@c FIXME: What about non-stop mode?
39811
2d717e4f
DJ
39812This packet is only available in extended mode (@pxref{extended mode}).
39813
39814Reply:
39815@table @samp
39816@item E @var{nn}
39817for an error
39818@item @r{Any stop packet}
39819for success (@pxref{Stop Reply Packets})
39820@end table
39821
8b23ecc4 39822@item vStopped
8b23ecc4 39823@cindex @samp{vStopped} packet
8dbe8ece 39824@xref{Notification Packets}.
8b23ecc4 39825
b8ff78ce 39826@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 39827@anchor{X packet}
b8ff78ce
JB
39828@cindex @samp{X} packet
39829Write data to memory, where the data is transmitted in binary.
a86c90e6
SM
39830Memory is specified by its address @var{addr} and number of addressable memory
39831units @var{length} (@pxref{addressable memory unit});
0876f84a 39832@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 39833
ee2d5c50
AC
39834Reply:
39835@table @samp
39836@item OK
39837for success
b8ff78ce 39838@item E @var{NN}
ee2d5c50
AC
39839for an error
39840@end table
39841
a1dcb23a
DJ
39842@item z @var{type},@var{addr},@var{kind}
39843@itemx Z @var{type},@var{addr},@var{kind}
2f870471 39844@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
39845@cindex @samp{z} packet
39846@cindex @samp{Z} packets
39847Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
a1dcb23a 39848watchpoint starting at address @var{address} of kind @var{kind}.
ee2d5c50 39849
2f870471
AC
39850Each breakpoint and watchpoint packet @var{type} is documented
39851separately.
39852
512217c7
AC
39853@emph{Implementation notes: A remote target shall return an empty string
39854for an unrecognized breakpoint or watchpoint packet @var{type}. A
39855remote target shall support either both or neither of a given
b8ff78ce 39856@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
39857avoid potential problems with duplicate packets, the operations should
39858be implemented in an idempotent way.}
39859
a1dcb23a 39860@item z0,@var{addr},@var{kind}
d3ce09f5 39861@itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
39862@cindex @samp{z0} packet
39863@cindex @samp{Z0} packet
4435e1cc 39864Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
a1dcb23a 39865@var{addr} of type @var{kind}.
2f870471 39866
4435e1cc 39867A software breakpoint is implemented by replacing the instruction at
2f870471 39868@var{addr} with a software breakpoint or trap instruction. The
4435e1cc
TT
39869@var{kind} is target-specific and typically indicates the size of the
39870breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
39871@sc{mips} can insert either a 2 or 4 byte breakpoint. Some
39872architectures have additional meanings for @var{kind}
39873(@pxref{Architecture-Specific Protocol Details}); if no
39874architecture-specific value is being used, it should be @samp{0}.
39875@var{kind} is hex-encoded. @var{cond_list} is an optional list of
39876conditional expressions in bytecode form that should be evaluated on
39877the target's side. These are the conditions that should be taken into
39878consideration when deciding if the breakpoint trigger should be
39879reported back to @value{GDBN}.
83364271 39880
f7e6eed5 39881See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
4435e1cc 39882for how to best report a software breakpoint event to @value{GDBN}.
f7e6eed5 39883
83364271
LM
39884The @var{cond_list} parameter is comprised of a series of expressions,
39885concatenated without separators. Each expression has the following form:
39886
39887@table @samp
39888
39889@item X @var{len},@var{expr}
39890@var{len} is the length of the bytecode expression and @var{expr} is the
39891actual conditional expression in bytecode form.
39892
39893@end table
39894
d3ce09f5
SS
39895The optional @var{cmd_list} parameter introduces commands that may be
39896run on the target, rather than being reported back to @value{GDBN}.
39897The parameter starts with a numeric flag @var{persist}; if the flag is
39898nonzero, then the breakpoint may remain active and the commands
39899continue to be run even when @value{GDBN} disconnects from the target.
39900Following this flag is a series of expressions concatenated with no
39901separators. Each expression has the following form:
39902
39903@table @samp
39904
39905@item X @var{len},@var{expr}
39906@var{len} is the length of the bytecode expression and @var{expr} is the
0968fbae 39907actual commands expression in bytecode form.
d3ce09f5
SS
39908
39909@end table
39910
2f870471 39911@emph{Implementation note: It is possible for a target to copy or move
4435e1cc 39912code that contains software breakpoints (e.g., when implementing
2f870471
AC
39913overlays). The behavior of this packet, in the presence of such a
39914target, is not defined.}
c906108c 39915
ee2d5c50
AC
39916Reply:
39917@table @samp
2f870471
AC
39918@item OK
39919success
d57350ea 39920@item @w{}
2f870471 39921not supported
b8ff78ce 39922@item E @var{NN}
ee2d5c50 39923for an error
2f870471
AC
39924@end table
39925
a1dcb23a 39926@item z1,@var{addr},@var{kind}
4435e1cc 39927@itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
39928@cindex @samp{z1} packet
39929@cindex @samp{Z1} packet
39930Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
a1dcb23a 39931address @var{addr}.
2f870471
AC
39932
39933A hardware breakpoint is implemented using a mechanism that is not
4435e1cc
TT
39934dependent on being able to modify the target's memory. The
39935@var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
39936same meaning as in @samp{Z0} packets.
2f870471
AC
39937
39938@emph{Implementation note: A hardware breakpoint is not affected by code
39939movement.}
39940
39941Reply:
39942@table @samp
ee2d5c50 39943@item OK
2f870471 39944success
d57350ea 39945@item @w{}
2f870471 39946not supported
b8ff78ce 39947@item E @var{NN}
2f870471
AC
39948for an error
39949@end table
39950
a1dcb23a
DJ
39951@item z2,@var{addr},@var{kind}
39952@itemx Z2,@var{addr},@var{kind}
b8ff78ce
JB
39953@cindex @samp{z2} packet
39954@cindex @samp{Z2} packet
a1dcb23a 39955Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
697aa1b7 39956The number of bytes to watch is specified by @var{kind}.
2f870471
AC
39957
39958Reply:
39959@table @samp
39960@item OK
39961success
d57350ea 39962@item @w{}
2f870471 39963not supported
b8ff78ce 39964@item E @var{NN}
2f870471
AC
39965for an error
39966@end table
39967
a1dcb23a
DJ
39968@item z3,@var{addr},@var{kind}
39969@itemx Z3,@var{addr},@var{kind}
b8ff78ce
JB
39970@cindex @samp{z3} packet
39971@cindex @samp{Z3} packet
a1dcb23a 39972Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
697aa1b7 39973The number of bytes to watch is specified by @var{kind}.
2f870471
AC
39974
39975Reply:
39976@table @samp
39977@item OK
39978success
d57350ea 39979@item @w{}
2f870471 39980not supported
b8ff78ce 39981@item E @var{NN}
2f870471
AC
39982for an error
39983@end table
39984
a1dcb23a
DJ
39985@item z4,@var{addr},@var{kind}
39986@itemx Z4,@var{addr},@var{kind}
b8ff78ce
JB
39987@cindex @samp{z4} packet
39988@cindex @samp{Z4} packet
a1dcb23a 39989Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
697aa1b7 39990The number of bytes to watch is specified by @var{kind}.
2f870471
AC
39991
39992Reply:
39993@table @samp
39994@item OK
39995success
d57350ea 39996@item @w{}
2f870471 39997not supported
b8ff78ce 39998@item E @var{NN}
2f870471 39999for an error
ee2d5c50
AC
40000@end table
40001
40002@end table
c906108c 40003
ee2d5c50
AC
40004@node Stop Reply Packets
40005@section Stop Reply Packets
40006@cindex stop reply packets
c906108c 40007
8b23ecc4
SL
40008The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
40009@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
40010receive any of the below as a reply. Except for @samp{?}
40011and @samp{vStopped}, that reply is only returned
b8ff78ce 40012when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
40013number} is defined by the header @file{include/gdb/signals.h} in the
40014@value{GDBN} source code.
c906108c 40015
4435e1cc
TT
40016In non-stop mode, the server will simply reply @samp{OK} to commands
40017such as @samp{vCont}; any stop will be the subject of a future
40018notification. @xref{Remote Non-Stop}.
40019
b8ff78ce
JB
40020As in the description of request packets, we include spaces in the
40021reply templates for clarity; these are not part of the reply packet's
40022syntax. No @value{GDBN} stop reply packet uses spaces to separate its
40023components.
c906108c 40024
b8ff78ce 40025@table @samp
ee2d5c50 40026
b8ff78ce 40027@item S @var{AA}
599b237a 40028The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
40029number). This is equivalent to a @samp{T} response with no
40030@var{n}:@var{r} pairs.
c906108c 40031
b8ff78ce
JB
40032@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
40033@cindex @samp{T} packet reply
599b237a 40034The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
40035number). This is equivalent to an @samp{S} response, except that the
40036@samp{@var{n}:@var{r}} pairs can carry values of important registers
40037and other information directly in the stop reply packet, reducing
40038round-trip latency. Single-step and breakpoint traps are reported
40039this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
40040
40041@itemize @bullet
b8ff78ce 40042@item
599b237a 40043If @var{n} is a hexadecimal number, it is a register number, and the
697aa1b7 40044corresponding @var{r} gives that register's value. The data @var{r} is a
b8ff78ce
JB
40045series of bytes in target byte order, with each byte given by a
40046two-digit hex number.
cfa9d6d9 40047
b8ff78ce 40048@item
b90a069a
SL
40049If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
40050the stopped thread, as specified in @ref{thread-id syntax}.
cfa9d6d9 40051
dc146f7c
VP
40052@item
40053If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
40054the core on which the stop event was detected.
40055
b8ff78ce 40056@item
cfa9d6d9
DJ
40057If @var{n} is a recognized @dfn{stop reason}, it describes a more
40058specific event that stopped the target. The currently defined stop
697aa1b7 40059reasons are listed below. The @var{aa} should be @samp{05}, the trap
cfa9d6d9
DJ
40060signal. At most one stop reason should be present.
40061
b8ff78ce
JB
40062@item
40063Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
40064and go on to the next; this allows us to extend the protocol in the
40065future.
cfa9d6d9
DJ
40066@end itemize
40067
40068The currently defined stop reasons are:
40069
40070@table @samp
40071@item watch
40072@itemx rwatch
40073@itemx awatch
40074The packet indicates a watchpoint hit, and @var{r} is the data address, in
40075hex.
40076
82075af2
JS
40077@item syscall_entry
40078@itemx syscall_return
40079The packet indicates a syscall entry or return, and @var{r} is the
40080syscall number, in hex.
40081
cfa9d6d9
DJ
40082@cindex shared library events, remote reply
40083@item library
40084The packet indicates that the loaded libraries have changed.
40085@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
697aa1b7 40086list of loaded libraries. The @var{r} part is ignored.
bacec72f
MS
40087
40088@cindex replay log events, remote reply
40089@item replaylog
40090The packet indicates that the target cannot continue replaying
40091logged execution events, because it has reached the end (or the
40092beginning when executing backward) of the log. The value of @var{r}
40093will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
40094for more information.
f7e6eed5
PA
40095
40096@item swbreak
40097@anchor{swbreak stop reason}
4435e1cc 40098The packet indicates a software breakpoint instruction was executed,
f7e6eed5
PA
40099irrespective of whether it was @value{GDBN} that planted the
40100breakpoint or the breakpoint is hardcoded in the program. The @var{r}
40101part must be left empty.
40102
40103On some architectures, such as x86, at the architecture level, when a
40104breakpoint instruction executes the program counter points at the
40105breakpoint address plus an offset. On such targets, the stub is
40106responsible for adjusting the PC to point back at the breakpoint
40107address.
40108
40109This packet should not be sent by default; older @value{GDBN} versions
40110did not support it. @value{GDBN} requests it, by supplying an
40111appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40112remote stub must also supply the appropriate @samp{qSupported} feature
40113indicating support.
40114
40115This packet is required for correct non-stop mode operation.
40116
40117@item hwbreak
40118The packet indicates the target stopped for a hardware breakpoint.
40119The @var{r} part must be left empty.
40120
40121The same remarks about @samp{qSupported} and non-stop mode above
40122apply.
0d71eef5
DB
40123
40124@cindex fork events, remote reply
40125@item fork
40126The packet indicates that @code{fork} was called, and @var{r}
40127is the thread ID of the new child process. Refer to
40128@ref{thread-id syntax} for the format of the @var{thread-id}
40129field. This packet is only applicable to targets that support
40130fork events.
40131
40132This packet should not be sent by default; older @value{GDBN} versions
40133did not support it. @value{GDBN} requests it, by supplying an
40134appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40135remote stub must also supply the appropriate @samp{qSupported} feature
40136indicating support.
40137
40138@cindex vfork events, remote reply
40139@item vfork
40140The packet indicates that @code{vfork} was called, and @var{r}
40141is the thread ID of the new child process. Refer to
40142@ref{thread-id syntax} for the format of the @var{thread-id}
40143field. This packet is only applicable to targets that support
40144vfork events.
40145
40146This packet should not be sent by default; older @value{GDBN} versions
40147did not support it. @value{GDBN} requests it, by supplying an
40148appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40149remote stub must also supply the appropriate @samp{qSupported} feature
40150indicating support.
40151
40152@cindex vforkdone events, remote reply
40153@item vforkdone
e68fa6f0
PA
40154The packet indicates that a child process created by a vfork
40155has either called @code{exec} or terminated, so that the
40156address spaces of the parent and child process are no longer
40157shared. The @var{r} part is ignored. This packet is only
40158applicable to targets that support vforkdone events.
0d71eef5
DB
40159
40160This packet should not be sent by default; older @value{GDBN} versions
40161did not support it. @value{GDBN} requests it, by supplying an
40162appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40163remote stub must also supply the appropriate @samp{qSupported} feature
40164indicating support.
40165
b459a59b
DB
40166@cindex exec events, remote reply
40167@item exec
40168The packet indicates that @code{execve} was called, and @var{r}
40169is the absolute pathname of the file that was executed, in hex.
40170This packet is only applicable to targets that support exec events.
40171
40172This packet should not be sent by default; older @value{GDBN} versions
40173did not support it. @value{GDBN} requests it, by supplying an
40174appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40175remote stub must also supply the appropriate @samp{qSupported} feature
40176indicating support.
40177
65706a29
PA
40178@cindex thread create event, remote reply
40179@anchor{thread create event}
40180@item create
40181The packet indicates that the thread was just created. The new thread
40182is stopped until @value{GDBN} sets it running with a resumption packet
40183(@pxref{vCont packet}). This packet should not be sent by default;
40184@value{GDBN} requests it with the @ref{QThreadEvents} packet. See
4435e1cc
TT
40185also the @samp{w} (@pxref{thread exit event}) remote reply below. The
40186@var{r} part is ignored.
65706a29 40187
cfa9d6d9 40188@end table
ee2d5c50 40189
b8ff78ce 40190@item W @var{AA}
b90a069a 40191@itemx W @var{AA} ; process:@var{pid}
8e04817f 40192The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
40193applicable to certain targets.
40194
4435e1cc
TT
40195The second form of the response, including the process ID of the
40196exited process, can be used only when @value{GDBN} has reported
40197support for multiprocess protocol extensions; see @ref{multiprocess
40198extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40199hex strings.
b90a069a 40200
b8ff78ce 40201@item X @var{AA}
b90a069a 40202@itemx X @var{AA} ; process:@var{pid}
8e04817f 40203The process terminated with signal @var{AA}.
c906108c 40204
b90a069a
SL
40205The second form of the response, including the process ID of the
40206terminated process, can be used only when @value{GDBN} has reported
40207support for multiprocess protocol extensions; see @ref{multiprocess
4435e1cc
TT
40208extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40209hex strings.
b90a069a 40210
65706a29
PA
40211@anchor{thread exit event}
40212@cindex thread exit event, remote reply
40213@item w @var{AA} ; @var{tid}
40214
40215The thread exited, and @var{AA} is the exit status. This response
40216should not be sent by default; @value{GDBN} requests it with the
40217@ref{QThreadEvents} packet. See also @ref{thread create event} above.
4435e1cc 40218@var{AA} is formatted as a big-endian hex string.
65706a29 40219
f2faf941
PA
40220@item N
40221There are no resumed threads left in the target. In other words, even
40222though the process is alive, the last resumed thread has exited. For
40223example, say the target process has two threads: thread 1 and thread
402242. The client leaves thread 1 stopped, and resumes thread 2, which
40225subsequently exits. At this point, even though the process is still
40226alive, and thus no @samp{W} stop reply is sent, no thread is actually
40227executing either. The @samp{N} stop reply thus informs the client
40228that it can stop waiting for stop replies. This packet should not be
40229sent by default; older @value{GDBN} versions did not support it.
40230@value{GDBN} requests it, by supplying an appropriate
40231@samp{qSupported} feature (@pxref{qSupported}). The remote stub must
40232also supply the appropriate @samp{qSupported} feature indicating
40233support.
40234
b8ff78ce
JB
40235@item O @var{XX}@dots{}
40236@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
40237written as the program's console output. This can happen at any time
40238while the program is running and the debugger should continue to wait
8b23ecc4 40239for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
0ce1b118 40240
b8ff78ce 40241@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
40242@var{call-id} is the identifier which says which host system call should
40243be called. This is just the name of the function. Translation into the
40244correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 40245@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
40246system calls.
40247
b8ff78ce
JB
40248@samp{@var{parameter}@dots{}} is a list of parameters as defined for
40249this very system call.
0ce1b118 40250
b8ff78ce
JB
40251The target replies with this packet when it expects @value{GDBN} to
40252call a host system call on behalf of the target. @value{GDBN} replies
40253with an appropriate @samp{F} packet and keeps up waiting for the next
40254reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
40255or @samp{s} action is expected to be continued. @xref{File-I/O Remote
40256Protocol Extension}, for more details.
0ce1b118 40257
ee2d5c50
AC
40258@end table
40259
40260@node General Query Packets
40261@section General Query Packets
9c16f35a 40262@cindex remote query requests
c906108c 40263
5f3bebba
JB
40264Packets starting with @samp{q} are @dfn{general query packets};
40265packets starting with @samp{Q} are @dfn{general set packets}. General
40266query and set packets are a semi-unified form for retrieving and
40267sending information to and from the stub.
40268
40269The initial letter of a query or set packet is followed by a name
40270indicating what sort of thing the packet applies to. For example,
40271@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
40272definitions with the stub. These packet names follow some
40273conventions:
40274
40275@itemize @bullet
40276@item
40277The name must not contain commas, colons or semicolons.
40278@item
40279Most @value{GDBN} query and set packets have a leading upper case
40280letter.
40281@item
40282The names of custom vendor packets should use a company prefix, in
40283lower case, followed by a period. For example, packets designed at
40284the Acme Corporation might begin with @samp{qacme.foo} (for querying
40285foos) or @samp{Qacme.bar} (for setting bars).
40286@end itemize
40287
aa56d27a
JB
40288The name of a query or set packet should be separated from any
40289parameters by a @samp{:}; the parameters themselves should be
40290separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
40291full packet name, and check for a separator or the end of the packet,
40292in case two packet names share a common prefix. New packets should not begin
40293with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
40294packets predate these conventions, and have arguments without any terminator
40295for the packet name; we suspect they are in widespread use in places that
40296are difficult to upgrade. The @samp{qC} packet has no arguments, but some
40297existing stubs (e.g.@: RedBoot) are known to not check for the end of the
40298packet.}.
c906108c 40299
b8ff78ce
JB
40300Like the descriptions of the other packets, each description here
40301has a template showing the packet's overall syntax, followed by an
40302explanation of the packet's meaning. We include spaces in some of the
40303templates for clarity; these are not part of the packet's syntax. No
40304@value{GDBN} packet uses spaces to separate its components.
40305
5f3bebba
JB
40306Here are the currently defined query and set packets:
40307
b8ff78ce 40308@table @samp
c906108c 40309
d1feda86 40310@item QAgent:1
af4238e5 40311@itemx QAgent:0
d1feda86
YQ
40312Turn on or off the agent as a helper to perform some debugging operations
40313delegated from @value{GDBN} (@pxref{Control Agent}).
40314
d914c394
SS
40315@item QAllow:@var{op}:@var{val}@dots{}
40316@cindex @samp{QAllow} packet
40317Specify which operations @value{GDBN} expects to request of the
40318target, as a semicolon-separated list of operation name and value
40319pairs. Possible values for @var{op} include @samp{WriteReg},
40320@samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
40321@samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
40322indicating that @value{GDBN} will not request the operation, or 1,
40323indicating that it may. (The target can then use this to set up its
40324own internals optimally, for instance if the debugger never expects to
40325insert breakpoints, it may not need to install its own trap handler.)
40326
b8ff78ce 40327@item qC
9c16f35a 40328@cindex current thread, remote request
b8ff78ce 40329@cindex @samp{qC} packet
b90a069a 40330Return the current thread ID.
ee2d5c50
AC
40331
40332Reply:
40333@table @samp
b90a069a
SL
40334@item QC @var{thread-id}
40335Where @var{thread-id} is a thread ID as documented in
40336@ref{thread-id syntax}.
b8ff78ce 40337@item @r{(anything else)}
b90a069a 40338Any other reply implies the old thread ID.
ee2d5c50
AC
40339@end table
40340
b8ff78ce 40341@item qCRC:@var{addr},@var{length}
ff2587ec 40342@cindex CRC of memory block, remote request
b8ff78ce 40343@cindex @samp{qCRC} packet
936d2992 40344@anchor{qCRC packet}
99e008fe
EZ
40345Compute the CRC checksum of a block of memory using CRC-32 defined in
40346IEEE 802.3. The CRC is computed byte at a time, taking the most
40347significant bit of each byte first. The initial pattern code
40348@code{0xffffffff} is used to ensure leading zeros affect the CRC.
40349
40350@emph{Note:} This is the same CRC used in validating separate debug
40351files (@pxref{Separate Debug Files, , Debugging Information in Separate
40352Files}). However the algorithm is slightly different. When validating
40353separate debug files, the CRC is computed taking the @emph{least}
40354significant bit of each byte first, and the final result is inverted to
40355detect trailing zeros.
40356
ff2587ec
WZ
40357Reply:
40358@table @samp
b8ff78ce 40359@item E @var{NN}
ff2587ec 40360An error (such as memory fault)
b8ff78ce
JB
40361@item C @var{crc32}
40362The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
40363@end table
40364
03583c20
UW
40365@item QDisableRandomization:@var{value}
40366@cindex disable address space randomization, remote request
40367@cindex @samp{QDisableRandomization} packet
40368Some target operating systems will randomize the virtual address space
40369of the inferior process as a security feature, but provide a feature
40370to disable such randomization, e.g.@: to allow for a more deterministic
40371debugging experience. On such systems, this packet with a @var{value}
40372of 1 directs the target to disable address space randomization for
40373processes subsequently started via @samp{vRun} packets, while a packet
40374with a @var{value} of 0 tells the target to enable address space
40375randomization.
40376
40377This packet is only available in extended mode (@pxref{extended mode}).
40378
40379Reply:
40380@table @samp
40381@item OK
40382The request succeeded.
40383
40384@item E @var{nn}
697aa1b7 40385An error occurred. The error number @var{nn} is given as hex digits.
03583c20 40386
d57350ea 40387@item @w{}
03583c20
UW
40388An empty reply indicates that @samp{QDisableRandomization} is not supported
40389by the stub.
40390@end table
40391
40392This packet is not probed by default; the remote stub must request it,
40393by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40394This should only be done on targets that actually support disabling
40395address space randomization.
40396
aefd8b33
SDJ
40397@item QStartupWithShell:@var{value}
40398@cindex startup with shell, remote request
40399@cindex @samp{QStartupWithShell} packet
40400On UNIX-like targets, it is possible to start the inferior using a
40401shell program. This is the default behavior on both @value{GDBN} and
40402@command{gdbserver} (@pxref{set startup-with-shell}). This packet is
40403used to inform @command{gdbserver} whether it should start the
40404inferior using a shell or not.
40405
40406If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
40407to start the inferior. If @var{value} is @samp{1},
40408@command{gdbserver} will use a shell to start the inferior. All other
40409values are considered an error.
40410
40411This packet is only available in extended mode (@pxref{extended
40412mode}).
40413
40414Reply:
40415@table @samp
40416@item OK
40417The request succeeded.
40418
40419@item E @var{nn}
40420An error occurred. The error number @var{nn} is given as hex digits.
40421@end table
40422
40423This packet is not probed by default; the remote stub must request it,
40424by supplying an appropriate @samp{qSupported} response
40425(@pxref{qSupported}). This should only be done on targets that
40426actually support starting the inferior using a shell.
40427
40428Use of this packet is controlled by the @code{set startup-with-shell}
40429command; @pxref{set startup-with-shell}.
40430
0a2dde4a
SDJ
40431@item QEnvironmentHexEncoded:@var{hex-value}
40432@anchor{QEnvironmentHexEncoded}
40433@cindex set environment variable, remote request
40434@cindex @samp{QEnvironmentHexEncoded} packet
40435On UNIX-like targets, it is possible to set environment variables that
40436will be passed to the inferior during the startup process. This
40437packet is used to inform @command{gdbserver} of an environment
40438variable that has been defined by the user on @value{GDBN} (@pxref{set
40439environment}).
40440
40441The packet is composed by @var{hex-value}, an hex encoded
40442representation of the @var{name=value} format representing an
40443environment variable. The name of the environment variable is
40444represented by @var{name}, and the value to be assigned to the
40445environment variable is represented by @var{value}. If the variable
40446has no value (i.e., the value is @code{null}), then @var{value} will
40447not be present.
40448
40449This packet is only available in extended mode (@pxref{extended
40450mode}).
40451
40452Reply:
40453@table @samp
40454@item OK
40455The request succeeded.
40456@end table
40457
40458This packet is not probed by default; the remote stub must request it,
40459by supplying an appropriate @samp{qSupported} response
40460(@pxref{qSupported}). This should only be done on targets that
40461actually support passing environment variables to the starting
40462inferior.
40463
40464This packet is related to the @code{set environment} command;
40465@pxref{set environment}.
40466
40467@item QEnvironmentUnset:@var{hex-value}
40468@anchor{QEnvironmentUnset}
40469@cindex unset environment variable, remote request
40470@cindex @samp{QEnvironmentUnset} packet
40471On UNIX-like targets, it is possible to unset environment variables
40472before starting the inferior in the remote target. This packet is
40473used to inform @command{gdbserver} of an environment variable that has
40474been unset by the user on @value{GDBN} (@pxref{unset environment}).
40475
40476The packet is composed by @var{hex-value}, an hex encoded
40477representation of the name of the environment variable to be unset.
40478
40479This packet is only available in extended mode (@pxref{extended
40480mode}).
40481
40482Reply:
40483@table @samp
40484@item OK
40485The request succeeded.
40486@end table
40487
40488This packet is not probed by default; the remote stub must request it,
40489by supplying an appropriate @samp{qSupported} response
40490(@pxref{qSupported}). This should only be done on targets that
40491actually support passing environment variables to the starting
40492inferior.
40493
40494This packet is related to the @code{unset environment} command;
40495@pxref{unset environment}.
40496
40497@item QEnvironmentReset
40498@anchor{QEnvironmentReset}
40499@cindex reset environment, remote request
40500@cindex @samp{QEnvironmentReset} packet
40501On UNIX-like targets, this packet is used to reset the state of
40502environment variables in the remote target before starting the
40503inferior. In this context, reset means unsetting all environment
40504variables that were previously set by the user (i.e., were not
40505initially present in the environment). It is sent to
40506@command{gdbserver} before the @samp{QEnvironmentHexEncoded}
40507(@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
40508(@pxref{QEnvironmentUnset}) packets.
40509
40510This packet is only available in extended mode (@pxref{extended
40511mode}).
40512
40513Reply:
40514@table @samp
40515@item OK
40516The request succeeded.
40517@end table
40518
40519This packet is not probed by default; the remote stub must request it,
40520by supplying an appropriate @samp{qSupported} response
40521(@pxref{qSupported}). This should only be done on targets that
40522actually support passing environment variables to the starting
40523inferior.
40524
bc3b087d
SDJ
40525@item QSetWorkingDir:@r{[}@var{directory}@r{]}
40526@anchor{QSetWorkingDir packet}
40527@cindex set working directory, remote request
40528@cindex @samp{QSetWorkingDir} packet
40529This packet is used to inform the remote server of the intended
40530current working directory for programs that are going to be executed.
40531
40532The packet is composed by @var{directory}, an hex encoded
40533representation of the directory that the remote inferior will use as
40534its current working directory. If @var{directory} is an empty string,
40535the remote server should reset the inferior's current working
40536directory to its original, empty value.
40537
40538This packet is only available in extended mode (@pxref{extended
40539mode}).
40540
40541Reply:
40542@table @samp
40543@item OK
40544The request succeeded.
40545@end table
40546
b8ff78ce
JB
40547@item qfThreadInfo
40548@itemx qsThreadInfo
9c16f35a 40549@cindex list active threads, remote request
b8ff78ce
JB
40550@cindex @samp{qfThreadInfo} packet
40551@cindex @samp{qsThreadInfo} packet
b90a069a 40552Obtain a list of all active thread IDs from the target (OS). Since there
8e04817f
AC
40553may be too many active threads to fit into one reply packet, this query
40554works iteratively: it may require more than one query/reply sequence to
40555obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
40556be the @samp{qfThreadInfo} query; subsequent queries in the
40557sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 40558
b8ff78ce 40559NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
40560
40561Reply:
40562@table @samp
b90a069a
SL
40563@item m @var{thread-id}
40564A single thread ID
40565@item m @var{thread-id},@var{thread-id}@dots{}
40566a comma-separated list of thread IDs
b8ff78ce
JB
40567@item l
40568(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
40569@end table
40570
40571In response to each query, the target will reply with a list of one or
b90a069a 40572more thread IDs, separated by commas.
e1aac25b 40573@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce 40574ids (using the @samp{qs} form of the query), until the target responds
501994c0 40575with @samp{l} (lower-case ell, for @dfn{last}).
b90a069a
SL
40576Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
40577fields.
c906108c 40578
8dfcab11
DT
40579@emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
40580initial connection with the remote target, and the very first thread ID
40581mentioned in the reply will be stopped by @value{GDBN} in a subsequent
40582message. Therefore, the stub should ensure that the first thread ID in
40583the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
40584
b8ff78ce 40585@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 40586@cindex get thread-local storage address, remote request
b8ff78ce 40587@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
40588Fetch the address associated with thread local storage specified
40589by @var{thread-id}, @var{offset}, and @var{lm}.
40590
b90a069a
SL
40591@var{thread-id} is the thread ID associated with the
40592thread for which to fetch the TLS address. @xref{thread-id syntax}.
ff2587ec
WZ
40593
40594@var{offset} is the (big endian, hex encoded) offset associated with the
40595thread local variable. (This offset is obtained from the debug
40596information associated with the variable.)
40597
db2e3e2e 40598@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
7a9dd1b2 40599load module associated with the thread local storage. For example,
ff2587ec
WZ
40600a @sc{gnu}/Linux system will pass the link map address of the shared
40601object associated with the thread local storage under consideration.
40602Other operating environments may choose to represent the load module
40603differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
40604
40605Reply:
b8ff78ce
JB
40606@table @samp
40607@item @var{XX}@dots{}
ff2587ec
WZ
40608Hex encoded (big endian) bytes representing the address of the thread
40609local storage requested.
40610
b8ff78ce 40611@item E @var{nn}
697aa1b7 40612An error occurred. The error number @var{nn} is given as hex digits.
ff2587ec 40613
d57350ea 40614@item @w{}
b8ff78ce 40615An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
40616@end table
40617
711e434b
PM
40618@item qGetTIBAddr:@var{thread-id}
40619@cindex get thread information block address
40620@cindex @samp{qGetTIBAddr} packet
40621Fetch address of the Windows OS specific Thread Information Block.
40622
40623@var{thread-id} is the thread ID associated with the thread.
40624
40625Reply:
40626@table @samp
40627@item @var{XX}@dots{}
40628Hex encoded (big endian) bytes representing the linear address of the
40629thread information block.
40630
40631@item E @var{nn}
40632An error occured. This means that either the thread was not found, or the
40633address could not be retrieved.
40634
d57350ea 40635@item @w{}
711e434b
PM
40636An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
40637@end table
40638
b8ff78ce 40639@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
40640Obtain thread information from RTOS. Where: @var{startflag} (one hex
40641digit) is one to indicate the first query and zero to indicate a
40642subsequent query; @var{threadcount} (two hex digits) is the maximum
40643number of threads the response packet can contain; and @var{nextthread}
40644(eight hex digits), for subsequent queries (@var{startflag} is zero), is
40645returned in the response as @var{argthread}.
ee2d5c50 40646
b8ff78ce 40647Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
40648
40649Reply:
40650@table @samp
b8ff78ce 40651@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
40652Where: @var{count} (two hex digits) is the number of threads being
40653returned; @var{done} (one hex digit) is zero to indicate more threads
40654and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 40655digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
697aa1b7
EZ
40656is a sequence of thread IDs, @var{threadid} (eight hex
40657digits), from the target. See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 40658@end table
c906108c 40659
b8ff78ce 40660@item qOffsets
9c16f35a 40661@cindex section offsets, remote request
b8ff78ce 40662@cindex @samp{qOffsets} packet
31d99776
DJ
40663Get section offsets that the target used when relocating the downloaded
40664image.
c906108c 40665
ee2d5c50
AC
40666Reply:
40667@table @samp
31d99776
DJ
40668@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
40669Relocate the @code{Text} section by @var{xxx} from its original address.
40670Relocate the @code{Data} section by @var{yyy} from its original address.
40671If the object file format provides segment information (e.g.@: @sc{elf}
40672@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
40673segments by the supplied offsets.
40674
40675@emph{Note: while a @code{Bss} offset may be included in the response,
40676@value{GDBN} ignores this and instead applies the @code{Data} offset
40677to the @code{Bss} section.}
40678
40679@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
40680Relocate the first segment of the object file, which conventionally
40681contains program code, to a starting address of @var{xxx}. If
40682@samp{DataSeg} is specified, relocate the second segment, which
40683conventionally contains modifiable data, to a starting address of
40684@var{yyy}. @value{GDBN} will report an error if the object file
40685does not contain segment information, or does not contain at least
40686as many segments as mentioned in the reply. Extra segments are
40687kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
40688@end table
40689
b90a069a 40690@item qP @var{mode} @var{thread-id}
9c16f35a 40691@cindex thread information, remote request
b8ff78ce 40692@cindex @samp{qP} packet
b90a069a
SL
40693Returns information on @var{thread-id}. Where: @var{mode} is a hex
40694encoded 32 bit mode; @var{thread-id} is a thread ID
40695(@pxref{thread-id syntax}).
ee2d5c50 40696
aa56d27a
JB
40697Don't use this packet; use the @samp{qThreadExtraInfo} query instead
40698(see below).
40699
b8ff78ce 40700Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 40701
8b23ecc4 40702@item QNonStop:1
687e43a4 40703@itemx QNonStop:0
8b23ecc4
SL
40704@cindex non-stop mode, remote request
40705@cindex @samp{QNonStop} packet
40706@anchor{QNonStop}
40707Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
40708@xref{Remote Non-Stop}, for more information.
40709
40710Reply:
40711@table @samp
40712@item OK
40713The request succeeded.
40714
40715@item E @var{nn}
697aa1b7 40716An error occurred. The error number @var{nn} is given as hex digits.
8b23ecc4 40717
d57350ea 40718@item @w{}
8b23ecc4
SL
40719An empty reply indicates that @samp{QNonStop} is not supported by
40720the stub.
40721@end table
40722
40723This packet is not probed by default; the remote stub must request it,
40724by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40725Use of this packet is controlled by the @code{set non-stop} command;
40726@pxref{Non-Stop Mode}.
40727
82075af2
JS
40728@item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
40729@itemx QCatchSyscalls:0
40730@cindex catch syscalls from inferior, remote request
40731@cindex @samp{QCatchSyscalls} packet
40732@anchor{QCatchSyscalls}
40733Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
40734catching syscalls from the inferior process.
40735
40736For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
40737in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
40738is listed, every system call should be reported.
40739
40740Note that if a syscall not in the list is reported, @value{GDBN} will
40741still filter the event according to its own list from all corresponding
40742@code{catch syscall} commands. However, it is more efficient to only
40743report the requested syscalls.
40744
40745Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
40746@samp{QCatchSyscalls:1} list is completely replaced by the new list.
40747
40748If the inferior process execs, the state of @samp{QCatchSyscalls} is
40749kept for the new process too. On targets where exec may affect syscall
40750numbers, for example with exec between 32 and 64-bit processes, the
40751client should send a new packet with the new syscall list.
40752
40753Reply:
40754@table @samp
40755@item OK
40756The request succeeded.
40757
40758@item E @var{nn}
40759An error occurred. @var{nn} are hex digits.
40760
40761@item @w{}
40762An empty reply indicates that @samp{QCatchSyscalls} is not supported by
40763the stub.
40764@end table
40765
40766Use of this packet is controlled by the @code{set remote catch-syscalls}
40767command (@pxref{Remote Configuration, set remote catch-syscalls}).
40768This packet is not probed by default; the remote stub must request it,
40769by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40770
89be2091
DJ
40771@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
40772@cindex pass signals to inferior, remote request
40773@cindex @samp{QPassSignals} packet
23181151 40774@anchor{QPassSignals}
89be2091
DJ
40775Each listed @var{signal} should be passed directly to the inferior process.
40776Signals are numbered identically to continue packets and stop replies
40777(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
40778strictly greater than the previous item. These signals do not need to stop
40779the inferior, or be reported to @value{GDBN}. All other signals should be
40780reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
40781combine; any earlier @samp{QPassSignals} list is completely replaced by the
40782new list. This packet improves performance when using @samp{handle
40783@var{signal} nostop noprint pass}.
40784
40785Reply:
40786@table @samp
40787@item OK
40788The request succeeded.
40789
40790@item E @var{nn}
697aa1b7 40791An error occurred. The error number @var{nn} is given as hex digits.
89be2091 40792
d57350ea 40793@item @w{}
89be2091
DJ
40794An empty reply indicates that @samp{QPassSignals} is not supported by
40795the stub.
40796@end table
40797
40798Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 40799command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
40800This packet is not probed by default; the remote stub must request it,
40801by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40802
9b224c5e
PA
40803@item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
40804@cindex signals the inferior may see, remote request
40805@cindex @samp{QProgramSignals} packet
40806@anchor{QProgramSignals}
40807Each listed @var{signal} may be delivered to the inferior process.
40808Others should be silently discarded.
40809
40810In some cases, the remote stub may need to decide whether to deliver a
40811signal to the program or not without @value{GDBN} involvement. One
40812example of that is while detaching --- the program's threads may have
40813stopped for signals that haven't yet had a chance of being reported to
40814@value{GDBN}, and so the remote stub can use the signal list specified
40815by this packet to know whether to deliver or ignore those pending
40816signals.
40817
40818This does not influence whether to deliver a signal as requested by a
40819resumption packet (@pxref{vCont packet}).
40820
40821Signals are numbered identically to continue packets and stop replies
40822(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
40823strictly greater than the previous item. Multiple
40824@samp{QProgramSignals} packets do not combine; any earlier
40825@samp{QProgramSignals} list is completely replaced by the new list.
40826
40827Reply:
40828@table @samp
40829@item OK
40830The request succeeded.
40831
40832@item E @var{nn}
697aa1b7 40833An error occurred. The error number @var{nn} is given as hex digits.
9b224c5e 40834
d57350ea 40835@item @w{}
9b224c5e
PA
40836An empty reply indicates that @samp{QProgramSignals} is not supported
40837by the stub.
40838@end table
40839
40840Use of this packet is controlled by the @code{set remote program-signals}
40841command (@pxref{Remote Configuration, set remote program-signals}).
40842This packet is not probed by default; the remote stub must request it,
40843by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40844
65706a29
PA
40845@anchor{QThreadEvents}
40846@item QThreadEvents:1
40847@itemx QThreadEvents:0
40848@cindex thread create/exit events, remote request
40849@cindex @samp{QThreadEvents} packet
40850
40851Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
40852reporting of thread create and exit events. @xref{thread create
40853event}, for the reply specifications. For example, this is used in
40854non-stop mode when @value{GDBN} stops a set of threads and
40855synchronously waits for the their corresponding stop replies. Without
40856exit events, if one of the threads exits, @value{GDBN} would hang
40857forever not knowing that it should no longer expect a stop for that
40858same thread. @value{GDBN} does not enable this feature unless the
40859stub reports that it supports it by including @samp{QThreadEvents+} in
40860its @samp{qSupported} reply.
40861
40862Reply:
40863@table @samp
40864@item OK
40865The request succeeded.
40866
40867@item E @var{nn}
40868An error occurred. The error number @var{nn} is given as hex digits.
40869
40870@item @w{}
40871An empty reply indicates that @samp{QThreadEvents} is not supported by
40872the stub.
40873@end table
40874
40875Use of this packet is controlled by the @code{set remote thread-events}
40876command (@pxref{Remote Configuration, set remote thread-events}).
40877
b8ff78ce 40878@item qRcmd,@var{command}
ff2587ec 40879@cindex execute remote command, remote request
b8ff78ce 40880@cindex @samp{qRcmd} packet
ff2587ec 40881@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
40882execution. Invalid commands should be reported using the output
40883string. Before the final result packet, the target may also respond
40884with a number of intermediate @samp{O@var{output}} console output
40885packets. @emph{Implementors should note that providing access to a
40886stubs's interpreter may have security implications}.
fa93a9d8 40887
ff2587ec
WZ
40888Reply:
40889@table @samp
40890@item OK
40891A command response with no output.
40892@item @var{OUTPUT}
40893A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 40894@item E @var{NN}
ff2587ec 40895Indicate a badly formed request.
d57350ea 40896@item @w{}
b8ff78ce 40897An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 40898@end table
fa93a9d8 40899
aa56d27a
JB
40900(Note that the @code{qRcmd} packet's name is separated from the
40901command by a @samp{,}, not a @samp{:}, contrary to the naming
40902conventions above. Please don't use this packet as a model for new
40903packets.)
40904
08388c79
DE
40905@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
40906@cindex searching memory, in remote debugging
5c4808ca 40907@ifnotinfo
08388c79 40908@cindex @samp{qSearch:memory} packet
5c4808ca
EZ
40909@end ifnotinfo
40910@cindex @samp{qSearch memory} packet
08388c79
DE
40911@anchor{qSearch memory}
40912Search @var{length} bytes at @var{address} for @var{search-pattern}.
697aa1b7
EZ
40913Both @var{address} and @var{length} are encoded in hex;
40914@var{search-pattern} is a sequence of bytes, also hex encoded.
08388c79
DE
40915
40916Reply:
40917@table @samp
40918@item 0
40919The pattern was not found.
40920@item 1,address
40921The pattern was found at @var{address}.
40922@item E @var{NN}
40923A badly formed request or an error was encountered while searching memory.
d57350ea 40924@item @w{}
08388c79
DE
40925An empty reply indicates that @samp{qSearch:memory} is not recognized.
40926@end table
40927
a6f3e723
SL
40928@item QStartNoAckMode
40929@cindex @samp{QStartNoAckMode} packet
40930@anchor{QStartNoAckMode}
40931Request that the remote stub disable the normal @samp{+}/@samp{-}
40932protocol acknowledgments (@pxref{Packet Acknowledgment}).
40933
40934Reply:
40935@table @samp
40936@item OK
40937The stub has switched to no-acknowledgment mode.
6b92c0d3 40938@value{GDBN} acknowledges this response,
a6f3e723
SL
40939but neither the stub nor @value{GDBN} shall send or expect further
40940@samp{+}/@samp{-} acknowledgments in the current connection.
d57350ea 40941@item @w{}
a6f3e723
SL
40942An empty reply indicates that the stub does not support no-acknowledgment mode.
40943@end table
40944
be2a5f71
DJ
40945@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
40946@cindex supported packets, remote query
40947@cindex features of the remote protocol
40948@cindex @samp{qSupported} packet
0876f84a 40949@anchor{qSupported}
be2a5f71
DJ
40950Tell the remote stub about features supported by @value{GDBN}, and
40951query the stub for features it supports. This packet allows
40952@value{GDBN} and the remote stub to take advantage of each others'
40953features. @samp{qSupported} also consolidates multiple feature probes
40954at startup, to improve @value{GDBN} performance---a single larger
40955packet performs better than multiple smaller probe packets on
40956high-latency links. Some features may enable behavior which must not
40957be on by default, e.g.@: because it would confuse older clients or
40958stubs. Other features may describe packets which could be
40959automatically probed for, but are not. These features must be
40960reported before @value{GDBN} will use them. This ``default
40961unsupported'' behavior is not appropriate for all packets, but it
40962helps to keep the initial connection time under control with new
40963versions of @value{GDBN} which support increasing numbers of packets.
40964
40965Reply:
40966@table @samp
40967@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
40968The stub supports or does not support each returned @var{stubfeature},
40969depending on the form of each @var{stubfeature} (see below for the
40970possible forms).
d57350ea 40971@item @w{}
be2a5f71
DJ
40972An empty reply indicates that @samp{qSupported} is not recognized,
40973or that no features needed to be reported to @value{GDBN}.
40974@end table
40975
40976The allowed forms for each feature (either a @var{gdbfeature} in the
40977@samp{qSupported} packet, or a @var{stubfeature} in the response)
40978are:
40979
40980@table @samp
40981@item @var{name}=@var{value}
40982The remote protocol feature @var{name} is supported, and associated
40983with the specified @var{value}. The format of @var{value} depends
40984on the feature, but it must not include a semicolon.
40985@item @var{name}+
40986The remote protocol feature @var{name} is supported, and does not
40987need an associated value.
40988@item @var{name}-
40989The remote protocol feature @var{name} is not supported.
40990@item @var{name}?
40991The remote protocol feature @var{name} may be supported, and
40992@value{GDBN} should auto-detect support in some other way when it is
40993needed. This form will not be used for @var{gdbfeature} notifications,
40994but may be used for @var{stubfeature} responses.
40995@end table
40996
40997Whenever the stub receives a @samp{qSupported} request, the
40998supplied set of @value{GDBN} features should override any previous
40999request. This allows @value{GDBN} to put the stub in a known
41000state, even if the stub had previously been communicating with
41001a different version of @value{GDBN}.
41002
b90a069a
SL
41003The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
41004are defined:
41005
41006@table @samp
41007@item multiprocess
41008This feature indicates whether @value{GDBN} supports multiprocess
41009extensions to the remote protocol. @value{GDBN} does not use such
41010extensions unless the stub also reports that it supports them by
41011including @samp{multiprocess+} in its @samp{qSupported} reply.
41012@xref{multiprocess extensions}, for details.
c8d5aac9
L
41013
41014@item xmlRegisters
41015This feature indicates that @value{GDBN} supports the XML target
41016description. If the stub sees @samp{xmlRegisters=} with target
41017specific strings separated by a comma, it will report register
41018description.
dde08ee1
PA
41019
41020@item qRelocInsn
41021This feature indicates whether @value{GDBN} supports the
41022@samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
41023instruction reply packet}).
f7e6eed5
PA
41024
41025@item swbreak
41026This feature indicates whether @value{GDBN} supports the swbreak stop
41027reason in stop replies. @xref{swbreak stop reason}, for details.
41028
41029@item hwbreak
41030This feature indicates whether @value{GDBN} supports the hwbreak stop
41031reason in stop replies. @xref{swbreak stop reason}, for details.
0d71eef5
DB
41032
41033@item fork-events
41034This feature indicates whether @value{GDBN} supports fork event
41035extensions to the remote protocol. @value{GDBN} does not use such
41036extensions unless the stub also reports that it supports them by
41037including @samp{fork-events+} in its @samp{qSupported} reply.
41038
41039@item vfork-events
41040This feature indicates whether @value{GDBN} supports vfork event
41041extensions to the remote protocol. @value{GDBN} does not use such
41042extensions unless the stub also reports that it supports them by
41043including @samp{vfork-events+} in its @samp{qSupported} reply.
b459a59b
DB
41044
41045@item exec-events
41046This feature indicates whether @value{GDBN} supports exec event
41047extensions to the remote protocol. @value{GDBN} does not use such
41048extensions unless the stub also reports that it supports them by
41049including @samp{exec-events+} in its @samp{qSupported} reply.
750ce8d1
YQ
41050
41051@item vContSupported
41052This feature indicates whether @value{GDBN} wants to know the
41053supported actions in the reply to @samp{vCont?} packet.
b90a069a
SL
41054@end table
41055
41056Stubs should ignore any unknown values for
be2a5f71
DJ
41057@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
41058packet supports receiving packets of unlimited length (earlier
b90a069a 41059versions of @value{GDBN} may reject overly long responses). Additional values
be2a5f71
DJ
41060for @var{gdbfeature} may be defined in the future to let the stub take
41061advantage of new features in @value{GDBN}, e.g.@: incompatible
b90a069a
SL
41062improvements in the remote protocol---the @samp{multiprocess} feature is
41063an example of such a feature. The stub's reply should be independent
be2a5f71
DJ
41064of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
41065describes all the features it supports, and then the stub replies with
41066all the features it supports.
41067
41068Similarly, @value{GDBN} will silently ignore unrecognized stub feature
41069responses, as long as each response uses one of the standard forms.
41070
41071Some features are flags. A stub which supports a flag feature
41072should respond with a @samp{+} form response. Other features
41073require values, and the stub should respond with an @samp{=}
41074form response.
41075
41076Each feature has a default value, which @value{GDBN} will use if
41077@samp{qSupported} is not available or if the feature is not mentioned
41078in the @samp{qSupported} response. The default values are fixed; a
41079stub is free to omit any feature responses that match the defaults.
41080
41081Not all features can be probed, but for those which can, the probing
41082mechanism is useful: in some cases, a stub's internal
41083architecture may not allow the protocol layer to know some information
41084about the underlying target in advance. This is especially common in
41085stubs which may be configured for multiple targets.
41086
41087These are the currently defined stub features and their properties:
41088
cfa9d6d9 41089@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
41090@c NOTE: The first row should be @headitem, but we do not yet require
41091@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 41092@item Feature Name
be2a5f71
DJ
41093@tab Value Required
41094@tab Default
41095@tab Probe Allowed
41096
41097@item @samp{PacketSize}
41098@tab Yes
41099@tab @samp{-}
41100@tab No
41101
0876f84a
DJ
41102@item @samp{qXfer:auxv:read}
41103@tab No
41104@tab @samp{-}
41105@tab Yes
41106
2ae8c8e7
MM
41107@item @samp{qXfer:btrace:read}
41108@tab No
41109@tab @samp{-}
41110@tab Yes
41111
f4abbc16
MM
41112@item @samp{qXfer:btrace-conf:read}
41113@tab No
41114@tab @samp{-}
41115@tab Yes
41116
c78fa86a
GB
41117@item @samp{qXfer:exec-file:read}
41118@tab No
41119@tab @samp{-}
41120@tab Yes
41121
23181151
DJ
41122@item @samp{qXfer:features:read}
41123@tab No
41124@tab @samp{-}
41125@tab Yes
41126
cfa9d6d9
DJ
41127@item @samp{qXfer:libraries:read}
41128@tab No
41129@tab @samp{-}
41130@tab Yes
41131
85dc5a12
GB
41132@item @samp{qXfer:libraries-svr4:read}
41133@tab No
41134@tab @samp{-}
41135@tab Yes
41136
41137@item @samp{augmented-libraries-svr4-read}
41138@tab No
41139@tab @samp{-}
41140@tab No
41141
68437a39
DJ
41142@item @samp{qXfer:memory-map:read}
41143@tab No
41144@tab @samp{-}
41145@tab Yes
41146
0fb4aa4b
PA
41147@item @samp{qXfer:sdata:read}
41148@tab No
41149@tab @samp{-}
41150@tab Yes
41151
4aa995e1
PA
41152@item @samp{qXfer:siginfo:read}
41153@tab No
41154@tab @samp{-}
41155@tab Yes
41156
41157@item @samp{qXfer:siginfo:write}
41158@tab No
41159@tab @samp{-}
41160@tab Yes
41161
dc146f7c
VP
41162@item @samp{qXfer:threads:read}
41163@tab No
41164@tab @samp{-}
41165@tab Yes
41166
b3b9301e
PA
41167@item @samp{qXfer:traceframe-info:read}
41168@tab No
41169@tab @samp{-}
41170@tab Yes
41171
169081d0
TG
41172@item @samp{qXfer:uib:read}
41173@tab No
41174@tab @samp{-}
41175@tab Yes
41176
78d85199
YQ
41177@item @samp{qXfer:fdpic:read}
41178@tab No
41179@tab @samp{-}
41180@tab Yes
dc146f7c 41181
2ae8c8e7
MM
41182@item @samp{Qbtrace:off}
41183@tab Yes
41184@tab @samp{-}
41185@tab Yes
41186
41187@item @samp{Qbtrace:bts}
41188@tab Yes
41189@tab @samp{-}
41190@tab Yes
41191
b20a6524
MM
41192@item @samp{Qbtrace:pt}
41193@tab Yes
41194@tab @samp{-}
41195@tab Yes
41196
d33501a5
MM
41197@item @samp{Qbtrace-conf:bts:size}
41198@tab Yes
41199@tab @samp{-}
41200@tab Yes
41201
b20a6524
MM
41202@item @samp{Qbtrace-conf:pt:size}
41203@tab Yes
41204@tab @samp{-}
41205@tab Yes
41206
8b23ecc4
SL
41207@item @samp{QNonStop}
41208@tab No
41209@tab @samp{-}
41210@tab Yes
41211
82075af2
JS
41212@item @samp{QCatchSyscalls}
41213@tab No
41214@tab @samp{-}
41215@tab Yes
41216
89be2091
DJ
41217@item @samp{QPassSignals}
41218@tab No
41219@tab @samp{-}
41220@tab Yes
41221
a6f3e723
SL
41222@item @samp{QStartNoAckMode}
41223@tab No
41224@tab @samp{-}
41225@tab Yes
41226
b90a069a
SL
41227@item @samp{multiprocess}
41228@tab No
41229@tab @samp{-}
41230@tab No
41231
83364271
LM
41232@item @samp{ConditionalBreakpoints}
41233@tab No
41234@tab @samp{-}
41235@tab No
41236
782b2b07
SS
41237@item @samp{ConditionalTracepoints}
41238@tab No
41239@tab @samp{-}
41240@tab No
41241
0d772ac9
MS
41242@item @samp{ReverseContinue}
41243@tab No
2f8132f3 41244@tab @samp{-}
0d772ac9
MS
41245@tab No
41246
41247@item @samp{ReverseStep}
41248@tab No
2f8132f3 41249@tab @samp{-}
0d772ac9
MS
41250@tab No
41251
409873ef
SS
41252@item @samp{TracepointSource}
41253@tab No
41254@tab @samp{-}
41255@tab No
41256
d1feda86
YQ
41257@item @samp{QAgent}
41258@tab No
41259@tab @samp{-}
41260@tab No
41261
d914c394
SS
41262@item @samp{QAllow}
41263@tab No
41264@tab @samp{-}
41265@tab No
41266
03583c20
UW
41267@item @samp{QDisableRandomization}
41268@tab No
41269@tab @samp{-}
41270@tab No
41271
d248b706
KY
41272@item @samp{EnableDisableTracepoints}
41273@tab No
41274@tab @samp{-}
41275@tab No
41276
f6f899bf
HAQ
41277@item @samp{QTBuffer:size}
41278@tab No
41279@tab @samp{-}
41280@tab No
41281
3065dfb6
SS
41282@item @samp{tracenz}
41283@tab No
41284@tab @samp{-}
41285@tab No
41286
d3ce09f5
SS
41287@item @samp{BreakpointCommands}
41288@tab No
41289@tab @samp{-}
41290@tab No
41291
f7e6eed5
PA
41292@item @samp{swbreak}
41293@tab No
41294@tab @samp{-}
41295@tab No
41296
41297@item @samp{hwbreak}
41298@tab No
41299@tab @samp{-}
41300@tab No
41301
0d71eef5
DB
41302@item @samp{fork-events}
41303@tab No
41304@tab @samp{-}
41305@tab No
41306
41307@item @samp{vfork-events}
41308@tab No
41309@tab @samp{-}
41310@tab No
41311
b459a59b
DB
41312@item @samp{exec-events}
41313@tab No
41314@tab @samp{-}
41315@tab No
41316
65706a29
PA
41317@item @samp{QThreadEvents}
41318@tab No
41319@tab @samp{-}
41320@tab No
41321
f2faf941
PA
41322@item @samp{no-resumed}
41323@tab No
41324@tab @samp{-}
41325@tab No
41326
be2a5f71
DJ
41327@end multitable
41328
41329These are the currently defined stub features, in more detail:
41330
41331@table @samp
41332@cindex packet size, remote protocol
41333@item PacketSize=@var{bytes}
41334The remote stub can accept packets up to at least @var{bytes} in
41335length. @value{GDBN} will send packets up to this size for bulk
41336transfers, and will never send larger packets. This is a limit on the
41337data characters in the packet, including the frame and checksum.
41338There is no trailing NUL byte in a remote protocol packet; if the stub
41339stores packets in a NUL-terminated format, it should allow an extra
41340byte in its buffer for the NUL. If this stub feature is not supported,
41341@value{GDBN} guesses based on the size of the @samp{g} packet response.
41342
0876f84a
DJ
41343@item qXfer:auxv:read
41344The remote stub understands the @samp{qXfer:auxv:read} packet
41345(@pxref{qXfer auxiliary vector read}).
41346
2ae8c8e7
MM
41347@item qXfer:btrace:read
41348The remote stub understands the @samp{qXfer:btrace:read}
41349packet (@pxref{qXfer btrace read}).
41350
f4abbc16
MM
41351@item qXfer:btrace-conf:read
41352The remote stub understands the @samp{qXfer:btrace-conf:read}
41353packet (@pxref{qXfer btrace-conf read}).
41354
c78fa86a
GB
41355@item qXfer:exec-file:read
41356The remote stub understands the @samp{qXfer:exec-file:read} packet
41357(@pxref{qXfer executable filename read}).
41358
23181151
DJ
41359@item qXfer:features:read
41360The remote stub understands the @samp{qXfer:features:read} packet
41361(@pxref{qXfer target description read}).
41362
cfa9d6d9
DJ
41363@item qXfer:libraries:read
41364The remote stub understands the @samp{qXfer:libraries:read} packet
41365(@pxref{qXfer library list read}).
41366
2268b414
JK
41367@item qXfer:libraries-svr4:read
41368The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
41369(@pxref{qXfer svr4 library list read}).
41370
85dc5a12
GB
41371@item augmented-libraries-svr4-read
41372The remote stub understands the augmented form of the
41373@samp{qXfer:libraries-svr4:read} packet
41374(@pxref{qXfer svr4 library list read}).
41375
23181151
DJ
41376@item qXfer:memory-map:read
41377The remote stub understands the @samp{qXfer:memory-map:read} packet
41378(@pxref{qXfer memory map read}).
41379
0fb4aa4b
PA
41380@item qXfer:sdata:read
41381The remote stub understands the @samp{qXfer:sdata:read} packet
41382(@pxref{qXfer sdata read}).
41383
4aa995e1
PA
41384@item qXfer:siginfo:read
41385The remote stub understands the @samp{qXfer:siginfo:read} packet
41386(@pxref{qXfer siginfo read}).
41387
41388@item qXfer:siginfo:write
41389The remote stub understands the @samp{qXfer:siginfo:write} packet
41390(@pxref{qXfer siginfo write}).
41391
dc146f7c
VP
41392@item qXfer:threads:read
41393The remote stub understands the @samp{qXfer:threads:read} packet
41394(@pxref{qXfer threads read}).
41395
b3b9301e
PA
41396@item qXfer:traceframe-info:read
41397The remote stub understands the @samp{qXfer:traceframe-info:read}
41398packet (@pxref{qXfer traceframe info read}).
41399
169081d0
TG
41400@item qXfer:uib:read
41401The remote stub understands the @samp{qXfer:uib:read}
41402packet (@pxref{qXfer unwind info block}).
41403
78d85199
YQ
41404@item qXfer:fdpic:read
41405The remote stub understands the @samp{qXfer:fdpic:read}
41406packet (@pxref{qXfer fdpic loadmap read}).
41407
8b23ecc4
SL
41408@item QNonStop
41409The remote stub understands the @samp{QNonStop} packet
41410(@pxref{QNonStop}).
41411
82075af2
JS
41412@item QCatchSyscalls
41413The remote stub understands the @samp{QCatchSyscalls} packet
41414(@pxref{QCatchSyscalls}).
41415
23181151
DJ
41416@item QPassSignals
41417The remote stub understands the @samp{QPassSignals} packet
41418(@pxref{QPassSignals}).
41419
a6f3e723
SL
41420@item QStartNoAckMode
41421The remote stub understands the @samp{QStartNoAckMode} packet and
41422prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
41423
b90a069a
SL
41424@item multiprocess
41425@anchor{multiprocess extensions}
41426@cindex multiprocess extensions, in remote protocol
41427The remote stub understands the multiprocess extensions to the remote
41428protocol syntax. The multiprocess extensions affect the syntax of
41429thread IDs in both packets and replies (@pxref{thread-id syntax}), and
41430add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
41431replies. Note that reporting this feature indicates support for the
41432syntactic extensions only, not that the stub necessarily supports
41433debugging of more than one process at a time. The stub must not use
41434multiprocess extensions in packet replies unless @value{GDBN} has also
41435indicated it supports them in its @samp{qSupported} request.
41436
07e059b5
VP
41437@item qXfer:osdata:read
41438The remote stub understands the @samp{qXfer:osdata:read} packet
41439((@pxref{qXfer osdata read}).
41440
83364271
LM
41441@item ConditionalBreakpoints
41442The target accepts and implements evaluation of conditional expressions
41443defined for breakpoints. The target will only report breakpoint triggers
41444when such conditions are true (@pxref{Conditions, ,Break Conditions}).
41445
782b2b07
SS
41446@item ConditionalTracepoints
41447The remote stub accepts and implements conditional expressions defined
41448for tracepoints (@pxref{Tracepoint Conditions}).
41449
0d772ac9
MS
41450@item ReverseContinue
41451The remote stub accepts and implements the reverse continue packet
41452(@pxref{bc}).
41453
41454@item ReverseStep
41455The remote stub accepts and implements the reverse step packet
41456(@pxref{bs}).
41457
409873ef
SS
41458@item TracepointSource
41459The remote stub understands the @samp{QTDPsrc} packet that supplies
41460the source form of tracepoint definitions.
41461
d1feda86
YQ
41462@item QAgent
41463The remote stub understands the @samp{QAgent} packet.
41464
d914c394
SS
41465@item QAllow
41466The remote stub understands the @samp{QAllow} packet.
41467
03583c20
UW
41468@item QDisableRandomization
41469The remote stub understands the @samp{QDisableRandomization} packet.
41470
0fb4aa4b
PA
41471@item StaticTracepoint
41472@cindex static tracepoints, in remote protocol
41473The remote stub supports static tracepoints.
41474
1e4d1764
YQ
41475@item InstallInTrace
41476@anchor{install tracepoint in tracing}
41477The remote stub supports installing tracepoint in tracing.
41478
d248b706
KY
41479@item EnableDisableTracepoints
41480The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
41481@samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
41482to be enabled and disabled while a trace experiment is running.
41483
f6f899bf 41484@item QTBuffer:size
28abe188 41485The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
f6f899bf
HAQ
41486packet that allows to change the size of the trace buffer.
41487
3065dfb6
SS
41488@item tracenz
41489@cindex string tracing, in remote protocol
41490The remote stub supports the @samp{tracenz} bytecode for collecting strings.
41491See @ref{Bytecode Descriptions} for details about the bytecode.
41492
d3ce09f5
SS
41493@item BreakpointCommands
41494@cindex breakpoint commands, in remote protocol
41495The remote stub supports running a breakpoint's command list itself,
41496rather than reporting the hit to @value{GDBN}.
41497
2ae8c8e7
MM
41498@item Qbtrace:off
41499The remote stub understands the @samp{Qbtrace:off} packet.
41500
41501@item Qbtrace:bts
41502The remote stub understands the @samp{Qbtrace:bts} packet.
41503
b20a6524
MM
41504@item Qbtrace:pt
41505The remote stub understands the @samp{Qbtrace:pt} packet.
41506
d33501a5
MM
41507@item Qbtrace-conf:bts:size
41508The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
41509
b20a6524
MM
41510@item Qbtrace-conf:pt:size
41511The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
41512
f7e6eed5
PA
41513@item swbreak
41514The remote stub reports the @samp{swbreak} stop reason for memory
41515breakpoints.
41516
41517@item hwbreak
41518The remote stub reports the @samp{hwbreak} stop reason for hardware
41519breakpoints.
41520
0d71eef5
DB
41521@item fork-events
41522The remote stub reports the @samp{fork} stop reason for fork events.
41523
41524@item vfork-events
41525The remote stub reports the @samp{vfork} stop reason for vfork events
41526and vforkdone events.
41527
b459a59b
DB
41528@item exec-events
41529The remote stub reports the @samp{exec} stop reason for exec events.
41530
750ce8d1
YQ
41531@item vContSupported
41532The remote stub reports the supported actions in the reply to
41533@samp{vCont?} packet.
41534
65706a29
PA
41535@item QThreadEvents
41536The remote stub understands the @samp{QThreadEvents} packet.
41537
f2faf941
PA
41538@item no-resumed
41539The remote stub reports the @samp{N} stop reply.
41540
be2a5f71
DJ
41541@end table
41542
b8ff78ce 41543@item qSymbol::
ff2587ec 41544@cindex symbol lookup, remote request
b8ff78ce 41545@cindex @samp{qSymbol} packet
ff2587ec
WZ
41546Notify the target that @value{GDBN} is prepared to serve symbol lookup
41547requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
41548
41549Reply:
ff2587ec 41550@table @samp
b8ff78ce 41551@item OK
ff2587ec 41552The target does not need to look up any (more) symbols.
b8ff78ce 41553@item qSymbol:@var{sym_name}
ff2587ec
WZ
41554The target requests the value of symbol @var{sym_name} (hex encoded).
41555@value{GDBN} may provide the value by using the
b8ff78ce
JB
41556@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
41557below.
ff2587ec 41558@end table
83761cbd 41559
b8ff78ce 41560@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
41561Set the value of @var{sym_name} to @var{sym_value}.
41562
41563@var{sym_name} (hex encoded) is the name of a symbol whose value the
41564target has previously requested.
41565
41566@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
41567@value{GDBN} cannot supply a value for @var{sym_name}, then this field
41568will be empty.
41569
41570Reply:
41571@table @samp
b8ff78ce 41572@item OK
ff2587ec 41573The target does not need to look up any (more) symbols.
b8ff78ce 41574@item qSymbol:@var{sym_name}
ff2587ec
WZ
41575The target requests the value of a new symbol @var{sym_name} (hex
41576encoded). @value{GDBN} will continue to supply the values of symbols
41577(if available), until the target ceases to request them.
fa93a9d8 41578@end table
0abb7bc7 41579
00bf0b85 41580@item qTBuffer
687e43a4
TT
41581@itemx QTBuffer
41582@itemx QTDisconnected
d5551862 41583@itemx QTDP
409873ef 41584@itemx QTDPsrc
d5551862 41585@itemx QTDV
00bf0b85
SS
41586@itemx qTfP
41587@itemx qTfV
9d29849a 41588@itemx QTFrame
405f8e94
SS
41589@itemx qTMinFTPILen
41590
9d29849a
JB
41591@xref{Tracepoint Packets}.
41592
b90a069a 41593@item qThreadExtraInfo,@var{thread-id}
ff2587ec 41594@cindex thread attributes info, remote request
b8ff78ce 41595@cindex @samp{qThreadExtraInfo} packet
697aa1b7
EZ
41596Obtain from the target OS a printable string description of thread
41597attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
41598for the forms of @var{thread-id}. This
b8ff78ce
JB
41599string may contain anything that the target OS thinks is interesting
41600for @value{GDBN} to tell the user about the thread. The string is
41601displayed in @value{GDBN}'s @code{info threads} display. Some
41602examples of possible thread extra info strings are @samp{Runnable}, or
41603@samp{Blocked on Mutex}.
ff2587ec
WZ
41604
41605Reply:
41606@table @samp
b8ff78ce
JB
41607@item @var{XX}@dots{}
41608Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
41609comprising the printable string containing the extra information about
41610the thread's attributes.
ff2587ec 41611@end table
814e32d7 41612
aa56d27a
JB
41613(Note that the @code{qThreadExtraInfo} packet's name is separated from
41614the command by a @samp{,}, not a @samp{:}, contrary to the naming
41615conventions above. Please don't use this packet as a model for new
41616packets.)
41617
f196051f 41618@item QTNotes
687e43a4
TT
41619@itemx qTP
41620@itemx QTSave
41621@itemx qTsP
41622@itemx qTsV
d5551862 41623@itemx QTStart
9d29849a 41624@itemx QTStop
d248b706
KY
41625@itemx QTEnable
41626@itemx QTDisable
9d29849a
JB
41627@itemx QTinit
41628@itemx QTro
41629@itemx qTStatus
d5551862 41630@itemx qTV
0fb4aa4b
PA
41631@itemx qTfSTM
41632@itemx qTsSTM
41633@itemx qTSTMat
9d29849a
JB
41634@xref{Tracepoint Packets}.
41635
0876f84a
DJ
41636@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
41637@cindex read special object, remote request
41638@cindex @samp{qXfer} packet
68437a39 41639@anchor{qXfer read}
0876f84a
DJ
41640Read uninterpreted bytes from the target's special data area
41641identified by the keyword @var{object}. Request @var{length} bytes
41642starting at @var{offset} bytes into the data. The content and
0e7f50da 41643encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
41644additional details about what data to access.
41645
c185ba27
EZ
41646Reply:
41647@table @samp
41648@item m @var{data}
41649Data @var{data} (@pxref{Binary Data}) has been read from the
41650target. There may be more data at a higher address (although
41651it is permitted to return @samp{m} even for the last valid
41652block of data, as long as at least one byte of data was read).
41653It is possible for @var{data} to have fewer bytes than the @var{length} in the
41654request.
41655
41656@item l @var{data}
41657Data @var{data} (@pxref{Binary Data}) has been read from the target.
41658There is no more data to be read. It is possible for @var{data} to
41659have fewer bytes than the @var{length} in the request.
41660
41661@item l
41662The @var{offset} in the request is at the end of the data.
41663There is no more data to be read.
41664
41665@item E00
41666The request was malformed, or @var{annex} was invalid.
41667
41668@item E @var{nn}
41669The offset was invalid, or there was an error encountered reading the data.
41670The @var{nn} part is a hex-encoded @code{errno} value.
41671
41672@item @w{}
41673An empty reply indicates the @var{object} string was not recognized by
41674the stub, or that the object does not support reading.
41675@end table
41676
41677Here are the specific requests of this form defined so far. All the
0876f84a 41678@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
c185ba27 41679formats, listed above.
0876f84a
DJ
41680
41681@table @samp
41682@item qXfer:auxv:read::@var{offset},@var{length}
41683@anchor{qXfer auxiliary vector read}
41684Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 41685auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
41686
41687This packet is not probed by default; the remote stub must request it,
89be2091 41688by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 41689
2ae8c8e7
MM
41690@item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
41691@anchor{qXfer btrace read}
41692
41693Return a description of the current branch trace.
41694@xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
41695packet may have one of the following values:
41696
41697@table @code
41698@item all
41699Returns all available branch trace.
41700
41701@item new
41702Returns all available branch trace if the branch trace changed since
41703the last read request.
969c39fb
MM
41704
41705@item delta
41706Returns the new branch trace since the last read request. Adds a new
41707block to the end of the trace that begins at zero and ends at the source
41708location of the first branch in the trace buffer. This extra block is
41709used to stitch traces together.
41710
41711If the trace buffer overflowed, returns an error indicating the overflow.
2ae8c8e7
MM
41712@end table
41713
41714This packet is not probed by default; the remote stub must request it
41715by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41716
f4abbc16
MM
41717@item qXfer:btrace-conf:read::@var{offset},@var{length}
41718@anchor{qXfer btrace-conf read}
41719
41720Return a description of the current branch trace configuration.
41721@xref{Branch Trace Configuration Format}.
41722
41723This packet is not probed by default; the remote stub must request it
41724by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
c78fa86a
GB
41725
41726@item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
41727@anchor{qXfer executable filename read}
41728Return the full absolute name of the file that was executed to create
41729a process running on the remote system. The annex specifies the
41730numeric process ID of the process to query, encoded as a hexadecimal
835205d0
GB
41731number. If the annex part is empty the remote stub should return the
41732filename corresponding to the currently executing process.
c78fa86a
GB
41733
41734This packet is not probed by default; the remote stub must request it,
41735by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
f4abbc16 41736
23181151
DJ
41737@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
41738@anchor{qXfer target description read}
41739Access the @dfn{target description}. @xref{Target Descriptions}. The
41740annex specifies which XML document to access. The main description is
41741always loaded from the @samp{target.xml} annex.
41742
41743This packet is not probed by default; the remote stub must request it,
41744by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41745
cfa9d6d9
DJ
41746@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
41747@anchor{qXfer library list read}
41748Access the target's list of loaded libraries. @xref{Library List Format}.
41749The annex part of the generic @samp{qXfer} packet must be empty
41750(@pxref{qXfer read}).
41751
41752Targets which maintain a list of libraries in the program's memory do
41753not need to implement this packet; it is designed for platforms where
41754the operating system manages the list of loaded libraries.
41755
41756This packet is not probed by default; the remote stub must request it,
41757by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41758
2268b414
JK
41759@item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
41760@anchor{qXfer svr4 library list read}
41761Access the target's list of loaded libraries when the target is an SVR4
41762platform. @xref{Library List Format for SVR4 Targets}. The annex part
85dc5a12
GB
41763of the generic @samp{qXfer} packet must be empty unless the remote
41764stub indicated it supports the augmented form of this packet
41765by supplying an appropriate @samp{qSupported} response
41766(@pxref{qXfer read}, @ref{qSupported}).
2268b414
JK
41767
41768This packet is optional for better performance on SVR4 targets.
41769@value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
41770
41771This packet is not probed by default; the remote stub must request it,
41772by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41773
85dc5a12
GB
41774If the remote stub indicates it supports the augmented form of this
41775packet then the annex part of the generic @samp{qXfer} packet may
41776contain a semicolon-separated list of @samp{@var{name}=@var{value}}
41777arguments. The currently supported arguments are:
41778
41779@table @code
41780@item start=@var{address}
41781A hexadecimal number specifying the address of the @samp{struct
41782link_map} to start reading the library list from. If unset or zero
41783then the first @samp{struct link_map} in the library list will be
41784chosen as the starting point.
41785
41786@item prev=@var{address}
41787A hexadecimal number specifying the address of the @samp{struct
41788link_map} immediately preceding the @samp{struct link_map}
41789specified by the @samp{start} argument. If unset or zero then
41790the remote stub will expect that no @samp{struct link_map}
41791exists prior to the starting point.
41792
41793@end table
41794
41795Arguments that are not understood by the remote stub will be silently
41796ignored.
41797
68437a39
DJ
41798@item qXfer:memory-map:read::@var{offset},@var{length}
41799@anchor{qXfer memory map read}
79a6e687 41800Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
41801annex part of the generic @samp{qXfer} packet must be empty
41802(@pxref{qXfer read}).
41803
0e7f50da
UW
41804This packet is not probed by default; the remote stub must request it,
41805by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41806
0fb4aa4b
PA
41807@item qXfer:sdata:read::@var{offset},@var{length}
41808@anchor{qXfer sdata read}
41809
41810Read contents of the extra collected static tracepoint marker
41811information. The annex part of the generic @samp{qXfer} packet must
41812be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
41813Action Lists}.
41814
41815This packet is not probed by default; the remote stub must request it,
41816by supplying an appropriate @samp{qSupported} response
41817(@pxref{qSupported}).
41818
4aa995e1
PA
41819@item qXfer:siginfo:read::@var{offset},@var{length}
41820@anchor{qXfer siginfo read}
41821Read contents of the extra signal information on the target
41822system. The annex part of the generic @samp{qXfer} packet must be
41823empty (@pxref{qXfer read}).
41824
41825This packet is not probed by default; the remote stub must request it,
41826by supplying an appropriate @samp{qSupported} response
41827(@pxref{qSupported}).
41828
dc146f7c
VP
41829@item qXfer:threads:read::@var{offset},@var{length}
41830@anchor{qXfer threads read}
41831Access the list of threads on target. @xref{Thread List Format}. The
41832annex part of the generic @samp{qXfer} packet must be empty
41833(@pxref{qXfer read}).
41834
41835This packet is not probed by default; the remote stub must request it,
41836by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41837
b3b9301e
PA
41838@item qXfer:traceframe-info:read::@var{offset},@var{length}
41839@anchor{qXfer traceframe info read}
41840
41841Return a description of the current traceframe's contents.
41842@xref{Traceframe Info Format}. The annex part of the generic
41843@samp{qXfer} packet must be empty (@pxref{qXfer read}).
41844
41845This packet is not probed by default; the remote stub must request it,
41846by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41847
169081d0
TG
41848@item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
41849@anchor{qXfer unwind info block}
41850
41851Return the unwind information block for @var{pc}. This packet is used
41852on OpenVMS/ia64 to ask the kernel unwind information.
41853
41854This packet is not probed by default.
41855
78d85199
YQ
41856@item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
41857@anchor{qXfer fdpic loadmap read}
41858Read contents of @code{loadmap}s on the target system. The
41859annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
41860executable @code{loadmap} or interpreter @code{loadmap} to read.
41861
41862This packet is not probed by default; the remote stub must request it,
41863by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41864
07e059b5
VP
41865@item qXfer:osdata:read::@var{offset},@var{length}
41866@anchor{qXfer osdata read}
697aa1b7 41867Access the target's @dfn{operating system information}.
07e059b5
VP
41868@xref{Operating System Information}.
41869
68437a39
DJ
41870@end table
41871
c185ba27
EZ
41872@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
41873@cindex write data into object, remote request
41874@anchor{qXfer write}
41875Write uninterpreted bytes into the target's special data area
41876identified by the keyword @var{object}, starting at @var{offset} bytes
41877into the data. The binary-encoded data (@pxref{Binary Data}) to be
41878written is given by @var{data}@dots{}. The content and encoding of @var{annex}
41879is specific to @var{object}; it can supply additional details about what data
41880to access.
41881
0876f84a
DJ
41882Reply:
41883@table @samp
c185ba27
EZ
41884@item @var{nn}
41885@var{nn} (hex encoded) is the number of bytes written.
41886This may be fewer bytes than supplied in the request.
0876f84a
DJ
41887
41888@item E00
41889The request was malformed, or @var{annex} was invalid.
41890
41891@item E @var{nn}
c185ba27 41892The offset was invalid, or there was an error encountered writing the data.
697aa1b7 41893The @var{nn} part is a hex-encoded @code{errno} value.
0876f84a 41894
d57350ea 41895@item @w{}
c185ba27
EZ
41896An empty reply indicates the @var{object} string was not
41897recognized by the stub, or that the object does not support writing.
0876f84a
DJ
41898@end table
41899
c185ba27 41900Here are the specific requests of this form defined so far. All the
0e7f50da 41901@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
c185ba27 41902formats, listed above.
0e7f50da
UW
41903
41904@table @samp
4aa995e1
PA
41905@item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
41906@anchor{qXfer siginfo write}
41907Write @var{data} to the extra signal information on the target system.
41908The annex part of the generic @samp{qXfer} packet must be
41909empty (@pxref{qXfer write}).
41910
41911This packet is not probed by default; the remote stub must request it,
41912by supplying an appropriate @samp{qSupported} response
41913(@pxref{qSupported}).
0e7f50da 41914@end table
0876f84a 41915
0876f84a
DJ
41916@item qXfer:@var{object}:@var{operation}:@dots{}
41917Requests of this form may be added in the future. When a stub does
41918not recognize the @var{object} keyword, or its support for
41919@var{object} does not recognize the @var{operation} keyword, the stub
41920must respond with an empty packet.
41921
0b16c5cf
PA
41922@item qAttached:@var{pid}
41923@cindex query attached, remote request
41924@cindex @samp{qAttached} packet
41925Return an indication of whether the remote server attached to an
41926existing process or created a new process. When the multiprocess
41927protocol extensions are supported (@pxref{multiprocess extensions}),
41928@var{pid} is an integer in hexadecimal format identifying the target
41929process. Otherwise, @value{GDBN} will omit the @var{pid} field and
41930the query packet will be simplified as @samp{qAttached}.
41931
41932This query is used, for example, to know whether the remote process
41933should be detached or killed when a @value{GDBN} session is ended with
41934the @code{quit} command.
41935
41936Reply:
41937@table @samp
41938@item 1
41939The remote server attached to an existing process.
41940@item 0
41941The remote server created a new process.
41942@item E @var{NN}
41943A badly formed request or an error was encountered.
41944@end table
41945
2ae8c8e7 41946@item Qbtrace:bts
b20a6524
MM
41947Enable branch tracing for the current thread using Branch Trace Store.
41948
41949Reply:
41950@table @samp
41951@item OK
41952Branch tracing has been enabled.
41953@item E.errtext
41954A badly formed request or an error was encountered.
41955@end table
41956
41957@item Qbtrace:pt
bc504a31 41958Enable branch tracing for the current thread using Intel Processor Trace.
2ae8c8e7
MM
41959
41960Reply:
41961@table @samp
41962@item OK
41963Branch tracing has been enabled.
41964@item E.errtext
41965A badly formed request or an error was encountered.
41966@end table
41967
41968@item Qbtrace:off
41969Disable branch tracing for the current thread.
41970
41971Reply:
41972@table @samp
41973@item OK
41974Branch tracing has been disabled.
41975@item E.errtext
41976A badly formed request or an error was encountered.
41977@end table
41978
d33501a5
MM
41979@item Qbtrace-conf:bts:size=@var{value}
41980Set the requested ring buffer size for new threads that use the
41981btrace recording method in bts format.
41982
41983Reply:
41984@table @samp
41985@item OK
41986The ring buffer size has been set.
41987@item E.errtext
41988A badly formed request or an error was encountered.
41989@end table
41990
b20a6524
MM
41991@item Qbtrace-conf:pt:size=@var{value}
41992Set the requested ring buffer size for new threads that use the
41993btrace recording method in pt format.
41994
41995Reply:
41996@table @samp
41997@item OK
41998The ring buffer size has been set.
41999@item E.errtext
42000A badly formed request or an error was encountered.
42001@end table
42002
ee2d5c50
AC
42003@end table
42004
a1dcb23a
DJ
42005@node Architecture-Specific Protocol Details
42006@section Architecture-Specific Protocol Details
42007
42008This section describes how the remote protocol is applied to specific
42009target architectures. Also see @ref{Standard Target Features}, for
42010details of XML target descriptions for each architecture.
42011
02b67415
MR
42012@menu
42013* ARM-Specific Protocol Details::
42014* MIPS-Specific Protocol Details::
42015@end menu
42016
42017@node ARM-Specific Protocol Details
42018@subsection @acronym{ARM}-specific Protocol Details
42019
42020@menu
42021* ARM Breakpoint Kinds::
42022@end menu
a1dcb23a 42023
02b67415
MR
42024@node ARM Breakpoint Kinds
42025@subsubsection @acronym{ARM} Breakpoint Kinds
42026@cindex breakpoint kinds, @acronym{ARM}
a1dcb23a
DJ
42027
42028These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42029
42030@table @r
42031
42032@item 2
4203316-bit Thumb mode breakpoint.
42034
42035@item 3
4203632-bit Thumb mode (Thumb-2) breakpoint.
42037
42038@item 4
02b67415 4203932-bit @acronym{ARM} mode breakpoint.
a1dcb23a
DJ
42040
42041@end table
42042
02b67415
MR
42043@node MIPS-Specific Protocol Details
42044@subsection @acronym{MIPS}-specific Protocol Details
42045
42046@menu
42047* MIPS Register packet Format::
4cc0665f 42048* MIPS Breakpoint Kinds::
02b67415 42049@end menu
a1dcb23a 42050
02b67415
MR
42051@node MIPS Register packet Format
42052@subsubsection @acronym{MIPS} Register Packet Format
eb17f351 42053@cindex register packet format, @acronym{MIPS}
eb12ee30 42054
b8ff78ce 42055The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
42056In the below, some thirty-two bit registers are transferred as
42057sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
42058to fill the space allocated. Register bytes are transferred in target
42059byte order. The two nibbles within a register byte are transferred
02b67415 42060most-significant -- least-significant.
eb12ee30 42061
ee2d5c50 42062@table @r
eb12ee30 42063
8e04817f 42064@item MIPS32
599b237a 42065All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
4206632 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
42067registers; fsr; fir; fp.
eb12ee30 42068
8e04817f 42069@item MIPS64
599b237a 42070All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
42071thirty-two bit registers such as @code{sr}). The ordering is the same
42072as @code{MIPS32}.
eb12ee30 42073
ee2d5c50
AC
42074@end table
42075
4cc0665f
MR
42076@node MIPS Breakpoint Kinds
42077@subsubsection @acronym{MIPS} Breakpoint Kinds
42078@cindex breakpoint kinds, @acronym{MIPS}
42079
42080These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42081
42082@table @r
42083
42084@item 2
4208516-bit @acronym{MIPS16} mode breakpoint.
42086
42087@item 3
4208816-bit @acronym{microMIPS} mode breakpoint.
42089
42090@item 4
4209132-bit standard @acronym{MIPS} mode breakpoint.
42092
42093@item 5
4209432-bit @acronym{microMIPS} mode breakpoint.
42095
42096@end table
42097
9d29849a
JB
42098@node Tracepoint Packets
42099@section Tracepoint Packets
42100@cindex tracepoint packets
42101@cindex packets, tracepoint
42102
42103Here we describe the packets @value{GDBN} uses to implement
42104tracepoints (@pxref{Tracepoints}).
42105
42106@table @samp
42107
7a697b8d 42108@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
c614397c 42109@cindex @samp{QTDP} packet
9d29849a
JB
42110Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
42111is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
697aa1b7
EZ
42112the tracepoint is disabled. The @var{step} gives the tracepoint's step
42113count, and @var{pass} gives its pass count. If an @samp{F} is present,
7a697b8d
SS
42114then the tracepoint is to be a fast tracepoint, and the @var{flen} is
42115the number of bytes that the target should copy elsewhere to make room
42116for the tracepoint. If an @samp{X} is present, it introduces a
42117tracepoint condition, which consists of a hexadecimal length, followed
42118by a comma and hex-encoded bytes, in a manner similar to action
42119encodings as described below. If the trailing @samp{-} is present,
42120further @samp{QTDP} packets will follow to specify this tracepoint's
42121actions.
9d29849a
JB
42122
42123Replies:
42124@table @samp
42125@item OK
42126The packet was understood and carried out.
dde08ee1
PA
42127@item qRelocInsn
42128@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 42129@item @w{}
9d29849a
JB
42130The packet was not recognized.
42131@end table
42132
42133@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
697aa1b7 42134Define actions to be taken when a tracepoint is hit. The @var{n} and
9d29849a
JB
42135@var{addr} must be the same as in the initial @samp{QTDP} packet for
42136this tracepoint. This packet may only be sent immediately after
42137another @samp{QTDP} packet that ended with a @samp{-}. If the
42138trailing @samp{-} is present, further @samp{QTDP} packets will follow,
42139specifying more actions for this tracepoint.
42140
42141In the series of action packets for a given tracepoint, at most one
42142can have an @samp{S} before its first @var{action}. If such a packet
42143is sent, it and the following packets define ``while-stepping''
42144actions. Any prior packets define ordinary actions --- that is, those
42145taken when the tracepoint is first hit. If no action packet has an
42146@samp{S}, then all the packets in the series specify ordinary
42147tracepoint actions.
42148
42149The @samp{@var{action}@dots{}} portion of the packet is a series of
42150actions, concatenated without separators. Each action has one of the
42151following forms:
42152
42153@table @samp
42154
42155@item R @var{mask}
697aa1b7 42156Collect the registers whose bits are set in @var{mask},
599b237a 42157a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
42158@var{i} should be collected. (The least significant bit is numbered
42159zero.) Note that @var{mask} may be any number of digits long; it may
42160not fit in a 32-bit word.
42161
42162@item M @var{basereg},@var{offset},@var{len}
42163Collect @var{len} bytes of memory starting at the address in register
42164number @var{basereg}, plus @var{offset}. If @var{basereg} is
42165@samp{-1}, then the range has a fixed address: @var{offset} is the
42166address of the lowest byte to collect. The @var{basereg},
599b237a 42167@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
42168values (the @samp{-1} value for @var{basereg} is a special case).
42169
42170@item X @var{len},@var{expr}
42171Evaluate @var{expr}, whose length is @var{len}, and collect memory as
697aa1b7 42172it directs. The agent expression @var{expr} is as described in
9d29849a
JB
42173@ref{Agent Expressions}. Each byte of the expression is encoded as a
42174two-digit hex number in the packet; @var{len} is the number of bytes
42175in the expression (and thus one-half the number of hex digits in the
42176packet).
42177
42178@end table
42179
42180Any number of actions may be packed together in a single @samp{QTDP}
42181packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
42182length (400 bytes, for many stubs). There may be only one @samp{R}
42183action per tracepoint, and it must precede any @samp{M} or @samp{X}
42184actions. Any registers referred to by @samp{M} and @samp{X} actions
42185must be collected by a preceding @samp{R} action. (The
42186``while-stepping'' actions are treated as if they were attached to a
42187separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
42188
42189Replies:
42190@table @samp
42191@item OK
42192The packet was understood and carried out.
dde08ee1
PA
42193@item qRelocInsn
42194@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 42195@item @w{}
9d29849a
JB
42196The packet was not recognized.
42197@end table
42198
409873ef
SS
42199@item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
42200@cindex @samp{QTDPsrc} packet
42201Specify a source string of tracepoint @var{n} at address @var{addr}.
42202This is useful to get accurate reproduction of the tracepoints
697aa1b7 42203originally downloaded at the beginning of the trace run. The @var{type}
409873ef
SS
42204is the name of the tracepoint part, such as @samp{cond} for the
42205tracepoint's conditional expression (see below for a list of types), while
42206@var{bytes} is the string, encoded in hexadecimal.
42207
42208@var{start} is the offset of the @var{bytes} within the overall source
42209string, while @var{slen} is the total length of the source string.
42210This is intended for handling source strings that are longer than will
42211fit in a single packet.
42212@c Add detailed example when this info is moved into a dedicated
42213@c tracepoint descriptions section.
42214
42215The available string types are @samp{at} for the location,
42216@samp{cond} for the conditional, and @samp{cmd} for an action command.
42217@value{GDBN} sends a separate packet for each command in the action
42218list, in the same order in which the commands are stored in the list.
42219
42220The target does not need to do anything with source strings except
42221report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
42222query packets.
42223
42224Although this packet is optional, and @value{GDBN} will only send it
42225if the target replies with @samp{TracepointSource} @xref{General
42226Query Packets}, it makes both disconnected tracing and trace files
42227much easier to use. Otherwise the user must be careful that the
42228tracepoints in effect while looking at trace frames are identical to
42229the ones in effect during the trace run; even a small discrepancy
42230could cause @samp{tdump} not to work, or a particular trace frame not
42231be found.
42232
fa3f8d5a 42233@item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
f61e138d
SS
42234@cindex define trace state variable, remote request
42235@cindex @samp{QTDV} packet
42236Create a new trace state variable, number @var{n}, with an initial
42237value of @var{value}, which is a 64-bit signed integer. Both @var{n}
42238and @var{value} are encoded as hexadecimal values. @value{GDBN} has
42239the option of not using this packet for initial values of zero; the
42240target should simply create the trace state variables as they are
fa3f8d5a
DT
42241mentioned in expressions. The value @var{builtin} should be 1 (one)
42242if the trace state variable is builtin and 0 (zero) if it is not builtin.
42243@value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
42244@samp{qTsV} packet had it set. The contents of @var{name} is the
42245hex-encoded name (without the leading @samp{$}) of the trace state
42246variable.
f61e138d 42247
9d29849a 42248@item QTFrame:@var{n}
c614397c 42249@cindex @samp{QTFrame} packet
9d29849a
JB
42250Select the @var{n}'th tracepoint frame from the buffer, and use the
42251register and memory contents recorded there to answer subsequent
42252request packets from @value{GDBN}.
42253
42254A successful reply from the stub indicates that the stub has found the
42255requested frame. The response is a series of parts, concatenated
42256without separators, describing the frame we selected. Each part has
42257one of the following forms:
42258
42259@table @samp
42260@item F @var{f}
42261The selected frame is number @var{n} in the trace frame buffer;
599b237a 42262@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
42263was no frame matching the criteria in the request packet.
42264
42265@item T @var{t}
42266The selected trace frame records a hit of tracepoint number @var{t};
599b237a 42267@var{t} is a hexadecimal number.
9d29849a
JB
42268
42269@end table
42270
42271@item QTFrame:pc:@var{addr}
42272Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42273currently selected frame whose PC is @var{addr};
599b237a 42274@var{addr} is a hexadecimal number.
9d29849a
JB
42275
42276@item QTFrame:tdp:@var{t}
42277Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42278currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 42279is a hexadecimal number.
9d29849a
JB
42280
42281@item QTFrame:range:@var{start}:@var{end}
42282Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42283currently selected frame whose PC is between @var{start} (inclusive)
081dfbf7 42284and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
42285numbers.
42286
42287@item QTFrame:outside:@var{start}:@var{end}
42288Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
081dfbf7 42289frame @emph{outside} the given range of addresses (exclusive).
9d29849a 42290
405f8e94 42291@item qTMinFTPILen
c614397c 42292@cindex @samp{qTMinFTPILen} packet
405f8e94
SS
42293This packet requests the minimum length of instruction at which a fast
42294tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
42295the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
42296it depends on the target system being able to create trampolines in
42297the first 64K of memory, which might or might not be possible for that
42298system. So the reply to this packet will be 4 if it is able to
42299arrange for that.
42300
42301Replies:
42302
42303@table @samp
42304@item 0
42305The minimum instruction length is currently unknown.
42306@item @var{length}
697aa1b7
EZ
42307The minimum instruction length is @var{length}, where @var{length}
42308is a hexadecimal number greater or equal to 1. A reply
42309of 1 means that a fast tracepoint may be placed on any instruction
42310regardless of size.
405f8e94
SS
42311@item E
42312An error has occurred.
d57350ea 42313@item @w{}
405f8e94
SS
42314An empty reply indicates that the request is not supported by the stub.
42315@end table
42316
9d29849a 42317@item QTStart
c614397c 42318@cindex @samp{QTStart} packet
dde08ee1
PA
42319Begin the tracepoint experiment. Begin collecting data from
42320tracepoint hits in the trace frame buffer. This packet supports the
42321@samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
42322instruction reply packet}).
9d29849a
JB
42323
42324@item QTStop
c614397c 42325@cindex @samp{QTStop} packet
9d29849a
JB
42326End the tracepoint experiment. Stop collecting trace frames.
42327
d248b706
KY
42328@item QTEnable:@var{n}:@var{addr}
42329@anchor{QTEnable}
c614397c 42330@cindex @samp{QTEnable} packet
d248b706
KY
42331Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
42332experiment. If the tracepoint was previously disabled, then collection
42333of data from it will resume.
42334
42335@item QTDisable:@var{n}:@var{addr}
42336@anchor{QTDisable}
c614397c 42337@cindex @samp{QTDisable} packet
d248b706
KY
42338Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
42339experiment. No more data will be collected from the tracepoint unless
42340@samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
42341
9d29849a 42342@item QTinit
c614397c 42343@cindex @samp{QTinit} packet
9d29849a
JB
42344Clear the table of tracepoints, and empty the trace frame buffer.
42345
42346@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
c614397c 42347@cindex @samp{QTro} packet
9d29849a
JB
42348Establish the given ranges of memory as ``transparent''. The stub
42349will answer requests for these ranges from memory's current contents,
42350if they were not collected as part of the tracepoint hit.
42351
42352@value{GDBN} uses this to mark read-only regions of memory, like those
42353containing program code. Since these areas never change, they should
42354still have the same contents they did when the tracepoint was hit, so
42355there's no reason for the stub to refuse to provide their contents.
42356
d5551862 42357@item QTDisconnected:@var{value}
c614397c 42358@cindex @samp{QTDisconnected} packet
d5551862
SS
42359Set the choice to what to do with the tracing run when @value{GDBN}
42360disconnects from the target. A @var{value} of 1 directs the target to
42361continue the tracing run, while 0 tells the target to stop tracing if
42362@value{GDBN} is no longer in the picture.
42363
9d29849a 42364@item qTStatus
c614397c 42365@cindex @samp{qTStatus} packet
9d29849a
JB
42366Ask the stub if there is a trace experiment running right now.
42367
4daf5ac0
SS
42368The reply has the form:
42369
42370@table @samp
42371
42372@item T@var{running}@r{[};@var{field}@r{]}@dots{}
42373@var{running} is a single digit @code{1} if the trace is presently
42374running, or @code{0} if not. It is followed by semicolon-separated
42375optional fields that an agent may use to report additional status.
42376
42377@end table
42378
42379If the trace is not running, the agent may report any of several
42380explanations as one of the optional fields:
42381
42382@table @samp
42383
42384@item tnotrun:0
42385No trace has been run yet.
42386
f196051f
SS
42387@item tstop[:@var{text}]:0
42388The trace was stopped by a user-originated stop command. The optional
42389@var{text} field is a user-supplied string supplied as part of the
42390stop command (for instance, an explanation of why the trace was
42391stopped manually). It is hex-encoded.
4daf5ac0
SS
42392
42393@item tfull:0
42394The trace stopped because the trace buffer filled up.
42395
42396@item tdisconnected:0
42397The trace stopped because @value{GDBN} disconnected from the target.
42398
42399@item tpasscount:@var{tpnum}
42400The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
42401
6c28cbf2
SS
42402@item terror:@var{text}:@var{tpnum}
42403The trace stopped because tracepoint @var{tpnum} had an error. The
42404string @var{text} is available to describe the nature of the error
697aa1b7
EZ
42405(for instance, a divide by zero in the condition expression); it
42406is hex encoded.
6c28cbf2 42407
4daf5ac0
SS
42408@item tunknown:0
42409The trace stopped for some other reason.
42410
42411@end table
42412
33da3f1c
SS
42413Additional optional fields supply statistical and other information.
42414Although not required, they are extremely useful for users monitoring
42415the progress of a trace run. If a trace has stopped, and these
42416numbers are reported, they must reflect the state of the just-stopped
42417trace.
4daf5ac0 42418
9d29849a 42419@table @samp
4daf5ac0
SS
42420
42421@item tframes:@var{n}
42422The number of trace frames in the buffer.
42423
42424@item tcreated:@var{n}
42425The total number of trace frames created during the run. This may
42426be larger than the trace frame count, if the buffer is circular.
42427
42428@item tsize:@var{n}
42429The total size of the trace buffer, in bytes.
42430
42431@item tfree:@var{n}
42432The number of bytes still unused in the buffer.
42433
33da3f1c
SS
42434@item circular:@var{n}
42435The value of the circular trace buffer flag. @code{1} means that the
42436trace buffer is circular and old trace frames will be discarded if
42437necessary to make room, @code{0} means that the trace buffer is linear
42438and may fill up.
42439
42440@item disconn:@var{n}
42441The value of the disconnected tracing flag. @code{1} means that
42442tracing will continue after @value{GDBN} disconnects, @code{0} means
42443that the trace run will stop.
42444
9d29849a
JB
42445@end table
42446
f196051f
SS
42447@item qTP:@var{tp}:@var{addr}
42448@cindex tracepoint status, remote request
42449@cindex @samp{qTP} packet
42450Ask the stub for the current state of tracepoint number @var{tp} at
42451address @var{addr}.
42452
42453Replies:
42454@table @samp
42455@item V@var{hits}:@var{usage}
42456The tracepoint has been hit @var{hits} times so far during the trace
42457run, and accounts for @var{usage} in the trace buffer. Note that
42458@code{while-stepping} steps are not counted as separate hits, but the
42459steps' space consumption is added into the usage number.
42460
42461@end table
42462
f61e138d
SS
42463@item qTV:@var{var}
42464@cindex trace state variable value, remote request
42465@cindex @samp{qTV} packet
42466Ask the stub for the value of the trace state variable number @var{var}.
42467
42468Replies:
42469@table @samp
42470@item V@var{value}
42471The value of the variable is @var{value}. This will be the current
42472value of the variable if the user is examining a running target, or a
42473saved value if the variable was collected in the trace frame that the
42474user is looking at. Note that multiple requests may result in
42475different reply values, such as when requesting values while the
42476program is running.
42477
42478@item U
42479The value of the variable is unknown. This would occur, for example,
42480if the user is examining a trace frame in which the requested variable
42481was not collected.
9d29849a
JB
42482@end table
42483
d5551862 42484@item qTfP
c614397c 42485@cindex @samp{qTfP} packet
d5551862 42486@itemx qTsP
c614397c 42487@cindex @samp{qTsP} packet
d5551862
SS
42488These packets request data about tracepoints that are being used by
42489the target. @value{GDBN} sends @code{qTfP} to get the first piece
42490of data, and multiple @code{qTsP} to get additional pieces. Replies
42491to these packets generally take the form of the @code{QTDP} packets
42492that define tracepoints. (FIXME add detailed syntax)
42493
00bf0b85 42494@item qTfV
c614397c 42495@cindex @samp{qTfV} packet
00bf0b85 42496@itemx qTsV
c614397c 42497@cindex @samp{qTsV} packet
00bf0b85
SS
42498These packets request data about trace state variables that are on the
42499target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
42500and multiple @code{qTsV} to get additional variables. Replies to
42501these packets follow the syntax of the @code{QTDV} packets that define
42502trace state variables.
42503
0fb4aa4b
PA
42504@item qTfSTM
42505@itemx qTsSTM
16bdd41f
YQ
42506@anchor{qTfSTM}
42507@anchor{qTsSTM}
c614397c
YQ
42508@cindex @samp{qTfSTM} packet
42509@cindex @samp{qTsSTM} packet
0fb4aa4b
PA
42510These packets request data about static tracepoint markers that exist
42511in the target program. @value{GDBN} sends @code{qTfSTM} to get the
42512first piece of data, and multiple @code{qTsSTM} to get additional
42513pieces. Replies to these packets take the following form:
42514
42515Reply:
42516@table @samp
42517@item m @var{address}:@var{id}:@var{extra}
42518A single marker
42519@item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
42520a comma-separated list of markers
42521@item l
42522(lower case letter @samp{L}) denotes end of list.
42523@item E @var{nn}
697aa1b7 42524An error occurred. The error number @var{nn} is given as hex digits.
d57350ea 42525@item @w{}
0fb4aa4b
PA
42526An empty reply indicates that the request is not supported by the
42527stub.
42528@end table
42529
697aa1b7 42530The @var{address} is encoded in hex;
0fb4aa4b
PA
42531@var{id} and @var{extra} are strings encoded in hex.
42532
42533In response to each query, the target will reply with a list of one or
42534more markers, separated by commas. @value{GDBN} will respond to each
42535reply with a request for more markers (using the @samp{qs} form of the
42536query), until the target responds with @samp{l} (lower-case ell, for
42537@dfn{last}).
42538
42539@item qTSTMat:@var{address}
16bdd41f 42540@anchor{qTSTMat}
c614397c 42541@cindex @samp{qTSTMat} packet
0fb4aa4b
PA
42542This packets requests data about static tracepoint markers in the
42543target program at @var{address}. Replies to this packet follow the
42544syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
42545tracepoint markers.
42546
00bf0b85 42547@item QTSave:@var{filename}
c614397c 42548@cindex @samp{QTSave} packet
00bf0b85 42549This packet directs the target to save trace data to the file name
697aa1b7 42550@var{filename} in the target's filesystem. The @var{filename} is encoded
00bf0b85
SS
42551as a hex string; the interpretation of the file name (relative vs
42552absolute, wild cards, etc) is up to the target.
42553
42554@item qTBuffer:@var{offset},@var{len}
c614397c 42555@cindex @samp{qTBuffer} packet
00bf0b85
SS
42556Return up to @var{len} bytes of the current contents of trace buffer,
42557starting at @var{offset}. The trace buffer is treated as if it were
42558a contiguous collection of traceframes, as per the trace file format.
42559The reply consists as many hex-encoded bytes as the target can deliver
42560in a packet; it is not an error to return fewer than were asked for.
42561A reply consisting of just @code{l} indicates that no bytes are
42562available.
42563
4daf5ac0
SS
42564@item QTBuffer:circular:@var{value}
42565This packet directs the target to use a circular trace buffer if
42566@var{value} is 1, or a linear buffer if the value is 0.
42567
f6f899bf 42568@item QTBuffer:size:@var{size}
28abe188
EZ
42569@anchor{QTBuffer-size}
42570@cindex @samp{QTBuffer size} packet
f6f899bf
HAQ
42571This packet directs the target to make the trace buffer be of size
42572@var{size} if possible. A value of @code{-1} tells the target to
42573use whatever size it prefers.
42574
f196051f 42575@item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
c614397c 42576@cindex @samp{QTNotes} packet
f196051f
SS
42577This packet adds optional textual notes to the trace run. Allowable
42578types include @code{user}, @code{notes}, and @code{tstop}, the
42579@var{text} fields are arbitrary strings, hex-encoded.
42580
f61e138d 42581@end table
9d29849a 42582
dde08ee1
PA
42583@subsection Relocate instruction reply packet
42584When installing fast tracepoints in memory, the target may need to
42585relocate the instruction currently at the tracepoint address to a
42586different address in memory. For most instructions, a simple copy is
42587enough, but, for example, call instructions that implicitly push the
42588return address on the stack, and relative branches or other
42589PC-relative instructions require offset adjustment, so that the effect
42590of executing the instruction at a different address is the same as if
42591it had executed in the original location.
42592
42593In response to several of the tracepoint packets, the target may also
42594respond with a number of intermediate @samp{qRelocInsn} request
42595packets before the final result packet, to have @value{GDBN} handle
42596this relocation operation. If a packet supports this mechanism, its
42597documentation will explicitly say so. See for example the above
42598descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
42599format of the request is:
42600
42601@table @samp
42602@item qRelocInsn:@var{from};@var{to}
42603
42604This requests @value{GDBN} to copy instruction at address @var{from}
42605to address @var{to}, possibly adjusted so that executing the
42606instruction at @var{to} has the same effect as executing it at
42607@var{from}. @value{GDBN} writes the adjusted instruction to target
42608memory starting at @var{to}.
42609@end table
42610
42611Replies:
42612@table @samp
42613@item qRelocInsn:@var{adjusted_size}
697aa1b7 42614Informs the stub the relocation is complete. The @var{adjusted_size} is
dde08ee1
PA
42615the length in bytes of resulting relocated instruction sequence.
42616@item E @var{NN}
42617A badly formed request was detected, or an error was encountered while
42618relocating the instruction.
42619@end table
42620
a6b151f1
DJ
42621@node Host I/O Packets
42622@section Host I/O Packets
42623@cindex Host I/O, remote protocol
42624@cindex file transfer, remote protocol
42625
42626The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
42627operations on the far side of a remote link. For example, Host I/O is
42628used to upload and download files to a remote target with its own
42629filesystem. Host I/O uses the same constant values and data structure
42630layout as the target-initiated File-I/O protocol. However, the
42631Host I/O packets are structured differently. The target-initiated
42632protocol relies on target memory to store parameters and buffers.
42633Host I/O requests are initiated by @value{GDBN}, and the
42634target's memory is not involved. @xref{File-I/O Remote Protocol
42635Extension}, for more details on the target-initiated protocol.
42636
42637The Host I/O request packets all encode a single operation along with
42638its arguments. They have this format:
42639
42640@table @samp
42641
42642@item vFile:@var{operation}: @var{parameter}@dots{}
42643@var{operation} is the name of the particular request; the target
42644should compare the entire packet name up to the second colon when checking
42645for a supported operation. The format of @var{parameter} depends on
42646the operation. Numbers are always passed in hexadecimal. Negative
42647numbers have an explicit minus sign (i.e.@: two's complement is not
42648used). Strings (e.g.@: filenames) are encoded as a series of
42649hexadecimal bytes. The last argument to a system call may be a
42650buffer of escaped binary data (@pxref{Binary Data}).
42651
42652@end table
42653
42654The valid responses to Host I/O packets are:
42655
42656@table @samp
42657
42658@item F @var{result} [, @var{errno}] [; @var{attachment}]
42659@var{result} is the integer value returned by this operation, usually
42660non-negative for success and -1 for errors. If an error has occured,
697aa1b7 42661@var{errno} will be included in the result specifying a
a6b151f1
DJ
42662value defined by the File-I/O protocol (@pxref{Errno Values}). For
42663operations which return data, @var{attachment} supplies the data as a
42664binary buffer. Binary buffers in response packets are escaped in the
42665normal way (@pxref{Binary Data}). See the individual packet
42666documentation for the interpretation of @var{result} and
42667@var{attachment}.
42668
d57350ea 42669@item @w{}
a6b151f1
DJ
42670An empty response indicates that this operation is not recognized.
42671
42672@end table
42673
42674These are the supported Host I/O operations:
42675
42676@table @samp
697aa1b7
EZ
42677@item vFile:open: @var{filename}, @var{flags}, @var{mode}
42678Open a file at @var{filename} and return a file descriptor for it, or
42679return -1 if an error occurs. The @var{filename} is a string,
a6b151f1
DJ
42680@var{flags} is an integer indicating a mask of open flags
42681(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
42682of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 42683@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
42684
42685@item vFile:close: @var{fd}
42686Close the open file corresponding to @var{fd} and return 0, or
42687-1 if an error occurs.
42688
42689@item vFile:pread: @var{fd}, @var{count}, @var{offset}
42690Read data from the open file corresponding to @var{fd}. Up to
42691@var{count} bytes will be read from the file, starting at @var{offset}
42692relative to the start of the file. The target may read fewer bytes;
42693common reasons include packet size limits and an end-of-file
42694condition. The number of bytes read is returned. Zero should only be
42695returned for a successful read at the end of the file, or if
42696@var{count} was zero.
42697
42698The data read should be returned as a binary attachment on success.
42699If zero bytes were read, the response should include an empty binary
42700attachment (i.e.@: a trailing semicolon). The return value is the
42701number of target bytes read; the binary attachment may be longer if
42702some characters were escaped.
42703
42704@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
42705Write @var{data} (a binary buffer) to the open file corresponding
42706to @var{fd}. Start the write at @var{offset} from the start of the
42707file. Unlike many @code{write} system calls, there is no
42708separate @var{count} argument; the length of @var{data} in the
fb092e09 42709packet is used. @samp{vFile:pwrite} returns the number of bytes written,
a6b151f1
DJ
42710which may be shorter than the length of @var{data}, or -1 if an
42711error occurred.
42712
0a93529c
GB
42713@item vFile:fstat: @var{fd}
42714Get information about the open file corresponding to @var{fd}.
42715On success the information is returned as a binary attachment
42716and the return value is the size of this attachment in bytes.
42717If an error occurs the return value is -1. The format of the
42718returned binary attachment is as described in @ref{struct stat}.
42719
697aa1b7
EZ
42720@item vFile:unlink: @var{filename}
42721Delete the file at @var{filename} on the target. Return 0,
42722or -1 if an error occurs. The @var{filename} is a string.
a6b151f1 42723
b9e7b9c3
UW
42724@item vFile:readlink: @var{filename}
42725Read value of symbolic link @var{filename} on the target. Return
42726the number of bytes read, or -1 if an error occurs.
42727
42728The data read should be returned as a binary attachment on success.
42729If zero bytes were read, the response should include an empty binary
42730attachment (i.e.@: a trailing semicolon). The return value is the
42731number of target bytes read; the binary attachment may be longer if
42732some characters were escaped.
42733
15a201c8
GB
42734@item vFile:setfs: @var{pid}
42735Select the filesystem on which @code{vFile} operations with
42736@var{filename} arguments will operate. This is required for
42737@value{GDBN} to be able to access files on remote targets where
42738the remote stub does not share a common filesystem with the
42739inferior(s).
42740
42741If @var{pid} is nonzero, select the filesystem as seen by process
42742@var{pid}. If @var{pid} is zero, select the filesystem as seen by
42743the remote stub. Return 0 on success, or -1 if an error occurs.
42744If @code{vFile:setfs:} indicates success, the selected filesystem
42745remains selected until the next successful @code{vFile:setfs:}
42746operation.
42747
a6b151f1
DJ
42748@end table
42749
9a6253be
KB
42750@node Interrupts
42751@section Interrupts
42752@cindex interrupts (remote protocol)
de979965 42753@anchor{interrupting remote targets}
9a6253be 42754
de979965
PA
42755In all-stop mode, when a program on the remote target is running,
42756@value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
42757@code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
42758is specified via @value{GDBN}'s @samp{interrupt-sequence}.
9a6253be
KB
42759
42760The precise meaning of @code{BREAK} is defined by the transport
8775bb90
MS
42761mechanism and may, in fact, be undefined. @value{GDBN} does not
42762currently define a @code{BREAK} mechanism for any of the network
42763interfaces except for TCP, in which case @value{GDBN} sends the
42764@code{telnet} BREAK sequence.
9a6253be
KB
42765
42766@samp{Ctrl-C}, on the other hand, is defined and implemented for all
42767transport mechanisms. It is represented by sending the single byte
42768@code{0x03} without any of the usual packet overhead described in
42769the Overview section (@pxref{Overview}). When a @code{0x03} byte is
42770transmitted as part of a packet, it is considered to be packet data
42771and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 42772(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
42773@code{0x03} as part of its packet.
42774
9a7071a8
JB
42775@code{BREAK} followed by @code{g} is also known as Magic SysRq g.
42776When Linux kernel receives this sequence from serial port,
42777it stops execution and connects to gdb.
42778
de979965
PA
42779In non-stop mode, because packet resumptions are asynchronous
42780(@pxref{vCont packet}), @value{GDBN} is always free to send a remote
42781command to the remote stub, even when the target is running. For that
42782reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
42783packet}) with the usual packet framing instead of the single byte
42784@code{0x03}.
42785
9a6253be
KB
42786Stubs are not required to recognize these interrupt mechanisms and the
42787precise meaning associated with receipt of the interrupt is
8b23ecc4
SL
42788implementation defined. If the target supports debugging of multiple
42789threads and/or processes, it should attempt to interrupt all
42790currently-executing threads and processes.
42791If the stub is successful at interrupting the
42792running program, it should send one of the stop
42793reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
42794of successfully stopping the program in all-stop mode, and a stop reply
42795for each stopped thread in non-stop mode.
42796Interrupts received while the
cde67b27
YQ
42797program is stopped are queued and the program will be interrupted when
42798it is resumed next time.
8b23ecc4
SL
42799
42800@node Notification Packets
42801@section Notification Packets
42802@cindex notification packets
42803@cindex packets, notification
42804
42805The @value{GDBN} remote serial protocol includes @dfn{notifications},
42806packets that require no acknowledgment. Both the GDB and the stub
42807may send notifications (although the only notifications defined at
42808present are sent by the stub). Notifications carry information
42809without incurring the round-trip latency of an acknowledgment, and so
42810are useful for low-impact communications where occasional packet loss
42811is not a problem.
42812
42813A notification packet has the form @samp{% @var{data} #
42814@var{checksum}}, where @var{data} is the content of the notification,
42815and @var{checksum} is a checksum of @var{data}, computed and formatted
42816as for ordinary @value{GDBN} packets. A notification's @var{data}
42817never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
42818receiving a notification, the recipient sends no @samp{+} or @samp{-}
42819to acknowledge the notification's receipt or to report its corruption.
42820
42821Every notification's @var{data} begins with a name, which contains no
42822colon characters, followed by a colon character.
42823
42824Recipients should silently ignore corrupted notifications and
42825notifications they do not understand. Recipients should restart
42826timeout periods on receipt of a well-formed notification, whether or
42827not they understand it.
42828
42829Senders should only send the notifications described here when this
42830protocol description specifies that they are permitted. In the
42831future, we may extend the protocol to permit existing notifications in
42832new contexts; this rule helps older senders avoid confusing newer
42833recipients.
42834
42835(Older versions of @value{GDBN} ignore bytes received until they see
42836the @samp{$} byte that begins an ordinary packet, so new stubs may
42837transmit notifications without fear of confusing older clients. There
42838are no notifications defined for @value{GDBN} to send at the moment, but we
42839assume that most older stubs would ignore them, as well.)
42840
8dbe8ece 42841Each notification is comprised of three parts:
8b23ecc4 42842@table @samp
8dbe8ece
YQ
42843@item @var{name}:@var{event}
42844The notification packet is sent by the side that initiates the
42845exchange (currently, only the stub does that), with @var{event}
697aa1b7
EZ
42846carrying the specific information about the notification, and
42847@var{name} specifying the name of the notification.
8dbe8ece
YQ
42848@item @var{ack}
42849The acknowledge sent by the other side, usually @value{GDBN}, to
42850acknowledge the exchange and request the event.
42851@end table
42852
42853The purpose of an asynchronous notification mechanism is to report to
42854@value{GDBN} that something interesting happened in the remote stub.
42855
42856The remote stub may send notification @var{name}:@var{event}
42857at any time, but @value{GDBN} acknowledges the notification when
42858appropriate. The notification event is pending before @value{GDBN}
42859acknowledges. Only one notification at a time may be pending; if
42860additional events occur before @value{GDBN} has acknowledged the
42861previous notification, they must be queued by the stub for later
42862synchronous transmission in response to @var{ack} packets from
42863@value{GDBN}. Because the notification mechanism is unreliable,
42864the stub is permitted to resend a notification if it believes
42865@value{GDBN} may not have received it.
42866
42867Specifically, notifications may appear when @value{GDBN} is not
42868otherwise reading input from the stub, or when @value{GDBN} is
42869expecting to read a normal synchronous response or a
42870@samp{+}/@samp{-} acknowledgment to a packet it has sent.
42871Notification packets are distinct from any other communication from
42872the stub so there is no ambiguity.
42873
42874After receiving a notification, @value{GDBN} shall acknowledge it by
42875sending a @var{ack} packet as a regular, synchronous request to the
42876stub. Such acknowledgment is not required to happen immediately, as
42877@value{GDBN} is permitted to send other, unrelated packets to the
42878stub first, which the stub should process normally.
42879
42880Upon receiving a @var{ack} packet, if the stub has other queued
42881events to report to @value{GDBN}, it shall respond by sending a
42882normal @var{event}. @value{GDBN} shall then send another @var{ack}
42883packet to solicit further responses; again, it is permitted to send
42884other, unrelated packets as well which the stub should process
42885normally.
42886
42887If the stub receives a @var{ack} packet and there are no additional
42888@var{event} to report, the stub shall return an @samp{OK} response.
42889At this point, @value{GDBN} has finished processing a notification
42890and the stub has completed sending any queued events. @value{GDBN}
42891won't accept any new notifications until the final @samp{OK} is
42892received . If further notification events occur, the stub shall send
42893a new notification, @value{GDBN} shall accept the notification, and
42894the process shall be repeated.
42895
42896The process of asynchronous notification can be illustrated by the
42897following example:
42898@smallexample
4435e1cc 42899<- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
8dbe8ece
YQ
42900@code{...}
42901-> @code{vStopped}
42902<- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
42903-> @code{vStopped}
42904<- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
42905-> @code{vStopped}
42906<- @code{OK}
42907@end smallexample
42908
42909The following notifications are defined:
42910@multitable @columnfractions 0.12 0.12 0.38 0.38
42911
42912@item Notification
42913@tab Ack
42914@tab Event
42915@tab Description
42916
42917@item Stop
42918@tab vStopped
42919@tab @var{reply}. The @var{reply} has the form of a stop reply, as
8b23ecc4
SL
42920described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
42921for information on how these notifications are acknowledged by
42922@value{GDBN}.
8dbe8ece
YQ
42923@tab Report an asynchronous stop event in non-stop mode.
42924
42925@end multitable
8b23ecc4
SL
42926
42927@node Remote Non-Stop
42928@section Remote Protocol Support for Non-Stop Mode
42929
42930@value{GDBN}'s remote protocol supports non-stop debugging of
42931multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
42932supports non-stop mode, it should report that to @value{GDBN} by including
42933@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
42934
42935@value{GDBN} typically sends a @samp{QNonStop} packet only when
42936establishing a new connection with the stub. Entering non-stop mode
42937does not alter the state of any currently-running threads, but targets
42938must stop all threads in any already-attached processes when entering
42939all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
42940probe the target state after a mode change.
42941
42942In non-stop mode, when an attached process encounters an event that
42943would otherwise be reported with a stop reply, it uses the
42944asynchronous notification mechanism (@pxref{Notification Packets}) to
42945inform @value{GDBN}. In contrast to all-stop mode, where all threads
42946in all processes are stopped when a stop reply is sent, in non-stop
42947mode only the thread reporting the stop event is stopped. That is,
42948when reporting a @samp{S} or @samp{T} response to indicate completion
42949of a step operation, hitting a breakpoint, or a fault, only the
42950affected thread is stopped; any other still-running threads continue
42951to run. When reporting a @samp{W} or @samp{X} response, all running
42952threads belonging to other attached processes continue to run.
42953
8b23ecc4
SL
42954In non-stop mode, the target shall respond to the @samp{?} packet as
42955follows. First, any incomplete stop reply notification/@samp{vStopped}
42956sequence in progress is abandoned. The target must begin a new
42957sequence reporting stop events for all stopped threads, whether or not
42958it has previously reported those events to @value{GDBN}. The first
42959stop reply is sent as a synchronous reply to the @samp{?} packet, and
42960subsequent stop replies are sent as responses to @samp{vStopped} packets
42961using the mechanism described above. The target must not send
42962asynchronous stop reply notifications until the sequence is complete.
42963If all threads are running when the target receives the @samp{?} packet,
42964or if the target is not attached to any process, it shall respond
42965@samp{OK}.
9a6253be 42966
f7e6eed5
PA
42967If the stub supports non-stop mode, it should also support the
42968@samp{swbreak} stop reason if software breakpoints are supported, and
42969the @samp{hwbreak} stop reason if hardware breakpoints are supported
42970(@pxref{swbreak stop reason}). This is because given the asynchronous
42971nature of non-stop mode, between the time a thread hits a breakpoint
42972and the time the event is finally processed by @value{GDBN}, the
42973breakpoint may have already been removed from the target. Due to
42974this, @value{GDBN} needs to be able to tell whether a trap stop was
42975caused by a delayed breakpoint event, which should be ignored, as
42976opposed to a random trap signal, which should be reported to the user.
42977Note the @samp{swbreak} feature implies that the target is responsible
42978for adjusting the PC when a software breakpoint triggers, if
42979necessary, such as on the x86 architecture.
42980
a6f3e723
SL
42981@node Packet Acknowledgment
42982@section Packet Acknowledgment
42983
42984@cindex acknowledgment, for @value{GDBN} remote
42985@cindex packet acknowledgment, for @value{GDBN} remote
42986By default, when either the host or the target machine receives a packet,
42987the first response expected is an acknowledgment: either @samp{+} (to indicate
42988the package was received correctly) or @samp{-} (to request retransmission).
42989This mechanism allows the @value{GDBN} remote protocol to operate over
42990unreliable transport mechanisms, such as a serial line.
42991
42992In cases where the transport mechanism is itself reliable (such as a pipe or
42993TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
42994It may be desirable to disable them in that case to reduce communication
42995overhead, or for other reasons. This can be accomplished by means of the
42996@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
42997
42998When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
42999expect @samp{+}/@samp{-} protocol acknowledgments. The packet
43000and response format still includes the normal checksum, as described in
43001@ref{Overview}, but the checksum may be ignored by the receiver.
43002
43003If the stub supports @samp{QStartNoAckMode} and prefers to operate in
43004no-acknowledgment mode, it should report that to @value{GDBN}
43005by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
43006@pxref{qSupported}.
43007If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
43008disabled via the @code{set remote noack-packet off} command
43009(@pxref{Remote Configuration}),
43010@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
43011Only then may the stub actually turn off packet acknowledgments.
43012@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
43013response, which can be safely ignored by the stub.
43014
43015Note that @code{set remote noack-packet} command only affects negotiation
43016between @value{GDBN} and the stub when subsequent connections are made;
43017it does not affect the protocol acknowledgment state for any current
43018connection.
43019Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
43020new connection is established,
43021there is also no protocol request to re-enable the acknowledgments
43022for the current connection, once disabled.
43023
ee2d5c50
AC
43024@node Examples
43025@section Examples
eb12ee30 43026
8e04817f
AC
43027Example sequence of a target being re-started. Notice how the restart
43028does not get any direct output:
eb12ee30 43029
474c8240 43030@smallexample
d2c6833e
AC
43031-> @code{R00}
43032<- @code{+}
8e04817f 43033@emph{target restarts}
d2c6833e 43034-> @code{?}
8e04817f 43035<- @code{+}
d2c6833e
AC
43036<- @code{T001:1234123412341234}
43037-> @code{+}
474c8240 43038@end smallexample
eb12ee30 43039
8e04817f 43040Example sequence of a target being stepped by a single instruction:
eb12ee30 43041
474c8240 43042@smallexample
d2c6833e 43043-> @code{G1445@dots{}}
8e04817f 43044<- @code{+}
d2c6833e
AC
43045-> @code{s}
43046<- @code{+}
43047@emph{time passes}
43048<- @code{T001:1234123412341234}
8e04817f 43049-> @code{+}
d2c6833e 43050-> @code{g}
8e04817f 43051<- @code{+}
d2c6833e
AC
43052<- @code{1455@dots{}}
43053-> @code{+}
474c8240 43054@end smallexample
eb12ee30 43055
79a6e687
BW
43056@node File-I/O Remote Protocol Extension
43057@section File-I/O Remote Protocol Extension
0ce1b118
CV
43058@cindex File-I/O remote protocol extension
43059
43060@menu
43061* File-I/O Overview::
79a6e687
BW
43062* Protocol Basics::
43063* The F Request Packet::
43064* The F Reply Packet::
43065* The Ctrl-C Message::
0ce1b118 43066* Console I/O::
79a6e687 43067* List of Supported Calls::
db2e3e2e 43068* Protocol-specific Representation of Datatypes::
0ce1b118
CV
43069* Constants::
43070* File-I/O Examples::
43071@end menu
43072
43073@node File-I/O Overview
43074@subsection File-I/O Overview
43075@cindex file-i/o overview
43076
9c16f35a 43077The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 43078target to use the host's file system and console I/O to perform various
0ce1b118 43079system calls. System calls on the target system are translated into a
fc320d37
SL
43080remote protocol packet to the host system, which then performs the needed
43081actions and returns a response packet to the target system.
0ce1b118
CV
43082This simulates file system operations even on targets that lack file systems.
43083
fc320d37
SL
43084The protocol is defined to be independent of both the host and target systems.
43085It uses its own internal representation of datatypes and values. Both
0ce1b118 43086@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
43087translating the system-dependent value representations into the internal
43088protocol representations when data is transmitted.
0ce1b118 43089
fc320d37
SL
43090The communication is synchronous. A system call is possible only when
43091@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
43092or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 43093the target is stopped to allow deterministic access to the target's
fc320d37
SL
43094memory. Therefore File-I/O is not interruptible by target signals. On
43095the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 43096(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
43097
43098The target's request to perform a host system call does not finish
43099the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
43100after finishing the system call, the target returns to continuing the
43101previous activity (continue, step). No additional continue or step
43102request from @value{GDBN} is required.
43103
43104@smallexample
f7dc1244 43105(@value{GDBP}) continue
0ce1b118
CV
43106 <- target requests 'system call X'
43107 target is stopped, @value{GDBN} executes system call
3f94c067
BW
43108 -> @value{GDBN} returns result
43109 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
43110 <- target hits breakpoint and sends a Txx packet
43111@end smallexample
43112
fc320d37
SL
43113The protocol only supports I/O on the console and to regular files on
43114the host file system. Character or block special devices, pipes,
43115named pipes, sockets or any other communication method on the host
0ce1b118
CV
43116system are not supported by this protocol.
43117
8b23ecc4
SL
43118File I/O is not supported in non-stop mode.
43119
79a6e687
BW
43120@node Protocol Basics
43121@subsection Protocol Basics
0ce1b118
CV
43122@cindex protocol basics, file-i/o
43123
fc320d37
SL
43124The File-I/O protocol uses the @code{F} packet as the request as well
43125as reply packet. Since a File-I/O system call can only occur when
43126@value{GDBN} is waiting for a response from the continuing or stepping target,
43127the File-I/O request is a reply that @value{GDBN} has to expect as a result
43128of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
43129This @code{F} packet contains all information needed to allow @value{GDBN}
43130to call the appropriate host system call:
43131
43132@itemize @bullet
b383017d 43133@item
0ce1b118
CV
43134A unique identifier for the requested system call.
43135
43136@item
43137All parameters to the system call. Pointers are given as addresses
43138in the target memory address space. Pointers to strings are given as
b383017d 43139pointer/length pair. Numerical values are given as they are.
db2e3e2e 43140Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
43141
43142@end itemize
43143
fc320d37 43144At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
43145
43146@itemize @bullet
b383017d 43147@item
fc320d37
SL
43148If the parameters include pointer values to data needed as input to a
43149system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
43150standard @code{m} packet request. This additional communication has to be
43151expected by the target implementation and is handled as any other @code{m}
43152packet.
43153
43154@item
43155@value{GDBN} translates all value from protocol representation to host
43156representation as needed. Datatypes are coerced into the host types.
43157
43158@item
fc320d37 43159@value{GDBN} calls the system call.
0ce1b118
CV
43160
43161@item
43162It then coerces datatypes back to protocol representation.
43163
43164@item
fc320d37
SL
43165If the system call is expected to return data in buffer space specified
43166by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
43167target using a @code{M} or @code{X} packet. This packet has to be expected
43168by the target implementation and is handled as any other @code{M} or @code{X}
43169packet.
43170
43171@end itemize
43172
43173Eventually @value{GDBN} replies with another @code{F} packet which contains all
43174necessary information for the target to continue. This at least contains
43175
43176@itemize @bullet
43177@item
43178Return value.
43179
43180@item
43181@code{errno}, if has been changed by the system call.
43182
43183@item
43184``Ctrl-C'' flag.
43185
43186@end itemize
43187
43188After having done the needed type and value coercion, the target continues
43189the latest continue or step action.
43190
79a6e687
BW
43191@node The F Request Packet
43192@subsection The @code{F} Request Packet
0ce1b118
CV
43193@cindex file-i/o request packet
43194@cindex @code{F} request packet
43195
43196The @code{F} request packet has the following format:
43197
43198@table @samp
fc320d37 43199@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
43200
43201@var{call-id} is the identifier to indicate the host system call to be called.
43202This is just the name of the function.
43203
fc320d37
SL
43204@var{parameter@dots{}} are the parameters to the system call.
43205Parameters are hexadecimal integer values, either the actual values in case
43206of scalar datatypes, pointers to target buffer space in case of compound
43207datatypes and unspecified memory areas, or pointer/length pairs in case
43208of string parameters. These are appended to the @var{call-id} as a
43209comma-delimited list. All values are transmitted in ASCII
43210string representation, pointer/length pairs separated by a slash.
0ce1b118 43211
b383017d 43212@end table
0ce1b118 43213
fc320d37 43214
0ce1b118 43215
79a6e687
BW
43216@node The F Reply Packet
43217@subsection The @code{F} Reply Packet
0ce1b118
CV
43218@cindex file-i/o reply packet
43219@cindex @code{F} reply packet
43220
43221The @code{F} reply packet has the following format:
43222
43223@table @samp
43224
d3bdde98 43225@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
43226
43227@var{retcode} is the return code of the system call as hexadecimal value.
43228
db2e3e2e
BW
43229@var{errno} is the @code{errno} set by the call, in protocol-specific
43230representation.
0ce1b118
CV
43231This parameter can be omitted if the call was successful.
43232
fc320d37
SL
43233@var{Ctrl-C flag} is only sent if the user requested a break. In this
43234case, @var{errno} must be sent as well, even if the call was successful.
43235The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
43236
43237@smallexample
43238F0,0,C
43239@end smallexample
43240
43241@noindent
fc320d37 43242or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
43243
43244@smallexample
43245F-1,4,C
43246@end smallexample
43247
43248@noindent
db2e3e2e 43249assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
43250
43251@end table
43252
0ce1b118 43253
79a6e687
BW
43254@node The Ctrl-C Message
43255@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
43256@cindex ctrl-c message, in file-i/o protocol
43257
c8aa23ab 43258If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 43259reply packet (@pxref{The F Reply Packet}),
fc320d37 43260the target should behave as if it had
0ce1b118 43261gotten a break message. The meaning for the target is ``system call
fc320d37 43262interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 43263(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 43264packet.
fc320d37
SL
43265
43266It's important for the target to know in which
43267state the system call was interrupted. There are two possible cases:
0ce1b118
CV
43268
43269@itemize @bullet
43270@item
43271The system call hasn't been performed on the host yet.
43272
43273@item
43274The system call on the host has been finished.
43275
43276@end itemize
43277
43278These two states can be distinguished by the target by the value of the
43279returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
43280call hasn't been performed. This is equivalent to the @code{EINTR} handling
43281on POSIX systems. In any other case, the target may presume that the
fc320d37 43282system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
43283as if the break message arrived right after the system call.
43284
fc320d37 43285@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
43286yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
43287@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
43288before the user requests a break, the full action must be finished by
43289@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
43290The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
43291or the full action has been completed.
43292
43293@node Console I/O
43294@subsection Console I/O
43295@cindex console i/o as part of file-i/o
43296
d3e8051b 43297By default and if not explicitly closed by the target system, the file
0ce1b118
CV
43298descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
43299on the @value{GDBN} console is handled as any other file output operation
43300(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
43301by @value{GDBN} so that after the target read request from file descriptor
433020 all following typing is buffered until either one of the following
43303conditions is met:
43304
43305@itemize @bullet
43306@item
c8aa23ab 43307The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
43308@code{read}
43309system call is treated as finished.
43310
43311@item
7f9087cb 43312The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 43313newline.
0ce1b118
CV
43314
43315@item
c8aa23ab
EZ
43316The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
43317character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
43318
43319@end itemize
43320
fc320d37
SL
43321If the user has typed more characters than fit in the buffer given to
43322the @code{read} call, the trailing characters are buffered in @value{GDBN} until
43323either another @code{read(0, @dots{})} is requested by the target, or debugging
43324is stopped at the user's request.
0ce1b118 43325
0ce1b118 43326
79a6e687
BW
43327@node List of Supported Calls
43328@subsection List of Supported Calls
0ce1b118
CV
43329@cindex list of supported file-i/o calls
43330
43331@menu
43332* open::
43333* close::
43334* read::
43335* write::
43336* lseek::
43337* rename::
43338* unlink::
43339* stat/fstat::
43340* gettimeofday::
43341* isatty::
43342* system::
43343@end menu
43344
43345@node open
43346@unnumberedsubsubsec open
43347@cindex open, file-i/o system call
43348
fc320d37
SL
43349@table @asis
43350@item Synopsis:
0ce1b118 43351@smallexample
0ce1b118
CV
43352int open(const char *pathname, int flags);
43353int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
43354@end smallexample
43355
fc320d37
SL
43356@item Request:
43357@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
43358
0ce1b118 43359@noindent
fc320d37 43360@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
43361
43362@table @code
b383017d 43363@item O_CREAT
0ce1b118
CV
43364If the file does not exist it will be created. The host
43365rules apply as far as file ownership and time stamps
43366are concerned.
43367
b383017d 43368@item O_EXCL
fc320d37 43369When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
43370an error and open() fails.
43371
b383017d 43372@item O_TRUNC
0ce1b118 43373If the file already exists and the open mode allows
fc320d37
SL
43374writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
43375truncated to zero length.
0ce1b118 43376
b383017d 43377@item O_APPEND
0ce1b118
CV
43378The file is opened in append mode.
43379
b383017d 43380@item O_RDONLY
0ce1b118
CV
43381The file is opened for reading only.
43382
b383017d 43383@item O_WRONLY
0ce1b118
CV
43384The file is opened for writing only.
43385
b383017d 43386@item O_RDWR
0ce1b118 43387The file is opened for reading and writing.
fc320d37 43388@end table
0ce1b118
CV
43389
43390@noindent
fc320d37 43391Other bits are silently ignored.
0ce1b118 43392
0ce1b118
CV
43393
43394@noindent
fc320d37 43395@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
43396
43397@table @code
b383017d 43398@item S_IRUSR
0ce1b118
CV
43399User has read permission.
43400
b383017d 43401@item S_IWUSR
0ce1b118
CV
43402User has write permission.
43403
b383017d 43404@item S_IRGRP
0ce1b118
CV
43405Group has read permission.
43406
b383017d 43407@item S_IWGRP
0ce1b118
CV
43408Group has write permission.
43409
b383017d 43410@item S_IROTH
0ce1b118
CV
43411Others have read permission.
43412
b383017d 43413@item S_IWOTH
0ce1b118 43414Others have write permission.
fc320d37 43415@end table
0ce1b118
CV
43416
43417@noindent
fc320d37 43418Other bits are silently ignored.
0ce1b118 43419
0ce1b118 43420
fc320d37
SL
43421@item Return value:
43422@code{open} returns the new file descriptor or -1 if an error
43423occurred.
0ce1b118 43424
fc320d37 43425@item Errors:
0ce1b118
CV
43426
43427@table @code
b383017d 43428@item EEXIST
fc320d37 43429@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 43430
b383017d 43431@item EISDIR
fc320d37 43432@var{pathname} refers to a directory.
0ce1b118 43433
b383017d 43434@item EACCES
0ce1b118
CV
43435The requested access is not allowed.
43436
43437@item ENAMETOOLONG
fc320d37 43438@var{pathname} was too long.
0ce1b118 43439
b383017d 43440@item ENOENT
fc320d37 43441A directory component in @var{pathname} does not exist.
0ce1b118 43442
b383017d 43443@item ENODEV
fc320d37 43444@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 43445
b383017d 43446@item EROFS
fc320d37 43447@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
43448write access was requested.
43449
b383017d 43450@item EFAULT
fc320d37 43451@var{pathname} is an invalid pointer value.
0ce1b118 43452
b383017d 43453@item ENOSPC
0ce1b118
CV
43454No space on device to create the file.
43455
b383017d 43456@item EMFILE
0ce1b118
CV
43457The process already has the maximum number of files open.
43458
b383017d 43459@item ENFILE
0ce1b118
CV
43460The limit on the total number of files open on the system
43461has been reached.
43462
b383017d 43463@item EINTR
0ce1b118
CV
43464The call was interrupted by the user.
43465@end table
43466
fc320d37
SL
43467@end table
43468
0ce1b118
CV
43469@node close
43470@unnumberedsubsubsec close
43471@cindex close, file-i/o system call
43472
fc320d37
SL
43473@table @asis
43474@item Synopsis:
0ce1b118 43475@smallexample
0ce1b118 43476int close(int fd);
fc320d37 43477@end smallexample
0ce1b118 43478
fc320d37
SL
43479@item Request:
43480@samp{Fclose,@var{fd}}
0ce1b118 43481
fc320d37
SL
43482@item Return value:
43483@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 43484
fc320d37 43485@item Errors:
0ce1b118
CV
43486
43487@table @code
b383017d 43488@item EBADF
fc320d37 43489@var{fd} isn't a valid open file descriptor.
0ce1b118 43490
b383017d 43491@item EINTR
0ce1b118
CV
43492The call was interrupted by the user.
43493@end table
43494
fc320d37
SL
43495@end table
43496
0ce1b118
CV
43497@node read
43498@unnumberedsubsubsec read
43499@cindex read, file-i/o system call
43500
fc320d37
SL
43501@table @asis
43502@item Synopsis:
0ce1b118 43503@smallexample
0ce1b118 43504int read(int fd, void *buf, unsigned int count);
fc320d37 43505@end smallexample
0ce1b118 43506
fc320d37
SL
43507@item Request:
43508@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 43509
fc320d37 43510@item Return value:
0ce1b118
CV
43511On success, the number of bytes read is returned.
43512Zero indicates end of file. If count is zero, read
b383017d 43513returns zero as well. On error, -1 is returned.
0ce1b118 43514
fc320d37 43515@item Errors:
0ce1b118
CV
43516
43517@table @code
b383017d 43518@item EBADF
fc320d37 43519@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
43520reading.
43521
b383017d 43522@item EFAULT
fc320d37 43523@var{bufptr} is an invalid pointer value.
0ce1b118 43524
b383017d 43525@item EINTR
0ce1b118
CV
43526The call was interrupted by the user.
43527@end table
43528
fc320d37
SL
43529@end table
43530
0ce1b118
CV
43531@node write
43532@unnumberedsubsubsec write
43533@cindex write, file-i/o system call
43534
fc320d37
SL
43535@table @asis
43536@item Synopsis:
0ce1b118 43537@smallexample
0ce1b118 43538int write(int fd, const void *buf, unsigned int count);
fc320d37 43539@end smallexample
0ce1b118 43540
fc320d37
SL
43541@item Request:
43542@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 43543
fc320d37 43544@item Return value:
0ce1b118
CV
43545On success, the number of bytes written are returned.
43546Zero indicates nothing was written. On error, -1
43547is returned.
43548
fc320d37 43549@item Errors:
0ce1b118
CV
43550
43551@table @code
b383017d 43552@item EBADF
fc320d37 43553@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
43554writing.
43555
b383017d 43556@item EFAULT
fc320d37 43557@var{bufptr} is an invalid pointer value.
0ce1b118 43558
b383017d 43559@item EFBIG
0ce1b118 43560An attempt was made to write a file that exceeds the
db2e3e2e 43561host-specific maximum file size allowed.
0ce1b118 43562
b383017d 43563@item ENOSPC
0ce1b118
CV
43564No space on device to write the data.
43565
b383017d 43566@item EINTR
0ce1b118
CV
43567The call was interrupted by the user.
43568@end table
43569
fc320d37
SL
43570@end table
43571
0ce1b118
CV
43572@node lseek
43573@unnumberedsubsubsec lseek
43574@cindex lseek, file-i/o system call
43575
fc320d37
SL
43576@table @asis
43577@item Synopsis:
0ce1b118 43578@smallexample
0ce1b118 43579long lseek (int fd, long offset, int flag);
0ce1b118
CV
43580@end smallexample
43581
fc320d37
SL
43582@item Request:
43583@samp{Flseek,@var{fd},@var{offset},@var{flag}}
43584
43585@var{flag} is one of:
0ce1b118
CV
43586
43587@table @code
b383017d 43588@item SEEK_SET
fc320d37 43589The offset is set to @var{offset} bytes.
0ce1b118 43590
b383017d 43591@item SEEK_CUR
fc320d37 43592The offset is set to its current location plus @var{offset}
0ce1b118
CV
43593bytes.
43594
b383017d 43595@item SEEK_END
fc320d37 43596The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
43597bytes.
43598@end table
43599
fc320d37 43600@item Return value:
0ce1b118
CV
43601On success, the resulting unsigned offset in bytes from
43602the beginning of the file is returned. Otherwise, a
43603value of -1 is returned.
43604
fc320d37 43605@item Errors:
0ce1b118
CV
43606
43607@table @code
b383017d 43608@item EBADF
fc320d37 43609@var{fd} is not a valid open file descriptor.
0ce1b118 43610
b383017d 43611@item ESPIPE
fc320d37 43612@var{fd} is associated with the @value{GDBN} console.
0ce1b118 43613
b383017d 43614@item EINVAL
fc320d37 43615@var{flag} is not a proper value.
0ce1b118 43616
b383017d 43617@item EINTR
0ce1b118
CV
43618The call was interrupted by the user.
43619@end table
43620
fc320d37
SL
43621@end table
43622
0ce1b118
CV
43623@node rename
43624@unnumberedsubsubsec rename
43625@cindex rename, file-i/o system call
43626
fc320d37
SL
43627@table @asis
43628@item Synopsis:
0ce1b118 43629@smallexample
0ce1b118 43630int rename(const char *oldpath, const char *newpath);
fc320d37 43631@end smallexample
0ce1b118 43632
fc320d37
SL
43633@item Request:
43634@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 43635
fc320d37 43636@item Return value:
0ce1b118
CV
43637On success, zero is returned. On error, -1 is returned.
43638
fc320d37 43639@item Errors:
0ce1b118
CV
43640
43641@table @code
b383017d 43642@item EISDIR
fc320d37 43643@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
43644directory.
43645
b383017d 43646@item EEXIST
fc320d37 43647@var{newpath} is a non-empty directory.
0ce1b118 43648
b383017d 43649@item EBUSY
fc320d37 43650@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
43651process.
43652
b383017d 43653@item EINVAL
0ce1b118
CV
43654An attempt was made to make a directory a subdirectory
43655of itself.
43656
b383017d 43657@item ENOTDIR
fc320d37
SL
43658A component used as a directory in @var{oldpath} or new
43659path is not a directory. Or @var{oldpath} is a directory
43660and @var{newpath} exists but is not a directory.
0ce1b118 43661
b383017d 43662@item EFAULT
fc320d37 43663@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 43664
b383017d 43665@item EACCES
0ce1b118
CV
43666No access to the file or the path of the file.
43667
43668@item ENAMETOOLONG
b383017d 43669
fc320d37 43670@var{oldpath} or @var{newpath} was too long.
0ce1b118 43671
b383017d 43672@item ENOENT
fc320d37 43673A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 43674
b383017d 43675@item EROFS
0ce1b118
CV
43676The file is on a read-only filesystem.
43677
b383017d 43678@item ENOSPC
0ce1b118
CV
43679The device containing the file has no room for the new
43680directory entry.
43681
b383017d 43682@item EINTR
0ce1b118
CV
43683The call was interrupted by the user.
43684@end table
43685
fc320d37
SL
43686@end table
43687
0ce1b118
CV
43688@node unlink
43689@unnumberedsubsubsec unlink
43690@cindex unlink, file-i/o system call
43691
fc320d37
SL
43692@table @asis
43693@item Synopsis:
0ce1b118 43694@smallexample
0ce1b118 43695int unlink(const char *pathname);
fc320d37 43696@end smallexample
0ce1b118 43697
fc320d37
SL
43698@item Request:
43699@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 43700
fc320d37 43701@item Return value:
0ce1b118
CV
43702On success, zero is returned. On error, -1 is returned.
43703
fc320d37 43704@item Errors:
0ce1b118
CV
43705
43706@table @code
b383017d 43707@item EACCES
0ce1b118
CV
43708No access to the file or the path of the file.
43709
b383017d 43710@item EPERM
0ce1b118
CV
43711The system does not allow unlinking of directories.
43712
b383017d 43713@item EBUSY
fc320d37 43714The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
43715being used by another process.
43716
b383017d 43717@item EFAULT
fc320d37 43718@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
43719
43720@item ENAMETOOLONG
fc320d37 43721@var{pathname} was too long.
0ce1b118 43722
b383017d 43723@item ENOENT
fc320d37 43724A directory component in @var{pathname} does not exist.
0ce1b118 43725
b383017d 43726@item ENOTDIR
0ce1b118
CV
43727A component of the path is not a directory.
43728
b383017d 43729@item EROFS
0ce1b118
CV
43730The file is on a read-only filesystem.
43731
b383017d 43732@item EINTR
0ce1b118
CV
43733The call was interrupted by the user.
43734@end table
43735
fc320d37
SL
43736@end table
43737
0ce1b118
CV
43738@node stat/fstat
43739@unnumberedsubsubsec stat/fstat
43740@cindex fstat, file-i/o system call
43741@cindex stat, file-i/o system call
43742
fc320d37
SL
43743@table @asis
43744@item Synopsis:
0ce1b118 43745@smallexample
0ce1b118
CV
43746int stat(const char *pathname, struct stat *buf);
43747int fstat(int fd, struct stat *buf);
fc320d37 43748@end smallexample
0ce1b118 43749
fc320d37
SL
43750@item Request:
43751@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
43752@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 43753
fc320d37 43754@item Return value:
0ce1b118
CV
43755On success, zero is returned. On error, -1 is returned.
43756
fc320d37 43757@item Errors:
0ce1b118
CV
43758
43759@table @code
b383017d 43760@item EBADF
fc320d37 43761@var{fd} is not a valid open file.
0ce1b118 43762
b383017d 43763@item ENOENT
fc320d37 43764A directory component in @var{pathname} does not exist or the
0ce1b118
CV
43765path is an empty string.
43766
b383017d 43767@item ENOTDIR
0ce1b118
CV
43768A component of the path is not a directory.
43769
b383017d 43770@item EFAULT
fc320d37 43771@var{pathnameptr} is an invalid pointer value.
0ce1b118 43772
b383017d 43773@item EACCES
0ce1b118
CV
43774No access to the file or the path of the file.
43775
43776@item ENAMETOOLONG
fc320d37 43777@var{pathname} was too long.
0ce1b118 43778
b383017d 43779@item EINTR
0ce1b118
CV
43780The call was interrupted by the user.
43781@end table
43782
fc320d37
SL
43783@end table
43784
0ce1b118
CV
43785@node gettimeofday
43786@unnumberedsubsubsec gettimeofday
43787@cindex gettimeofday, file-i/o system call
43788
fc320d37
SL
43789@table @asis
43790@item Synopsis:
0ce1b118 43791@smallexample
0ce1b118 43792int gettimeofday(struct timeval *tv, void *tz);
fc320d37 43793@end smallexample
0ce1b118 43794
fc320d37
SL
43795@item Request:
43796@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 43797
fc320d37 43798@item Return value:
0ce1b118
CV
43799On success, 0 is returned, -1 otherwise.
43800
fc320d37 43801@item Errors:
0ce1b118
CV
43802
43803@table @code
b383017d 43804@item EINVAL
fc320d37 43805@var{tz} is a non-NULL pointer.
0ce1b118 43806
b383017d 43807@item EFAULT
fc320d37
SL
43808@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
43809@end table
43810
0ce1b118
CV
43811@end table
43812
43813@node isatty
43814@unnumberedsubsubsec isatty
43815@cindex isatty, file-i/o system call
43816
fc320d37
SL
43817@table @asis
43818@item Synopsis:
0ce1b118 43819@smallexample
0ce1b118 43820int isatty(int fd);
fc320d37 43821@end smallexample
0ce1b118 43822
fc320d37
SL
43823@item Request:
43824@samp{Fisatty,@var{fd}}
0ce1b118 43825
fc320d37
SL
43826@item Return value:
43827Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 43828
fc320d37 43829@item Errors:
0ce1b118
CV
43830
43831@table @code
b383017d 43832@item EINTR
0ce1b118
CV
43833The call was interrupted by the user.
43834@end table
43835
fc320d37
SL
43836@end table
43837
43838Note that the @code{isatty} call is treated as a special case: it returns
438391 to the target if the file descriptor is attached
43840to the @value{GDBN} console, 0 otherwise. Implementing through system calls
43841would require implementing @code{ioctl} and would be more complex than
43842needed.
43843
43844
0ce1b118
CV
43845@node system
43846@unnumberedsubsubsec system
43847@cindex system, file-i/o system call
43848
fc320d37
SL
43849@table @asis
43850@item Synopsis:
0ce1b118 43851@smallexample
0ce1b118 43852int system(const char *command);
fc320d37 43853@end smallexample
0ce1b118 43854
fc320d37
SL
43855@item Request:
43856@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 43857
fc320d37 43858@item Return value:
5600ea19
NS
43859If @var{len} is zero, the return value indicates whether a shell is
43860available. A zero return value indicates a shell is not available.
43861For non-zero @var{len}, the value returned is -1 on error and the
43862return status of the command otherwise. Only the exit status of the
43863command is returned, which is extracted from the host's @code{system}
43864return value by calling @code{WEXITSTATUS(retval)}. In case
43865@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 43866
fc320d37 43867@item Errors:
0ce1b118
CV
43868
43869@table @code
b383017d 43870@item EINTR
0ce1b118
CV
43871The call was interrupted by the user.
43872@end table
43873
fc320d37
SL
43874@end table
43875
43876@value{GDBN} takes over the full task of calling the necessary host calls
43877to perform the @code{system} call. The return value of @code{system} on
43878the host is simplified before it's returned
43879to the target. Any termination signal information from the child process
43880is discarded, and the return value consists
43881entirely of the exit status of the called command.
43882
43883Due to security concerns, the @code{system} call is by default refused
43884by @value{GDBN}. The user has to allow this call explicitly with the
43885@code{set remote system-call-allowed 1} command.
43886
43887@table @code
43888@item set remote system-call-allowed
43889@kindex set remote system-call-allowed
43890Control whether to allow the @code{system} calls in the File I/O
43891protocol for the remote target. The default is zero (disabled).
43892
43893@item show remote system-call-allowed
43894@kindex show remote system-call-allowed
43895Show whether the @code{system} calls are allowed in the File I/O
43896protocol.
43897@end table
43898
db2e3e2e
BW
43899@node Protocol-specific Representation of Datatypes
43900@subsection Protocol-specific Representation of Datatypes
43901@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
43902
43903@menu
79a6e687
BW
43904* Integral Datatypes::
43905* Pointer Values::
43906* Memory Transfer::
0ce1b118
CV
43907* struct stat::
43908* struct timeval::
43909@end menu
43910
79a6e687
BW
43911@node Integral Datatypes
43912@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
43913@cindex integral datatypes, in file-i/o protocol
43914
fc320d37
SL
43915The integral datatypes used in the system calls are @code{int},
43916@code{unsigned int}, @code{long}, @code{unsigned long},
43917@code{mode_t}, and @code{time_t}.
0ce1b118 43918
fc320d37 43919@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
43920implemented as 32 bit values in this protocol.
43921
fc320d37 43922@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 43923
0ce1b118
CV
43924@xref{Limits}, for corresponding MIN and MAX values (similar to those
43925in @file{limits.h}) to allow range checking on host and target.
43926
43927@code{time_t} datatypes are defined as seconds since the Epoch.
43928
43929All integral datatypes transferred as part of a memory read or write of a
43930structured datatype e.g.@: a @code{struct stat} have to be given in big endian
43931byte order.
43932
79a6e687
BW
43933@node Pointer Values
43934@unnumberedsubsubsec Pointer Values
0ce1b118
CV
43935@cindex pointer values, in file-i/o protocol
43936
43937Pointers to target data are transmitted as they are. An exception
43938is made for pointers to buffers for which the length isn't
43939transmitted as part of the function call, namely strings. Strings
43940are transmitted as a pointer/length pair, both as hex values, e.g.@:
43941
43942@smallexample
43943@code{1aaf/12}
43944@end smallexample
43945
43946@noindent
43947which is a pointer to data of length 18 bytes at position 0x1aaf.
43948The length is defined as the full string length in bytes, including
fc320d37
SL
43949the trailing null byte. For example, the string @code{"hello world"}
43950at address 0x123456 is transmitted as
0ce1b118
CV
43951
43952@smallexample
fc320d37 43953@code{123456/d}
0ce1b118
CV
43954@end smallexample
43955
79a6e687
BW
43956@node Memory Transfer
43957@unnumberedsubsubsec Memory Transfer
fc320d37
SL
43958@cindex memory transfer, in file-i/o protocol
43959
43960Structured data which is transferred using a memory read or write (for
db2e3e2e 43961example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
43962with all scalar multibyte datatypes being big endian. Translation to
43963this representation needs to be done both by the target before the @code{F}
43964packet is sent, and by @value{GDBN} before
43965it transfers memory to the target. Transferred pointers to structured
43966data should point to the already-coerced data at any time.
0ce1b118 43967
0ce1b118
CV
43968
43969@node struct stat
43970@unnumberedsubsubsec struct stat
43971@cindex struct stat, in file-i/o protocol
43972
fc320d37
SL
43973The buffer of type @code{struct stat} used by the target and @value{GDBN}
43974is defined as follows:
0ce1b118
CV
43975
43976@smallexample
43977struct stat @{
43978 unsigned int st_dev; /* device */
43979 unsigned int st_ino; /* inode */
43980 mode_t st_mode; /* protection */
43981 unsigned int st_nlink; /* number of hard links */
43982 unsigned int st_uid; /* user ID of owner */
43983 unsigned int st_gid; /* group ID of owner */
43984 unsigned int st_rdev; /* device type (if inode device) */
43985 unsigned long st_size; /* total size, in bytes */
43986 unsigned long st_blksize; /* blocksize for filesystem I/O */
43987 unsigned long st_blocks; /* number of blocks allocated */
43988 time_t st_atime; /* time of last access */
43989 time_t st_mtime; /* time of last modification */
43990 time_t st_ctime; /* time of last change */
43991@};
43992@end smallexample
43993
fc320d37 43994The integral datatypes conform to the definitions given in the
79a6e687 43995appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
43996structure is of size 64 bytes.
43997
43998The values of several fields have a restricted meaning and/or
43999range of values.
44000
fc320d37 44001@table @code
0ce1b118 44002
fc320d37
SL
44003@item st_dev
44004A value of 0 represents a file, 1 the console.
0ce1b118 44005
fc320d37
SL
44006@item st_ino
44007No valid meaning for the target. Transmitted unchanged.
0ce1b118 44008
fc320d37
SL
44009@item st_mode
44010Valid mode bits are described in @ref{Constants}. Any other
44011bits have currently no meaning for the target.
0ce1b118 44012
fc320d37
SL
44013@item st_uid
44014@itemx st_gid
44015@itemx st_rdev
44016No valid meaning for the target. Transmitted unchanged.
0ce1b118 44017
fc320d37
SL
44018@item st_atime
44019@itemx st_mtime
44020@itemx st_ctime
44021These values have a host and file system dependent
44022accuracy. Especially on Windows hosts, the file system may not
44023support exact timing values.
44024@end table
0ce1b118 44025
fc320d37
SL
44026The target gets a @code{struct stat} of the above representation and is
44027responsible for coercing it to the target representation before
0ce1b118
CV
44028continuing.
44029
fc320d37
SL
44030Note that due to size differences between the host, target, and protocol
44031representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
44032get truncated on the target.
44033
44034@node struct timeval
44035@unnumberedsubsubsec struct timeval
44036@cindex struct timeval, in file-i/o protocol
44037
fc320d37 44038The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
44039is defined as follows:
44040
44041@smallexample
b383017d 44042struct timeval @{
0ce1b118
CV
44043 time_t tv_sec; /* second */
44044 long tv_usec; /* microsecond */
44045@};
44046@end smallexample
44047
fc320d37 44048The integral datatypes conform to the definitions given in the
79a6e687 44049appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
44050structure is of size 8 bytes.
44051
44052@node Constants
44053@subsection Constants
44054@cindex constants, in file-i/o protocol
44055
44056The following values are used for the constants inside of the
fc320d37 44057protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
44058values before and after the call as needed.
44059
44060@menu
79a6e687
BW
44061* Open Flags::
44062* mode_t Values::
44063* Errno Values::
44064* Lseek Flags::
0ce1b118
CV
44065* Limits::
44066@end menu
44067
79a6e687
BW
44068@node Open Flags
44069@unnumberedsubsubsec Open Flags
0ce1b118
CV
44070@cindex open flags, in file-i/o protocol
44071
44072All values are given in hexadecimal representation.
44073
44074@smallexample
44075 O_RDONLY 0x0
44076 O_WRONLY 0x1
44077 O_RDWR 0x2
44078 O_APPEND 0x8
44079 O_CREAT 0x200
44080 O_TRUNC 0x400
44081 O_EXCL 0x800
44082@end smallexample
44083
79a6e687
BW
44084@node mode_t Values
44085@unnumberedsubsubsec mode_t Values
0ce1b118
CV
44086@cindex mode_t values, in file-i/o protocol
44087
44088All values are given in octal representation.
44089
44090@smallexample
44091 S_IFREG 0100000
44092 S_IFDIR 040000
44093 S_IRUSR 0400
44094 S_IWUSR 0200
44095 S_IXUSR 0100
44096 S_IRGRP 040
44097 S_IWGRP 020
44098 S_IXGRP 010
44099 S_IROTH 04
44100 S_IWOTH 02
44101 S_IXOTH 01
44102@end smallexample
44103
79a6e687
BW
44104@node Errno Values
44105@unnumberedsubsubsec Errno Values
0ce1b118
CV
44106@cindex errno values, in file-i/o protocol
44107
44108All values are given in decimal representation.
44109
44110@smallexample
44111 EPERM 1
44112 ENOENT 2
44113 EINTR 4
44114 EBADF 9
44115 EACCES 13
44116 EFAULT 14
44117 EBUSY 16
44118 EEXIST 17
44119 ENODEV 19
44120 ENOTDIR 20
44121 EISDIR 21
44122 EINVAL 22
44123 ENFILE 23
44124 EMFILE 24
44125 EFBIG 27
44126 ENOSPC 28
44127 ESPIPE 29
44128 EROFS 30
44129 ENAMETOOLONG 91
44130 EUNKNOWN 9999
44131@end smallexample
44132
fc320d37 44133 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
44134 any error value not in the list of supported error numbers.
44135
79a6e687
BW
44136@node Lseek Flags
44137@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
44138@cindex lseek flags, in file-i/o protocol
44139
44140@smallexample
44141 SEEK_SET 0
44142 SEEK_CUR 1
44143 SEEK_END 2
44144@end smallexample
44145
44146@node Limits
44147@unnumberedsubsubsec Limits
44148@cindex limits, in file-i/o protocol
44149
44150All values are given in decimal representation.
44151
44152@smallexample
44153 INT_MIN -2147483648
44154 INT_MAX 2147483647
44155 UINT_MAX 4294967295
44156 LONG_MIN -9223372036854775808
44157 LONG_MAX 9223372036854775807
44158 ULONG_MAX 18446744073709551615
44159@end smallexample
44160
44161@node File-I/O Examples
44162@subsection File-I/O Examples
44163@cindex file-i/o examples
44164
44165Example sequence of a write call, file descriptor 3, buffer is at target
44166address 0x1234, 6 bytes should be written:
44167
44168@smallexample
44169<- @code{Fwrite,3,1234,6}
44170@emph{request memory read from target}
44171-> @code{m1234,6}
44172<- XXXXXX
44173@emph{return "6 bytes written"}
44174-> @code{F6}
44175@end smallexample
44176
44177Example sequence of a read call, file descriptor 3, buffer is at target
44178address 0x1234, 6 bytes should be read:
44179
44180@smallexample
44181<- @code{Fread,3,1234,6}
44182@emph{request memory write to target}
44183-> @code{X1234,6:XXXXXX}
44184@emph{return "6 bytes read"}
44185-> @code{F6}
44186@end smallexample
44187
44188Example sequence of a read call, call fails on the host due to invalid
fc320d37 44189file descriptor (@code{EBADF}):
0ce1b118
CV
44190
44191@smallexample
44192<- @code{Fread,3,1234,6}
44193-> @code{F-1,9}
44194@end smallexample
44195
c8aa23ab 44196Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
44197host is called:
44198
44199@smallexample
44200<- @code{Fread,3,1234,6}
44201-> @code{F-1,4,C}
44202<- @code{T02}
44203@end smallexample
44204
c8aa23ab 44205Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
44206host is called:
44207
44208@smallexample
44209<- @code{Fread,3,1234,6}
44210-> @code{X1234,6:XXXXXX}
44211<- @code{T02}
44212@end smallexample
44213
cfa9d6d9
DJ
44214@node Library List Format
44215@section Library List Format
44216@cindex library list format, remote protocol
44217
44218On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
44219same process as your application to manage libraries. In this case,
44220@value{GDBN} can use the loader's symbol table and normal memory
44221operations to maintain a list of shared libraries. On other
44222platforms, the operating system manages loaded libraries.
44223@value{GDBN} can not retrieve the list of currently loaded libraries
44224through memory operations, so it uses the @samp{qXfer:libraries:read}
44225packet (@pxref{qXfer library list read}) instead. The remote stub
44226queries the target's operating system and reports which libraries
44227are loaded.
44228
44229The @samp{qXfer:libraries:read} packet returns an XML document which
44230lists loaded libraries and their offsets. Each library has an
1fddbabb
PA
44231associated name and one or more segment or section base addresses,
44232which report where the library was loaded in memory.
44233
44234For the common case of libraries that are fully linked binaries, the
44235library should have a list of segments. If the target supports
44236dynamic linking of a relocatable object file, its library XML element
44237should instead include a list of allocated sections. The segment or
44238section bases are start addresses, not relocation offsets; they do not
44239depend on the library's link-time base addresses.
cfa9d6d9 44240
9cceb671
DJ
44241@value{GDBN} must be linked with the Expat library to support XML
44242library lists. @xref{Expat}.
44243
cfa9d6d9
DJ
44244A simple memory map, with one loaded library relocated by a single
44245offset, looks like this:
44246
44247@smallexample
44248<library-list>
44249 <library name="/lib/libc.so.6">
44250 <segment address="0x10000000"/>
44251 </library>
44252</library-list>
44253@end smallexample
44254
1fddbabb
PA
44255Another simple memory map, with one loaded library with three
44256allocated sections (.text, .data, .bss), looks like this:
44257
44258@smallexample
44259<library-list>
44260 <library name="sharedlib.o">
44261 <section address="0x10000000"/>
44262 <section address="0x20000000"/>
44263 <section address="0x30000000"/>
44264 </library>
44265</library-list>
44266@end smallexample
44267
cfa9d6d9
DJ
44268The format of a library list is described by this DTD:
44269
44270@smallexample
44271<!-- library-list: Root element with versioning -->
44272<!ELEMENT library-list (library)*>
44273<!ATTLIST library-list version CDATA #FIXED "1.0">
1fddbabb 44274<!ELEMENT library (segment*, section*)>
cfa9d6d9
DJ
44275<!ATTLIST library name CDATA #REQUIRED>
44276<!ELEMENT segment EMPTY>
44277<!ATTLIST segment address CDATA #REQUIRED>
1fddbabb
PA
44278<!ELEMENT section EMPTY>
44279<!ATTLIST section address CDATA #REQUIRED>
cfa9d6d9
DJ
44280@end smallexample
44281
1fddbabb
PA
44282In addition, segments and section descriptors cannot be mixed within a
44283single library element, and you must supply at least one segment or
44284section for each library.
44285
2268b414
JK
44286@node Library List Format for SVR4 Targets
44287@section Library List Format for SVR4 Targets
44288@cindex library list format, remote protocol
44289
44290On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
44291(e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
44292shared libraries. Still a special library list provided by this packet is
44293more efficient for the @value{GDBN} remote protocol.
44294
44295The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
44296loaded libraries and their SVR4 linker parameters. For each library on SVR4
44297target, the following parameters are reported:
44298
44299@itemize @minus
44300@item
44301@code{name}, the absolute file name from the @code{l_name} field of
44302@code{struct link_map}.
44303@item
44304@code{lm} with address of @code{struct link_map} used for TLS
44305(Thread Local Storage) access.
44306@item
44307@code{l_addr}, the displacement as read from the field @code{l_addr} of
44308@code{struct link_map}. For prelinked libraries this is not an absolute
44309memory address. It is a displacement of absolute memory address against
44310address the file was prelinked to during the library load.
44311@item
44312@code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
44313@end itemize
44314
44315Additionally the single @code{main-lm} attribute specifies address of
44316@code{struct link_map} used for the main executable. This parameter is used
44317for TLS access and its presence is optional.
44318
44319@value{GDBN} must be linked with the Expat library to support XML
44320SVR4 library lists. @xref{Expat}.
44321
44322A simple memory map, with two loaded libraries (which do not use prelink),
44323looks like this:
44324
44325@smallexample
44326<library-list-svr4 version="1.0" main-lm="0xe4f8f8">
44327 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
44328 l_ld="0xe4eefc"/>
44329 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
db1ff28b 44330 l_ld="0x152350"/>
2268b414
JK
44331</library-list-svr>
44332@end smallexample
44333
44334The format of an SVR4 library list is described by this DTD:
44335
44336@smallexample
44337<!-- library-list-svr4: Root element with versioning -->
44338<!ELEMENT library-list-svr4 (library)*>
db1ff28b
JK
44339<!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
44340<!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
2268b414 44341<!ELEMENT library EMPTY>
db1ff28b
JK
44342<!ATTLIST library name CDATA #REQUIRED>
44343<!ATTLIST library lm CDATA #REQUIRED>
44344<!ATTLIST library l_addr CDATA #REQUIRED>
44345<!ATTLIST library l_ld CDATA #REQUIRED>
2268b414
JK
44346@end smallexample
44347
79a6e687
BW
44348@node Memory Map Format
44349@section Memory Map Format
68437a39
DJ
44350@cindex memory map format
44351
44352To be able to write into flash memory, @value{GDBN} needs to obtain a
44353memory map from the target. This section describes the format of the
44354memory map.
44355
44356The memory map is obtained using the @samp{qXfer:memory-map:read}
44357(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
44358lists memory regions.
44359
44360@value{GDBN} must be linked with the Expat library to support XML
44361memory maps. @xref{Expat}.
44362
44363The top-level structure of the document is shown below:
68437a39
DJ
44364
44365@smallexample
44366<?xml version="1.0"?>
44367<!DOCTYPE memory-map
44368 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44369 "http://sourceware.org/gdb/gdb-memory-map.dtd">
44370<memory-map>
44371 region...
44372</memory-map>
44373@end smallexample
44374
44375Each region can be either:
44376
44377@itemize
44378
44379@item
44380A region of RAM starting at @var{addr} and extending for @var{length}
44381bytes from there:
44382
44383@smallexample
44384<memory type="ram" start="@var{addr}" length="@var{length}"/>
44385@end smallexample
44386
44387
44388@item
44389A region of read-only memory:
44390
44391@smallexample
44392<memory type="rom" start="@var{addr}" length="@var{length}"/>
44393@end smallexample
44394
44395
44396@item
44397A region of flash memory, with erasure blocks @var{blocksize}
44398bytes in length:
44399
44400@smallexample
44401<memory type="flash" start="@var{addr}" length="@var{length}">
44402 <property name="blocksize">@var{blocksize}</property>
44403</memory>
44404@end smallexample
44405
44406@end itemize
44407
44408Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
44409by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
44410packets to write to addresses in such ranges.
44411
44412The formal DTD for memory map format is given below:
44413
44414@smallexample
44415<!-- ................................................... -->
44416<!-- Memory Map XML DTD ................................ -->
44417<!-- File: memory-map.dtd .............................. -->
44418<!-- .................................... .............. -->
44419<!-- memory-map.dtd -->
44420<!-- memory-map: Root element with versioning -->
5f1ca24a 44421<!ELEMENT memory-map (memory)*>
68437a39 44422<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
5f1ca24a 44423<!ELEMENT memory (property)*>
68437a39
DJ
44424<!-- memory: Specifies a memory region,
44425 and its type, or device. -->
5f1ca24a 44426<!ATTLIST memory type (ram|rom|flash) #REQUIRED
68437a39 44427 start CDATA #REQUIRED
5f1ca24a 44428 length CDATA #REQUIRED>
68437a39
DJ
44429<!-- property: Generic attribute tag -->
44430<!ELEMENT property (#PCDATA | property)*>
5f1ca24a 44431<!ATTLIST property name (blocksize) #REQUIRED>
68437a39
DJ
44432@end smallexample
44433
dc146f7c
VP
44434@node Thread List Format
44435@section Thread List Format
44436@cindex thread list format
44437
44438To efficiently update the list of threads and their attributes,
44439@value{GDBN} issues the @samp{qXfer:threads:read} packet
44440(@pxref{qXfer threads read}) and obtains the XML document with
44441the following structure:
44442
44443@smallexample
44444<?xml version="1.0"?>
44445<threads>
79efa585 44446 <thread id="id" core="0" name="name">
dc146f7c
VP
44447 ... description ...
44448 </thread>
44449</threads>
44450@end smallexample
44451
44452Each @samp{thread} element must have the @samp{id} attribute that
44453identifies the thread (@pxref{thread-id syntax}). The
44454@samp{core} attribute, if present, specifies which processor core
79efa585
SM
44455the thread was last executing on. The @samp{name} attribute, if
44456present, specifies the human-readable name of the thread. The content
44457of the of @samp{thread} element is interpreted as human-readable
f2ff95c5
KB
44458auxiliary information. The @samp{handle} attribute, if present,
44459is a hex encoded representation of the thread handle.
44460
dc146f7c 44461
b3b9301e
PA
44462@node Traceframe Info Format
44463@section Traceframe Info Format
44464@cindex traceframe info format
44465
44466To be able to know which objects in the inferior can be examined when
44467inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
44468memory ranges, registers and trace state variables that have been
44469collected in a traceframe.
44470
44471This list is obtained using the @samp{qXfer:traceframe-info:read}
44472(@pxref{qXfer traceframe info read}) packet and is an XML document.
44473
44474@value{GDBN} must be linked with the Expat library to support XML
44475traceframe info discovery. @xref{Expat}.
44476
44477The top-level structure of the document is shown below:
44478
44479@smallexample
44480<?xml version="1.0"?>
44481<!DOCTYPE traceframe-info
44482 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44483 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
44484<traceframe-info>
44485 block...
44486</traceframe-info>
44487@end smallexample
44488
44489Each traceframe block can be either:
44490
44491@itemize
44492
44493@item
44494A region of collected memory starting at @var{addr} and extending for
44495@var{length} bytes from there:
44496
44497@smallexample
44498<memory start="@var{addr}" length="@var{length}"/>
44499@end smallexample
44500
28a93511
YQ
44501@item
44502A block indicating trace state variable numbered @var{number} has been
44503collected:
44504
44505@smallexample
44506<tvar id="@var{number}"/>
44507@end smallexample
44508
b3b9301e
PA
44509@end itemize
44510
44511The formal DTD for the traceframe info format is given below:
44512
44513@smallexample
28a93511 44514<!ELEMENT traceframe-info (memory | tvar)* >
b3b9301e
PA
44515<!ATTLIST traceframe-info version CDATA #FIXED "1.0">
44516
44517<!ELEMENT memory EMPTY>
44518<!ATTLIST memory start CDATA #REQUIRED
44519 length CDATA #REQUIRED>
28a93511
YQ
44520<!ELEMENT tvar>
44521<!ATTLIST tvar id CDATA #REQUIRED>
b3b9301e
PA
44522@end smallexample
44523
2ae8c8e7
MM
44524@node Branch Trace Format
44525@section Branch Trace Format
44526@cindex branch trace format
44527
44528In order to display the branch trace of an inferior thread,
44529@value{GDBN} needs to obtain the list of branches. This list is
44530represented as list of sequential code blocks that are connected via
44531branches. The code in each block has been executed sequentially.
44532
44533This list is obtained using the @samp{qXfer:btrace:read}
44534(@pxref{qXfer btrace read}) packet and is an XML document.
44535
44536@value{GDBN} must be linked with the Expat library to support XML
44537traceframe info discovery. @xref{Expat}.
44538
44539The top-level structure of the document is shown below:
44540
44541@smallexample
44542<?xml version="1.0"?>
44543<!DOCTYPE btrace
44544 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
44545 "http://sourceware.org/gdb/gdb-btrace.dtd">
44546<btrace>
44547 block...
44548</btrace>
44549@end smallexample
44550
44551@itemize
44552
44553@item
44554A block of sequentially executed instructions starting at @var{begin}
44555and ending at @var{end}:
44556
44557@smallexample
44558<block begin="@var{begin}" end="@var{end}"/>
44559@end smallexample
44560
44561@end itemize
44562
44563The formal DTD for the branch trace format is given below:
44564
44565@smallexample
b20a6524 44566<!ELEMENT btrace (block* | pt) >
2ae8c8e7
MM
44567<!ATTLIST btrace version CDATA #FIXED "1.0">
44568
44569<!ELEMENT block EMPTY>
44570<!ATTLIST block begin CDATA #REQUIRED
44571 end CDATA #REQUIRED>
b20a6524
MM
44572
44573<!ELEMENT pt (pt-config?, raw?)>
44574
44575<!ELEMENT pt-config (cpu?)>
44576
44577<!ELEMENT cpu EMPTY>
44578<!ATTLIST cpu vendor CDATA #REQUIRED
44579 family CDATA #REQUIRED
44580 model CDATA #REQUIRED
44581 stepping CDATA #REQUIRED>
44582
44583<!ELEMENT raw (#PCDATA)>
2ae8c8e7
MM
44584@end smallexample
44585
f4abbc16
MM
44586@node Branch Trace Configuration Format
44587@section Branch Trace Configuration Format
44588@cindex branch trace configuration format
44589
44590For each inferior thread, @value{GDBN} can obtain the branch trace
44591configuration using the @samp{qXfer:btrace-conf:read}
44592(@pxref{qXfer btrace-conf read}) packet.
44593
44594The configuration describes the branch trace format and configuration
d33501a5
MM
44595settings for that format. The following information is described:
44596
44597@table @code
44598@item bts
44599This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
44600@table @code
44601@item size
44602The size of the @acronym{BTS} ring buffer in bytes.
44603@end table
b20a6524 44604@item pt
bc504a31 44605This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
b20a6524
MM
44606PT}) format.
44607@table @code
44608@item size
bc504a31 44609The size of the @acronym{Intel PT} ring buffer in bytes.
b20a6524 44610@end table
d33501a5 44611@end table
f4abbc16
MM
44612
44613@value{GDBN} must be linked with the Expat library to support XML
44614branch trace configuration discovery. @xref{Expat}.
44615
44616The formal DTD for the branch trace configuration format is given below:
44617
44618@smallexample
b20a6524 44619<!ELEMENT btrace-conf (bts?, pt?)>
f4abbc16
MM
44620<!ATTLIST btrace-conf version CDATA #FIXED "1.0">
44621
44622<!ELEMENT bts EMPTY>
d33501a5 44623<!ATTLIST bts size CDATA #IMPLIED>
b20a6524
MM
44624
44625<!ELEMENT pt EMPTY>
44626<!ATTLIST pt size CDATA #IMPLIED>
f4abbc16
MM
44627@end smallexample
44628
f418dd93
DJ
44629@include agentexpr.texi
44630
23181151
DJ
44631@node Target Descriptions
44632@appendix Target Descriptions
44633@cindex target descriptions
44634
23181151
DJ
44635One of the challenges of using @value{GDBN} to debug embedded systems
44636is that there are so many minor variants of each processor
44637architecture in use. It is common practice for vendors to start with
eb17f351 44638a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
23181151
DJ
44639and then make changes to adapt it to a particular market niche. Some
44640architectures have hundreds of variants, available from dozens of
44641vendors. This leads to a number of problems:
44642
44643@itemize @bullet
44644@item
44645With so many different customized processors, it is difficult for
44646the @value{GDBN} maintainers to keep up with the changes.
44647@item
44648Since individual variants may have short lifetimes or limited
44649audiences, it may not be worthwhile to carry information about every
44650variant in the @value{GDBN} source tree.
44651@item
44652When @value{GDBN} does support the architecture of the embedded system
44653at hand, the task of finding the correct architecture name to give the
44654@command{set architecture} command can be error-prone.
44655@end itemize
44656
44657To address these problems, the @value{GDBN} remote protocol allows a
44658target system to not only identify itself to @value{GDBN}, but to
44659actually describe its own features. This lets @value{GDBN} support
44660processor variants it has never seen before --- to the extent that the
44661descriptions are accurate, and that @value{GDBN} understands them.
44662
9cceb671
DJ
44663@value{GDBN} must be linked with the Expat library to support XML
44664target descriptions. @xref{Expat}.
123dc839 44665
23181151
DJ
44666@menu
44667* Retrieving Descriptions:: How descriptions are fetched from a target.
44668* Target Description Format:: The contents of a target description.
123dc839
DJ
44669* Predefined Target Types:: Standard types available for target
44670 descriptions.
81516450 44671* Enum Target Types:: How to define enum target types.
123dc839 44672* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
44673@end menu
44674
44675@node Retrieving Descriptions
44676@section Retrieving Descriptions
44677
44678Target descriptions can be read from the target automatically, or
44679specified by the user manually. The default behavior is to read the
44680description from the target. @value{GDBN} retrieves it via the remote
44681protocol using @samp{qXfer} requests (@pxref{General Query Packets,
44682qXfer}). The @var{annex} in the @samp{qXfer} packet will be
44683@samp{target.xml}. The contents of the @samp{target.xml} annex are an
44684XML document, of the form described in @ref{Target Description
44685Format}.
44686
44687Alternatively, you can specify a file to read for the target description.
44688If a file is set, the target will not be queried. The commands to
44689specify a file are:
44690
44691@table @code
44692@cindex set tdesc filename
44693@item set tdesc filename @var{path}
44694Read the target description from @var{path}.
44695
44696@cindex unset tdesc filename
44697@item unset tdesc filename
44698Do not read the XML target description from a file. @value{GDBN}
44699will use the description supplied by the current target.
44700
44701@cindex show tdesc filename
44702@item show tdesc filename
44703Show the filename to read for a target description, if any.
44704@end table
44705
44706
44707@node Target Description Format
44708@section Target Description Format
44709@cindex target descriptions, XML format
44710
44711A target description annex is an @uref{http://www.w3.org/XML/, XML}
44712document which complies with the Document Type Definition provided in
44713the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
44714means you can use generally available tools like @command{xmllint} to
44715check that your feature descriptions are well-formed and valid.
44716However, to help people unfamiliar with XML write descriptions for
44717their targets, we also describe the grammar here.
44718
123dc839
DJ
44719Target descriptions can identify the architecture of the remote target
44720and (for some architectures) provide information about custom register
08d16641
PA
44721sets. They can also identify the OS ABI of the remote target.
44722@value{GDBN} can use this information to autoconfigure for your
123dc839 44723target, or to warn you if you connect to an unsupported target.
23181151
DJ
44724
44725Here is a simple target description:
44726
123dc839 44727@smallexample
1780a0ed 44728<target version="1.0">
23181151
DJ
44729 <architecture>i386:x86-64</architecture>
44730</target>
123dc839 44731@end smallexample
23181151
DJ
44732
44733@noindent
44734This minimal description only says that the target uses
44735the x86-64 architecture.
44736
123dc839
DJ
44737A target description has the following overall form, with [ ] marking
44738optional elements and @dots{} marking repeatable elements. The elements
44739are explained further below.
23181151 44740
123dc839 44741@smallexample
23181151
DJ
44742<?xml version="1.0"?>
44743<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 44744<target version="1.0">
123dc839 44745 @r{[}@var{architecture}@r{]}
08d16641 44746 @r{[}@var{osabi}@r{]}
e35359c5 44747 @r{[}@var{compatible}@r{]}
123dc839 44748 @r{[}@var{feature}@dots{}@r{]}
23181151 44749</target>
123dc839 44750@end smallexample
23181151
DJ
44751
44752@noindent
44753The description is generally insensitive to whitespace and line
44754breaks, under the usual common-sense rules. The XML version
44755declaration and document type declaration can generally be omitted
44756(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
44757useful for XML validation tools. The @samp{version} attribute for
44758@samp{<target>} may also be omitted, but we recommend
44759including it; if future versions of @value{GDBN} use an incompatible
44760revision of @file{gdb-target.dtd}, they will detect and report
44761the version mismatch.
23181151 44762
108546a0
DJ
44763@subsection Inclusion
44764@cindex target descriptions, inclusion
44765@cindex XInclude
44766@ifnotinfo
44767@cindex <xi:include>
44768@end ifnotinfo
44769
44770It can sometimes be valuable to split a target description up into
44771several different annexes, either for organizational purposes, or to
44772share files between different possible target descriptions. You can
44773divide a description into multiple files by replacing any element of
44774the target description with an inclusion directive of the form:
44775
123dc839 44776@smallexample
108546a0 44777<xi:include href="@var{document}"/>
123dc839 44778@end smallexample
108546a0
DJ
44779
44780@noindent
44781When @value{GDBN} encounters an element of this form, it will retrieve
44782the named XML @var{document}, and replace the inclusion directive with
44783the contents of that document. If the current description was read
44784using @samp{qXfer}, then so will be the included document;
44785@var{document} will be interpreted as the name of an annex. If the
44786current description was read from a file, @value{GDBN} will look for
44787@var{document} as a file in the same directory where it found the
44788original description.
44789
123dc839
DJ
44790@subsection Architecture
44791@cindex <architecture>
44792
44793An @samp{<architecture>} element has this form:
44794
44795@smallexample
44796 <architecture>@var{arch}</architecture>
44797@end smallexample
44798
e35359c5
UW
44799@var{arch} is one of the architectures from the set accepted by
44800@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
123dc839 44801
08d16641
PA
44802@subsection OS ABI
44803@cindex @code{<osabi>}
44804
44805This optional field was introduced in @value{GDBN} version 7.0.
44806Previous versions of @value{GDBN} ignore it.
44807
44808An @samp{<osabi>} element has this form:
44809
44810@smallexample
44811 <osabi>@var{abi-name}</osabi>
44812@end smallexample
44813
44814@var{abi-name} is an OS ABI name from the same selection accepted by
44815@w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
44816
e35359c5
UW
44817@subsection Compatible Architecture
44818@cindex @code{<compatible>}
44819
44820This optional field was introduced in @value{GDBN} version 7.0.
44821Previous versions of @value{GDBN} ignore it.
44822
44823A @samp{<compatible>} element has this form:
44824
44825@smallexample
44826 <compatible>@var{arch}</compatible>
44827@end smallexample
44828
44829@var{arch} is one of the architectures from the set accepted by
44830@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
44831
44832A @samp{<compatible>} element is used to specify that the target
44833is able to run binaries in some other than the main target architecture
44834given by the @samp{<architecture>} element. For example, on the
44835Cell Broadband Engine, the main architecture is @code{powerpc:common}
44836or @code{powerpc:common64}, but the system is able to run binaries
44837in the @code{spu} architecture as well. The way to describe this
44838capability with @samp{<compatible>} is as follows:
44839
44840@smallexample
44841 <architecture>powerpc:common</architecture>
44842 <compatible>spu</compatible>
44843@end smallexample
44844
123dc839
DJ
44845@subsection Features
44846@cindex <feature>
44847
44848Each @samp{<feature>} describes some logical portion of the target
44849system. Features are currently used to describe available CPU
44850registers and the types of their contents. A @samp{<feature>} element
44851has this form:
44852
44853@smallexample
44854<feature name="@var{name}">
44855 @r{[}@var{type}@dots{}@r{]}
44856 @var{reg}@dots{}
44857</feature>
44858@end smallexample
44859
44860@noindent
44861Each feature's name should be unique within the description. The name
44862of a feature does not matter unless @value{GDBN} has some special
44863knowledge of the contents of that feature; if it does, the feature
44864should have its standard name. @xref{Standard Target Features}.
44865
44866@subsection Types
44867
44868Any register's value is a collection of bits which @value{GDBN} must
44869interpret. The default interpretation is a two's complement integer,
44870but other types can be requested by name in the register description.
44871Some predefined types are provided by @value{GDBN} (@pxref{Predefined
81516450
DE
44872Target Types}), and the description can define additional composite
44873and enum types.
123dc839
DJ
44874
44875Each type element must have an @samp{id} attribute, which gives
44876a unique (within the containing @samp{<feature>}) name to the type.
44877Types must be defined before they are used.
44878
44879@cindex <vector>
44880Some targets offer vector registers, which can be treated as arrays
44881of scalar elements. These types are written as @samp{<vector>} elements,
44882specifying the array element type, @var{type}, and the number of elements,
44883@var{count}:
44884
44885@smallexample
44886<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
44887@end smallexample
44888
44889@cindex <union>
44890If a register's value is usefully viewed in multiple ways, define it
44891with a union type containing the useful representations. The
44892@samp{<union>} element contains one or more @samp{<field>} elements,
44893each of which has a @var{name} and a @var{type}:
44894
44895@smallexample
44896<union id="@var{id}">
44897 <field name="@var{name}" type="@var{type}"/>
44898 @dots{}
44899</union>
44900@end smallexample
44901
f5dff777 44902@cindex <struct>
81516450 44903@cindex <flags>
f5dff777 44904If a register's value is composed from several separate values, define
81516450
DE
44905it with either a structure type or a flags type.
44906A flags type may only contain bitfields.
44907A structure type may either contain only bitfields or contain no bitfields.
44908If the value contains only bitfields, its total size in bytes must be
44909specified.
44910
44911Non-bitfield values have a @var{name} and @var{type}.
f5dff777
DJ
44912
44913@smallexample
81516450
DE
44914<struct id="@var{id}">
44915 <field name="@var{name}" type="@var{type}"/>
f5dff777
DJ
44916 @dots{}
44917</struct>
44918@end smallexample
44919
81516450
DE
44920Both @var{name} and @var{type} values are required.
44921No implicit padding is added.
44922
44923Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
f5dff777
DJ
44924
44925@smallexample
81516450
DE
44926<struct id="@var{id}" size="@var{size}">
44927 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
f5dff777
DJ
44928 @dots{}
44929</struct>
44930@end smallexample
44931
f5dff777
DJ
44932@smallexample
44933<flags id="@var{id}" size="@var{size}">
81516450 44934 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
f5dff777
DJ
44935 @dots{}
44936</flags>
44937@end smallexample
44938
81516450
DE
44939The @var{name} value is required.
44940Bitfield values may be named with the empty string, @samp{""},
44941in which case the field is ``filler'' and its value is not printed.
44942Not all bits need to be specified, so ``filler'' fields are optional.
44943
ee8da4b8
DE
44944The @var{start} and @var{end} values are required, and @var{type}
44945is optional.
81516450
DE
44946The field's @var{start} must be less than or equal to its @var{end},
44947and zero represents the least significant bit.
81516450 44948
ee8da4b8
DE
44949The default value of @var{type} is @code{bool} for single bit fields,
44950and an unsigned integer otherwise.
81516450
DE
44951
44952Which to choose? Structures or flags?
44953
44954Registers defined with @samp{flags} have these advantages over
44955defining them with @samp{struct}:
44956
44957@itemize @bullet
44958@item
44959Arithmetic may be performed on them as if they were integers.
44960@item
44961They are printed in a more readable fashion.
44962@end itemize
44963
44964Registers defined with @samp{struct} have one advantage over
44965defining them with @samp{flags}:
44966
44967@itemize @bullet
44968@item
44969One can fetch individual fields like in @samp{C}.
44970
44971@smallexample
44972(gdb) print $my_struct_reg.field3
44973$1 = 42
44974@end smallexample
44975
44976@end itemize
44977
123dc839
DJ
44978@subsection Registers
44979@cindex <reg>
44980
44981Each register is represented as an element with this form:
44982
44983@smallexample
44984<reg name="@var{name}"
44985 bitsize="@var{size}"
44986 @r{[}regnum="@var{num}"@r{]}
44987 @r{[}save-restore="@var{save-restore}"@r{]}
44988 @r{[}type="@var{type}"@r{]}
44989 @r{[}group="@var{group}"@r{]}/>
44990@end smallexample
44991
44992@noindent
44993The components are as follows:
44994
44995@table @var
44996
44997@item name
44998The register's name; it must be unique within the target description.
44999
45000@item bitsize
45001The register's size, in bits.
45002
45003@item regnum
45004The register's number. If omitted, a register's number is one greater
45005than that of the previous register (either in the current feature or in
177b42fe 45006a preceding feature); the first register in the target description
123dc839
DJ
45007defaults to zero. This register number is used to read or write
45008the register; e.g.@: it is used in the remote @code{p} and @code{P}
45009packets, and registers appear in the @code{g} and @code{G} packets
45010in order of increasing register number.
45011
45012@item save-restore
45013Whether the register should be preserved across inferior function
45014calls; this must be either @code{yes} or @code{no}. The default is
45015@code{yes}, which is appropriate for most registers except for
45016some system control registers; this is not related to the target's
45017ABI.
45018
45019@item type
697aa1b7 45020The type of the register. It may be a predefined type, a type
123dc839
DJ
45021defined in the current feature, or one of the special types @code{int}
45022and @code{float}. @code{int} is an integer type of the correct size
45023for @var{bitsize}, and @code{float} is a floating point type (in the
45024architecture's normal floating point format) of the correct size for
45025@var{bitsize}. The default is @code{int}.
45026
45027@item group
cef0f868
SH
45028The register group to which this register belongs. It can be one of the
45029standard register groups @code{general}, @code{float}, @code{vector} or an
45030arbitrary string. Group names should be limited to alphanumeric characters.
45031If a group name is made up of multiple words the words may be separated by
45032hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
45033@var{group} is specified, @value{GDBN} will not display the register in
45034@code{info registers}.
123dc839
DJ
45035
45036@end table
45037
45038@node Predefined Target Types
45039@section Predefined Target Types
45040@cindex target descriptions, predefined types
45041
45042Type definitions in the self-description can build up composite types
45043from basic building blocks, but can not define fundamental types. Instead,
45044standard identifiers are provided by @value{GDBN} for the fundamental
45045types. The currently supported types are:
45046
45047@table @code
45048
81516450
DE
45049@item bool
45050Boolean type, occupying a single bit.
45051
123dc839
DJ
45052@item int8
45053@itemx int16
d1908f2d 45054@itemx int24
123dc839
DJ
45055@itemx int32
45056@itemx int64
7cc46491 45057@itemx int128
123dc839
DJ
45058Signed integer types holding the specified number of bits.
45059
45060@item uint8
45061@itemx uint16
d1908f2d 45062@itemx uint24
123dc839
DJ
45063@itemx uint32
45064@itemx uint64
7cc46491 45065@itemx uint128
123dc839
DJ
45066Unsigned integer types holding the specified number of bits.
45067
45068@item code_ptr
45069@itemx data_ptr
45070Pointers to unspecified code and data. The program counter and
45071any dedicated return address register may be marked as code
45072pointers; printing a code pointer converts it into a symbolic
45073address. The stack pointer and any dedicated address registers
45074may be marked as data pointers.
45075
6e3bbd1a
PB
45076@item ieee_single
45077Single precision IEEE floating point.
45078
45079@item ieee_double
45080Double precision IEEE floating point.
45081
123dc839
DJ
45082@item arm_fpa_ext
45083The 12-byte extended precision format used by ARM FPA registers.
45084
075b51b7
L
45085@item i387_ext
45086The 10-byte extended precision format used by x87 registers.
45087
45088@item i386_eflags
4508932bit @sc{eflags} register used by x86.
45090
45091@item i386_mxcsr
4509232bit @sc{mxcsr} register used by x86.
45093
123dc839
DJ
45094@end table
45095
81516450
DE
45096@node Enum Target Types
45097@section Enum Target Types
45098@cindex target descriptions, enum types
45099
45100Enum target types are useful in @samp{struct} and @samp{flags}
45101register descriptions. @xref{Target Description Format}.
45102
45103Enum types have a name, size and a list of name/value pairs.
45104
45105@smallexample
45106<enum id="@var{id}" size="@var{size}">
45107 <evalue name="@var{name}" value="@var{value}"/>
45108 @dots{}
45109</enum>
45110@end smallexample
45111
45112Enums must be defined before they are used.
45113
45114@smallexample
45115<enum id="levels_type" size="4">
45116 <evalue name="low" value="0"/>
45117 <evalue name="high" value="1"/>
45118</enum>
45119<flags id="flags_type" size="4">
45120 <field name="X" start="0"/>
45121 <field name="LEVEL" start="1" end="1" type="levels_type"/>
45122</flags>
45123<reg name="flags" bitsize="32" type="flags_type"/>
45124@end smallexample
45125
45126Given that description, a value of 3 for the @samp{flags} register
45127would be printed as:
45128
45129@smallexample
45130(gdb) info register flags
45131flags 0x3 [ X LEVEL=high ]
45132@end smallexample
45133
123dc839
DJ
45134@node Standard Target Features
45135@section Standard Target Features
45136@cindex target descriptions, standard features
45137
45138A target description must contain either no registers or all the
45139target's registers. If the description contains no registers, then
45140@value{GDBN} will assume a default register layout, selected based on
45141the architecture. If the description contains any registers, the
45142default layout will not be used; the standard registers must be
45143described in the target description, in such a way that @value{GDBN}
45144can recognize them.
45145
45146This is accomplished by giving specific names to feature elements
45147which contain standard registers. @value{GDBN} will look for features
45148with those names and verify that they contain the expected registers;
45149if any known feature is missing required registers, or if any required
45150feature is missing, @value{GDBN} will reject the target
45151description. You can add additional registers to any of the
45152standard features --- @value{GDBN} will display them just as if
45153they were added to an unrecognized feature.
45154
45155This section lists the known features and their expected contents.
45156Sample XML documents for these features are included in the
45157@value{GDBN} source tree, in the directory @file{gdb/features}.
45158
45159Names recognized by @value{GDBN} should include the name of the
45160company or organization which selected the name, and the overall
45161architecture to which the feature applies; so e.g.@: the feature
45162containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
45163
ff6f572f
DJ
45164The names of registers are not case sensitive for the purpose
45165of recognizing standard features, but @value{GDBN} will only display
45166registers using the capitalization used in the description.
45167
e9c17194 45168@menu
430ed3f0 45169* AArch64 Features::
ad0a504f 45170* ARC Features::
e9c17194 45171* ARM Features::
3bb8d5c3 45172* i386 Features::
164224e9 45173* MicroBlaze Features::
1e26b4f8 45174* MIPS Features::
e9c17194 45175* M68K Features::
a28d8e50 45176* NDS32 Features::
a1217d97 45177* Nios II Features::
a994fec4 45178* OpenRISC 1000 Features::
1e26b4f8 45179* PowerPC Features::
b5ffee31 45180* RISC-V Features::
e3ec872f 45181* RX Features::
4ac33720 45182* S/390 and System z Features::
3f7b46f2 45183* Sparc Features::
224bbe49 45184* TIC6x Features::
e9c17194
VP
45185@end menu
45186
45187
430ed3f0
MS
45188@node AArch64 Features
45189@subsection AArch64 Features
45190@cindex target descriptions, AArch64 features
45191
45192The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
45193targets. It should contain registers @samp{x0} through @samp{x30},
45194@samp{sp}, @samp{pc}, and @samp{cpsr}.
45195
45196The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
45197it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
45198and @samp{fpcr}.
45199
95228a0d
AH
45200The @samp{org.gnu.gdb.aarch64.sve} feature is optional. If present,
45201it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
45202through @samp{p15}, @samp{ffr} and @samp{vg}.
45203
6dc0ebde
AH
45204The @samp{org.gnu.gdb.aarch64.pauth} feature is optional. If present,
45205it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
45206
ad0a504f
AK
45207@node ARC Features
45208@subsection ARC Features
45209@cindex target descriptions, ARC Features
45210
45211ARC processors are highly configurable, so even core registers and their number
45212are not completely predetermined. In addition flags and PC registers which are
45213important to @value{GDBN} are not ``core'' registers in ARC. It is required
45214that one of the core registers features is present.
45215@samp{org.gnu.gdb.arc.aux-minimal} feature is mandatory.
45216
45217The @samp{org.gnu.gdb.arc.core.v2} feature is required for ARC EM and ARC HS
45218targets with a normal register file. It should contain registers @samp{r0}
45219through @samp{r25}, @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink},
45220@samp{lp_count} and @samp{pcl}. This feature may contain register @samp{ilink}
45221and any of extension core registers @samp{r32} through @samp{r59/acch}.
45222@samp{ilink} and extension core registers are not available to read/write, when
45223debugging GNU/Linux applications, thus @samp{ilink} is made optional.
45224
45225The @samp{org.gnu.gdb.arc.core-reduced.v2} feature is required for ARC EM and
45226ARC HS targets with a reduced register file. It should contain registers
45227@samp{r0} through @samp{r3}, @samp{r10} through @samp{r15}, @samp{gp},
45228@samp{fp}, @samp{sp}, @samp{r30}, @samp{blink}, @samp{lp_count} and @samp{pcl}.
45229This feature may contain register @samp{ilink} and any of extension core
45230registers @samp{r32} through @samp{r59/acch}.
45231
45232The @samp{org.gnu.gdb.arc.core.arcompact} feature is required for ARCompact
45233targets with a normal register file. It should contain registers @samp{r0}
45234through @samp{r25}, @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink},
45235@samp{lp_count} and @samp{pcl}. This feature may contain registers
45236@samp{ilink1}, @samp{ilink2} and any of extension core registers @samp{r32}
45237through @samp{r59/acch}. @samp{ilink1} and @samp{ilink2} and extension core
45238registers are not available when debugging GNU/Linux applications. The only
45239difference with @samp{org.gnu.gdb.arc.core.v2} feature is in the names of
45240@samp{ilink1} and @samp{ilink2} registers and that @samp{r30} is mandatory in
45241ARC v2, but @samp{ilink2} is optional on ARCompact.
45242
45243The @samp{org.gnu.gdb.arc.aux-minimal} feature is required for all ARC
45244targets. It should contain registers @samp{pc} and @samp{status32}.
45245
e9c17194 45246@node ARM Features
123dc839
DJ
45247@subsection ARM Features
45248@cindex target descriptions, ARM features
45249
9779414d
DJ
45250The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
45251ARM targets.
123dc839
DJ
45252It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
45253@samp{lr}, @samp{pc}, and @samp{cpsr}.
45254
9779414d
DJ
45255For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
45256feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
45257registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
45258and @samp{xpsr}.
45259
123dc839
DJ
45260The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
45261should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
45262
ff6f572f
DJ
45263The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
45264it should contain at least registers @samp{wR0} through @samp{wR15} and
45265@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
45266@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 45267
58d6951d
DJ
45268The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
45269should contain at least registers @samp{d0} through @samp{d15}. If
45270they are present, @samp{d16} through @samp{d31} should also be included.
45271@value{GDBN} will synthesize the single-precision registers from
45272halves of the double-precision registers.
45273
45274The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
45275need to contain registers; it instructs @value{GDBN} to display the
45276VFP double-precision registers as vectors and to synthesize the
45277quad-precision registers from pairs of double-precision registers.
45278If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
45279be present and include 32 double-precision registers.
45280
3bb8d5c3
L
45281@node i386 Features
45282@subsection i386 Features
45283@cindex target descriptions, i386 features
45284
45285The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
45286targets. It should describe the following registers:
45287
45288@itemize @minus
45289@item
45290@samp{eax} through @samp{edi} plus @samp{eip} for i386
45291@item
45292@samp{rax} through @samp{r15} plus @samp{rip} for amd64
45293@item
45294@samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
45295@samp{fs}, @samp{gs}
45296@item
45297@samp{st0} through @samp{st7}
45298@item
45299@samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
45300@samp{foseg}, @samp{fooff} and @samp{fop}
45301@end itemize
45302
45303The register sets may be different, depending on the target.
45304
3a13a53b 45305The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
3bb8d5c3
L
45306describe registers:
45307
45308@itemize @minus
45309@item
45310@samp{xmm0} through @samp{xmm7} for i386
45311@item
45312@samp{xmm0} through @samp{xmm15} for amd64
45313@item
45314@samp{mxcsr}
45315@end itemize
45316
3a13a53b
L
45317The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
45318@samp{org.gnu.gdb.i386.sse} feature. It should
f68eb612
L
45319describe the upper 128 bits of @sc{ymm} registers:
45320
45321@itemize @minus
45322@item
45323@samp{ymm0h} through @samp{ymm7h} for i386
45324@item
45325@samp{ymm0h} through @samp{ymm15h} for amd64
f68eb612
L
45326@end itemize
45327
bc504a31 45328The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
ca8941bb
WT
45329Memory Protection Extension (MPX). It should describe the following registers:
45330
45331@itemize @minus
45332@item
45333@samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
45334@item
45335@samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
45336@end itemize
45337
3bb8d5c3
L
45338The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
45339describe a single register, @samp{orig_eax}.
45340
2735833d
WT
45341The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
45342describe two system registers: @samp{fs_base} and @samp{gs_base}.
45343
01f9f808
MS
45344The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
45345@samp{org.gnu.gdb.i386.avx} feature. It should
45346describe additional @sc{xmm} registers:
45347
45348@itemize @minus
45349@item
45350@samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
45351@end itemize
45352
45353It should describe the upper 128 bits of additional @sc{ymm} registers:
45354
45355@itemize @minus
45356@item
45357@samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
45358@end itemize
45359
45360It should
45361describe the upper 256 bits of @sc{zmm} registers:
45362
45363@itemize @minus
45364@item
45365@samp{zmm0h} through @samp{zmm7h} for i386.
45366@item
45367@samp{zmm0h} through @samp{zmm15h} for amd64.
45368@end itemize
45369
45370It should
45371describe the additional @sc{zmm} registers:
45372
45373@itemize @minus
45374@item
45375@samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
45376@end itemize
45377
51547df6
MS
45378The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
45379describe a single register, @samp{pkru}. It is a 32-bit register
45380valid for i386 and amd64.
45381
164224e9
ME
45382@node MicroBlaze Features
45383@subsection MicroBlaze Features
45384@cindex target descriptions, MicroBlaze features
45385
45386The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
45387targets. It should contain registers @samp{r0} through @samp{r31},
45388@samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
45389@samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
45390@samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
45391
45392The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
45393If present, it should contain registers @samp{rshr} and @samp{rslr}
45394
1e26b4f8 45395@node MIPS Features
eb17f351
EZ
45396@subsection @acronym{MIPS} Features
45397@cindex target descriptions, @acronym{MIPS} features
f8b73d13 45398
eb17f351 45399The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
f8b73d13
DJ
45400It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
45401@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
45402on the target.
45403
45404The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
45405contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
45406registers. They may be 32-bit or 64-bit depending on the target.
45407
45408The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
45409it may be optional in a future version of @value{GDBN}. It should
45410contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
45411@samp{fir}. They may be 32-bit or 64-bit depending on the target.
45412
1faeff08
MR
45413The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
45414contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
45415@samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
45416be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
45417
822b6570
DJ
45418The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
45419contain a single register, @samp{restart}, which is used by the
45420Linux kernel to control restartable syscalls.
45421
e9c17194
VP
45422@node M68K Features
45423@subsection M68K Features
45424@cindex target descriptions, M68K features
45425
45426@table @code
45427@item @samp{org.gnu.gdb.m68k.core}
45428@itemx @samp{org.gnu.gdb.coldfire.core}
45429@itemx @samp{org.gnu.gdb.fido.core}
45430One of those features must be always present.
249e1128 45431The feature that is present determines which flavor of m68k is
e9c17194
VP
45432used. The feature that is present should contain registers
45433@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
45434@samp{sp}, @samp{ps} and @samp{pc}.
45435
45436@item @samp{org.gnu.gdb.coldfire.fp}
45437This feature is optional. If present, it should contain registers
45438@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
45439@samp{fpiaddr}.
b7d2fe14
TT
45440
45441Note that, despite the fact that this feature's name says
45442@samp{coldfire}, it is used to describe any floating point registers.
45443The size of the registers must match the main m68k flavor; so, for
45444example, if the primary feature is reported as @samp{coldfire}, then
4544564-bit floating point registers are required.
e9c17194
VP
45446@end table
45447
a28d8e50
YTL
45448@node NDS32 Features
45449@subsection NDS32 Features
45450@cindex target descriptions, NDS32 features
45451
45452The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
45453targets. It should contain at least registers @samp{r0} through
45454@samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
45455and @samp{pc}.
45456
45457The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
45458it should contain 64-bit double-precision floating-point registers
45459@samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
45460@samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
45461
45462@emph{Note:} The first sixteen 64-bit double-precision floating-point
45463registers are overlapped with the thirty-two 32-bit single-precision
45464floating-point registers. The 32-bit single-precision registers, if
45465not being listed explicitly, will be synthesized from halves of the
45466overlapping 64-bit double-precision registers. Listing 32-bit
45467single-precision registers explicitly is deprecated, and the
45468support to it could be totally removed some day.
45469
a1217d97
SL
45470@node Nios II Features
45471@subsection Nios II Features
45472@cindex target descriptions, Nios II features
45473
45474The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
45475targets. It should contain the 32 core registers (@samp{zero},
45476@samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
45477@samp{pc}, and the 16 control registers (@samp{status} through
45478@samp{mpuacc}).
45479
a994fec4
FJ
45480@node OpenRISC 1000 Features
45481@subsection Openrisc 1000 Features
45482@cindex target descriptions, OpenRISC 1000 features
45483
45484The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
45485targets. It should contain the 32 general purpose registers (@samp{r0}
45486through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
45487
1e26b4f8 45488@node PowerPC Features
7cc46491
DJ
45489@subsection PowerPC Features
45490@cindex target descriptions, PowerPC features
45491
45492The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
45493targets. It should contain registers @samp{r0} through @samp{r31},
45494@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
45495@samp{xer}. They may be 32-bit or 64-bit depending on the target.
45496
45497The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
45498contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
45499
45500The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
6f072a10
PFC
45501contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
45502@samp{vrsave}. @value{GDBN} will define pseudo-registers @samp{v0}
45503through @samp{v31} as aliases for the corresponding @samp{vrX}
45504registers.
7cc46491 45505
677c5bb1 45506The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
4b905ae1
PFC
45507contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN} will
45508combine these registers with the floating point registers (@samp{f0}
45509through @samp{f31}) and the altivec registers (@samp{vr0} through
45510@samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
45511@samp{vs63}, the set of vector-scalar registers for POWER7.
45512Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
45513@samp{org.gnu.gdb.power.altivec}.
677c5bb1 45514
7cc46491
DJ
45515The @samp{org.gnu.gdb.power.spe} feature is optional. It should
45516contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
45517@samp{spefscr}. SPE targets should provide 32-bit registers in
45518@samp{org.gnu.gdb.power.core} and provide the upper halves in
45519@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
45520these to present registers @samp{ev0} through @samp{ev31} to the
45521user.
45522
7ca18ed6
EBM
45523The @samp{org.gnu.gdb.power.ppr} feature is optional. It should
45524contain the 64-bit register @samp{ppr}.
45525
45526The @samp{org.gnu.gdb.power.dscr} feature is optional. It should
45527contain the 64-bit register @samp{dscr}.
45528
f2cf6173
EBM
45529The @samp{org.gnu.gdb.power.tar} feature is optional. It should
45530contain the 64-bit register @samp{tar}.
45531
232bfb86
EBM
45532The @samp{org.gnu.gdb.power.ebb} feature is optional. It should
45533contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
4553464-bit wide.
45535
45536The @samp{org.gnu.gdb.power.linux.pmu} feature is optional. It should
45537contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
45538and @samp{sier}, all 64-bit wide. This is the subset of the isa 2.07
45539server PMU registers provided by @sc{gnu}/Linux.
45540
8d619c01
EBM
45541The @samp{org.gnu.gdb.power.htm.spr} feature is optional. It should
45542contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
4554364-bit wide.
45544
45545The @samp{org.gnu.gdb.power.htm.core} feature is optional. It should
45546contain the checkpointed general-purpose registers @samp{cr0} through
45547@samp{cr31}, as well as the checkpointed registers @samp{clr} and
45548@samp{cctr}. These registers may all be either 32-bit or 64-bit
45549depending on the target. It should also contain the checkpointed
45550registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
45551wide.
45552
45553The @samp{org.gnu.gdb.power.htm.fpu} feature is optional. It should
45554contain the checkpointed 64-bit floating-point registers @samp{cf0}
45555through @samp{cf31}, as well as the checkpointed 64-bit register
45556@samp{cfpscr}.
45557
45558The @samp{org.gnu.gdb.power.htm.altivec} feature is optional. It
45559should contain the checkpointed altivec registers @samp{cvr0} through
45560@samp{cvr31}, all 128-bit wide. It should also contain the
45561checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
45562wide.
45563
45564The @samp{org.gnu.gdb.power.htm.vsx} feature is optional. It should
45565contain registers @samp{cvs0h} through @samp{cvs31h}. @value{GDBN}
45566will combine these registers with the checkpointed floating point
45567registers (@samp{cf0} through @samp{cf31}) and the checkpointed
45568altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
45569128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
45570@samp{cvs63}. Therefore, this feature requires both
45571@samp{org.gnu.gdb.power.htm.altivec} and
45572@samp{org.gnu.gdb.power.htm.fpu}.
45573
45574The @samp{org.gnu.gdb.power.htm.ppr} feature is optional. It should
45575contain the 64-bit checkpointed register @samp{cppr}.
45576
45577The @samp{org.gnu.gdb.power.htm.dscr} feature is optional. It should
45578contain the 64-bit checkpointed register @samp{cdscr}.
45579
45580The @samp{org.gnu.gdb.power.htm.tar} feature is optional. It should
45581contain the 64-bit checkpointed register @samp{ctar}.
45582
b5ffee31
AB
45583
45584@node RISC-V Features
45585@subsection RISC-V Features
45586@cindex target descriptions, RISC-V Features
45587
45588The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
45589targets. It should contain the registers @samp{x0} through
45590@samp{x31}, and @samp{pc}. Either the architectural names (@samp{x0},
45591@samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
45592etc).
45593
45594The @samp{org.gnu.gdb.riscv.fpu} feature is optional. If present, it
45595should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
45596@samp{frm}, and @samp{fcsr}. As with the cpu feature, either the
45597architectural register names, or the ABI names can be used.
45598
45599The @samp{org.gnu.gdb.riscv.virtual} feature is optional. If present,
45600it should contain registers that are not backed by real registers on
45601the target, but are instead virtual, where the register value is
45602derived from other target state. In many ways these are like
45603@value{GDBN}s pseudo-registers, except implemented by the target.
45604Currently the only register expected in this set is the one byte
45605@samp{priv} register that contains the target's privilege level in the
45606least significant two bits.
45607
45608The @samp{org.gnu.gdb.riscv.csr} feature is optional. If present, it
45609should contain all of the target's standard CSRs. Standard CSRs are
45610those defined in the RISC-V specification documents. There is some
45611overlap between this feature and the fpu feature; the @samp{fflags},
45612@samp{frm}, and @samp{fcsr} registers could be in either feature. The
45613expectation is that these registers will be in the fpu feature if the
45614target has floating point hardware, but can be moved into the csr
45615feature if the target has the floating point control registers, but no
45616other floating point hardware.
45617
e3ec872f
YS
45618@node RX Features
45619@subsection RX Features
45620@cindex target descriptions, RX Features
45621
45622The @samp{org.gnu.gdb.rx.core} feature is required for RX
45623targets. It should contain the registers @samp{r0} through
45624@samp{r15}, @samp{usp}, @samp{isp}, @samp{psw}, @samp{pc}, @samp{intb},
45625@samp{bpsw}, @samp{bpc}, @samp{fintv}, @samp{fpsw}, and @samp{acc}.
45626
4ac33720
UW
45627@node S/390 and System z Features
45628@subsection S/390 and System z Features
45629@cindex target descriptions, S/390 features
45630@cindex target descriptions, System z features
45631
45632The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
45633System z targets. It should contain the PSW and the 16 general
45634registers. In particular, System z targets should provide the 64-bit
45635registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
45636S/390 targets should provide the 32-bit versions of these registers.
45637A System z target that runs in 31-bit addressing mode should provide
4563832-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
45639register's upper halves @samp{r0h} through @samp{r15h}, and their
45640lower halves @samp{r0l} through @samp{r15l}.
45641
45642The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
45643contain the 64-bit registers @samp{f0} through @samp{f15}, and
45644@samp{fpc}.
45645
45646The @samp{org.gnu.gdb.s390.acr} feature is required. It should
45647contain the 32-bit registers @samp{acr0} through @samp{acr15}.
45648
45649The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
45650contain the register @samp{orig_r2}, which is 64-bit wide on System z
45651targets and 32-bit otherwise. In addition, the feature may contain
45652the @samp{last_break} register, whose width depends on the addressing
45653mode, as well as the @samp{system_call} register, which is always
4565432-bit wide.
45655
45656The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
45657contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
45658@samp{atia}, and @samp{tr0} through @samp{tr15}.
45659
446899e4
AA
45660The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
4566164-bit wide registers @samp{v0l} through @samp{v15l}, which will be
45662combined by @value{GDBN} with the floating point registers @samp{f0}
45663through @samp{f15} to present the 128-bit wide vector registers
45664@samp{v0} through @samp{v15}. In addition, this feature should
45665contain the 128-bit wide vector registers @samp{v16} through
45666@samp{v31}.
45667
289e23aa
AA
45668The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
45669the 64-bit wide guarded-storage-control registers @samp{gsd},
45670@samp{gssm}, and @samp{gsepla}.
45671
45672The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
45673the 64-bit wide guarded-storage broadcast control registers
45674@samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
45675
3f7b46f2
IR
45676@node Sparc Features
45677@subsection Sparc Features
45678@cindex target descriptions, sparc32 features
45679@cindex target descriptions, sparc64 features
45680The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
45681targets. It should describe the following registers:
45682
45683@itemize @minus
45684@item
45685@samp{g0} through @samp{g7}
45686@item
45687@samp{o0} through @samp{o7}
45688@item
45689@samp{l0} through @samp{l7}
45690@item
45691@samp{i0} through @samp{i7}
45692@end itemize
45693
45694They may be 32-bit or 64-bit depending on the target.
45695
45696Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
45697targets. It should describe the following registers:
45698
45699@itemize @minus
45700@item
45701@samp{f0} through @samp{f31}
45702@item
45703@samp{f32} through @samp{f62} for sparc64
45704@end itemize
45705
45706The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
45707targets. It should describe the following registers:
45708
45709@itemize @minus
45710@item
45711@samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
45712@samp{fsr}, and @samp{csr} for sparc32
45713@item
45714@samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
45715for sparc64
45716@end itemize
45717
224bbe49
YQ
45718@node TIC6x Features
45719@subsection TMS320C6x Features
45720@cindex target descriptions, TIC6x features
45721@cindex target descriptions, TMS320C6x features
45722The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
45723targets. It should contain registers @samp{A0} through @samp{A15},
45724registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
45725
45726The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
45727contain registers @samp{A16} through @samp{A31} and @samp{B16}
45728through @samp{B31}.
45729
45730The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
45731contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
45732
07e059b5
VP
45733@node Operating System Information
45734@appendix Operating System Information
45735@cindex operating system information
45736
45737@menu
45738* Process list::
45739@end menu
45740
45741Users of @value{GDBN} often wish to obtain information about the state of
45742the operating system running on the target---for example the list of
45743processes, or the list of open files. This section describes the
45744mechanism that makes it possible. This mechanism is similar to the
45745target features mechanism (@pxref{Target Descriptions}), but focuses
45746on a different aspect of target.
45747
6b92c0d3 45748Operating system information is retrieved from the target via the
07e059b5
VP
45749remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
45750read}). The object name in the request should be @samp{osdata}, and
45751the @var{annex} identifies the data to be fetched.
45752
45753@node Process list
45754@appendixsection Process list
45755@cindex operating system information, process list
45756
45757When requesting the process list, the @var{annex} field in the
45758@samp{qXfer} request should be @samp{processes}. The returned data is
45759an XML document. The formal syntax of this document is defined in
45760@file{gdb/features/osdata.dtd}.
45761
45762An example document is:
45763
45764@smallexample
45765<?xml version="1.0"?>
45766<!DOCTYPE target SYSTEM "osdata.dtd">
45767<osdata type="processes">
45768 <item>
45769 <column name="pid">1</column>
45770 <column name="user">root</column>
45771 <column name="command">/sbin/init</column>
dc146f7c 45772 <column name="cores">1,2,3</column>
07e059b5
VP
45773 </item>
45774</osdata>
45775@end smallexample
45776
45777Each item should include a column whose name is @samp{pid}. The value
45778of that column should identify the process on the target. The
45779@samp{user} and @samp{command} columns are optional, and will be
dc146f7c
VP
45780displayed by @value{GDBN}. The @samp{cores} column, if present,
45781should contain a comma-separated list of cores that this process
45782is running on. Target may provide additional columns,
07e059b5
VP
45783which @value{GDBN} currently ignores.
45784
05c8c3f5
TT
45785@node Trace File Format
45786@appendix Trace File Format
45787@cindex trace file format
45788
45789The trace file comes in three parts: a header, a textual description
45790section, and a trace frame section with binary data.
45791
45792The header has the form @code{\x7fTRACE0\n}. The first byte is
45793@code{0x7f} so as to indicate that the file contains binary data,
45794while the @code{0} is a version number that may have different values
45795in the future.
45796
45797The description section consists of multiple lines of @sc{ascii} text
45798separated by newline characters (@code{0xa}). The lines may include a
45799variety of optional descriptive or context-setting information, such
45800as tracepoint definitions or register set size. @value{GDBN} will
45801ignore any line that it does not recognize. An empty line marks the end
45802of this section.
45803
0748bf3e
MK
45804@table @code
45805@item R @var{size}
45806Specifies the size of a register block in bytes. This is equal to the
45807size of a @code{g} packet payload in the remote protocol. @var{size}
45808is an ascii decimal number. There should be only one such line in
45809a single trace file.
45810
45811@item status @var{status}
45812Trace status. @var{status} has the same format as a @code{qTStatus}
45813remote packet reply. There should be only one such line in a single trace
45814file.
45815
45816@item tp @var{payload}
45817Tracepoint definition. The @var{payload} has the same format as
45818@code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
45819may take multiple lines of definition, corresponding to the multiple
45820reply packets.
45821
45822@item tsv @var{payload}
45823Trace state variable definition. The @var{payload} has the same format as
45824@code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
45825may take multiple lines of definition, corresponding to the multiple
45826reply packets.
45827
45828@item tdesc @var{payload}
45829Target description in XML format. The @var{payload} is a single line of
45830the XML file. All such lines should be concatenated together to get
45831the original XML file. This file is in the same format as @code{qXfer}
45832@code{features} payload, and corresponds to the main @code{target.xml}
45833file. Includes are not allowed.
45834
45835@end table
05c8c3f5
TT
45836
45837The trace frame section consists of a number of consecutive frames.
45838Each frame begins with a two-byte tracepoint number, followed by a
45839four-byte size giving the amount of data in the frame. The data in
45840the frame consists of a number of blocks, each introduced by a
45841character indicating its type (at least register, memory, and trace
45842state variable). The data in this section is raw binary, not a
45843hexadecimal or other encoding; its endianness matches the target's
45844endianness.
45845
45846@c FIXME bi-arch may require endianness/arch info in description section
45847
45848@table @code
45849@item R @var{bytes}
45850Register block. The number and ordering of bytes matches that of a
45851@code{g} packet in the remote protocol. Note that these are the
e909d859 45852actual bytes, in target order, not a hexadecimal encoding.
05c8c3f5
TT
45853
45854@item M @var{address} @var{length} @var{bytes}...
45855Memory block. This is a contiguous block of memory, at the 8-byte
45856address @var{address}, with a 2-byte length @var{length}, followed by
45857@var{length} bytes.
45858
45859@item V @var{number} @var{value}
45860Trace state variable block. This records the 8-byte signed value
45861@var{value} of trace state variable numbered @var{number}.
45862
45863@end table
45864
45865Future enhancements of the trace file format may include additional types
45866of blocks.
45867
90476074
TT
45868@node Index Section Format
45869@appendix @code{.gdb_index} section format
45870@cindex .gdb_index section format
45871@cindex index section format
45872
45873This section documents the index section that is created by @code{save
45874gdb-index} (@pxref{Index Files}). The index section is
45875DWARF-specific; some knowledge of DWARF is assumed in this
45876description.
45877
45878The mapped index file format is designed to be directly
45879@code{mmap}able on any architecture. In most cases, a datum is
45880represented using a little-endian 32-bit integer value, called an
45881@code{offset_type}. Big endian machines must byte-swap the values
45882before using them. Exceptions to this rule are noted. The data is
45883laid out such that alignment is always respected.
45884
45885A mapped index consists of several areas, laid out in order.
45886
45887@enumerate
45888@item
45889The file header. This is a sequence of values, of @code{offset_type}
45890unless otherwise noted:
45891
45892@enumerate
45893@item
796a7ff8 45894The version number, currently 8. Versions 1, 2 and 3 are obsolete.
481860b3 45895Version 4 uses a different hashing function from versions 5 and 6.
b6ba681c
TT
45896Version 6 includes symbols for inlined functions, whereas versions 4
45897and 5 do not. Version 7 adds attributes to the CU indices in the
796a7ff8
DE
45898symbol table. Version 8 specifies that symbols from DWARF type units
45899(@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
45900compilation unit (@samp{DW_TAG_comp_unit}) using the type.
45901
45902@value{GDBN} will only read version 4, 5, or 6 indices
e615022a 45903by specifying @code{set use-deprecated-index-sections on}.
796a7ff8
DE
45904GDB has a workaround for potentially broken version 7 indices so it is
45905currently not flagged as deprecated.
90476074
TT
45906
45907@item
45908The offset, from the start of the file, of the CU list.
45909
45910@item
45911The offset, from the start of the file, of the types CU list. Note
45912that this area can be empty, in which case this offset will be equal
45913to the next offset.
45914
45915@item
45916The offset, from the start of the file, of the address area.
45917
45918@item
45919The offset, from the start of the file, of the symbol table.
45920
45921@item
45922The offset, from the start of the file, of the constant pool.
45923@end enumerate
45924
45925@item
45926The CU list. This is a sequence of pairs of 64-bit little-endian
45927values, sorted by the CU offset. The first element in each pair is
45928the offset of a CU in the @code{.debug_info} section. The second
45929element in each pair is the length of that CU. References to a CU
45930elsewhere in the map are done using a CU index, which is just the
459310-based index into this table. Note that if there are type CUs, then
45932conceptually CUs and type CUs form a single list for the purposes of
45933CU indices.
45934
45935@item
45936The types CU list. This is a sequence of triplets of 64-bit
45937little-endian values. In a triplet, the first value is the CU offset,
45938the second value is the type offset in the CU, and the third value is
45939the type signature. The types CU list is not sorted.
45940
45941@item
45942The address area. The address area consists of a sequence of address
45943entries. Each address entry has three elements:
45944
45945@enumerate
45946@item
45947The low address. This is a 64-bit little-endian value.
45948
45949@item
45950The high address. This is a 64-bit little-endian value. Like
45951@code{DW_AT_high_pc}, the value is one byte beyond the end.
45952
45953@item
45954The CU index. This is an @code{offset_type} value.
45955@end enumerate
45956
45957@item
45958The symbol table. This is an open-addressed hash table. The size of
45959the hash table is always a power of 2.
45960
45961Each slot in the hash table consists of a pair of @code{offset_type}
45962values. The first value is the offset of the symbol's name in the
45963constant pool. The second value is the offset of the CU vector in the
45964constant pool.
45965
45966If both values are 0, then this slot in the hash table is empty. This
45967is ok because while 0 is a valid constant pool index, it cannot be a
45968valid index for both a string and a CU vector.
45969
45970The hash value for a table entry is computed by applying an
45971iterative hash function to the symbol's name. Starting with an
45972initial value of @code{r = 0}, each (unsigned) character @samp{c} in
559a7a62
JK
45973the string is incorporated into the hash using the formula depending on the
45974index version:
45975
45976@table @asis
45977@item Version 4
45978The formula is @code{r = r * 67 + c - 113}.
45979
156942c7 45980@item Versions 5 to 7
559a7a62
JK
45981The formula is @code{r = r * 67 + tolower (c) - 113}.
45982@end table
45983
45984The terminating @samp{\0} is not incorporated into the hash.
90476074
TT
45985
45986The step size used in the hash table is computed via
45987@code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
45988value, and @samp{size} is the size of the hash table. The step size
45989is used to find the next candidate slot when handling a hash
45990collision.
45991
45992The names of C@t{++} symbols in the hash table are canonicalized. We
45993don't currently have a simple description of the canonicalization
45994algorithm; if you intend to create new index sections, you must read
45995the code.
45996
45997@item
45998The constant pool. This is simply a bunch of bytes. It is organized
45999so that alignment is correct: CU vectors are stored first, followed by
46000strings.
46001
46002A CU vector in the constant pool is a sequence of @code{offset_type}
46003values. The first value is the number of CU indices in the vector.
156942c7
DE
46004Each subsequent value is the index and symbol attributes of a CU in
46005the CU list. This element in the hash table is used to indicate which
46006CUs define the symbol and how the symbol is used.
46007See below for the format of each CU index+attributes entry.
90476074
TT
46008
46009A string in the constant pool is zero-terminated.
46010@end enumerate
46011
156942c7
DE
46012Attributes were added to CU index values in @code{.gdb_index} version 7.
46013If a symbol has multiple uses within a CU then there is one
46014CU index+attributes value for each use.
46015
46016The format of each CU index+attributes entry is as follows
46017(bit 0 = LSB):
46018
46019@table @asis
46020
46021@item Bits 0-23
46022This is the index of the CU in the CU list.
46023@item Bits 24-27
46024These bits are reserved for future purposes and must be zero.
46025@item Bits 28-30
46026The kind of the symbol in the CU.
46027
46028@table @asis
46029@item 0
46030This value is reserved and should not be used.
46031By reserving zero the full @code{offset_type} value is backwards compatible
46032with previous versions of the index.
46033@item 1
46034The symbol is a type.
46035@item 2
46036The symbol is a variable or an enum value.
46037@item 3
46038The symbol is a function.
46039@item 4
46040Any other kind of symbol.
46041@item 5,6,7
46042These values are reserved.
46043@end table
46044
46045@item Bit 31
46046This bit is zero if the value is global and one if it is static.
46047
46048The determination of whether a symbol is global or static is complicated.
46049The authorative reference is the file @file{dwarf2read.c} in
46050@value{GDBN} sources.
46051
46052@end table
46053
46054This pseudo-code describes the computation of a symbol's kind and
46055global/static attributes in the index.
46056
46057@smallexample
46058is_external = get_attribute (die, DW_AT_external);
46059language = get_attribute (cu_die, DW_AT_language);
46060switch (die->tag)
46061 @{
46062 case DW_TAG_typedef:
46063 case DW_TAG_base_type:
46064 case DW_TAG_subrange_type:
46065 kind = TYPE;
46066 is_static = 1;
46067 break;
46068 case DW_TAG_enumerator:
46069 kind = VARIABLE;
9c37b5ae 46070 is_static = language != CPLUS;
156942c7
DE
46071 break;
46072 case DW_TAG_subprogram:
46073 kind = FUNCTION;
46074 is_static = ! (is_external || language == ADA);
46075 break;
46076 case DW_TAG_constant:
46077 kind = VARIABLE;
46078 is_static = ! is_external;
46079 break;
46080 case DW_TAG_variable:
46081 kind = VARIABLE;
46082 is_static = ! is_external;
46083 break;
46084 case DW_TAG_namespace:
46085 kind = TYPE;
46086 is_static = 0;
46087 break;
46088 case DW_TAG_class_type:
46089 case DW_TAG_interface_type:
46090 case DW_TAG_structure_type:
46091 case DW_TAG_union_type:
46092 case DW_TAG_enumeration_type:
46093 kind = TYPE;
9c37b5ae 46094 is_static = language != CPLUS;
156942c7
DE
46095 break;
46096 default:
46097 assert (0);
46098 @}
46099@end smallexample
46100
43662968
JK
46101@node Man Pages
46102@appendix Manual pages
46103@cindex Man pages
46104
46105@menu
46106* gdb man:: The GNU Debugger man page
46107* gdbserver man:: Remote Server for the GNU Debugger man page
b292c783 46108* gcore man:: Generate a core file of a running program
43662968 46109* gdbinit man:: gdbinit scripts
ba643918 46110* gdb-add-index man:: Add index files to speed up GDB
43662968
JK
46111@end menu
46112
46113@node gdb man
46114@heading gdb man
46115
46116@c man title gdb The GNU Debugger
46117
46118@c man begin SYNOPSIS gdb
46119gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
46120[@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
46121[@option{-b}@w{ }@var{bps}]
46122 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
46123[@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
906ccdf0
JK
46124[@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
46125 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
46126[@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
43662968
JK
46127@c man end
46128
46129@c man begin DESCRIPTION gdb
46130The purpose of a debugger such as @value{GDBN} is to allow you to see what is
46131going on ``inside'' another program while it executes -- or what another
46132program was doing at the moment it crashed.
46133
46134@value{GDBN} can do four main kinds of things (plus other things in support of
46135these) to help you catch bugs in the act:
46136
46137@itemize @bullet
46138@item
46139Start your program, specifying anything that might affect its behavior.
46140
46141@item
46142Make your program stop on specified conditions.
46143
46144@item
46145Examine what has happened, when your program has stopped.
46146
46147@item
46148Change things in your program, so you can experiment with correcting the
46149effects of one bug and go on to learn about another.
46150@end itemize
46151
906ccdf0
JK
46152You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
46153Modula-2.
43662968
JK
46154
46155@value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
46156commands from the terminal until you tell it to exit with the @value{GDBN}
46157command @code{quit}. You can get online help from @value{GDBN} itself
46158by using the command @code{help}.
46159
46160You can run @code{gdb} with no arguments or options; but the most
46161usual way to start @value{GDBN} is with one argument or two, specifying an
46162executable program as the argument:
46163
46164@smallexample
46165gdb program
46166@end smallexample
46167
46168You can also start with both an executable program and a core file specified:
46169
46170@smallexample
46171gdb program core
46172@end smallexample
46173
4ed4690f
SM
46174You can, instead, specify a process ID as a second argument or use option
46175@code{-p}, if you want to debug a running process:
43662968
JK
46176
46177@smallexample
46178gdb program 1234
906ccdf0 46179gdb -p 1234
43662968
JK
46180@end smallexample
46181
46182@noindent
4ed4690f
SM
46183would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
46184can omit the @var{program} filename.
43662968
JK
46185
46186Here are some of the most frequently needed @value{GDBN} commands:
46187
46188@c pod2man highlights the right hand side of the @item lines.
46189@table @env
224f10c1 46190@item break [@var{file}:]@var{function}
43662968
JK
46191Set a breakpoint at @var{function} (in @var{file}).
46192
46193@item run [@var{arglist}]
46194Start your program (with @var{arglist}, if specified).
46195
46196@item bt
46197Backtrace: display the program stack.
46198
46199@item print @var{expr}
46200Display the value of an expression.
46201
46202@item c
46203Continue running your program (after stopping, e.g. at a breakpoint).
46204
46205@item next
46206Execute next program line (after stopping); step @emph{over} any
46207function calls in the line.
46208
46209@item edit [@var{file}:]@var{function}
46210look at the program line where it is presently stopped.
46211
46212@item list [@var{file}:]@var{function}
46213type the text of the program in the vicinity of where it is presently stopped.
46214
46215@item step
46216Execute next program line (after stopping); step @emph{into} any
46217function calls in the line.
46218
46219@item help [@var{name}]
46220Show information about @value{GDBN} command @var{name}, or general information
46221about using @value{GDBN}.
46222
46223@item quit
46224Exit from @value{GDBN}.
46225@end table
46226
46227@ifset man
46228For full details on @value{GDBN},
46229see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46230by Richard M. Stallman and Roland H. Pesch. The same text is available online
46231as the @code{gdb} entry in the @code{info} program.
46232@end ifset
46233@c man end
46234
46235@c man begin OPTIONS gdb
46236Any arguments other than options specify an executable
46237file and core file (or process ID); that is, the first argument
46238encountered with no
46239associated option flag is equivalent to a @option{-se} option, and the second,
46240if any, is equivalent to a @option{-c} option if it's the name of a file.
46241Many options have
46242both long and short forms; both are shown here. The long forms are also
46243recognized if you truncate them, so long as enough of the option is
46244present to be unambiguous. (If you prefer, you can flag option
46245arguments with @option{+} rather than @option{-}, though we illustrate the
46246more usual convention.)
46247
46248All the options and command line arguments you give are processed
46249in sequential order. The order makes a difference when the @option{-x}
46250option is used.
46251
46252@table @env
46253@item -help
46254@itemx -h
46255List all options, with brief explanations.
46256
46257@item -symbols=@var{file}
46258@itemx -s @var{file}
46259Read symbol table from file @var{file}.
46260
46261@item -write
46262Enable writing into executable and core files.
46263
46264@item -exec=@var{file}
46265@itemx -e @var{file}
46266Use file @var{file} as the executable file to execute when
46267appropriate, and for examining pure data in conjunction with a core
46268dump.
46269
46270@item -se=@var{file}
46271Read symbol table from file @var{file} and use it as the executable
46272file.
46273
46274@item -core=@var{file}
46275@itemx -c @var{file}
46276Use file @var{file} as a core dump to examine.
46277
46278@item -command=@var{file}
46279@itemx -x @var{file}
46280Execute @value{GDBN} commands from file @var{file}.
46281
46282@item -ex @var{command}
46283Execute given @value{GDBN} @var{command}.
46284
46285@item -directory=@var{directory}
46286@itemx -d @var{directory}
46287Add @var{directory} to the path to search for source files.
46288
46289@item -nh
46290Do not execute commands from @file{~/.gdbinit}.
46291
46292@item -nx
46293@itemx -n
46294Do not execute commands from any @file{.gdbinit} initialization files.
46295
46296@item -quiet
46297@itemx -q
46298``Quiet''. Do not print the introductory and copyright messages. These
46299messages are also suppressed in batch mode.
46300
46301@item -batch
46302Run in batch mode. Exit with status @code{0} after processing all the command
46303files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
46304Exit with nonzero status if an error occurs in executing the @value{GDBN}
46305commands in the command files.
46306
46307Batch mode may be useful for running @value{GDBN} as a filter, for example to
46308download and run a program on another computer; in order to make this
46309more useful, the message
46310
46311@smallexample
46312Program exited normally.
46313@end smallexample
46314
46315@noindent
46316(which is ordinarily issued whenever a program running under @value{GDBN} control
46317terminates) is not issued when running in batch mode.
46318
46319@item -cd=@var{directory}
46320Run @value{GDBN} using @var{directory} as its working directory,
46321instead of the current directory.
46322
46323@item -fullname
46324@itemx -f
46325Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
46326@value{GDBN} to output the full file name and line number in a standard,
46327recognizable fashion each time a stack frame is displayed (which
46328includes each time the program stops). This recognizable format looks
46329like two @samp{\032} characters, followed by the file name, line number
46330and character position separated by colons, and a newline. The
46331Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
46332characters as a signal to display the source code for the frame.
46333
46334@item -b @var{bps}
46335Set the line speed (baud rate or bits per second) of any serial
46336interface used by @value{GDBN} for remote debugging.
46337
46338@item -tty=@var{device}
46339Run using @var{device} for your program's standard input and output.
46340@end table
46341@c man end
46342
46343@c man begin SEEALSO gdb
46344@ifset man
46345The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46346If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46347documentation are properly installed at your site, the command
46348
46349@smallexample
46350info gdb
46351@end smallexample
46352
46353@noindent
46354should give you access to the complete manual.
46355
46356@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46357Richard M. Stallman and Roland H. Pesch, July 1991.
46358@end ifset
46359@c man end
46360
46361@node gdbserver man
46362@heading gdbserver man
46363
46364@c man title gdbserver Remote Server for the GNU Debugger
46365@format
46366@c man begin SYNOPSIS gdbserver
5b8b6385 46367gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
43662968 46368
5b8b6385
JK
46369gdbserver --attach @var{comm} @var{pid}
46370
46371gdbserver --multi @var{comm}
43662968
JK
46372@c man end
46373@end format
46374
46375@c man begin DESCRIPTION gdbserver
46376@command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
46377than the one which is running the program being debugged.
46378
46379@ifclear man
46380@subheading Usage (server (target) side)
46381@end ifclear
46382@ifset man
46383Usage (server (target) side):
46384@end ifset
46385
46386First, you need to have a copy of the program you want to debug put onto
46387the target system. The program can be stripped to save space if needed, as
46388@command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
46389the @value{GDBN} running on the host system.
46390
46391To use the server, you log on to the target system, and run the @command{gdbserver}
46392program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
46393your program, and (c) its arguments. The general syntax is:
46394
46395@smallexample
46396target> gdbserver @var{comm} @var{program} [@var{args} ...]
46397@end smallexample
46398
46399For example, using a serial port, you might say:
46400
46401@smallexample
46402@ifset man
46403@c @file would wrap it as F</dev/com1>.
46404target> gdbserver /dev/com1 emacs foo.txt
46405@end ifset
46406@ifclear man
46407target> gdbserver @file{/dev/com1} emacs foo.txt
46408@end ifclear
46409@end smallexample
46410
46411This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
46412to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
46413waits patiently for the host @value{GDBN} to communicate with it.
46414
46415To use a TCP connection, you could say:
46416
46417@smallexample
46418target> gdbserver host:2345 emacs foo.txt
46419@end smallexample
46420
46421This says pretty much the same thing as the last example, except that we are
46422going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
46423that we are expecting to see a TCP connection from @code{host} to local TCP port
464242345. (Currently, the @code{host} part is ignored.) You can choose any number you
46425want for the port number as long as it does not conflict with any existing TCP
46426ports on the target system. This same port number must be used in the host
46427@value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
46428you chose a port number that conflicts with another service, @command{gdbserver} will
46429print an error message and exit.
46430
5b8b6385 46431@command{gdbserver} can also attach to running programs.
43662968
JK
46432This is accomplished via the @option{--attach} argument. The syntax is:
46433
46434@smallexample
5b8b6385 46435target> gdbserver --attach @var{comm} @var{pid}
43662968
JK
46436@end smallexample
46437
46438@var{pid} is the process ID of a currently running process. It isn't
46439necessary to point @command{gdbserver} at a binary for the running process.
46440
5b8b6385
JK
46441To start @code{gdbserver} without supplying an initial command to run
46442or process ID to attach, use the @option{--multi} command line option.
46443In such case you should connect using @kbd{target extended-remote} to start
46444the program you want to debug.
46445
46446@smallexample
46447target> gdbserver --multi @var{comm}
46448@end smallexample
46449
43662968
JK
46450@ifclear man
46451@subheading Usage (host side)
46452@end ifclear
46453@ifset man
46454Usage (host side):
46455@end ifset
46456
46457You need an unstripped copy of the target program on your host system, since
1a088a2e 46458@value{GDBN} needs to examine its symbol tables and such. Start up @value{GDBN} as you normally
43662968
JK
46459would, with the target program as the first argument. (You may need to use the
46460@option{--baud} option if the serial line is running at anything except 9600 baud.)
46461That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
5b8b6385
JK
46462new command you need to know about is @code{target remote}
46463(or @code{target extended-remote}). Its argument is either
43662968
JK
46464a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
46465descriptor. For example:
46466
46467@smallexample
46468@ifset man
46469@c @file would wrap it as F</dev/ttyb>.
46470(gdb) target remote /dev/ttyb
46471@end ifset
46472@ifclear man
46473(gdb) target remote @file{/dev/ttyb}
46474@end ifclear
46475@end smallexample
46476
46477@noindent
46478communicates with the server via serial line @file{/dev/ttyb}, and:
46479
46480@smallexample
46481(gdb) target remote the-target:2345
46482@end smallexample
46483
46484@noindent
46485communicates via a TCP connection to port 2345 on host `the-target', where
46486you previously started up @command{gdbserver} with the same port number. Note that for
46487TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
46488command, otherwise you may get an error that looks something like
46489`Connection refused'.
5b8b6385
JK
46490
46491@command{gdbserver} can also debug multiple inferiors at once,
46492described in
46493@ifset man
65c574f6
PA
46494the @value{GDBN} manual in node @code{Inferiors Connections and Programs}
46495-- shell command @code{info -f gdb -n 'Inferiors Connections and Programs'}.
5b8b6385
JK
46496@end ifset
46497@ifclear man
65c574f6 46498@ref{Inferiors Connections and Programs}.
5b8b6385
JK
46499@end ifclear
46500In such case use the @code{extended-remote} @value{GDBN} command variant:
46501
46502@smallexample
46503(gdb) target extended-remote the-target:2345
46504@end smallexample
46505
46506The @command{gdbserver} option @option{--multi} may or may not be used in such
46507case.
43662968
JK
46508@c man end
46509
46510@c man begin OPTIONS gdbserver
5b8b6385
JK
46511There are three different modes for invoking @command{gdbserver}:
46512
46513@itemize @bullet
46514
46515@item
46516Debug a specific program specified by its program name:
46517
46518@smallexample
46519gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
46520@end smallexample
46521
46522The @var{comm} parameter specifies how should the server communicate
46523with @value{GDBN}; it is either a device name (to use a serial line),
46524a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
46525stdin/stdout of @code{gdbserver}. Specify the name of the program to
46526debug in @var{prog}. Any remaining arguments will be passed to the
46527program verbatim. When the program exits, @value{GDBN} will close the
46528connection, and @code{gdbserver} will exit.
46529
46530@item
46531Debug a specific program by specifying the process ID of a running
46532program:
46533
46534@smallexample
46535gdbserver --attach @var{comm} @var{pid}
46536@end smallexample
46537
46538The @var{comm} parameter is as described above. Supply the process ID
46539of a running program in @var{pid}; @value{GDBN} will do everything
46540else. Like with the previous mode, when the process @var{pid} exits,
46541@value{GDBN} will close the connection, and @code{gdbserver} will exit.
46542
46543@item
46544Multi-process mode -- debug more than one program/process:
46545
46546@smallexample
46547gdbserver --multi @var{comm}
46548@end smallexample
46549
46550In this mode, @value{GDBN} can instruct @command{gdbserver} which
46551command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
46552close the connection when a process being debugged exits, so you can
46553debug several processes in the same session.
46554@end itemize
46555
46556In each of the modes you may specify these options:
46557
46558@table @env
46559
46560@item --help
46561List all options, with brief explanations.
46562
46563@item --version
46564This option causes @command{gdbserver} to print its version number and exit.
46565
46566@item --attach
46567@command{gdbserver} will attach to a running program. The syntax is:
46568
46569@smallexample
46570target> gdbserver --attach @var{comm} @var{pid}
46571@end smallexample
46572
46573@var{pid} is the process ID of a currently running process. It isn't
46574necessary to point @command{gdbserver} at a binary for the running process.
46575
46576@item --multi
46577To start @code{gdbserver} without supplying an initial command to run
46578or process ID to attach, use this command line option.
46579Then you can connect using @kbd{target extended-remote} and start
46580the program you want to debug. The syntax is:
46581
46582@smallexample
46583target> gdbserver --multi @var{comm}
46584@end smallexample
46585
46586@item --debug
46587Instruct @code{gdbserver} to display extra status information about the debugging
46588process.
46589This option is intended for @code{gdbserver} development and for bug reports to
46590the developers.
46591
46592@item --remote-debug
46593Instruct @code{gdbserver} to display remote protocol debug output.
46594This option is intended for @code{gdbserver} development and for bug reports to
46595the developers.
46596
aeb2e706
AH
46597@item --debug-file=@var{filename}
46598Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
46599This option is intended for @code{gdbserver} development and for bug reports to
46600the developers.
46601
87ce2a04
DE
46602@item --debug-format=option1@r{[},option2,...@r{]}
46603Instruct @code{gdbserver} to include extra information in each line
46604of debugging output.
46605@xref{Other Command-Line Arguments for gdbserver}.
46606
5b8b6385
JK
46607@item --wrapper
46608Specify a wrapper to launch programs
46609for debugging. The option should be followed by the name of the
46610wrapper, then any command-line arguments to pass to the wrapper, then
46611@kbd{--} indicating the end of the wrapper arguments.
46612
46613@item --once
46614By default, @command{gdbserver} keeps the listening TCP port open, so that
46615additional connections are possible. However, if you start @code{gdbserver}
46616with the @option{--once} option, it will stop listening for any further
46617connection attempts after connecting to the first @value{GDBN} session.
46618
46619@c --disable-packet is not documented for users.
46620
46621@c --disable-randomization and --no-disable-randomization are superseded by
46622@c QDisableRandomization.
46623
46624@end table
43662968
JK
46625@c man end
46626
46627@c man begin SEEALSO gdbserver
46628@ifset man
46629The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46630If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46631documentation are properly installed at your site, the command
46632
46633@smallexample
46634info gdb
46635@end smallexample
46636
46637should give you access to the complete manual.
46638
46639@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46640Richard M. Stallman and Roland H. Pesch, July 1991.
46641@end ifset
46642@c man end
46643
b292c783
JK
46644@node gcore man
46645@heading gcore
46646
46647@c man title gcore Generate a core file of a running program
46648
46649@format
46650@c man begin SYNOPSIS gcore
129eb0f1 46651gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
b292c783
JK
46652@c man end
46653@end format
46654
46655@c man begin DESCRIPTION gcore
129eb0f1
SDJ
46656Generate core dumps of one or more running programs with process IDs
46657@var{pid1}, @var{pid2}, etc. A core file produced by @command{gcore}
46658is equivalent to one produced by the kernel when the process crashes
46659(and when @kbd{ulimit -c} was used to set up an appropriate core dump
46660limit). However, unlike after a crash, after @command{gcore} finishes
46661its job the program remains running without any change.
b292c783
JK
46662@c man end
46663
46664@c man begin OPTIONS gcore
46665@table @env
c179febe
SL
46666@item -a
46667Dump all memory mappings. The actual effect of this option depends on
46668the Operating System. On @sc{gnu}/Linux, it will disable
46669@code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
46670enable @code{dump-excluded-mappings} (@pxref{set
46671dump-excluded-mappings}).
46672
129eb0f1
SDJ
46673@item -o @var{prefix}
46674The optional argument @var{prefix} specifies the prefix to be used
46675when composing the file names of the core dumps. The file name is
46676composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
46677process ID of the running program being analyzed by @command{gcore}.
46678If not specified, @var{prefix} defaults to @var{gcore}.
b292c783
JK
46679@end table
46680@c man end
46681
46682@c man begin SEEALSO gcore
46683@ifset man
46684The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46685If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46686documentation are properly installed at your site, the command
46687
46688@smallexample
46689info gdb
46690@end smallexample
46691
46692@noindent
46693should give you access to the complete manual.
46694
46695@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46696Richard M. Stallman and Roland H. Pesch, July 1991.
46697@end ifset
46698@c man end
46699
43662968
JK
46700@node gdbinit man
46701@heading gdbinit
46702
46703@c man title gdbinit GDB initialization scripts
46704
46705@format
46706@c man begin SYNOPSIS gdbinit
46707@ifset SYSTEM_GDBINIT
46708@value{SYSTEM_GDBINIT}
46709@end ifset
46710
ed2a2229
CB
46711@ifset SYSTEM_GDBINIT_DIR
46712@value{SYSTEM_GDBINIT_DIR}/*
46713@end ifset
46714
43662968
JK
46715~/.gdbinit
46716
46717./.gdbinit
46718@c man end
46719@end format
46720
46721@c man begin DESCRIPTION gdbinit
46722These files contain @value{GDBN} commands to automatically execute during
46723@value{GDBN} startup. The lines of contents are canned sequences of commands,
46724described in
46725@ifset man
46726the @value{GDBN} manual in node @code{Sequences}
46727-- shell command @code{info -f gdb -n Sequences}.
46728@end ifset
46729@ifclear man
46730@ref{Sequences}.
46731@end ifclear
46732
46733Please read more in
46734@ifset man
46735the @value{GDBN} manual in node @code{Startup}
46736-- shell command @code{info -f gdb -n Startup}.
46737@end ifset
46738@ifclear man
46739@ref{Startup}.
46740@end ifclear
46741
46742@table @env
46743@ifset SYSTEM_GDBINIT
46744@item @value{SYSTEM_GDBINIT}
46745@end ifset
46746@ifclear SYSTEM_GDBINIT
46747@item (not enabled with @code{--with-system-gdbinit} during compilation)
46748@end ifclear
46749System-wide initialization file. It is executed unless user specified
46750@value{GDBN} option @code{-nx} or @code{-n}.
46751See more in
46752@ifset man
46753the @value{GDBN} manual in node @code{System-wide configuration}
46754-- shell command @code{info -f gdb -n 'System-wide configuration'}.
46755@end ifset
ed2a2229
CB
46756@ifset SYSTEM_GDBINIT_DIR
46757@item @value{SYSTEM_GDBINIT_DIR}
46758@end ifset
46759@ifclear SYSTEM_GDBINIT_DIR
46760@item (not enabled with @code{--with-system-gdbinit-dir} during compilation)
46761@end ifclear
46762System-wide initialization directory. All files in this directory are
46763executed on startup unless user specified @value{GDBN} option @code{-nx} or
46764@code{-n}, as long as they have a recognized file extension.
46765See more in
46766@ifset man
46767the @value{GDBN} manual in node @code{System-wide configuration}
46768-- shell command @code{info -f gdb -n 'System-wide configuration'}.
46769@end ifset
43662968
JK
46770@ifclear man
46771@ref{System-wide configuration}.
46772@end ifclear
46773
46774@item ~/.gdbinit
46775User initialization file. It is executed unless user specified
46776@value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
46777
46778@item ./.gdbinit
46779Initialization file for current directory. It may need to be enabled with
46780@value{GDBN} security command @code{set auto-load local-gdbinit}.
46781See more in
46782@ifset man
46783the @value{GDBN} manual in node @code{Init File in the Current Directory}
46784-- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
46785@end ifset
46786@ifclear man
46787@ref{Init File in the Current Directory}.
46788@end ifclear
46789@end table
46790@c man end
46791
46792@c man begin SEEALSO gdbinit
46793@ifset man
46794gdb(1), @code{info -f gdb -n Startup}
46795
46796The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46797If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46798documentation are properly installed at your site, the command
ba643918
SDJ
46799
46800@smallexample
46801info gdb
46802@end smallexample
46803
46804should give you access to the complete manual.
46805
46806@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46807Richard M. Stallman and Roland H. Pesch, July 1991.
46808@end ifset
46809@c man end
46810
46811@node gdb-add-index man
ba643918 46812@heading gdb-add-index
d726cb5d 46813@pindex gdb-add-index
dbfa4523 46814@anchor{gdb-add-index}
ba643918
SDJ
46815
46816@c man title gdb-add-index Add index files to speed up GDB
46817
46818@c man begin SYNOPSIS gdb-add-index
46819gdb-add-index @var{filename}
46820@c man end
46821
46822@c man begin DESCRIPTION gdb-add-index
46823When @value{GDBN} finds a symbol file, it scans the symbols in the
46824file in order to construct an internal symbol table. This lets most
46825@value{GDBN} operations work quickly--at the cost of a delay early on.
46826For large programs, this delay can be quite lengthy, so @value{GDBN}
46827provides a way to build an index, which speeds up startup.
46828
46829To determine whether a file contains such an index, use the command
46830@kbd{readelf -S filename}: the index is stored in a section named
46831@code{.gdb_index}. The index file can only be produced on systems
46832which use ELF binaries and DWARF debug information (i.e., sections
46833named @code{.debug_*}).
46834
46835@command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
46836in the @env{PATH} environment variable. If you want to use different
46837versions of these programs, you can specify them through the
46838@env{GDB} and @env{OBJDUMP} environment variables.
46839
46840See more in
46841@ifset man
46842the @value{GDBN} manual in node @code{Index Files}
46843-- shell command @kbd{info -f gdb -n "Index Files"}.
46844@end ifset
46845@ifclear man
46846@ref{Index Files}.
46847@end ifclear
46848@c man end
46849
46850@c man begin SEEALSO gdb-add-index
46851@ifset man
46852The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46853If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46854documentation are properly installed at your site, the command
43662968
JK
46855
46856@smallexample
46857info gdb
46858@end smallexample
46859
46860should give you access to the complete manual.
46861
46862@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46863Richard M. Stallman and Roland H. Pesch, July 1991.
46864@end ifset
46865@c man end
46866
aab4e0ec 46867@include gpl.texi
eb12ee30 46868
e4c0cfae
SS
46869@node GNU Free Documentation License
46870@appendix GNU Free Documentation License
6826cf00
EZ
46871@include fdl.texi
46872
00595b5e
EZ
46873@node Concept Index
46874@unnumbered Concept Index
c906108c
SS
46875
46876@printindex cp
46877
00595b5e
EZ
46878@node Command and Variable Index
46879@unnumbered Command, Variable, and Function Index
46880
46881@printindex fn
46882
c906108c 46883@tex
984359d2 46884% I think something like @@colophon should be in texinfo. In the
c906108c
SS
46885% meantime:
46886\long\def\colophon{\hbox to0pt{}\vfill
46887\centerline{The body of this manual is set in}
46888\centerline{\fontname\tenrm,}
46889\centerline{with headings in {\bf\fontname\tenbf}}
46890\centerline{and examples in {\tt\fontname\tentt}.}
46891\centerline{{\it\fontname\tenit\/},}
46892\centerline{{\bf\fontname\tenbf}, and}
46893\centerline{{\sl\fontname\tensl\/}}
46894\centerline{are used for emphasis.}\vfill}
46895\page\colophon
984359d2 46896% Blame: doc@@cygnus.com, 1991.
c906108c
SS
46897@end tex
46898
c906108c 46899@bye
This page took 8.499047 seconds and 4 git commands to generate.