Implement Ada operator overloading
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
3666a048 2@c Copyright (C) 1988--2021 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
b5b5650a 53Copyright @copyright{} 1988-2021 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
b5b5650a 123Copyright (C) 1988-2021 Free Software Foundation, Inc.
6d2ebf8b 124
3fb6a982
JB
125This edition of the GDB manual is dedicated to the memory of Fred
126Fish. Fred was a long-standing contributor to GDB and to Free
127software in general. We will miss him.
128
6d2ebf8b
SS
129@menu
130* Summary:: Summary of @value{GDBN}
131* Sample Session:: A sample @value{GDBN} session
132
133* Invocation:: Getting in and out of @value{GDBN}
134* Commands:: @value{GDBN} commands
135* Running:: Running programs under @value{GDBN}
136* Stopping:: Stopping and continuing
bacec72f 137* Reverse Execution:: Running programs backward
a2311334 138* Process Record and Replay:: Recording inferior's execution and replaying it
6d2ebf8b
SS
139* Stack:: Examining the stack
140* Source:: Examining source files
141* Data:: Examining data
edb3359d 142* Optimized Code:: Debugging optimized code
e2e0bcd1 143* Macros:: Preprocessor Macros
b37052ae 144* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 145* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
146
147* Languages:: Using @value{GDBN} with different languages
148
149* Symbols:: Examining the symbol table
150* Altering:: Altering execution
151* GDB Files:: @value{GDBN} files
152* Targets:: Specifying a debugging target
6b2f586d 153* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
154* Configurations:: Configuration-specific information
155* Controlling GDB:: Controlling @value{GDBN}
d57a3c85 156* Extending GDB:: Extending @value{GDBN}
21c294e6 157* Interpreters:: Command Interpreters
c8f4133a 158* TUI:: @value{GDBN} Text User Interface
6d2ebf8b 159* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
7162c0ca 160* GDB/MI:: @value{GDBN}'s Machine Interface.
c8f4133a 161* Annotations:: @value{GDBN}'s annotation interface.
4efc6507 162* JIT Interface:: Using the JIT debugging interface.
d1feda86 163* In-Process Agent:: In-Process Agent
6d2ebf8b
SS
164
165* GDB Bugs:: Reporting bugs in @value{GDBN}
6d2ebf8b 166
39037522
TT
167@ifset SYSTEM_READLINE
168* Command Line Editing: (rluserman). Command Line Editing
169* Using History Interactively: (history). Using History Interactively
170@end ifset
171@ifclear SYSTEM_READLINE
6d2ebf8b
SS
172* Command Line Editing:: Command Line Editing
173* Using History Interactively:: Using History Interactively
39037522 174@end ifclear
4ceed123 175* In Memoriam:: In Memoriam
0869d01b 176* Formatting Documentation:: How to format and print @value{GDBN} documentation
6d2ebf8b 177* Installing GDB:: Installing GDB
eb12ee30 178* Maintenance Commands:: Maintenance Commands
e0ce93ac 179* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 180* Agent Expressions:: The GDB Agent Expression Mechanism
23181151
DJ
181* Target Descriptions:: How targets can describe themselves to
182 @value{GDBN}
07e059b5
VP
183* Operating System Information:: Getting additional information from
184 the operating system
00bf0b85 185* Trace File Format:: GDB trace file format
90476074 186* Index Section Format:: .gdb_index section format
43662968 187* Man Pages:: Manual pages
aab4e0ec
AC
188* Copying:: GNU General Public License says
189 how you can copy and share GDB
6826cf00 190* GNU Free Documentation License:: The license for this documentation
00595b5e
EZ
191* Concept Index:: Index of @value{GDBN} concepts
192* Command and Variable Index:: Index of @value{GDBN} commands, variables,
193 functions, and Python data types
6d2ebf8b
SS
194@end menu
195
6c0e9fb3 196@end ifnottex
c906108c 197
449f3b6c 198@contents
449f3b6c 199
6d2ebf8b 200@node Summary
c906108c
SS
201@unnumbered Summary of @value{GDBN}
202
203The purpose of a debugger such as @value{GDBN} is to allow you to see what is
204going on ``inside'' another program while it executes---or what another
205program was doing at the moment it crashed.
206
207@value{GDBN} can do four main kinds of things (plus other things in support of
208these) to help you catch bugs in the act:
209
210@itemize @bullet
211@item
212Start your program, specifying anything that might affect its behavior.
213
214@item
215Make your program stop on specified conditions.
216
217@item
218Examine what has happened, when your program has stopped.
219
220@item
221Change things in your program, so you can experiment with correcting the
222effects of one bug and go on to learn about another.
223@end itemize
224
49efadf5 225You can use @value{GDBN} to debug programs written in C and C@t{++}.
79a6e687 226For more information, see @ref{Supported Languages,,Supported Languages}.
c906108c
SS
227For more information, see @ref{C,,C and C++}.
228
6aecb9c2
JB
229Support for D is partial. For information on D, see
230@ref{D,,D}.
231
cce74817 232@cindex Modula-2
e632838e
AC
233Support for Modula-2 is partial. For information on Modula-2, see
234@ref{Modula-2,,Modula-2}.
c906108c 235
f4b8a18d
KW
236Support for OpenCL C is partial. For information on OpenCL C, see
237@ref{OpenCL C,,OpenCL C}.
238
cce74817
JM
239@cindex Pascal
240Debugging Pascal programs which use sets, subranges, file variables, or
241nested functions does not currently work. @value{GDBN} does not support
242entering expressions, printing values, or similar features using Pascal
243syntax.
c906108c 244
c906108c
SS
245@cindex Fortran
246@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 247it may be necessary to refer to some variables with a trailing
cce74817 248underscore.
c906108c 249
b37303ee
AF
250@value{GDBN} can be used to debug programs written in Objective-C,
251using either the Apple/NeXT or the GNU Objective-C runtime.
252
c906108c
SS
253@menu
254* Free Software:: Freely redistributable software
984359d2 255* Free Documentation:: Free Software Needs Free Documentation
c906108c
SS
256* Contributors:: Contributors to GDB
257@end menu
258
6d2ebf8b 259@node Free Software
79a6e687 260@unnumberedsec Free Software
c906108c 261
5d161b24 262@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
263General Public License
264(GPL). The GPL gives you the freedom to copy or adapt a licensed
265program---but every person getting a copy also gets with it the
266freedom to modify that copy (which means that they must get access to
267the source code), and the freedom to distribute further copies.
268Typical software companies use copyrights to limit your freedoms; the
269Free Software Foundation uses the GPL to preserve these freedoms.
270
271Fundamentally, the General Public License is a license which says that
272you have these freedoms and that you cannot take these freedoms away
273from anyone else.
274
984359d2 275@node Free Documentation
2666264b 276@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
277
278The biggest deficiency in the free software community today is not in
279the software---it is the lack of good free documentation that we can
280include with the free software. Many of our most important
281programs do not come with free reference manuals and free introductory
282texts. Documentation is an essential part of any software package;
283when an important free software package does not come with a free
284manual and a free tutorial, that is a major gap. We have many such
285gaps today.
286
287Consider Perl, for instance. The tutorial manuals that people
288normally use are non-free. How did this come about? Because the
289authors of those manuals published them with restrictive terms---no
290copying, no modification, source files not available---which exclude
291them from the free software world.
292
293That wasn't the first time this sort of thing happened, and it was far
294from the last. Many times we have heard a GNU user eagerly describe a
295manual that he is writing, his intended contribution to the community,
296only to learn that he had ruined everything by signing a publication
297contract to make it non-free.
298
299Free documentation, like free software, is a matter of freedom, not
300price. The problem with the non-free manual is not that publishers
301charge a price for printed copies---that in itself is fine. (The Free
302Software Foundation sells printed copies of manuals, too.) The
303problem is the restrictions on the use of the manual. Free manuals
304are available in source code form, and give you permission to copy and
305modify. Non-free manuals do not allow this.
306
307The criteria of freedom for a free manual are roughly the same as for
308free software. Redistribution (including the normal kinds of
309commercial redistribution) must be permitted, so that the manual can
310accompany every copy of the program, both on-line and on paper.
311
312Permission for modification of the technical content is crucial too.
313When people modify the software, adding or changing features, if they
314are conscientious they will change the manual too---so they can
315provide accurate and clear documentation for the modified program. A
316manual that leaves you no choice but to write a new manual to document
317a changed version of the program is not really available to our
318community.
319
320Some kinds of limits on the way modification is handled are
321acceptable. For example, requirements to preserve the original
322author's copyright notice, the distribution terms, or the list of
323authors, are ok. It is also no problem to require modified versions
324to include notice that they were modified. Even entire sections that
325may not be deleted or changed are acceptable, as long as they deal
326with nontechnical topics (like this one). These kinds of restrictions
327are acceptable because they don't obstruct the community's normal use
328of the manual.
329
330However, it must be possible to modify all the @emph{technical}
331content of the manual, and then distribute the result in all the usual
332media, through all the usual channels. Otherwise, the restrictions
333obstruct the use of the manual, it is not free, and we need another
334manual to replace it.
335
336Please spread the word about this issue. Our community continues to
337lose manuals to proprietary publishing. If we spread the word that
338free software needs free reference manuals and free tutorials, perhaps
339the next person who wants to contribute by writing documentation will
340realize, before it is too late, that only free manuals contribute to
341the free software community.
342
343If you are writing documentation, please insist on publishing it under
344the GNU Free Documentation License or another free documentation
345license. Remember that this decision requires your approval---you
346don't have to let the publisher decide. Some commercial publishers
347will use a free license if you insist, but they will not propose the
348option; it is up to you to raise the issue and say firmly that this is
349what you want. If the publisher you are dealing with refuses, please
350try other publishers. If you're not sure whether a proposed license
42584a72 351is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
352
353You can encourage commercial publishers to sell more free, copylefted
354manuals and tutorials by buying them, and particularly by buying
355copies from the publishers that paid for their writing or for major
356improvements. Meanwhile, try to avoid buying non-free documentation
357at all. Check the distribution terms of a manual before you buy it,
358and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
359Check the history of the book, and try to reward the publishers that
360have paid or pay the authors to work on it.
959acfd1
EZ
361
362The Free Software Foundation maintains a list of free documentation
363published by other publishers, at
364@url{http://www.fsf.org/doc/other-free-books.html}.
365
6d2ebf8b 366@node Contributors
96a2c332
SS
367@unnumberedsec Contributors to @value{GDBN}
368
369Richard Stallman was the original author of @value{GDBN}, and of many
370other @sc{gnu} programs. Many others have contributed to its
371development. This section attempts to credit major contributors. One
372of the virtues of free software is that everyone is free to contribute
373to it; with regret, we cannot actually acknowledge everyone here. The
374file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
375blow-by-blow account.
376
377Changes much prior to version 2.0 are lost in the mists of time.
378
379@quotation
380@emph{Plea:} Additions to this section are particularly welcome. If you
381or your friends (or enemies, to be evenhanded) have been unfairly
382omitted from this list, we would like to add your names!
383@end quotation
384
385So that they may not regard their many labors as thankless, we
386particularly thank those who shepherded @value{GDBN} through major
387releases:
7ba3cf9c 388Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
389Jim Blandy (release 4.18);
390Jason Molenda (release 4.17);
391Stan Shebs (release 4.14);
392Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
393Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
394John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
395Jim Kingdon (releases 3.5, 3.4, and 3.3);
396and Randy Smith (releases 3.2, 3.1, and 3.0).
397
398Richard Stallman, assisted at various times by Peter TerMaat, Chris
399Hanson, and Richard Mlynarik, handled releases through 2.8.
400
b37052ae
EZ
401Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
402in @value{GDBN}, with significant additional contributions from Per
403Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
404demangler. Early work on C@t{++} was by Peter TerMaat (who also did
405much general update work leading to release 3.0).
c906108c 406
b37052ae 407@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
408object-file formats; BFD was a joint project of David V.
409Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
410
411David Johnson wrote the original COFF support; Pace Willison did
412the original support for encapsulated COFF.
413
0179ffac 414Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
415
416Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
417Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
418support.
419Jean-Daniel Fekete contributed Sun 386i support.
420Chris Hanson improved the HP9000 support.
421Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
422David Johnson contributed Encore Umax support.
423Jyrki Kuoppala contributed Altos 3068 support.
424Jeff Law contributed HP PA and SOM support.
425Keith Packard contributed NS32K support.
426Doug Rabson contributed Acorn Risc Machine support.
427Bob Rusk contributed Harris Nighthawk CX-UX support.
428Chris Smith contributed Convex support (and Fortran debugging).
429Jonathan Stone contributed Pyramid support.
430Michael Tiemann contributed SPARC support.
431Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
432Pace Willison contributed Intel 386 support.
433Jay Vosburgh contributed Symmetry support.
a37295f9 434Marko Mlinar contributed OpenRISC 1000 support.
c906108c 435
1104b9e7 436Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
437
438Rich Schaefer and Peter Schauer helped with support of SunOS shared
439libraries.
440
441Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
442about several machine instruction sets.
443
444Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
445remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
446contributed remote debugging modules for the i960, VxWorks, A29K UDI,
447and RDI targets, respectively.
448
449Brian Fox is the author of the readline libraries providing
450command-line editing and command history.
451
7a292a7a
SS
452Andrew Beers of SUNY Buffalo wrote the language-switching code, the
453Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 454
5d161b24 455Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 456He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 457symbols.
c906108c 458
f24c5e49
KI
459Hitachi America (now Renesas America), Ltd. sponsored the support for
460H8/300, H8/500, and Super-H processors.
c906108c
SS
461
462NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
463
f24c5e49
KI
464Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
465processors.
c906108c
SS
466
467Toshiba sponsored the support for the TX39 Mips processor.
468
469Matsushita sponsored the support for the MN10200 and MN10300 processors.
470
96a2c332 471Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
472
473Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
474watchpoints.
475
476Michael Snyder added support for tracepoints.
477
478Stu Grossman wrote gdbserver.
479
480Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 481nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
482
483The following people at the Hewlett-Packard Company contributed
484support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 485(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
486compiler, and the Text User Interface (nee Terminal User Interface):
487Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
488Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
489provided HP-specific information in this manual.
c906108c 490
b37052ae
EZ
491DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
492Robert Hoehne made significant contributions to the DJGPP port.
493
96a2c332
SS
494Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
495development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
496fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
497Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
498Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
499Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
500Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
501addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
502JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
503Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
504Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
505Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
506Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
507Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
508Zuhn have made contributions both large and small.
c906108c 509
ffed4509
AC
510Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
511Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
512
e2e0bcd1
JB
513Jim Blandy added support for preprocessor macros, while working for Red
514Hat.
c906108c 515
a9967aef
AC
516Andrew Cagney designed @value{GDBN}'s architecture vector. Many
517people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
518Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
519Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
520Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
521with the migration of old architectures to this new framework.
522
c5e30d01
AC
523Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
524unwinder framework, this consisting of a fresh new design featuring
525frame IDs, independent frame sniffers, and the sentinel frame. Mark
526Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
527libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
db2e3e2e 528trad unwinders. The architecture-specific changes, each involving a
c5e30d01
AC
529complete rewrite of the architecture's frame code, were carried out by
530Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
531Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
532Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
533Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
534Weigand.
535
ca3bf3bd
DJ
536Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
537Tensilica, Inc.@: contributed support for Xtensa processors. Others
538who have worked on the Xtensa port of @value{GDBN} in the past include
539Steve Tjiang, John Newlin, and Scott Foehner.
540
08be9d71
ME
541Michael Eager and staff of Xilinx, Inc., contributed support for the
542Xilinx MicroBlaze architecture.
543
387360da
JB
544Initial support for the FreeBSD/mips target and native configuration
545was developed by SRI International and the University of Cambridge
546Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
547("CTSRD"), as part of the DARPA CRASH research programme.
548
74792ff7
JB
549Initial support for the FreeBSD/riscv target and native configuration
550was developed by SRI International and the University of Cambridge
551Computer Laboratory (Department of Computer Science and Technology)
552under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the DARPA
553SSITH research programme.
554
a994fec4
FJ
555The original port to the OpenRISC 1000 is believed to be due to
556Alessandro Forin and Per Bothner. More recent ports have been the work
557of Jeremy Bennett, Franck Jullien, Stefan Wallentowitz and
558Stafford Horne.
559
39791af2
JM
560Weimin Pan, David Faust and Jose E. Marchesi contributed support for
561the Linux kernel BPF virtual architecture. This work was sponsored by
562Oracle.
563
6d2ebf8b 564@node Sample Session
c906108c
SS
565@chapter A Sample @value{GDBN} Session
566
567You can use this manual at your leisure to read all about @value{GDBN}.
568However, a handful of commands are enough to get started using the
569debugger. This chapter illustrates those commands.
570
571@iftex
572In this sample session, we emphasize user input like this: @b{input},
573to make it easier to pick out from the surrounding output.
574@end iftex
575
576@c FIXME: this example may not be appropriate for some configs, where
577@c FIXME...primary interest is in remote use.
578
579One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
580processor) exhibits the following bug: sometimes, when we change its
581quote strings from the default, the commands used to capture one macro
582definition within another stop working. In the following short @code{m4}
583session, we define a macro @code{foo} which expands to @code{0000}; we
584then use the @code{m4} built-in @code{defn} to define @code{bar} as the
585same thing. However, when we change the open quote string to
586@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
587procedure fails to define a new synonym @code{baz}:
588
589@smallexample
590$ @b{cd gnu/m4}
591$ @b{./m4}
592@b{define(foo,0000)}
593
594@b{foo}
5950000
596@b{define(bar,defn(`foo'))}
597
598@b{bar}
5990000
600@b{changequote(<QUOTE>,<UNQUOTE>)}
601
602@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
603@b{baz}
c8aa23ab 604@b{Ctrl-d}
c906108c
SS
605m4: End of input: 0: fatal error: EOF in string
606@end smallexample
607
608@noindent
609Let us use @value{GDBN} to try to see what is going on.
610
c906108c
SS
611@smallexample
612$ @b{@value{GDBP} m4}
613@c FIXME: this falsifies the exact text played out, to permit smallbook
614@c FIXME... format to come out better.
615@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 616 of it under certain conditions; type "show copying" to see
c906108c 617 the conditions.
5d161b24 618There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
619 for details.
620
621@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
622(@value{GDBP})
623@end smallexample
c906108c
SS
624
625@noindent
626@value{GDBN} reads only enough symbol data to know where to find the
627rest when needed; as a result, the first prompt comes up very quickly.
628We now tell @value{GDBN} to use a narrower display width than usual, so
629that examples fit in this manual.
630
631@smallexample
632(@value{GDBP}) @b{set width 70}
633@end smallexample
634
635@noindent
636We need to see how the @code{m4} built-in @code{changequote} works.
637Having looked at the source, we know the relevant subroutine is
638@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
639@code{break} command.
640
641@smallexample
642(@value{GDBP}) @b{break m4_changequote}
643Breakpoint 1 at 0x62f4: file builtin.c, line 879.
644@end smallexample
645
646@noindent
647Using the @code{run} command, we start @code{m4} running under @value{GDBN}
648control; as long as control does not reach the @code{m4_changequote}
649subroutine, the program runs as usual:
650
651@smallexample
652(@value{GDBP}) @b{run}
653Starting program: /work/Editorial/gdb/gnu/m4/m4
654@b{define(foo,0000)}
655
656@b{foo}
6570000
658@end smallexample
659
660@noindent
661To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
662suspends execution of @code{m4}, displaying information about the
663context where it stops.
664
665@smallexample
666@b{changequote(<QUOTE>,<UNQUOTE>)}
667
5d161b24 668Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
669 at builtin.c:879
670879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
671@end smallexample
672
673@noindent
674Now we use the command @code{n} (@code{next}) to advance execution to
675the next line of the current function.
676
677@smallexample
678(@value{GDBP}) @b{n}
679882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
680 : nil,
681@end smallexample
682
683@noindent
684@code{set_quotes} looks like a promising subroutine. We can go into it
685by using the command @code{s} (@code{step}) instead of @code{next}.
686@code{step} goes to the next line to be executed in @emph{any}
687subroutine, so it steps into @code{set_quotes}.
688
689@smallexample
690(@value{GDBP}) @b{s}
691set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
692 at input.c:530
693530 if (lquote != def_lquote)
694@end smallexample
695
696@noindent
697The display that shows the subroutine where @code{m4} is now
698suspended (and its arguments) is called a stack frame display. It
699shows a summary of the stack. We can use the @code{backtrace}
700command (which can also be spelled @code{bt}), to see where we are
701in the stack as a whole: the @code{backtrace} command displays a
702stack frame for each active subroutine.
703
704@smallexample
705(@value{GDBP}) @b{bt}
706#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
707 at input.c:530
5d161b24 708#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
709 at builtin.c:882
710#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
711#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
712 at macro.c:71
713#4 0x79dc in expand_input () at macro.c:40
714#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
715@end smallexample
716
717@noindent
718We step through a few more lines to see what happens. The first two
719times, we can use @samp{s}; the next two times we use @code{n} to avoid
720falling into the @code{xstrdup} subroutine.
721
722@smallexample
723(@value{GDBP}) @b{s}
7240x3b5c 532 if (rquote != def_rquote)
725(@value{GDBP}) @b{s}
7260x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
727def_lquote : xstrdup(lq);
728(@value{GDBP}) @b{n}
729536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
730 : xstrdup(rq);
731(@value{GDBP}) @b{n}
732538 len_lquote = strlen(rquote);
733@end smallexample
734
735@noindent
736The last line displayed looks a little odd; we can examine the variables
737@code{lquote} and @code{rquote} to see if they are in fact the new left
738and right quotes we specified. We use the command @code{p}
739(@code{print}) to see their values.
740
741@smallexample
742(@value{GDBP}) @b{p lquote}
743$1 = 0x35d40 "<QUOTE>"
744(@value{GDBP}) @b{p rquote}
745$2 = 0x35d50 "<UNQUOTE>"
746@end smallexample
747
748@noindent
749@code{lquote} and @code{rquote} are indeed the new left and right quotes.
750To look at some context, we can display ten lines of source
751surrounding the current line with the @code{l} (@code{list}) command.
752
753@smallexample
754(@value{GDBP}) @b{l}
755533 xfree(rquote);
756534
757535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
758 : xstrdup (lq);
759536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
760 : xstrdup (rq);
761537
762538 len_lquote = strlen(rquote);
763539 len_rquote = strlen(lquote);
764540 @}
765541
766542 void
767@end smallexample
768
769@noindent
770Let us step past the two lines that set @code{len_lquote} and
771@code{len_rquote}, and then examine the values of those variables.
772
773@smallexample
774(@value{GDBP}) @b{n}
775539 len_rquote = strlen(lquote);
776(@value{GDBP}) @b{n}
777540 @}
778(@value{GDBP}) @b{p len_lquote}
779$3 = 9
780(@value{GDBP}) @b{p len_rquote}
781$4 = 7
782@end smallexample
783
784@noindent
785That certainly looks wrong, assuming @code{len_lquote} and
786@code{len_rquote} are meant to be the lengths of @code{lquote} and
787@code{rquote} respectively. We can set them to better values using
788the @code{p} command, since it can print the value of
789any expression---and that expression can include subroutine calls and
790assignments.
791
792@smallexample
793(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
794$5 = 7
795(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
796$6 = 9
797@end smallexample
798
799@noindent
800Is that enough to fix the problem of using the new quotes with the
801@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
802executing with the @code{c} (@code{continue}) command, and then try the
803example that caused trouble initially:
804
805@smallexample
806(@value{GDBP}) @b{c}
807Continuing.
808
809@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
810
811baz
8120000
813@end smallexample
814
815@noindent
816Success! The new quotes now work just as well as the default ones. The
817problem seems to have been just the two typos defining the wrong
818lengths. We allow @code{m4} exit by giving it an EOF as input:
819
820@smallexample
c8aa23ab 821@b{Ctrl-d}
c906108c
SS
822Program exited normally.
823@end smallexample
824
825@noindent
826The message @samp{Program exited normally.} is from @value{GDBN}; it
827indicates @code{m4} has finished executing. We can end our @value{GDBN}
828session with the @value{GDBN} @code{quit} command.
829
830@smallexample
831(@value{GDBP}) @b{quit}
832@end smallexample
c906108c 833
6d2ebf8b 834@node Invocation
c906108c
SS
835@chapter Getting In and Out of @value{GDBN}
836
837This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 838The essentials are:
c906108c 839@itemize @bullet
5d161b24 840@item
53a5351d 841type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 842@item
c8aa23ab 843type @kbd{quit} or @kbd{Ctrl-d} to exit.
c906108c
SS
844@end itemize
845
846@menu
847* Invoking GDB:: How to start @value{GDBN}
848* Quitting GDB:: How to quit @value{GDBN}
849* Shell Commands:: How to use shell commands inside @value{GDBN}
79a6e687 850* Logging Output:: How to log @value{GDBN}'s output to a file
c906108c
SS
851@end menu
852
6d2ebf8b 853@node Invoking GDB
c906108c
SS
854@section Invoking @value{GDBN}
855
c906108c
SS
856Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
857@value{GDBN} reads commands from the terminal until you tell it to exit.
858
859You can also run @code{@value{GDBP}} with a variety of arguments and options,
860to specify more of your debugging environment at the outset.
861
c906108c
SS
862The command-line options described here are designed
863to cover a variety of situations; in some environments, some of these
5d161b24 864options may effectively be unavailable.
c906108c
SS
865
866The most usual way to start @value{GDBN} is with one argument,
867specifying an executable program:
868
474c8240 869@smallexample
c906108c 870@value{GDBP} @var{program}
474c8240 871@end smallexample
c906108c 872
c906108c
SS
873@noindent
874You can also start with both an executable program and a core file
875specified:
876
474c8240 877@smallexample
c906108c 878@value{GDBP} @var{program} @var{core}
474c8240 879@end smallexample
c906108c 880
4ed4690f
SM
881You can, instead, specify a process ID as a second argument or use option
882@code{-p}, if you want to debug a running process:
c906108c 883
474c8240 884@smallexample
c906108c 885@value{GDBP} @var{program} 1234
4ed4690f 886@value{GDBP} -p 1234
474c8240 887@end smallexample
c906108c
SS
888
889@noindent
4ed4690f
SM
890would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
891can omit the @var{program} filename.
c906108c 892
c906108c 893Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
894complete operating system; when you use @value{GDBN} as a remote
895debugger attached to a bare board, there may not be any notion of
896``process'', and there is often no way to get a core dump. @value{GDBN}
897will warn you if it is unable to attach or to read core dumps.
c906108c 898
aa26fa3a
TT
899You can optionally have @code{@value{GDBP}} pass any arguments after the
900executable file to the inferior using @code{--args}. This option stops
901option processing.
474c8240 902@smallexample
3f94c067 903@value{GDBP} --args gcc -O2 -c foo.c
474c8240 904@end smallexample
aa26fa3a
TT
905This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
906@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
907
96a2c332 908You can run @code{@value{GDBP}} without printing the front material, which describes
adcc0a31 909@value{GDBN}'s non-warranty, by specifying @code{--silent}
910(or @code{-q}/@code{--quiet}):
c906108c
SS
911
912@smallexample
adcc0a31 913@value{GDBP} --silent
c906108c
SS
914@end smallexample
915
916@noindent
917You can further control how @value{GDBN} starts up by using command-line
918options. @value{GDBN} itself can remind you of the options available.
919
920@noindent
921Type
922
474c8240 923@smallexample
c906108c 924@value{GDBP} -help
474c8240 925@end smallexample
c906108c
SS
926
927@noindent
928to display all available options and briefly describe their use
929(@samp{@value{GDBP} -h} is a shorter equivalent).
930
931All options and command line arguments you give are processed
932in sequential order. The order makes a difference when the
933@samp{-x} option is used.
934
935
936@menu
c906108c
SS
937* File Options:: Choosing files
938* Mode Options:: Choosing modes
6fc08d32 939* Startup:: What @value{GDBN} does during startup
64aaad63 940* Initialization Files:: Initialization Files
c906108c
SS
941@end menu
942
6d2ebf8b 943@node File Options
79a6e687 944@subsection Choosing Files
c906108c 945
2df3850c 946When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
947specifying an executable file and core file (or process ID). This is
948the same as if the arguments were specified by the @samp{-se} and
d52fb0e9 949@samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
19837790
MS
950first argument that does not have an associated option flag as
951equivalent to the @samp{-se} option followed by that argument; and the
952second argument that does not have an associated option flag, if any, as
953equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
954If the second argument begins with a decimal digit, @value{GDBN} will
955first attempt to attach to it as a process, and if that fails, attempt
956to open it as a corefile. If you have a corefile whose name begins with
b383017d 957a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 958prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
959
960If @value{GDBN} has not been configured to included core file support,
961such as for most embedded targets, then it will complain about a second
962argument and ignore it.
c906108c
SS
963
964Many options have both long and short forms; both are shown in the
965following list. @value{GDBN} also recognizes the long forms if you truncate
966them, so long as enough of the option is present to be unambiguous.
967(If you prefer, you can flag option arguments with @samp{--} rather
968than @samp{-}, though we illustrate the more usual convention.)
969
d700128c
EZ
970@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
971@c way, both those who look for -foo and --foo in the index, will find
972@c it.
973
c906108c
SS
974@table @code
975@item -symbols @var{file}
976@itemx -s @var{file}
d700128c
EZ
977@cindex @code{--symbols}
978@cindex @code{-s}
c906108c
SS
979Read symbol table from file @var{file}.
980
981@item -exec @var{file}
982@itemx -e @var{file}
d700128c
EZ
983@cindex @code{--exec}
984@cindex @code{-e}
7a292a7a
SS
985Use file @var{file} as the executable file to execute when appropriate,
986and for examining pure data in conjunction with a core dump.
c906108c
SS
987
988@item -se @var{file}
d700128c 989@cindex @code{--se}
c906108c
SS
990Read symbol table from file @var{file} and use it as the executable
991file.
992
c906108c
SS
993@item -core @var{file}
994@itemx -c @var{file}
d700128c
EZ
995@cindex @code{--core}
996@cindex @code{-c}
b383017d 997Use file @var{file} as a core dump to examine.
c906108c 998
19837790
MS
999@item -pid @var{number}
1000@itemx -p @var{number}
1001@cindex @code{--pid}
1002@cindex @code{-p}
1003Connect to process ID @var{number}, as with the @code{attach} command.
c906108c
SS
1004
1005@item -command @var{file}
1006@itemx -x @var{file}
d700128c
EZ
1007@cindex @code{--command}
1008@cindex @code{-x}
95433b34
JB
1009Execute commands from file @var{file}. The contents of this file is
1010evaluated exactly as the @code{source} command would.
8150ff9c 1011@xref{Command Files,, Command files}.
c906108c 1012
8a5a3c82
AS
1013@item -eval-command @var{command}
1014@itemx -ex @var{command}
1015@cindex @code{--eval-command}
1016@cindex @code{-ex}
1017Execute a single @value{GDBN} command.
1018
1019This option may be used multiple times to call multiple commands. It may
1020also be interleaved with @samp{-command} as required.
1021
1022@smallexample
1023@value{GDBP} -ex 'target sim' -ex 'load' \
1024 -x setbreakpoints -ex 'run' a.out
1025@end smallexample
1026
8320cc4f
JK
1027@item -init-command @var{file}
1028@itemx -ix @var{file}
1029@cindex @code{--init-command}
1030@cindex @code{-ix}
2d7b58e8
JK
1031Execute commands from file @var{file} before loading the inferior (but
1032after loading gdbinit files).
8320cc4f
JK
1033@xref{Startup}.
1034
1035@item -init-eval-command @var{command}
1036@itemx -iex @var{command}
1037@cindex @code{--init-eval-command}
1038@cindex @code{-iex}
2d7b58e8
JK
1039Execute a single @value{GDBN} command before loading the inferior (but
1040after loading gdbinit files).
8320cc4f
JK
1041@xref{Startup}.
1042
c906108c
SS
1043@item -directory @var{directory}
1044@itemx -d @var{directory}
d700128c
EZ
1045@cindex @code{--directory}
1046@cindex @code{-d}
4b505b12 1047Add @var{directory} to the path to search for source and script files.
c906108c 1048
c906108c
SS
1049@item -r
1050@itemx -readnow
d700128c
EZ
1051@cindex @code{--readnow}
1052@cindex @code{-r}
c906108c
SS
1053Read each symbol file's entire symbol table immediately, rather than
1054the default, which is to read it incrementally as it is needed.
1055This makes startup slower, but makes future operations faster.
53a5351d 1056
97cbe998
SDJ
1057@item --readnever
1058@anchor{--readnever}
1059@cindex @code{--readnever}, command-line option
1060Do not read each symbol file's symbolic debug information. This makes
1061startup faster but at the expense of not being able to perform
1062symbolic debugging. DWARF unwind information is also not read,
1063meaning backtraces may become incomplete or inaccurate. One use of
1064this is when a user simply wants to do the following sequence: attach,
1065dump core, detach. Loading the debugging information in this case is
1066an unnecessary cause of delay.
c906108c
SS
1067@end table
1068
6d2ebf8b 1069@node Mode Options
79a6e687 1070@subsection Choosing Modes
c906108c
SS
1071
1072You can run @value{GDBN} in various alternative modes---for example, in
1073batch mode or quiet mode.
1074
1075@table @code
bf88dd68 1076@anchor{-nx}
c906108c
SS
1077@item -nx
1078@itemx -n
d700128c
EZ
1079@cindex @code{--nx}
1080@cindex @code{-n}
64aaad63
AB
1081Do not execute commands found in any initialization files
1082(@pxref{Initialization Files}).
07540c15
DE
1083
1084@anchor{-nh}
1085@item -nh
1086@cindex @code{--nh}
64aaad63
AB
1087Do not execute commands found in any home directory initialization
1088file (@pxref{Initialization Files,,Home directory initialization
1089file}). The system wide and current directory initialization files
1090are still loaded.
c906108c
SS
1091
1092@item -quiet
d700128c 1093@itemx -silent
c906108c 1094@itemx -q
d700128c
EZ
1095@cindex @code{--quiet}
1096@cindex @code{--silent}
1097@cindex @code{-q}
c906108c
SS
1098``Quiet''. Do not print the introductory and copyright messages. These
1099messages are also suppressed in batch mode.
1100
1101@item -batch
d700128c 1102@cindex @code{--batch}
c906108c
SS
1103Run in batch mode. Exit with status @code{0} after processing all the
1104command files specified with @samp{-x} (and all commands from
1105initialization files, if not inhibited with @samp{-n}). Exit with
1106nonzero status if an error occurs in executing the @value{GDBN} commands
5da1313b
JK
1107in the command files. Batch mode also disables pagination, sets unlimited
1108terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1109off} were in effect (@pxref{Messages/Warnings}).
c906108c 1110
2df3850c
JM
1111Batch mode may be useful for running @value{GDBN} as a filter, for
1112example to download and run a program on another computer; in order to
1113make this more useful, the message
c906108c 1114
474c8240 1115@smallexample
c906108c 1116Program exited normally.
474c8240 1117@end smallexample
c906108c
SS
1118
1119@noindent
2df3850c
JM
1120(which is ordinarily issued whenever a program running under
1121@value{GDBN} control terminates) is not issued when running in batch
1122mode.
1123
1a088d06
AS
1124@item -batch-silent
1125@cindex @code{--batch-silent}
1126Run in batch mode exactly like @samp{-batch}, but totally silently. All
1127@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1128unaffected). This is much quieter than @samp{-silent} and would be useless
1129for an interactive session.
1130
1131This is particularly useful when using targets that give @samp{Loading section}
1132messages, for example.
1133
1134Note that targets that give their output via @value{GDBN}, as opposed to
1135writing directly to @code{stdout}, will also be made silent.
1136
4b0ad762
AS
1137@item -return-child-result
1138@cindex @code{--return-child-result}
1139The return code from @value{GDBN} will be the return code from the child
1140process (the process being debugged), with the following exceptions:
1141
1142@itemize @bullet
1143@item
1144@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1145internal error. In this case the exit code is the same as it would have been
1146without @samp{-return-child-result}.
1147@item
1148The user quits with an explicit value. E.g., @samp{quit 1}.
1149@item
1150The child process never runs, or is not allowed to terminate, in which case
1151the exit code will be -1.
1152@end itemize
1153
1154This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1155when @value{GDBN} is being used as a remote program loader or simulator
1156interface.
1157
2df3850c
JM
1158@item -nowindows
1159@itemx -nw
d700128c
EZ
1160@cindex @code{--nowindows}
1161@cindex @code{-nw}
2df3850c 1162``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1163(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1164interface. If no GUI is available, this option has no effect.
1165
1166@item -windows
1167@itemx -w
d700128c
EZ
1168@cindex @code{--windows}
1169@cindex @code{-w}
2df3850c
JM
1170If @value{GDBN} includes a GUI, then this option requires it to be
1171used if possible.
c906108c
SS
1172
1173@item -cd @var{directory}
d700128c 1174@cindex @code{--cd}
c906108c
SS
1175Run @value{GDBN} using @var{directory} as its working directory,
1176instead of the current directory.
1177
aae1c79a 1178@item -data-directory @var{directory}
8d551b02 1179@itemx -D @var{directory}
aae1c79a 1180@cindex @code{--data-directory}
8d551b02 1181@cindex @code{-D}
aae1c79a
DE
1182Run @value{GDBN} using @var{directory} as its data directory.
1183The data directory is where @value{GDBN} searches for its
1184auxiliary files. @xref{Data Files}.
1185
c906108c
SS
1186@item -fullname
1187@itemx -f
d700128c
EZ
1188@cindex @code{--fullname}
1189@cindex @code{-f}
7a292a7a
SS
1190@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1191subprocess. It tells @value{GDBN} to output the full file name and line
1192number in a standard, recognizable fashion each time a stack frame is
1193displayed (which includes each time your program stops). This
1194recognizable format looks like two @samp{\032} characters, followed by
1195the file name, line number and character position separated by colons,
1196and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1197@samp{\032} characters as a signal to display the source code for the
1198frame.
c906108c 1199
d700128c
EZ
1200@item -annotate @var{level}
1201@cindex @code{--annotate}
1202This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1203effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1204(@pxref{Annotations}). The annotation @var{level} controls how much
1205information @value{GDBN} prints together with its prompt, values of
1206expressions, source lines, and other types of output. Level 0 is the
1207normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1208@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1209that control @value{GDBN}, and level 2 has been deprecated.
1210
265eeb58 1211The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1212(@pxref{GDB/MI}).
d700128c 1213
aa26fa3a
TT
1214@item --args
1215@cindex @code{--args}
1216Change interpretation of command line so that arguments following the
1217executable file are passed as command line arguments to the inferior.
1218This option stops option processing.
1219
2df3850c
JM
1220@item -baud @var{bps}
1221@itemx -b @var{bps}
d700128c
EZ
1222@cindex @code{--baud}
1223@cindex @code{-b}
c906108c
SS
1224Set the line speed (baud rate or bits per second) of any serial
1225interface used by @value{GDBN} for remote debugging.
c906108c 1226
f47b1503
AS
1227@item -l @var{timeout}
1228@cindex @code{-l}
1229Set the timeout (in seconds) of any communication used by @value{GDBN}
1230for remote debugging.
1231
c906108c 1232@item -tty @var{device}
d700128c
EZ
1233@itemx -t @var{device}
1234@cindex @code{--tty}
1235@cindex @code{-t}
c906108c
SS
1236Run using @var{device} for your program's standard input and output.
1237@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1238
53a5351d 1239@c resolve the situation of these eventually
c4555f82
SC
1240@item -tui
1241@cindex @code{--tui}
d0d5df6f
AC
1242Activate the @dfn{Text User Interface} when starting. The Text User
1243Interface manages several text windows on the terminal, showing
1244source, assembly, registers and @value{GDBN} command outputs
217bff3e
JK
1245(@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1246option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1247Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d 1248
d700128c
EZ
1249@item -interpreter @var{interp}
1250@cindex @code{--interpreter}
1251Use the interpreter @var{interp} for interface with the controlling
1252program or device. This option is meant to be set by programs which
94bbb2c0 1253communicate with @value{GDBN} using it as a back end.
21c294e6 1254@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1255
b4be1b06
SM
1256@samp{--interpreter=mi} (or @samp{--interpreter=mi3}) causes
1257@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} version 3 (@pxref{GDB/MI, ,
1258The @sc{gdb/mi} Interface}) included since @value{GDBN} version 9.1. @sc{gdb/mi}
1259version 2 (@code{mi2}), included in @value{GDBN} 6.0 and version 1 (@code{mi1}),
1260included in @value{GDBN} 5.3, are also available. Earlier @sc{gdb/mi}
1261interfaces are no longer supported.
d700128c
EZ
1262
1263@item -write
1264@cindex @code{--write}
1265Open the executable and core files for both reading and writing. This
1266is equivalent to the @samp{set write on} command inside @value{GDBN}
1267(@pxref{Patching}).
1268
1269@item -statistics
1270@cindex @code{--statistics}
1271This option causes @value{GDBN} to print statistics about time and
1272memory usage after it completes each command and returns to the prompt.
1273
1274@item -version
1275@cindex @code{--version}
1276This option causes @value{GDBN} to print its version number and
1277no-warranty blurb, and exit.
1278
6eaaf48b
EZ
1279@item -configuration
1280@cindex @code{--configuration}
1281This option causes @value{GDBN} to print details about its build-time
1282configuration parameters, and then exit. These details can be
1283important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1284
c906108c
SS
1285@end table
1286
6fc08d32 1287@node Startup
79a6e687 1288@subsection What @value{GDBN} Does During Startup
6fc08d32
EZ
1289@cindex @value{GDBN} startup
1290
1291Here's the description of what @value{GDBN} does during session startup:
1292
1293@enumerate
1294@item
1295Sets up the command interpreter as specified by the command line
1296(@pxref{Mode Options, interpreter}).
1297
1298@item
1299@cindex init file
64aaad63
AB
1300Reads the system wide initialization file and the files from the
1301system wide initialization directory, @pxref{System Wide Init Files}.
098b41a6
JG
1302
1303@item
64aaad63
AB
1304Reads the initialization file (if any) in your home directory and
1305executes all the commands in that file, @pxref{Home Directory Init
1306File}.
6fc08d32 1307
2d7b58e8
JK
1308@anchor{Option -init-eval-command}
1309@item
1310Executes commands and command files specified by the @samp{-iex} and
1311@samp{-ix} options in their specified order. Usually you should use the
1312@samp{-ex} and @samp{-x} options instead, but this way you can apply
1313settings before @value{GDBN} init files get executed and before inferior
1314gets loaded.
1315
6fc08d32
EZ
1316@item
1317Processes command line options and operands.
1318
1319@item
64aaad63
AB
1320Reads and executes the commands from the initialization file (if any)
1321in the current working directory as long as @samp{set auto-load
1322local-gdbinit} is set to @samp{on} (@pxref{Init File in the Current
1323Directory}). This is only done if the current directory is different
1324from your home directory. Thus, you can have more than one init file,
1325one generic in your home directory, and another, specific to the
1326program you are debugging, in the directory where you invoke
1327@value{GDBN}. @xref{Init File in the Current Directory during
1328Startup}.
6fc08d32 1329
a86caf66
DE
1330@item
1331If the command line specified a program to debug, or a process to
1332attach to, or a core file, @value{GDBN} loads any auto-loaded
1333scripts provided for the program or for its loaded shared libraries.
1334@xref{Auto-loading}.
1335
1336If you wish to disable the auto-loading during startup,
1337you must do something like the following:
1338
1339@smallexample
bf88dd68 1340$ gdb -iex "set auto-load python-scripts off" myprogram
a86caf66
DE
1341@end smallexample
1342
8320cc4f
JK
1343Option @samp{-ex} does not work because the auto-loading is then turned
1344off too late.
a86caf66 1345
6fc08d32 1346@item
6fe37d23
JK
1347Executes commands and command files specified by the @samp{-ex} and
1348@samp{-x} options in their specified order. @xref{Command Files}, for
1349more details about @value{GDBN} command files.
6fc08d32
EZ
1350
1351@item
1352Reads the command history recorded in the @dfn{history file}.
d620b259 1353@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1354files where @value{GDBN} records it.
1355@end enumerate
1356
64aaad63
AB
1357@node Initialization Files
1358@subsection Initialization Files
1359@cindex init file name
6fc08d32 1360
64aaad63
AB
1361During startup (@pxref{Startup}) @value{GDBN} will execute commands
1362from several initialization files. These initialization files use the
1363same syntax as @dfn{command files} (@pxref{Command Files}) and are
1364processed by @value{GDBN} in the same way.
098b41a6 1365
64aaad63
AB
1366To display the list of initialization files loaded by @value{GDBN} at
1367startup, in the order they will be loaded, you can use @kbd{gdb
1368--help}.
1369
1370As the system wide and home directory initialization files are
1371processed before most command line options, changes to settings
1372(e.g. @samp{set complaints}) can affect subsequent processing of
1373command line options and operands.
1374
1375The following sections describe where @value{GDBN} looks for the
1376initialization and the order that the files are searched for.
1377
1378@anchor{System Wide Init Files}
1379@subsubsection System wide initialization files
1380
1381There are two locations that are searched for system wide
1382initialization files. Both of these locations are always checked:
1383
1384@table @code
1385
1386@item @file{system.gdbinit}
1387This is a single system-wide initialization file. Its location is
1388specified with the @code{--with-system-gdbinit} configure option
1389(@pxref{System-wide configuration}). It is loaded first when
1390@value{GDBN} starts, before command line options have been processed.
1391
1392@item @file{system.gdbinit.d}
1393This is the system-wide initialization directory. Its location is
1394specified with the @code{--with-system-gdbinit-dir} configure option
1395(@pxref{System-wide configuration}). Files in this directory are
1396loaded in alphabetical order immediately after @file{system.gdbinit}
1397(if enabled) when @value{GDBN} starts, before command line options
1398have been processed. Files need to have a recognized scripting
1399language extension (@file{.py}/@file{.scm}) or be named with a
1400@file{.gdb} extension to be interpreted as regular @value{GDBN}
1401commands. @value{GDBN} will not recurse into any subdirectories of
1402this directory.
1403
1404@end table
1405
1406It is possible to prevent the system wide initialization files from
1407being loaded using the @samp{-nx} command line option, @pxref{Mode
1408Options,,Choosing Modes}.
1409
1410@anchor{Home Directory Init File}
1411@subsubsection Home directory initialization file
1412@cindex @file{gdbinit}
6fc08d32 1413@cindex @file{.gdbinit}
119b882a 1414@cindex @file{gdb.ini}
119b882a 1415
64aaad63
AB
1416After loading the system wide initialization files @value{GDBN} will
1417look for an initialization file in the users home
1418directory@footnote{On DOS/Windows systems, the home directory is the
1419one pointed to by the @code{HOME} environment variable.}. There are a
1420number of locations that @value{GDBN} will search in the home
1421directory, these locations are searched in order and @value{GDBN} will
1422load the first file that it finds, and subsequent locations will not
1423be checked.
1424
1425On non-Apple hosts the locations searched are:
1426@table @file
1427@item $XDG_CONFIG_HOME/gdb/gdbinit
1428@item $HOME/.config/gdb/gdbinit
1429@item $HOME/.gdbinit
1430@end table
1431
1432While on Apple hosts the locations searched are:
1433@table @file
1434@item $HOME/Library/Preferences/gdb/gdbinit
1435@item $HOME/.gdbinit
1436@end table
1437
1438It is possible to prevent the home directory initialization file from
1439being loaded using the @samp{-nx} or @samp{-nh} command line options,
1440@pxref{Mode Options,,Choosing Modes}.
1441
1442The DJGPP port of @value{GDBN} uses the name @file{gdb.ini} instead of
1443@file{.gdbinit} or @file{gdbinit}, due to the limitations of file
1444names imposed by DOS filesystems. The Windows port of @value{GDBN}
1445uses the standard name, but if it finds a @file{gdb.ini} file in your
1446home directory, it warns you about that and suggests to rename the
1447file to the standard name.
1448
1449@anchor{Init File in the Current Directory during Startup}
1450@subsubsection Local directory initialization file
1451
1452@value{GDBN} will check the current directory for a file called
1453@file{.gdbinit}. It is loaded last, after command line options
1454other than @samp{-x} and @samp{-ex} have been processed. The command
1455line options @samp{-x} and @samp{-ex} are processed last, after
1456@file{.gdbinit} has been loaded, @pxref{File Options,,Choosing
1457Files}.
1458
1459If the file in the current directory was already loaded as the home
1460directory initialization file then it will not be loaded a second
1461time.
1462
1463It is possible to prevent the local directory initialization file from
1464being loaded using the @samp{-nx} command line option, @pxref{Mode
1465Options,,Choosing Modes}.
6fc08d32 1466
6d2ebf8b 1467@node Quitting GDB
c906108c
SS
1468@section Quitting @value{GDBN}
1469@cindex exiting @value{GDBN}
1470@cindex leaving @value{GDBN}
1471
1472@table @code
1473@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1474@kindex q @r{(@code{quit})}
96a2c332
SS
1475@item quit @r{[}@var{expression}@r{]}
1476@itemx q
1477To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1478@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1479do not supply @var{expression}, @value{GDBN} will terminate normally;
1480otherwise it will terminate using the result of @var{expression} as the
1481error code.
c906108c
SS
1482@end table
1483
1484@cindex interrupt
c8aa23ab 1485An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1486terminates the action of any @value{GDBN} command that is in progress and
1487returns to @value{GDBN} command level. It is safe to type the interrupt
1488character at any time because @value{GDBN} does not allow it to take effect
1489until a time when it is safe.
1490
c906108c
SS
1491If you have been using @value{GDBN} to control an attached process or
1492device, you can release it with the @code{detach} command
79a6e687 1493(@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 1494
6d2ebf8b 1495@node Shell Commands
79a6e687 1496@section Shell Commands
c906108c
SS
1497
1498If you need to execute occasional shell commands during your
1499debugging session, there is no need to leave or suspend @value{GDBN}; you can
1500just use the @code{shell} command.
1501
1502@table @code
1503@kindex shell
ed59ded5 1504@kindex !
c906108c 1505@cindex shell escape
ed59ded5
DE
1506@item shell @var{command-string}
1507@itemx !@var{command-string}
1508Invoke a standard shell to execute @var{command-string}.
1509Note that no space is needed between @code{!} and @var{command-string}.
edf92af0
EZ
1510On GNU and Unix systems, the environment variable @code{SHELL}, if it
1511exists, determines which shell to run. Otherwise @value{GDBN} uses
1512the default shell (@file{/bin/sh} on GNU and Unix systems,
1513@file{cmd.exe} on MS-Windows, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1514@end table
1515
1516The utility @code{make} is often needed in development environments.
1517You do not have to use the @code{shell} command for this purpose in
1518@value{GDBN}:
1519
1520@table @code
1521@kindex make
1522@cindex calling make
1523@item make @var{make-args}
1524Execute the @code{make} program with the specified
1525arguments. This is equivalent to @samp{shell make @var{make-args}}.
1526@end table
1527
e2c52041
PW
1528@table @code
1529@kindex pipe
1530@kindex |
1531@cindex send the output of a gdb command to a shell command
1532@anchor{pipe}
1533@item pipe [@var{command}] | @var{shell_command}
1534@itemx | [@var{command}] | @var{shell_command}
1535@itemx pipe -d @var{delim} @var{command} @var{delim} @var{shell_command}
1536@itemx | -d @var{delim} @var{command} @var{delim} @var{shell_command}
1537Executes @var{command} and sends its output to @var{shell_command}.
1538Note that no space is needed around @code{|}.
1539If no @var{command} is provided, the last command executed is repeated.
1540
1541In case the @var{command} contains a @code{|}, the option @code{-d @var{delim}}
1542can be used to specify an alternate delimiter string @var{delim} that separates
1543the @var{command} from the @var{shell_command}.
1544
1545Example:
1546@smallexample
1547@group
1548(gdb) p var
1549$1 = @{
1550 black = 144,
1551 red = 233,
1552 green = 377,
1553 blue = 610,
1554 white = 987
1555@}
1556@end group
1557@group
1558(gdb) pipe p var|wc
1559 7 19 80
1560(gdb) |p var|wc -l
15617
1562@end group
1563@group
1564(gdb) p /x var
1565$4 = @{
1566 black = 0x90,
1567 red = 0xe9,
1568 green = 0x179,
1569 blue = 0x262,
1570 white = 0x3db
1571@}
1572(gdb) ||grep red
1573 red => 0xe9,
1574@end group
1575@group
1576(gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
1577this contains a PIPE char
1578(gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
1579this contains a PIPE char!
1580(gdb)
1581@end group
1582@end smallexample
1583@end table
1584
1585The convenience variables @code{$_shell_exitcode} and @code{$_shell_exitsignal}
1586can be used to examine the exit status of the last shell command launched
1587by @code{shell}, @code{make}, @code{pipe} and @code{|}.
1588@xref{Convenience Vars,, Convenience Variables}.
1589
79a6e687
BW
1590@node Logging Output
1591@section Logging Output
0fac0b41 1592@cindex logging @value{GDBN} output
9c16f35a 1593@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1594
1595You may want to save the output of @value{GDBN} commands to a file.
1596There are several commands to control @value{GDBN}'s logging.
1597
1598@table @code
1599@kindex set logging
1600@item set logging on
1601Enable logging.
1602@item set logging off
1603Disable logging.
9c16f35a 1604@cindex logging file name
0fac0b41
DJ
1605@item set logging file @var{file}
1606Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1607@item set logging overwrite [on|off]
1608By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1609you want @code{set logging on} to overwrite the logfile instead.
1610@item set logging redirect [on|off]
1611By default, @value{GDBN} output will go to both the terminal and the logfile.
1612Set @code{redirect} if you want output to go only to the log file.
b7060614
AH
1613@item set logging debugredirect [on|off]
1614By default, @value{GDBN} debug output will go to both the terminal and the logfile.
1615Set @code{debugredirect} if you want debug output to go only to the log file.
0fac0b41
DJ
1616@kindex show logging
1617@item show logging
1618Show the current values of the logging settings.
1619@end table
1620
e2c52041
PW
1621You can also redirect the output of a @value{GDBN} command to a
1622shell command. @xref{pipe}.
6d2ebf8b 1623@node Commands
c906108c
SS
1624@chapter @value{GDBN} Commands
1625
1626You can abbreviate a @value{GDBN} command to the first few letters of the command
1627name, if that abbreviation is unambiguous; and you can repeat certain
1628@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1629key to get @value{GDBN} to fill out the rest of a word in a command (or to
1630show you the alternatives available, if there is more than one possibility).
1631
1632@menu
1633* Command Syntax:: How to give commands to @value{GDBN}
fdbc9870 1634* Command Settings:: How to change default behavior of commands
c906108c 1635* Completion:: Command completion
3345721a 1636* Command Options:: Command options
c906108c
SS
1637* Help:: How to ask @value{GDBN} for help
1638@end menu
1639
6d2ebf8b 1640@node Command Syntax
79a6e687 1641@section Command Syntax
c906108c
SS
1642
1643A @value{GDBN} command is a single line of input. There is no limit on
1644how long it can be. It starts with a command name, which is followed by
1645arguments whose meaning depends on the command name. For example, the
1646command @code{step} accepts an argument which is the number of times to
1647step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1648with no arguments. Some commands do not allow any arguments.
c906108c
SS
1649
1650@cindex abbreviation
1651@value{GDBN} command names may always be truncated if that abbreviation is
1652unambiguous. Other possible command abbreviations are listed in the
1653documentation for individual commands. In some cases, even ambiguous
1654abbreviations are allowed; for example, @code{s} is specially defined as
1655equivalent to @code{step} even though there are other commands whose
1656names start with @code{s}. You can test abbreviations by using them as
1657arguments to the @code{help} command.
1658
1659@cindex repeating commands
41afff9a 1660@kindex RET @r{(repeat last command)}
c906108c 1661A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1662repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1663will not repeat this way; these are commands whose unintentional
1664repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1665repeat. User-defined commands can disable this feature; see
1666@ref{Define, dont-repeat}.
c906108c
SS
1667
1668The @code{list} and @code{x} commands, when you repeat them with
1669@key{RET}, construct new arguments rather than repeating
1670exactly as typed. This permits easy scanning of source or memory.
1671
1672@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1673output, in a way similar to the common utility @code{more}
79a6e687 1674(@pxref{Screen Size,,Screen Size}). Since it is easy to press one
c906108c
SS
1675@key{RET} too many in this situation, @value{GDBN} disables command
1676repetition after any command that generates this sort of display.
1677
41afff9a 1678@kindex # @r{(a comment)}
c906108c
SS
1679@cindex comment
1680Any text from a @kbd{#} to the end of the line is a comment; it does
1681nothing. This is useful mainly in command files (@pxref{Command
79a6e687 1682Files,,Command Files}).
c906108c 1683
88118b3a 1684@cindex repeating command sequences
c8aa23ab
EZ
1685@kindex Ctrl-o @r{(operate-and-get-next)}
1686The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1687commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1688then fetches the next line relative to the current line from the history
1689for editing.
1690
fdbc9870
PA
1691
1692@node Command Settings
1693@section Command Settings
1694@cindex default behavior of commands, changing
1695@cindex default settings, changing
1696
1697Many commands change their behavior according to command-specific
1698variables or settings. These settings can be changed with the
1699@code{set} subcommands. For example, the @code{print} command
1700(@pxref{Data, ,Examining Data}) prints arrays differently depending on
1701settings changeable with the commands @code{set print elements
1702NUMBER-OF-ELEMENTS} and @code{set print array-indexes}, among others.
1703
1704You can change these settings to your preference in the gdbinit files
1705loaded at @value{GDBN} startup. @xref{Startup}.
1706
1707The settings can also be changed interactively during the debugging
1708session. For example, to change the limit of array elements to print,
1709you can do the following:
1710@smallexample
1711(@value{GDBN}) set print elements 10
1712(@value{GDBN}) print some_array
1713$1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1714@end smallexample
1715
1716The above @code{set print elements 10} command changes the number of
1717elements to print from the default of 200 to 10. If you only intend
1718this limit of 10 to be used for printing @code{some_array}, then you
1719must restore the limit back to 200, with @code{set print elements
1720200}.
1721
1722Some commands allow overriding settings with command options. For
1723example, the @code{print} command supports a number of options that
1724allow overriding relevant global print settings as set by @code{set
1725print} subcommands. @xref{print options}. The example above could be
1726rewritten as:
1727@smallexample
1728(@value{GDBN}) print -elements 10 -- some_array
1729$1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1730@end smallexample
1731
1732Alternatively, you can use the @code{with} command to change a setting
1733temporarily, for the duration of a command invocation.
1734
1735@table @code
1736@kindex with command
1737@kindex w @r{(@code{with})}
1738@cindex settings
1739@cindex temporarily change settings
1740@item with @var{setting} [@var{value}] [-- @var{command}]
1741@itemx w @var{setting} [@var{value}] [-- @var{command}]
1742Temporarily set @var{setting} to @var{value} for the duration of
1743@var{command}.
1744
1745@var{setting} is any setting you can change with the @code{set}
1746subcommands. @var{value} is the value to assign to @code{setting}
1747while running @code{command}.
1748
1749If no @var{command} is provided, the last command executed is
1750repeated.
1751
1752If a @var{command} is provided, it must be preceded by a double dash
1753(@code{--}) separator. This is required because some settings accept
1754free-form arguments, such as expressions or filenames.
1755
1756For example, the command
1757@smallexample
1758(@value{GDBN}) with print array on -- print some_array
1759@end smallexample
1760@noindent
1761is equivalent to the following 3 commands:
1762@smallexample
1763(@value{GDBN}) set print array on
1764(@value{GDBN}) print some_array
1765(@value{GDBN}) set print array off
1766@end smallexample
1767
1768The @code{with} command is particularly useful when you want to
1769override a setting while running user-defined commands, or commands
1770defined in Python or Guile. @xref{Extending GDB,, Extending GDB}.
1771
1772@smallexample
1773(@value{GDBN}) with print pretty on -- my_complex_command
1774@end smallexample
1775
1776To change several settings for the same command, you can nest
1777@code{with} commands. For example, @code{with language ada -- with
1778print elements 10} temporarily changes the language to Ada and sets a
1779limit of 10 elements to print for arrays and strings.
1780
1781@end table
1782
6d2ebf8b 1783@node Completion
79a6e687 1784@section Command Completion
c906108c
SS
1785
1786@cindex completion
1787@cindex word completion
1788@value{GDBN} can fill in the rest of a word in a command for you, if there is
1789only one possibility; it can also show you what the valid possibilities
1790are for the next word in a command, at any time. This works for @value{GDBN}
3345721a
PA
1791commands, @value{GDBN} subcommands, command options, and the names of symbols
1792in your program.
c906108c
SS
1793
1794Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1795of a word. If there is only one possibility, @value{GDBN} fills in the
1796word, and waits for you to finish the command (or press @key{RET} to
1797enter it). For example, if you type
1798
1799@c FIXME "@key" does not distinguish its argument sufficiently to permit
1800@c complete accuracy in these examples; space introduced for clarity.
1801@c If texinfo enhancements make it unnecessary, it would be nice to
1802@c replace " @key" by "@key" in the following...
474c8240 1803@smallexample
c906108c 1804(@value{GDBP}) info bre @key{TAB}
474c8240 1805@end smallexample
c906108c
SS
1806
1807@noindent
1808@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1809the only @code{info} subcommand beginning with @samp{bre}:
1810
474c8240 1811@smallexample
c906108c 1812(@value{GDBP}) info breakpoints
474c8240 1813@end smallexample
c906108c
SS
1814
1815@noindent
1816You can either press @key{RET} at this point, to run the @code{info
1817breakpoints} command, or backspace and enter something else, if
1818@samp{breakpoints} does not look like the command you expected. (If you
1819were sure you wanted @code{info breakpoints} in the first place, you
1820might as well just type @key{RET} immediately after @samp{info bre},
1821to exploit command abbreviations rather than command completion).
1822
1823If there is more than one possibility for the next word when you press
1824@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1825characters and try again, or just press @key{TAB} a second time;
1826@value{GDBN} displays all the possible completions for that word. For
1827example, you might want to set a breakpoint on a subroutine whose name
1828begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1829just sounds the bell. Typing @key{TAB} again displays all the
1830function names in your program that begin with those characters, for
1831example:
1832
474c8240 1833@smallexample
c906108c
SS
1834(@value{GDBP}) b make_ @key{TAB}
1835@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1836make_a_section_from_file make_environ
1837make_abs_section make_function_type
1838make_blockvector make_pointer_type
1839make_cleanup make_reference_type
c906108c
SS
1840make_command make_symbol_completion_list
1841(@value{GDBP}) b make_
474c8240 1842@end smallexample
c906108c
SS
1843
1844@noindent
1845After displaying the available possibilities, @value{GDBN} copies your
1846partial input (@samp{b make_} in the example) so you can finish the
1847command.
1848
1849If you just want to see the list of alternatives in the first place, you
b37052ae 1850can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1851means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1852key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1853one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c 1854
ef0b411a
GB
1855If the number of possible completions is large, @value{GDBN} will
1856print as much of the list as it has collected, as well as a message
1857indicating that the list may be truncated.
1858
1859@smallexample
1860(@value{GDBP}) b m@key{TAB}@key{TAB}
1861main
1862<... the rest of the possible completions ...>
1863*** List may be truncated, max-completions reached. ***
1864(@value{GDBP}) b m
1865@end smallexample
1866
1867@noindent
1868This behavior can be controlled with the following commands:
1869
1870@table @code
1871@kindex set max-completions
1872@item set max-completions @var{limit}
1873@itemx set max-completions unlimited
1874Set the maximum number of completion candidates. @value{GDBN} will
1875stop looking for more completions once it collects this many candidates.
1876This is useful when completing on things like function names as collecting
1877all the possible candidates can be time consuming.
1878The default value is 200. A value of zero disables tab-completion.
1879Note that setting either no limit or a very large limit can make
1880completion slow.
1881@kindex show max-completions
1882@item show max-completions
1883Show the maximum number of candidates that @value{GDBN} will collect and show
1884during completion.
1885@end table
1886
c906108c
SS
1887@cindex quotes in commands
1888@cindex completion of quoted strings
1889Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1890parentheses or other characters that @value{GDBN} normally excludes from
1891its notion of a word. To permit word completion to work in this
1892situation, you may enclose words in @code{'} (single quote marks) in
1893@value{GDBN} commands.
c906108c 1894
d044bac8
PA
1895A likely situation where you might need this is in typing an
1896expression that involves a C@t{++} symbol name with template
1897parameters. This is because when completing expressions, GDB treats
1898the @samp{<} character as word delimiter, assuming that it's the
1899less-than comparison operator (@pxref{C Operators, , C and C@t{++}
1900Operators}).
1901
1902For example, when you want to call a C@t{++} template function
1903interactively using the @code{print} or @code{call} commands, you may
1904need to distinguish whether you mean the version of @code{name} that
1905was specialized for @code{int}, @code{name<int>()}, or the version
1906that was specialized for @code{float}, @code{name<float>()}. To use
1907the word-completion facilities in this situation, type a single quote
b37052ae
EZ
1908@code{'} at the beginning of the function name. This alerts
1909@value{GDBN} that it may need to consider more information than usual
1910when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1911
474c8240 1912@smallexample
d044bac8
PA
1913(@value{GDBP}) p 'func< @kbd{M-?}
1914func<int>() func<float>()
1915(@value{GDBP}) p 'func<
474c8240 1916@end smallexample
c906108c 1917
d044bac8
PA
1918When setting breakpoints however (@pxref{Specify Location}), you don't
1919usually need to type a quote before the function name, because
1920@value{GDBN} understands that you want to set a breakpoint on a
1921function:
c906108c 1922
474c8240 1923@smallexample
d044bac8
PA
1924(@value{GDBP}) b func< @kbd{M-?}
1925func<int>() func<float>()
1926(@value{GDBP}) b func<
474c8240 1927@end smallexample
c906108c 1928
d044bac8
PA
1929This is true even in the case of typing the name of C@t{++} overloaded
1930functions (multiple definitions of the same function, distinguished by
1931argument type). For example, when you want to set a breakpoint you
1932don't need to distinguish whether you mean the version of @code{name}
1933that takes an @code{int} parameter, @code{name(int)}, or the version
1934that takes a @code{float} parameter, @code{name(float)}.
1935
1936@smallexample
1937(@value{GDBP}) b bubble( @kbd{M-?}
1938bubble(int) bubble(double)
1939(@value{GDBP}) b bubble(dou @kbd{M-?}
1940bubble(double)
1941@end smallexample
1942
1943See @ref{quoting names} for a description of other scenarios that
1944require quoting.
c906108c 1945
79a6e687
BW
1946For more information about overloaded functions, see @ref{C Plus Plus
1947Expressions, ,C@t{++} Expressions}. You can use the command @code{set
c906108c 1948overload-resolution off} to disable overload resolution;
79a6e687 1949see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
c906108c 1950
65d12d83
TT
1951@cindex completion of structure field names
1952@cindex structure field name completion
1953@cindex completion of union field names
1954@cindex union field name completion
1955When completing in an expression which looks up a field in a
1956structure, @value{GDBN} also tries@footnote{The completer can be
1957confused by certain kinds of invalid expressions. Also, it only
1958examines the static type of the expression, not the dynamic type.} to
1959limit completions to the field names available in the type of the
1960left-hand-side:
1961
1962@smallexample
1963(@value{GDBP}) p gdb_stdout.@kbd{M-?}
01124a23
DE
1964magic to_fputs to_rewind
1965to_data to_isatty to_write
1966to_delete to_put to_write_async_safe
1967to_flush to_read
65d12d83
TT
1968@end smallexample
1969
1970@noindent
1971This is because the @code{gdb_stdout} is a variable of the type
1972@code{struct ui_file} that is defined in @value{GDBN} sources as
1973follows:
1974
1975@smallexample
1976struct ui_file
1977@{
1978 int *magic;
1979 ui_file_flush_ftype *to_flush;
1980 ui_file_write_ftype *to_write;
01124a23 1981 ui_file_write_async_safe_ftype *to_write_async_safe;
65d12d83
TT
1982 ui_file_fputs_ftype *to_fputs;
1983 ui_file_read_ftype *to_read;
1984 ui_file_delete_ftype *to_delete;
1985 ui_file_isatty_ftype *to_isatty;
1986 ui_file_rewind_ftype *to_rewind;
1987 ui_file_put_ftype *to_put;
1988 void *to_data;
1989@}
1990@end smallexample
1991
3345721a
PA
1992@node Command Options
1993@section Command options
1994
1995@cindex command options
1996Some commands accept options starting with a leading dash. For
1997example, @code{print -pretty}. Similarly to command names, you can
1998abbreviate a @value{GDBN} option to the first few letters of the
1999option name, if that abbreviation is unambiguous, and you can also use
2000the @key{TAB} key to get @value{GDBN} to fill out the rest of a word
2001in an option (or to show you the alternatives available, if there is
2002more than one possibility).
2003
2004@cindex command options, raw input
2005Some commands take raw input as argument. For example, the print
2006command processes arbitrary expressions in any of the languages
2007supported by @value{GDBN}. With such commands, because raw input may
2008start with a leading dash that would be confused with an option or any
d8edc8b7
PW
2009of its abbreviations, e.g.@: @code{print -p} (short for @code{print
2010-pretty} or printing negative @code{p}?), if you specify any command
3345721a
PA
2011option, then you must use a double-dash (@code{--}) delimiter to
2012indicate the end of options.
2013
2014@cindex command options, boolean
2015
2016Some options are described as accepting an argument which can be
2017either @code{on} or @code{off}. These are known as @dfn{boolean
2018options}. Similarly to boolean settings commands---@code{on} and
2019@code{off} are the typical values, but any of @code{1}, @code{yes} and
2020@code{enable} can also be used as ``true'' value, and any of @code{0},
2021@code{no} and @code{disable} can also be used as ``false'' value. You
2022can also omit a ``true'' value, as it is implied by default.
2023
2024For example, these are equivalent:
2025
2026@smallexample
2027(@value{GDBP}) print -object on -pretty off -element unlimited -- *myptr
2028(@value{GDBP}) p -o -p 0 -e u -- *myptr
2029@end smallexample
2030
2031You can discover the set of options some command accepts by completing
2032on @code{-} after the command name. For example:
2033
2034@smallexample
2035(@value{GDBP}) print -@key{TAB}@key{TAB}
d8edc8b7
PW
2036-address -max-depth -raw-values -union
2037-array -null-stop -repeats -vtbl
2038-array-indexes -object -static-members
2039-elements -pretty -symbol
3345721a
PA
2040@end smallexample
2041
2042Completion will in some cases guide you with a suggestion of what kind
2043of argument an option expects. For example:
2044
2045@smallexample
2046(@value{GDBP}) print -elements @key{TAB}@key{TAB}
2047NUMBER unlimited
2048@end smallexample
2049
2050Here, the option expects a number (e.g., @code{100}), not literal
2051@code{NUMBER}. Such metasyntactical arguments are always presented in
2052uppercase.
2053
2054(For more on using the @code{print} command, see @ref{Data, ,Examining
2055Data}.)
c906108c 2056
6d2ebf8b 2057@node Help
79a6e687 2058@section Getting Help
c906108c
SS
2059@cindex online documentation
2060@kindex help
2061
5d161b24 2062You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
2063using the command @code{help}.
2064
2065@table @code
41afff9a 2066@kindex h @r{(@code{help})}
c906108c
SS
2067@item help
2068@itemx h
2069You can use @code{help} (abbreviated @code{h}) with no arguments to
2070display a short list of named classes of commands:
2071
2072@smallexample
2073(@value{GDBP}) help
2074List of classes of commands:
2075
5b860c93 2076aliases -- User-defined aliases of other commands
c906108c 2077breakpoints -- Making program stop at certain points
2df3850c 2078data -- Examining data
c906108c 2079files -- Specifying and examining files
2df3850c
JM
2080internals -- Maintenance commands
2081obscure -- Obscure features
2082running -- Running the program
2083stack -- Examining the stack
c906108c
SS
2084status -- Status inquiries
2085support -- Support facilities
12c27660 2086tracepoints -- Tracing of program execution without
96a2c332 2087 stopping the program
c906108c 2088user-defined -- User-defined commands
c906108c 2089
5d161b24 2090Type "help" followed by a class name for a list of
c906108c 2091commands in that class.
5d161b24 2092Type "help" followed by command name for full
c906108c
SS
2093documentation.
2094Command name abbreviations are allowed if unambiguous.
2095(@value{GDBP})
2096@end smallexample
96a2c332 2097@c the above line break eliminates huge line overfull...
c906108c
SS
2098
2099@item help @var{class}
2100Using one of the general help classes as an argument, you can get a
5b4a1a8d
PW
2101list of the individual commands in that class. If a command has
2102aliases, the aliases are given after the command name, separated by
5b860c93
PW
2103commas. If an alias has default arguments, the full definition of
2104the alias is given after the first line.
2105For example, here is the help display for the class @code{status}:
c906108c
SS
2106
2107@smallexample
2108(@value{GDBP}) help status
2109Status inquiries.
2110
2111List of commands:
2112
2113@c Line break in "show" line falsifies real output, but needed
2114@c to fit in smallbook page size.
5b4a1a8d 2115info, inf, i -- Generic command for showing things
12c27660 2116 about the program being debugged
5b860c93
PW
2117info address, iamain -- Describe where symbol SYM is stored.
2118 alias iamain = info address main
2119info all-registers -- List of all registers and their contents,
2120 for selected stack frame.
5b4a1a8d
PW
2121...
2122show, info set -- Generic command for showing things
12c27660 2123 about the debugger
c906108c 2124
5d161b24 2125Type "help" followed by command name for full
c906108c
SS
2126documentation.
2127Command name abbreviations are allowed if unambiguous.
2128(@value{GDBP})
2129@end smallexample
2130
2131@item help @var{command}
2132With a command name as @code{help} argument, @value{GDBN} displays a
5b4a1a8d
PW
2133short paragraph on how to use that command. If that command has
2134one or more aliases, @value{GDBN} will display a first line with
2135the command name and all its aliases separated by commas.
5b860c93
PW
2136This first line will be followed by the full definition of all aliases
2137having default arguments.
c906108c 2138
6837a0a2 2139@kindex apropos
e664d728 2140@item apropos [-v] @var{regexp}
09d4efe1 2141The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2 2142commands, and their documentation, for the regular expression specified in
e664d728
PW
2143@var{args}. It prints out all matches found. The optional flag @samp{-v},
2144which stands for @samp{verbose}, indicates to output the full documentation
2145of the matching commands and highlight the parts of the documentation
2146matching @var{regexp}. For example:
6837a0a2
DB
2147
2148@smallexample
16899756 2149apropos alias
6837a0a2
DB
2150@end smallexample
2151
b37052ae
EZ
2152@noindent
2153results in:
6837a0a2
DB
2154
2155@smallexample
e664d728 2156@group
16899756 2157alias -- Define a new command that is an alias of an existing command
5b860c93 2158aliases -- User-defined aliases of other commands
e664d728
PW
2159@end group
2160@end smallexample
2161
2162@noindent
2163while
2164
2165@smallexample
2166apropos -v cut.*thread apply
2167@end smallexample
2168
2169@noindent
2170results in the below output, where @samp{cut for 'thread apply}
2171is highlighted if styling is enabled.
2172
2173@smallexample
2174@group
2175taas -- Apply a command to all threads (ignoring errors
2176and empty output).
2177Usage: taas COMMAND
2178shortcut for 'thread apply all -s COMMAND'
2179
2180tfaas -- Apply a command to all frames of all threads
2181(ignoring errors and empty output).
2182Usage: tfaas COMMAND
2183shortcut for 'thread apply all -s frame apply all -s COMMAND'
2184@end group
6837a0a2
DB
2185@end smallexample
2186
c906108c
SS
2187@kindex complete
2188@item complete @var{args}
2189The @code{complete @var{args}} command lists all the possible completions
2190for the beginning of a command. Use @var{args} to specify the beginning of the
2191command you want completed. For example:
2192
2193@smallexample
2194complete i
2195@end smallexample
2196
2197@noindent results in:
2198
2199@smallexample
2200@group
2df3850c
JM
2201if
2202ignore
c906108c
SS
2203info
2204inspect
c906108c
SS
2205@end group
2206@end smallexample
2207
2208@noindent This is intended for use by @sc{gnu} Emacs.
2209@end table
2210
2211In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
2212and @code{show} to inquire about the state of your program, or the state
2213of @value{GDBN} itself. Each command supports many topics of inquiry; this
2214manual introduces each of them in the appropriate context. The listings
00595b5e
EZ
2215under @code{info} and under @code{show} in the Command, Variable, and
2216Function Index point to all the sub-commands. @xref{Command and Variable
2217Index}.
c906108c
SS
2218
2219@c @group
2220@table @code
2221@kindex info
41afff9a 2222@kindex i @r{(@code{info})}
c906108c
SS
2223@item info
2224This command (abbreviated @code{i}) is for describing the state of your
cda4ce5a 2225program. For example, you can show the arguments passed to a function
c906108c
SS
2226with @code{info args}, list the registers currently in use with @code{info
2227registers}, or list the breakpoints you have set with @code{info breakpoints}.
2228You can get a complete list of the @code{info} sub-commands with
2229@w{@code{help info}}.
2230
2231@kindex set
2232@item set
5d161b24 2233You can assign the result of an expression to an environment variable with
c906108c
SS
2234@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
2235@code{set prompt $}.
2236
2237@kindex show
2238@item show
5d161b24 2239In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
2240@value{GDBN} itself.
2241You can change most of the things you can @code{show}, by using the
2242related command @code{set}; for example, you can control what number
2243system is used for displays with @code{set radix}, or simply inquire
2244which is currently in use with @code{show radix}.
2245
2246@kindex info set
2247To display all the settable parameters and their current
2248values, you can use @code{show} with no arguments; you may also use
2249@code{info set}. Both commands produce the same display.
2250@c FIXME: "info set" violates the rule that "info" is for state of
2251@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
2252@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2253@end table
2254@c @end group
2255
6eaaf48b 2256Here are several miscellaneous @code{show} subcommands, all of which are
c906108c
SS
2257exceptional in lacking corresponding @code{set} commands:
2258
2259@table @code
2260@kindex show version
9c16f35a 2261@cindex @value{GDBN} version number
c906108c
SS
2262@item show version
2263Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
2264information in @value{GDBN} bug-reports. If multiple versions of
2265@value{GDBN} are in use at your site, you may need to determine which
2266version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2267commands are introduced, and old ones may wither away. Also, many
2268system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 2269variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
2270The version number is the same as the one announced when you start
2271@value{GDBN}.
c906108c
SS
2272
2273@kindex show copying
09d4efe1 2274@kindex info copying
9c16f35a 2275@cindex display @value{GDBN} copyright
c906108c 2276@item show copying
09d4efe1 2277@itemx info copying
c906108c
SS
2278Display information about permission for copying @value{GDBN}.
2279
2280@kindex show warranty
09d4efe1 2281@kindex info warranty
c906108c 2282@item show warranty
09d4efe1 2283@itemx info warranty
2df3850c 2284Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 2285if your version of @value{GDBN} comes with one.
2df3850c 2286
6eaaf48b
EZ
2287@kindex show configuration
2288@item show configuration
2289Display detailed information about the way @value{GDBN} was configured
2290when it was built. This displays the optional arguments passed to the
2291@file{configure} script and also configuration parameters detected
2292automatically by @command{configure}. When reporting a @value{GDBN}
2293bug (@pxref{GDB Bugs}), it is important to include this information in
2294your report.
2295
c906108c
SS
2296@end table
2297
6d2ebf8b 2298@node Running
c906108c
SS
2299@chapter Running Programs Under @value{GDBN}
2300
2301When you run a program under @value{GDBN}, you must first generate
2302debugging information when you compile it.
7a292a7a
SS
2303
2304You may start @value{GDBN} with its arguments, if any, in an environment
2305of your choice. If you are doing native debugging, you may redirect
2306your program's input and output, debug an already running process, or
2307kill a child process.
c906108c
SS
2308
2309@menu
2310* Compilation:: Compiling for debugging
2311* Starting:: Starting your program
c906108c
SS
2312* Arguments:: Your program's arguments
2313* Environment:: Your program's environment
c906108c
SS
2314
2315* Working Directory:: Your program's working directory
2316* Input/Output:: Your program's input and output
2317* Attach:: Debugging an already-running process
2318* Kill Process:: Killing the child process
65c574f6
PA
2319* Inferiors Connections and Programs:: Debugging multiple inferiors
2320 connections and programs
c906108c 2321* Threads:: Debugging programs with multiple threads
6c95b8df 2322* Forks:: Debugging forks
5c95884b 2323* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
2324@end menu
2325
6d2ebf8b 2326@node Compilation
79a6e687 2327@section Compiling for Debugging
c906108c
SS
2328
2329In order to debug a program effectively, you need to generate
2330debugging information when you compile it. This debugging information
2331is stored in the object file; it describes the data type of each
2332variable or function and the correspondence between source line numbers
2333and addresses in the executable code.
2334
2335To request debugging information, specify the @samp{-g} option when you run
2336the compiler.
2337
514c4d71 2338Programs that are to be shipped to your customers are compiled with
edb3359d 2339optimizations, using the @samp{-O} compiler option. However, some
514c4d71
EZ
2340compilers are unable to handle the @samp{-g} and @samp{-O} options
2341together. Using those compilers, you cannot generate optimized
c906108c
SS
2342executables containing debugging information.
2343
514c4d71 2344@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
2345without @samp{-O}, making it possible to debug optimized code. We
2346recommend that you @emph{always} use @samp{-g} whenever you compile a
2347program. You may think your program is correct, but there is no sense
edb3359d 2348in pushing your luck. For more information, see @ref{Optimized Code}.
c906108c
SS
2349
2350Older versions of the @sc{gnu} C compiler permitted a variant option
2351@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2352format; if your @sc{gnu} C compiler has this option, do not use it.
2353
514c4d71
EZ
2354@value{GDBN} knows about preprocessor macros and can show you their
2355expansion (@pxref{Macros}). Most compilers do not include information
2356about preprocessor macros in the debugging information if you specify
e0f8f636
TT
2357the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2358the @sc{gnu} C compiler, provides macro information if you are using
2359the DWARF debugging format, and specify the option @option{-g3}.
2360
2361@xref{Debugging Options,,Options for Debugging Your Program or GCC,
f5a476a7 2362gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
e0f8f636
TT
2363information on @value{NGCC} options affecting debug information.
2364
2365You will have the best debugging experience if you use the latest
2366version of the DWARF debugging format that your compiler supports.
2367DWARF is currently the most expressive and best supported debugging
2368format in @value{GDBN}.
514c4d71 2369
c906108c 2370@need 2000
6d2ebf8b 2371@node Starting
79a6e687 2372@section Starting your Program
c906108c
SS
2373@cindex starting
2374@cindex running
2375
2376@table @code
2377@kindex run
41afff9a 2378@kindex r @r{(@code{run})}
c906108c
SS
2379@item run
2380@itemx r
7a292a7a 2381Use the @code{run} command to start your program under @value{GDBN}.
deb8ff2b
PA
2382You must first specify the program name with an argument to
2383@value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2384@value{GDBN}}), or by using the @code{file} or @code{exec-file}
2385command (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
2386
2387@end table
2388
c906108c
SS
2389If you are running your program in an execution environment that
2390supports processes, @code{run} creates an inferior process and makes
8edfe269
DJ
2391that process run your program. In some environments without processes,
2392@code{run} jumps to the start of your program. Other targets,
2393like @samp{remote}, are always running. If you get an error
2394message like this one:
2395
2396@smallexample
2397The "remote" target does not support "run".
2398Try "help target" or "continue".
2399@end smallexample
2400
2401@noindent
2402then use @code{continue} to run your program. You may need @code{load}
2403first (@pxref{load}).
c906108c
SS
2404
2405The execution of a program is affected by certain information it
2406receives from its superior. @value{GDBN} provides ways to specify this
2407information, which you must do @emph{before} starting your program. (You
2408can change it after starting your program, but such changes only affect
2409your program the next time you start it.) This information may be
2410divided into four categories:
2411
2412@table @asis
2413@item The @emph{arguments.}
2414Specify the arguments to give your program as the arguments of the
2415@code{run} command. If a shell is available on your target, the shell
2416is used to pass the arguments, so that you may use normal conventions
2417(such as wildcard expansion or variable substitution) in describing
2418the arguments.
2419In Unix systems, you can control which shell is used with the
98882a26
PA
2420@code{SHELL} environment variable. If you do not define @code{SHELL},
2421@value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2422use of any shell with the @code{set startup-with-shell} command (see
2423below for details).
c906108c
SS
2424
2425@item The @emph{environment.}
2426Your program normally inherits its environment from @value{GDBN}, but you can
2427use the @value{GDBN} commands @code{set environment} and @code{unset
2428environment} to change parts of the environment that affect
79a6e687 2429your program. @xref{Environment, ,Your Program's Environment}.
c906108c
SS
2430
2431@item The @emph{working directory.}
d092c5a2
SDJ
2432You can set your program's working directory with the command
2433@kbd{set cwd}. If you do not set any working directory with this
bc3b087d
SDJ
2434command, your program will inherit @value{GDBN}'s working directory if
2435native debugging, or the remote server's working directory if remote
2436debugging. @xref{Working Directory, ,Your Program's Working
2437Directory}.
c906108c
SS
2438
2439@item The @emph{standard input and output.}
2440Your program normally uses the same device for standard input and
2441standard output as @value{GDBN} is using. You can redirect input and output
2442in the @code{run} command line, or you can use the @code{tty} command to
2443set a different device for your program.
79a6e687 2444@xref{Input/Output, ,Your Program's Input and Output}.
c906108c
SS
2445
2446@cindex pipes
2447@emph{Warning:} While input and output redirection work, you cannot use
2448pipes to pass the output of the program you are debugging to another
2449program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2450wrong program.
2451@end table
c906108c
SS
2452
2453When you issue the @code{run} command, your program begins to execute
79a6e687 2454immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
c906108c
SS
2455of how to arrange for your program to stop. Once your program has
2456stopped, you may call functions in your program, using the @code{print}
2457or @code{call} commands. @xref{Data, ,Examining Data}.
2458
2459If the modification time of your symbol file has changed since the last
2460time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2461table, and reads it again. When it does this, @value{GDBN} tries to retain
2462your current breakpoints.
2463
4e8b0763
JB
2464@table @code
2465@kindex start
2466@item start
2467@cindex run to main procedure
2468The name of the main procedure can vary from language to language.
2469With C or C@t{++}, the main procedure name is always @code{main}, but
2470other languages such as Ada do not require a specific name for their
2471main procedure. The debugger provides a convenient way to start the
2472execution of the program and to stop at the beginning of the main
2473procedure, depending on the language used.
2474
2475The @samp{start} command does the equivalent of setting a temporary
2476breakpoint at the beginning of the main procedure and then invoking
2477the @samp{run} command.
2478
f018e82f
EZ
2479@cindex elaboration phase
2480Some programs contain an @dfn{elaboration} phase where some startup code is
2481executed before the main procedure is called. This depends on the
2482languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
2483constructors for static and global objects are executed before
2484@code{main} is called. It is therefore possible that the debugger stops
2485before reaching the main procedure. However, the temporary breakpoint
2486will remain to halt execution.
2487
2488Specify the arguments to give to your program as arguments to the
2489@samp{start} command. These arguments will be given verbatim to the
2490underlying @samp{run} command. Note that the same arguments will be
2491reused if no argument is provided during subsequent calls to
2492@samp{start} or @samp{run}.
2493
2494It is sometimes necessary to debug the program during elaboration. In
4e5a4f58
JB
2495these cases, using the @code{start} command would stop the execution
2496of your program too late, as the program would have already completed
2497the elaboration phase. Under these circumstances, either insert
2498breakpoints in your elaboration code before running your program or
2499use the @code{starti} command.
2500
2501@kindex starti
2502@item starti
2503@cindex run to first instruction
2504The @samp{starti} command does the equivalent of setting a temporary
2505breakpoint at the first instruction of a program's execution and then
2506invoking the @samp{run} command. For programs containing an
2507elaboration phase, the @code{starti} command will stop execution at
2508the start of the elaboration phase.
ccd213ac 2509
41ef2965 2510@anchor{set exec-wrapper}
ccd213ac
DJ
2511@kindex set exec-wrapper
2512@item set exec-wrapper @var{wrapper}
2513@itemx show exec-wrapper
2514@itemx unset exec-wrapper
2515When @samp{exec-wrapper} is set, the specified wrapper is used to
2516launch programs for debugging. @value{GDBN} starts your program
2517with a shell command of the form @kbd{exec @var{wrapper}
2518@var{program}}. Quoting is added to @var{program} and its
2519arguments, but not to @var{wrapper}, so you should add quotes if
2520appropriate for your shell. The wrapper runs until it executes
2521your program, and then @value{GDBN} takes control.
2522
2523You can use any program that eventually calls @code{execve} with
2524its arguments as a wrapper. Several standard Unix utilities do
2525this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2526with @code{exec "$@@"} will also work.
2527
2528For example, you can use @code{env} to pass an environment variable to
2529the debugged program, without setting the variable in your shell's
2530environment:
2531
2532@smallexample
2533(@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2534(@value{GDBP}) run
2535@end smallexample
2536
2537This command is available when debugging locally on most targets, excluding
2538@sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2539
98882a26 2540@kindex set startup-with-shell
aefd8b33 2541@anchor{set startup-with-shell}
98882a26
PA
2542@item set startup-with-shell
2543@itemx set startup-with-shell on
2544@itemx set startup-with-shell off
ca145713 2545@itemx show startup-with-shell
98882a26
PA
2546On Unix systems, by default, if a shell is available on your target,
2547@value{GDBN}) uses it to start your program. Arguments of the
2548@code{run} command are passed to the shell, which does variable
2549substitution, expands wildcard characters and performs redirection of
2550I/O. In some circumstances, it may be useful to disable such use of a
2551shell, for example, when debugging the shell itself or diagnosing
2552startup failures such as:
2553
2554@smallexample
2555(@value{GDBP}) run
2556Starting program: ./a.out
2557During startup program terminated with signal SIGSEGV, Segmentation fault.
2558@end smallexample
2559
2560@noindent
2561which indicates the shell or the wrapper specified with
2562@samp{exec-wrapper} crashed, not your program. Most often, this is
afa332ce
PA
2563caused by something odd in your shell's non-interactive mode
2564initialization file---such as @file{.cshrc} for C-shell,
2565$@file{.zshenv} for the Z shell, or the file specified in the
2566@samp{BASH_ENV} environment variable for BASH.
98882a26 2567
6a3cb8e8
PA
2568@anchor{set auto-connect-native-target}
2569@kindex set auto-connect-native-target
2570@item set auto-connect-native-target
2571@itemx set auto-connect-native-target on
2572@itemx set auto-connect-native-target off
2573@itemx show auto-connect-native-target
2574
65c574f6
PA
2575By default, if the current inferior is not connected to any target yet
2576(e.g., with @code{target remote}), the @code{run} command starts your
2577program as a native process under @value{GDBN}, on your local machine.
2578If you're sure you don't want to debug programs on your local machine,
2579you can tell @value{GDBN} to not connect to the native target
2580automatically with the @code{set auto-connect-native-target off}
2581command.
6a3cb8e8 2582
65c574f6 2583If @code{on}, which is the default, and if the current inferior is not
6a3cb8e8
PA
2584connected to a target already, the @code{run} command automaticaly
2585connects to the native target, if one is available.
2586
65c574f6
PA
2587If @code{off}, and if the current inferior is not connected to a
2588target already, the @code{run} command fails with an error:
6a3cb8e8
PA
2589
2590@smallexample
2591(@value{GDBP}) run
2592Don't know how to run. Try "help target".
2593@end smallexample
2594
65c574f6
PA
2595If the current inferior is already connected to a target, @value{GDBN}
2596always uses it with the @code{run} command.
6a3cb8e8
PA
2597
2598In any case, you can explicitly connect to the native target with the
2599@code{target native} command. For example,
2600
2601@smallexample
2602(@value{GDBP}) set auto-connect-native-target off
2603(@value{GDBP}) run
2604Don't know how to run. Try "help target".
2605(@value{GDBP}) target native
2606(@value{GDBP}) run
2607Starting program: ./a.out
2608[Inferior 1 (process 10421) exited normally]
2609@end smallexample
2610
2611In case you connected explicitly to the @code{native} target,
2612@value{GDBN} remains connected even if all inferiors exit, ready for
2613the next @code{run} command. Use the @code{disconnect} command to
2614disconnect.
2615
2616Examples of other commands that likewise respect the
2617@code{auto-connect-native-target} setting: @code{attach}, @code{info
2618proc}, @code{info os}.
2619
10568435
JK
2620@kindex set disable-randomization
2621@item set disable-randomization
2622@itemx set disable-randomization on
2623This option (enabled by default in @value{GDBN}) will turn off the native
2624randomization of the virtual address space of the started program. This option
2625is useful for multiple debugging sessions to make the execution better
2626reproducible and memory addresses reusable across debugging sessions.
2627
03583c20
UW
2628This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2629On @sc{gnu}/Linux you can get the same behavior using
10568435
JK
2630
2631@smallexample
2632(@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2633@end smallexample
2634
2635@item set disable-randomization off
2636Leave the behavior of the started executable unchanged. Some bugs rear their
2637ugly heads only when the program is loaded at certain addresses. If your bug
2638disappears when you run the program under @value{GDBN}, that might be because
2639@value{GDBN} by default disables the address randomization on platforms, such
2640as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2641disable-randomization off} to try to reproduce such elusive bugs.
2642
03583c20
UW
2643On targets where it is available, virtual address space randomization
2644protects the programs against certain kinds of security attacks. In these
10568435
JK
2645cases the attacker needs to know the exact location of a concrete executable
2646code. Randomizing its location makes it impossible to inject jumps misusing
2647a code at its expected addresses.
2648
2649Prelinking shared libraries provides a startup performance advantage but it
2650makes addresses in these libraries predictable for privileged processes by
2651having just unprivileged access at the target system. Reading the shared
2652library binary gives enough information for assembling the malicious code
2653misusing it. Still even a prelinked shared library can get loaded at a new
2654random address just requiring the regular relocation process during the
2655startup. Shared libraries not already prelinked are always loaded at
2656a randomly chosen address.
2657
2658Position independent executables (PIE) contain position independent code
2659similar to the shared libraries and therefore such executables get loaded at
2660a randomly chosen address upon startup. PIE executables always load even
2661already prelinked shared libraries at a random address. You can build such
2662executable using @command{gcc -fPIE -pie}.
2663
2664Heap (malloc storage), stack and custom mmap areas are always placed randomly
2665(as long as the randomization is enabled).
2666
2667@item show disable-randomization
2668Show the current setting of the explicit disable of the native randomization of
2669the virtual address space of the started program.
2670
4e8b0763
JB
2671@end table
2672
6d2ebf8b 2673@node Arguments
79a6e687 2674@section Your Program's Arguments
c906108c
SS
2675
2676@cindex arguments (to your program)
2677The arguments to your program can be specified by the arguments of the
5d161b24 2678@code{run} command.
c906108c
SS
2679They are passed to a shell, which expands wildcard characters and
2680performs redirection of I/O, and thence to your program. Your
2681@code{SHELL} environment variable (if it exists) specifies what shell
2682@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
2683the default shell (@file{/bin/sh} on Unix).
2684
2685On non-Unix systems, the program is usually invoked directly by
2686@value{GDBN}, which emulates I/O redirection via the appropriate system
2687calls, and the wildcard characters are expanded by the startup code of
2688the program, not by the shell.
c906108c
SS
2689
2690@code{run} with no arguments uses the same arguments used by the previous
2691@code{run}, or those set by the @code{set args} command.
2692
c906108c 2693@table @code
41afff9a 2694@kindex set args
c906108c
SS
2695@item set args
2696Specify the arguments to be used the next time your program is run. If
2697@code{set args} has no arguments, @code{run} executes your program
2698with no arguments. Once you have run your program with arguments,
2699using @code{set args} before the next @code{run} is the only way to run
2700it again without arguments.
2701
2702@kindex show args
2703@item show args
2704Show the arguments to give your program when it is started.
2705@end table
2706
6d2ebf8b 2707@node Environment
79a6e687 2708@section Your Program's Environment
c906108c
SS
2709
2710@cindex environment (of your program)
2711The @dfn{environment} consists of a set of environment variables and
2712their values. Environment variables conventionally record such things as
2713your user name, your home directory, your terminal type, and your search
2714path for programs to run. Usually you set up environment variables with
2715the shell and they are inherited by all the other programs you run. When
2716debugging, it can be useful to try running your program with a modified
2717environment without having to start @value{GDBN} over again.
2718
2719@table @code
2720@kindex path
2721@item path @var{directory}
2722Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
2723(the search path for executables) that will be passed to your program.
2724The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
2725You may specify several directory names, separated by whitespace or by a
2726system-dependent separator character (@samp{:} on Unix, @samp{;} on
2727MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2728is moved to the front, so it is searched sooner.
c906108c
SS
2729
2730You can use the string @samp{$cwd} to refer to whatever is the current
2731working directory at the time @value{GDBN} searches the path. If you
2732use @samp{.} instead, it refers to the directory where you executed the
2733@code{path} command. @value{GDBN} replaces @samp{.} in the
2734@var{directory} argument (with the current path) before adding
2735@var{directory} to the search path.
2736@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2737@c document that, since repeating it would be a no-op.
2738
2739@kindex show paths
2740@item show paths
2741Display the list of search paths for executables (the @code{PATH}
2742environment variable).
2743
2744@kindex show environment
2745@item show environment @r{[}@var{varname}@r{]}
2746Print the value of environment variable @var{varname} to be given to
2747your program when it starts. If you do not supply @var{varname},
2748print the names and values of all environment variables to be given to
2749your program. You can abbreviate @code{environment} as @code{env}.
2750
2751@kindex set environment
0a2dde4a 2752@anchor{set environment}
53a5351d 2753@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c 2754Set environment variable @var{varname} to @var{value}. The value
41ef2965 2755changes for your program (and the shell @value{GDBN} uses to launch
697aa1b7 2756it), not for @value{GDBN} itself. The @var{value} may be any string; the
41ef2965
PA
2757values of environment variables are just strings, and any
2758interpretation is supplied by your program itself. The @var{value}
c906108c
SS
2759parameter is optional; if it is eliminated, the variable is set to a
2760null value.
2761@c "any string" here does not include leading, trailing
2762@c blanks. Gnu asks: does anyone care?
2763
2764For example, this command:
2765
474c8240 2766@smallexample
c906108c 2767set env USER = foo
474c8240 2768@end smallexample
c906108c
SS
2769
2770@noindent
d4f3574e 2771tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2772@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2773are not actually required.)
2774
41ef2965
PA
2775Note that on Unix systems, @value{GDBN} runs your program via a shell,
2776which also inherits the environment set with @code{set environment}.
2777If necessary, you can avoid that by using the @samp{env} program as a
2778wrapper instead of using @code{set environment}. @xref{set
2779exec-wrapper}, for an example doing just that.
2780
0a2dde4a
SDJ
2781Environment variables that are set by the user are also transmitted to
2782@command{gdbserver} to be used when starting the remote inferior.
2783@pxref{QEnvironmentHexEncoded}.
2784
c906108c 2785@kindex unset environment
0a2dde4a 2786@anchor{unset environment}
c906108c
SS
2787@item unset environment @var{varname}
2788Remove variable @var{varname} from the environment to be passed to your
2789program. This is different from @samp{set env @var{varname} =};
2790@code{unset environment} removes the variable from the environment,
2791rather than assigning it an empty value.
0a2dde4a
SDJ
2792
2793Environment variables that are unset by the user are also unset on
2794@command{gdbserver} when starting the remote inferior.
2795@pxref{QEnvironmentUnset}.
c906108c
SS
2796@end table
2797
d4f3574e 2798@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
afa332ce
PA
2799the shell indicated by your @code{SHELL} environment variable if it
2800exists (or @code{/bin/sh} if not). If your @code{SHELL} variable
2801names a shell that runs an initialization file when started
2802non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2803for the Z shell, or the file specified in the @samp{BASH_ENV}
2804environment variable for BASH---any variables you set in that file
2805affect your program. You may wish to move setting of environment
2806variables to files that are only run when you sign on, such as
2807@file{.login} or @file{.profile}.
c906108c 2808
6d2ebf8b 2809@node Working Directory
79a6e687 2810@section Your Program's Working Directory
c906108c
SS
2811
2812@cindex working directory (of your program)
d092c5a2
SDJ
2813Each time you start your program with @code{run}, the inferior will be
2814initialized with the current working directory specified by the
2815@kbd{set cwd} command. If no directory has been specified by this
2816command, then the inferior will inherit @value{GDBN}'s current working
bc3b087d
SDJ
2817directory as its working directory if native debugging, or it will
2818inherit the remote server's current working directory if remote
2819debugging.
c906108c
SS
2820
2821@table @code
d092c5a2
SDJ
2822@kindex set cwd
2823@cindex change inferior's working directory
2824@anchor{set cwd command}
2825@item set cwd @r{[}@var{directory}@r{]}
2826Set the inferior's working directory to @var{directory}, which will be
2827@code{glob}-expanded in order to resolve tildes (@file{~}). If no
2828argument has been specified, the command clears the setting and resets
2829it to an empty state. This setting has no effect on @value{GDBN}'s
2830working directory, and it only takes effect the next time you start
2831the inferior. The @file{~} in @var{directory} is a short for the
2832@dfn{home directory}, usually pointed to by the @env{HOME} environment
2833variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2834uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2835fallback.
2836
2837You can also change @value{GDBN}'s current working directory by using
2838the @code{cd} command.
dbfa4523 2839@xref{cd command}.
d092c5a2
SDJ
2840
2841@kindex show cwd
2842@cindex show inferior's working directory
2843@item show cwd
2844Show the inferior's working directory. If no directory has been
2845specified by @kbd{set cwd}, then the default inferior's working
2846directory is the same as @value{GDBN}'s working directory.
2847
c906108c 2848@kindex cd
d092c5a2
SDJ
2849@cindex change @value{GDBN}'s working directory
2850@anchor{cd command}
f3c8a52a
JK
2851@item cd @r{[}@var{directory}@r{]}
2852Set the @value{GDBN} working directory to @var{directory}. If not
2853given, @var{directory} uses @file{'~'}.
c906108c 2854
d092c5a2
SDJ
2855The @value{GDBN} working directory serves as a default for the
2856commands that specify files for @value{GDBN} to operate on.
2857@xref{Files, ,Commands to Specify Files}.
dbfa4523 2858@xref{set cwd command}.
d092c5a2 2859
c906108c
SS
2860@kindex pwd
2861@item pwd
2862Print the @value{GDBN} working directory.
2863@end table
2864
60bf7e09
EZ
2865It is generally impossible to find the current working directory of
2866the process being debugged (since a program can change its directory
2d97a5d9 2867during its run). If you work on a system where @value{GDBN} supports
754452f0 2868the @code{info proc} command (@pxref{Process Information}), you can
2d97a5d9 2869use the @code{info proc} command to find out the
60bf7e09
EZ
2870current working directory of the debuggee.
2871
6d2ebf8b 2872@node Input/Output
79a6e687 2873@section Your Program's Input and Output
c906108c
SS
2874
2875@cindex redirection
2876@cindex i/o
2877@cindex terminal
2878By default, the program you run under @value{GDBN} does input and output to
5d161b24 2879the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2880to its own terminal modes to interact with you, but it records the terminal
2881modes your program was using and switches back to them when you continue
2882running your program.
2883
2884@table @code
2885@kindex info terminal
2886@item info terminal
2887Displays information recorded by @value{GDBN} about the terminal modes your
2888program is using.
2889@end table
2890
2891You can redirect your program's input and/or output using shell
2892redirection with the @code{run} command. For example,
2893
474c8240 2894@smallexample
c906108c 2895run > outfile
474c8240 2896@end smallexample
c906108c
SS
2897
2898@noindent
2899starts your program, diverting its output to the file @file{outfile}.
2900
2901@kindex tty
2902@cindex controlling terminal
2903Another way to specify where your program should do input and output is
2904with the @code{tty} command. This command accepts a file name as
2905argument, and causes this file to be the default for future @code{run}
2906commands. It also resets the controlling terminal for the child
2907process, for future @code{run} commands. For example,
2908
474c8240 2909@smallexample
c906108c 2910tty /dev/ttyb
474c8240 2911@end smallexample
c906108c
SS
2912
2913@noindent
2914directs that processes started with subsequent @code{run} commands
2915default to do input and output on the terminal @file{/dev/ttyb} and have
2916that as their controlling terminal.
2917
2918An explicit redirection in @code{run} overrides the @code{tty} command's
2919effect on the input/output device, but not its effect on the controlling
2920terminal.
2921
2922When you use the @code{tty} command or redirect input in the @code{run}
2923command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2924for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2925for @code{set inferior-tty}.
2926
2927@cindex inferior tty
2928@cindex set inferior controlling terminal
2929You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2930display the name of the terminal that will be used for future runs of your
2931program.
2932
2933@table @code
0a1ddfa6 2934@item set inferior-tty [ @var{tty} ]
3cb3b8df 2935@kindex set inferior-tty
0a1ddfa6
SM
2936Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
2937restores the default behavior, which is to use the same terminal as
2938@value{GDBN}.
3cb3b8df
BR
2939
2940@item show inferior-tty
2941@kindex show inferior-tty
2942Show the current tty for the program being debugged.
2943@end table
c906108c 2944
6d2ebf8b 2945@node Attach
79a6e687 2946@section Debugging an Already-running Process
c906108c
SS
2947@kindex attach
2948@cindex attach
2949
2950@table @code
2951@item attach @var{process-id}
2952This command attaches to a running process---one that was started
2953outside @value{GDBN}. (@code{info files} shows your active
2954targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2955find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2956or with the @samp{jobs -l} shell command.
2957
2958@code{attach} does not repeat if you press @key{RET} a second time after
2959executing the command.
2960@end table
2961
2962To use @code{attach}, your program must be running in an environment
2963which supports processes; for example, @code{attach} does not work for
2964programs on bare-board targets that lack an operating system. You must
2965also have permission to send the process a signal.
2966
2967When you use @code{attach}, the debugger finds the program running in
2968the process first by looking in the current working directory, then (if
2969the program is not found) by using the source file search path
79a6e687 2970(@pxref{Source Path, ,Specifying Source Directories}). You can also use
c906108c
SS
2971the @code{file} command to load the program. @xref{Files, ,Commands to
2972Specify Files}.
2973
e47e48f6 2974@anchor{set exec-file-mismatch}
98c59b52
PA
2975If the debugger can determine that the executable file running in the
2976process it is attaching to does not match the current exec-file loaded
2977by @value{GDBN}, the option @code{exec-file-mismatch} specifies how to
2978handle the mismatch. @value{GDBN} tries to compare the files by
2979comparing their build IDs (@pxref{build ID}), if available.
e47e48f6
PW
2980
2981@table @code
2982@kindex exec-file-mismatch
2983@cindex set exec-file-mismatch
2984@item set exec-file-mismatch @samp{ask|warn|off}
2985
98c59b52
PA
2986Whether to detect mismatch between the current executable file loaded
2987by @value{GDBN} and the executable file used to start the process. If
2988@samp{ask}, the default, display a warning and ask the user whether to
2989load the process executable file; if @samp{warn}, just display a
2990warning; if @samp{off}, don't attempt to detect a mismatch.
0a278aa7
PW
2991If the user confirms loading the process executable file, then its symbols
2992will be loaded as well.
e47e48f6
PW
2993
2994@cindex show exec-file-mismatch
2995@item show exec-file-mismatch
2996Show the current value of @code{exec-file-mismatch}.
2997
2998@end table
2999
c906108c
SS
3000The first thing @value{GDBN} does after arranging to debug the specified
3001process is to stop it. You can examine and modify an attached process
53a5351d
JM
3002with all the @value{GDBN} commands that are ordinarily available when
3003you start processes with @code{run}. You can insert breakpoints; you
3004can step and continue; you can modify storage. If you would rather the
3005process continue running, you may use the @code{continue} command after
c906108c
SS
3006attaching @value{GDBN} to the process.
3007
3008@table @code
3009@kindex detach
3010@item detach
3011When you have finished debugging the attached process, you can use the
3012@code{detach} command to release it from @value{GDBN} control. Detaching
3013the process continues its execution. After the @code{detach} command,
3014that process and @value{GDBN} become completely independent once more, and you
3015are ready to @code{attach} another process or start one with @code{run}.
3016@code{detach} does not repeat if you press @key{RET} again after
3017executing the command.
3018@end table
3019
159fcc13
JK
3020If you exit @value{GDBN} while you have an attached process, you detach
3021that process. If you use the @code{run} command, you kill that process.
3022By default, @value{GDBN} asks for confirmation if you try to do either of these
3023things; you can control whether or not you need to confirm by using the
3024@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
79a6e687 3025Messages}).
c906108c 3026
6d2ebf8b 3027@node Kill Process
79a6e687 3028@section Killing the Child Process
c906108c
SS
3029
3030@table @code
3031@kindex kill
3032@item kill
3033Kill the child process in which your program is running under @value{GDBN}.
3034@end table
3035
3036This command is useful if you wish to debug a core dump instead of a
3037running process. @value{GDBN} ignores any core dump file while your program
3038is running.
3039
3040On some operating systems, a program cannot be executed outside @value{GDBN}
3041while you have breakpoints set on it inside @value{GDBN}. You can use the
3042@code{kill} command in this situation to permit running your program
3043outside the debugger.
3044
3045The @code{kill} command is also useful if you wish to recompile and
3046relink your program, since on many systems it is impossible to modify an
3047executable file while it is running in a process. In this case, when you
3048next type @code{run}, @value{GDBN} notices that the file has changed, and
3049reads the symbol table again (while trying to preserve your current
3050breakpoint settings).
3051
65c574f6
PA
3052@node Inferiors Connections and Programs
3053@section Debugging Multiple Inferiors Connections and Programs
b77209e0 3054
6c95b8df
PA
3055@value{GDBN} lets you run and debug multiple programs in a single
3056session. In addition, @value{GDBN} on some systems may let you run
3057several programs simultaneously (otherwise you have to exit from one
65c574f6
PA
3058before starting another). On some systems @value{GDBN} may even let
3059you debug several programs simultaneously on different remote systems.
3060In the most general case, you can have multiple threads of execution
3061in each of multiple processes, launched from multiple executables,
3062running on different machines.
b77209e0
PA
3063
3064@cindex inferior
3065@value{GDBN} represents the state of each program execution with an
3066object called an @dfn{inferior}. An inferior typically corresponds to
3067a process, but is more general and applies also to targets that do not
3068have processes. Inferiors may be created before a process runs, and
6c95b8df
PA
3069may be retained after a process exits. Inferiors have unique
3070identifiers that are different from process ids. Usually each
3071inferior will also have its own distinct address space, although some
3072embedded targets may have several inferiors running in different parts
3073of a single address space. Each inferior may in turn have multiple
3074threads running in it.
b77209e0 3075
6c95b8df
PA
3076To find out what inferiors exist at any moment, use @w{@code{info
3077inferiors}}:
b77209e0
PA
3078
3079@table @code
a3c25011 3080@kindex info inferiors [ @var{id}@dots{} ]
b77209e0
PA
3081@item info inferiors
3082Print a list of all inferiors currently being managed by @value{GDBN}.
a3c25011
TT
3083By default all inferiors are printed, but the argument @var{id}@dots{}
3084-- a space separated list of inferior numbers -- can be used to limit
3085the display to just the requested inferiors.
3a1ff0b6
PA
3086
3087@value{GDBN} displays for each inferior (in this order):
3088
3089@enumerate
3090@item
3091the inferior number assigned by @value{GDBN}
3092
3093@item
3094the target system's inferior identifier
6c95b8df 3095
65c574f6
PA
3096@item
3097the target connection the inferior is bound to, including the unique
3098connection number assigned by @value{GDBN}, and the protocol used by
3099the connection.
3100
6c95b8df
PA
3101@item
3102the name of the executable the inferior is running.
3103
3a1ff0b6
PA
3104@end enumerate
3105
3106@noindent
3107An asterisk @samp{*} preceding the @value{GDBN} inferior number
3108indicates the current inferior.
3109
3110For example,
2277426b 3111@end table
3a1ff0b6
PA
3112@c end table here to get a little more width for example
3113
3114@smallexample
3115(@value{GDBP}) info inferiors
65c574f6
PA
3116 Num Description Connection Executable
3117* 1 process 3401 1 (native) goodbye
3118 2 process 2307 2 (extended-remote host:10000) hello
3119@end smallexample
3120
2e3773ff
LS
3121To get informations about the current inferior, use @code{inferior}:
3122
3123@table @code
3124@kindex inferior
3125@item inferior
3126Shows information about the current inferior.
3127
3128For example,
3129@end table
3130@c end table here to get a little more width for example
3131
3132@smallexample
3133(@value{GDBP}) inferior
3134[Current inferior is 1 [process 3401] (helloworld)]
3135@end smallexample
3136
65c574f6
PA
3137To find out what open target connections exist at any moment, use
3138@w{@code{info connections}}:
3139
3140@table @code
3141@kindex info connections [ @var{id}@dots{} ]
3142@item info connections
3143Print a list of all open target connections currently being managed by
3144@value{GDBN}. By default all connections are printed, but the
3145argument @var{id}@dots{} -- a space separated list of connections
3146numbers -- can be used to limit the display to just the requested
3147connections.
3148
3149@value{GDBN} displays for each connection (in this order):
3150
3151@enumerate
3152@item
3153the connection number assigned by @value{GDBN}.
3154
3155@item
3156the protocol used by the connection.
3157
3158@item
3159a textual description of the protocol used by the connection.
3160
3161@end enumerate
3162
3163@noindent
3164An asterisk @samp{*} preceding the connection number indicates the
3165connection of the current inferior.
3166
3167For example,
3168@end table
3169@c end table here to get a little more width for example
3170
3171@smallexample
3172(@value{GDBP}) info connections
3173 Num What Description
3174* 1 extended-remote host:10000 Extended remote serial target in gdb-specific protocol
3175 2 native Native process
3176 3 core Local core dump file
3a1ff0b6 3177@end smallexample
2277426b
PA
3178
3179To switch focus between inferiors, use the @code{inferior} command:
3180
3181@table @code
3a1ff0b6
PA
3182@kindex inferior @var{infno}
3183@item inferior @var{infno}
3184Make inferior number @var{infno} the current inferior. The argument
3185@var{infno} is the inferior number assigned by @value{GDBN}, as shown
3186in the first field of the @samp{info inferiors} display.
2277426b
PA
3187@end table
3188
e3940304
PA
3189@vindex $_inferior@r{, convenience variable}
3190The debugger convenience variable @samp{$_inferior} contains the
3191number of the current inferior. You may find this useful in writing
3192breakpoint conditional expressions, command scripts, and so forth.
3193@xref{Convenience Vars,, Convenience Variables}, for general
3194information on convenience variables.
6c95b8df
PA
3195
3196You can get multiple executables into a debugging session via the
3197@code{add-inferior} and @w{@code{clone-inferior}} commands. On some
3198systems @value{GDBN} can add inferiors to the debug session
3199automatically by following calls to @code{fork} and @code{exec}. To
3200remove inferiors from the debugging session use the
af624141 3201@w{@code{remove-inferiors}} command.
6c95b8df
PA
3202
3203@table @code
3204@kindex add-inferior
65c574f6 3205@item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
6c95b8df 3206Adds @var{n} inferiors to be run using @var{executable} as the
697aa1b7 3207executable; @var{n} defaults to 1. If no executable is specified,
6c95b8df
PA
3208the inferiors begins empty, with no program. You can still assign or
3209change the program assigned to the inferior at any time by using the
3210@code{file} command with the executable name as its argument.
3211
65c574f6
PA
3212By default, the new inferior begins connected to the same target
3213connection as the current inferior. For example, if the current
3214inferior was connected to @code{gdbserver} with @code{target remote},
3215then the new inferior will be connected to the same @code{gdbserver}
3216instance. The @samp{-no-connection} option starts the new inferior
3217with no connection yet. You can then for example use the @code{target
3218remote} command to connect to some other @code{gdbserver} instance,
3219use @code{run} to spawn a local program, etc.
3220
6c95b8df
PA
3221@kindex clone-inferior
3222@item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
3223Adds @var{n} inferiors ready to execute the same program as inferior
697aa1b7 3224@var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
6c95b8df
PA
3225number of the current inferior. This is a convenient command when you
3226want to run another instance of the inferior you are debugging.
3227
3228@smallexample
3229(@value{GDBP}) info inferiors
65c574f6
PA
3230 Num Description Connection Executable
3231* 1 process 29964 1 (native) helloworld
6c95b8df
PA
3232(@value{GDBP}) clone-inferior
3233Added inferior 2.
32341 inferiors added.
3235(@value{GDBP}) info inferiors
65c574f6
PA
3236 Num Description Connection Executable
3237* 1 process 29964 1 (native) helloworld
3238 2 <null> 1 (native) helloworld
6c95b8df
PA
3239@end smallexample
3240
3241You can now simply switch focus to inferior 2 and run it.
3242
af624141
MS
3243@kindex remove-inferiors
3244@item remove-inferiors @var{infno}@dots{}
3245Removes the inferior or inferiors @var{infno}@dots{}. It is not
3246possible to remove an inferior that is running with this command. For
3247those, use the @code{kill} or @code{detach} command first.
6c95b8df
PA
3248
3249@end table
3250
3251To quit debugging one of the running inferiors that is not the current
3252inferior, you can either detach from it by using the @w{@code{detach
3253inferior}} command (allowing it to run independently), or kill it
af624141 3254using the @w{@code{kill inferiors}} command:
2277426b
PA
3255
3256@table @code
af624141
MS
3257@kindex detach inferiors @var{infno}@dots{}
3258@item detach inferior @var{infno}@dots{}
3259Detach from the inferior or inferiors identified by @value{GDBN}
5e30da2c 3260inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
af624141
MS
3261still stays on the list of inferiors shown by @code{info inferiors},
3262but its Description will show @samp{<null>}.
3263
3264@kindex kill inferiors @var{infno}@dots{}
3265@item kill inferiors @var{infno}@dots{}
3266Kill the inferior or inferiors identified by @value{GDBN} inferior
3267number(s) @var{infno}@dots{}. Note that the inferior's entry still
3268stays on the list of inferiors shown by @code{info inferiors}, but its
3269Description will show @samp{<null>}.
2277426b
PA
3270@end table
3271
6c95b8df 3272After the successful completion of a command such as @code{detach},
af624141 3273@code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
6c95b8df
PA
3274a normal process exit, the inferior is still valid and listed with
3275@code{info inferiors}, ready to be restarted.
3276
3277
2277426b
PA
3278To be notified when inferiors are started or exit under @value{GDBN}'s
3279control use @w{@code{set print inferior-events}}:
b77209e0 3280
2277426b 3281@table @code
b77209e0
PA
3282@kindex set print inferior-events
3283@cindex print messages on inferior start and exit
3284@item set print inferior-events
3285@itemx set print inferior-events on
3286@itemx set print inferior-events off
3287The @code{set print inferior-events} command allows you to enable or
3288disable printing of messages when @value{GDBN} notices that new
3289inferiors have started or that inferiors have exited or have been
3290detached. By default, these messages will not be printed.
3291
3292@kindex show print inferior-events
3293@item show print inferior-events
3294Show whether messages will be printed when @value{GDBN} detects that
3295inferiors have started, exited or have been detached.
3296@end table
3297
6c95b8df
PA
3298Many commands will work the same with multiple programs as with a
3299single program: e.g., @code{print myglobal} will simply display the
3300value of @code{myglobal} in the current inferior.
3301
3302
6b92c0d3 3303Occasionally, when debugging @value{GDBN} itself, it may be useful to
6c95b8df
PA
3304get more info about the relationship of inferiors, programs, address
3305spaces in a debug session. You can do that with the @w{@code{maint
3306info program-spaces}} command.
3307
3308@table @code
3309@kindex maint info program-spaces
3310@item maint info program-spaces
3311Print a list of all program spaces currently being managed by
3312@value{GDBN}.
3313
3314@value{GDBN} displays for each program space (in this order):
3315
3316@enumerate
3317@item
3318the program space number assigned by @value{GDBN}
3319
3320@item
3321the name of the executable loaded into the program space, with e.g.,
3322the @code{file} command.
3323
3324@end enumerate
3325
3326@noindent
3327An asterisk @samp{*} preceding the @value{GDBN} program space number
3328indicates the current program space.
3329
3330In addition, below each program space line, @value{GDBN} prints extra
3331information that isn't suitable to display in tabular form. For
3332example, the list of inferiors bound to the program space.
3333
3334@smallexample
3335(@value{GDBP}) maint info program-spaces
3336 Id Executable
b05b1202 3337* 1 hello
6c95b8df
PA
3338 2 goodbye
3339 Bound inferiors: ID 1 (process 21561)
6c95b8df
PA
3340@end smallexample
3341
3342Here we can see that no inferior is running the program @code{hello},
3343while @code{process 21561} is running the program @code{goodbye}. On
3344some targets, it is possible that multiple inferiors are bound to the
3345same program space. The most common example is that of debugging both
3346the parent and child processes of a @code{vfork} call. For example,
3347
3348@smallexample
3349(@value{GDBP}) maint info program-spaces
3350 Id Executable
3351* 1 vfork-test
3352 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3353@end smallexample
3354
3355Here, both inferior 2 and inferior 1 are running in the same program
3356space as a result of inferior 1 having executed a @code{vfork} call.
3357@end table
3358
6d2ebf8b 3359@node Threads
79a6e687 3360@section Debugging Programs with Multiple Threads
c906108c
SS
3361
3362@cindex threads of execution
3363@cindex multiple threads
3364@cindex switching threads
b1236ac3 3365In some operating systems, such as GNU/Linux and Solaris, a single program
c906108c
SS
3366may have more than one @dfn{thread} of execution. The precise semantics
3367of threads differ from one operating system to another, but in general
3368the threads of a single program are akin to multiple processes---except
3369that they share one address space (that is, they can all examine and
3370modify the same variables). On the other hand, each thread has its own
3371registers and execution stack, and perhaps private memory.
3372
3373@value{GDBN} provides these facilities for debugging multi-thread
3374programs:
3375
3376@itemize @bullet
3377@item automatic notification of new threads
5d5658a1 3378@item @samp{thread @var{thread-id}}, a command to switch among threads
c906108c 3379@item @samp{info threads}, a command to inquire about existing threads
0a232300 3380@item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
c906108c
SS
3381a command to apply a command to a list of threads
3382@item thread-specific breakpoints
93815fbf
VP
3383@item @samp{set print thread-events}, which controls printing of
3384messages on thread start and exit.
17a37d48
PP
3385@item @samp{set libthread-db-search-path @var{path}}, which lets
3386the user specify which @code{libthread_db} to use if the default choice
3387isn't compatible with the program.
c906108c
SS
3388@end itemize
3389
c906108c
SS
3390@cindex focus of debugging
3391@cindex current thread
3392The @value{GDBN} thread debugging facility allows you to observe all
3393threads while your program runs---but whenever @value{GDBN} takes
3394control, one thread in particular is always the focus of debugging.
3395This thread is called the @dfn{current thread}. Debugging commands show
3396program information from the perspective of the current thread.
3397
41afff9a 3398@cindex @code{New} @var{systag} message
c906108c
SS
3399@cindex thread identifier (system)
3400@c FIXME-implementors!! It would be more helpful if the [New...] message
3401@c included GDB's numeric thread handle, so you could just go to that
3402@c thread without first checking `info threads'.
3403Whenever @value{GDBN} detects a new thread in your program, it displays
3404the target system's identification for the thread with a message in the
697aa1b7 3405form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
c906108c 3406whose form varies depending on the particular system. For example, on
8807d78b 3407@sc{gnu}/Linux, you might see
c906108c 3408
474c8240 3409@smallexample
08e796bc 3410[New Thread 0x41e02940 (LWP 25582)]
474c8240 3411@end smallexample
c906108c
SS
3412
3413@noindent
b1236ac3 3414when @value{GDBN} notices a new thread. In contrast, on other systems,
c906108c
SS
3415the @var{systag} is simply something like @samp{process 368}, with no
3416further qualifier.
3417
3418@c FIXME!! (1) Does the [New...] message appear even for the very first
3419@c thread of a program, or does it only appear for the
6ca652b0 3420@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
3421@c program?
3422@c (2) *Is* there necessarily a first thread always? Or do some
3423@c multithread systems permit starting a program with multiple
5d161b24 3424@c threads ab initio?
c906108c 3425
5d5658a1
PA
3426@anchor{thread numbers}
3427@cindex thread number, per inferior
c906108c 3428@cindex thread identifier (GDB)
5d5658a1
PA
3429For debugging purposes, @value{GDBN} associates its own thread number
3430---always a single integer---with each thread of an inferior. This
3431number is unique between all threads of an inferior, but not unique
3432between threads of different inferiors.
3433
3434@cindex qualified thread ID
3435You can refer to a given thread in an inferior using the qualified
3436@var{inferior-num}.@var{thread-num} syntax, also known as
3437@dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3438number and @var{thread-num} being the thread number of the given
3439inferior. For example, thread @code{2.3} refers to thread number 3 of
3440inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
3441then @value{GDBN} infers you're referring to a thread of the current
3442inferior.
3443
3444Until you create a second inferior, @value{GDBN} does not show the
3445@var{inferior-num} part of thread IDs, even though you can always use
3446the full @var{inferior-num}.@var{thread-num} form to refer to threads
3447of inferior 1, the initial inferior.
3448
3449@anchor{thread ID lists}
3450@cindex thread ID lists
3451Some commands accept a space-separated @dfn{thread ID list} as
71ef29a8
PA
3452argument. A list element can be:
3453
3454@enumerate
3455@item
3456A thread ID as shown in the first field of the @samp{info threads}
3457display, with or without an inferior qualifier. E.g., @samp{2.1} or
3458@samp{1}.
3459
3460@item
3461A range of thread numbers, again with or without an inferior
3462qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3463@var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3464
3465@item
3466All threads of an inferior, specified with a star wildcard, with or
3467without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3468@samp{1.*}) or @code{*}. The former refers to all threads of the
3469given inferior, and the latter form without an inferior qualifier
3470refers to all threads of the current inferior.
3471
3472@end enumerate
3473
3474For example, if the current inferior is 1, and inferior 7 has one
3475thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3476includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
34777 to 9 of inferior 6 and all threads of inferior 7. That is, in
3478expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
34797.1}.
3480
5d5658a1
PA
3481
3482@anchor{global thread numbers}
3483@cindex global thread number
3484@cindex global thread identifier (GDB)
3485In addition to a @emph{per-inferior} number, each thread is also
3486assigned a unique @emph{global} number, also known as @dfn{global
3487thread ID}, a single integer. Unlike the thread number component of
3488the thread ID, no two threads have the same global ID, even when
3489you're debugging multiple inferiors.
c906108c 3490
f4f4330e
PA
3491From @value{GDBN}'s perspective, a process always has at least one
3492thread. In other words, @value{GDBN} assigns a thread number to the
3493program's ``main thread'' even if the program is not multi-threaded.
3494
5d5658a1 3495@vindex $_thread@r{, convenience variable}
663f6d42
PA
3496@vindex $_gthread@r{, convenience variable}
3497The debugger convenience variables @samp{$_thread} and
3498@samp{$_gthread} contain, respectively, the per-inferior thread number
3499and the global thread number of the current thread. You may find this
5d5658a1
PA
3500useful in writing breakpoint conditional expressions, command scripts,
3501and so forth. @xref{Convenience Vars,, Convenience Variables}, for
3502general information on convenience variables.
3503
f303dbd6
PA
3504If @value{GDBN} detects the program is multi-threaded, it augments the
3505usual message about stopping at a breakpoint with the ID and name of
3506the thread that hit the breakpoint.
3507
3508@smallexample
3509Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3510@end smallexample
3511
3512Likewise when the program receives a signal:
3513
3514@smallexample
3515Thread 1 "main" received signal SIGINT, Interrupt.
3516@end smallexample
3517
c906108c
SS
3518@table @code
3519@kindex info threads
5d5658a1
PA
3520@item info threads @r{[}@var{thread-id-list}@r{]}
3521
3522Display information about one or more threads. With no arguments
3523displays information about all threads. You can specify the list of
3524threads that you want to display using the thread ID list syntax
3525(@pxref{thread ID lists}).
3526
60f98dde 3527@value{GDBN} displays for each thread (in this order):
c906108c
SS
3528
3529@enumerate
09d4efe1 3530@item
5d5658a1 3531the per-inferior thread number assigned by @value{GDBN}
c906108c 3532
c84f6bbf
PA
3533@item
3534the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3535option was specified
3536
09d4efe1
EZ
3537@item
3538the target system's thread identifier (@var{systag})
c906108c 3539
4694da01
TT
3540@item
3541the thread's name, if one is known. A thread can either be named by
3542the user (see @code{thread name}, below), or, in some cases, by the
3543program itself.
3544
09d4efe1
EZ
3545@item
3546the current stack frame summary for that thread
c906108c
SS
3547@end enumerate
3548
3549@noindent
3550An asterisk @samp{*} to the left of the @value{GDBN} thread number
3551indicates the current thread.
3552
5d161b24 3553For example,
c906108c
SS
3554@end table
3555@c end table here to get a little more width for example
3556
3557@smallexample
3558(@value{GDBP}) info threads
e56d7f1e 3559 Id Target Id Frame
c0ecb95f 3560* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
b05b1202
PA
3561 2 process 35 thread 23 0x34e5 in sigpause ()
3562 3 process 35 thread 27 0x34e5 in sigpause ()
c906108c
SS
3563 at threadtest.c:68
3564@end smallexample
53a5351d 3565
5d5658a1
PA
3566If you're debugging multiple inferiors, @value{GDBN} displays thread
3567IDs using the qualified @var{inferior-num}.@var{thread-num} format.
c84f6bbf
PA
3568Otherwise, only @var{thread-num} is shown.
3569
3570If you specify the @samp{-gid} option, @value{GDBN} displays a column
3571indicating each thread's global thread ID:
5d5658a1
PA
3572
3573@smallexample
3574(@value{GDBP}) info threads
c84f6bbf
PA
3575 Id GId Target Id Frame
3576 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3577 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3578 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3579* 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
5d5658a1
PA
3580@end smallexample
3581
c45da7e6
EZ
3582On Solaris, you can display more information about user threads with a
3583Solaris-specific command:
3584
3585@table @code
3586@item maint info sol-threads
3587@kindex maint info sol-threads
3588@cindex thread info (Solaris)
3589Display info on Solaris user threads.
3590@end table
3591
c906108c 3592@table @code
5d5658a1
PA
3593@kindex thread @var{thread-id}
3594@item thread @var{thread-id}
3595Make thread ID @var{thread-id} the current thread. The command
3596argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3597the first field of the @samp{info threads} display, with or without an
3598inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3599
3600@value{GDBN} responds by displaying the system identifier of the
3601thread you selected, and its current stack frame summary:
c906108c
SS
3602
3603@smallexample
c906108c 3604(@value{GDBP}) thread 2
13fd8b81
TT
3605[Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3606#0 some_function (ignore=0x0) at example.c:8
36078 printf ("hello\n");
c906108c
SS
3608@end smallexample
3609
3610@noindent
3611As with the @samp{[New @dots{}]} message, the form of the text after
3612@samp{Switching to} depends on your system's conventions for identifying
5d161b24 3613threads.
c906108c 3614
3345721a 3615@anchor{thread apply all}
9c16f35a 3616@kindex thread apply
638ac427 3617@cindex apply command to several threads
0a232300 3618@item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
839c27b7 3619The @code{thread apply} command allows you to apply the named
5d5658a1
PA
3620@var{command} to one or more threads. Specify the threads that you
3621want affected using the thread ID list syntax (@pxref{thread ID
3622lists}), or specify @code{all} to apply to all threads. To apply a
3623command to all threads in descending order, type @kbd{thread apply all
253828f1
JK
3624@var{command}}. To apply a command to all threads in ascending order,
3625type @kbd{thread apply all -ascending @var{command}}.
3626
0a232300
PW
3627The @var{flag} arguments control what output to produce and how to handle
3628errors raised when applying @var{command} to a thread. @var{flag}
3629must start with a @code{-} directly followed by one letter in
3630@code{qcs}. If several flags are provided, they must be given
3631individually, such as @code{-c -q}.
3632
3633By default, @value{GDBN} displays some thread information before the
3634output produced by @var{command}, and an error raised during the
3635execution of a @var{command} will abort @code{thread apply}. The
3636following flags can be used to fine-tune this behavior:
3637
3638@table @code
3639@item -c
3640The flag @code{-c}, which stands for @samp{continue}, causes any
3641errors in @var{command} to be displayed, and the execution of
3642@code{thread apply} then continues.
3643@item -s
3644The flag @code{-s}, which stands for @samp{silent}, causes any errors
3645or empty output produced by a @var{command} to be silently ignored.
3646That is, the execution continues, but the thread information and errors
3647are not printed.
3648@item -q
3649The flag @code{-q} (@samp{quiet}) disables printing the thread
3650information.
3651@end table
3652
3653Flags @code{-c} and @code{-s} cannot be used together.
3654
3655@kindex taas
3656@cindex apply command to all threads (ignoring errors and empty output)
3345721a
PA
3657@item taas [@var{option}]@dots{} @var{command}
3658Shortcut for @code{thread apply all -s [@var{option}]@dots{} @var{command}}.
0a232300
PW
3659Applies @var{command} on all threads, ignoring errors and empty output.
3660
3345721a
PA
3661The @code{taas} command accepts the same options as the @code{thread
3662apply all} command. @xref{thread apply all}.
3663
0a232300
PW
3664@kindex tfaas
3665@cindex apply a command to all frames of all threads (ignoring errors and empty output)
3345721a
PA
3666@item tfaas [@var{option}]@dots{} @var{command}
3667Shortcut for @code{thread apply all -s -- frame apply all -s [@var{option}]@dots{} @var{command}}.
0a232300
PW
3668Applies @var{command} on all frames of all threads, ignoring errors
3669and empty output. Note that the flag @code{-s} is specified twice:
3670The first @code{-s} ensures that @code{thread apply} only shows the thread
3671information of the threads for which @code{frame apply} produces
3672some output. The second @code{-s} is needed to ensure that @code{frame
3673apply} shows the frame information of a frame only if the
3674@var{command} successfully produced some output.
3675
3676It can for example be used to print a local variable or a function
3677argument without knowing the thread or frame where this variable or argument
3678is, using:
3679@smallexample
3680(@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3681@end smallexample
3682
3345721a 3683The @code{tfaas} command accepts the same options as the @code{frame
ed788fee 3684apply} command. @xref{Frame Apply,,frame apply}.
93815fbf 3685
4694da01
TT
3686@kindex thread name
3687@cindex name a thread
3688@item thread name [@var{name}]
3689This command assigns a name to the current thread. If no argument is
3690given, any existing user-specified name is removed. The thread name
3691appears in the @samp{info threads} display.
3692
3693On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3694determine the name of the thread as given by the OS. On these
3695systems, a name specified with @samp{thread name} will override the
3696system-give name, and removing the user-specified name will cause
3697@value{GDBN} to once again display the system-specified name.
3698
60f98dde
MS
3699@kindex thread find
3700@cindex search for a thread
3701@item thread find [@var{regexp}]
3702Search for and display thread ids whose name or @var{systag}
3703matches the supplied regular expression.
3704
3705As well as being the complement to the @samp{thread name} command,
3706this command also allows you to identify a thread by its target
3707@var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3708is the LWP id.
3709
3710@smallexample
3711(@value{GDBN}) thread find 26688
3712Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3713(@value{GDBN}) info thread 4
3714 Id Target Id Frame
3715 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3716@end smallexample
3717
93815fbf
VP
3718@kindex set print thread-events
3719@cindex print messages on thread start and exit
3720@item set print thread-events
3721@itemx set print thread-events on
3722@itemx set print thread-events off
3723The @code{set print thread-events} command allows you to enable or
3724disable printing of messages when @value{GDBN} notices that new threads have
3725started or that threads have exited. By default, these messages will
3726be printed if detection of these events is supported by the target.
3727Note that these messages cannot be disabled on all targets.
3728
3729@kindex show print thread-events
3730@item show print thread-events
3731Show whether messages will be printed when @value{GDBN} detects that threads
3732have started and exited.
c906108c
SS
3733@end table
3734
79a6e687 3735@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
c906108c
SS
3736more information about how @value{GDBN} behaves when you stop and start
3737programs with multiple threads.
3738
79a6e687 3739@xref{Set Watchpoints,,Setting Watchpoints}, for information about
c906108c 3740watchpoints in programs with multiple threads.
c906108c 3741
bf88dd68 3742@anchor{set libthread-db-search-path}
17a37d48
PP
3743@table @code
3744@kindex set libthread-db-search-path
3745@cindex search path for @code{libthread_db}
3746@item set libthread-db-search-path @r{[}@var{path}@r{]}
3747If this variable is set, @var{path} is a colon-separated list of
3748directories @value{GDBN} will use to search for @code{libthread_db}.
3749If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
98a5dd13 3750its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
7e0396aa
DE
3751Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3752macro.
17a37d48
PP
3753
3754On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3755@code{libthread_db} library to obtain information about threads in the
3756inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
bf88dd68
JK
3757to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3758specific thread debugging library loading is enabled
3759by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3760
3761A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3762refers to the default system directories that are
bf88dd68
JK
3763normally searched for loading shared libraries. The @samp{$sdir} entry
3764is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3765(@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3766
3767A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3768refers to the directory from which @code{libpthread}
3769was loaded in the inferior process.
17a37d48
PP
3770
3771For any @code{libthread_db} library @value{GDBN} finds in above directories,
3772@value{GDBN} attempts to initialize it with the current inferior process.
3773If this initialization fails (which could happen because of a version
3774mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3775will unload @code{libthread_db}, and continue with the next directory.
3776If none of @code{libthread_db} libraries initialize successfully,
3777@value{GDBN} will issue a warning and thread debugging will be disabled.
3778
3779Setting @code{libthread-db-search-path} is currently implemented
3780only on some platforms.
3781
3782@kindex show libthread-db-search-path
3783@item show libthread-db-search-path
3784Display current libthread_db search path.
02d868e8
PP
3785
3786@kindex set debug libthread-db
3787@kindex show debug libthread-db
3788@cindex debugging @code{libthread_db}
3789@item set debug libthread-db
3790@itemx show debug libthread-db
3791Turns on or off display of @code{libthread_db}-related events.
3792Use @code{1} to enable, @code{0} to disable.
17a37d48
PP
3793@end table
3794
6c95b8df
PA
3795@node Forks
3796@section Debugging Forks
c906108c
SS
3797
3798@cindex fork, debugging programs which call
3799@cindex multiple processes
3800@cindex processes, multiple
53a5351d
JM
3801On most systems, @value{GDBN} has no special support for debugging
3802programs which create additional processes using the @code{fork}
3803function. When a program forks, @value{GDBN} will continue to debug the
3804parent process and the child process will run unimpeded. If you have
3805set a breakpoint in any code which the child then executes, the child
3806will get a @code{SIGTRAP} signal which (unless it catches the signal)
3807will cause it to terminate.
c906108c
SS
3808
3809However, if you want to debug the child process there is a workaround
3810which isn't too painful. Put a call to @code{sleep} in the code which
3811the child process executes after the fork. It may be useful to sleep
3812only if a certain environment variable is set, or a certain file exists,
3813so that the delay need not occur when you don't want to run @value{GDBN}
3814on the child. While the child is sleeping, use the @code{ps} program to
3815get its process ID. Then tell @value{GDBN} (a new invocation of
3816@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 3817the child process (@pxref{Attach}). From that point on you can debug
c906108c 3818the child process just like any other process which you attached to.
c906108c 3819
b1236ac3
PA
3820On some systems, @value{GDBN} provides support for debugging programs
3821that create additional processes using the @code{fork} or @code{vfork}
3822functions. On @sc{gnu}/Linux platforms, this feature is supported
19d9d4ef 3823with kernel version 2.5.46 and later.
c906108c 3824
19d9d4ef
DB
3825The fork debugging commands are supported in native mode and when
3826connected to @code{gdbserver} in either @code{target remote} mode or
3827@code{target extended-remote} mode.
0d71eef5 3828
c906108c
SS
3829By default, when a program forks, @value{GDBN} will continue to debug
3830the parent process and the child process will run unimpeded.
3831
3832If you want to follow the child process instead of the parent process,
3833use the command @w{@code{set follow-fork-mode}}.
3834
3835@table @code
3836@kindex set follow-fork-mode
3837@item set follow-fork-mode @var{mode}
3838Set the debugger response to a program call of @code{fork} or
3839@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 3840process. The @var{mode} argument can be:
c906108c
SS
3841
3842@table @code
3843@item parent
3844The original process is debugged after a fork. The child process runs
2df3850c 3845unimpeded. This is the default.
c906108c
SS
3846
3847@item child
3848The new process is debugged after a fork. The parent process runs
3849unimpeded.
3850
c906108c
SS
3851@end table
3852
9c16f35a 3853@kindex show follow-fork-mode
c906108c 3854@item show follow-fork-mode
2df3850c 3855Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
3856@end table
3857
5c95884b
MS
3858@cindex debugging multiple processes
3859On Linux, if you want to debug both the parent and child processes, use the
3860command @w{@code{set detach-on-fork}}.
3861
3862@table @code
3863@kindex set detach-on-fork
3864@item set detach-on-fork @var{mode}
3865Tells gdb whether to detach one of the processes after a fork, or
3866retain debugger control over them both.
3867
3868@table @code
3869@item on
3870The child process (or parent process, depending on the value of
3871@code{follow-fork-mode}) will be detached and allowed to run
3872independently. This is the default.
3873
3874@item off
3875Both processes will be held under the control of @value{GDBN}.
3876One process (child or parent, depending on the value of
3877@code{follow-fork-mode}) is debugged as usual, while the other
3878is held suspended.
3879
3880@end table
3881
11310833
NR
3882@kindex show detach-on-fork
3883@item show detach-on-fork
3884Show whether detach-on-fork mode is on/off.
5c95884b
MS
3885@end table
3886
2277426b
PA
3887If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3888will retain control of all forked processes (including nested forks).
3889You can list the forked processes under the control of @value{GDBN} by
3890using the @w{@code{info inferiors}} command, and switch from one fork
65c574f6
PA
3891to another by using the @code{inferior} command (@pxref{Inferiors Connections and
3892Programs, ,Debugging Multiple Inferiors Connections and Programs}).
5c95884b
MS
3893
3894To quit debugging one of the forked processes, you can either detach
af624141
MS
3895from it by using the @w{@code{detach inferiors}} command (allowing it
3896to run independently), or kill it using the @w{@code{kill inferiors}}
65c574f6
PA
3897command. @xref{Inferiors Connections and Programs, ,Debugging
3898Multiple Inferiors Connections and Programs}.
5c95884b 3899
c906108c
SS
3900If you ask to debug a child process and a @code{vfork} is followed by an
3901@code{exec}, @value{GDBN} executes the new target up to the first
3902breakpoint in the new target. If you have a breakpoint set on
3903@code{main} in your original program, the breakpoint will also be set on
3904the child process's @code{main}.
3905
2277426b
PA
3906On some systems, when a child process is spawned by @code{vfork}, you
3907cannot debug the child or parent until an @code{exec} call completes.
c906108c
SS
3908
3909If you issue a @code{run} command to @value{GDBN} after an @code{exec}
6c95b8df
PA
3910call executes, the new target restarts. To restart the parent
3911process, use the @code{file} command with the parent executable name
3912as its argument. By default, after an @code{exec} call executes,
3913@value{GDBN} discards the symbols of the previous executable image.
3914You can change this behaviour with the @w{@code{set follow-exec-mode}}
3915command.
3916
3917@table @code
3918@kindex set follow-exec-mode
3919@item set follow-exec-mode @var{mode}
3920
3921Set debugger response to a program call of @code{exec}. An
3922@code{exec} call replaces the program image of a process.
3923
3924@code{follow-exec-mode} can be:
3925
3926@table @code
3927@item new
3928@value{GDBN} creates a new inferior and rebinds the process to this
3929new inferior. The program the process was running before the
3930@code{exec} call can be restarted afterwards by restarting the
3931original inferior.
3932
3933For example:
3934
3935@smallexample
3936(@value{GDBP}) info inferiors
3937(gdb) info inferior
3938 Id Description Executable
3939* 1 <null> prog1
3940(@value{GDBP}) run
3941process 12020 is executing new program: prog2
3942Program exited normally.
3943(@value{GDBP}) info inferiors
3944 Id Description Executable
c0ecb95f 3945 1 <null> prog1
b05b1202 3946* 2 <null> prog2
6c95b8df
PA
3947@end smallexample
3948
3949@item same
3950@value{GDBN} keeps the process bound to the same inferior. The new
3951executable image replaces the previous executable loaded in the
3952inferior. Restarting the inferior after the @code{exec} call, with
3953e.g., the @code{run} command, restarts the executable the process was
3954running after the @code{exec} call. This is the default mode.
3955
3956For example:
3957
3958@smallexample
3959(@value{GDBP}) info inferiors
3960 Id Description Executable
3961* 1 <null> prog1
3962(@value{GDBP}) run
3963process 12020 is executing new program: prog2
3964Program exited normally.
3965(@value{GDBP}) info inferiors
3966 Id Description Executable
3967* 1 <null> prog2
3968@end smallexample
3969
3970@end table
3971@end table
c906108c 3972
19d9d4ef
DB
3973@code{follow-exec-mode} is supported in native mode and
3974@code{target extended-remote} mode.
3975
c906108c
SS
3976You can use the @code{catch} command to make @value{GDBN} stop whenever
3977a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
79a6e687 3978Catchpoints, ,Setting Catchpoints}.
c906108c 3979
5c95884b 3980@node Checkpoint/Restart
79a6e687 3981@section Setting a @emph{Bookmark} to Return to Later
5c95884b
MS
3982
3983@cindex checkpoint
3984@cindex restart
3985@cindex bookmark
3986@cindex snapshot of a process
3987@cindex rewind program state
3988
3989On certain operating systems@footnote{Currently, only
3990@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3991program's state, called a @dfn{checkpoint}, and come back to it
3992later.
3993
3994Returning to a checkpoint effectively undoes everything that has
3995happened in the program since the @code{checkpoint} was saved. This
3996includes changes in memory, registers, and even (within some limits)
3997system state. Effectively, it is like going back in time to the
3998moment when the checkpoint was saved.
3999
4000Thus, if you're stepping thru a program and you think you're
4001getting close to the point where things go wrong, you can save
4002a checkpoint. Then, if you accidentally go too far and miss
4003the critical statement, instead of having to restart your program
4004from the beginning, you can just go back to the checkpoint and
4005start again from there.
4006
4007This can be especially useful if it takes a lot of time or
4008steps to reach the point where you think the bug occurs.
4009
4010To use the @code{checkpoint}/@code{restart} method of debugging:
4011
4012@table @code
4013@kindex checkpoint
4014@item checkpoint
4015Save a snapshot of the debugged program's current execution state.
4016The @code{checkpoint} command takes no arguments, but each checkpoint
4017is assigned a small integer id, similar to a breakpoint id.
4018
4019@kindex info checkpoints
4020@item info checkpoints
4021List the checkpoints that have been saved in the current debugging
4022session. For each checkpoint, the following information will be
4023listed:
4024
4025@table @code
4026@item Checkpoint ID
4027@item Process ID
4028@item Code Address
4029@item Source line, or label
4030@end table
4031
4032@kindex restart @var{checkpoint-id}
4033@item restart @var{checkpoint-id}
4034Restore the program state that was saved as checkpoint number
4035@var{checkpoint-id}. All program variables, registers, stack frames
4036etc.@: will be returned to the values that they had when the checkpoint
4037was saved. In essence, gdb will ``wind back the clock'' to the point
4038in time when the checkpoint was saved.
4039
4040Note that breakpoints, @value{GDBN} variables, command history etc.
4041are not affected by restoring a checkpoint. In general, a checkpoint
4042only restores things that reside in the program being debugged, not in
4043the debugger.
4044
b8db102d
MS
4045@kindex delete checkpoint @var{checkpoint-id}
4046@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
4047Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
4048
4049@end table
4050
4051Returning to a previously saved checkpoint will restore the user state
4052of the program being debugged, plus a significant subset of the system
4053(OS) state, including file pointers. It won't ``un-write'' data from
4054a file, but it will rewind the file pointer to the previous location,
4055so that the previously written data can be overwritten. For files
4056opened in read mode, the pointer will also be restored so that the
4057previously read data can be read again.
4058
4059Of course, characters that have been sent to a printer (or other
4060external device) cannot be ``snatched back'', and characters received
4061from eg.@: a serial device can be removed from internal program buffers,
4062but they cannot be ``pushed back'' into the serial pipeline, ready to
4063be received again. Similarly, the actual contents of files that have
4064been changed cannot be restored (at this time).
4065
4066However, within those constraints, you actually can ``rewind'' your
4067program to a previously saved point in time, and begin debugging it
4068again --- and you can change the course of events so as to debug a
4069different execution path this time.
4070
4071@cindex checkpoints and process id
4072Finally, there is one bit of internal program state that will be
4073different when you return to a checkpoint --- the program's process
4074id. Each checkpoint will have a unique process id (or @var{pid}),
4075and each will be different from the program's original @var{pid}.
4076If your program has saved a local copy of its process id, this could
4077potentially pose a problem.
4078
79a6e687 4079@subsection A Non-obvious Benefit of Using Checkpoints
5c95884b
MS
4080
4081On some systems such as @sc{gnu}/Linux, address space randomization
4082is performed on new processes for security reasons. This makes it
4083difficult or impossible to set a breakpoint, or watchpoint, on an
4084absolute address if you have to restart the program, since the
4085absolute location of a symbol will change from one execution to the
4086next.
4087
4088A checkpoint, however, is an @emph{identical} copy of a process.
4089Therefore if you create a checkpoint at (eg.@:) the start of main,
4090and simply return to that checkpoint instead of restarting the
4091process, you can avoid the effects of address randomization and
4092your symbols will all stay in the same place.
4093
6d2ebf8b 4094@node Stopping
c906108c
SS
4095@chapter Stopping and Continuing
4096
4097The principal purposes of using a debugger are so that you can stop your
4098program before it terminates; or so that, if your program runs into
4099trouble, you can investigate and find out why.
4100
7a292a7a
SS
4101Inside @value{GDBN}, your program may stop for any of several reasons,
4102such as a signal, a breakpoint, or reaching a new line after a
4103@value{GDBN} command such as @code{step}. You may then examine and
4104change variables, set new breakpoints or remove old ones, and then
4105continue execution. Usually, the messages shown by @value{GDBN} provide
4106ample explanation of the status of your program---but you can also
4107explicitly request this information at any time.
c906108c
SS
4108
4109@table @code
4110@kindex info program
4111@item info program
4112Display information about the status of your program: whether it is
7a292a7a 4113running or not, what process it is, and why it stopped.
c906108c
SS
4114@end table
4115
4116@menu
4117* Breakpoints:: Breakpoints, watchpoints, and catchpoints
4118* Continuing and Stepping:: Resuming execution
aad1c02c
TT
4119* Skipping Over Functions and Files::
4120 Skipping over functions and files
c906108c 4121* Signals:: Signals
c906108c 4122* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
4123@end menu
4124
6d2ebf8b 4125@node Breakpoints
79a6e687 4126@section Breakpoints, Watchpoints, and Catchpoints
c906108c
SS
4127
4128@cindex breakpoints
4129A @dfn{breakpoint} makes your program stop whenever a certain point in
4130the program is reached. For each breakpoint, you can add conditions to
4131control in finer detail whether your program stops. You can set
4132breakpoints with the @code{break} command and its variants (@pxref{Set
79a6e687 4133Breaks, ,Setting Breakpoints}), to specify the place where your program
c906108c
SS
4134should stop by line number, function name or exact address in the
4135program.
4136
09d4efe1 4137On some systems, you can set breakpoints in shared libraries before
b1236ac3 4138the executable is run.
c906108c
SS
4139
4140@cindex watchpoints
fd60e0df 4141@cindex data breakpoints
c906108c
SS
4142@cindex memory tracing
4143@cindex breakpoint on memory address
4144@cindex breakpoint on variable modification
4145A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 4146when the value of an expression changes. The expression may be a value
0ced0c34 4147of a variable, or it could involve values of one or more variables
fd60e0df
EZ
4148combined by operators, such as @samp{a + b}. This is sometimes called
4149@dfn{data breakpoints}. You must use a different command to set
79a6e687 4150watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
fd60e0df
EZ
4151from that, you can manage a watchpoint like any other breakpoint: you
4152enable, disable, and delete both breakpoints and watchpoints using the
4153same commands.
c906108c
SS
4154
4155You can arrange to have values from your program displayed automatically
4156whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
79a6e687 4157Automatic Display}.
c906108c
SS
4158
4159@cindex catchpoints
4160@cindex breakpoint on events
4161A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 4162when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
4163exception or the loading of a library. As with watchpoints, you use a
4164different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
79a6e687 4165Catchpoints}), but aside from that, you can manage a catchpoint like any
c906108c 4166other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 4167@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
4168
4169@cindex breakpoint numbers
4170@cindex numbers for breakpoints
4171@value{GDBN} assigns a number to each breakpoint, watchpoint, or
4172catchpoint when you create it; these numbers are successive integers
4173starting with one. In many of the commands for controlling various
4174features of breakpoints you use the breakpoint number to say which
4175breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
4176@dfn{disabled}; if disabled, it has no effect on your program until you
4177enable it again.
4178
c5394b80 4179@cindex breakpoint ranges
18da0c51 4180@cindex breakpoint lists
c5394b80 4181@cindex ranges of breakpoints
18da0c51
MG
4182@cindex lists of breakpoints
4183Some @value{GDBN} commands accept a space-separated list of breakpoints
4184on which to operate. A list element can be either a single breakpoint number,
4185like @samp{5}, or a range of such numbers, like @samp{5-7}.
4186When a breakpoint list is given to a command, all breakpoints in that list
4187are operated on.
c5394b80 4188
c906108c
SS
4189@menu
4190* Set Breaks:: Setting breakpoints
4191* Set Watchpoints:: Setting watchpoints
4192* Set Catchpoints:: Setting catchpoints
4193* Delete Breaks:: Deleting breakpoints
4194* Disabling:: Disabling breakpoints
4195* Conditions:: Break conditions
4196* Break Commands:: Breakpoint command lists
e7e0cddf 4197* Dynamic Printf:: Dynamic printf
6149aea9 4198* Save Breakpoints:: How to save breakpoints in a file
62e5f89c 4199* Static Probe Points:: Listing static probe points
d4f3574e 4200* Error in Breakpoints:: ``Cannot insert breakpoints''
79a6e687 4201* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
c906108c
SS
4202@end menu
4203
6d2ebf8b 4204@node Set Breaks
79a6e687 4205@subsection Setting Breakpoints
c906108c 4206
5d161b24 4207@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
4208@c consider in particular declaration with/without initialization.
4209@c
4210@c FIXME 2 is there stuff on this already? break at fun start, already init?
4211
4212@kindex break
41afff9a
EZ
4213@kindex b @r{(@code{break})}
4214@vindex $bpnum@r{, convenience variable}
c906108c
SS
4215@cindex latest breakpoint
4216Breakpoints are set with the @code{break} command (abbreviated
5d161b24 4217@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 4218number of the breakpoint you've set most recently; see @ref{Convenience
79a6e687 4219Vars,, Convenience Variables}, for a discussion of what you can do with
c906108c
SS
4220convenience variables.
4221
c906108c 4222@table @code
2a25a5ba
EZ
4223@item break @var{location}
4224Set a breakpoint at the given @var{location}, which can specify a
4225function name, a line number, or an address of an instruction.
4226(@xref{Specify Location}, for a list of all the possible ways to
4227specify a @var{location}.) The breakpoint will stop your program just
4228before it executes any of the code in the specified @var{location}.
4229
c906108c 4230When using source languages that permit overloading of symbols, such as
2a25a5ba 4231C@t{++}, a function name may refer to more than one possible place to break.
6ba66d6a
JB
4232@xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
4233that situation.
c906108c 4234
45ac276d 4235It is also possible to insert a breakpoint that will stop the program
2c88c651
JB
4236only if a specific thread (@pxref{Thread-Specific Breakpoints})
4237or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
45ac276d 4238
c906108c
SS
4239@item break
4240When called without any arguments, @code{break} sets a breakpoint at
4241the next instruction to be executed in the selected stack frame
4242(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
4243innermost, this makes your program stop as soon as control
4244returns to that frame. This is similar to the effect of a
4245@code{finish} command in the frame inside the selected frame---except
4246that @code{finish} does not leave an active breakpoint. If you use
4247@code{break} without an argument in the innermost frame, @value{GDBN} stops
4248the next time it reaches the current location; this may be useful
4249inside loops.
4250
4251@value{GDBN} normally ignores breakpoints when it resumes execution, until at
4252least one instruction has been executed. If it did not do this, you
4253would be unable to proceed past a breakpoint without first disabling the
4254breakpoint. This rule applies whether or not the breakpoint already
4255existed when your program stopped.
4256
4257@item break @dots{} if @var{cond}
4258Set a breakpoint with condition @var{cond}; evaluate the expression
4259@var{cond} each time the breakpoint is reached, and stop only if the
4260value is nonzero---that is, if @var{cond} evaluates as true.
4261@samp{@dots{}} stands for one of the possible arguments described
4262above (or no argument) specifying where to break. @xref{Conditions,
79a6e687 4263,Break Conditions}, for more information on breakpoint conditions.
c906108c 4264
b5fa468f
TBA
4265The breakpoint may be mapped to multiple locations. If the breakpoint
4266condition @var{cond} is invalid at some but not all of the locations,
4267the locations for which the condition is invalid are disabled. For
4268example, @value{GDBN} reports below that two of the three locations
4269are disabled.
4270
4271@smallexample
4272(@value{GDBP}) break func if a == 10
4273warning: failed to validate condition at location 0x11ce, disabling:
4274 No symbol "a" in current context.
4275warning: failed to validate condition at location 0x11b6, disabling:
4276 No symbol "a" in current context.
4277Breakpoint 1 at 0x11b6: func. (3 locations)
4278@end smallexample
4279
4280Locations that are disabled because of the condition are denoted by an
4281uppercase @code{N} in the output of the @code{info breakpoints}
4282command:
4283
4284@smallexample
4285(@value{GDBP}) info breakpoints
4286Num Type Disp Enb Address What
42871 breakpoint keep y <MULTIPLE>
4288 stop only if a == 10
42891.1 N* 0x00000000000011b6 in ...
42901.2 y 0x00000000000011c2 in ...
42911.3 N* 0x00000000000011ce in ...
4292(*): Breakpoint condition is invalid at this location.
4293@end smallexample
4294
4295If the breakpoint condition @var{cond} is invalid in the context of
4296@emph{all} the locations of the breakpoint, @value{GDBN} refuses to
4297define the breakpoint. For example, if variable @code{foo} is an
4298undefined variable:
4299
4300@smallexample
4301(@value{GDBP}) break func if foo
4302No symbol "foo" in current context.
4303@end smallexample
4304
733d554a
TBA
4305@item break @dots{} -force-condition if @var{cond}
4306There may be cases where the condition @var{cond} is invalid at all
4307the current locations, but the user knows that it will be valid at a
4308future location; for example, because of a library load. In such
4309cases, by using the @code{-force-condition} keyword before @samp{if},
4310@value{GDBN} can be forced to define the breakpoint with the given
4311condition expression instead of refusing it.
4312
4313@smallexample
4314(@value{GDBP}) break func -force-condition if foo
4315warning: failed to validate condition at location 1, disabling:
4316 No symbol "foo" in current context.
4317warning: failed to validate condition at location 2, disabling:
4318 No symbol "foo" in current context.
4319warning: failed to validate condition at location 3, disabling:
4320 No symbol "foo" in current context.
4321Breakpoint 1 at 0x1158: test.c:18. (3 locations)
4322@end smallexample
4323
4324This causes all the present locations where the breakpoint would
4325otherwise be inserted, to be disabled, as seen in the example above.
4326However, if there exist locations at which the condition is valid, the
4327@code{-force-condition} keyword has no effect.
4328
c906108c
SS
4329@kindex tbreak
4330@item tbreak @var{args}
697aa1b7 4331Set a breakpoint enabled only for one stop. The @var{args} are the
c906108c
SS
4332same as for the @code{break} command, and the breakpoint is set in the same
4333way, but the breakpoint is automatically deleted after the first time your
79a6e687 4334program stops there. @xref{Disabling, ,Disabling Breakpoints}.
c906108c 4335
c906108c 4336@kindex hbreak
ba04e063 4337@cindex hardware breakpoints
c906108c 4338@item hbreak @var{args}
697aa1b7 4339Set a hardware-assisted breakpoint. The @var{args} are the same as for the
d4f3574e 4340@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
4341breakpoint requires hardware support and some target hardware may not
4342have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
4343debugging, so you can set a breakpoint at an instruction without
4344changing the instruction. This can be used with the new trap-generation
09d4efe1 4345provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
4346will generate traps when a program accesses some data or instruction
4347address that is assigned to the debug registers. However the hardware
4348breakpoint registers can take a limited number of breakpoints. For
4349example, on the DSU, only two data breakpoints can be set at a time, and
4350@value{GDBN} will reject this command if more than two are used. Delete
4351or disable unused hardware breakpoints before setting new ones
79a6e687
BW
4352(@pxref{Disabling, ,Disabling Breakpoints}).
4353@xref{Conditions, ,Break Conditions}.
9c16f35a
EZ
4354For remote targets, you can restrict the number of hardware
4355breakpoints @value{GDBN} will use, see @ref{set remote
4356hardware-breakpoint-limit}.
501eef12 4357
c906108c
SS
4358@kindex thbreak
4359@item thbreak @var{args}
697aa1b7 4360Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
c906108c 4361are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 4362the same way. However, like the @code{tbreak} command,
c906108c
SS
4363the breakpoint is automatically deleted after the
4364first time your program stops there. Also, like the @code{hbreak}
5d161b24 4365command, the breakpoint requires hardware support and some target hardware
79a6e687
BW
4366may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
4367See also @ref{Conditions, ,Break Conditions}.
c906108c
SS
4368
4369@kindex rbreak
4370@cindex regular expression
8bd10a10 4371@cindex breakpoints at functions matching a regexp
c45da7e6 4372@cindex set breakpoints in many functions
c906108c 4373@item rbreak @var{regex}
c906108c 4374Set breakpoints on all functions matching the regular expression
11cf8741
JM
4375@var{regex}. This command sets an unconditional breakpoint on all
4376matches, printing a list of all breakpoints it set. Once these
4377breakpoints are set, they are treated just like the breakpoints set with
4378the @code{break} command. You can delete them, disable them, or make
4379them conditional the same way as any other breakpoint.
4380
20813a0b
PW
4381In programs using different languages, @value{GDBN} chooses the syntax
4382to print the list of all breakpoints it sets according to the
4383@samp{set language} value: using @samp{set language auto}
4384(see @ref{Automatically, ,Set Language Automatically}) means to use the
4385language of the breakpoint's function, other values mean to use
4386the manually specified language (see @ref{Manually, ,Set Language Manually}).
4387
11cf8741
JM
4388The syntax of the regular expression is the standard one used with tools
4389like @file{grep}. Note that this is different from the syntax used by
4390shells, so for instance @code{foo*} matches all functions that include
4391an @code{fo} followed by zero or more @code{o}s. There is an implicit
4392@code{.*} leading and trailing the regular expression you supply, so to
4393match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 4394
f7dc1244 4395@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 4396When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
4397breakpoints on overloaded functions that are not members of any special
4398classes.
c906108c 4399
f7dc1244
EZ
4400@cindex set breakpoints on all functions
4401The @code{rbreak} command can be used to set breakpoints in
4402@strong{all} the functions in a program, like this:
4403
4404@smallexample
4405(@value{GDBP}) rbreak .
4406@end smallexample
4407
8bd10a10
CM
4408@item rbreak @var{file}:@var{regex}
4409If @code{rbreak} is called with a filename qualification, it limits
4410the search for functions matching the given regular expression to the
4411specified @var{file}. This can be used, for example, to set breakpoints on
4412every function in a given file:
4413
4414@smallexample
4415(@value{GDBP}) rbreak file.c:.
4416@end smallexample
4417
4418The colon separating the filename qualifier from the regex may
4419optionally be surrounded by spaces.
4420
c906108c
SS
4421@kindex info breakpoints
4422@cindex @code{$_} and @code{info breakpoints}
18da0c51
MG
4423@item info breakpoints @r{[}@var{list}@dots{}@r{]}
4424@itemx info break @r{[}@var{list}@dots{}@r{]}
c906108c 4425Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734 4426not deleted. Optional argument @var{n} means print information only
e5a67952
MS
4427about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4428For each breakpoint, following columns are printed:
c906108c
SS
4429
4430@table @emph
4431@item Breakpoint Numbers
4432@item Type
4433Breakpoint, watchpoint, or catchpoint.
4434@item Disposition
4435Whether the breakpoint is marked to be disabled or deleted when hit.
4436@item Enabled or Disabled
4437Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
b3db7447 4438that are not enabled.
c906108c 4439@item Address
fe6fbf8b 4440Where the breakpoint is in your program, as a memory address. For a
b3db7447
NR
4441pending breakpoint whose address is not yet known, this field will
4442contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
4443library that has the symbol or line referred by breakpoint is loaded.
4444See below for details. A breakpoint with several locations will
3b784c4f 4445have @samp{<MULTIPLE>} in this field---see below for details.
c906108c
SS
4446@item What
4447Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
4448line number. For a pending breakpoint, the original string passed to
4449the breakpoint command will be listed as it cannot be resolved until
4450the appropriate shared library is loaded in the future.
c906108c
SS
4451@end table
4452
4453@noindent
83364271
LM
4454If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4455``target''. If mode is ``host'', breakpoint condition evaluation is done by
4456@value{GDBN} on the host's side. If it is ``target'', then the condition
4457is evaluated by the target. The @code{info break} command shows
4458the condition on the line following the affected breakpoint, together with
4459its condition evaluation mode in between parentheses.
4460
4461Breakpoint commands, if any, are listed after that. A pending breakpoint is
4462allowed to have a condition specified for it. The condition is not parsed for
4463validity until a shared library is loaded that allows the pending
4464breakpoint to resolve to a valid location.
c906108c
SS
4465
4466@noindent
4467@code{info break} with a breakpoint
4468number @var{n} as argument lists only that breakpoint. The
4469convenience variable @code{$_} and the default examining-address for
4470the @code{x} command are set to the address of the last breakpoint
79a6e687 4471listed (@pxref{Memory, ,Examining Memory}).
c906108c
SS
4472
4473@noindent
4474@code{info break} displays a count of the number of times the breakpoint
4475has been hit. This is especially useful in conjunction with the
4476@code{ignore} command. You can ignore a large number of breakpoint
4477hits, look at the breakpoint info to see how many times the breakpoint
4478was hit, and then run again, ignoring one less than that number. This
4479will get you quickly to the last hit of that breakpoint.
816338b5
SS
4480
4481@noindent
4482For a breakpoints with an enable count (xref) greater than 1,
4483@code{info break} also displays that count.
4484
c906108c
SS
4485@end table
4486
4487@value{GDBN} allows you to set any number of breakpoints at the same place in
4488your program. There is nothing silly or meaningless about this. When
4489the breakpoints are conditional, this is even useful
79a6e687 4490(@pxref{Conditions, ,Break Conditions}).
c906108c 4491
2e9132cc
EZ
4492@cindex multiple locations, breakpoints
4493@cindex breakpoints, multiple locations
fcda367b 4494It is possible that a breakpoint corresponds to several locations
fe6fbf8b
VP
4495in your program. Examples of this situation are:
4496
4497@itemize @bullet
f8eba3c6
TT
4498@item
4499Multiple functions in the program may have the same name.
4500
fe6fbf8b
VP
4501@item
4502For a C@t{++} constructor, the @value{NGCC} compiler generates several
4503instances of the function body, used in different cases.
4504
4505@item
4506For a C@t{++} template function, a given line in the function can
4507correspond to any number of instantiations.
4508
4509@item
4510For an inlined function, a given source line can correspond to
4511several places where that function is inlined.
fe6fbf8b
VP
4512@end itemize
4513
4514In all those cases, @value{GDBN} will insert a breakpoint at all
f8eba3c6 4515the relevant locations.
fe6fbf8b 4516
3b784c4f
EZ
4517A breakpoint with multiple locations is displayed in the breakpoint
4518table using several rows---one header row, followed by one row for
4519each breakpoint location. The header row has @samp{<MULTIPLE>} in the
4520address column. The rows for individual locations contain the actual
4521addresses for locations, and show the functions to which those
4522locations belong. The number column for a location is of the form
fe6fbf8b
VP
4523@var{breakpoint-number}.@var{location-number}.
4524
4525For example:
3b784c4f 4526
fe6fbf8b
VP
4527@smallexample
4528Num Type Disp Enb Address What
45291 breakpoint keep y <MULTIPLE>
4530 stop only if i==1
4531 breakpoint already hit 1 time
45321.1 y 0x080486a2 in void foo<int>() at t.cc:8
45331.2 y 0x080486ca in void foo<double>() at t.cc:8
4534@end smallexample
4535
d0fe4701
XR
4536You cannot delete the individual locations from a breakpoint. However,
4537each location can be individually enabled or disabled by passing
fe6fbf8b 4538@var{breakpoint-number}.@var{location-number} as argument to the
d0fe4701
XR
4539@code{enable} and @code{disable} commands. It's also possible to
4540@code{enable} and @code{disable} a range of @var{location-number}
4541locations using a @var{breakpoint-number} and two @var{location-number}s,
4542in increasing order, separated by a hyphen, like
4543@kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4544in which case @value{GDBN} acts on all the locations in the range (inclusive).
4545Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4546all of the locations that belong to that breakpoint.
fe6fbf8b 4547
2650777c 4548@cindex pending breakpoints
fe6fbf8b 4549It's quite common to have a breakpoint inside a shared library.
3b784c4f 4550Shared libraries can be loaded and unloaded explicitly,
fe6fbf8b
VP
4551and possibly repeatedly, as the program is executed. To support
4552this use case, @value{GDBN} updates breakpoint locations whenever
4553any shared library is loaded or unloaded. Typically, you would
fcda367b 4554set a breakpoint in a shared library at the beginning of your
fe6fbf8b
VP
4555debugging session, when the library is not loaded, and when the
4556symbols from the library are not available. When you try to set
4557breakpoint, @value{GDBN} will ask you if you want to set
3b784c4f 4558a so called @dfn{pending breakpoint}---breakpoint whose address
fe6fbf8b
VP
4559is not yet resolved.
4560
4561After the program is run, whenever a new shared library is loaded,
4562@value{GDBN} reevaluates all the breakpoints. When a newly loaded
4563shared library contains the symbol or line referred to by some
4564pending breakpoint, that breakpoint is resolved and becomes an
4565ordinary breakpoint. When a library is unloaded, all breakpoints
4566that refer to its symbols or source lines become pending again.
4567
4568This logic works for breakpoints with multiple locations, too. For
4569example, if you have a breakpoint in a C@t{++} template function, and
4570a newly loaded shared library has an instantiation of that template,
4571a new location is added to the list of locations for the breakpoint.
4572
4573Except for having unresolved address, pending breakpoints do not
4574differ from regular breakpoints. You can set conditions or commands,
4575enable and disable them and perform other breakpoint operations.
4576
4577@value{GDBN} provides some additional commands for controlling what
4578happens when the @samp{break} command cannot resolve breakpoint
4579address specification to an address:
dd79a6cf
JJ
4580
4581@kindex set breakpoint pending
4582@kindex show breakpoint pending
4583@table @code
4584@item set breakpoint pending auto
4585This is the default behavior. When @value{GDBN} cannot find the breakpoint
4586location, it queries you whether a pending breakpoint should be created.
4587
4588@item set breakpoint pending on
4589This indicates that an unrecognized breakpoint location should automatically
4590result in a pending breakpoint being created.
4591
4592@item set breakpoint pending off
4593This indicates that pending breakpoints are not to be created. Any
4594unrecognized breakpoint location results in an error. This setting does
4595not affect any pending breakpoints previously created.
4596
4597@item show breakpoint pending
4598Show the current behavior setting for creating pending breakpoints.
4599@end table
2650777c 4600
fe6fbf8b
VP
4601The settings above only affect the @code{break} command and its
4602variants. Once breakpoint is set, it will be automatically updated
4603as shared libraries are loaded and unloaded.
2650777c 4604
765dc015
VP
4605@cindex automatic hardware breakpoints
4606For some targets, @value{GDBN} can automatically decide if hardware or
4607software breakpoints should be used, depending on whether the
4608breakpoint address is read-only or read-write. This applies to
4609breakpoints set with the @code{break} command as well as to internal
4610breakpoints set by commands like @code{next} and @code{finish}. For
fcda367b 4611breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
765dc015
VP
4612breakpoints.
4613
18da0c51 4614You can control this automatic behaviour with the following commands:
765dc015
VP
4615
4616@kindex set breakpoint auto-hw
4617@kindex show breakpoint auto-hw
4618@table @code
4619@item set breakpoint auto-hw on
4620This is the default behavior. When @value{GDBN} sets a breakpoint, it
4621will try to use the target memory map to decide if software or hardware
4622breakpoint must be used.
4623
4624@item set breakpoint auto-hw off
4625This indicates @value{GDBN} should not automatically select breakpoint
4626type. If the target provides a memory map, @value{GDBN} will warn when
4627trying to set software breakpoint at a read-only address.
4628@end table
4629
74960c60
VP
4630@value{GDBN} normally implements breakpoints by replacing the program code
4631at the breakpoint address with a special instruction, which, when
4632executed, given control to the debugger. By default, the program
4633code is so modified only when the program is resumed. As soon as
4634the program stops, @value{GDBN} restores the original instructions. This
4635behaviour guards against leaving breakpoints inserted in the
4636target should gdb abrubptly disconnect. However, with slow remote
4637targets, inserting and removing breakpoint can reduce the performance.
4638This behavior can be controlled with the following commands::
4639
4640@kindex set breakpoint always-inserted
4641@kindex show breakpoint always-inserted
4642@table @code
4643@item set breakpoint always-inserted off
33e5cbd6
PA
4644All breakpoints, including newly added by the user, are inserted in
4645the target only when the target is resumed. All breakpoints are
a25a5a45 4646removed from the target when it stops. This is the default mode.
74960c60
VP
4647
4648@item set breakpoint always-inserted on
4649Causes all breakpoints to be inserted in the target at all times. If
4650the user adds a new breakpoint, or changes an existing breakpoint, the
4651breakpoints in the target are updated immediately. A breakpoint is
a25a5a45 4652removed from the target only when breakpoint itself is deleted.
342cc091 4653@end table
765dc015 4654
83364271
LM
4655@value{GDBN} handles conditional breakpoints by evaluating these conditions
4656when a breakpoint breaks. If the condition is true, then the process being
4657debugged stops, otherwise the process is resumed.
4658
4659If the target supports evaluating conditions on its end, @value{GDBN} may
4660download the breakpoint, together with its conditions, to it.
4661
4662This feature can be controlled via the following commands:
4663
4664@kindex set breakpoint condition-evaluation
4665@kindex show breakpoint condition-evaluation
4666@table @code
4667@item set breakpoint condition-evaluation host
4668This option commands @value{GDBN} to evaluate the breakpoint
4669conditions on the host's side. Unconditional breakpoints are sent to
4670the target which in turn receives the triggers and reports them back to GDB
4671for condition evaluation. This is the standard evaluation mode.
4672
4673@item set breakpoint condition-evaluation target
4674This option commands @value{GDBN} to download breakpoint conditions
4675to the target at the moment of their insertion. The target
4676is responsible for evaluating the conditional expression and reporting
4677breakpoint stop events back to @value{GDBN} whenever the condition
4678is true. Due to limitations of target-side evaluation, some conditions
4679cannot be evaluated there, e.g., conditions that depend on local data
4680that is only known to the host. Examples include
4681conditional expressions involving convenience variables, complex types
4682that cannot be handled by the agent expression parser and expressions
4683that are too long to be sent over to the target, specially when the
4684target is a remote system. In these cases, the conditions will be
4685evaluated by @value{GDBN}.
4686
4687@item set breakpoint condition-evaluation auto
4688This is the default mode. If the target supports evaluating breakpoint
4689conditions on its end, @value{GDBN} will download breakpoint conditions to
4690the target (limitations mentioned previously apply). If the target does
4691not support breakpoint condition evaluation, then @value{GDBN} will fallback
4692to evaluating all these conditions on the host's side.
4693@end table
4694
4695
c906108c
SS
4696@cindex negative breakpoint numbers
4697@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
4698@value{GDBN} itself sometimes sets breakpoints in your program for
4699special purposes, such as proper handling of @code{longjmp} (in C
4700programs). These internal breakpoints are assigned negative numbers,
4701starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 4702You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 4703@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
4704
4705
6d2ebf8b 4706@node Set Watchpoints
79a6e687 4707@subsection Setting Watchpoints
c906108c
SS
4708
4709@cindex setting watchpoints
c906108c
SS
4710You can use a watchpoint to stop execution whenever the value of an
4711expression changes, without having to predict a particular place where
fd60e0df
EZ
4712this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4713The expression may be as simple as the value of a single variable, or
4714as complex as many variables combined by operators. Examples include:
4715
4716@itemize @bullet
4717@item
4718A reference to the value of a single variable.
4719
4720@item
4721An address cast to an appropriate data type. For example,
4722@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4723address (assuming an @code{int} occupies 4 bytes).
4724
4725@item
4726An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4727expression can use any operators valid in the program's native
4728language (@pxref{Languages}).
4729@end itemize
c906108c 4730
fa4727a6
DJ
4731You can set a watchpoint on an expression even if the expression can
4732not be evaluated yet. For instance, you can set a watchpoint on
4733@samp{*global_ptr} before @samp{global_ptr} is initialized.
4734@value{GDBN} will stop when your program sets @samp{global_ptr} and
4735the expression produces a valid value. If the expression becomes
4736valid in some other way than changing a variable (e.g.@: if the memory
4737pointed to by @samp{*global_ptr} becomes readable as the result of a
4738@code{malloc} call), @value{GDBN} may not stop until the next time
4739the expression changes.
4740
82f2d802
EZ
4741@cindex software watchpoints
4742@cindex hardware watchpoints
c906108c 4743Depending on your system, watchpoints may be implemented in software or
2df3850c 4744hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
4745program and testing the variable's value each time, which is hundreds of
4746times slower than normal execution. (But this may still be worth it, to
4747catch errors where you have no clue what part of your program is the
4748culprit.)
4749
b1236ac3
PA
4750On some systems, such as most PowerPC or x86-based targets,
4751@value{GDBN} includes support for hardware watchpoints, which do not
4752slow down the running of your program.
c906108c
SS
4753
4754@table @code
4755@kindex watch
5d5658a1 4756@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
fd60e0df
EZ
4757Set a watchpoint for an expression. @value{GDBN} will break when the
4758expression @var{expr} is written into by the program and its value
4759changes. The simplest (and the most popular) use of this command is
4760to watch the value of a single variable:
4761
4762@smallexample
4763(@value{GDBP}) watch foo
4764@end smallexample
c906108c 4765
5d5658a1 4766If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
9c06b0b4 4767argument, @value{GDBN} breaks only when the thread identified by
5d5658a1 4768@var{thread-id} changes the value of @var{expr}. If any other threads
d8b2a693
JB
4769change the value of @var{expr}, @value{GDBN} will not break. Note
4770that watchpoints restricted to a single thread in this way only work
4771with Hardware Watchpoints.
4772
06a64a0b
TT
4773Ordinarily a watchpoint respects the scope of variables in @var{expr}
4774(see below). The @code{-location} argument tells @value{GDBN} to
4775instead watch the memory referred to by @var{expr}. In this case,
4776@value{GDBN} will evaluate @var{expr}, take the address of the result,
4777and watch the memory at that address. The type of the result is used
4778to determine the size of the watched memory. If the expression's
4779result does not have an address, then @value{GDBN} will print an
4780error.
4781
9c06b0b4
TJB
4782The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4783of masked watchpoints, if the current architecture supports this
4784feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4785Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4786to an address to watch. The mask specifies that some bits of an address
4787(the bits which are reset in the mask) should be ignored when matching
4788the address accessed by the inferior against the watchpoint address.
4789Thus, a masked watchpoint watches many addresses simultaneously---those
4790addresses whose unmasked bits are identical to the unmasked bits in the
4791watchpoint address. The @code{mask} argument implies @code{-location}.
4792Examples:
4793
4794@smallexample
4795(@value{GDBP}) watch foo mask 0xffff00ff
4796(@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4797@end smallexample
4798
c906108c 4799@kindex rwatch
5d5658a1 4800@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4801Set a watchpoint that will break when the value of @var{expr} is read
4802by the program.
c906108c
SS
4803
4804@kindex awatch
5d5658a1 4805@item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4806Set a watchpoint that will break when @var{expr} is either read from
4807or written into by the program.
c906108c 4808
18da0c51
MG
4809@kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4810@item info watchpoints @r{[}@var{list}@dots{}@r{]}
d77f58be
SS
4811This command prints a list of watchpoints, using the same format as
4812@code{info break} (@pxref{Set Breaks}).
c906108c
SS
4813@end table
4814
65d79d4b
SDJ
4815If you watch for a change in a numerically entered address you need to
4816dereference it, as the address itself is just a constant number which will
4817never change. @value{GDBN} refuses to create a watchpoint that watches
4818a never-changing value:
4819
4820@smallexample
4821(@value{GDBP}) watch 0x600850
4822Cannot watch constant value 0x600850.
4823(@value{GDBP}) watch *(int *) 0x600850
4824Watchpoint 1: *(int *) 6293584
4825@end smallexample
4826
c906108c
SS
4827@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4828watchpoints execute very quickly, and the debugger reports a change in
4829value at the exact instruction where the change occurs. If @value{GDBN}
4830cannot set a hardware watchpoint, it sets a software watchpoint, which
4831executes more slowly and reports the change in value at the next
82f2d802
EZ
4832@emph{statement}, not the instruction, after the change occurs.
4833
82f2d802
EZ
4834@cindex use only software watchpoints
4835You can force @value{GDBN} to use only software watchpoints with the
4836@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4837zero, @value{GDBN} will never try to use hardware watchpoints, even if
4838the underlying system supports them. (Note that hardware-assisted
4839watchpoints that were set @emph{before} setting
4840@code{can-use-hw-watchpoints} to zero will still use the hardware
d3e8051b 4841mechanism of watching expression values.)
c906108c 4842
9c16f35a
EZ
4843@table @code
4844@item set can-use-hw-watchpoints
4845@kindex set can-use-hw-watchpoints
4846Set whether or not to use hardware watchpoints.
4847
4848@item show can-use-hw-watchpoints
4849@kindex show can-use-hw-watchpoints
4850Show the current mode of using hardware watchpoints.
4851@end table
4852
4853For remote targets, you can restrict the number of hardware
4854watchpoints @value{GDBN} will use, see @ref{set remote
4855hardware-breakpoint-limit}.
4856
c906108c
SS
4857When you issue the @code{watch} command, @value{GDBN} reports
4858
474c8240 4859@smallexample
c906108c 4860Hardware watchpoint @var{num}: @var{expr}
474c8240 4861@end smallexample
c906108c
SS
4862
4863@noindent
4864if it was able to set a hardware watchpoint.
4865
7be570e7
JM
4866Currently, the @code{awatch} and @code{rwatch} commands can only set
4867hardware watchpoints, because accesses to data that don't change the
4868value of the watched expression cannot be detected without examining
4869every instruction as it is being executed, and @value{GDBN} does not do
4870that currently. If @value{GDBN} finds that it is unable to set a
4871hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4872will print a message like this:
4873
4874@smallexample
4875Expression cannot be implemented with read/access watchpoint.
4876@end smallexample
4877
4878Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4879data type of the watched expression is wider than what a hardware
4880watchpoint on the target machine can handle. For example, some systems
4881can only watch regions that are up to 4 bytes wide; on such systems you
4882cannot set hardware watchpoints for an expression that yields a
4883double-precision floating-point number (which is typically 8 bytes
4884wide). As a work-around, it might be possible to break the large region
4885into a series of smaller ones and watch them with separate watchpoints.
4886
4887If you set too many hardware watchpoints, @value{GDBN} might be unable
4888to insert all of them when you resume the execution of your program.
4889Since the precise number of active watchpoints is unknown until such
4890time as the program is about to be resumed, @value{GDBN} might not be
4891able to warn you about this when you set the watchpoints, and the
4892warning will be printed only when the program is resumed:
4893
4894@smallexample
4895Hardware watchpoint @var{num}: Could not insert watchpoint
4896@end smallexample
4897
4898@noindent
4899If this happens, delete or disable some of the watchpoints.
4900
fd60e0df
EZ
4901Watching complex expressions that reference many variables can also
4902exhaust the resources available for hardware-assisted watchpoints.
4903That's because @value{GDBN} needs to watch every variable in the
4904expression with separately allocated resources.
4905
c906108c 4906If you call a function interactively using @code{print} or @code{call},
2df3850c 4907any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
4908kind of breakpoint or the call completes.
4909
7be570e7
JM
4910@value{GDBN} automatically deletes watchpoints that watch local
4911(automatic) variables, or expressions that involve such variables, when
4912they go out of scope, that is, when the execution leaves the block in
4913which these variables were defined. In particular, when the program
4914being debugged terminates, @emph{all} local variables go out of scope,
4915and so only watchpoints that watch global variables remain set. If you
4916rerun the program, you will need to set all such watchpoints again. One
4917way of doing that would be to set a code breakpoint at the entry to the
4918@code{main} function and when it breaks, set all the watchpoints.
4919
c906108c
SS
4920@cindex watchpoints and threads
4921@cindex threads and watchpoints
d983da9c
DJ
4922In multi-threaded programs, watchpoints will detect changes to the
4923watched expression from every thread.
4924
4925@quotation
4926@emph{Warning:} In multi-threaded programs, software watchpoints
53a5351d
JM
4927have only limited usefulness. If @value{GDBN} creates a software
4928watchpoint, it can only watch the value of an expression @emph{in a
4929single thread}. If you are confident that the expression can only
4930change due to the current thread's activity (and if you are also
4931confident that no other thread can become current), then you can use
4932software watchpoints as usual. However, @value{GDBN} may not notice
4933when a non-current thread's activity changes the expression. (Hardware
4934watchpoints, in contrast, watch an expression in all threads.)
c906108c 4935@end quotation
c906108c 4936
501eef12
AC
4937@xref{set remote hardware-watchpoint-limit}.
4938
6d2ebf8b 4939@node Set Catchpoints
79a6e687 4940@subsection Setting Catchpoints
d4f3574e 4941@cindex catchpoints, setting
c906108c
SS
4942@cindex exception handlers
4943@cindex event handling
4944
4945You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 4946kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
4947shared library. Use the @code{catch} command to set a catchpoint.
4948
4949@table @code
4950@kindex catch
4951@item catch @var{event}
697aa1b7 4952Stop when @var{event} occurs. The @var{event} can be any of the following:
591f19e8 4953
c906108c 4954@table @code
cc16e6c9
TT
4955@item throw @r{[}@var{regexp}@r{]}
4956@itemx rethrow @r{[}@var{regexp}@r{]}
4957@itemx catch @r{[}@var{regexp}@r{]}
1a4f73eb
TT
4958@kindex catch throw
4959@kindex catch rethrow
4960@kindex catch catch
4644b6e3 4961@cindex stop on C@t{++} exceptions
591f19e8
TT
4962The throwing, re-throwing, or catching of a C@t{++} exception.
4963
cc16e6c9
TT
4964If @var{regexp} is given, then only exceptions whose type matches the
4965regular expression will be caught.
4966
72f1fe8a
TT
4967@vindex $_exception@r{, convenience variable}
4968The convenience variable @code{$_exception} is available at an
4969exception-related catchpoint, on some systems. This holds the
4970exception being thrown.
4971
591f19e8
TT
4972There are currently some limitations to C@t{++} exception handling in
4973@value{GDBN}:
c906108c 4974
591f19e8
TT
4975@itemize @bullet
4976@item
4977The support for these commands is system-dependent. Currently, only
4978systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
4979supported.
4980
72f1fe8a 4981@item
cc16e6c9
TT
4982The regular expression feature and the @code{$_exception} convenience
4983variable rely on the presence of some SDT probes in @code{libstdc++}.
4984If these probes are not present, then these features cannot be used.
dee368d3
TT
4985These probes were first available in the GCC 4.8 release, but whether
4986or not they are available in your GCC also depends on how it was
4987built.
72f1fe8a
TT
4988
4989@item
4990The @code{$_exception} convenience variable is only valid at the
4991instruction at which an exception-related catchpoint is set.
4992
591f19e8
TT
4993@item
4994When an exception-related catchpoint is hit, @value{GDBN} stops at a
4995location in the system library which implements runtime exception
4996support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
4997(@pxref{Selection}) to get to your code.
4998
4999@item
5000If you call a function interactively, @value{GDBN} normally returns
5001control to you when the function has finished executing. If the call
5002raises an exception, however, the call may bypass the mechanism that
5003returns control to you and cause your program either to abort or to
5004simply continue running until it hits a breakpoint, catches a signal
5005that @value{GDBN} is listening for, or exits. This is the case even if
5006you set a catchpoint for the exception; catchpoints on exceptions are
5007disabled within interactive calls. @xref{Calling}, for information on
5008controlling this with @code{set unwind-on-terminating-exception}.
5009
5010@item
5011You cannot raise an exception interactively.
5012
5013@item
5014You cannot install an exception handler interactively.
5015@end itemize
c906108c 5016
b8e07335 5017@item exception @r{[}@var{name}@r{]}
1a4f73eb 5018@kindex catch exception
8936fcda
JB
5019@cindex Ada exception catching
5020@cindex catch Ada exceptions
5021An Ada exception being raised. If an exception name is specified
5022at the end of the command (eg @code{catch exception Program_Error}),
5023the debugger will stop only when this specific exception is raised.
5024Otherwise, the debugger stops execution when any Ada exception is raised.
5025
87f67dba
JB
5026When inserting an exception catchpoint on a user-defined exception whose
5027name is identical to one of the exceptions defined by the language, the
5028fully qualified name must be used as the exception name. Otherwise,
5029@value{GDBN} will assume that it should stop on the pre-defined exception
5030rather than the user-defined one. For instance, assuming an exception
5031called @code{Constraint_Error} is defined in package @code{Pck}, then
5032the command to use to catch such exceptions is @kbd{catch exception
5033Pck.Constraint_Error}.
5034
37f6a7f4
TT
5035@vindex $_ada_exception@r{, convenience variable}
5036The convenience variable @code{$_ada_exception} holds the address of
5037the exception being thrown. This can be useful when setting a
5038condition for such a catchpoint.
5039
b8e07335
TT
5040@item exception unhandled
5041@kindex catch exception unhandled
37f6a7f4
TT
5042An exception that was raised but is not handled by the program. The
5043convenience variable @code{$_ada_exception} is set as for @code{catch
5044exception}.
b8e07335
TT
5045
5046@item handlers @r{[}@var{name}@r{]}
9f757bf7
XR
5047@kindex catch handlers
5048@cindex Ada exception handlers catching
5049@cindex catch Ada exceptions when handled
5050An Ada exception being handled. If an exception name is
5051specified at the end of the command
5052 (eg @kbd{catch handlers Program_Error}), the debugger will stop
5053only when this specific exception is handled.
5054Otherwise, the debugger stops execution when any Ada exception is handled.
5055
5056When inserting a handlers catchpoint on a user-defined
5057exception whose name is identical to one of the exceptions
5058defined by the language, the fully qualified name must be used
5059as the exception name. Otherwise, @value{GDBN} will assume that it
5060should stop on the pre-defined exception rather than the
5061user-defined one. For instance, assuming an exception called
5062 @code{Constraint_Error} is defined in package @code{Pck}, then the
5063command to use to catch such exceptions handling is
5064@kbd{catch handlers Pck.Constraint_Error}.
5065
37f6a7f4
TT
5066The convenience variable @code{$_ada_exception} is set as for
5067@code{catch exception}.
5068
8936fcda 5069@item assert
1a4f73eb 5070@kindex catch assert
37f6a7f4
TT
5071A failed Ada assertion. Note that the convenience variable
5072@code{$_ada_exception} is @emph{not} set by this catchpoint.
8936fcda 5073
c906108c 5074@item exec
1a4f73eb 5075@kindex catch exec
4644b6e3 5076@cindex break on fork/exec
b1236ac3 5077A call to @code{exec}.
c906108c 5078
e9076973 5079@anchor{catch syscall}
a96d9b2e 5080@item syscall
e3487908 5081@itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
1a4f73eb 5082@kindex catch syscall
a96d9b2e
SDJ
5083@cindex break on a system call.
5084A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
5085syscall is a mechanism for application programs to request a service
5086from the operating system (OS) or one of the OS system services.
5087@value{GDBN} can catch some or all of the syscalls issued by the
5088debuggee, and show the related information for each syscall. If no
5089argument is specified, calls to and returns from all system calls
5090will be caught.
5091
5092@var{name} can be any system call name that is valid for the
5093underlying OS. Just what syscalls are valid depends on the OS. On
5094GNU and Unix systems, you can find the full list of valid syscall
5095names on @file{/usr/include/asm/unistd.h}.
5096
5097@c For MS-Windows, the syscall names and the corresponding numbers
5098@c can be found, e.g., on this URL:
5099@c http://www.metasploit.com/users/opcode/syscalls.html
5100@c but we don't support Windows syscalls yet.
5101
5102Normally, @value{GDBN} knows in advance which syscalls are valid for
5103each OS, so you can use the @value{GDBN} command-line completion
5104facilities (@pxref{Completion,, command completion}) to list the
5105available choices.
5106
5107You may also specify the system call numerically. A syscall's
5108number is the value passed to the OS's syscall dispatcher to
5109identify the requested service. When you specify the syscall by its
5110name, @value{GDBN} uses its database of syscalls to convert the name
5111into the corresponding numeric code, but using the number directly
5112may be useful if @value{GDBN}'s database does not have the complete
5113list of syscalls on your system (e.g., because @value{GDBN} lags
5114behind the OS upgrades).
5115
e3487908
GKB
5116You may specify a group of related syscalls to be caught at once using
5117the @code{group:} syntax (@code{g:} is a shorter equivalent). For
5118instance, on some platforms @value{GDBN} allows you to catch all
5119network related syscalls, by passing the argument @code{group:network}
5120to @code{catch syscall}. Note that not all syscall groups are
5121available in every system. You can use the command completion
5122facilities (@pxref{Completion,, command completion}) to list the
5123syscall groups available on your environment.
5124
a96d9b2e
SDJ
5125The example below illustrates how this command works if you don't provide
5126arguments to it:
5127
5128@smallexample
5129(@value{GDBP}) catch syscall
5130Catchpoint 1 (syscall)
5131(@value{GDBP}) r
5132Starting program: /tmp/catch-syscall
5133
5134Catchpoint 1 (call to syscall 'close'), \
5135 0xffffe424 in __kernel_vsyscall ()
5136(@value{GDBP}) c
5137Continuing.
5138
5139Catchpoint 1 (returned from syscall 'close'), \
5140 0xffffe424 in __kernel_vsyscall ()
5141(@value{GDBP})
5142@end smallexample
5143
5144Here is an example of catching a system call by name:
5145
5146@smallexample
5147(@value{GDBP}) catch syscall chroot
5148Catchpoint 1 (syscall 'chroot' [61])
5149(@value{GDBP}) r
5150Starting program: /tmp/catch-syscall
5151
5152Catchpoint 1 (call to syscall 'chroot'), \
5153 0xffffe424 in __kernel_vsyscall ()
5154(@value{GDBP}) c
5155Continuing.
5156
5157Catchpoint 1 (returned from syscall 'chroot'), \
5158 0xffffe424 in __kernel_vsyscall ()
5159(@value{GDBP})
5160@end smallexample
5161
5162An example of specifying a system call numerically. In the case
5163below, the syscall number has a corresponding entry in the XML
5164file, so @value{GDBN} finds its name and prints it:
5165
5166@smallexample
5167(@value{GDBP}) catch syscall 252
5168Catchpoint 1 (syscall(s) 'exit_group')
5169(@value{GDBP}) r
5170Starting program: /tmp/catch-syscall
5171
5172Catchpoint 1 (call to syscall 'exit_group'), \
5173 0xffffe424 in __kernel_vsyscall ()
5174(@value{GDBP}) c
5175Continuing.
5176
5177Program exited normally.
5178(@value{GDBP})
5179@end smallexample
5180
e3487908
GKB
5181Here is an example of catching a syscall group:
5182
5183@smallexample
5184(@value{GDBP}) catch syscall group:process
5185Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
5186'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
5187'exit_group' [252] 'waitid' [284] 'unshare' [310])
5188(@value{GDBP}) r
5189Starting program: /tmp/catch-syscall
5190
5191Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
5192 from /lib64/ld-linux-x86-64.so.2
5193
5194(@value{GDBP}) c
5195Continuing.
5196@end smallexample
5197
a96d9b2e
SDJ
5198However, there can be situations when there is no corresponding name
5199in XML file for that syscall number. In this case, @value{GDBN} prints
5200a warning message saying that it was not able to find the syscall name,
5201but the catchpoint will be set anyway. See the example below:
5202
5203@smallexample
5204(@value{GDBP}) catch syscall 764
5205warning: The number '764' does not represent a known syscall.
5206Catchpoint 2 (syscall 764)
5207(@value{GDBP})
5208@end smallexample
5209
5210If you configure @value{GDBN} using the @samp{--without-expat} option,
5211it will not be able to display syscall names. Also, if your
5212architecture does not have an XML file describing its system calls,
5213you will not be able to see the syscall names. It is important to
5214notice that these two features are used for accessing the syscall
5215name database. In either case, you will see a warning like this:
5216
5217@smallexample
5218(@value{GDBP}) catch syscall
5219warning: Could not open "syscalls/i386-linux.xml"
5220warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
5221GDB will not be able to display syscall names.
5222Catchpoint 1 (syscall)
5223(@value{GDBP})
5224@end smallexample
5225
5226Of course, the file name will change depending on your architecture and system.
5227
5228Still using the example above, you can also try to catch a syscall by its
5229number. In this case, you would see something like:
5230
5231@smallexample
5232(@value{GDBP}) catch syscall 252
5233Catchpoint 1 (syscall(s) 252)
5234@end smallexample
5235
5236Again, in this case @value{GDBN} would not be able to display syscall's names.
5237
c906108c 5238@item fork
1a4f73eb 5239@kindex catch fork
b1236ac3 5240A call to @code{fork}.
c906108c
SS
5241
5242@item vfork
1a4f73eb 5243@kindex catch vfork
b1236ac3 5244A call to @code{vfork}.
c906108c 5245
b8e07335
TT
5246@item load @r{[}@var{regexp}@r{]}
5247@itemx unload @r{[}@var{regexp}@r{]}
1a4f73eb
TT
5248@kindex catch load
5249@kindex catch unload
edcc5120
TT
5250The loading or unloading of a shared library. If @var{regexp} is
5251given, then the catchpoint will stop only if the regular expression
5252matches one of the affected libraries.
5253
ab04a2af 5254@item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
1a4f73eb 5255@kindex catch signal
ab04a2af
TT
5256The delivery of a signal.
5257
5258With no arguments, this catchpoint will catch any signal that is not
5259used internally by @value{GDBN}, specifically, all signals except
5260@samp{SIGTRAP} and @samp{SIGINT}.
5261
5262With the argument @samp{all}, all signals, including those used by
5263@value{GDBN}, will be caught. This argument cannot be used with other
5264signal names.
5265
5266Otherwise, the arguments are a list of signal names as given to
5267@code{handle} (@pxref{Signals}). Only signals specified in this list
5268will be caught.
5269
5270One reason that @code{catch signal} can be more useful than
5271@code{handle} is that you can attach commands and conditions to the
5272catchpoint.
5273
5274When a signal is caught by a catchpoint, the signal's @code{stop} and
5275@code{print} settings, as specified by @code{handle}, are ignored.
5276However, whether the signal is still delivered to the inferior depends
5277on the @code{pass} setting; this can be changed in the catchpoint's
5278commands.
5279
c906108c
SS
5280@end table
5281
5282@item tcatch @var{event}
1a4f73eb 5283@kindex tcatch
c906108c
SS
5284Set a catchpoint that is enabled only for one stop. The catchpoint is
5285automatically deleted after the first time the event is caught.
5286
5287@end table
5288
5289Use the @code{info break} command to list the current catchpoints.
5290
c906108c 5291
6d2ebf8b 5292@node Delete Breaks
79a6e687 5293@subsection Deleting Breakpoints
c906108c
SS
5294
5295@cindex clearing breakpoints, watchpoints, catchpoints
5296@cindex deleting breakpoints, watchpoints, catchpoints
5297It is often necessary to eliminate a breakpoint, watchpoint, or
5298catchpoint once it has done its job and you no longer want your program
5299to stop there. This is called @dfn{deleting} the breakpoint. A
5300breakpoint that has been deleted no longer exists; it is forgotten.
5301
5302With the @code{clear} command you can delete breakpoints according to
5303where they are in your program. With the @code{delete} command you can
5304delete individual breakpoints, watchpoints, or catchpoints by specifying
5305their breakpoint numbers.
5306
5307It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
5308automatically ignores breakpoints on the first instruction to be executed
5309when you continue execution without changing the execution address.
5310
5311@table @code
5312@kindex clear
5313@item clear
5314Delete any breakpoints at the next instruction to be executed in the
79a6e687 5315selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
c906108c
SS
5316the innermost frame is selected, this is a good way to delete a
5317breakpoint where your program just stopped.
5318
2a25a5ba
EZ
5319@item clear @var{location}
5320Delete any breakpoints set at the specified @var{location}.
5321@xref{Specify Location}, for the various forms of @var{location}; the
5322most useful ones are listed below:
5323
5324@table @code
c906108c
SS
5325@item clear @var{function}
5326@itemx clear @var{filename}:@var{function}
09d4efe1 5327Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
5328
5329@item clear @var{linenum}
5330@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
5331Delete any breakpoints set at or within the code of the specified
5332@var{linenum} of the specified @var{filename}.
2a25a5ba 5333@end table
c906108c
SS
5334
5335@cindex delete breakpoints
5336@kindex delete
41afff9a 5337@kindex d @r{(@code{delete})}
18da0c51 5338@item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c5394b80 5339Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
18da0c51 5340list specified as argument. If no argument is specified, delete all
c906108c
SS
5341breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
5342confirm off}). You can abbreviate this command as @code{d}.
5343@end table
5344
6d2ebf8b 5345@node Disabling
79a6e687 5346@subsection Disabling Breakpoints
c906108c 5347
4644b6e3 5348@cindex enable/disable a breakpoint
c906108c
SS
5349Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
5350prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
5351it had been deleted, but remembers the information on the breakpoint so
5352that you can @dfn{enable} it again later.
5353
5354You disable and enable breakpoints, watchpoints, and catchpoints with
d77f58be
SS
5355the @code{enable} and @code{disable} commands, optionally specifying
5356one or more breakpoint numbers as arguments. Use @code{info break} to
5357print a list of all breakpoints, watchpoints, and catchpoints if you
5358do not know which numbers to use.
c906108c 5359
3b784c4f
EZ
5360Disabling and enabling a breakpoint that has multiple locations
5361affects all of its locations.
5362
816338b5
SS
5363A breakpoint, watchpoint, or catchpoint can have any of several
5364different states of enablement:
c906108c
SS
5365
5366@itemize @bullet
5367@item
5368Enabled. The breakpoint stops your program. A breakpoint set
5369with the @code{break} command starts out in this state.
5370@item
5371Disabled. The breakpoint has no effect on your program.
5372@item
5373Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 5374disabled.
c906108c 5375@item
816338b5
SS
5376Enabled for a count. The breakpoint stops your program for the next
5377N times, then becomes disabled.
5378@item
c906108c 5379Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
5380immediately after it does so it is deleted permanently. A breakpoint
5381set with the @code{tbreak} command starts out in this state.
c906108c
SS
5382@end itemize
5383
5384You can use the following commands to enable or disable breakpoints,
5385watchpoints, and catchpoints:
5386
5387@table @code
c906108c 5388@kindex disable
41afff9a 5389@kindex dis @r{(@code{disable})}
18da0c51 5390@item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5391Disable the specified breakpoints---or all breakpoints, if none are
5392listed. A disabled breakpoint has no effect but is not forgotten. All
5393options such as ignore-counts, conditions and commands are remembered in
5394case the breakpoint is enabled again later. You may abbreviate
5395@code{disable} as @code{dis}.
5396
c906108c 5397@kindex enable
18da0c51 5398@item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5399Enable the specified breakpoints (or all defined breakpoints). They
5400become effective once again in stopping your program.
5401
18da0c51 5402@item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
c906108c
SS
5403Enable the specified breakpoints temporarily. @value{GDBN} disables any
5404of these breakpoints immediately after stopping your program.
5405
18da0c51 5406@item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
816338b5
SS
5407Enable the specified breakpoints temporarily. @value{GDBN} records
5408@var{count} with each of the specified breakpoints, and decrements a
5409breakpoint's count when it is hit. When any count reaches 0,
5410@value{GDBN} disables that breakpoint. If a breakpoint has an ignore
5411count (@pxref{Conditions, ,Break Conditions}), that will be
5412decremented to 0 before @var{count} is affected.
5413
18da0c51 5414@item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
c906108c
SS
5415Enable the specified breakpoints to work once, then die. @value{GDBN}
5416deletes any of these breakpoints as soon as your program stops there.
09d4efe1 5417Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
5418@end table
5419
d4f3574e
SS
5420@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5421@c confusing: tbreak is also initially enabled.
c906108c 5422Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
79a6e687 5423,Setting Breakpoints}), breakpoints that you set are initially enabled;
c906108c
SS
5424subsequently, they become disabled or enabled only when you use one of
5425the commands above. (The command @code{until} can set and delete a
5426breakpoint of its own, but it does not change the state of your other
5427breakpoints; see @ref{Continuing and Stepping, ,Continuing and
79a6e687 5428Stepping}.)
c906108c 5429
6d2ebf8b 5430@node Conditions
79a6e687 5431@subsection Break Conditions
c906108c
SS
5432@cindex conditional breakpoints
5433@cindex breakpoint conditions
5434
5435@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 5436@c in particular for a watchpoint?
c906108c
SS
5437The simplest sort of breakpoint breaks every time your program reaches a
5438specified place. You can also specify a @dfn{condition} for a
5439breakpoint. A condition is just a Boolean expression in your
5440programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
5441a condition evaluates the expression each time your program reaches it,
5442and your program stops only if the condition is @emph{true}.
5443
5444This is the converse of using assertions for program validation; in that
5445situation, you want to stop when the assertion is violated---that is,
5446when the condition is false. In C, if you want to test an assertion expressed
5447by the condition @var{assert}, you should set the condition
5448@samp{! @var{assert}} on the appropriate breakpoint.
5449
5450Conditions are also accepted for watchpoints; you may not need them,
5451since a watchpoint is inspecting the value of an expression anyhow---but
5452it might be simpler, say, to just set a watchpoint on a variable name,
5453and specify a condition that tests whether the new value is an interesting
5454one.
5455
5456Break conditions can have side effects, and may even call functions in
5457your program. This can be useful, for example, to activate functions
5458that log program progress, or to use your own print functions to
99e008fe 5459format special data structures. The effects are completely predictable
c906108c
SS
5460unless there is another enabled breakpoint at the same address. (In
5461that case, @value{GDBN} might see the other breakpoint first and stop your
5462program without checking the condition of this one.) Note that
d4f3574e
SS
5463breakpoint commands are usually more convenient and flexible than break
5464conditions for the
c906108c 5465purpose of performing side effects when a breakpoint is reached
79a6e687 5466(@pxref{Break Commands, ,Breakpoint Command Lists}).
c906108c 5467
83364271
LM
5468Breakpoint conditions can also be evaluated on the target's side if
5469the target supports it. Instead of evaluating the conditions locally,
5470@value{GDBN} encodes the expression into an agent expression
5471(@pxref{Agent Expressions}) suitable for execution on the target,
5472independently of @value{GDBN}. Global variables become raw memory
5473locations, locals become stack accesses, and so forth.
5474
5475In this case, @value{GDBN} will only be notified of a breakpoint trigger
5476when its condition evaluates to true. This mechanism may provide faster
5477response times depending on the performance characteristics of the target
5478since it does not need to keep @value{GDBN} informed about
5479every breakpoint trigger, even those with false conditions.
5480
c906108c
SS
5481Break conditions can be specified when a breakpoint is set, by using
5482@samp{if} in the arguments to the @code{break} command. @xref{Set
79a6e687 5483Breaks, ,Setting Breakpoints}. They can also be changed at any time
c906108c 5484with the @code{condition} command.
53a5351d 5485
c906108c
SS
5486You can also use the @code{if} keyword with the @code{watch} command.
5487The @code{catch} command does not recognize the @code{if} keyword;
5488@code{condition} is the only way to impose a further condition on a
5489catchpoint.
c906108c
SS
5490
5491@table @code
5492@kindex condition
5493@item condition @var{bnum} @var{expression}
5494Specify @var{expression} as the break condition for breakpoint,
5495watchpoint, or catchpoint number @var{bnum}. After you set a condition,
5496breakpoint @var{bnum} stops your program only if the value of
5497@var{expression} is true (nonzero, in C). When you use
5498@code{condition}, @value{GDBN} checks @var{expression} immediately for
5499syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
5500referents in the context of your breakpoint. If @var{expression} uses
5501symbols not referenced in the context of the breakpoint, @value{GDBN}
5502prints an error message:
5503
474c8240 5504@smallexample
d4f3574e 5505No symbol "foo" in current context.
474c8240 5506@end smallexample
d4f3574e
SS
5507
5508@noindent
c906108c
SS
5509@value{GDBN} does
5510not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
5511command (or a command that sets a breakpoint with a condition, like
5512@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c 5513
733d554a
TBA
5514@item condition -force @var{bnum} @var{expression}
5515When the @code{-force} flag is used, define the condition even if
5516@var{expression} is invalid at all the current locations of breakpoint
5517@var{bnum}. This is similar to the @code{-force-condition} option
5518of the @code{break} command.
5519
c906108c
SS
5520@item condition @var{bnum}
5521Remove the condition from breakpoint number @var{bnum}. It becomes
5522an ordinary unconditional breakpoint.
5523@end table
5524
5525@cindex ignore count (of breakpoint)
5526A special case of a breakpoint condition is to stop only when the
5527breakpoint has been reached a certain number of times. This is so
5528useful that there is a special way to do it, using the @dfn{ignore
5529count} of the breakpoint. Every breakpoint has an ignore count, which
5530is an integer. Most of the time, the ignore count is zero, and
5531therefore has no effect. But if your program reaches a breakpoint whose
5532ignore count is positive, then instead of stopping, it just decrements
5533the ignore count by one and continues. As a result, if the ignore count
5534value is @var{n}, the breakpoint does not stop the next @var{n} times
5535your program reaches it.
5536
5537@table @code
5538@kindex ignore
5539@item ignore @var{bnum} @var{count}
5540Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5541The next @var{count} times the breakpoint is reached, your program's
5542execution does not stop; other than to decrement the ignore count, @value{GDBN}
5543takes no action.
5544
5545To make the breakpoint stop the next time it is reached, specify
5546a count of zero.
5547
5548When you use @code{continue} to resume execution of your program from a
5549breakpoint, you can specify an ignore count directly as an argument to
5550@code{continue}, rather than using @code{ignore}. @xref{Continuing and
79a6e687 5551Stepping,,Continuing and Stepping}.
c906108c
SS
5552
5553If a breakpoint has a positive ignore count and a condition, the
5554condition is not checked. Once the ignore count reaches zero,
5555@value{GDBN} resumes checking the condition.
5556
5557You could achieve the effect of the ignore count with a condition such
5558as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5559is decremented each time. @xref{Convenience Vars, ,Convenience
79a6e687 5560Variables}.
c906108c
SS
5561@end table
5562
5563Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5564
5565
6d2ebf8b 5566@node Break Commands
79a6e687 5567@subsection Breakpoint Command Lists
c906108c
SS
5568
5569@cindex breakpoint commands
5570You can give any breakpoint (or watchpoint or catchpoint) a series of
5571commands to execute when your program stops due to that breakpoint. For
5572example, you might want to print the values of certain expressions, or
5573enable other breakpoints.
5574
5575@table @code
5576@kindex commands
ca91424e 5577@kindex end@r{ (breakpoint commands)}
18da0c51 5578@item commands @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5579@itemx @dots{} @var{command-list} @dots{}
5580@itemx end
95a42b64 5581Specify a list of commands for the given breakpoints. The commands
c906108c
SS
5582themselves appear on the following lines. Type a line containing just
5583@code{end} to terminate the commands.
5584
5585To remove all commands from a breakpoint, type @code{commands} and
5586follow it immediately with @code{end}; that is, give no commands.
5587
95a42b64
TT
5588With no argument, @code{commands} refers to the last breakpoint,
5589watchpoint, or catchpoint set (not to the breakpoint most recently
5590encountered). If the most recent breakpoints were set with a single
5591command, then the @code{commands} will apply to all the breakpoints
5592set by that command. This applies to breakpoints set by
86b17b60
PA
5593@code{rbreak}, and also applies when a single @code{break} command
5594creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5595Expressions}).
c906108c
SS
5596@end table
5597
5598Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5599disabled within a @var{command-list}.
5600
5601You can use breakpoint commands to start your program up again. Simply
5602use the @code{continue} command, or @code{step}, or any other command
5603that resumes execution.
5604
5605Any other commands in the command list, after a command that resumes
5606execution, are ignored. This is because any time you resume execution
5607(even with a simple @code{next} or @code{step}), you may encounter
5608another breakpoint---which could have its own command list, leading to
5609ambiguities about which list to execute.
5610
5611@kindex silent
5612If the first command you specify in a command list is @code{silent}, the
5613usual message about stopping at a breakpoint is not printed. This may
5614be desirable for breakpoints that are to print a specific message and
5615then continue. If none of the remaining commands print anything, you
5616see no sign that the breakpoint was reached. @code{silent} is
5617meaningful only at the beginning of a breakpoint command list.
5618
5619The commands @code{echo}, @code{output}, and @code{printf} allow you to
5620print precisely controlled output, and are often useful in silent
79a6e687 5621breakpoints. @xref{Output, ,Commands for Controlled Output}.
c906108c
SS
5622
5623For example, here is how you could use breakpoint commands to print the
5624value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5625
474c8240 5626@smallexample
c906108c
SS
5627break foo if x>0
5628commands
5629silent
5630printf "x is %d\n",x
5631cont
5632end
474c8240 5633@end smallexample
c906108c
SS
5634
5635One application for breakpoint commands is to compensate for one bug so
5636you can test for another. Put a breakpoint just after the erroneous line
5637of code, give it a condition to detect the case in which something
5638erroneous has been done, and give it commands to assign correct values
5639to any variables that need them. End with the @code{continue} command
5640so that your program does not stop, and start with the @code{silent}
5641command so that no output is produced. Here is an example:
5642
474c8240 5643@smallexample
c906108c
SS
5644break 403
5645commands
5646silent
5647set x = y + 4
5648cont
5649end
474c8240 5650@end smallexample
c906108c 5651
e7e0cddf
SS
5652@node Dynamic Printf
5653@subsection Dynamic Printf
5654
5655@cindex dynamic printf
5656@cindex dprintf
5657The dynamic printf command @code{dprintf} combines a breakpoint with
5658formatted printing of your program's data to give you the effect of
5659inserting @code{printf} calls into your program on-the-fly, without
5660having to recompile it.
5661
5662In its most basic form, the output goes to the GDB console. However,
5663you can set the variable @code{dprintf-style} for alternate handling.
5664For instance, you can ask to format the output by calling your
5665program's @code{printf} function. This has the advantage that the
5666characters go to the program's output device, so they can recorded in
5667redirects to files and so forth.
5668
d3ce09f5
SS
5669If you are doing remote debugging with a stub or agent, you can also
5670ask to have the printf handled by the remote agent. In addition to
5671ensuring that the output goes to the remote program's device along
5672with any other output the program might produce, you can also ask that
5673the dprintf remain active even after disconnecting from the remote
5674target. Using the stub/agent is also more efficient, as it can do
5675everything without needing to communicate with @value{GDBN}.
5676
e7e0cddf
SS
5677@table @code
5678@kindex dprintf
5679@item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
5680Whenever execution reaches @var{location}, print the values of one or
5681more @var{expressions} under the control of the string @var{template}.
5682To print several values, separate them with commas.
5683
5684@item set dprintf-style @var{style}
5685Set the dprintf output to be handled in one of several different
5686styles enumerated below. A change of style affects all existing
5687dynamic printfs immediately. (If you need individual control over the
5688print commands, simply define normal breakpoints with
5689explicitly-supplied command lists.)
5690
18da0c51 5691@table @code
e7e0cddf
SS
5692@item gdb
5693@kindex dprintf-style gdb
5694Handle the output using the @value{GDBN} @code{printf} command.
5695
5696@item call
5697@kindex dprintf-style call
5698Handle the output by calling a function in your program (normally
5699@code{printf}).
5700
d3ce09f5
SS
5701@item agent
5702@kindex dprintf-style agent
5703Have the remote debugging agent (such as @code{gdbserver}) handle
5704the output itself. This style is only available for agents that
5705support running commands on the target.
18da0c51 5706@end table
d3ce09f5 5707
e7e0cddf
SS
5708@item set dprintf-function @var{function}
5709Set the function to call if the dprintf style is @code{call}. By
5710default its value is @code{printf}. You may set it to any expression.
5711that @value{GDBN} can evaluate to a function, as per the @code{call}
5712command.
5713
5714@item set dprintf-channel @var{channel}
5715Set a ``channel'' for dprintf. If set to a non-empty value,
5716@value{GDBN} will evaluate it as an expression and pass the result as
5717a first argument to the @code{dprintf-function}, in the manner of
5718@code{fprintf} and similar functions. Otherwise, the dprintf format
5719string will be the first argument, in the manner of @code{printf}.
5720
5721As an example, if you wanted @code{dprintf} output to go to a logfile
5722that is a standard I/O stream assigned to the variable @code{mylog},
5723you could do the following:
5724
5725@example
5726(gdb) set dprintf-style call
5727(gdb) set dprintf-function fprintf
5728(gdb) set dprintf-channel mylog
5729(gdb) dprintf 25,"at line 25, glob=%d\n",glob
5730Dprintf 1 at 0x123456: file main.c, line 25.
5731(gdb) info break
57321 dprintf keep y 0x00123456 in main at main.c:25
5733 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5734 continue
5735(gdb)
5736@end example
5737
5738Note that the @code{info break} displays the dynamic printf commands
5739as normal breakpoint commands; you can thus easily see the effect of
5740the variable settings.
5741
d3ce09f5
SS
5742@item set disconnected-dprintf on
5743@itemx set disconnected-dprintf off
5744@kindex set disconnected-dprintf
5745Choose whether @code{dprintf} commands should continue to run if
5746@value{GDBN} has disconnected from the target. This only applies
5747if the @code{dprintf-style} is @code{agent}.
5748
5749@item show disconnected-dprintf off
5750@kindex show disconnected-dprintf
5751Show the current choice for disconnected @code{dprintf}.
5752
e7e0cddf
SS
5753@end table
5754
5755@value{GDBN} does not check the validity of function and channel,
5756relying on you to supply values that are meaningful for the contexts
5757in which they are being used. For instance, the function and channel
5758may be the values of local variables, but if that is the case, then
5759all enabled dynamic prints must be at locations within the scope of
5760those locals. If evaluation fails, @value{GDBN} will report an error.
5761
6149aea9
PA
5762@node Save Breakpoints
5763@subsection How to save breakpoints to a file
5764
5765To save breakpoint definitions to a file use the @w{@code{save
5766breakpoints}} command.
5767
5768@table @code
5769@kindex save breakpoints
5770@cindex save breakpoints to a file for future sessions
5771@item save breakpoints [@var{filename}]
5772This command saves all current breakpoint definitions together with
5773their commands and ignore counts, into a file @file{@var{filename}}
5774suitable for use in a later debugging session. This includes all
5775types of breakpoints (breakpoints, watchpoints, catchpoints,
5776tracepoints). To read the saved breakpoint definitions, use the
5777@code{source} command (@pxref{Command Files}). Note that watchpoints
5778with expressions involving local variables may fail to be recreated
5779because it may not be possible to access the context where the
5780watchpoint is valid anymore. Because the saved breakpoint definitions
5781are simply a sequence of @value{GDBN} commands that recreate the
5782breakpoints, you can edit the file in your favorite editing program,
5783and remove the breakpoint definitions you're not interested in, or
5784that can no longer be recreated.
5785@end table
5786
62e5f89c
SDJ
5787@node Static Probe Points
5788@subsection Static Probe Points
5789
5790@cindex static probe point, SystemTap
3133f8c1 5791@cindex static probe point, DTrace
62e5f89c
SDJ
5792@value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5793for Statically Defined Tracing, and the probes are designed to have a tiny
3133f8c1
JM
5794runtime code and data footprint, and no dynamic relocations.
5795
5796Currently, the following types of probes are supported on
5797ELF-compatible systems:
5798
5799@itemize @bullet
62e5f89c 5800
3133f8c1
JM
5801@item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5802@acronym{SDT} probes@footnote{See
62e5f89c 5803@uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
3133f8c1
JM
5804for more information on how to add @code{SystemTap} @acronym{SDT}
5805probes in your applications.}. @code{SystemTap} probes are usable
5806from assembly, C and C@t{++} languages@footnote{See
5807@uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5808for a good reference on how the @acronym{SDT} probes are implemented.}.
5809
5810@item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5811@acronym{USDT} probes. @code{DTrace} probes are usable from C and
5812C@t{++} languages.
5813@end itemize
62e5f89c
SDJ
5814
5815@cindex semaphores on static probe points
3133f8c1
JM
5816Some @code{SystemTap} probes have an associated semaphore variable;
5817for instance, this happens automatically if you defined your probe
5818using a DTrace-style @file{.d} file. If your probe has a semaphore,
5819@value{GDBN} will automatically enable it when you specify a
5820breakpoint using the @samp{-probe-stap} notation. But, if you put a
5821breakpoint at a probe's location by some other method (e.g.,
5822@code{break file:line}), then @value{GDBN} will not automatically set
5823the semaphore. @code{DTrace} probes do not support semaphores.
62e5f89c
SDJ
5824
5825You can examine the available static static probes using @code{info
5826probes}, with optional arguments:
5827
5828@table @code
5829@kindex info probes
3133f8c1
JM
5830@item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5831If given, @var{type} is either @code{stap} for listing
5832@code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5833probes. If omitted all probes are listed regardless of their types.
5834
62e5f89c
SDJ
5835If given, @var{provider} is a regular expression used to match against provider
5836names when selecting which probes to list. If omitted, probes by all
5837probes from all providers are listed.
5838
5839If given, @var{name} is a regular expression to match against probe names
5840when selecting which probes to list. If omitted, probe names are not
5841considered when deciding whether to display them.
5842
5843If given, @var{objfile} is a regular expression used to select which
5844object files (executable or shared libraries) to examine. If not
5845given, all object files are considered.
5846
5847@item info probes all
5848List the available static probes, from all types.
5849@end table
5850
9aca2ff8
JM
5851@cindex enabling and disabling probes
5852Some probe points can be enabled and/or disabled. The effect of
5853enabling or disabling a probe depends on the type of probe being
3133f8c1
JM
5854handled. Some @code{DTrace} probes can be enabled or
5855disabled, but @code{SystemTap} probes cannot be disabled.
9aca2ff8
JM
5856
5857You can enable (or disable) one or more probes using the following
5858commands, with optional arguments:
5859
5860@table @code
5861@kindex enable probes
5862@item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5863If given, @var{provider} is a regular expression used to match against
5864provider names when selecting which probes to enable. If omitted,
5865all probes from all providers are enabled.
5866
5867If given, @var{name} is a regular expression to match against probe
5868names when selecting which probes to enable. If omitted, probe names
5869are not considered when deciding whether to enable them.
5870
5871If given, @var{objfile} is a regular expression used to select which
5872object files (executable or shared libraries) to examine. If not
5873given, all object files are considered.
5874
5875@kindex disable probes
5876@item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5877See the @code{enable probes} command above for a description of the
5878optional arguments accepted by this command.
5879@end table
5880
62e5f89c
SDJ
5881@vindex $_probe_arg@r{, convenience variable}
5882A probe may specify up to twelve arguments. These are available at the
5883point at which the probe is defined---that is, when the current PC is
5884at the probe's location. The arguments are available using the
5885convenience variables (@pxref{Convenience Vars})
3133f8c1
JM
5886@code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
5887probes each probe argument is an integer of the appropriate size;
5888types are not preserved. In @code{DTrace} probes types are preserved
5889provided that they are recognized as such by @value{GDBN}; otherwise
5890the value of the probe argument will be a long integer. The
62e5f89c
SDJ
5891convenience variable @code{$_probe_argc} holds the number of arguments
5892at the current probe point.
5893
5894These variables are always available, but attempts to access them at
5895any location other than a probe point will cause @value{GDBN} to give
5896an error message.
5897
5898
c906108c 5899@c @ifclear BARETARGET
6d2ebf8b 5900@node Error in Breakpoints
d4f3574e 5901@subsection ``Cannot insert breakpoints''
c906108c 5902
fa3a767f
PA
5903If you request too many active hardware-assisted breakpoints and
5904watchpoints, you will see this error message:
d4f3574e
SS
5905
5906@c FIXME: the precise wording of this message may change; the relevant
5907@c source change is not committed yet (Sep 3, 1999).
5908@smallexample
5909Stopped; cannot insert breakpoints.
5910You may have requested too many hardware breakpoints and watchpoints.
5911@end smallexample
5912
5913@noindent
5914This message is printed when you attempt to resume the program, since
5915only then @value{GDBN} knows exactly how many hardware breakpoints and
5916watchpoints it needs to insert.
5917
5918When this message is printed, you need to disable or remove some of the
5919hardware-assisted breakpoints and watchpoints, and then continue.
5920
79a6e687 5921@node Breakpoint-related Warnings
1485d690
KB
5922@subsection ``Breakpoint address adjusted...''
5923@cindex breakpoint address adjusted
5924
5925Some processor architectures place constraints on the addresses at
5926which breakpoints may be placed. For architectures thus constrained,
5927@value{GDBN} will attempt to adjust the breakpoint's address to comply
5928with the constraints dictated by the architecture.
5929
5930One example of such an architecture is the Fujitsu FR-V. The FR-V is
5931a VLIW architecture in which a number of RISC-like instructions may be
5932bundled together for parallel execution. The FR-V architecture
5933constrains the location of a breakpoint instruction within such a
5934bundle to the instruction with the lowest address. @value{GDBN}
5935honors this constraint by adjusting a breakpoint's address to the
5936first in the bundle.
5937
5938It is not uncommon for optimized code to have bundles which contain
5939instructions from different source statements, thus it may happen that
5940a breakpoint's address will be adjusted from one source statement to
5941another. Since this adjustment may significantly alter @value{GDBN}'s
5942breakpoint related behavior from what the user expects, a warning is
5943printed when the breakpoint is first set and also when the breakpoint
5944is hit.
5945
5946A warning like the one below is printed when setting a breakpoint
5947that's been subject to address adjustment:
5948
5949@smallexample
5950warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
5951@end smallexample
5952
5953Such warnings are printed both for user settable and @value{GDBN}'s
5954internal breakpoints. If you see one of these warnings, you should
5955verify that a breakpoint set at the adjusted address will have the
5956desired affect. If not, the breakpoint in question may be removed and
b383017d 5957other breakpoints may be set which will have the desired behavior.
1485d690
KB
5958E.g., it may be sufficient to place the breakpoint at a later
5959instruction. A conditional breakpoint may also be useful in some
5960cases to prevent the breakpoint from triggering too often.
5961
5962@value{GDBN} will also issue a warning when stopping at one of these
5963adjusted breakpoints:
5964
5965@smallexample
5966warning: Breakpoint 1 address previously adjusted from 0x00010414
5967to 0x00010410.
5968@end smallexample
5969
5970When this warning is encountered, it may be too late to take remedial
5971action except in cases where the breakpoint is hit earlier or more
5972frequently than expected.
d4f3574e 5973
6d2ebf8b 5974@node Continuing and Stepping
79a6e687 5975@section Continuing and Stepping
c906108c
SS
5976
5977@cindex stepping
5978@cindex continuing
5979@cindex resuming execution
5980@dfn{Continuing} means resuming program execution until your program
5981completes normally. In contrast, @dfn{stepping} means executing just
5982one more ``step'' of your program, where ``step'' may mean either one
5983line of source code, or one machine instruction (depending on what
7a292a7a
SS
5984particular command you use). Either when continuing or when stepping,
5985your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e 5986it stops due to a signal, you may want to use @code{handle}, or use
e5f8a7cc
PA
5987@samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
5988or you may step into the signal's handler (@pxref{stepping and signal
5989handlers}).)
c906108c
SS
5990
5991@table @code
5992@kindex continue
41afff9a
EZ
5993@kindex c @r{(@code{continue})}
5994@kindex fg @r{(resume foreground execution)}
c906108c
SS
5995@item continue @r{[}@var{ignore-count}@r{]}
5996@itemx c @r{[}@var{ignore-count}@r{]}
5997@itemx fg @r{[}@var{ignore-count}@r{]}
5998Resume program execution, at the address where your program last stopped;
5999any breakpoints set at that address are bypassed. The optional argument
6000@var{ignore-count} allows you to specify a further number of times to
6001ignore a breakpoint at this location; its effect is like that of
79a6e687 6002@code{ignore} (@pxref{Conditions, ,Break Conditions}).
c906108c
SS
6003
6004The argument @var{ignore-count} is meaningful only when your program
6005stopped due to a breakpoint. At other times, the argument to
6006@code{continue} is ignored.
6007
d4f3574e
SS
6008The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
6009debugged program is deemed to be the foreground program) are provided
6010purely for convenience, and have exactly the same behavior as
6011@code{continue}.
c906108c
SS
6012@end table
6013
6014To resume execution at a different place, you can use @code{return}
79a6e687 6015(@pxref{Returning, ,Returning from a Function}) to go back to the
c906108c 6016calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
79a6e687 6017Different Address}) to go to an arbitrary location in your program.
c906108c
SS
6018
6019A typical technique for using stepping is to set a breakpoint
79a6e687 6020(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
c906108c
SS
6021beginning of the function or the section of your program where a problem
6022is believed to lie, run your program until it stops at that breakpoint,
6023and then step through the suspect area, examining the variables that are
6024interesting, until you see the problem happen.
6025
6026@table @code
6027@kindex step
41afff9a 6028@kindex s @r{(@code{step})}
c906108c
SS
6029@item step
6030Continue running your program until control reaches a different source
6031line, then stop it and return control to @value{GDBN}. This command is
6032abbreviated @code{s}.
6033
6034@quotation
6035@c "without debugging information" is imprecise; actually "without line
6036@c numbers in the debugging information". (gcc -g1 has debugging info but
6037@c not line numbers). But it seems complex to try to make that
6038@c distinction here.
6039@emph{Warning:} If you use the @code{step} command while control is
6040within a function that was compiled without debugging information,
6041execution proceeds until control reaches a function that does have
6042debugging information. Likewise, it will not step into a function which
6043is compiled without debugging information. To step through functions
6044without debugging information, use the @code{stepi} command, described
6045below.
6046@end quotation
6047
4a92d011
EZ
6048The @code{step} command only stops at the first instruction of a source
6049line. This prevents the multiple stops that could otherwise occur in
6050@code{switch} statements, @code{for} loops, etc. @code{step} continues
6051to stop if a function that has debugging information is called within
6052the line. In other words, @code{step} @emph{steps inside} any functions
6053called within the line.
c906108c 6054
d4f3574e
SS
6055Also, the @code{step} command only enters a function if there is line
6056number information for the function. Otherwise it acts like the
5d161b24 6057@code{next} command. This avoids problems when using @code{cc -gl}
eb17f351 6058on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5d161b24 6059was any debugging information about the routine.
c906108c
SS
6060
6061@item step @var{count}
6062Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
6063breakpoint is reached, or a signal not related to stepping occurs before
6064@var{count} steps, stepping stops right away.
c906108c
SS
6065
6066@kindex next
41afff9a 6067@kindex n @r{(@code{next})}
c906108c
SS
6068@item next @r{[}@var{count}@r{]}
6069Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
6070This is similar to @code{step}, but function calls that appear within
6071the line of code are executed without stopping. Execution stops when
6072control reaches a different line of code at the original stack level
6073that was executing when you gave the @code{next} command. This command
6074is abbreviated @code{n}.
c906108c
SS
6075
6076An argument @var{count} is a repeat count, as for @code{step}.
6077
6078
6079@c FIX ME!! Do we delete this, or is there a way it fits in with
6080@c the following paragraph? --- Vctoria
6081@c
6082@c @code{next} within a function that lacks debugging information acts like
6083@c @code{step}, but any function calls appearing within the code of the
6084@c function are executed without stopping.
6085
d4f3574e
SS
6086The @code{next} command only stops at the first instruction of a
6087source line. This prevents multiple stops that could otherwise occur in
4a92d011 6088@code{switch} statements, @code{for} loops, etc.
c906108c 6089
b90a5f51
CF
6090@kindex set step-mode
6091@item set step-mode
6092@cindex functions without line info, and stepping
6093@cindex stepping into functions with no line info
6094@itemx set step-mode on
4a92d011 6095The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
6096stop at the first instruction of a function which contains no debug line
6097information rather than stepping over it.
6098
4a92d011
EZ
6099This is useful in cases where you may be interested in inspecting the
6100machine instructions of a function which has no symbolic info and do not
6101want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
6102
6103@item set step-mode off
4a92d011 6104Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
6105debug information. This is the default.
6106
9c16f35a
EZ
6107@item show step-mode
6108Show whether @value{GDBN} will stop in or step over functions without
6109source line debug information.
6110
c906108c 6111@kindex finish
8dfa32fc 6112@kindex fin @r{(@code{finish})}
c906108c
SS
6113@item finish
6114Continue running until just after function in the selected stack frame
8dfa32fc
JB
6115returns. Print the returned value (if any). This command can be
6116abbreviated as @code{fin}.
c906108c
SS
6117
6118Contrast this with the @code{return} command (@pxref{Returning,
79a6e687 6119,Returning from a Function}).
c906108c 6120
000439d5
TT
6121@kindex set print finish
6122@kindex show print finish
6123@item set print finish @r{[}on|off@r{]}
6124@itemx show print finish
6125By default the @code{finish} command will show the value that is
6126returned by the function. This can be disabled using @code{set print
6127finish off}. When disabled, the value is still entered into the value
6128history (@pxref{Value History}), but not displayed.
6129
c906108c 6130@kindex until
41afff9a 6131@kindex u @r{(@code{until})}
09d4efe1 6132@cindex run until specified location
c906108c
SS
6133@item until
6134@itemx u
6135Continue running until a source line past the current line, in the
6136current stack frame, is reached. This command is used to avoid single
6137stepping through a loop more than once. It is like the @code{next}
6138command, except that when @code{until} encounters a jump, it
6139automatically continues execution until the program counter is greater
6140than the address of the jump.
6141
6142This means that when you reach the end of a loop after single stepping
6143though it, @code{until} makes your program continue execution until it
6144exits the loop. In contrast, a @code{next} command at the end of a loop
6145simply steps back to the beginning of the loop, which forces you to step
6146through the next iteration.
6147
6148@code{until} always stops your program if it attempts to exit the current
6149stack frame.
6150
6151@code{until} may produce somewhat counterintuitive results if the order
6152of machine code does not match the order of the source lines. For
6153example, in the following excerpt from a debugging session, the @code{f}
6154(@code{frame}) command shows that execution is stopped at line
6155@code{206}; yet when we use @code{until}, we get to line @code{195}:
6156
474c8240 6157@smallexample
c906108c
SS
6158(@value{GDBP}) f
6159#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
6160206 expand_input();
6161(@value{GDBP}) until
6162195 for ( ; argc > 0; NEXTARG) @{
474c8240 6163@end smallexample
c906108c
SS
6164
6165This happened because, for execution efficiency, the compiler had
6166generated code for the loop closure test at the end, rather than the
6167start, of the loop---even though the test in a C @code{for}-loop is
6168written before the body of the loop. The @code{until} command appeared
6169to step back to the beginning of the loop when it advanced to this
6170expression; however, it has not really gone to an earlier
6171statement---not in terms of the actual machine code.
6172
6173@code{until} with no argument works by means of single
6174instruction stepping, and hence is slower than @code{until} with an
6175argument.
6176
6177@item until @var{location}
6178@itemx u @var{location}
697aa1b7
EZ
6179Continue running your program until either the specified @var{location} is
6180reached, or the current stack frame returns. The location is any of
2a25a5ba
EZ
6181the forms described in @ref{Specify Location}.
6182This form of the command uses temporary breakpoints, and
c60eb6f1
EZ
6183hence is quicker than @code{until} without an argument. The specified
6184location is actually reached only if it is in the current frame. This
6185implies that @code{until} can be used to skip over recursive function
6186invocations. For instance in the code below, if the current location is
6187line @code{96}, issuing @code{until 99} will execute the program up to
db2e3e2e 6188line @code{99} in the same invocation of factorial, i.e., after the inner
c60eb6f1
EZ
6189invocations have returned.
6190
6191@smallexample
619294 int factorial (int value)
619395 @{
619496 if (value > 1) @{
619597 value *= factorial (value - 1);
619698 @}
619799 return (value);
6198100 @}
6199@end smallexample
6200
6201
6202@kindex advance @var{location}
984359d2 6203@item advance @var{location}
09d4efe1 6204Continue running the program up to the given @var{location}. An argument is
2a25a5ba
EZ
6205required, which should be of one of the forms described in
6206@ref{Specify Location}.
6207Execution will also stop upon exit from the current stack
c60eb6f1
EZ
6208frame. This command is similar to @code{until}, but @code{advance} will
6209not skip over recursive function calls, and the target location doesn't
6210have to be in the same frame as the current one.
6211
c906108c
SS
6212
6213@kindex stepi
41afff9a 6214@kindex si @r{(@code{stepi})}
c906108c 6215@item stepi
96a2c332 6216@itemx stepi @var{arg}
c906108c
SS
6217@itemx si
6218Execute one machine instruction, then stop and return to the debugger.
6219
6220It is often useful to do @samp{display/i $pc} when stepping by machine
6221instructions. This makes @value{GDBN} automatically display the next
6222instruction to be executed, each time your program stops. @xref{Auto
79a6e687 6223Display,, Automatic Display}.
c906108c
SS
6224
6225An argument is a repeat count, as in @code{step}.
6226
6227@need 750
6228@kindex nexti
41afff9a 6229@kindex ni @r{(@code{nexti})}
c906108c 6230@item nexti
96a2c332 6231@itemx nexti @var{arg}
c906108c
SS
6232@itemx ni
6233Execute one machine instruction, but if it is a function call,
6234proceed until the function returns.
6235
6236An argument is a repeat count, as in @code{next}.
c1e36e3e
PA
6237
6238@end table
6239
6240@anchor{range stepping}
6241@cindex range stepping
6242@cindex target-assisted range stepping
6243By default, and if available, @value{GDBN} makes use of
6244target-assisted @dfn{range stepping}. In other words, whenever you
6245use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
6246tells the target to step the corresponding range of instruction
6247addresses instead of issuing multiple single-steps. This speeds up
6248line stepping, particularly for remote targets. Ideally, there should
6249be no reason you would want to turn range stepping off. However, it's
6250possible that a bug in the debug info, a bug in the remote stub (for
6251remote targets), or even a bug in @value{GDBN} could make line
6252stepping behave incorrectly when target-assisted range stepping is
6253enabled. You can use the following command to turn off range stepping
6254if necessary:
6255
6256@table @code
6257@kindex set range-stepping
6258@kindex show range-stepping
6259@item set range-stepping
6260@itemx show range-stepping
6261Control whether range stepping is enabled.
6262
6263If @code{on}, and the target supports it, @value{GDBN} tells the
6264target to step a range of addresses itself, instead of issuing
6265multiple single-steps. If @code{off}, @value{GDBN} always issues
6266single-steps, even if range stepping is supported by the target. The
6267default is @code{on}.
6268
c906108c
SS
6269@end table
6270
aad1c02c
TT
6271@node Skipping Over Functions and Files
6272@section Skipping Over Functions and Files
1bfeeb0f
JL
6273@cindex skipping over functions and files
6274
6275The program you are debugging may contain some functions which are
8244c20d 6276uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
cce0e923
DE
6277skip a function, all functions in a file or a particular function in
6278a particular file when stepping.
1bfeeb0f
JL
6279
6280For example, consider the following C function:
6281
6282@smallexample
6283101 int func()
6284102 @{
6285103 foo(boring());
6286104 bar(boring());
6287105 @}
6288@end smallexample
6289
6290@noindent
6291Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
6292are not interested in stepping through @code{boring}. If you run @code{step}
6293at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
6294step over both @code{foo} and @code{boring}!
6295
6296One solution is to @code{step} into @code{boring} and use the @code{finish}
6297command to immediately exit it. But this can become tedious if @code{boring}
6298is called from many places.
6299
6300A more flexible solution is to execute @kbd{skip boring}. This instructs
6301@value{GDBN} never to step into @code{boring}. Now when you execute
6302@code{step} at line 103, you'll step over @code{boring} and directly into
6303@code{foo}.
6304
cce0e923
DE
6305Functions may be skipped by providing either a function name, linespec
6306(@pxref{Specify Location}), regular expression that matches the function's
6307name, file name or a @code{glob}-style pattern that matches the file name.
6308
6309On Posix systems the form of the regular expression is
6310``Extended Regular Expressions''. See for example @samp{man 7 regex}
6311on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
6312expression is whatever is provided by the @code{regcomp} function of
6313the underlying system.
6314See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
6315description of @code{glob}-style patterns.
6316
6317@table @code
6318@kindex skip
6319@item skip @r{[}@var{options}@r{]}
6320The basic form of the @code{skip} command takes zero or more options
6321that specify what to skip.
6322The @var{options} argument is any useful combination of the following:
1bfeeb0f
JL
6323
6324@table @code
cce0e923
DE
6325@item -file @var{file}
6326@itemx -fi @var{file}
6327Functions in @var{file} will be skipped over when stepping.
6328
6329@item -gfile @var{file-glob-pattern}
6330@itemx -gfi @var{file-glob-pattern}
6331@cindex skipping over files via glob-style patterns
6332Functions in files matching @var{file-glob-pattern} will be skipped
6333over when stepping.
6334
6335@smallexample
6336(gdb) skip -gfi utils/*.c
6337@end smallexample
6338
6339@item -function @var{linespec}
6340@itemx -fu @var{linespec}
6341Functions named by @var{linespec} or the function containing the line
6342named by @var{linespec} will be skipped over when stepping.
6343@xref{Specify Location}.
6344
6345@item -rfunction @var{regexp}
6346@itemx -rfu @var{regexp}
6347@cindex skipping over functions via regular expressions
6348Functions whose name matches @var{regexp} will be skipped over when stepping.
6349
6350This form is useful for complex function names.
6351For example, there is generally no need to step into C@t{++} @code{std::string}
6352constructors or destructors. Plus with C@t{++} templates it can be hard to
6353write out the full name of the function, and often it doesn't matter what
6354the template arguments are. Specifying the function to be skipped as a
6355regular expression makes this easier.
6356
6357@smallexample
6358(gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
6359@end smallexample
6360
6361If you want to skip every templated C@t{++} constructor and destructor
6362in the @code{std} namespace you can do:
6363
6364@smallexample
6365(gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
6366@end smallexample
6367@end table
6368
6369If no options are specified, the function you're currently debugging
6370will be skipped.
6371
1bfeeb0f 6372@kindex skip function
cce0e923 6373@item skip function @r{[}@var{linespec}@r{]}
1bfeeb0f
JL
6374After running this command, the function named by @var{linespec} or the
6375function containing the line named by @var{linespec} will be skipped over when
983fb131 6376stepping. @xref{Specify Location}.
1bfeeb0f
JL
6377
6378If you do not specify @var{linespec}, the function you're currently debugging
6379will be skipped.
6380
6381(If you have a function called @code{file} that you want to skip, use
6382@kbd{skip function file}.)
6383
6384@kindex skip file
6385@item skip file @r{[}@var{filename}@r{]}
6386After running this command, any function whose source lives in @var{filename}
6387will be skipped over when stepping.
6388
cce0e923
DE
6389@smallexample
6390(gdb) skip file boring.c
6391File boring.c will be skipped when stepping.
6392@end smallexample
6393
1bfeeb0f
JL
6394If you do not specify @var{filename}, functions whose source lives in the file
6395you're currently debugging will be skipped.
6396@end table
6397
6398Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
6399These are the commands for managing your list of skips:
6400
6401@table @code
6402@kindex info skip
6403@item info skip @r{[}@var{range}@r{]}
6404Print details about the specified skip(s). If @var{range} is not specified,
6405print a table with details about all functions and files marked for skipping.
6406@code{info skip} prints the following information about each skip:
6407
6408@table @emph
6409@item Identifier
6410A number identifying this skip.
1bfeeb0f 6411@item Enabled or Disabled
cce0e923
DE
6412Enabled skips are marked with @samp{y}.
6413Disabled skips are marked with @samp{n}.
6414@item Glob
6415If the file name is a @samp{glob} pattern this is @samp{y}.
6416Otherwise it is @samp{n}.
6417@item File
6418The name or @samp{glob} pattern of the file to be skipped.
6419If no file is specified this is @samp{<none>}.
6420@item RE
6421If the function name is a @samp{regular expression} this is @samp{y}.
6422Otherwise it is @samp{n}.
6423@item Function
6424The name or regular expression of the function to skip.
6425If no function is specified this is @samp{<none>}.
1bfeeb0f
JL
6426@end table
6427
6428@kindex skip delete
6429@item skip delete @r{[}@var{range}@r{]}
6430Delete the specified skip(s). If @var{range} is not specified, delete all
6431skips.
6432
6433@kindex skip enable
6434@item skip enable @r{[}@var{range}@r{]}
6435Enable the specified skip(s). If @var{range} is not specified, enable all
6436skips.
6437
6438@kindex skip disable
6439@item skip disable @r{[}@var{range}@r{]}
6440Disable the specified skip(s). If @var{range} is not specified, disable all
6441skips.
6442
3e68067f
SM
6443@kindex set debug skip
6444@item set debug skip @r{[}on|off@r{]}
6445Set whether to print the debug output about skipping files and functions.
6446
6447@kindex show debug skip
6448@item show debug skip
6449Show whether the debug output about skipping files and functions is printed.
6450
1bfeeb0f
JL
6451@end table
6452
6d2ebf8b 6453@node Signals
c906108c
SS
6454@section Signals
6455@cindex signals
6456
6457A signal is an asynchronous event that can happen in a program. The
6458operating system defines the possible kinds of signals, and gives each
6459kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 6460signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
6461@code{SIGSEGV} is the signal a program gets from referencing a place in
6462memory far away from all the areas in use; @code{SIGALRM} occurs when
6463the alarm clock timer goes off (which happens only if your program has
6464requested an alarm).
6465
6466@cindex fatal signals
6467Some signals, including @code{SIGALRM}, are a normal part of the
6468functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 6469errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
6470program has not specified in advance some other way to handle the signal.
6471@code{SIGINT} does not indicate an error in your program, but it is normally
6472fatal so it can carry out the purpose of the interrupt: to kill the program.
6473
6474@value{GDBN} has the ability to detect any occurrence of a signal in your
6475program. You can tell @value{GDBN} in advance what to do for each kind of
6476signal.
6477
6478@cindex handling signals
24f93129
EZ
6479Normally, @value{GDBN} is set up to let the non-erroneous signals like
6480@code{SIGALRM} be silently passed to your program
6481(so as not to interfere with their role in the program's functioning)
c906108c
SS
6482but to stop your program immediately whenever an error signal happens.
6483You can change these settings with the @code{handle} command.
6484
6485@table @code
6486@kindex info signals
09d4efe1 6487@kindex info handle
c906108c 6488@item info signals
96a2c332 6489@itemx info handle
c906108c
SS
6490Print a table of all the kinds of signals and how @value{GDBN} has been told to
6491handle each one. You can use this to see the signal numbers of all
6492the defined types of signals.
6493
45ac1734
EZ
6494@item info signals @var{sig}
6495Similar, but print information only about the specified signal number.
6496
d4f3574e 6497@code{info handle} is an alias for @code{info signals}.
c906108c 6498
ab04a2af
TT
6499@item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6500Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
6501for details about this command.
6502
c906108c 6503@kindex handle
45ac1734 6504@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
697aa1b7 6505Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
5ece1a18 6506can be the number of a signal or its name (with or without the
24f93129 6507@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 6508@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
6509known signals. Optional arguments @var{keywords}, described below,
6510say what change to make.
c906108c
SS
6511@end table
6512
6513@c @group
6514The keywords allowed by the @code{handle} command can be abbreviated.
6515Their full names are:
6516
6517@table @code
6518@item nostop
6519@value{GDBN} should not stop your program when this signal happens. It may
6520still print a message telling you that the signal has come in.
6521
6522@item stop
6523@value{GDBN} should stop your program when this signal happens. This implies
6524the @code{print} keyword as well.
6525
6526@item print
6527@value{GDBN} should print a message when this signal happens.
6528
6529@item noprint
6530@value{GDBN} should not mention the occurrence of the signal at all. This
6531implies the @code{nostop} keyword as well.
6532
6533@item pass
5ece1a18 6534@itemx noignore
c906108c
SS
6535@value{GDBN} should allow your program to see this signal; your program
6536can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 6537and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
6538
6539@item nopass
5ece1a18 6540@itemx ignore
c906108c 6541@value{GDBN} should not allow your program to see this signal.
5ece1a18 6542@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
6543@end table
6544@c @end group
6545
d4f3574e
SS
6546When a signal stops your program, the signal is not visible to the
6547program until you
c906108c
SS
6548continue. Your program sees the signal then, if @code{pass} is in
6549effect for the signal in question @emph{at that time}. In other words,
6550after @value{GDBN} reports a signal, you can use the @code{handle}
6551command with @code{pass} or @code{nopass} to control whether your
6552program sees that signal when you continue.
6553
24f93129
EZ
6554The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6555non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6556@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6557erroneous signals.
6558
c906108c
SS
6559You can also use the @code{signal} command to prevent your program from
6560seeing a signal, or cause it to see a signal it normally would not see,
6561or to give it any signal at any time. For example, if your program stopped
6562due to some sort of memory reference error, you might store correct
6563values into the erroneous variables and continue, hoping to see more
6564execution; but your program would probably terminate immediately as
6565a result of the fatal signal once it saw the signal. To prevent this,
6566you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
79a6e687 6567Program a Signal}.
c906108c 6568
e5f8a7cc
PA
6569@cindex stepping and signal handlers
6570@anchor{stepping and signal handlers}
6571
6572@value{GDBN} optimizes for stepping the mainline code. If a signal
6573that has @code{handle nostop} and @code{handle pass} set arrives while
6574a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6575in progress, @value{GDBN} lets the signal handler run and then resumes
6576stepping the mainline code once the signal handler returns. In other
6577words, @value{GDBN} steps over the signal handler. This prevents
6578signals that you've specified as not interesting (with @code{handle
6579nostop}) from changing the focus of debugging unexpectedly. Note that
6580the signal handler itself may still hit a breakpoint, stop for another
6581signal that has @code{handle stop} in effect, or for any other event
6582that normally results in stopping the stepping command sooner. Also
6583note that @value{GDBN} still informs you that the program received a
6584signal if @code{handle print} is set.
6585
6586@anchor{stepping into signal handlers}
6587
6588If you set @code{handle pass} for a signal, and your program sets up a
6589handler for it, then issuing a stepping command, such as @code{step}
6590or @code{stepi}, when your program is stopped due to the signal will
6591step @emph{into} the signal handler (if the target supports that).
6592
6593Likewise, if you use the @code{queue-signal} command to queue a signal
6594to be delivered to the current thread when execution of the thread
6595resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6596stepping command will step into the signal handler.
6597
6598Here's an example, using @code{stepi} to step to the first instruction
6599of @code{SIGUSR1}'s handler:
6600
6601@smallexample
6602(@value{GDBP}) handle SIGUSR1
6603Signal Stop Print Pass to program Description
6604SIGUSR1 Yes Yes Yes User defined signal 1
6605(@value{GDBP}) c
6606Continuing.
6607
6608Program received signal SIGUSR1, User defined signal 1.
6609main () sigusr1.c:28
661028 p = 0;
6611(@value{GDBP}) si
6612sigusr1_handler () at sigusr1.c:9
66139 @{
6614@end smallexample
6615
6616The same, but using @code{queue-signal} instead of waiting for the
6617program to receive the signal first:
6618
6619@smallexample
6620(@value{GDBP}) n
662128 p = 0;
6622(@value{GDBP}) queue-signal SIGUSR1
6623(@value{GDBP}) si
6624sigusr1_handler () at sigusr1.c:9
66259 @{
6626(@value{GDBP})
6627@end smallexample
6628
4aa995e1
PA
6629@cindex extra signal information
6630@anchor{extra signal information}
6631
6632On some targets, @value{GDBN} can inspect extra signal information
6633associated with the intercepted signal, before it is actually
6634delivered to the program being debugged. This information is exported
6635by the convenience variable @code{$_siginfo}, and consists of data
6636that is passed by the kernel to the signal handler at the time of the
6637receipt of a signal. The data type of the information itself is
6638target dependent. You can see the data type using the @code{ptype
6639$_siginfo} command. On Unix systems, it typically corresponds to the
6640standard @code{siginfo_t} type, as defined in the @file{signal.h}
6641system header.
6642
6643Here's an example, on a @sc{gnu}/Linux system, printing the stray
6644referenced address that raised a segmentation fault.
6645
6646@smallexample
6647@group
6648(@value{GDBP}) continue
6649Program received signal SIGSEGV, Segmentation fault.
66500x0000000000400766 in main ()
665169 *(int *)p = 0;
6652(@value{GDBP}) ptype $_siginfo
6653type = struct @{
6654 int si_signo;
6655 int si_errno;
6656 int si_code;
6657 union @{
6658 int _pad[28];
6659 struct @{...@} _kill;
6660 struct @{...@} _timer;
6661 struct @{...@} _rt;
6662 struct @{...@} _sigchld;
6663 struct @{...@} _sigfault;
6664 struct @{...@} _sigpoll;
6665 @} _sifields;
6666@}
6667(@value{GDBP}) ptype $_siginfo._sifields._sigfault
6668type = struct @{
6669 void *si_addr;
6670@}
6671(@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6672$1 = (void *) 0x7ffff7ff7000
6673@end group
6674@end smallexample
6675
6676Depending on target support, @code{$_siginfo} may also be writable.
6677
012b3a21
WT
6678@cindex Intel MPX boundary violations
6679@cindex boundary violations, Intel MPX
6680On some targets, a @code{SIGSEGV} can be caused by a boundary
6681violation, i.e., accessing an address outside of the allowed range.
6682In those cases @value{GDBN} may displays additional information,
6683depending on how @value{GDBN} has been told to handle the signal.
6684With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6685kind: "Upper" or "Lower", the memory address accessed and the
6686bounds, while with @code{handle nostop SIGSEGV} no additional
6687information is displayed.
6688
6689The usual output of a segfault is:
6690@smallexample
6691Program received signal SIGSEGV, Segmentation fault
66920x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
669368 value = *(p + len);
6694@end smallexample
6695
6696While a bound violation is presented as:
6697@smallexample
6698Program received signal SIGSEGV, Segmentation fault
6699Upper bound violation while accessing address 0x7fffffffc3b3
6700Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
67010x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
670268 value = *(p + len);
6703@end smallexample
6704
6d2ebf8b 6705@node Thread Stops
79a6e687 6706@section Stopping and Starting Multi-thread Programs
c906108c 6707
0606b73b
SL
6708@cindex stopped threads
6709@cindex threads, stopped
6710
6711@cindex continuing threads
6712@cindex threads, continuing
6713
6714@value{GDBN} supports debugging programs with multiple threads
6715(@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6716are two modes of controlling execution of your program within the
6717debugger. In the default mode, referred to as @dfn{all-stop mode},
6718when any thread in your program stops (for example, at a breakpoint
6719or while being stepped), all other threads in the program are also stopped by
6720@value{GDBN}. On some targets, @value{GDBN} also supports
6721@dfn{non-stop mode}, in which other threads can continue to run freely while
6722you examine the stopped thread in the debugger.
6723
6724@menu
6725* All-Stop Mode:: All threads stop when GDB takes control
6726* Non-Stop Mode:: Other threads continue to execute
6727* Background Execution:: Running your program asynchronously
6728* Thread-Specific Breakpoints:: Controlling breakpoints
6729* Interrupted System Calls:: GDB may interfere with system calls
d914c394 6730* Observer Mode:: GDB does not alter program behavior
0606b73b
SL
6731@end menu
6732
6733@node All-Stop Mode
6734@subsection All-Stop Mode
6735
6736@cindex all-stop mode
6737
6738In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6739@emph{all} threads of execution stop, not just the current thread. This
6740allows you to examine the overall state of the program, including
6741switching between threads, without worrying that things may change
6742underfoot.
6743
6744Conversely, whenever you restart the program, @emph{all} threads start
6745executing. @emph{This is true even when single-stepping} with commands
6746like @code{step} or @code{next}.
6747
6748In particular, @value{GDBN} cannot single-step all threads in lockstep.
6749Since thread scheduling is up to your debugging target's operating
6750system (not controlled by @value{GDBN}), other threads may
6751execute more than one statement while the current thread completes a
6752single step. Moreover, in general other threads stop in the middle of a
6753statement, rather than at a clean statement boundary, when the program
6754stops.
6755
6756You might even find your program stopped in another thread after
6757continuing or even single-stepping. This happens whenever some other
6758thread runs into a breakpoint, a signal, or an exception before the
6759first thread completes whatever you requested.
6760
6761@cindex automatic thread selection
6762@cindex switching threads automatically
6763@cindex threads, automatic switching
6764Whenever @value{GDBN} stops your program, due to a breakpoint or a
6765signal, it automatically selects the thread where that breakpoint or
6766signal happened. @value{GDBN} alerts you to the context switch with a
6767message such as @samp{[Switching to Thread @var{n}]} to identify the
6768thread.
6769
6770On some OSes, you can modify @value{GDBN}'s default behavior by
6771locking the OS scheduler to allow only a single thread to run.
6772
6773@table @code
6774@item set scheduler-locking @var{mode}
6775@cindex scheduler locking mode
6776@cindex lock scheduler
f2665db5
MM
6777Set the scheduler locking mode. It applies to normal execution,
6778record mode, and replay mode. If it is @code{off}, then there is no
6779locking and any thread may run at any time. If @code{on}, then only
6780the current thread may run when the inferior is resumed. The
6781@code{step} mode optimizes for single-stepping; it prevents other
6782threads from preempting the current thread while you are stepping, so
6783that the focus of debugging does not change unexpectedly. Other
6784threads never get a chance to run when you step, and they are
6785completely free to run when you use commands like @samp{continue},
6786@samp{until}, or @samp{finish}. However, unless another thread hits a
6787breakpoint during its timeslice, @value{GDBN} does not change the
6788current thread away from the thread that you are debugging. The
6789@code{replay} mode behaves like @code{off} in record mode and like
6790@code{on} in replay mode.
0606b73b
SL
6791
6792@item show scheduler-locking
6793Display the current scheduler locking mode.
6794@end table
6795
d4db2f36
PA
6796@cindex resume threads of multiple processes simultaneously
6797By default, when you issue one of the execution commands such as
6798@code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6799threads of the current inferior to run. For example, if @value{GDBN}
6800is attached to two inferiors, each with two threads, the
6801@code{continue} command resumes only the two threads of the current
6802inferior. This is useful, for example, when you debug a program that
6803forks and you want to hold the parent stopped (so that, for instance,
6804it doesn't run to exit), while you debug the child. In other
6805situations, you may not be interested in inspecting the current state
6806of any of the processes @value{GDBN} is attached to, and you may want
6807to resume them all until some breakpoint is hit. In the latter case,
6808you can instruct @value{GDBN} to allow all threads of all the
6809inferiors to run with the @w{@code{set schedule-multiple}} command.
6810
6811@table @code
6812@kindex set schedule-multiple
6813@item set schedule-multiple
6814Set the mode for allowing threads of multiple processes to be resumed
6815when an execution command is issued. When @code{on}, all threads of
6816all processes are allowed to run. When @code{off}, only the threads
6817of the current process are resumed. The default is @code{off}. The
6818@code{scheduler-locking} mode takes precedence when set to @code{on},
6819or while you are stepping and set to @code{step}.
6820
6821@item show schedule-multiple
6822Display the current mode for resuming the execution of threads of
6823multiple processes.
6824@end table
6825
0606b73b
SL
6826@node Non-Stop Mode
6827@subsection Non-Stop Mode
6828
6829@cindex non-stop mode
6830
6831@c This section is really only a place-holder, and needs to be expanded
97d8f0ee 6832@c with more details.
0606b73b
SL
6833
6834For some multi-threaded targets, @value{GDBN} supports an optional
6835mode of operation in which you can examine stopped program threads in
6836the debugger while other threads continue to execute freely. This
97d8f0ee
DE
6837minimizes intrusion when debugging live systems, such as programs
6838where some threads have real-time constraints or must continue to
0606b73b
SL
6839respond to external events. This is referred to as @dfn{non-stop} mode.
6840
6841In non-stop mode, when a thread stops to report a debugging event,
6842@emph{only} that thread is stopped; @value{GDBN} does not stop other
6843threads as well, in contrast to the all-stop mode behavior. Additionally,
6844execution commands such as @code{continue} and @code{step} apply by default
6845only to the current thread in non-stop mode, rather than all threads as
6846in all-stop mode. This allows you to control threads explicitly in
97d8f0ee 6847ways that are not possible in all-stop mode --- for example, stepping
0606b73b 6848one thread while allowing others to run freely, stepping
97d8f0ee 6849one thread while holding all others stopped, or stepping several threads
0606b73b
SL
6850independently and simultaneously.
6851
6852To enter non-stop mode, use this sequence of commands before you run
6853or attach to your program:
6854
0606b73b 6855@smallexample
0606b73b
SL
6856# If using the CLI, pagination breaks non-stop.
6857set pagination off
6858
6859# Finally, turn it on!
6860set non-stop on
6861@end smallexample
6862
6863You can use these commands to manipulate the non-stop mode setting:
6864
6865@table @code
6866@kindex set non-stop
6867@item set non-stop on
6868Enable selection of non-stop mode.
6869@item set non-stop off
6870Disable selection of non-stop mode.
6871@kindex show non-stop
6872@item show non-stop
6873Show the current non-stop enablement setting.
6874@end table
6875
6876Note these commands only reflect whether non-stop mode is enabled,
97d8f0ee 6877not whether the currently-executing program is being run in non-stop mode.
0606b73b 6878In particular, the @code{set non-stop} preference is only consulted when
97d8f0ee 6879@value{GDBN} starts or connects to the target program, and it is generally
0606b73b
SL
6880not possible to switch modes once debugging has started. Furthermore,
6881since not all targets support non-stop mode, even when you have enabled
6882non-stop mode, @value{GDBN} may still fall back to all-stop operation by
6883default.
6884
6885In non-stop mode, all execution commands apply only to the current thread
97d8f0ee 6886by default. That is, @code{continue} only continues one thread.
0606b73b
SL
6887To continue all threads, issue @code{continue -a} or @code{c -a}.
6888
97d8f0ee 6889You can use @value{GDBN}'s background execution commands
0606b73b 6890(@pxref{Background Execution}) to run some threads in the background
97d8f0ee 6891while you continue to examine or step others from @value{GDBN}.
0606b73b
SL
6892The MI execution commands (@pxref{GDB/MI Program Execution}) are
6893always executed asynchronously in non-stop mode.
6894
6895Suspending execution is done with the @code{interrupt} command when
97d8f0ee
DE
6896running in the background, or @kbd{Ctrl-c} during foreground execution.
6897In all-stop mode, this stops the whole process;
6898but in non-stop mode the interrupt applies only to the current thread.
0606b73b
SL
6899To stop the whole program, use @code{interrupt -a}.
6900
6901Other execution commands do not currently support the @code{-a} option.
6902
6903In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
6904that thread current, as it does in all-stop mode. This is because the
97d8f0ee 6905thread stop notifications are asynchronous with respect to @value{GDBN}'s
0606b73b
SL
6906command interpreter, and it would be confusing if @value{GDBN} unexpectedly
6907changed to a different thread just as you entered a command to operate on the
6908previously current thread.
6909
6910@node Background Execution
6911@subsection Background Execution
6912
6913@cindex foreground execution
6914@cindex background execution
6915@cindex asynchronous execution
6916@cindex execution, foreground, background and asynchronous
6917
6918@value{GDBN}'s execution commands have two variants: the normal
6919foreground (synchronous) behavior, and a background
97d8f0ee 6920(asynchronous) behavior. In foreground execution, @value{GDBN} waits for
0606b73b
SL
6921the program to report that some thread has stopped before prompting for
6922another command. In background execution, @value{GDBN} immediately gives
6923a command prompt so that you can issue other commands while your program runs.
6924
32fc0df9
PA
6925If the target doesn't support async mode, @value{GDBN} issues an error
6926message if you attempt to use the background execution commands.
6927
74fdb8ff 6928@cindex @code{&}, background execution of commands
0606b73b
SL
6929To specify background execution, add a @code{&} to the command. For example,
6930the background form of the @code{continue} command is @code{continue&}, or
6931just @code{c&}. The execution commands that accept background execution
6932are:
6933
6934@table @code
6935@kindex run&
6936@item run
6937@xref{Starting, , Starting your Program}.
6938
6939@item attach
6940@kindex attach&
6941@xref{Attach, , Debugging an Already-running Process}.
6942
6943@item step
6944@kindex step&
6945@xref{Continuing and Stepping, step}.
6946
6947@item stepi
6948@kindex stepi&
6949@xref{Continuing and Stepping, stepi}.
6950
6951@item next
6952@kindex next&
6953@xref{Continuing and Stepping, next}.
6954
7ce58dd2
DE
6955@item nexti
6956@kindex nexti&
6957@xref{Continuing and Stepping, nexti}.
6958
0606b73b
SL
6959@item continue
6960@kindex continue&
6961@xref{Continuing and Stepping, continue}.
6962
6963@item finish
6964@kindex finish&
6965@xref{Continuing and Stepping, finish}.
6966
6967@item until
6968@kindex until&
6969@xref{Continuing and Stepping, until}.
6970
6971@end table
6972
6973Background execution is especially useful in conjunction with non-stop
6974mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
6975However, you can also use these commands in the normal all-stop mode with
6976the restriction that you cannot issue another execution command until the
6977previous one finishes. Examples of commands that are valid in all-stop
6978mode while the program is running include @code{help} and @code{info break}.
6979
6980You can interrupt your program while it is running in the background by
6981using the @code{interrupt} command.
6982
6983@table @code
6984@kindex interrupt
6985@item interrupt
6986@itemx interrupt -a
6987
97d8f0ee 6988Suspend execution of the running program. In all-stop mode,
0606b73b 6989@code{interrupt} stops the whole process, but in non-stop mode, it stops
97d8f0ee 6990only the current thread. To stop the whole program in non-stop mode,
0606b73b
SL
6991use @code{interrupt -a}.
6992@end table
6993
0606b73b
SL
6994@node Thread-Specific Breakpoints
6995@subsection Thread-Specific Breakpoints
6996
c906108c 6997When your program has multiple threads (@pxref{Threads,, Debugging
79a6e687 6998Programs with Multiple Threads}), you can choose whether to set
c906108c
SS
6999breakpoints on all threads, or on a particular thread.
7000
7001@table @code
7002@cindex breakpoints and threads
7003@cindex thread breakpoints
5d5658a1
PA
7004@kindex break @dots{} thread @var{thread-id}
7005@item break @var{location} thread @var{thread-id}
7006@itemx break @var{location} thread @var{thread-id} if @dots{}
629500fa 7007@var{location} specifies source lines; there are several ways of
2a25a5ba
EZ
7008writing them (@pxref{Specify Location}), but the effect is always to
7009specify some source line.
c906108c 7010
5d5658a1 7011Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
c906108c 7012to specify that you only want @value{GDBN} to stop the program when a
5d5658a1
PA
7013particular thread reaches this breakpoint. The @var{thread-id} specifier
7014is one of the thread identifiers assigned by @value{GDBN}, shown
697aa1b7 7015in the first column of the @samp{info threads} display.
c906108c 7016
5d5658a1 7017If you do not specify @samp{thread @var{thread-id}} when you set a
c906108c
SS
7018breakpoint, the breakpoint applies to @emph{all} threads of your
7019program.
7020
7021You can use the @code{thread} qualifier on conditional breakpoints as
5d5658a1 7022well; in this case, place @samp{thread @var{thread-id}} before or
b6199126 7023after the breakpoint condition, like this:
c906108c
SS
7024
7025@smallexample
2df3850c 7026(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
7027@end smallexample
7028
7029@end table
7030
f4fb82a1
PA
7031Thread-specific breakpoints are automatically deleted when
7032@value{GDBN} detects the corresponding thread is no longer in the
7033thread list. For example:
7034
7035@smallexample
7036(@value{GDBP}) c
7037Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
7038@end smallexample
7039
7040There are several ways for a thread to disappear, such as a regular
7041thread exit, but also when you detach from the process with the
7042@code{detach} command (@pxref{Attach, ,Debugging an Already-running
7043Process}), or if @value{GDBN} loses the remote connection
7044(@pxref{Remote Debugging}), etc. Note that with some targets,
7045@value{GDBN} is only able to detect a thread has exited when the user
7046explictly asks for the thread list with the @code{info threads}
7047command.
7048
0606b73b
SL
7049@node Interrupted System Calls
7050@subsection Interrupted System Calls
c906108c 7051
36d86913
MC
7052@cindex thread breakpoints and system calls
7053@cindex system calls and thread breakpoints
7054@cindex premature return from system calls
0606b73b
SL
7055There is an unfortunate side effect when using @value{GDBN} to debug
7056multi-threaded programs. If one thread stops for a
36d86913
MC
7057breakpoint, or for some other reason, and another thread is blocked in a
7058system call, then the system call may return prematurely. This is a
7059consequence of the interaction between multiple threads and the signals
7060that @value{GDBN} uses to implement breakpoints and other events that
7061stop execution.
7062
7063To handle this problem, your program should check the return value of
7064each system call and react appropriately. This is good programming
7065style anyways.
7066
7067For example, do not write code like this:
7068
7069@smallexample
7070 sleep (10);
7071@end smallexample
7072
7073The call to @code{sleep} will return early if a different thread stops
7074at a breakpoint or for some other reason.
7075
7076Instead, write this:
7077
7078@smallexample
7079 int unslept = 10;
7080 while (unslept > 0)
7081 unslept = sleep (unslept);
7082@end smallexample
7083
7084A system call is allowed to return early, so the system is still
7085conforming to its specification. But @value{GDBN} does cause your
7086multi-threaded program to behave differently than it would without
7087@value{GDBN}.
7088
7089Also, @value{GDBN} uses internal breakpoints in the thread library to
7090monitor certain events such as thread creation and thread destruction.
7091When such an event happens, a system call in another thread may return
7092prematurely, even though your program does not appear to stop.
7093
d914c394
SS
7094@node Observer Mode
7095@subsection Observer Mode
7096
7097If you want to build on non-stop mode and observe program behavior
7098without any chance of disruption by @value{GDBN}, you can set
7099variables to disable all of the debugger's attempts to modify state,
7100whether by writing memory, inserting breakpoints, etc. These operate
7101at a low level, intercepting operations from all commands.
7102
7103When all of these are set to @code{off}, then @value{GDBN} is said to
7104be @dfn{observer mode}. As a convenience, the variable
7105@code{observer} can be set to disable these, plus enable non-stop
7106mode.
7107
7108Note that @value{GDBN} will not prevent you from making nonsensical
7109combinations of these settings. For instance, if you have enabled
7110@code{may-insert-breakpoints} but disabled @code{may-write-memory},
7111then breakpoints that work by writing trap instructions into the code
7112stream will still not be able to be placed.
7113
7114@table @code
7115
7116@kindex observer
7117@item set observer on
7118@itemx set observer off
7119When set to @code{on}, this disables all the permission variables
7120below (except for @code{insert-fast-tracepoints}), plus enables
7121non-stop debugging. Setting this to @code{off} switches back to
7122normal debugging, though remaining in non-stop mode.
7123
7124@item show observer
7125Show whether observer mode is on or off.
7126
7127@kindex may-write-registers
7128@item set may-write-registers on
7129@itemx set may-write-registers off
7130This controls whether @value{GDBN} will attempt to alter the values of
7131registers, such as with assignment expressions in @code{print}, or the
7132@code{jump} command. It defaults to @code{on}.
7133
7134@item show may-write-registers
7135Show the current permission to write registers.
7136
7137@kindex may-write-memory
7138@item set may-write-memory on
7139@itemx set may-write-memory off
7140This controls whether @value{GDBN} will attempt to alter the contents
7141of memory, such as with assignment expressions in @code{print}. It
7142defaults to @code{on}.
7143
7144@item show may-write-memory
7145Show the current permission to write memory.
7146
7147@kindex may-insert-breakpoints
7148@item set may-insert-breakpoints on
7149@itemx set may-insert-breakpoints off
7150This controls whether @value{GDBN} will attempt to insert breakpoints.
7151This affects all breakpoints, including internal breakpoints defined
7152by @value{GDBN}. It defaults to @code{on}.
7153
7154@item show may-insert-breakpoints
7155Show the current permission to insert breakpoints.
7156
7157@kindex may-insert-tracepoints
7158@item set may-insert-tracepoints on
7159@itemx set may-insert-tracepoints off
7160This controls whether @value{GDBN} will attempt to insert (regular)
7161tracepoints at the beginning of a tracing experiment. It affects only
7162non-fast tracepoints, fast tracepoints being under the control of
7163@code{may-insert-fast-tracepoints}. It defaults to @code{on}.
7164
7165@item show may-insert-tracepoints
7166Show the current permission to insert tracepoints.
7167
7168@kindex may-insert-fast-tracepoints
7169@item set may-insert-fast-tracepoints on
7170@itemx set may-insert-fast-tracepoints off
7171This controls whether @value{GDBN} will attempt to insert fast
7172tracepoints at the beginning of a tracing experiment. It affects only
7173fast tracepoints, regular (non-fast) tracepoints being under the
7174control of @code{may-insert-tracepoints}. It defaults to @code{on}.
7175
7176@item show may-insert-fast-tracepoints
7177Show the current permission to insert fast tracepoints.
7178
7179@kindex may-interrupt
7180@item set may-interrupt on
7181@itemx set may-interrupt off
7182This controls whether @value{GDBN} will attempt to interrupt or stop
7183program execution. When this variable is @code{off}, the
7184@code{interrupt} command will have no effect, nor will
7185@kbd{Ctrl-c}. It defaults to @code{on}.
7186
7187@item show may-interrupt
7188Show the current permission to interrupt or stop the program.
7189
7190@end table
c906108c 7191
bacec72f
MS
7192@node Reverse Execution
7193@chapter Running programs backward
7194@cindex reverse execution
7195@cindex running programs backward
7196
7197When you are debugging a program, it is not unusual to realize that
7198you have gone too far, and some event of interest has already happened.
7199If the target environment supports it, @value{GDBN} can allow you to
7200``rewind'' the program by running it backward.
7201
7202A target environment that supports reverse execution should be able
7203to ``undo'' the changes in machine state that have taken place as the
7204program was executing normally. Variables, registers etc.@: should
7205revert to their previous values. Obviously this requires a great
7206deal of sophistication on the part of the target environment; not
7207all target environments can support reverse execution.
7208
7209When a program is executed in reverse, the instructions that
7210have most recently been executed are ``un-executed'', in reverse
7211order. The program counter runs backward, following the previous
7212thread of execution in reverse. As each instruction is ``un-executed'',
7213the values of memory and/or registers that were changed by that
7214instruction are reverted to their previous states. After executing
7215a piece of source code in reverse, all side effects of that code
7216should be ``undone'', and all variables should be returned to their
7217prior values@footnote{
7218Note that some side effects are easier to undo than others. For instance,
7219memory and registers are relatively easy, but device I/O is hard. Some
7220targets may be able undo things like device I/O, and some may not.
7221
7222The contract between @value{GDBN} and the reverse executing target
7223requires only that the target do something reasonable when
7224@value{GDBN} tells it to execute backwards, and then report the
7225results back to @value{GDBN}. Whatever the target reports back to
7226@value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
7227assumes that the memory and registers that the target reports are in a
6b92c0d3 7228consistent state, but @value{GDBN} accepts whatever it is given.
bacec72f
MS
7229}.
7230
73f8a590
PA
7231On some platforms, @value{GDBN} has built-in support for reverse
7232execution, activated with the @code{record} or @code{record btrace}
7233commands. @xref{Process Record and Replay}. Some remote targets,
7234typically full system emulators, support reverse execution directly
7235without requiring any special command.
7236
bacec72f
MS
7237If you are debugging in a target environment that supports
7238reverse execution, @value{GDBN} provides the following commands.
7239
7240@table @code
7241@kindex reverse-continue
7242@kindex rc @r{(@code{reverse-continue})}
7243@item reverse-continue @r{[}@var{ignore-count}@r{]}
7244@itemx rc @r{[}@var{ignore-count}@r{]}
7245Beginning at the point where your program last stopped, start executing
7246in reverse. Reverse execution will stop for breakpoints and synchronous
7247exceptions (signals), just like normal execution. Behavior of
7248asynchronous signals depends on the target environment.
7249
7250@kindex reverse-step
7251@kindex rs @r{(@code{step})}
7252@item reverse-step @r{[}@var{count}@r{]}
7253Run the program backward until control reaches the start of a
7254different source line; then stop it, and return control to @value{GDBN}.
7255
7256Like the @code{step} command, @code{reverse-step} will only stop
7257at the beginning of a source line. It ``un-executes'' the previously
7258executed source line. If the previous source line included calls to
7259debuggable functions, @code{reverse-step} will step (backward) into
7260the called function, stopping at the beginning of the @emph{last}
7261statement in the called function (typically a return statement).
7262
7263Also, as with the @code{step} command, if non-debuggable functions are
7264called, @code{reverse-step} will run thru them backward without stopping.
7265
7266@kindex reverse-stepi
7267@kindex rsi @r{(@code{reverse-stepi})}
7268@item reverse-stepi @r{[}@var{count}@r{]}
7269Reverse-execute one machine instruction. Note that the instruction
7270to be reverse-executed is @emph{not} the one pointed to by the program
7271counter, but the instruction executed prior to that one. For instance,
7272if the last instruction was a jump, @code{reverse-stepi} will take you
7273back from the destination of the jump to the jump instruction itself.
7274
7275@kindex reverse-next
7276@kindex rn @r{(@code{reverse-next})}
7277@item reverse-next @r{[}@var{count}@r{]}
7278Run backward to the beginning of the previous line executed in
7279the current (innermost) stack frame. If the line contains function
7280calls, they will be ``un-executed'' without stopping. Starting from
7281the first line of a function, @code{reverse-next} will take you back
7282to the caller of that function, @emph{before} the function was called,
7283just as the normal @code{next} command would take you from the last
7284line of a function back to its return to its caller
16af530a 7285@footnote{Unless the code is too heavily optimized.}.
bacec72f
MS
7286
7287@kindex reverse-nexti
7288@kindex rni @r{(@code{reverse-nexti})}
7289@item reverse-nexti @r{[}@var{count}@r{]}
7290Like @code{nexti}, @code{reverse-nexti} executes a single instruction
7291in reverse, except that called functions are ``un-executed'' atomically.
7292That is, if the previously executed instruction was a return from
540aa8e7 7293another function, @code{reverse-nexti} will continue to execute
bacec72f
MS
7294in reverse until the call to that function (from the current stack
7295frame) is reached.
7296
7297@kindex reverse-finish
7298@item reverse-finish
7299Just as the @code{finish} command takes you to the point where the
7300current function returns, @code{reverse-finish} takes you to the point
7301where it was called. Instead of ending up at the end of the current
7302function invocation, you end up at the beginning.
7303
7304@kindex set exec-direction
7305@item set exec-direction
7306Set the direction of target execution.
984359d2 7307@item set exec-direction reverse
bacec72f
MS
7308@cindex execute forward or backward in time
7309@value{GDBN} will perform all execution commands in reverse, until the
7310exec-direction mode is changed to ``forward''. Affected commands include
7311@code{step, stepi, next, nexti, continue, and finish}. The @code{return}
7312command cannot be used in reverse mode.
7313@item set exec-direction forward
7314@value{GDBN} will perform all execution commands in the normal fashion.
7315This is the default.
7316@end table
7317
c906108c 7318
a2311334
EZ
7319@node Process Record and Replay
7320@chapter Recording Inferior's Execution and Replaying It
53cc454a
HZ
7321@cindex process record and replay
7322@cindex recording inferior's execution and replaying it
7323
8e05493c
EZ
7324On some platforms, @value{GDBN} provides a special @dfn{process record
7325and replay} target that can record a log of the process execution, and
7326replay it later with both forward and reverse execution commands.
a2311334
EZ
7327
7328@cindex replay mode
7329When this target is in use, if the execution log includes the record
7330for the next instruction, @value{GDBN} will debug in @dfn{replay
7331mode}. In the replay mode, the inferior does not really execute code
7332instructions. Instead, all the events that normally happen during
7333code execution are taken from the execution log. While code is not
7334really executed in replay mode, the values of registers (including the
7335program counter register) and the memory of the inferior are still
8e05493c
EZ
7336changed as they normally would. Their contents are taken from the
7337execution log.
a2311334
EZ
7338
7339@cindex record mode
7340If the record for the next instruction is not in the execution log,
7341@value{GDBN} will debug in @dfn{record mode}. In this mode, the
7342inferior executes normally, and @value{GDBN} records the execution log
7343for future replay.
7344
8e05493c
EZ
7345The process record and replay target supports reverse execution
7346(@pxref{Reverse Execution}), even if the platform on which the
7347inferior runs does not. However, the reverse execution is limited in
7348this case by the range of the instructions recorded in the execution
7349log. In other words, reverse execution on platforms that don't
7350support it directly can only be done in the replay mode.
7351
7352When debugging in the reverse direction, @value{GDBN} will work in
7353replay mode as long as the execution log includes the record for the
7354previous instruction; otherwise, it will work in record mode, if the
7355platform supports reverse execution, or stop if not.
7356
73f8a590
PA
7357Currently, process record and replay is supported on ARM, Aarch64,
7358Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
7359GNU/Linux. Process record and replay can be used both when native
7360debugging, and when remote debugging via @code{gdbserver}.
7361
a2311334
EZ
7362For architecture environments that support process record and replay,
7363@value{GDBN} provides the following commands:
53cc454a
HZ
7364
7365@table @code
7366@kindex target record
59ea5688
MM
7367@kindex target record-full
7368@kindex target record-btrace
53cc454a 7369@kindex record
59ea5688
MM
7370@kindex record full
7371@kindex record btrace
f4abbc16 7372@kindex record btrace bts
b20a6524 7373@kindex record btrace pt
f4abbc16 7374@kindex record bts
b20a6524 7375@kindex record pt
53cc454a 7376@kindex rec
59ea5688
MM
7377@kindex rec full
7378@kindex rec btrace
f4abbc16 7379@kindex rec btrace bts
b20a6524 7380@kindex rec btrace pt
f4abbc16 7381@kindex rec bts
b20a6524 7382@kindex rec pt
59ea5688
MM
7383@item record @var{method}
7384This command starts the process record and replay target. The
7385recording method can be specified as parameter. Without a parameter
7386the command uses the @code{full} recording method. The following
7387recording methods are available:
a2311334 7388
59ea5688
MM
7389@table @code
7390@item full
7391Full record/replay recording using @value{GDBN}'s software record and
7392replay implementation. This method allows replaying and reverse
7393execution.
7394
f4abbc16 7395@item btrace @var{format}
73f8a590
PA
7396Hardware-supported instruction recording, supported on Intel
7397processors. This method does not record data. Further, the data is
7398collected in a ring buffer so old data will be overwritten when the
7399buffer is full. It allows limited reverse execution. Variables and
7400registers are not available during reverse execution. In remote
7401debugging, recording continues on disconnect. Recorded data can be
7402inspected after reconnecting. The recording may be stopped using
7403@code{record stop}.
59ea5688 7404
f4abbc16
MM
7405The recording format can be specified as parameter. Without a parameter
7406the command chooses the recording format. The following recording
7407formats are available:
7408
7409@table @code
7410@item bts
7411@cindex branch trace store
7412Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
7413this format, the processor stores a from/to record for each executed
7414branch in the btrace ring buffer.
b20a6524
MM
7415
7416@item pt
bc504a31
PA
7417@cindex Intel Processor Trace
7418Use the @dfn{Intel Processor Trace} recording format. In this
b20a6524
MM
7419format, the processor stores the execution trace in a compressed form
7420that is afterwards decoded by @value{GDBN}.
7421
7422The trace can be recorded with very low overhead. The compressed
7423trace format also allows small trace buffers to already contain a big
7424number of instructions compared to @acronym{BTS}.
7425
7426Decoding the recorded execution trace, on the other hand, is more
7427expensive than decoding @acronym{BTS} trace. This is mostly due to the
7428increased number of instructions to process. You should increase the
7429buffer-size with care.
f4abbc16
MM
7430@end table
7431
7432Not all recording formats may be available on all processors.
59ea5688
MM
7433@end table
7434
7435The process record and replay target can only debug a process that is
7436already running. Therefore, you need first to start the process with
7437the @kbd{run} or @kbd{start} commands, and then start the recording
7438with the @kbd{record @var{method}} command.
7439
a2311334
EZ
7440@cindex displaced stepping, and process record and replay
7441Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7442will be automatically disabled when process record and replay target
7443is started. That's because the process record and replay target
7444doesn't support displaced stepping.
7445
7446@cindex non-stop mode, and process record and replay
7447@cindex asynchronous execution, and process record and replay
7448If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
59ea5688
MM
7449the asynchronous execution mode (@pxref{Background Execution}), not
7450all recording methods are available. The @code{full} recording method
7451does not support these two modes.
53cc454a
HZ
7452
7453@kindex record stop
7454@kindex rec s
7455@item record stop
a2311334
EZ
7456Stop the process record and replay target. When process record and
7457replay target stops, the entire execution log will be deleted and the
7458inferior will either be terminated, or will remain in its final state.
53cc454a 7459
a2311334
EZ
7460When you stop the process record and replay target in record mode (at
7461the end of the execution log), the inferior will be stopped at the
7462next instruction that would have been recorded. In other words, if
7463you record for a while and then stop recording, the inferior process
7464will be left in the same state as if the recording never happened.
53cc454a 7465
a2311334
EZ
7466On the other hand, if the process record and replay target is stopped
7467while in replay mode (that is, not at the end of the execution log,
7468but at some earlier point), the inferior process will become ``live''
7469at that earlier state, and it will then be possible to continue the
7470usual ``live'' debugging of the process from that state.
53cc454a 7471
a2311334
EZ
7472When the inferior process exits, or @value{GDBN} detaches from it,
7473process record and replay target will automatically stop itself.
53cc454a 7474
742ce053
MM
7475@kindex record goto
7476@item record goto
7477Go to a specific location in the execution log. There are several
7478ways to specify the location to go to:
7479
7480@table @code
7481@item record goto begin
7482@itemx record goto start
7483Go to the beginning of the execution log.
7484
7485@item record goto end
7486Go to the end of the execution log.
7487
7488@item record goto @var{n}
7489Go to instruction number @var{n} in the execution log.
7490@end table
7491
24e933df
HZ
7492@kindex record save
7493@item record save @var{filename}
7494Save the execution log to a file @file{@var{filename}}.
7495Default filename is @file{gdb_record.@var{process_id}}, where
7496@var{process_id} is the process ID of the inferior.
7497
59ea5688
MM
7498This command may not be available for all recording methods.
7499
24e933df
HZ
7500@kindex record restore
7501@item record restore @var{filename}
7502Restore the execution log from a file @file{@var{filename}}.
7503File must have been created with @code{record save}.
7504
59ea5688
MM
7505@kindex set record full
7506@item set record full insn-number-max @var{limit}
f81d1120 7507@itemx set record full insn-number-max unlimited
59ea5688
MM
7508Set the limit of instructions to be recorded for the @code{full}
7509recording method. Default value is 200000.
53cc454a 7510
a2311334
EZ
7511If @var{limit} is a positive number, then @value{GDBN} will start
7512deleting instructions from the log once the number of the record
7513instructions becomes greater than @var{limit}. For every new recorded
7514instruction, @value{GDBN} will delete the earliest recorded
7515instruction to keep the number of recorded instructions at the limit.
7516(Since deleting recorded instructions loses information, @value{GDBN}
7517lets you control what happens when the limit is reached, by means of
7518the @code{stop-at-limit} option, described below.)
53cc454a 7519
f81d1120
PA
7520If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7521delete recorded instructions from the execution log. The number of
7522recorded instructions is limited only by the available memory.
53cc454a 7523
59ea5688
MM
7524@kindex show record full
7525@item show record full insn-number-max
7526Show the limit of instructions to be recorded with the @code{full}
7527recording method.
53cc454a 7528
59ea5688
MM
7529@item set record full stop-at-limit
7530Control the behavior of the @code{full} recording method when the
7531number of recorded instructions reaches the limit. If ON (the
7532default), @value{GDBN} will stop when the limit is reached for the
7533first time and ask you whether you want to stop the inferior or
7534continue running it and recording the execution log. If you decide
7535to continue recording, each new recorded instruction will cause the
7536oldest one to be deleted.
53cc454a 7537
a2311334
EZ
7538If this option is OFF, @value{GDBN} will automatically delete the
7539oldest record to make room for each new one, without asking.
53cc454a 7540
59ea5688 7541@item show record full stop-at-limit
a2311334 7542Show the current setting of @code{stop-at-limit}.
53cc454a 7543
59ea5688 7544@item set record full memory-query
bb08c432 7545Control the behavior when @value{GDBN} is unable to record memory
59ea5688
MM
7546changes caused by an instruction for the @code{full} recording method.
7547If ON, @value{GDBN} will query whether to stop the inferior in that
7548case.
bb08c432
HZ
7549
7550If this option is OFF (the default), @value{GDBN} will automatically
7551ignore the effect of such instructions on memory. Later, when
7552@value{GDBN} replays this execution log, it will mark the log of this
7553instruction as not accessible, and it will not affect the replay
7554results.
7555
59ea5688 7556@item show record full memory-query
bb08c432
HZ
7557Show the current setting of @code{memory-query}.
7558
67b5c0c1
MM
7559@kindex set record btrace
7560The @code{btrace} record target does not trace data. As a
7561convenience, when replaying, @value{GDBN} reads read-only memory off
7562the live program directly, assuming that the addresses of the
7563read-only areas don't change. This for example makes it possible to
7564disassemble code while replaying, but not to print variables.
7565In some cases, being able to inspect variables might be useful.
7566You can use the following command for that:
7567
7568@item set record btrace replay-memory-access
7569Control the behavior of the @code{btrace} recording method when
7570accessing memory during replay. If @code{read-only} (the default),
7571@value{GDBN} will only allow accesses to read-only memory.
7572If @code{read-write}, @value{GDBN} will allow accesses to read-only
7573and to read-write memory. Beware that the accessed memory corresponds
7574to the live target and not necessarily to the current replay
7575position.
7576
4a4495d6
MM
7577@item set record btrace cpu @var{identifier}
7578Set the processor to be used for enabling workarounds for processor
7579errata when decoding the trace.
7580
7581Processor errata are defects in processor operation, caused by its
7582design or manufacture. They can cause a trace not to match the
7583specification. This, in turn, may cause trace decode to fail.
7584@value{GDBN} can detect erroneous trace packets and correct them, thus
7585avoiding the decoding failures. These corrections are known as
7586@dfn{errata workarounds}, and are enabled based on the processor on
7587which the trace was recorded.
7588
7589By default, @value{GDBN} attempts to detect the processor
7590automatically, and apply the necessary workarounds for it. However,
7591you may need to specify the processor if @value{GDBN} does not yet
7592support it. This command allows you to do that, and also allows to
7593disable the workarounds.
7594
7595The argument @var{identifier} identifies the @sc{cpu} and is of the
6b92c0d3 7596form: @code{@var{vendor}:@var{processor identifier}}. In addition,
4a4495d6
MM
7597there are two special identifiers, @code{none} and @code{auto}
7598(default).
7599
7600The following vendor identifiers and corresponding processor
7601identifiers are currently supported:
7602
7603@multitable @columnfractions .1 .9
7604
7605@item @code{intel}
7606@tab @var{family}/@var{model}[/@var{stepping}]
7607
7608@end multitable
7609
7610On GNU/Linux systems, the processor @var{family}, @var{model}, and
7611@var{stepping} can be obtained from @code{/proc/cpuinfo}.
7612
7613If @var{identifier} is @code{auto}, enable errata workarounds for the
7614processor on which the trace was recorded. If @var{identifier} is
7615@code{none}, errata workarounds are disabled.
7616
7617For example, when using an old @value{GDBN} on a new system, decode
7618may fail because @value{GDBN} does not support the new processor. It
7619often suffices to specify an older processor that @value{GDBN}
7620supports.
7621
7622@smallexample
7623(gdb) info record
7624Active record target: record-btrace
7625Recording format: Intel Processor Trace.
7626Buffer size: 16kB.
7627Failed to configure the Intel Processor Trace decoder: unknown cpu.
7628(gdb) set record btrace cpu intel:6/158
7629(gdb) info record
7630Active record target: record-btrace
7631Recording format: Intel Processor Trace.
7632Buffer size: 16kB.
7633Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7634@end smallexample
7635
67b5c0c1
MM
7636@kindex show record btrace
7637@item show record btrace replay-memory-access
7638Show the current setting of @code{replay-memory-access}.
7639
4a4495d6
MM
7640@item show record btrace cpu
7641Show the processor to be used for enabling trace decode errata
7642workarounds.
7643
d33501a5
MM
7644@kindex set record btrace bts
7645@item set record btrace bts buffer-size @var{size}
7646@itemx set record btrace bts buffer-size unlimited
7647Set the requested ring buffer size for branch tracing in @acronym{BTS}
7648format. Default is 64KB.
7649
7650If @var{size} is a positive number, then @value{GDBN} will try to
7651allocate a buffer of at least @var{size} bytes for each new thread
7652that uses the btrace recording method and the @acronym{BTS} format.
7653The actually obtained buffer size may differ from the requested
7654@var{size}. Use the @code{info record} command to see the actual
7655buffer size for each thread that uses the btrace recording method and
7656the @acronym{BTS} format.
7657
7658If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7659allocate a buffer of 4MB.
7660
7661Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7662also need longer to process the branch trace data before it can be used.
7663
7664@item show record btrace bts buffer-size @var{size}
7665Show the current setting of the requested ring buffer size for branch
7666tracing in @acronym{BTS} format.
7667
b20a6524
MM
7668@kindex set record btrace pt
7669@item set record btrace pt buffer-size @var{size}
7670@itemx set record btrace pt buffer-size unlimited
bc504a31 7671Set the requested ring buffer size for branch tracing in Intel
b20a6524
MM
7672Processor Trace format. Default is 16KB.
7673
7674If @var{size} is a positive number, then @value{GDBN} will try to
7675allocate a buffer of at least @var{size} bytes for each new thread
bc504a31 7676that uses the btrace recording method and the Intel Processor Trace
b20a6524
MM
7677format. The actually obtained buffer size may differ from the
7678requested @var{size}. Use the @code{info record} command to see the
7679actual buffer size for each thread.
7680
7681If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7682allocate a buffer of 4MB.
7683
7684Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7685also need longer to process the branch trace data before it can be used.
7686
7687@item show record btrace pt buffer-size @var{size}
7688Show the current setting of the requested ring buffer size for branch
bc504a31 7689tracing in Intel Processor Trace format.
b20a6524 7690
29153c24
MS
7691@kindex info record
7692@item info record
59ea5688
MM
7693Show various statistics about the recording depending on the recording
7694method:
7695
7696@table @code
7697@item full
7698For the @code{full} recording method, it shows the state of process
7699record and its in-memory execution log buffer, including:
29153c24
MS
7700
7701@itemize @bullet
7702@item
7703Whether in record mode or replay mode.
7704@item
7705Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7706@item
7707Highest recorded instruction number.
7708@item
7709Current instruction about to be replayed (if in replay mode).
7710@item
7711Number of instructions contained in the execution log.
7712@item
7713Maximum number of instructions that may be contained in the execution log.
7714@end itemize
53cc454a 7715
59ea5688 7716@item btrace
d33501a5
MM
7717For the @code{btrace} recording method, it shows:
7718
7719@itemize @bullet
7720@item
7721Recording format.
7722@item
7723Number of instructions that have been recorded.
7724@item
7725Number of blocks of sequential control-flow formed by the recorded
7726instructions.
7727@item
7728Whether in record mode or replay mode.
7729@end itemize
7730
7731For the @code{bts} recording format, it also shows:
7732@itemize @bullet
7733@item
7734Size of the perf ring buffer.
7735@end itemize
b20a6524
MM
7736
7737For the @code{pt} recording format, it also shows:
7738@itemize @bullet
7739@item
7740Size of the perf ring buffer.
7741@end itemize
59ea5688
MM
7742@end table
7743
53cc454a
HZ
7744@kindex record delete
7745@kindex rec del
7746@item record delete
a2311334 7747When record target runs in replay mode (``in the past''), delete the
53cc454a 7748subsequent execution log and begin to record a new execution log starting
a2311334 7749from the current address. This means you will abandon the previously
53cc454a 7750recorded ``future'' and begin recording a new ``future''.
59ea5688
MM
7751
7752@kindex record instruction-history
7753@kindex rec instruction-history
7754@item record instruction-history
7755Disassembles instructions from the recorded execution log. By
7756default, ten instructions are disassembled. This can be changed using
7757the @code{set record instruction-history-size} command. Instructions
da8c46d2
MM
7758are printed in execution order.
7759
0c532a29
MM
7760It can also print mixed source+disassembly if you specify the the
7761@code{/m} or @code{/s} modifier, and print the raw instructions in hex
7762as well as in symbolic form by specifying the @code{/r} modifier.
7763
7764The current position marker is printed for the instruction at the
7765current program counter value. This instruction can appear multiple
7766times in the trace and the current position marker will be printed
7767every time. To omit the current position marker, specify the
7768@code{/p} modifier.
7769
7770To better align the printed instructions when the trace contains
7771instructions from more than one function, the function name may be
7772omitted by specifying the @code{/f} modifier.
7773
da8c46d2
MM
7774Speculatively executed instructions are prefixed with @samp{?}. This
7775feature is not available for all recording formats.
7776
7777There are several ways to specify what part of the execution log to
7778disassemble:
59ea5688
MM
7779
7780@table @code
7781@item record instruction-history @var{insn}
7782Disassembles ten instructions starting from instruction number
7783@var{insn}.
7784
7785@item record instruction-history @var{insn}, +/-@var{n}
7786Disassembles @var{n} instructions around instruction number
7787@var{insn}. If @var{n} is preceded with @code{+}, disassembles
7788@var{n} instructions after instruction number @var{insn}. If
7789@var{n} is preceded with @code{-}, disassembles @var{n}
7790instructions before instruction number @var{insn}.
7791
7792@item record instruction-history
7793Disassembles ten more instructions after the last disassembly.
7794
7795@item record instruction-history -
7796Disassembles ten more instructions before the last disassembly.
7797
792005b0 7798@item record instruction-history @var{begin}, @var{end}
59ea5688
MM
7799Disassembles instructions beginning with instruction number
7800@var{begin} until instruction number @var{end}. The instruction
0688d04e 7801number @var{end} is included.
59ea5688
MM
7802@end table
7803
7804This command may not be available for all recording methods.
7805
7806@kindex set record
f81d1120
PA
7807@item set record instruction-history-size @var{size}
7808@itemx set record instruction-history-size unlimited
59ea5688
MM
7809Define how many instructions to disassemble in the @code{record
7810instruction-history} command. The default value is 10.
f81d1120 7811A @var{size} of @code{unlimited} means unlimited instructions.
59ea5688
MM
7812
7813@kindex show record
7814@item show record instruction-history-size
7815Show how many instructions to disassemble in the @code{record
7816instruction-history} command.
7817
7818@kindex record function-call-history
7819@kindex rec function-call-history
7820@item record function-call-history
7821Prints the execution history at function granularity. It prints one
7822line for each sequence of instructions that belong to the same
7823function giving the name of that function, the source lines
7824for this instruction sequence (if the @code{/l} modifier is
7825specified), and the instructions numbers that form the sequence (if
8710b709
MM
7826the @code{/i} modifier is specified). The function names are indented
7827to reflect the call stack depth if the @code{/c} modifier is
7828specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be
7829given together.
59ea5688
MM
7830
7831@smallexample
7832(@value{GDBP}) @b{list 1, 10}
78331 void foo (void)
78342 @{
78353 @}
78364
78375 void bar (void)
78386 @{
78397 ...
78408 foo ();
78419 ...
784210 @}
8710b709
MM
7843(@value{GDBP}) @b{record function-call-history /ilc}
78441 bar inst 1,4 at foo.c:6,8
78452 foo inst 5,10 at foo.c:2,3
78463 bar inst 11,13 at foo.c:9,10
59ea5688
MM
7847@end smallexample
7848
7849By default, ten lines are printed. This can be changed using the
7850@code{set record function-call-history-size} command. Functions are
7851printed in execution order. There are several ways to specify what
7852to print:
7853
7854@table @code
7855@item record function-call-history @var{func}
7856Prints ten functions starting from function number @var{func}.
7857
7858@item record function-call-history @var{func}, +/-@var{n}
7859Prints @var{n} functions around function number @var{func}. If
7860@var{n} is preceded with @code{+}, prints @var{n} functions after
7861function number @var{func}. If @var{n} is preceded with @code{-},
7862prints @var{n} functions before function number @var{func}.
7863
7864@item record function-call-history
7865Prints ten more functions after the last ten-line print.
7866
7867@item record function-call-history -
7868Prints ten more functions before the last ten-line print.
7869
792005b0 7870@item record function-call-history @var{begin}, @var{end}
59ea5688 7871Prints functions beginning with function number @var{begin} until
0688d04e 7872function number @var{end}. The function number @var{end} is included.
59ea5688
MM
7873@end table
7874
7875This command may not be available for all recording methods.
7876
f81d1120
PA
7877@item set record function-call-history-size @var{size}
7878@itemx set record function-call-history-size unlimited
59ea5688
MM
7879Define how many lines to print in the
7880@code{record function-call-history} command. The default value is 10.
f81d1120 7881A size of @code{unlimited} means unlimited lines.
59ea5688
MM
7882
7883@item show record function-call-history-size
7884Show how many lines to print in the
7885@code{record function-call-history} command.
53cc454a
HZ
7886@end table
7887
7888
6d2ebf8b 7889@node Stack
c906108c
SS
7890@chapter Examining the Stack
7891
7892When your program has stopped, the first thing you need to know is where it
7893stopped and how it got there.
7894
7895@cindex call stack
5d161b24
DB
7896Each time your program performs a function call, information about the call
7897is generated.
7898That information includes the location of the call in your program,
7899the arguments of the call,
c906108c 7900and the local variables of the function being called.
5d161b24 7901The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
7902The stack frames are allocated in a region of memory called the @dfn{call
7903stack}.
7904
7905When your program stops, the @value{GDBN} commands for examining the
7906stack allow you to see all of this information.
7907
7908@cindex selected frame
7909One of the stack frames is @dfn{selected} by @value{GDBN} and many
7910@value{GDBN} commands refer implicitly to the selected frame. In
7911particular, whenever you ask @value{GDBN} for the value of a variable in
7912your program, the value is found in the selected frame. There are
7913special @value{GDBN} commands to select whichever frame you are
79a6e687 7914interested in. @xref{Selection, ,Selecting a Frame}.
c906108c
SS
7915
7916When your program stops, @value{GDBN} automatically selects the
5d161b24 7917currently executing frame and describes it briefly, similar to the
79a6e687 7918@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
c906108c
SS
7919
7920@menu
7921* Frames:: Stack frames
7922* Backtrace:: Backtraces
7923* Selection:: Selecting a frame
7924* Frame Info:: Information on a frame
0a232300 7925* Frame Apply:: Applying a command to several frames
0f59c28f 7926* Frame Filter Management:: Managing frame filters
c906108c
SS
7927
7928@end menu
7929
6d2ebf8b 7930@node Frames
79a6e687 7931@section Stack Frames
c906108c 7932
d4f3574e 7933@cindex frame, definition
c906108c
SS
7934@cindex stack frame
7935The call stack is divided up into contiguous pieces called @dfn{stack
7936frames}, or @dfn{frames} for short; each frame is the data associated
7937with one call to one function. The frame contains the arguments given
7938to the function, the function's local variables, and the address at
7939which the function is executing.
7940
7941@cindex initial frame
7942@cindex outermost frame
7943@cindex innermost frame
7944When your program is started, the stack has only one frame, that of the
7945function @code{main}. This is called the @dfn{initial} frame or the
7946@dfn{outermost} frame. Each time a function is called, a new frame is
7947made. Each time a function returns, the frame for that function invocation
7948is eliminated. If a function is recursive, there can be many frames for
7949the same function. The frame for the function in which execution is
7950actually occurring is called the @dfn{innermost} frame. This is the most
7951recently created of all the stack frames that still exist.
7952
7953@cindex frame pointer
7954Inside your program, stack frames are identified by their addresses. A
7955stack frame consists of many bytes, each of which has its own address; each
7956kind of computer has a convention for choosing one byte whose
7957address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
7958in a register called the @dfn{frame pointer register}
7959(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c 7960
f67ffa6a 7961@cindex frame level
c906108c 7962@cindex frame number
f67ffa6a
AB
7963@value{GDBN} labels each existing stack frame with a @dfn{level}, a
7964number that is zero for the innermost frame, one for the frame that
7965called it, and so on upward. These level numbers give you a way of
7966designating stack frames in @value{GDBN} commands. The terms
7967@dfn{frame number} and @dfn{frame level} can be used interchangeably to
7968describe this number.
c906108c 7969
6d2ebf8b
SS
7970@c The -fomit-frame-pointer below perennially causes hbox overflow
7971@c underflow problems.
c906108c
SS
7972@cindex frameless execution
7973Some compilers provide a way to compile functions so that they operate
e22ea452 7974without stack frames. (For example, the @value{NGCC} option
474c8240 7975@smallexample
6d2ebf8b 7976@samp{-fomit-frame-pointer}
474c8240 7977@end smallexample
6d2ebf8b 7978generates functions without a frame.)
c906108c
SS
7979This is occasionally done with heavily used library functions to save
7980the frame setup time. @value{GDBN} has limited facilities for dealing
7981with these function invocations. If the innermost function invocation
7982has no stack frame, @value{GDBN} nevertheless regards it as though
7983it had a separate frame, which is numbered zero as usual, allowing
7984correct tracing of the function call chain. However, @value{GDBN} has
7985no provision for frameless functions elsewhere in the stack.
7986
6d2ebf8b 7987@node Backtrace
c906108c
SS
7988@section Backtraces
7989
09d4efe1
EZ
7990@cindex traceback
7991@cindex call stack traces
c906108c
SS
7992A backtrace is a summary of how your program got where it is. It shows one
7993line per frame, for many frames, starting with the currently executing
7994frame (frame zero), followed by its caller (frame one), and on up the
7995stack.
7996
1e611234 7997@anchor{backtrace-command}
c906108c 7998@kindex backtrace
41afff9a 7999@kindex bt @r{(@code{backtrace})}
ea3b0687
TT
8000To print a backtrace of the entire stack, use the @code{backtrace}
8001command, or its alias @code{bt}. This command will print one line per
8002frame for frames in the stack. By default, all stack frames are
8003printed. You can stop the backtrace at any time by typing the system
8004interrupt character, normally @kbd{Ctrl-c}.
8005
8006@table @code
3345721a
PA
8007@item backtrace [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
8008@itemx bt [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
8009Print the backtrace of the entire stack.
8010
8011The optional @var{count} can be one of the following:
ea3b0687
TT
8012
8013@table @code
8014@item @var{n}
8015@itemx @var{n}
8016Print only the innermost @var{n} frames, where @var{n} is a positive
8017number.
8018
8019@item -@var{n}
8020@itemx -@var{n}
8021Print only the outermost @var{n} frames, where @var{n} is a positive
8022number.
3345721a 8023@end table
ea3b0687 8024
3345721a
PA
8025Options:
8026
8027@table @code
8028@item -full
ea3b0687 8029Print the values of the local variables also. This can be combined
3345721a 8030with the optional @var{count} to limit the number of frames shown.
ea3b0687 8031
3345721a 8032@item -no-filters
1e611234
PM
8033Do not run Python frame filters on this backtrace. @xref{Frame
8034Filter API}, for more information. Additionally use @ref{disable
8035frame-filter all} to turn off all frame filters. This is only
8036relevant when @value{GDBN} has been configured with @code{Python}
8037support.
978d6c75 8038
3345721a 8039@item -hide
978d6c75
TT
8040A Python frame filter might decide to ``elide'' some frames. Normally
8041such elided frames are still printed, but they are indented relative
3345721a 8042to the filtered frames that cause them to be elided. The @code{-hide}
978d6c75 8043option causes elided frames to not be printed at all.
c906108c 8044@end table
3345721a
PA
8045
8046The @code{backtrace} command also supports a number of options that
8047allow overriding relevant global print settings as set by @code{set
8048backtrace} and @code{set print} subcommands:
8049
8050@table @code
8051@item -past-main [@code{on}|@code{off}]
8052Set whether backtraces should continue past @code{main}. Related setting:
8053@ref{set backtrace past-main}.
8054
8055@item -past-entry [@code{on}|@code{off}]
8056Set whether backtraces should continue past the entry point of a program.
8057Related setting: @ref{set backtrace past-entry}.
8058
8059@item -entry-values @code{no}|@code{only}|@code{preferred}|@code{if-needed}|@code{both}|@code{compact}|@code{default}
8060Set printing of function arguments at function entry.
8061Related setting: @ref{set print entry-values}.
8062
8063@item -frame-arguments @code{all}|@code{scalars}|@code{none}
8064Set printing of non-scalar frame arguments.
8065Related setting: @ref{set print frame-arguments}.
8066
8067@item -raw-frame-arguments [@code{on}|@code{off}]
8068Set whether to print frame arguments in raw form.
8069Related setting: @ref{set print raw-frame-arguments}.
bc4268a5
PW
8070
8071@item -frame-info @code{auto}|@code{source-line}|@code{location}|@code{source-and-location}|@code{location-and-address}|@code{short-location}
8072Set printing of frame information.
8073Related setting: @ref{set print frame-info}.
3345721a
PA
8074@end table
8075
8076The optional @var{qualifier} is maintained for backward compatibility.
8077It can be one of the following:
8078
8079@table @code
8080@item full
8081Equivalent to the @code{-full} option.
8082
8083@item no-filters
8084Equivalent to the @code{-no-filters} option.
8085
8086@item hide
8087Equivalent to the @code{-hide} option.
8088@end table
8089
ea3b0687 8090@end table
c906108c
SS
8091
8092@kindex where
8093@kindex info stack
c906108c
SS
8094The names @code{where} and @code{info stack} (abbreviated @code{info s})
8095are additional aliases for @code{backtrace}.
8096
839c27b7
EZ
8097@cindex multiple threads, backtrace
8098In a multi-threaded program, @value{GDBN} by default shows the
8099backtrace only for the current thread. To display the backtrace for
8100several or all of the threads, use the command @code{thread apply}
8101(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
8102apply all backtrace}, @value{GDBN} will display the backtrace for all
8103the threads; this is handy when you debug a core dump of a
8104multi-threaded program.
8105
c906108c
SS
8106Each line in the backtrace shows the frame number and the function name.
8107The program counter value is also shown---unless you use @code{set
8108print address off}. The backtrace also shows the source file name and
8109line number, as well as the arguments to the function. The program
8110counter value is omitted if it is at the beginning of the code for that
8111line number.
8112
8113Here is an example of a backtrace. It was made with the command
8114@samp{bt 3}, so it shows the innermost three frames.
8115
8116@smallexample
8117@group
5d161b24 8118#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c 8119 at builtin.c:993
4f5376b2 8120#1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
c906108c
SS
8121#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
8122 at macro.c:71
8123(More stack frames follow...)
8124@end group
8125@end smallexample
8126
8127@noindent
8128The display for frame zero does not begin with a program counter
8129value, indicating that your program has stopped at the beginning of the
8130code for line @code{993} of @code{builtin.c}.
8131
4f5376b2
JB
8132@noindent
8133The value of parameter @code{data} in frame 1 has been replaced by
8134@code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
8135only if it is a scalar (integer, pointer, enumeration, etc). See command
8136@kbd{set print frame-arguments} in @ref{Print Settings} for more details
8137on how to configure the way function parameter values are printed.
bc4268a5
PW
8138The command @kbd{set print frame-info} (@pxref{Print Settings}) controls
8139what frame information is printed.
4f5376b2 8140
585fdaa1 8141@cindex optimized out, in backtrace
18999be5
EZ
8142@cindex function call arguments, optimized out
8143If your program was compiled with optimizations, some compilers will
8144optimize away arguments passed to functions if those arguments are
8145never used after the call. Such optimizations generate code that
8146passes arguments through registers, but doesn't store those arguments
8147in the stack frame. @value{GDBN} has no way of displaying such
8148arguments in stack frames other than the innermost one. Here's what
8149such a backtrace might look like:
8150
8151@smallexample
8152@group
8153#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8154 at builtin.c:993
585fdaa1
PA
8155#1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
8156#2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
18999be5
EZ
8157 at macro.c:71
8158(More stack frames follow...)
8159@end group
8160@end smallexample
8161
8162@noindent
8163The values of arguments that were not saved in their stack frames are
585fdaa1 8164shown as @samp{<optimized out>}.
18999be5
EZ
8165
8166If you need to display the values of such optimized-out arguments,
8167either deduce that from other variables whose values depend on the one
8168you are interested in, or recompile without optimizations.
8169
a8f24a35
EZ
8170@cindex backtrace beyond @code{main} function
8171@cindex program entry point
8172@cindex startup code, and backtrace
25d29d70
AC
8173Most programs have a standard user entry point---a place where system
8174libraries and startup code transition into user code. For C this is
d416eeec
EZ
8175@code{main}@footnote{
8176Note that embedded programs (the so-called ``free-standing''
8177environment) are not required to have a @code{main} function as the
8178entry point. They could even have multiple entry points.}.
8179When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
8180it will terminate the backtrace, to avoid tracing into highly
8181system-specific (and generally uninteresting) code.
8182
8183If you need to examine the startup code, or limit the number of levels
8184in a backtrace, you can change this behavior:
95f90d25
DJ
8185
8186@table @code
25d29d70
AC
8187@item set backtrace past-main
8188@itemx set backtrace past-main on
3345721a 8189@anchor{set backtrace past-main}
4644b6e3 8190@kindex set backtrace
25d29d70
AC
8191Backtraces will continue past the user entry point.
8192
8193@item set backtrace past-main off
95f90d25
DJ
8194Backtraces will stop when they encounter the user entry point. This is the
8195default.
8196
25d29d70 8197@item show backtrace past-main
4644b6e3 8198@kindex show backtrace
25d29d70
AC
8199Display the current user entry point backtrace policy.
8200
2315ffec
RC
8201@item set backtrace past-entry
8202@itemx set backtrace past-entry on
3345721a 8203@anchor{set backtrace past-entry}
a8f24a35 8204Backtraces will continue past the internal entry point of an application.
2315ffec
RC
8205This entry point is encoded by the linker when the application is built,
8206and is likely before the user entry point @code{main} (or equivalent) is called.
8207
8208@item set backtrace past-entry off
d3e8051b 8209Backtraces will stop when they encounter the internal entry point of an
2315ffec
RC
8210application. This is the default.
8211
8212@item show backtrace past-entry
8213Display the current internal entry point backtrace policy.
8214
25d29d70
AC
8215@item set backtrace limit @var{n}
8216@itemx set backtrace limit 0
f81d1120 8217@itemx set backtrace limit unlimited
3345721a 8218@anchor{set backtrace limit}
25d29d70 8219@cindex backtrace limit
f81d1120
PA
8220Limit the backtrace to @var{n} levels. A value of @code{unlimited}
8221or zero means unlimited levels.
95f90d25 8222
25d29d70
AC
8223@item show backtrace limit
8224Display the current limit on backtrace levels.
95f90d25
DJ
8225@end table
8226
1b56eb55
JK
8227You can control how file names are displayed.
8228
8229@table @code
8230@item set filename-display
8231@itemx set filename-display relative
8232@cindex filename-display
8233Display file names relative to the compilation directory. This is the default.
8234
8235@item set filename-display basename
8236Display only basename of a filename.
8237
8238@item set filename-display absolute
8239Display an absolute filename.
8240
8241@item show filename-display
8242Show the current way to display filenames.
8243@end table
8244
6d2ebf8b 8245@node Selection
79a6e687 8246@section Selecting a Frame
c906108c
SS
8247
8248Most commands for examining the stack and other data in your program work on
8249whichever stack frame is selected at the moment. Here are the commands for
8250selecting a stack frame; all of them finish by printing a brief description
8251of the stack frame just selected.
8252
8253@table @code
d4f3574e 8254@kindex frame@r{, selecting}
41afff9a 8255@kindex f @r{(@code{frame})}
f67ffa6a
AB
8256@item frame @r{[} @var{frame-selection-spec} @r{]}
8257@item f @r{[} @var{frame-selection-spec} @r{]}
8258The @command{frame} command allows different stack frames to be
8259selected. The @var{frame-selection-spec} can be any of the following:
8260
8261@table @code
8262@kindex frame level
8263@item @var{num}
8264@item level @var{num}
8265Select frame level @var{num}. Recall that frame zero is the innermost
c906108c 8266(currently executing) frame, frame one is the frame that called the
f67ffa6a
AB
8267innermost one, and so on. The highest level frame is usually the one
8268for @code{main}.
8269
8270As this is the most common method of navigating the frame stack, the
8271string @command{level} can be omitted. For example, the following two
8272commands are equivalent:
8273
8274@smallexample
8275(@value{GDBP}) frame 3
8276(@value{GDBP}) frame level 3
8277@end smallexample
8278
8279@kindex frame address
8280@item address @var{stack-address}
8281Select the frame with stack address @var{stack-address}. The
8282@var{stack-address} for a frame can be seen in the output of
8283@command{info frame}, for example:
8284
8285@smallexample
8286(gdb) info frame
8287Stack level 1, frame at 0x7fffffffda30:
8288 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
8289 tail call frame, caller of frame at 0x7fffffffda30
8290 source language c++.
8291 Arglist at unknown address.
8292 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
8293@end smallexample
8294
8295The @var{stack-address} for this frame is @code{0x7fffffffda30} as
8296indicated by the line:
8297
8298@smallexample
8299Stack level 1, frame at 0x7fffffffda30:
8300@end smallexample
8301
8302@kindex frame function
8303@item function @var{function-name}
8304Select the stack frame for function @var{function-name}. If there are
8305multiple stack frames for function @var{function-name} then the inner
8306most stack frame is selected.
8307
8308@kindex frame view
8309@item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
8310View a frame that is not part of @value{GDBN}'s backtrace. The frame
8311viewed has stack address @var{stack-addr}, and optionally, a program
8312counter address of @var{pc-addr}.
8313
8314This is useful mainly if the chaining of stack frames has been
8315damaged by a bug, making it impossible for @value{GDBN} to assign
8316numbers properly to all frames. In addition, this can be useful
8317when your program has multiple stacks and switches between them.
8318
8319When viewing a frame outside the current backtrace using
8320@command{frame view} then you can always return to the original
8321stack using one of the previous stack frame selection instructions,
8322for example @command{frame level 0}.
8323
8324@end table
c906108c
SS
8325
8326@kindex up
8327@item up @var{n}
697aa1b7
EZ
8328Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
8329numbers @var{n}, this advances toward the outermost frame, to higher
8330frame numbers, to frames that have existed longer.
c906108c
SS
8331
8332@kindex down
41afff9a 8333@kindex do @r{(@code{down})}
c906108c 8334@item down @var{n}
697aa1b7
EZ
8335Move @var{n} frames down the stack; @var{n} defaults to 1. For
8336positive numbers @var{n}, this advances toward the innermost frame, to
8337lower frame numbers, to frames that were created more recently.
8338You may abbreviate @code{down} as @code{do}.
c906108c
SS
8339@end table
8340
8341All of these commands end by printing two lines of output describing the
8342frame. The first line shows the frame number, the function name, the
8343arguments, and the source file and line number of execution in that
5d161b24 8344frame. The second line shows the text of that source line.
c906108c
SS
8345
8346@need 1000
8347For example:
8348
8349@smallexample
8350@group
8351(@value{GDBP}) up
8352#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
8353 at env.c:10
835410 read_input_file (argv[i]);
8355@end group
8356@end smallexample
8357
8358After such a printout, the @code{list} command with no arguments
8359prints ten lines centered on the point of execution in the frame.
87885426
FN
8360You can also edit the program at the point of execution with your favorite
8361editing program by typing @code{edit}.
79a6e687 8362@xref{List, ,Printing Source Lines},
87885426 8363for details.
c906108c
SS
8364
8365@table @code
fc58fa65 8366@kindex select-frame
f67ffa6a 8367@item select-frame @r{[} @var{frame-selection-spec} @r{]}
fc58fa65
AB
8368The @code{select-frame} command is a variant of @code{frame} that does
8369not display the new frame after selecting it. This command is
8370intended primarily for use in @value{GDBN} command scripts, where the
f67ffa6a
AB
8371output might be unnecessary and distracting. The
8372@var{frame-selection-spec} is as for the @command{frame} command
8373described in @ref{Selection, ,Selecting a Frame}.
fc58fa65 8374
c906108c
SS
8375@kindex down-silently
8376@kindex up-silently
8377@item up-silently @var{n}
8378@itemx down-silently @var{n}
8379These two commands are variants of @code{up} and @code{down},
8380respectively; they differ in that they do their work silently, without
8381causing display of the new frame. They are intended primarily for use
8382in @value{GDBN} command scripts, where the output might be unnecessary and
8383distracting.
8384@end table
8385
6d2ebf8b 8386@node Frame Info
79a6e687 8387@section Information About a Frame
c906108c
SS
8388
8389There are several other commands to print information about the selected
8390stack frame.
8391
8392@table @code
8393@item frame
8394@itemx f
8395When used without any argument, this command does not change which
8396frame is selected, but prints a brief description of the currently
8397selected stack frame. It can be abbreviated @code{f}. With an
8398argument, this command is used to select a stack frame.
79a6e687 8399@xref{Selection, ,Selecting a Frame}.
c906108c
SS
8400
8401@kindex info frame
41afff9a 8402@kindex info f @r{(@code{info frame})}
c906108c
SS
8403@item info frame
8404@itemx info f
8405This command prints a verbose description of the selected stack frame,
8406including:
8407
8408@itemize @bullet
5d161b24
DB
8409@item
8410the address of the frame
c906108c
SS
8411@item
8412the address of the next frame down (called by this frame)
8413@item
8414the address of the next frame up (caller of this frame)
8415@item
8416the language in which the source code corresponding to this frame is written
8417@item
8418the address of the frame's arguments
8419@item
d4f3574e
SS
8420the address of the frame's local variables
8421@item
c906108c
SS
8422the program counter saved in it (the address of execution in the caller frame)
8423@item
8424which registers were saved in the frame
8425@end itemize
8426
8427@noindent The verbose description is useful when
8428something has gone wrong that has made the stack format fail to fit
8429the usual conventions.
8430
f67ffa6a
AB
8431@item info frame @r{[} @var{frame-selection-spec} @r{]}
8432@itemx info f @r{[} @var{frame-selection-spec} @r{]}
8433Print a verbose description of the frame selected by
8434@var{frame-selection-spec}. The @var{frame-selection-spec} is the
8435same as for the @command{frame} command (@pxref{Selection, ,Selecting
8436a Frame}). The selected frame remains unchanged by this command.
c906108c
SS
8437
8438@kindex info args
d321477b 8439@item info args [-q]
c906108c
SS
8440Print the arguments of the selected frame, each on a separate line.
8441
d321477b
PW
8442The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8443printing header information and messages explaining why no argument
8444have been printed.
8445
8446@item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
8447Like @kbd{info args}, but only print the arguments selected
8448with the provided regexp(s).
8449
8450If @var{regexp} is provided, print only the arguments whose names
8451match the regular expression @var{regexp}.
8452
8453If @var{type_regexp} is provided, print only the arguments whose
8454types, as printed by the @code{whatis} command, match
8455the regular expression @var{type_regexp}.
8456If @var{type_regexp} contains space(s), it should be enclosed in
8457quote characters. If needed, use backslash to escape the meaning
8458of special characters or quotes.
8459
8460If both @var{regexp} and @var{type_regexp} are provided, an argument
8461is printed only if its name matches @var{regexp} and its type matches
8462@var{type_regexp}.
8463
8464@item info locals [-q]
c906108c
SS
8465@kindex info locals
8466Print the local variables of the selected frame, each on a separate
8467line. These are all variables (declared either static or automatic)
8468accessible at the point of execution of the selected frame.
8469
d321477b
PW
8470The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8471printing header information and messages explaining why no local variables
8472have been printed.
8473
8474@item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
8475Like @kbd{info locals}, but only print the local variables selected
8476with the provided regexp(s).
8477
8478If @var{regexp} is provided, print only the local variables whose names
8479match the regular expression @var{regexp}.
8480
8481If @var{type_regexp} is provided, print only the local variables whose
8482types, as printed by the @code{whatis} command, match
8483the regular expression @var{type_regexp}.
8484If @var{type_regexp} contains space(s), it should be enclosed in
8485quote characters. If needed, use backslash to escape the meaning
8486of special characters or quotes.
8487
8488If both @var{regexp} and @var{type_regexp} are provided, a local variable
8489is printed only if its name matches @var{regexp} and its type matches
8490@var{type_regexp}.
8491
8492The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8493combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8494For example, your program might use Resource Acquisition Is
8495Initialization types (RAII) such as @code{lock_something_t}: each
8496local variable of type @code{lock_something_t} automatically places a
8497lock that is destroyed when the variable goes out of scope. You can
8498then list all acquired locks in your program by doing
8499@smallexample
8500thread apply all -s frame apply all -s info locals -q -t lock_something_t
8501@end smallexample
8502@noindent
8503or the equivalent shorter form
8504@smallexample
8505tfaas i lo -q -t lock_something_t
8506@end smallexample
8507
c906108c
SS
8508@end table
8509
0a232300
PW
8510@node Frame Apply
8511@section Applying a Command to Several Frames.
8512@kindex frame apply
8513@cindex apply command to several frames
8514@table @code
3345721a 8515@item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{option}]@dots{} @var{command}
0a232300
PW
8516The @code{frame apply} command allows you to apply the named
8517@var{command} to one or more frames.
8518
8519@table @code
8520@item @code{all}
8521Specify @code{all} to apply @var{command} to all frames.
8522
8523@item @var{count}
8524Use @var{count} to apply @var{command} to the innermost @var{count}
8525frames, where @var{count} is a positive number.
8526
8527@item @var{-count}
8528Use @var{-count} to apply @var{command} to the outermost @var{count}
8529frames, where @var{count} is a positive number.
8530
8531@item @code{level}
8532Use @code{level} to apply @var{command} to the set of frames identified
8533by the @var{level} list. @var{level} is a frame level or a range of frame
8534levels as @var{level1}-@var{level2}. The frame level is the number shown
8535in the first field of the @samp{backtrace} command output.
8536E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8537at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8538
8539@end table
8540
0a232300
PW
8541Note that the frames on which @code{frame apply} applies a command are
8542also influenced by the @code{set backtrace} settings such as @code{set
3345721a 8543backtrace past-main} and @code{set backtrace limit N}.
0a232300
PW
8544@xref{Backtrace,,Backtraces}.
8545
3345721a
PA
8546The @code{frame apply} command also supports a number of options that
8547allow overriding relevant @code{set backtrace} settings:
8548
8549@table @code
8550@item -past-main [@code{on}|@code{off}]
8551Whether backtraces should continue past @code{main}.
8552Related setting: @ref{set backtrace past-main}.
8553
8554@item -past-entry [@code{on}|@code{off}]
8555Whether backtraces should continue past the entry point of a program.
8556Related setting: @ref{set backtrace past-entry}.
8557@end table
0a232300
PW
8558
8559By default, @value{GDBN} displays some frame information before the
8560output produced by @var{command}, and an error raised during the
8561execution of a @var{command} will abort @code{frame apply}. The
3345721a 8562following options can be used to fine-tune these behaviors:
0a232300
PW
8563
8564@table @code
8565@item -c
8566The flag @code{-c}, which stands for @samp{continue}, causes any
8567errors in @var{command} to be displayed, and the execution of
8568@code{frame apply} then continues.
8569@item -s
8570The flag @code{-s}, which stands for @samp{silent}, causes any errors
8571or empty output produced by a @var{command} to be silently ignored.
8572That is, the execution continues, but the frame information and errors
8573are not printed.
8574@item -q
8575The flag @code{-q} (@samp{quiet}) disables printing the frame
8576information.
8577@end table
8578
8579The following example shows how the flags @code{-c} and @code{-s} are
8580working when applying the command @code{p j} to all frames, where
8581variable @code{j} can only be successfully printed in the outermost
8582@code{#1 main} frame.
8583
8584@smallexample
8585@group
8586(gdb) frame apply all p j
8587#0 some_function (i=5) at fun.c:4
8588No symbol "j" in current context.
8589(gdb) frame apply all -c p j
8590#0 some_function (i=5) at fun.c:4
8591No symbol "j" in current context.
8592#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8593$1 = 5
8594(gdb) frame apply all -s p j
8595#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8596$2 = 5
8597(gdb)
8598@end group
8599@end smallexample
8600
8601By default, @samp{frame apply}, prints the frame location
8602information before the command output:
8603
8604@smallexample
8605@group
8606(gdb) frame apply all p $sp
8607#0 some_function (i=5) at fun.c:4
8608$4 = (void *) 0xffffd1e0
8609#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8610$5 = (void *) 0xffffd1f0
8611(gdb)
8612@end group
8613@end smallexample
8614
3345721a 8615If the flag @code{-q} is given, no frame information is printed:
0a232300
PW
8616@smallexample
8617@group
8618(gdb) frame apply all -q p $sp
8619$12 = (void *) 0xffffd1e0
8620$13 = (void *) 0xffffd1f0
8621(gdb)
8622@end group
8623@end smallexample
8624
3345721a
PA
8625@end table
8626
0a232300
PW
8627@table @code
8628
8629@kindex faas
8630@cindex apply a command to all frames (ignoring errors and empty output)
8631@item faas @var{command}
8632Shortcut for @code{frame apply all -s @var{command}}.
8633Applies @var{command} on all frames, ignoring errors and empty output.
8634
8635It can for example be used to print a local variable or a function
8636argument without knowing the frame where this variable or argument
8637is, using:
8638@smallexample
8639(@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8640@end smallexample
8641
3345721a 8642The @code{faas} command accepts the same options as the @code{frame
ed788fee 8643apply} command. @xref{Frame Apply,,frame apply}.
3345721a 8644
0a232300
PW
8645Note that the command @code{tfaas @var{command}} applies @var{command}
8646on all frames of all threads. See @xref{Threads,,Threads}.
8647@end table
8648
8649
fc58fa65
AB
8650@node Frame Filter Management
8651@section Management of Frame Filters.
8652@cindex managing frame filters
8653
8654Frame filters are Python based utilities to manage and decorate the
8655output of frames. @xref{Frame Filter API}, for further information.
8656
8657Managing frame filters is performed by several commands available
8658within @value{GDBN}, detailed here.
8659
8660@table @code
8661@kindex info frame-filter
8662@item info frame-filter
8663Print a list of installed frame filters from all dictionaries, showing
8664their name, priority and enabled status.
8665
8666@kindex disable frame-filter
8667@anchor{disable frame-filter all}
8668@item disable frame-filter @var{filter-dictionary} @var{filter-name}
8669Disable a frame filter in the dictionary matching
8670@var{filter-dictionary} and @var{filter-name}. The
8671@var{filter-dictionary} may be @code{all}, @code{global},
8672@code{progspace}, or the name of the object file where the frame filter
8673dictionary resides. When @code{all} is specified, all frame filters
8674across all dictionaries are disabled. The @var{filter-name} is the name
8675of the frame filter and is used when @code{all} is not the option for
8676@var{filter-dictionary}. A disabled frame-filter is not deleted, it
8677may be enabled again later.
8678
8679@kindex enable frame-filter
8680@item enable frame-filter @var{filter-dictionary} @var{filter-name}
8681Enable a frame filter in the dictionary matching
8682@var{filter-dictionary} and @var{filter-name}. The
8683@var{filter-dictionary} may be @code{all}, @code{global},
8684@code{progspace} or the name of the object file where the frame filter
8685dictionary resides. When @code{all} is specified, all frame filters across
8686all dictionaries are enabled. The @var{filter-name} is the name of the frame
8687filter and is used when @code{all} is not the option for
8688@var{filter-dictionary}.
8689
8690Example:
8691
8692@smallexample
8693(gdb) info frame-filter
8694
8695global frame-filters:
8696 Priority Enabled Name
8697 1000 No PrimaryFunctionFilter
8698 100 Yes Reverse
8699
8700progspace /build/test frame-filters:
8701 Priority Enabled Name
8702 100 Yes ProgspaceFilter
8703
8704objfile /build/test frame-filters:
8705 Priority Enabled Name
6b92c0d3 8706 999 Yes BuildProgramFilter
fc58fa65
AB
8707
8708(gdb) disable frame-filter /build/test BuildProgramFilter
8709(gdb) info frame-filter
8710
8711global frame-filters:
8712 Priority Enabled Name
8713 1000 No PrimaryFunctionFilter
8714 100 Yes Reverse
8715
8716progspace /build/test frame-filters:
8717 Priority Enabled Name
8718 100 Yes ProgspaceFilter
8719
8720objfile /build/test frame-filters:
8721 Priority Enabled Name
8722 999 No BuildProgramFilter
8723
8724(gdb) enable frame-filter global PrimaryFunctionFilter
8725(gdb) info frame-filter
8726
8727global frame-filters:
8728 Priority Enabled Name
8729 1000 Yes PrimaryFunctionFilter
8730 100 Yes Reverse
8731
8732progspace /build/test frame-filters:
8733 Priority Enabled Name
8734 100 Yes ProgspaceFilter
8735
8736objfile /build/test frame-filters:
8737 Priority Enabled Name
8738 999 No BuildProgramFilter
8739@end smallexample
8740
8741@kindex set frame-filter priority
8742@item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
8743Set the @var{priority} of a frame filter in the dictionary matching
8744@var{filter-dictionary}, and the frame filter name matching
8745@var{filter-name}. The @var{filter-dictionary} may be @code{global},
8746@code{progspace} or the name of the object file where the frame filter
8747dictionary resides. The @var{priority} is an integer.
8748
8749@kindex show frame-filter priority
8750@item show frame-filter priority @var{filter-dictionary} @var{filter-name}
8751Show the @var{priority} of a frame filter in the dictionary matching
8752@var{filter-dictionary}, and the frame filter name matching
8753@var{filter-name}. The @var{filter-dictionary} may be @code{global},
8754@code{progspace} or the name of the object file where the frame filter
8755dictionary resides.
8756
8757Example:
8758
8759@smallexample
8760(gdb) info frame-filter
8761
8762global frame-filters:
8763 Priority Enabled Name
8764 1000 Yes PrimaryFunctionFilter
8765 100 Yes Reverse
8766
8767progspace /build/test frame-filters:
8768 Priority Enabled Name
8769 100 Yes ProgspaceFilter
8770
8771objfile /build/test frame-filters:
8772 Priority Enabled Name
8773 999 No BuildProgramFilter
8774
8775(gdb) set frame-filter priority global Reverse 50
8776(gdb) info frame-filter
8777
8778global frame-filters:
8779 Priority Enabled Name
8780 1000 Yes PrimaryFunctionFilter
8781 50 Yes Reverse
8782
8783progspace /build/test frame-filters:
8784 Priority Enabled Name
8785 100 Yes ProgspaceFilter
8786
8787objfile /build/test frame-filters:
8788 Priority Enabled Name
8789 999 No BuildProgramFilter
8790@end smallexample
8791@end table
c906108c 8792
6d2ebf8b 8793@node Source
c906108c
SS
8794@chapter Examining Source Files
8795
8796@value{GDBN} can print parts of your program's source, since the debugging
8797information recorded in the program tells @value{GDBN} what source files were
8798used to build it. When your program stops, @value{GDBN} spontaneously prints
8799the line where it stopped. Likewise, when you select a stack frame
79a6e687 8800(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
c906108c
SS
8801execution in that frame has stopped. You can print other portions of
8802source files by explicit command.
8803
7a292a7a 8804If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 8805prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 8806@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
8807
8808@menu
8809* List:: Printing source lines
2a25a5ba 8810* Specify Location:: How to specify code locations
87885426 8811* Edit:: Editing source files
c906108c 8812* Search:: Searching source files
c906108c
SS
8813* Source Path:: Specifying source directories
8814* Machine Code:: Source and machine code
8815@end menu
8816
6d2ebf8b 8817@node List
79a6e687 8818@section Printing Source Lines
c906108c
SS
8819
8820@kindex list
41afff9a 8821@kindex l @r{(@code{list})}
c906108c 8822To print lines from a source file, use the @code{list} command
5d161b24 8823(abbreviated @code{l}). By default, ten lines are printed.
2a25a5ba
EZ
8824There are several ways to specify what part of the file you want to
8825print; see @ref{Specify Location}, for the full list.
c906108c
SS
8826
8827Here are the forms of the @code{list} command most commonly used:
8828
8829@table @code
8830@item list @var{linenum}
8831Print lines centered around line number @var{linenum} in the
8832current source file.
8833
8834@item list @var{function}
8835Print lines centered around the beginning of function
8836@var{function}.
8837
8838@item list
8839Print more lines. If the last lines printed were printed with a
8840@code{list} command, this prints lines following the last lines
8841printed; however, if the last line printed was a solitary line printed
8842as part of displaying a stack frame (@pxref{Stack, ,Examining the
8843Stack}), this prints lines centered around that line.
8844
8845@item list -
8846Print lines just before the lines last printed.
8847@end table
8848
9c16f35a 8849@cindex @code{list}, how many lines to display
c906108c
SS
8850By default, @value{GDBN} prints ten source lines with any of these forms of
8851the @code{list} command. You can change this using @code{set listsize}:
8852
8853@table @code
8854@kindex set listsize
8855@item set listsize @var{count}
f81d1120 8856@itemx set listsize unlimited
c906108c
SS
8857Make the @code{list} command display @var{count} source lines (unless
8858the @code{list} argument explicitly specifies some other number).
f81d1120 8859Setting @var{count} to @code{unlimited} or 0 means there's no limit.
c906108c
SS
8860
8861@kindex show listsize
8862@item show listsize
8863Display the number of lines that @code{list} prints.
8864@end table
8865
8866Repeating a @code{list} command with @key{RET} discards the argument,
8867so it is equivalent to typing just @code{list}. This is more useful
8868than listing the same lines again. An exception is made for an
8869argument of @samp{-}; that argument is preserved in repetition so that
8870each repetition moves up in the source file.
8871
c906108c 8872In general, the @code{list} command expects you to supply zero, one or two
629500fa 8873@dfn{locations}. Locations specify source lines; there are several ways
2a25a5ba
EZ
8874of writing them (@pxref{Specify Location}), but the effect is always
8875to specify some source line.
8876
c906108c
SS
8877Here is a complete description of the possible arguments for @code{list}:
8878
8879@table @code
629500fa
KS
8880@item list @var{location}
8881Print lines centered around the line specified by @var{location}.
c906108c
SS
8882
8883@item list @var{first},@var{last}
8884Print lines from @var{first} to @var{last}. Both arguments are
629500fa
KS
8885locations. When a @code{list} command has two locations, and the
8886source file of the second location is omitted, this refers to
8887the same source file as the first location.
c906108c
SS
8888
8889@item list ,@var{last}
8890Print lines ending with @var{last}.
8891
8892@item list @var{first},
8893Print lines starting with @var{first}.
8894
8895@item list +
8896Print lines just after the lines last printed.
8897
8898@item list -
8899Print lines just before the lines last printed.
8900
8901@item list
8902As described in the preceding table.
8903@end table
8904
2a25a5ba
EZ
8905@node Specify Location
8906@section Specifying a Location
8907@cindex specifying location
629500fa
KS
8908@cindex location
8909@cindex source location
8910
2a25a5ba
EZ
8911Several @value{GDBN} commands accept arguments that specify a location
8912of your program's code. Since @value{GDBN} is a source-level
629500fa
KS
8913debugger, a location usually specifies some line in the source code.
8914Locations may be specified using three different formats:
8915linespec locations, explicit locations, or address locations.
c906108c 8916
04de9f3e
AB
8917@menu
8918* Linespec Locations:: Linespec locations
8919* Explicit Locations:: Explicit locations
8920* Address Locations:: Address locations
8921@end menu
8922
629500fa
KS
8923@node Linespec Locations
8924@subsection Linespec Locations
8925@cindex linespec locations
8926
8927A @dfn{linespec} is a colon-separated list of source location parameters such
8928as file name, function name, etc. Here are all the different ways of
8929specifying a linespec:
c906108c 8930
2a25a5ba
EZ
8931@table @code
8932@item @var{linenum}
8933Specifies the line number @var{linenum} of the current source file.
c906108c 8934
2a25a5ba
EZ
8935@item -@var{offset}
8936@itemx +@var{offset}
8937Specifies the line @var{offset} lines before or after the @dfn{current
8938line}. For the @code{list} command, the current line is the last one
8939printed; for the breakpoint commands, this is the line at which
8940execution stopped in the currently selected @dfn{stack frame}
8941(@pxref{Frames, ,Frames}, for a description of stack frames.) When
8942used as the second of the two linespecs in a @code{list} command,
8943this specifies the line @var{offset} lines up or down from the first
8944linespec.
8945
8946@item @var{filename}:@var{linenum}
8947Specifies the line @var{linenum} in the source file @var{filename}.
4aac40c8
TT
8948If @var{filename} is a relative file name, then it will match any
8949source file name with the same trailing components. For example, if
8950@var{filename} is @samp{gcc/expr.c}, then it will match source file
8951name of @file{/build/trunk/gcc/expr.c}, but not
8952@file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
c906108c
SS
8953
8954@item @var{function}
8955Specifies the line that begins the body of the function @var{function}.
2a25a5ba 8956For example, in C, this is the line with the open brace.
c906108c 8957
a20714ff
PA
8958By default, in C@t{++} and Ada, @var{function} is interpreted as
8959specifying all functions named @var{function} in all scopes. For
8960C@t{++}, this means in all namespaces and classes. For Ada, this
8961means in all packages.
8962
8963For example, assuming a program with C@t{++} symbols named
8964@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8965func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
8966
8967Commands that accept a linespec let you override this with the
8968@code{-qualified} option. For example, @w{@kbd{break -qualified
8969func}} sets a breakpoint on a free-function named @code{func} ignoring
8970any C@t{++} class methods and namespace functions called @code{func}.
8971
8972@xref{Explicit Locations}.
8973
9ef07c8c
TT
8974@item @var{function}:@var{label}
8975Specifies the line where @var{label} appears in @var{function}.
8976
c906108c 8977@item @var{filename}:@var{function}
2a25a5ba
EZ
8978Specifies the line that begins the body of the function @var{function}
8979in the file @var{filename}. You only need the file name with a
8980function name to avoid ambiguity when there are identically named
8981functions in different source files.
c906108c 8982
0f5238ed 8983@item @var{label}
629500fa
KS
8984Specifies the line at which the label named @var{label} appears
8985in the function corresponding to the currently selected stack frame.
8986If there is no current selected stack frame (for instance, if the inferior
8987is not running), then @value{GDBN} will not search for a label.
8988
8989@cindex breakpoint at static probe point
8990@item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
8991The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
8992applications to embed static probes. @xref{Static Probe Points}, for more
8993information on finding and using static probes. This form of linespec
8994specifies the location of such a static probe.
8995
8996If @var{objfile} is given, only probes coming from that shared library
8997or executable matching @var{objfile} as a regular expression are considered.
8998If @var{provider} is given, then only probes from that provider are considered.
8999If several probes match the spec, @value{GDBN} will insert a breakpoint at
9000each one of those probes.
9001@end table
9002
9003@node Explicit Locations
9004@subsection Explicit Locations
9005@cindex explicit locations
9006
9007@dfn{Explicit locations} allow the user to directly specify the source
9008location's parameters using option-value pairs.
9009
9010Explicit locations are useful when several functions, labels, or
9011file names have the same name (base name for files) in the program's
9012sources. In these cases, explicit locations point to the source
9013line you meant more accurately and unambiguously. Also, using
9014explicit locations might be faster in large programs.
9015
9016For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
9017defined in the file named @file{foo} or the label @code{bar} in a function
9018named @code{foo}. @value{GDBN} must search either the file system or
9019the symbol table to know.
9020
9021The list of valid explicit location options is summarized in the
9022following table:
9023
9024@table @code
9025@item -source @var{filename}
9026The value specifies the source file name. To differentiate between
9027files with the same base name, prepend as many directories as is necessary
9028to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
9029@value{GDBN} will use the first file it finds with the given base
9030name. This option requires the use of either @code{-function} or @code{-line}.
9031
9032@item -function @var{function}
9033The value specifies the name of a function. Operations
9034on function locations unmodified by other options (such as @code{-label}
9035or @code{-line}) refer to the line that begins the body of the function.
9036In C, for example, this is the line with the open brace.
9037
a20714ff
PA
9038By default, in C@t{++} and Ada, @var{function} is interpreted as
9039specifying all functions named @var{function} in all scopes. For
9040C@t{++}, this means in all namespaces and classes. For Ada, this
9041means in all packages.
9042
9043For example, assuming a program with C@t{++} symbols named
9044@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
9045-function func}} and @w{@kbd{break -function B::func}} set a
9046breakpoint on both symbols.
9047
9048You can use the @kbd{-qualified} flag to override this (see below).
9049
9050@item -qualified
9051
9052This flag makes @value{GDBN} interpret a function name specified with
9053@kbd{-function} as a complete fully-qualified name.
9054
9055For example, assuming a C@t{++} program with symbols named
9056@code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
9057-function B::func}} command sets a breakpoint on @code{B::func}, only.
9058
9059(Note: the @kbd{-qualified} option can precede a linespec as well
9060(@pxref{Linespec Locations}), so the particular example above could be
9061simplified as @w{@kbd{break -qualified B::func}}.)
9062
629500fa
KS
9063@item -label @var{label}
9064The value specifies the name of a label. When the function
9065name is not specified, the label is searched in the function of the currently
9066selected stack frame.
9067
9068@item -line @var{number}
9069The value specifies a line offset for the location. The offset may either
9070be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
9071the command. When specified without any other options, the line offset is
9072relative to the current line.
9073@end table
9074
9075Explicit location options may be abbreviated by omitting any non-unique
a20714ff 9076trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
629500fa
KS
9077
9078@node Address Locations
9079@subsection Address Locations
9080@cindex address locations
9081
9082@dfn{Address locations} indicate a specific program address. They have
9083the generalized form *@var{address}.
9084
9085For line-oriented commands, such as @code{list} and @code{edit}, this
9086specifies a source line that contains @var{address}. For @code{break} and
9087other breakpoint-oriented commands, this can be used to set breakpoints in
2a25a5ba
EZ
9088parts of your program which do not have debugging information or
9089source files.
9090
9091Here @var{address} may be any expression valid in the current working
9092language (@pxref{Languages, working language}) that specifies a code
5fa54e5d 9093address. In addition, as a convenience, @value{GDBN} extends the
629500fa
KS
9094semantics of expressions used in locations to cover several situations
9095that frequently occur during debugging. Here are the various forms
5fa54e5d 9096of @var{address}:
2a25a5ba
EZ
9097
9098@table @code
9099@item @var{expression}
9100Any expression valid in the current working language.
9101
9102@item @var{funcaddr}
9103An address of a function or procedure derived from its name. In C,
9c37b5ae 9104C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
2a25a5ba
EZ
9105simply the function's name @var{function} (and actually a special case
9106of a valid expression). In Pascal and Modula-2, this is
9107@code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
9108(although the Pascal form also works).
9109
9110This form specifies the address of the function's first instruction,
9111before the stack frame and arguments have been set up.
9112
9a284c97 9113@item '@var{filename}':@var{funcaddr}
2a25a5ba
EZ
9114Like @var{funcaddr} above, but also specifies the name of the source
9115file explicitly. This is useful if the name of the function does not
9116specify the function unambiguously, e.g., if there are several
9117functions with identical names in different source files.
c906108c
SS
9118@end table
9119
87885426 9120@node Edit
79a6e687 9121@section Editing Source Files
87885426
FN
9122@cindex editing source files
9123
9124@kindex edit
9125@kindex e @r{(@code{edit})}
9126To edit the lines in a source file, use the @code{edit} command.
9127The editing program of your choice
9128is invoked with the current line set to
9129the active line in the program.
9130Alternatively, there are several ways to specify what part of the file you
2a25a5ba 9131want to print if you want to see other parts of the program:
87885426
FN
9132
9133@table @code
2a25a5ba
EZ
9134@item edit @var{location}
9135Edit the source file specified by @code{location}. Editing starts at
9136that @var{location}, e.g., at the specified source line of the
9137specified file. @xref{Specify Location}, for all the possible forms
9138of the @var{location} argument; here are the forms of the @code{edit}
9139command most commonly used:
87885426 9140
2a25a5ba 9141@table @code
87885426
FN
9142@item edit @var{number}
9143Edit the current source file with @var{number} as the active line number.
9144
9145@item edit @var{function}
9146Edit the file containing @var{function} at the beginning of its definition.
2a25a5ba 9147@end table
87885426 9148
87885426
FN
9149@end table
9150
79a6e687 9151@subsection Choosing your Editor
87885426
FN
9152You can customize @value{GDBN} to use any editor you want
9153@footnote{
9154The only restriction is that your editor (say @code{ex}), recognizes the
9155following command-line syntax:
10998722 9156@smallexample
87885426 9157ex +@var{number} file
10998722 9158@end smallexample
15387254
EZ
9159The optional numeric value +@var{number} specifies the number of the line in
9160the file where to start editing.}.
9161By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
9162by setting the environment variable @code{EDITOR} before using
9163@value{GDBN}. For example, to configure @value{GDBN} to use the
9164@code{vi} editor, you could use these commands with the @code{sh} shell:
9165@smallexample
87885426
FN
9166EDITOR=/usr/bin/vi
9167export EDITOR
15387254 9168gdb @dots{}
10998722 9169@end smallexample
87885426 9170or in the @code{csh} shell,
10998722 9171@smallexample
87885426 9172setenv EDITOR /usr/bin/vi
15387254 9173gdb @dots{}
10998722 9174@end smallexample
87885426 9175
6d2ebf8b 9176@node Search
79a6e687 9177@section Searching Source Files
15387254 9178@cindex searching source files
c906108c
SS
9179
9180There are two commands for searching through the current source file for a
9181regular expression.
9182
9183@table @code
9184@kindex search
9185@kindex forward-search
1e96de83 9186@kindex fo @r{(@code{forward-search})}
c906108c
SS
9187@item forward-search @var{regexp}
9188@itemx search @var{regexp}
9189The command @samp{forward-search @var{regexp}} checks each line,
9190starting with the one following the last line listed, for a match for
5d161b24 9191@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
9192synonym @samp{search @var{regexp}} or abbreviate the command name as
9193@code{fo}.
9194
09d4efe1 9195@kindex reverse-search
c906108c
SS
9196@item reverse-search @var{regexp}
9197The command @samp{reverse-search @var{regexp}} checks each line, starting
9198with the one before the last line listed and going backward, for a match
9199for @var{regexp}. It lists the line that is found. You can abbreviate
9200this command as @code{rev}.
9201@end table
c906108c 9202
6d2ebf8b 9203@node Source Path
79a6e687 9204@section Specifying Source Directories
c906108c
SS
9205
9206@cindex source path
9207@cindex directories for source files
9208Executable programs sometimes do not record the directories of the source
9209files from which they were compiled, just the names. Even when they do,
9210the directories could be moved between the compilation and your debugging
9211session. @value{GDBN} has a list of directories to search for source files;
9212this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
9213it tries all the directories in the list, in the order they are present
0b66e38c
EZ
9214in the list, until it finds a file with the desired name.
9215
9216For example, suppose an executable references the file
f1b620e9
MG
9217@file{/usr/src/foo-1.0/lib/foo.c}, does not record a compilation
9218directory, and the @dfn{source path} is @file{/mnt/cross}.
9219@value{GDBN} would look for the source file in the following
9220locations:
9221
9222@enumerate
9223
9224@item @file{/usr/src/foo-1.0/lib/foo.c}
9225@item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9226@item @file{/mnt/cross/foo.c}
9227
9228@end enumerate
9229
9230If the source file is not present at any of the above locations then
9231an error is printed. @value{GDBN} does not look up the parts of the
0b66e38c
EZ
9232source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
9233Likewise, the subdirectories of the source path are not searched: if
9234the source path is @file{/mnt/cross}, and the binary refers to
9235@file{foo.c}, @value{GDBN} would not find it under
9236@file{/mnt/cross/usr/src/foo-1.0/lib}.
9237
9238Plain file names, relative file names with leading directories, file
f1b620e9
MG
9239names containing dots, etc.@: are all treated as described above,
9240except that non-absolute file names are not looked up literally. If
9241the @dfn{source path} is @file{/mnt/cross}, the source file is
9242recorded as @file{../lib/foo.c}, and no compilation directory is
9243recorded, then @value{GDBN} will search in the following locations:
9244
9245@enumerate
9246
9247@item @file{/mnt/cross/../lib/foo.c}
9248@item @file{/mnt/cross/foo.c}
9249
9250@end enumerate
9251
9252@kindex cdir
9253@kindex cwd
9254@vindex $cdir@r{, convenience variable}
9255@vindex $cwd@r{, convenience variable}
9256@cindex compilation directory
9257@cindex current directory
9258@cindex working directory
9259@cindex directory, current
9260@cindex directory, compilation
9261The @dfn{source path} will always include two special entries
9262@samp{$cdir} and @samp{$cwd}, these refer to the compilation directory
9263(if one is recorded) and the current working directory respectively.
9264
9265@samp{$cdir} causes @value{GDBN} to search within the compilation
9266directory, if one is recorded in the debug information. If no
9267compilation directory is recorded in the debug information then
9268@samp{$cdir} is ignored.
9269
9270@samp{$cwd} is not the same as @samp{.}---the former tracks the
9271current working directory as it changes during your @value{GDBN}
9272session, while the latter is immediately expanded to the current
9273directory at the time you add an entry to the source path.
9274
9275If a compilation directory is recorded in the debug information, and
9276@value{GDBN} has not found the source file after the first search
9277using @dfn{source path}, then @value{GDBN} will combine the
9278compilation directory and the filename, and then search for the source
9279file again using the @dfn{source path}.
9280
9281For example, if the executable records the source file as
9282@file{/usr/src/foo-1.0/lib/foo.c}, the compilation directory is
9283recorded as @file{/project/build}, and the @dfn{source path} is
9284@file{/mnt/cross:$cdir:$cwd} while the current working directory of
9285the @value{GDBN} session is @file{/home/user}, then @value{GDBN} will
6b92c0d3 9286search for the source file in the following locations:
f1b620e9
MG
9287
9288@enumerate
9289
9290@item @file{/usr/src/foo-1.0/lib/foo.c}
9291@item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9292@item @file{/project/build/usr/src/foo-1.0/lib/foo.c}
9293@item @file{/home/user/usr/src/foo-1.0/lib/foo.c}
9294@item @file{/mnt/cross/project/build/usr/src/foo-1.0/lib/foo.c}
9295@item @file{/project/build/project/build/usr/src/foo-1.0/lib/foo.c}
9296@item @file{/home/user/project/build/usr/src/foo-1.0/lib/foo.c}
9297@item @file{/mnt/cross/foo.c}
9298@item @file{/project/build/foo.c}
9299@item @file{/home/user/foo.c}
9300
9301@end enumerate
9302
9303If the file name in the previous example had been recorded in the
9304executable as a relative path rather than an absolute path, then the
9305first look up would not have occurred, but all of the remaining steps
9306would be similar.
9307
9308When searching for source files on MS-DOS and MS-Windows, where
9309absolute paths start with a drive letter (e.g.
9310@file{C:/project/foo.c}), @value{GDBN} will remove the drive letter
9311from the file name before appending it to a search directory from
9312@dfn{source path}; for instance if the executable references the
9313source file @file{C:/project/foo.c} and @dfn{source path} is set to
9314@file{D:/mnt/cross}, then @value{GDBN} will search in the following
9315locations for the source file:
9316
9317@enumerate
9318
9319@item @file{C:/project/foo.c}
9320@item @file{D:/mnt/cross/project/foo.c}
9321@item @file{D:/mnt/cross/foo.c}
9322
9323@end enumerate
0b66e38c
EZ
9324
9325Note that the executable search path is @emph{not} used to locate the
cd852561 9326source files.
c906108c
SS
9327
9328Whenever you reset or rearrange the source path, @value{GDBN} clears out
9329any information it has cached about where source files are found and where
9330each line is in the file.
9331
9332@kindex directory
9333@kindex dir
f1b620e9
MG
9334When you start @value{GDBN}, its source path includes only @samp{$cdir}
9335and @samp{$cwd}, in that order.
c906108c
SS
9336To add other directories, use the @code{directory} command.
9337
4b505b12
AS
9338The search path is used to find both program source files and @value{GDBN}
9339script files (read using the @samp{-command} option and @samp{source} command).
9340
30daae6c
JB
9341In addition to the source path, @value{GDBN} provides a set of commands
9342that manage a list of source path substitution rules. A @dfn{substitution
9343rule} specifies how to rewrite source directories stored in the program's
9344debug information in case the sources were moved to a different
9345directory between compilation and debugging. A rule is made of
9346two strings, the first specifying what needs to be rewritten in
9347the path, and the second specifying how it should be rewritten.
9348In @ref{set substitute-path}, we name these two parts @var{from} and
9349@var{to} respectively. @value{GDBN} does a simple string replacement
9350of @var{from} with @var{to} at the start of the directory part of the
9351source file name, and uses that result instead of the original file
9352name to look up the sources.
9353
9354Using the previous example, suppose the @file{foo-1.0} tree has been
9355moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
3f94c067 9356@value{GDBN} to replace @file{/usr/src} in all source path names with
30daae6c
JB
9357@file{/mnt/cross}. The first lookup will then be
9358@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
9359of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
9360substitution rule, use the @code{set substitute-path} command
9361(@pxref{set substitute-path}).
9362
9363To avoid unexpected substitution results, a rule is applied only if the
9364@var{from} part of the directory name ends at a directory separator.
9365For instance, a rule substituting @file{/usr/source} into
9366@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
9367not to @file{/usr/sourceware/foo-2.0}. And because the substitution
d3e8051b 9368is applied only at the beginning of the directory name, this rule will
30daae6c
JB
9369not be applied to @file{/root/usr/source/baz.c} either.
9370
9371In many cases, you can achieve the same result using the @code{directory}
9372command. However, @code{set substitute-path} can be more efficient in
9373the case where the sources are organized in a complex tree with multiple
9374subdirectories. With the @code{directory} command, you need to add each
9375subdirectory of your project. If you moved the entire tree while
9376preserving its internal organization, then @code{set substitute-path}
9377allows you to direct the debugger to all the sources with one single
9378command.
9379
9380@code{set substitute-path} is also more than just a shortcut command.
9381The source path is only used if the file at the original location no
9382longer exists. On the other hand, @code{set substitute-path} modifies
9383the debugger behavior to look at the rewritten location instead. So, if
9384for any reason a source file that is not relevant to your executable is
9385located at the original location, a substitution rule is the only
3f94c067 9386method available to point @value{GDBN} at the new location.
30daae6c 9387
29b0e8a2
JM
9388@cindex @samp{--with-relocated-sources}
9389@cindex default source path substitution
9390You can configure a default source path substitution rule by
9391configuring @value{GDBN} with the
9392@samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
9393should be the name of a directory under @value{GDBN}'s configured
9394prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
9395directory names in debug information under @var{dir} will be adjusted
9396automatically if the installed @value{GDBN} is moved to a new
9397location. This is useful if @value{GDBN}, libraries or executables
9398with debug information and corresponding source code are being moved
9399together.
9400
c906108c
SS
9401@table @code
9402@item directory @var{dirname} @dots{}
9403@item dir @var{dirname} @dots{}
9404Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
9405directory names may be given to this command, separated by @samp{:}
9406(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
9407part of absolute file names) or
c906108c
SS
9408whitespace. You may specify a directory that is already in the source
9409path; this moves it forward, so @value{GDBN} searches it sooner.
9410
f1b620e9
MG
9411The special strings @samp{$cdir} (to refer to the compilation
9412directory, if one is recorded), and @samp{$cwd} (to refer to the
9413current working directory) can also be included in the list of
9414directories @var{dirname}. Though these will already be in the source
9415path they will be moved forward in the list so @value{GDBN} searches
9416them sooner.
c906108c
SS
9417
9418@item directory
cd852561 9419Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
9420
9421@c RET-repeat for @code{directory} is explicitly disabled, but since
9422@c repeating it would be a no-op we do not say that. (thanks to RMS)
9423
99e7ae30
DE
9424@item set directories @var{path-list}
9425@kindex set directories
9426Set the source path to @var{path-list}.
9427@samp{$cdir:$cwd} are added if missing.
9428
c906108c
SS
9429@item show directories
9430@kindex show directories
9431Print the source path: show which directories it contains.
30daae6c
JB
9432
9433@anchor{set substitute-path}
9434@item set substitute-path @var{from} @var{to}
9435@kindex set substitute-path
9436Define a source path substitution rule, and add it at the end of the
9437current list of existing substitution rules. If a rule with the same
9438@var{from} was already defined, then the old rule is also deleted.
9439
9440For example, if the file @file{/foo/bar/baz.c} was moved to
9441@file{/mnt/cross/baz.c}, then the command
9442
9443@smallexample
c58b006b 9444(@value{GDBP}) set substitute-path /foo/bar /mnt/cross
30daae6c
JB
9445@end smallexample
9446
9447@noindent
c58b006b 9448will tell @value{GDBN} to replace @samp{/foo/bar} with
30daae6c
JB
9449@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
9450@file{baz.c} even though it was moved.
9451
9452In the case when more than one substitution rule have been defined,
9453the rules are evaluated one by one in the order where they have been
9454defined. The first one matching, if any, is selected to perform
9455the substitution.
9456
9457For instance, if we had entered the following commands:
9458
9459@smallexample
9460(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
9461(@value{GDBP}) set substitute-path /usr/src /mnt/src
9462@end smallexample
9463
9464@noindent
9465@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
9466@file{/mnt/include/defs.h} by using the first rule. However, it would
9467use the second rule to rewrite @file{/usr/src/lib/foo.c} into
9468@file{/mnt/src/lib/foo.c}.
9469
9470
9471@item unset substitute-path [path]
9472@kindex unset substitute-path
9473If a path is specified, search the current list of substitution rules
9474for a rule that would rewrite that path. Delete that rule if found.
9475A warning is emitted by the debugger if no rule could be found.
9476
9477If no path is specified, then all substitution rules are deleted.
9478
9479@item show substitute-path [path]
9480@kindex show substitute-path
9481If a path is specified, then print the source path substitution rule
9482which would rewrite that path, if any.
9483
9484If no path is specified, then print all existing source path substitution
9485rules.
9486
c906108c
SS
9487@end table
9488
9489If your source path is cluttered with directories that are no longer of
9490interest, @value{GDBN} may sometimes cause confusion by finding the wrong
9491versions of source. You can correct the situation as follows:
9492
9493@enumerate
9494@item
cd852561 9495Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
9496
9497@item
9498Use @code{directory} with suitable arguments to reinstall the
9499directories you want in the source path. You can add all the
9500directories in one command.
9501@end enumerate
9502
6d2ebf8b 9503@node Machine Code
79a6e687 9504@section Source and Machine Code
15387254 9505@cindex source line and its code address
c906108c
SS
9506
9507You can use the command @code{info line} to map source lines to program
9508addresses (and vice versa), and the command @code{disassemble} to display
91440f57
HZ
9509a range of addresses as machine instructions. You can use the command
9510@code{set disassemble-next-line} to set whether to disassemble next
9511source line when execution stops. When run under @sc{gnu} Emacs
d4f3574e 9512mode, the @code{info line} command causes the arrow to point to the
5d161b24 9513line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
9514well as hex.
9515
9516@table @code
9517@kindex info line
db1ae9c5
AB
9518@item info line
9519@itemx info line @var{location}
c906108c 9520Print the starting and ending addresses of the compiled code for
629500fa 9521source line @var{location}. You can specify source lines in any of
db1ae9c5
AB
9522the ways documented in @ref{Specify Location}. With no @var{location}
9523information about the current source line is printed.
c906108c
SS
9524@end table
9525
9526For example, we can use @code{info line} to discover the location of
9527the object code for the first line of function
9528@code{m4_changequote}:
9529
9530@smallexample
96a2c332 9531(@value{GDBP}) info line m4_changequote
db1ae9c5
AB
9532Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
9533 ends at 0x6350 <m4_changequote+4>.
c906108c
SS
9534@end smallexample
9535
9536@noindent
15387254 9537@cindex code address and its source line
c906108c 9538We can also inquire (using @code{*@var{addr}} as the form for
629500fa 9539@var{location}) what source line covers a particular address:
c906108c
SS
9540@smallexample
9541(@value{GDBP}) info line *0x63ff
db1ae9c5
AB
9542Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
9543 ends at 0x6404 <m4_changequote+184>.
c906108c
SS
9544@end smallexample
9545
9546@cindex @code{$_} and @code{info line}
15387254 9547@cindex @code{x} command, default address
41afff9a 9548@kindex x@r{(examine), and} info line
c906108c
SS
9549After @code{info line}, the default address for the @code{x} command
9550is changed to the starting address of the line, so that @samp{x/i} is
9551sufficient to begin examining the machine code (@pxref{Memory,
79a6e687 9552,Examining Memory}). Also, this address is saved as the value of the
c906108c 9553convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
79a6e687 9554Variables}).
c906108c 9555
db1ae9c5
AB
9556@cindex info line, repeated calls
9557After @code{info line}, using @code{info line} again without
9558specifying a location will display information about the next source
9559line.
9560
c906108c
SS
9561@table @code
9562@kindex disassemble
9563@cindex assembly instructions
9564@cindex instructions, assembly
9565@cindex machine instructions
9566@cindex listing machine instructions
9567@item disassemble
d14508fe 9568@itemx disassemble /m
6ff0ba5f 9569@itemx disassemble /s
9b117ef3 9570@itemx disassemble /r
c906108c 9571This specialized command dumps a range of memory as machine
d14508fe 9572instructions. It can also print mixed source+disassembly by specifying
6ff0ba5f
DE
9573the @code{/m} or @code{/s} modifier and print the raw instructions in hex
9574as well as in symbolic form by specifying the @code{/r} modifier.
d14508fe 9575The default memory range is the function surrounding the
c906108c
SS
9576program counter of the selected frame. A single argument to this
9577command is a program counter value; @value{GDBN} dumps the function
21a0512e
PP
9578surrounding this value. When two arguments are given, they should
9579be separated by a comma, possibly surrounded by whitespace. The
53a71c06
CR
9580arguments specify a range of addresses to dump, in one of two forms:
9581
9582@table @code
9583@item @var{start},@var{end}
9584the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9585@item @var{start},+@var{length}
9586the addresses from @var{start} (inclusive) to
9587@code{@var{start}+@var{length}} (exclusive).
9588@end table
9589
9590@noindent
9591When 2 arguments are specified, the name of the function is also
9592printed (since there could be several functions in the given range).
21a0512e
PP
9593
9594The argument(s) can be any expression yielding a numeric value, such as
9595@samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
2b28d209
PP
9596
9597If the range of memory being disassembled contains current program counter,
9598the instruction at that location is shown with a @code{=>} marker.
c906108c
SS
9599@end table
9600
c906108c
SS
9601The following example shows the disassembly of a range of addresses of
9602HP PA-RISC 2.0 code:
9603
9604@smallexample
21a0512e 9605(@value{GDBP}) disas 0x32c4, 0x32e4
c906108c 9606Dump of assembler code from 0x32c4 to 0x32e4:
2b28d209
PP
9607 0x32c4 <main+204>: addil 0,dp
9608 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
9609 0x32cc <main+212>: ldil 0x3000,r31
9610 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
9611 0x32d4 <main+220>: ldo 0(r31),rp
9612 0x32d8 <main+224>: addil -0x800,dp
9613 0x32dc <main+228>: ldo 0x588(r1),r26
9614 0x32e0 <main+232>: ldil 0x3000,r31
c906108c
SS
9615End of assembler dump.
9616@end smallexample
c906108c 9617
6ff0ba5f
DE
9618Here is an example showing mixed source+assembly for Intel x86
9619with @code{/m} or @code{/s}, when the program is stopped just after
9620function prologue in a non-optimized function with no inline code.
d14508fe
DE
9621
9622@smallexample
9623(@value{GDBP}) disas /m main
9624Dump of assembler code for function main:
96255 @{
9c419145
PP
9626 0x08048330 <+0>: push %ebp
9627 0x08048331 <+1>: mov %esp,%ebp
9628 0x08048333 <+3>: sub $0x8,%esp
9629 0x08048336 <+6>: and $0xfffffff0,%esp
9630 0x08048339 <+9>: sub $0x10,%esp
d14508fe
DE
9631
96326 printf ("Hello.\n");
9c419145
PP
9633=> 0x0804833c <+12>: movl $0x8048440,(%esp)
9634 0x08048343 <+19>: call 0x8048284 <puts@@plt>
d14508fe
DE
9635
96367 return 0;
96378 @}
9c419145
PP
9638 0x08048348 <+24>: mov $0x0,%eax
9639 0x0804834d <+29>: leave
9640 0x0804834e <+30>: ret
d14508fe
DE
9641
9642End of assembler dump.
9643@end smallexample
9644
6ff0ba5f
DE
9645The @code{/m} option is deprecated as its output is not useful when
9646there is either inlined code or re-ordered code.
9647The @code{/s} option is the preferred choice.
9648Here is an example for AMD x86-64 showing the difference between
9649@code{/m} output and @code{/s} output.
9650This example has one inline function defined in a header file,
9651and the code is compiled with @samp{-O2} optimization.
9652Note how the @code{/m} output is missing the disassembly of
9653several instructions that are present in the @code{/s} output.
9654
9655@file{foo.h}:
9656
9657@smallexample
9658int
9659foo (int a)
9660@{
9661 if (a < 0)
9662 return a * 2;
9663 if (a == 0)
9664 return 1;
9665 return a + 10;
9666@}
9667@end smallexample
9668
9669@file{foo.c}:
9670
9671@smallexample
9672#include "foo.h"
9673volatile int x, y;
9674int
9675main ()
9676@{
9677 x = foo (y);
9678 return 0;
9679@}
9680@end smallexample
9681
9682@smallexample
9683(@value{GDBP}) disas /m main
9684Dump of assembler code for function main:
96855 @{
9686
96876 x = foo (y);
9688 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9689 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9690
96917 return 0;
96928 @}
9693 0x000000000040041d <+29>: xor %eax,%eax
9694 0x000000000040041f <+31>: retq
9695 0x0000000000400420 <+32>: add %eax,%eax
9696 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9697
9698End of assembler dump.
9699(@value{GDBP}) disas /s main
9700Dump of assembler code for function main:
9701foo.c:
97025 @{
97036 x = foo (y);
9704 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9705
9706foo.h:
97074 if (a < 0)
9708 0x0000000000400406 <+6>: test %eax,%eax
9709 0x0000000000400408 <+8>: js 0x400420 <main+32>
9710
97116 if (a == 0)
97127 return 1;
97138 return a + 10;
9714 0x000000000040040a <+10>: lea 0xa(%rax),%edx
9715 0x000000000040040d <+13>: test %eax,%eax
9716 0x000000000040040f <+15>: mov $0x1,%eax
9717 0x0000000000400414 <+20>: cmovne %edx,%eax
9718
9719foo.c:
97206 x = foo (y);
9721 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9722
97237 return 0;
97248 @}
9725 0x000000000040041d <+29>: xor %eax,%eax
9726 0x000000000040041f <+31>: retq
9727
9728foo.h:
97295 return a * 2;
9730 0x0000000000400420 <+32>: add %eax,%eax
9731 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9732End of assembler dump.
9733@end smallexample
9734
53a71c06
CR
9735Here is another example showing raw instructions in hex for AMD x86-64,
9736
9737@smallexample
9738(gdb) disas /r 0x400281,+10
9739Dump of assembler code from 0x400281 to 0x40028b:
9740 0x0000000000400281: 38 36 cmp %dh,(%rsi)
9741 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
9742 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
9743 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
9744End of assembler dump.
9745@end smallexample
9746
629500fa 9747Addresses cannot be specified as a location (@pxref{Specify Location}).
7e1e0340
DE
9748So, for example, if you want to disassemble function @code{bar}
9749in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
9750and not @samp{disassemble foo.c:bar}.
9751
c906108c
SS
9752Some architectures have more than one commonly-used set of instruction
9753mnemonics or other syntax.
9754
76d17f34
EZ
9755For programs that were dynamically linked and use shared libraries,
9756instructions that call functions or branch to locations in the shared
9757libraries might show a seemingly bogus location---it's actually a
9758location of the relocation table. On some architectures, @value{GDBN}
9759might be able to resolve these to actual function names.
9760
65b48a81
PB
9761@table @code
9762@kindex set disassembler-options
9763@cindex disassembler options
9764@item set disassembler-options @var{option1}[,@var{option2}@dots{}]
9765This command controls the passing of target specific information to
9766the disassembler. For a list of valid options, please refer to the
9767@code{-M}/@code{--disassembler-options} section of the @samp{objdump}
9768manual and/or the output of @kbd{objdump --help}
f5a476a7 9769(@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
65b48a81
PB
9770The default value is the empty string.
9771
9772If it is necessary to specify more than one disassembler option, then
9773multiple options can be placed together into a comma separated list.
471b9d15 9774Currently this command is only supported on targets ARM, MIPS, PowerPC
65b48a81
PB
9775and S/390.
9776
9777@kindex show disassembler-options
9778@item show disassembler-options
9779Show the current setting of the disassembler options.
9780@end table
9781
c906108c 9782@table @code
d4f3574e 9783@kindex set disassembly-flavor
d4f3574e
SS
9784@cindex Intel disassembly flavor
9785@cindex AT&T disassembly flavor
9786@item set disassembly-flavor @var{instruction-set}
c906108c
SS
9787Select the instruction set to use when disassembling the
9788program via the @code{disassemble} or @code{x/i} commands.
9789
9790Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
9791can set @var{instruction-set} to either @code{intel} or @code{att}.
9792The default is @code{att}, the AT&T flavor used by default by Unix
9793assemblers for x86-based targets.
9c16f35a
EZ
9794
9795@kindex show disassembly-flavor
9796@item show disassembly-flavor
9797Show the current setting of the disassembly flavor.
c906108c
SS
9798@end table
9799
91440f57
HZ
9800@table @code
9801@kindex set disassemble-next-line
9802@kindex show disassemble-next-line
9803@item set disassemble-next-line
9804@itemx show disassemble-next-line
32ae1842
EZ
9805Control whether or not @value{GDBN} will disassemble the next source
9806line or instruction when execution stops. If ON, @value{GDBN} will
9807display disassembly of the next source line when execution of the
9808program being debugged stops. This is @emph{in addition} to
9809displaying the source line itself, which @value{GDBN} always does if
9810possible. If the next source line cannot be displayed for some reason
9811(e.g., if @value{GDBN} cannot find the source file, or there's no line
9812info in the debug info), @value{GDBN} will display disassembly of the
9813next @emph{instruction} instead of showing the next source line. If
9814AUTO, @value{GDBN} will display disassembly of next instruction only
9815if the source line cannot be displayed. This setting causes
9816@value{GDBN} to display some feedback when you step through a function
9817with no line info or whose source file is unavailable. The default is
9818OFF, which means never display the disassembly of the next line or
9819instruction.
91440f57
HZ
9820@end table
9821
c906108c 9822
6d2ebf8b 9823@node Data
c906108c
SS
9824@chapter Examining Data
9825
9826@cindex printing data
9827@cindex examining data
9828@kindex print
9829@kindex inspect
c906108c 9830The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
9831command (abbreviated @code{p}), or its synonym @code{inspect}. It
9832evaluates and prints the value of an expression of the language your
9833program is written in (@pxref{Languages, ,Using @value{GDBN} with
78e2826b
TT
9834Different Languages}). It may also print the expression using a
9835Python-based pretty-printer (@pxref{Pretty Printing}).
c906108c
SS
9836
9837@table @code
3345721a
PA
9838@item print [[@var{options}] --] @var{expr}
9839@itemx print [[@var{options}] --] /@var{f} @var{expr}
d4f3574e
SS
9840@var{expr} is an expression (in the source language). By default the
9841value of @var{expr} is printed in a format appropriate to its data type;
c906108c 9842you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 9843@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
79a6e687 9844Formats}.
c906108c 9845
3345721a
PA
9846@anchor{print options}
9847The @code{print} command supports a number of options that allow
9848overriding relevant global print settings as set by @code{set print}
9849subcommands:
9850
9851@table @code
9852@item -address [@code{on}|@code{off}]
9853Set printing of addresses.
9854Related setting: @ref{set print address}.
9855
9856@item -array [@code{on}|@code{off}]
9857Pretty formatting of arrays.
9858Related setting: @ref{set print array}.
9859
9860@item -array-indexes [@code{on}|@code{off}]
9861Set printing of array indexes.
9862Related setting: @ref{set print array-indexes}.
9863
9864@item -elements @var{number-of-elements}|@code{unlimited}
9865Set limit on string chars or array elements to print. The value
9866@code{unlimited} causes there to be no limit. Related setting:
9867@ref{set print elements}.
9868
9869@item -max-depth @var{depth}|@code{unlimited}
9870Set the threshold after which nested structures are replaced with
9871ellipsis. Related setting: @ref{set print max-depth}.
9872
9873@item -null-stop [@code{on}|@code{off}]
9874Set printing of char arrays to stop at first null char. Related
9875setting: @ref{set print null-stop}.
9876
9877@item -object [@code{on}|@code{off}]
9878Set printing C@t{++} virtual function tables. Related setting:
9879@ref{set print object}.
9880
9881@item -pretty [@code{on}|@code{off}]
9882Set pretty formatting of structures. Related setting: @ref{set print
9883pretty}.
9884
d8edc8b7
PW
9885@item -raw-values [@code{on}|@code{off}]
9886Set whether to print values in raw form, bypassing any
9887pretty-printers for that value. Related setting: @ref{set print
9888raw-values}.
9889
3345721a
PA
9890@item -repeats @var{number-of-repeats}|@code{unlimited}
9891Set threshold for repeated print elements. @code{unlimited} causes
9892all elements to be individually printed. Related setting: @ref{set
9893print repeats}.
9894
9895@item -static-members [@code{on}|@code{off}]
9896Set printing C@t{++} static members. Related setting: @ref{set print
9897static-members}.
9898
9899@item -symbol [@code{on}|@code{off}]
9900Set printing of symbol names when printing pointers. Related setting:
9901@ref{set print symbol}.
9902
9903@item -union [@code{on}|@code{off}]
9904Set printing of unions interior to structures. Related setting:
9905@ref{set print union}.
9906
9907@item -vtbl [@code{on}|@code{off}]
9908Set printing of C++ virtual function tables. Related setting:
9909@ref{set print vtbl}.
9910@end table
9911
9912Because the @code{print} command accepts arbitrary expressions which
9913may look like options (including abbreviations), if you specify any
9914command option, then you must use a double dash (@code{--}) to mark
9915the end of option processing.
9916
d8edc8b7 9917For example, this prints the value of the @code{-p} expression:
3345721a
PA
9918
9919@smallexample
d8edc8b7 9920(@value{GDBP}) print -p
3345721a
PA
9921@end smallexample
9922
9923While this repeats the last value in the value history (see below)
d8edc8b7 9924with the @code{-pretty} option in effect:
3345721a
PA
9925
9926@smallexample
d8edc8b7 9927(@value{GDBP}) print -p --
3345721a
PA
9928@end smallexample
9929
9930Here is an example including both on option and an expression:
9931
9932@smallexample
9933@group
9934(@value{GDBP}) print -pretty -- *myptr
9935$1 = @{
9936 next = 0x0,
9937 flags = @{
9938 sweet = 1,
9939 sour = 1
9940 @},
9941 meat = 0x54 "Pork"
9942@}
9943@end group
9944@end smallexample
9945
9946@item print [@var{options}]
9947@itemx print [@var{options}] /@var{f}
15387254 9948@cindex reprint the last value
d4f3574e 9949If you omit @var{expr}, @value{GDBN} displays the last value again (from the
79a6e687 9950@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
c906108c
SS
9951conveniently inspect the same value in an alternative format.
9952@end table
9953
9954A more low-level way of examining data is with the @code{x} command.
9955It examines data in memory at a specified address and prints it in a
79a6e687 9956specified format. @xref{Memory, ,Examining Memory}.
c906108c 9957
7a292a7a 9958If you are interested in information about types, or about how the
d4f3574e
SS
9959fields of a struct or a class are declared, use the @code{ptype @var{exp}}
9960command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 9961Table}.
c906108c 9962
06fc020f
SCR
9963@cindex exploring hierarchical data structures
9964@kindex explore
9965Another way of examining values of expressions and type information is
9966through the Python extension command @code{explore} (available only if
9967the @value{GDBN} build is configured with @code{--with-python}). It
9968offers an interactive way to start at the highest level (or, the most
9969abstract level) of the data type of an expression (or, the data type
9970itself) and explore all the way down to leaf scalar values/fields
9971embedded in the higher level data types.
9972
9973@table @code
9974@item explore @var{arg}
9975@var{arg} is either an expression (in the source language), or a type
9976visible in the current context of the program being debugged.
9977@end table
9978
9979The working of the @code{explore} command can be illustrated with an
9980example. If a data type @code{struct ComplexStruct} is defined in your
9981C program as
9982
9983@smallexample
9984struct SimpleStruct
9985@{
9986 int i;
9987 double d;
9988@};
9989
9990struct ComplexStruct
9991@{
9992 struct SimpleStruct *ss_p;
9993 int arr[10];
9994@};
9995@end smallexample
9996
9997@noindent
9998followed by variable declarations as
9999
10000@smallexample
10001struct SimpleStruct ss = @{ 10, 1.11 @};
10002struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
10003@end smallexample
10004
10005@noindent
10006then, the value of the variable @code{cs} can be explored using the
10007@code{explore} command as follows.
10008
10009@smallexample
10010(gdb) explore cs
10011The value of `cs' is a struct/class of type `struct ComplexStruct' with
10012the following fields:
10013
10014 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
10015 arr = <Enter 1 to explore this field of type `int [10]'>
10016
10017Enter the field number of choice:
10018@end smallexample
10019
10020@noindent
10021Since the fields of @code{cs} are not scalar values, you are being
10022prompted to chose the field you want to explore. Let's say you choose
10023the field @code{ss_p} by entering @code{0}. Then, since this field is a
10024pointer, you will be asked if it is pointing to a single value. From
10025the declaration of @code{cs} above, it is indeed pointing to a single
10026value, hence you enter @code{y}. If you enter @code{n}, then you will
10027be asked if it were pointing to an array of values, in which case this
10028field will be explored as if it were an array.
10029
10030@smallexample
10031`cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
10032Continue exploring it as a pointer to a single value [y/n]: y
10033The value of `*(cs.ss_p)' is a struct/class of type `struct
10034SimpleStruct' with the following fields:
10035
10036 i = 10 .. (Value of type `int')
10037 d = 1.1100000000000001 .. (Value of type `double')
10038
10039Press enter to return to parent value:
10040@end smallexample
10041
10042@noindent
10043If the field @code{arr} of @code{cs} was chosen for exploration by
10044entering @code{1} earlier, then since it is as array, you will be
10045prompted to enter the index of the element in the array that you want
10046to explore.
10047
10048@smallexample
10049`cs.arr' is an array of `int'.
10050Enter the index of the element you want to explore in `cs.arr': 5
10051
10052`(cs.arr)[5]' is a scalar value of type `int'.
10053
10054(cs.arr)[5] = 4
10055
10056Press enter to return to parent value:
10057@end smallexample
10058
10059In general, at any stage of exploration, you can go deeper towards the
10060leaf values by responding to the prompts appropriately, or hit the
10061return key to return to the enclosing data structure (the @i{higher}
10062level data structure).
10063
10064Similar to exploring values, you can use the @code{explore} command to
10065explore types. Instead of specifying a value (which is typically a
10066variable name or an expression valid in the current context of the
10067program being debugged), you specify a type name. If you consider the
10068same example as above, your can explore the type
10069@code{struct ComplexStruct} by passing the argument
10070@code{struct ComplexStruct} to the @code{explore} command.
10071
10072@smallexample
10073(gdb) explore struct ComplexStruct
10074@end smallexample
10075
10076@noindent
10077By responding to the prompts appropriately in the subsequent interactive
10078session, you can explore the type @code{struct ComplexStruct} in a
10079manner similar to how the value @code{cs} was explored in the above
10080example.
10081
10082The @code{explore} command also has two sub-commands,
10083@code{explore value} and @code{explore type}. The former sub-command is
10084a way to explicitly specify that value exploration of the argument is
10085being invoked, while the latter is a way to explicitly specify that type
10086exploration of the argument is being invoked.
10087
10088@table @code
10089@item explore value @var{expr}
10090@cindex explore value
10091This sub-command of @code{explore} explores the value of the
10092expression @var{expr} (if @var{expr} is an expression valid in the
10093current context of the program being debugged). The behavior of this
10094command is identical to that of the behavior of the @code{explore}
10095command being passed the argument @var{expr}.
10096
10097@item explore type @var{arg}
10098@cindex explore type
10099This sub-command of @code{explore} explores the type of @var{arg} (if
10100@var{arg} is a type visible in the current context of program being
10101debugged), or the type of the value/expression @var{arg} (if @var{arg}
10102is an expression valid in the current context of the program being
10103debugged). If @var{arg} is a type, then the behavior of this command is
10104identical to that of the @code{explore} command being passed the
10105argument @var{arg}. If @var{arg} is an expression, then the behavior of
10106this command will be identical to that of the @code{explore} command
10107being passed the type of @var{arg} as the argument.
10108@end table
10109
c906108c
SS
10110@menu
10111* Expressions:: Expressions
6ba66d6a 10112* Ambiguous Expressions:: Ambiguous Expressions
c906108c
SS
10113* Variables:: Program variables
10114* Arrays:: Artificial arrays
10115* Output Formats:: Output formats
10116* Memory:: Examining memory
10117* Auto Display:: Automatic display
10118* Print Settings:: Print settings
4c374409 10119* Pretty Printing:: Python pretty printing
c906108c
SS
10120* Value History:: Value history
10121* Convenience Vars:: Convenience variables
a72c3253 10122* Convenience Funs:: Convenience functions
c906108c 10123* Registers:: Registers
c906108c 10124* Floating Point Hardware:: Floating point hardware
53c69bd7 10125* Vector Unit:: Vector Unit
721c2651 10126* OS Information:: Auxiliary data provided by operating system
29e57380 10127* Memory Region Attributes:: Memory region attributes
16d9dec6 10128* Dump/Restore Files:: Copy between memory and a file
384ee23f 10129* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
10130* Character Sets:: Debugging programs that use a different
10131 character set than GDB does
b12039c6 10132* Caching Target Data:: Data caching for targets
08388c79 10133* Searching Memory:: Searching memory for a sequence of bytes
5fdf6324 10134* Value Sizes:: Managing memory allocated for values
c906108c
SS
10135@end menu
10136
6d2ebf8b 10137@node Expressions
c906108c
SS
10138@section Expressions
10139
10140@cindex expressions
10141@code{print} and many other @value{GDBN} commands accept an expression and
10142compute its value. Any kind of constant, variable or operator defined
10143by the programming language you are using is valid in an expression in
e2e0bcd1
JB
10144@value{GDBN}. This includes conditional expressions, function calls,
10145casts, and string constants. It also includes preprocessor macros, if
10146you compiled your program to include this information; see
10147@ref{Compilation}.
c906108c 10148
15387254 10149@cindex arrays in expressions
d4f3574e
SS
10150@value{GDBN} supports array constants in expressions input by
10151the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
63092375
DJ
10152you can use the command @code{print @{1, 2, 3@}} to create an array
10153of three integers. If you pass an array to a function or assign it
10154to a program variable, @value{GDBN} copies the array to memory that
10155is @code{malloc}ed in the target program.
c906108c 10156
c906108c
SS
10157Because C is so widespread, most of the expressions shown in examples in
10158this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
10159Languages}, for information on how to use expressions in other
10160languages.
10161
10162In this section, we discuss operators that you can use in @value{GDBN}
10163expressions regardless of your programming language.
10164
15387254 10165@cindex casts, in expressions
c906108c
SS
10166Casts are supported in all languages, not just in C, because it is so
10167useful to cast a number into a pointer in order to examine a structure
10168at that address in memory.
10169@c FIXME: casts supported---Mod2 true?
c906108c
SS
10170
10171@value{GDBN} supports these operators, in addition to those common
10172to programming languages:
10173
10174@table @code
10175@item @@
10176@samp{@@} is a binary operator for treating parts of memory as arrays.
79a6e687 10177@xref{Arrays, ,Artificial Arrays}, for more information.
c906108c
SS
10178
10179@item ::
10180@samp{::} allows you to specify a variable in terms of the file or
79a6e687 10181function where it is defined. @xref{Variables, ,Program Variables}.
c906108c
SS
10182
10183@cindex @{@var{type}@}
10184@cindex type casting memory
10185@cindex memory, viewing as typed object
10186@cindex casts, to view memory
10187@item @{@var{type}@} @var{addr}
10188Refers to an object of type @var{type} stored at address @var{addr} in
697aa1b7
EZ
10189memory. The address @var{addr} may be any expression whose value is
10190an integer or pointer (but parentheses are required around binary
10191operators, just as in a cast). This construct is allowed regardless
10192of what kind of data is normally supposed to reside at @var{addr}.
c906108c
SS
10193@end table
10194
6ba66d6a
JB
10195@node Ambiguous Expressions
10196@section Ambiguous Expressions
10197@cindex ambiguous expressions
10198
10199Expressions can sometimes contain some ambiguous elements. For instance,
10200some programming languages (notably Ada, C@t{++} and Objective-C) permit
10201a single function name to be defined several times, for application in
10202different contexts. This is called @dfn{overloading}. Another example
10203involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
10204templates and is typically instantiated several times, resulting in
10205the same function name being defined in different contexts.
10206
10207In some cases and depending on the language, it is possible to adjust
10208the expression to remove the ambiguity. For instance in C@t{++}, you
10209can specify the signature of the function you want to break on, as in
10210@kbd{break @var{function}(@var{types})}. In Ada, using the fully
10211qualified name of your function often makes the expression unambiguous
10212as well.
10213
10214When an ambiguity that needs to be resolved is detected, the debugger
10215has the capability to display a menu of numbered choices for each
10216possibility, and then waits for the selection with the prompt @samp{>}.
10217The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
10218aborts the current command. If the command in which the expression was
10219used allows more than one choice to be selected, the next option in the
10220menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
10221choices.
10222
10223For example, the following session excerpt shows an attempt to set a
10224breakpoint at the overloaded symbol @code{String::after}.
10225We choose three particular definitions of that function name:
10226
10227@c FIXME! This is likely to change to show arg type lists, at least
10228@smallexample
10229@group
10230(@value{GDBP}) b String::after
10231[0] cancel
10232[1] all
10233[2] file:String.cc; line number:867
10234[3] file:String.cc; line number:860
10235[4] file:String.cc; line number:875
10236[5] file:String.cc; line number:853
10237[6] file:String.cc; line number:846
10238[7] file:String.cc; line number:735
10239> 2 4 6
10240Breakpoint 1 at 0xb26c: file String.cc, line 867.
10241Breakpoint 2 at 0xb344: file String.cc, line 875.
10242Breakpoint 3 at 0xafcc: file String.cc, line 846.
10243Multiple breakpoints were set.
10244Use the "delete" command to delete unwanted
10245 breakpoints.
10246(@value{GDBP})
10247@end group
10248@end smallexample
10249
10250@table @code
10251@kindex set multiple-symbols
10252@item set multiple-symbols @var{mode}
10253@cindex multiple-symbols menu
10254
10255This option allows you to adjust the debugger behavior when an expression
10256is ambiguous.
10257
10258By default, @var{mode} is set to @code{all}. If the command with which
10259the expression is used allows more than one choice, then @value{GDBN}
10260automatically selects all possible choices. For instance, inserting
10261a breakpoint on a function using an ambiguous name results in a breakpoint
10262inserted on each possible match. However, if a unique choice must be made,
10263then @value{GDBN} uses the menu to help you disambiguate the expression.
10264For instance, printing the address of an overloaded function will result
10265in the use of the menu.
10266
10267When @var{mode} is set to @code{ask}, the debugger always uses the menu
10268when an ambiguity is detected.
10269
10270Finally, when @var{mode} is set to @code{cancel}, the debugger reports
10271an error due to the ambiguity and the command is aborted.
10272
10273@kindex show multiple-symbols
10274@item show multiple-symbols
10275Show the current value of the @code{multiple-symbols} setting.
10276@end table
10277
6d2ebf8b 10278@node Variables
79a6e687 10279@section Program Variables
c906108c
SS
10280
10281The most common kind of expression to use is the name of a variable
10282in your program.
10283
10284Variables in expressions are understood in the selected stack frame
79a6e687 10285(@pxref{Selection, ,Selecting a Frame}); they must be either:
c906108c
SS
10286
10287@itemize @bullet
10288@item
10289global (or file-static)
10290@end itemize
10291
5d161b24 10292@noindent or
c906108c
SS
10293
10294@itemize @bullet
10295@item
10296visible according to the scope rules of the
10297programming language from the point of execution in that frame
5d161b24 10298@end itemize
c906108c
SS
10299
10300@noindent This means that in the function
10301
474c8240 10302@smallexample
c906108c
SS
10303foo (a)
10304 int a;
10305@{
10306 bar (a);
10307 @{
10308 int b = test ();
10309 bar (b);
10310 @}
10311@}
474c8240 10312@end smallexample
c906108c
SS
10313
10314@noindent
10315you can examine and use the variable @code{a} whenever your program is
10316executing within the function @code{foo}, but you can only use or
10317examine the variable @code{b} while your program is executing inside
10318the block where @code{b} is declared.
10319
10320@cindex variable name conflict
10321There is an exception: you can refer to a variable or function whose
10322scope is a single source file even if the current execution point is not
10323in this file. But it is possible to have more than one such variable or
10324function with the same name (in different source files). If that
10325happens, referring to that name has unpredictable effects. If you wish,
72384ba3 10326you can specify a static variable in a particular function or file by
15387254 10327using the colon-colon (@code{::}) notation:
c906108c 10328
d4f3574e 10329@cindex colon-colon, context for variables/functions
12c27660 10330@ifnotinfo
c906108c 10331@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 10332@cindex @code{::}, context for variables/functions
12c27660 10333@end ifnotinfo
474c8240 10334@smallexample
c906108c
SS
10335@var{file}::@var{variable}
10336@var{function}::@var{variable}
474c8240 10337@end smallexample
c906108c
SS
10338
10339@noindent
10340Here @var{file} or @var{function} is the name of the context for the
10341static @var{variable}. In the case of file names, you can use quotes to
10342make sure @value{GDBN} parses the file name as a single word---for example,
10343to print a global value of @code{x} defined in @file{f2.c}:
10344
474c8240 10345@smallexample
c906108c 10346(@value{GDBP}) p 'f2.c'::x
474c8240 10347@end smallexample
c906108c 10348
72384ba3
PH
10349The @code{::} notation is normally used for referring to
10350static variables, since you typically disambiguate uses of local variables
10351in functions by selecting the appropriate frame and using the
10352simple name of the variable. However, you may also use this notation
10353to refer to local variables in frames enclosing the selected frame:
10354
10355@smallexample
10356void
10357foo (int a)
10358@{
10359 if (a < 10)
10360 bar (a);
10361 else
10362 process (a); /* Stop here */
10363@}
10364
10365int
10366bar (int a)
10367@{
10368 foo (a + 5);
10369@}
10370@end smallexample
10371
10372@noindent
10373For example, if there is a breakpoint at the commented line,
10374here is what you might see
10375when the program stops after executing the call @code{bar(0)}:
10376
10377@smallexample
10378(@value{GDBP}) p a
10379$1 = 10
10380(@value{GDBP}) p bar::a
10381$2 = 5
10382(@value{GDBP}) up 2
10383#2 0x080483d0 in foo (a=5) at foobar.c:12
10384(@value{GDBP}) p a
10385$3 = 5
10386(@value{GDBP}) p bar::a
10387$4 = 0
10388@end smallexample
10389
b37052ae 10390@cindex C@t{++} scope resolution
805e1f19
TT
10391These uses of @samp{::} are very rarely in conflict with the very
10392similar use of the same notation in C@t{++}. When they are in
10393conflict, the C@t{++} meaning takes precedence; however, this can be
10394overridden by quoting the file or function name with single quotes.
10395
10396For example, suppose the program is stopped in a method of a class
10397that has a field named @code{includefile}, and there is also an
10398include file named @file{includefile} that defines a variable,
10399@code{some_global}.
10400
10401@smallexample
10402(@value{GDBP}) p includefile
10403$1 = 23
10404(@value{GDBP}) p includefile::some_global
10405A syntax error in expression, near `'.
10406(@value{GDBP}) p 'includefile'::some_global
10407$2 = 27
10408@end smallexample
c906108c
SS
10409
10410@cindex wrong values
10411@cindex variable values, wrong
15387254
EZ
10412@cindex function entry/exit, wrong values of variables
10413@cindex optimized code, wrong values of variables
c906108c
SS
10414@quotation
10415@emph{Warning:} Occasionally, a local variable may appear to have the
10416wrong value at certain points in a function---just after entry to a new
10417scope, and just before exit.
10418@end quotation
10419You may see this problem when you are stepping by machine instructions.
10420This is because, on most machines, it takes more than one instruction to
10421set up a stack frame (including local variable definitions); if you are
10422stepping by machine instructions, variables may appear to have the wrong
10423values until the stack frame is completely built. On exit, it usually
10424also takes more than one machine instruction to destroy a stack frame;
10425after you begin stepping through that group of instructions, local
10426variable definitions may be gone.
10427
10428This may also happen when the compiler does significant optimizations.
10429To be sure of always seeing accurate values, turn off all optimization
10430when compiling.
10431
d4f3574e
SS
10432@cindex ``No symbol "foo" in current context''
10433Another possible effect of compiler optimizations is to optimize
10434unused variables out of existence, or assign variables to registers (as
10435opposed to memory addresses). Depending on the support for such cases
10436offered by the debug info format used by the compiler, @value{GDBN}
10437might not be able to display values for such local variables. If that
10438happens, @value{GDBN} will print a message like this:
10439
474c8240 10440@smallexample
d4f3574e 10441No symbol "foo" in current context.
474c8240 10442@end smallexample
d4f3574e
SS
10443
10444To solve such problems, either recompile without optimizations, or use a
10445different debug info format, if the compiler supports several such
e0f8f636
TT
10446formats. @xref{Compilation}, for more information on choosing compiler
10447options. @xref{C, ,C and C@t{++}}, for more information about debug
10448info formats that are best suited to C@t{++} programs.
d4f3574e 10449
ab1adacd
EZ
10450If you ask to print an object whose contents are unknown to
10451@value{GDBN}, e.g., because its data type is not completely specified
10452by the debug information, @value{GDBN} will say @samp{<incomplete
10453type>}. @xref{Symbols, incomplete type}, for more about this.
10454
d69cf9b2
PA
10455@cindex no debug info variables
10456If you try to examine or use the value of a (global) variable for
10457which @value{GDBN} has no type information, e.g., because the program
10458includes no debug information, @value{GDBN} displays an error message.
10459@xref{Symbols, unknown type}, for more about unknown types. If you
10460cast the variable to its declared type, @value{GDBN} gets the
10461variable's value using the cast-to type as the variable's type. For
10462example, in a C program:
10463
10464@smallexample
10465 (@value{GDBP}) p var
10466 'var' has unknown type; cast it to its declared type
10467 (@value{GDBP}) p (float) var
10468 $1 = 3.14
10469@end smallexample
10470
36b11add
JK
10471If you append @kbd{@@entry} string to a function parameter name you get its
10472value at the time the function got called. If the value is not available an
10473error message is printed. Entry values are available only with some compilers.
10474Entry values are normally also printed at the function parameter list according
10475to @ref{set print entry-values}.
10476
10477@smallexample
10478Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
1047929 i++;
10480(gdb) next
1048130 e (i);
10482(gdb) print i
10483$1 = 31
10484(gdb) print i@@entry
10485$2 = 30
10486@end smallexample
10487
3a60f64e
JK
10488Strings are identified as arrays of @code{char} values without specified
10489signedness. Arrays of either @code{signed char} or @code{unsigned char} get
10490printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
10491@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
10492defines literal string type @code{"char"} as @code{char} without a sign.
10493For program code
10494
10495@smallexample
10496char var0[] = "A";
10497signed char var1[] = "A";
10498@end smallexample
10499
10500You get during debugging
10501@smallexample
10502(gdb) print var0
10503$1 = "A"
10504(gdb) print var1
10505$2 = @{65 'A', 0 '\0'@}
10506@end smallexample
10507
6d2ebf8b 10508@node Arrays
79a6e687 10509@section Artificial Arrays
c906108c
SS
10510
10511@cindex artificial array
15387254 10512@cindex arrays
41afff9a 10513@kindex @@@r{, referencing memory as an array}
c906108c
SS
10514It is often useful to print out several successive objects of the
10515same type in memory; a section of an array, or an array of
10516dynamically determined size for which only a pointer exists in the
10517program.
10518
10519You can do this by referring to a contiguous span of memory as an
10520@dfn{artificial array}, using the binary operator @samp{@@}. The left
10521operand of @samp{@@} should be the first element of the desired array
10522and be an individual object. The right operand should be the desired length
10523of the array. The result is an array value whose elements are all of
10524the type of the left argument. The first element is actually the left
10525argument; the second element comes from bytes of memory immediately
10526following those that hold the first element, and so on. Here is an
10527example. If a program says
10528
474c8240 10529@smallexample
c906108c 10530int *array = (int *) malloc (len * sizeof (int));
474c8240 10531@end smallexample
c906108c
SS
10532
10533@noindent
10534you can print the contents of @code{array} with
10535
474c8240 10536@smallexample
c906108c 10537p *array@@len
474c8240 10538@end smallexample
c906108c
SS
10539
10540The left operand of @samp{@@} must reside in memory. Array values made
10541with @samp{@@} in this way behave just like other arrays in terms of
10542subscripting, and are coerced to pointers when used in expressions.
10543Artificial arrays most often appear in expressions via the value history
79a6e687 10544(@pxref{Value History, ,Value History}), after printing one out.
c906108c
SS
10545
10546Another way to create an artificial array is to use a cast.
10547This re-interprets a value as if it were an array.
10548The value need not be in memory:
474c8240 10549@smallexample
c906108c
SS
10550(@value{GDBP}) p/x (short[2])0x12345678
10551$1 = @{0x1234, 0x5678@}
474c8240 10552@end smallexample
c906108c
SS
10553
10554As a convenience, if you leave the array length out (as in
c3f6f71d 10555@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 10556the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 10557@smallexample
c906108c
SS
10558(@value{GDBP}) p/x (short[])0x12345678
10559$2 = @{0x1234, 0x5678@}
474c8240 10560@end smallexample
c906108c
SS
10561
10562Sometimes the artificial array mechanism is not quite enough; in
10563moderately complex data structures, the elements of interest may not
10564actually be adjacent---for example, if you are interested in the values
10565of pointers in an array. One useful work-around in this situation is
10566to use a convenience variable (@pxref{Convenience Vars, ,Convenience
79a6e687 10567Variables}) as a counter in an expression that prints the first
c906108c
SS
10568interesting value, and then repeat that expression via @key{RET}. For
10569instance, suppose you have an array @code{dtab} of pointers to
10570structures, and you are interested in the values of a field @code{fv}
10571in each structure. Here is an example of what you might type:
10572
474c8240 10573@smallexample
c906108c
SS
10574set $i = 0
10575p dtab[$i++]->fv
10576@key{RET}
10577@key{RET}
10578@dots{}
474c8240 10579@end smallexample
c906108c 10580
6d2ebf8b 10581@node Output Formats
79a6e687 10582@section Output Formats
c906108c
SS
10583
10584@cindex formatted output
10585@cindex output formats
10586By default, @value{GDBN} prints a value according to its data type. Sometimes
10587this is not what you want. For example, you might want to print a number
10588in hex, or a pointer in decimal. Or you might want to view data in memory
10589at a certain address as a character string or as an instruction. To do
10590these things, specify an @dfn{output format} when you print a value.
10591
10592The simplest use of output formats is to say how to print a value
10593already computed. This is done by starting the arguments of the
10594@code{print} command with a slash and a format letter. The format
10595letters supported are:
10596
10597@table @code
10598@item x
10599Regard the bits of the value as an integer, and print the integer in
10600hexadecimal.
10601
10602@item d
10603Print as integer in signed decimal.
10604
10605@item u
10606Print as integer in unsigned decimal.
10607
10608@item o
10609Print as integer in octal.
10610
10611@item t
10612Print as integer in binary. The letter @samp{t} stands for ``two''.
10613@footnote{@samp{b} cannot be used because these format letters are also
10614used with the @code{x} command, where @samp{b} stands for ``byte'';
79a6e687 10615see @ref{Memory,,Examining Memory}.}
c906108c
SS
10616
10617@item a
10618@cindex unknown address, locating
3d67e040 10619@cindex locate address
c906108c
SS
10620Print as an address, both absolute in hexadecimal and as an offset from
10621the nearest preceding symbol. You can use this format used to discover
10622where (in what function) an unknown address is located:
10623
474c8240 10624@smallexample
c906108c
SS
10625(@value{GDBP}) p/a 0x54320
10626$3 = 0x54320 <_initialize_vx+396>
474c8240 10627@end smallexample
c906108c 10628
3d67e040
EZ
10629@noindent
10630The command @code{info symbol 0x54320} yields similar results.
10631@xref{Symbols, info symbol}.
10632
c906108c 10633@item c
51274035
EZ
10634Regard as an integer and print it as a character constant. This
10635prints both the numerical value and its character representation. The
10636character representation is replaced with the octal escape @samp{\nnn}
10637for characters outside the 7-bit @sc{ascii} range.
c906108c 10638
ea37ba09
DJ
10639Without this format, @value{GDBN} displays @code{char},
10640@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
10641constants. Single-byte members of vectors are displayed as integer
10642data.
10643
c906108c
SS
10644@item f
10645Regard the bits of the value as a floating point number and print
10646using typical floating point syntax.
ea37ba09
DJ
10647
10648@item s
10649@cindex printing strings
10650@cindex printing byte arrays
10651Regard as a string, if possible. With this format, pointers to single-byte
10652data are displayed as null-terminated strings and arrays of single-byte data
10653are displayed as fixed-length strings. Other values are displayed in their
10654natural types.
10655
10656Without this format, @value{GDBN} displays pointers to and arrays of
10657@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
10658strings. Single-byte members of a vector are displayed as an integer
10659array.
a6bac58e 10660
6fbe845e
AB
10661@item z
10662Like @samp{x} formatting, the value is treated as an integer and
10663printed as hexadecimal, but leading zeros are printed to pad the value
10664to the size of the integer type.
10665
a6bac58e
TT
10666@item r
10667@cindex raw printing
10668Print using the @samp{raw} formatting. By default, @value{GDBN} will
78e2826b
TT
10669use a Python-based pretty-printer, if one is available (@pxref{Pretty
10670Printing}). This typically results in a higher-level display of the
10671value's contents. The @samp{r} format bypasses any Python
10672pretty-printer which might exist.
c906108c
SS
10673@end table
10674
10675For example, to print the program counter in hex (@pxref{Registers}), type
10676
474c8240 10677@smallexample
c906108c 10678p/x $pc
474c8240 10679@end smallexample
c906108c
SS
10680
10681@noindent
10682Note that no space is required before the slash; this is because command
10683names in @value{GDBN} cannot contain a slash.
10684
10685To reprint the last value in the value history with a different format,
10686you can use the @code{print} command with just a format and no
10687expression. For example, @samp{p/x} reprints the last value in hex.
10688
6d2ebf8b 10689@node Memory
79a6e687 10690@section Examining Memory
c906108c
SS
10691
10692You can use the command @code{x} (for ``examine'') to examine memory in
10693any of several formats, independently of your program's data types.
10694
10695@cindex examining memory
10696@table @code
41afff9a 10697@kindex x @r{(examine memory)}
c906108c
SS
10698@item x/@var{nfu} @var{addr}
10699@itemx x @var{addr}
10700@itemx x
10701Use the @code{x} command to examine memory.
10702@end table
10703
10704@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
10705much memory to display and how to format it; @var{addr} is an
10706expression giving the address where you want to start displaying memory.
10707If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
10708Several commands set convenient defaults for @var{addr}.
10709
10710@table @r
10711@item @var{n}, the repeat count
10712The repeat count is a decimal integer; the default is 1. It specifies
bb556f1f
TK
10713how much memory (counting by units @var{u}) to display. If a negative
10714number is specified, memory is examined backward from @var{addr}.
c906108c
SS
10715@c This really is **decimal**; unaffected by 'set radix' as of GDB
10716@c 4.1.2.
10717
10718@item @var{f}, the display format
51274035
EZ
10719The display format is one of the formats used by @code{print}
10720(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
ea37ba09
DJ
10721@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
10722The default is @samp{x} (hexadecimal) initially. The default changes
10723each time you use either @code{x} or @code{print}.
c906108c
SS
10724
10725@item @var{u}, the unit size
10726The unit size is any of
10727
10728@table @code
10729@item b
10730Bytes.
10731@item h
10732Halfwords (two bytes).
10733@item w
10734Words (four bytes). This is the initial default.
10735@item g
10736Giant words (eight bytes).
10737@end table
10738
10739Each time you specify a unit size with @code{x}, that size becomes the
9a22f0d0
PM
10740default unit the next time you use @code{x}. For the @samp{i} format,
10741the unit size is ignored and is normally not written. For the @samp{s} format,
10742the unit size defaults to @samp{b}, unless it is explicitly given.
10743Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
1074432-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
10745Note that the results depend on the programming language of the
10746current compilation unit. If the language is C, the @samp{s}
10747modifier will use the UTF-16 encoding while @samp{w} will use
10748UTF-32. The encoding is set by the programming language and cannot
10749be altered.
c906108c
SS
10750
10751@item @var{addr}, starting display address
10752@var{addr} is the address where you want @value{GDBN} to begin displaying
10753memory. The expression need not have a pointer value (though it may);
10754it is always interpreted as an integer address of a byte of memory.
10755@xref{Expressions, ,Expressions}, for more information on expressions. The default for
10756@var{addr} is usually just after the last address examined---but several
10757other commands also set the default address: @code{info breakpoints} (to
10758the address of the last breakpoint listed), @code{info line} (to the
10759starting address of a line), and @code{print} (if you use it to display
10760a value from memory).
10761@end table
10762
10763For example, @samp{x/3uh 0x54320} is a request to display three halfwords
10764(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
10765starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
10766words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 10767@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c 10768
bb556f1f
TK
10769You can also specify a negative repeat count to examine memory backward
10770from the given address. For example, @samp{x/-3uh 0x54320} prints three
10771halfwords (@code{h}) at @code{0x54314}, @code{0x54328}, and @code{0x5431c}.
10772
c906108c
SS
10773Since the letters indicating unit sizes are all distinct from the
10774letters specifying output formats, you do not have to remember whether
10775unit size or format comes first; either order works. The output
10776specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
10777(However, the count @var{n} must come first; @samp{wx4} does not work.)
10778
10779Even though the unit size @var{u} is ignored for the formats @samp{s}
10780and @samp{i}, you might still want to use a count @var{n}; for example,
10781@samp{3i} specifies that you want to see three machine instructions,
a4642986
MR
10782including any operands. For convenience, especially when used with
10783the @code{display} command, the @samp{i} format also prints branch delay
10784slot instructions, if any, beyond the count specified, which immediately
10785follow the last instruction that is within the count. The command
10786@code{disassemble} gives an alternative way of inspecting machine
10787instructions; see @ref{Machine Code,,Source and Machine Code}.
c906108c 10788
bb556f1f
TK
10789If a negative repeat count is specified for the formats @samp{s} or @samp{i},
10790the command displays null-terminated strings or instructions before the given
10791address as many as the absolute value of the given number. For the @samp{i}
10792format, we use line number information in the debug info to accurately locate
10793instruction boundaries while disassembling backward. If line info is not
10794available, the command stops examining memory with an error message.
10795
c906108c
SS
10796All the defaults for the arguments to @code{x} are designed to make it
10797easy to continue scanning memory with minimal specifications each time
10798you use @code{x}. For example, after you have inspected three machine
10799instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
10800with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
10801the repeat count @var{n} is used again; the other arguments default as
10802for successive uses of @code{x}.
10803
2b28d209
PP
10804When examining machine instructions, the instruction at current program
10805counter is shown with a @code{=>} marker. For example:
10806
10807@smallexample
10808(@value{GDBP}) x/5i $pc-6
10809 0x804837f <main+11>: mov %esp,%ebp
10810 0x8048381 <main+13>: push %ecx
10811 0x8048382 <main+14>: sub $0x4,%esp
10812=> 0x8048385 <main+17>: movl $0x8048460,(%esp)
10813 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
10814@end smallexample
10815
c906108c
SS
10816@cindex @code{$_}, @code{$__}, and value history
10817The addresses and contents printed by the @code{x} command are not saved
10818in the value history because there is often too much of them and they
10819would get in the way. Instead, @value{GDBN} makes these values available for
10820subsequent use in expressions as values of the convenience variables
10821@code{$_} and @code{$__}. After an @code{x} command, the last address
10822examined is available for use in expressions in the convenience variable
10823@code{$_}. The contents of that address, as examined, are available in
10824the convenience variable @code{$__}.
10825
10826If the @code{x} command has a repeat count, the address and contents saved
10827are from the last memory unit printed; this is not the same as the last
10828address printed if several units were printed on the last line of output.
10829
a86c90e6
SM
10830@anchor{addressable memory unit}
10831@cindex addressable memory unit
10832Most targets have an addressable memory unit size of 8 bits. This means
10833that to each memory address are associated 8 bits of data. Some
10834targets, however, have other addressable memory unit sizes.
10835Within @value{GDBN} and this document, the term
10836@dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
10837when explicitly referring to a chunk of data of that size. The word
10838@dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
10839the addressable memory unit size of the target. For most systems,
10840addressable memory unit is a synonym of byte.
10841
09d4efe1 10842@cindex remote memory comparison
936d2992 10843@cindex target memory comparison
09d4efe1 10844@cindex verify remote memory image
936d2992 10845@cindex verify target memory image
09d4efe1 10846When you are debugging a program running on a remote target machine
936d2992
PA
10847(@pxref{Remote Debugging}), you may wish to verify the program's image
10848in the remote machine's memory against the executable file you
10849downloaded to the target. Or, on any target, you may want to check
10850whether the program has corrupted its own read-only sections. The
10851@code{compare-sections} command is provided for such situations.
09d4efe1
EZ
10852
10853@table @code
10854@kindex compare-sections
95cf3b38 10855@item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
09d4efe1
EZ
10856Compare the data of a loadable section @var{section-name} in the
10857executable file of the program being debugged with the same section in
936d2992 10858the target machine's memory, and report any mismatches. With no
95cf3b38 10859arguments, compares all loadable sections. With an argument of
936d2992
PA
10860@code{-r}, compares all loadable read-only sections.
10861
10862Note: for remote targets, this command can be accelerated if the
10863target supports computing the CRC checksum of a block of memory
10864(@pxref{qCRC packet}).
09d4efe1
EZ
10865@end table
10866
6d2ebf8b 10867@node Auto Display
79a6e687 10868@section Automatic Display
c906108c
SS
10869@cindex automatic display
10870@cindex display of expressions
10871
10872If you find that you want to print the value of an expression frequently
10873(to see how it changes), you might want to add it to the @dfn{automatic
10874display list} so that @value{GDBN} prints its value each time your program stops.
10875Each expression added to the list is given a number to identify it;
10876to remove an expression from the list, you specify that number.
10877The automatic display looks like this:
10878
474c8240 10879@smallexample
c906108c
SS
108802: foo = 38
108813: bar[5] = (struct hack *) 0x3804
474c8240 10882@end smallexample
c906108c
SS
10883
10884@noindent
10885This display shows item numbers, expressions and their current values. As with
10886displays you request manually using @code{x} or @code{print}, you can
10887specify the output format you prefer; in fact, @code{display} decides
ea37ba09
DJ
10888whether to use @code{print} or @code{x} depending your format
10889specification---it uses @code{x} if you specify either the @samp{i}
10890or @samp{s} format, or a unit size; otherwise it uses @code{print}.
c906108c
SS
10891
10892@table @code
10893@kindex display
d4f3574e
SS
10894@item display @var{expr}
10895Add the expression @var{expr} to the list of expressions to display
c906108c
SS
10896each time your program stops. @xref{Expressions, ,Expressions}.
10897
10898@code{display} does not repeat if you press @key{RET} again after using it.
10899
d4f3574e 10900@item display/@var{fmt} @var{expr}
c906108c 10901For @var{fmt} specifying only a display format and not a size or
d4f3574e 10902count, add the expression @var{expr} to the auto-display list but
c906108c 10903arrange to display it each time in the specified format @var{fmt}.
79a6e687 10904@xref{Output Formats,,Output Formats}.
c906108c
SS
10905
10906@item display/@var{fmt} @var{addr}
10907For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
10908number of units, add the expression @var{addr} as a memory address to
10909be examined each time your program stops. Examining means in effect
79a6e687 10910doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
c906108c
SS
10911@end table
10912
10913For example, @samp{display/i $pc} can be helpful, to see the machine
10914instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 10915is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
10916
10917@table @code
10918@kindex delete display
10919@kindex undisplay
10920@item undisplay @var{dnums}@dots{}
10921@itemx delete display @var{dnums}@dots{}
c9174737
PA
10922Remove items from the list of expressions to display. Specify the
10923numbers of the displays that you want affected with the command
10924argument @var{dnums}. It can be a single display number, one of the
10925numbers shown in the first field of the @samp{info display} display;
10926or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
10927
10928@code{undisplay} does not repeat if you press @key{RET} after using it.
10929(Otherwise you would just get the error @samp{No display number @dots{}}.)
10930
10931@kindex disable display
10932@item disable display @var{dnums}@dots{}
10933Disable the display of item numbers @var{dnums}. A disabled display
10934item is not printed automatically, but is not forgotten. It may be
c9174737
PA
10935enabled again later. Specify the numbers of the displays that you
10936want affected with the command argument @var{dnums}. It can be a
10937single display number, one of the numbers shown in the first field of
10938the @samp{info display} display; or it could be a range of display
10939numbers, as in @code{2-4}.
c906108c
SS
10940
10941@kindex enable display
10942@item enable display @var{dnums}@dots{}
10943Enable display of item numbers @var{dnums}. It becomes effective once
10944again in auto display of its expression, until you specify otherwise.
c9174737
PA
10945Specify the numbers of the displays that you want affected with the
10946command argument @var{dnums}. It can be a single display number, one
10947of the numbers shown in the first field of the @samp{info display}
10948display; or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
10949
10950@item display
10951Display the current values of the expressions on the list, just as is
10952done when your program stops.
10953
10954@kindex info display
10955@item info display
10956Print the list of expressions previously set up to display
10957automatically, each one with its item number, but without showing the
10958values. This includes disabled expressions, which are marked as such.
10959It also includes expressions which would not be displayed right now
10960because they refer to automatic variables not currently available.
10961@end table
10962
15387254 10963@cindex display disabled out of scope
c906108c
SS
10964If a display expression refers to local variables, then it does not make
10965sense outside the lexical context for which it was set up. Such an
10966expression is disabled when execution enters a context where one of its
10967variables is not defined. For example, if you give the command
10968@code{display last_char} while inside a function with an argument
10969@code{last_char}, @value{GDBN} displays this argument while your program
10970continues to stop inside that function. When it stops elsewhere---where
10971there is no variable @code{last_char}---the display is disabled
10972automatically. The next time your program stops where @code{last_char}
10973is meaningful, you can enable the display expression once again.
10974
6d2ebf8b 10975@node Print Settings
79a6e687 10976@section Print Settings
c906108c
SS
10977
10978@cindex format options
10979@cindex print settings
10980@value{GDBN} provides the following ways to control how arrays, structures,
10981and symbols are printed.
10982
10983@noindent
10984These settings are useful for debugging programs in any language:
10985
10986@table @code
4644b6e3 10987@kindex set print
3345721a 10988@anchor{set print address}
c906108c
SS
10989@item set print address
10990@itemx set print address on
4644b6e3 10991@cindex print/don't print memory addresses
c906108c
SS
10992@value{GDBN} prints memory addresses showing the location of stack
10993traces, structure values, pointer values, breakpoints, and so forth,
10994even when it also displays the contents of those addresses. The default
10995is @code{on}. For example, this is what a stack frame display looks like with
10996@code{set print address on}:
10997
10998@smallexample
10999@group
11000(@value{GDBP}) f
11001#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
11002 at input.c:530
11003530 if (lquote != def_lquote)
11004@end group
11005@end smallexample
11006
11007@item set print address off
11008Do not print addresses when displaying their contents. For example,
11009this is the same stack frame displayed with @code{set print address off}:
11010
11011@smallexample
11012@group
11013(@value{GDBP}) set print addr off
11014(@value{GDBP}) f
11015#0 set_quotes (lq="<<", rq=">>") at input.c:530
11016530 if (lquote != def_lquote)
11017@end group
11018@end smallexample
11019
11020You can use @samp{set print address off} to eliminate all machine
11021dependent displays from the @value{GDBN} interface. For example, with
11022@code{print address off}, you should get the same text for backtraces on
11023all machines---whether or not they involve pointer arguments.
11024
4644b6e3 11025@kindex show print
c906108c
SS
11026@item show print address
11027Show whether or not addresses are to be printed.
11028@end table
11029
11030When @value{GDBN} prints a symbolic address, it normally prints the
11031closest earlier symbol plus an offset. If that symbol does not uniquely
11032identify the address (for example, it is a name whose scope is a single
11033source file), you may need to clarify. One way to do this is with
11034@code{info line}, for example @samp{info line *0x4537}. Alternately,
11035you can set @value{GDBN} to print the source file and line number when
11036it prints a symbolic address:
11037
11038@table @code
c906108c 11039@item set print symbol-filename on
9c16f35a
EZ
11040@cindex source file and line of a symbol
11041@cindex symbol, source file and line
c906108c
SS
11042Tell @value{GDBN} to print the source file name and line number of a
11043symbol in the symbolic form of an address.
11044
11045@item set print symbol-filename off
11046Do not print source file name and line number of a symbol. This is the
11047default.
11048
c906108c
SS
11049@item show print symbol-filename
11050Show whether or not @value{GDBN} will print the source file name and
11051line number of a symbol in the symbolic form of an address.
11052@end table
11053
11054Another situation where it is helpful to show symbol filenames and line
11055numbers is when disassembling code; @value{GDBN} shows you the line
11056number and source file that corresponds to each instruction.
11057
11058Also, you may wish to see the symbolic form only if the address being
11059printed is reasonably close to the closest earlier symbol:
11060
11061@table @code
c906108c 11062@item set print max-symbolic-offset @var{max-offset}
f81d1120 11063@itemx set print max-symbolic-offset unlimited
4644b6e3 11064@cindex maximum value for offset of closest symbol
c906108c
SS
11065Tell @value{GDBN} to only display the symbolic form of an address if the
11066offset between the closest earlier symbol and the address is less than
f81d1120
PA
11067@var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
11068to always print the symbolic form of an address if any symbol precedes
11069it. Zero is equivalent to @code{unlimited}.
c906108c 11070
c906108c
SS
11071@item show print max-symbolic-offset
11072Ask how large the maximum offset is that @value{GDBN} prints in a
11073symbolic address.
11074@end table
11075
11076@cindex wild pointer, interpreting
11077@cindex pointer, finding referent
11078If you have a pointer and you are not sure where it points, try
11079@samp{set print symbol-filename on}. Then you can determine the name
11080and source file location of the variable where it points, using
11081@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
11082For example, here @value{GDBN} shows that a variable @code{ptt} points
11083at another variable @code{t}, defined in @file{hi2.c}:
11084
474c8240 11085@smallexample
c906108c
SS
11086(@value{GDBP}) set print symbol-filename on
11087(@value{GDBP}) p/a ptt
11088$4 = 0xe008 <t in hi2.c>
474c8240 11089@end smallexample
c906108c
SS
11090
11091@quotation
11092@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
11093does not show the symbol name and filename of the referent, even with
11094the appropriate @code{set print} options turned on.
11095@end quotation
11096
9cb709b6
TT
11097You can also enable @samp{/a}-like formatting all the time using
11098@samp{set print symbol on}:
11099
3345721a 11100@anchor{set print symbol}
9cb709b6
TT
11101@table @code
11102@item set print symbol on
11103Tell @value{GDBN} to print the symbol corresponding to an address, if
11104one exists.
11105
11106@item set print symbol off
11107Tell @value{GDBN} not to print the symbol corresponding to an
11108address. In this mode, @value{GDBN} will still print the symbol
11109corresponding to pointers to functions. This is the default.
11110
11111@item show print symbol
11112Show whether @value{GDBN} will display the symbol corresponding to an
11113address.
11114@end table
11115
c906108c
SS
11116Other settings control how different kinds of objects are printed:
11117
11118@table @code
3345721a 11119@anchor{set print array}
c906108c
SS
11120@item set print array
11121@itemx set print array on
4644b6e3 11122@cindex pretty print arrays
c906108c
SS
11123Pretty print arrays. This format is more convenient to read,
11124but uses more space. The default is off.
11125
11126@item set print array off
11127Return to compressed format for arrays.
11128
c906108c
SS
11129@item show print array
11130Show whether compressed or pretty format is selected for displaying
11131arrays.
11132
3c9c013a 11133@cindex print array indexes
3345721a 11134@anchor{set print array-indexes}
3c9c013a
JB
11135@item set print array-indexes
11136@itemx set print array-indexes on
11137Print the index of each element when displaying arrays. May be more
11138convenient to locate a given element in the array or quickly find the
11139index of a given element in that printed array. The default is off.
11140
11141@item set print array-indexes off
11142Stop printing element indexes when displaying arrays.
11143
11144@item show print array-indexes
11145Show whether the index of each element is printed when displaying
11146arrays.
11147
3345721a 11148@anchor{set print elements}
c906108c 11149@item set print elements @var{number-of-elements}
f81d1120 11150@itemx set print elements unlimited
4644b6e3 11151@cindex number of array elements to print
9c16f35a 11152@cindex limit on number of printed array elements
c906108c
SS
11153Set a limit on how many elements of an array @value{GDBN} will print.
11154If @value{GDBN} is printing a large array, it stops printing after it has
11155printed the number of elements set by the @code{set print elements} command.
11156This limit also applies to the display of strings.
d4f3574e 11157When @value{GDBN} starts, this limit is set to 200.
f81d1120
PA
11158Setting @var{number-of-elements} to @code{unlimited} or zero means
11159that the number of elements to print is unlimited.
c906108c 11160
c906108c
SS
11161@item show print elements
11162Display the number of elements of a large array that @value{GDBN} will print.
11163If the number is 0, then the printing is unlimited.
11164
3345721a 11165@anchor{set print frame-arguments}
b4740add 11166@item set print frame-arguments @var{value}
a0381d3a 11167@kindex set print frame-arguments
b4740add
JB
11168@cindex printing frame argument values
11169@cindex print all frame argument values
11170@cindex print frame argument values for scalars only
bc4268a5 11171@cindex do not print frame arguments
b4740add
JB
11172This command allows to control how the values of arguments are printed
11173when the debugger prints a frame (@pxref{Frames}). The possible
11174values are:
11175
11176@table @code
11177@item all
4f5376b2 11178The values of all arguments are printed.
b4740add
JB
11179
11180@item scalars
11181Print the value of an argument only if it is a scalar. The value of more
11182complex arguments such as arrays, structures, unions, etc, is replaced
4f5376b2
JB
11183by @code{@dots{}}. This is the default. Here is an example where
11184only scalar arguments are shown:
b4740add
JB
11185
11186@smallexample
11187#1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
11188 at frame-args.c:23
11189@end smallexample
11190
11191@item none
11192None of the argument values are printed. Instead, the value of each argument
11193is replaced by @code{@dots{}}. In this case, the example above now becomes:
11194
11195@smallexample
11196#1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
11197 at frame-args.c:23
11198@end smallexample
bc4268a5
PW
11199
11200@item presence
11201Only the presence of arguments is indicated by @code{@dots{}}.
11202The @code{@dots{}} are not printed for function without any arguments.
11203None of the argument names and values are printed.
11204In this case, the example above now becomes:
11205
11206@smallexample
11207#1 0x08048361 in call_me (@dots{}) at frame-args.c:23
11208@end smallexample
11209
b4740add
JB
11210@end table
11211
4f5376b2
JB
11212By default, only scalar arguments are printed. This command can be used
11213to configure the debugger to print the value of all arguments, regardless
11214of their type. However, it is often advantageous to not print the value
11215of more complex parameters. For instance, it reduces the amount of
11216information printed in each frame, making the backtrace more readable.
11217Also, it improves performance when displaying Ada frames, because
11218the computation of large arguments can sometimes be CPU-intensive,
11219especially in large applications. Setting @code{print frame-arguments}
bc4268a5
PW
11220to @code{scalars} (the default), @code{none} or @code{presence} avoids
11221this computation, thus speeding up the display of each Ada frame.
b4740add
JB
11222
11223@item show print frame-arguments
11224Show how the value of arguments should be displayed when printing a frame.
11225
3345721a 11226@anchor{set print raw-frame-arguments}
2daf894e 11227@item set print raw-frame-arguments on
e7045703
DE
11228Print frame arguments in raw, non pretty-printed, form.
11229
2daf894e 11230@item set print raw-frame-arguments off
e7045703
DE
11231Print frame arguments in pretty-printed form, if there is a pretty-printer
11232for the value (@pxref{Pretty Printing}),
11233otherwise print the value in raw form.
11234This is the default.
11235
2daf894e 11236@item show print raw-frame-arguments
e7045703
DE
11237Show whether to print frame arguments in raw form.
11238
36b11add 11239@anchor{set print entry-values}
e18b2753
JK
11240@item set print entry-values @var{value}
11241@kindex set print entry-values
11242Set printing of frame argument values at function entry. In some cases
11243@value{GDBN} can determine the value of function argument which was passed by
11244the function caller, even if the value was modified inside the called function
11245and therefore is different. With optimized code, the current value could be
11246unavailable, but the entry value may still be known.
11247
11248The default value is @code{default} (see below for its description). Older
11249@value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
11250this feature will behave in the @code{default} setting the same way as with the
11251@code{no} setting.
11252
11253This functionality is currently supported only by DWARF 2 debugging format and
216f72a1 11254the compiler has to produce @samp{DW_TAG_call_site} tags. With
e18b2753
JK
11255@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11256this information.
11257
11258The @var{value} parameter can be one of the following:
11259
11260@table @code
11261@item no
11262Print only actual parameter values, never print values from function entry
11263point.
11264@smallexample
11265#0 equal (val=5)
11266#0 different (val=6)
11267#0 lost (val=<optimized out>)
11268#0 born (val=10)
11269#0 invalid (val=<optimized out>)
11270@end smallexample
11271
11272@item only
11273Print only parameter values from function entry point. The actual parameter
11274values are never printed.
11275@smallexample
11276#0 equal (val@@entry=5)
11277#0 different (val@@entry=5)
11278#0 lost (val@@entry=5)
11279#0 born (val@@entry=<optimized out>)
11280#0 invalid (val@@entry=<optimized out>)
11281@end smallexample
11282
11283@item preferred
11284Print only parameter values from function entry point. If value from function
11285entry point is not known while the actual value is known, print the actual
11286value for such parameter.
11287@smallexample
11288#0 equal (val@@entry=5)
11289#0 different (val@@entry=5)
11290#0 lost (val@@entry=5)
11291#0 born (val=10)
11292#0 invalid (val@@entry=<optimized out>)
11293@end smallexample
11294
11295@item if-needed
11296Print actual parameter values. If actual parameter value is not known while
11297value from function entry point is known, print the entry point value for such
11298parameter.
11299@smallexample
11300#0 equal (val=5)
11301#0 different (val=6)
11302#0 lost (val@@entry=5)
11303#0 born (val=10)
11304#0 invalid (val=<optimized out>)
11305@end smallexample
11306
11307@item both
11308Always print both the actual parameter value and its value from function entry
11309point, even if values of one or both are not available due to compiler
11310optimizations.
11311@smallexample
11312#0 equal (val=5, val@@entry=5)
11313#0 different (val=6, val@@entry=5)
11314#0 lost (val=<optimized out>, val@@entry=5)
11315#0 born (val=10, val@@entry=<optimized out>)
11316#0 invalid (val=<optimized out>, val@@entry=<optimized out>)
11317@end smallexample
11318
11319@item compact
11320Print the actual parameter value if it is known and also its value from
11321function entry point if it is known. If neither is known, print for the actual
11322value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
11323values are known and identical, print the shortened
11324@code{param=param@@entry=VALUE} notation.
11325@smallexample
11326#0 equal (val=val@@entry=5)
11327#0 different (val=6, val@@entry=5)
11328#0 lost (val@@entry=5)
11329#0 born (val=10)
11330#0 invalid (val=<optimized out>)
11331@end smallexample
11332
11333@item default
11334Always print the actual parameter value. Print also its value from function
11335entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
11336if both values are known and identical, print the shortened
11337@code{param=param@@entry=VALUE} notation.
11338@smallexample
11339#0 equal (val=val@@entry=5)
11340#0 different (val=6, val@@entry=5)
11341#0 lost (val=<optimized out>, val@@entry=5)
11342#0 born (val=10)
11343#0 invalid (val=<optimized out>)
11344@end smallexample
11345@end table
11346
11347For analysis messages on possible failures of frame argument values at function
11348entry resolution see @ref{set debug entry-values}.
11349
11350@item show print entry-values
11351Show the method being used for printing of frame argument values at function
11352entry.
11353
bc4268a5
PW
11354@anchor{set print frame-info}
11355@item set print frame-info @var{value}
11356@kindex set print frame-info
11357@cindex printing frame information
11358@cindex frame information, printing
11359This command allows to control the information printed when
11360the debugger prints a frame. See @ref{Frames}, @ref{Backtrace},
11361for a general explanation about frames and frame information.
11362Note that some other settings (such as @code{set print frame-arguments}
11363and @code{set print address}) are also influencing if and how some frame
11364information is displayed. In particular, the frame program counter is never
11365printed if @code{set print address} is off.
11366
11367The possible values for @code{set print frame-info} are:
11368@table @code
11369@item short-location
11370Print the frame level, the program counter (if not at the
11371beginning of the location source line), the function, the function
11372arguments.
11373@item location
11374Same as @code{short-location} but also print the source file and source line
11375number.
11376@item location-and-address
11377Same as @code{location} but print the program counter even if located at the
11378beginning of the location source line.
11379@item source-line
11380Print the program counter (if not at the beginning of the location
11381source line), the line number and the source line.
11382@item source-and-location
11383Print what @code{location} and @code{source-line} are printing.
11384@item auto
11385The information printed for a frame is decided automatically
11386by the @value{GDBN} command that prints a frame.
11387For example, @code{frame} prints the information printed by
11388@code{source-and-location} while @code{stepi} will switch between
11389@code{source-line} and @code{source-and-location} depending on the program
11390counter.
11391The default value is @code{auto}.
11392@end table
11393
3345721a 11394@anchor{set print repeats}
f81d1120
PA
11395@item set print repeats @var{number-of-repeats}
11396@itemx set print repeats unlimited
9c16f35a
EZ
11397@cindex repeated array elements
11398Set the threshold for suppressing display of repeated array
d3e8051b 11399elements. When the number of consecutive identical elements of an
9c16f35a
EZ
11400array exceeds the threshold, @value{GDBN} prints the string
11401@code{"<repeats @var{n} times>"}, where @var{n} is the number of
11402identical repetitions, instead of displaying the identical elements
f81d1120
PA
11403themselves. Setting the threshold to @code{unlimited} or zero will
11404cause all elements to be individually printed. The default threshold
11405is 10.
9c16f35a
EZ
11406
11407@item show print repeats
11408Display the current threshold for printing repeated identical
11409elements.
11410
3345721a 11411@anchor{set print max-depth}
2e62ab40
AB
11412@item set print max-depth @var{depth}
11413@item set print max-depth unlimited
11414@cindex printing nested structures
11415Set the threshold after which nested structures are replaced with
11416ellipsis, this can make visualising deeply nested structures easier.
11417
11418For example, given this C code
11419
11420@smallexample
11421typedef struct s1 @{ int a; @} s1;
11422typedef struct s2 @{ s1 b; @} s2;
11423typedef struct s3 @{ s2 c; @} s3;
11424typedef struct s4 @{ s3 d; @} s4;
11425
11426s4 var = @{ @{ @{ @{ 3 @} @} @} @};
11427@end smallexample
11428
11429The following table shows how different values of @var{depth} will
11430effect how @code{var} is printed by @value{GDBN}:
11431
11432@multitable @columnfractions .3 .7
11433@headitem @var{depth} setting @tab Result of @samp{p var}
11434@item unlimited
11435@tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11436@item @code{0}
11437@tab @code{$1 = @{...@}}
11438@item @code{1}
11439@tab @code{$1 = @{d = @{...@}@}}
11440@item @code{2}
11441@tab @code{$1 = @{d = @{c = @{...@}@}@}}
11442@item @code{3}
11443@tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
11444@item @code{4}
11445@tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11446@end multitable
11447
11448To see the contents of structures that have been hidden the user can
11449either increase the print max-depth, or they can print the elements of
11450the structure that are visible, for example
11451
11452@smallexample
11453(gdb) set print max-depth 2
11454(gdb) p var
11455$1 = @{d = @{c = @{...@}@}@}
11456(gdb) p var.d
11457$2 = @{c = @{b = @{...@}@}@}
11458(gdb) p var.d.c
11459$3 = @{b = @{a = 3@}@}
11460@end smallexample
11461
11462The pattern used to replace nested structures varies based on
11463language, for most languages @code{@{...@}} is used, but Fortran uses
11464@code{(...)}.
11465
11466@item show print max-depth
11467Display the current threshold after which nested structures are
11468replaces with ellipsis.
11469
3345721a 11470@anchor{set print null-stop}
c906108c 11471@item set print null-stop
4644b6e3 11472@cindex @sc{null} elements in arrays
c906108c 11473Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 11474@sc{null} is encountered. This is useful when large arrays actually
c906108c 11475contain only short strings.
d4f3574e 11476The default is off.
c906108c 11477
9c16f35a
EZ
11478@item show print null-stop
11479Show whether @value{GDBN} stops printing an array on the first
11480@sc{null} character.
11481
3345721a 11482@anchor{set print pretty}
c906108c 11483@item set print pretty on
9c16f35a
EZ
11484@cindex print structures in indented form
11485@cindex indentation in structure display
5d161b24 11486Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
11487per line, like this:
11488
11489@smallexample
11490@group
11491$1 = @{
11492 next = 0x0,
11493 flags = @{
11494 sweet = 1,
11495 sour = 1
11496 @},
11497 meat = 0x54 "Pork"
11498@}
11499@end group
11500@end smallexample
11501
11502@item set print pretty off
11503Cause @value{GDBN} to print structures in a compact format, like this:
11504
11505@smallexample
11506@group
11507$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
11508meat = 0x54 "Pork"@}
11509@end group
11510@end smallexample
11511
11512@noindent
11513This is the default format.
11514
c906108c
SS
11515@item show print pretty
11516Show which format @value{GDBN} is using to print structures.
11517
d8edc8b7
PW
11518@anchor{set print raw-values}
11519@item set print raw-values on
11520Print values in raw form, without applying the pretty
11521printers for the value.
11522
11523@item set print raw-values off
11524Print values in pretty-printed form, if there is a pretty-printer
11525for the value (@pxref{Pretty Printing}),
11526otherwise print the value in raw form.
11527
11528The default setting is ``off''.
11529
11530@item show print raw-values
11531Show whether to print values in raw form.
11532
c906108c 11533@item set print sevenbit-strings on
4644b6e3
EZ
11534@cindex eight-bit characters in strings
11535@cindex octal escapes in strings
c906108c
SS
11536Print using only seven-bit characters; if this option is set,
11537@value{GDBN} displays any eight-bit characters (in strings or
11538character values) using the notation @code{\}@var{nnn}. This setting is
11539best if you are working in English (@sc{ascii}) and you use the
11540high-order bit of characters as a marker or ``meta'' bit.
11541
11542@item set print sevenbit-strings off
11543Print full eight-bit characters. This allows the use of more
11544international character sets, and is the default.
11545
c906108c
SS
11546@item show print sevenbit-strings
11547Show whether or not @value{GDBN} is printing only seven-bit characters.
11548
3345721a 11549@anchor{set print union}
c906108c 11550@item set print union on
4644b6e3 11551@cindex unions in structures, printing
9c16f35a
EZ
11552Tell @value{GDBN} to print unions which are contained in structures
11553and other unions. This is the default setting.
c906108c
SS
11554
11555@item set print union off
9c16f35a
EZ
11556Tell @value{GDBN} not to print unions which are contained in
11557structures and other unions. @value{GDBN} will print @code{"@{...@}"}
11558instead.
c906108c 11559
c906108c
SS
11560@item show print union
11561Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 11562structures and other unions.
c906108c
SS
11563
11564For example, given the declarations
11565
11566@smallexample
11567typedef enum @{Tree, Bug@} Species;
11568typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 11569typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
11570 Bug_forms;
11571
11572struct thing @{
11573 Species it;
11574 union @{
11575 Tree_forms tree;
11576 Bug_forms bug;
11577 @} form;
11578@};
11579
11580struct thing foo = @{Tree, @{Acorn@}@};
11581@end smallexample
11582
11583@noindent
11584with @code{set print union on} in effect @samp{p foo} would print
11585
11586@smallexample
11587$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
11588@end smallexample
11589
11590@noindent
11591and with @code{set print union off} in effect it would print
11592
11593@smallexample
11594$1 = @{it = Tree, form = @{...@}@}
11595@end smallexample
9c16f35a
EZ
11596
11597@noindent
11598@code{set print union} affects programs written in C-like languages
11599and in Pascal.
c906108c
SS
11600@end table
11601
c906108c
SS
11602@need 1000
11603@noindent
b37052ae 11604These settings are of interest when debugging C@t{++} programs:
c906108c
SS
11605
11606@table @code
4644b6e3 11607@cindex demangling C@t{++} names
c906108c
SS
11608@item set print demangle
11609@itemx set print demangle on
b37052ae 11610Print C@t{++} names in their source form rather than in the encoded
c906108c 11611(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 11612linkage. The default is on.
c906108c 11613
c906108c 11614@item show print demangle
b37052ae 11615Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 11616
c906108c
SS
11617@item set print asm-demangle
11618@itemx set print asm-demangle on
b37052ae 11619Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
11620in assembler code printouts such as instruction disassemblies.
11621The default is off.
11622
c906108c 11623@item show print asm-demangle
b37052ae 11624Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
11625or demangled form.
11626
b37052ae
EZ
11627@cindex C@t{++} symbol decoding style
11628@cindex symbol decoding style, C@t{++}
a8f24a35 11629@kindex set demangle-style
c906108c 11630@item set demangle-style @var{style}
041be526
SM
11631Choose among several encoding schemes used by different compilers to represent
11632C@t{++} names. If you omit @var{style}, you will see a list of possible
11633formats. The default value is @var{auto}, which lets @value{GDBN} choose a
11634decoding style by inspecting your program.
c906108c 11635
c906108c 11636@item show demangle-style
b37052ae 11637Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 11638
3345721a 11639@anchor{set print object}
c906108c
SS
11640@item set print object
11641@itemx set print object on
4644b6e3 11642@cindex derived type of an object, printing
9c16f35a 11643@cindex display derived types
c906108c
SS
11644When displaying a pointer to an object, identify the @emph{actual}
11645(derived) type of the object rather than the @emph{declared} type, using
625c0d47
TT
11646the virtual function table. Note that the virtual function table is
11647required---this feature can only work for objects that have run-time
11648type identification; a single virtual method in the object's declared
8264ba82
AG
11649type is sufficient. Note that this setting is also taken into account when
11650working with variable objects via MI (@pxref{GDB/MI}).
c906108c
SS
11651
11652@item set print object off
11653Display only the declared type of objects, without reference to the
11654virtual function table. This is the default setting.
11655
c906108c
SS
11656@item show print object
11657Show whether actual, or declared, object types are displayed.
11658
3345721a 11659@anchor{set print static-members}
c906108c
SS
11660@item set print static-members
11661@itemx set print static-members on
4644b6e3 11662@cindex static members of C@t{++} objects
b37052ae 11663Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
11664
11665@item set print static-members off
b37052ae 11666Do not print static members when displaying a C@t{++} object.
c906108c 11667
c906108c 11668@item show print static-members
9c16f35a
EZ
11669Show whether C@t{++} static members are printed or not.
11670
11671@item set print pascal_static-members
11672@itemx set print pascal_static-members on
d3e8051b
EZ
11673@cindex static members of Pascal objects
11674@cindex Pascal objects, static members display
9c16f35a
EZ
11675Print static members when displaying a Pascal object. The default is on.
11676
11677@item set print pascal_static-members off
11678Do not print static members when displaying a Pascal object.
11679
11680@item show print pascal_static-members
11681Show whether Pascal static members are printed or not.
c906108c
SS
11682
11683@c These don't work with HP ANSI C++ yet.
3345721a 11684@anchor{set print vtbl}
c906108c
SS
11685@item set print vtbl
11686@itemx set print vtbl on
4644b6e3 11687@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
11688@cindex virtual functions (C@t{++}) display
11689@cindex VTBL display
b37052ae 11690Pretty print C@t{++} virtual function tables. The default is off.
c906108c 11691(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 11692ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
11693
11694@item set print vtbl off
b37052ae 11695Do not pretty print C@t{++} virtual function tables.
c906108c 11696
c906108c 11697@item show print vtbl
b37052ae 11698Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 11699@end table
c906108c 11700
4c374409
JK
11701@node Pretty Printing
11702@section Pretty Printing
11703
11704@value{GDBN} provides a mechanism to allow pretty-printing of values using
11705Python code. It greatly simplifies the display of complex objects. This
11706mechanism works for both MI and the CLI.
11707
7b51bc51
DE
11708@menu
11709* Pretty-Printer Introduction:: Introduction to pretty-printers
11710* Pretty-Printer Example:: An example pretty-printer
11711* Pretty-Printer Commands:: Pretty-printer commands
11712@end menu
11713
11714@node Pretty-Printer Introduction
11715@subsection Pretty-Printer Introduction
11716
11717When @value{GDBN} prints a value, it first sees if there is a pretty-printer
11718registered for the value. If there is then @value{GDBN} invokes the
11719pretty-printer to print the value. Otherwise the value is printed normally.
11720
11721Pretty-printers are normally named. This makes them easy to manage.
11722The @samp{info pretty-printer} command will list all the installed
11723pretty-printers with their names.
11724If a pretty-printer can handle multiple data types, then its
11725@dfn{subprinters} are the printers for the individual data types.
11726Each such subprinter has its own name.
4e04c971 11727The format of the name is @var{printer-name};@var{subprinter-name}.
7b51bc51
DE
11728
11729Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
11730Typically they are automatically loaded and registered when the corresponding
11731debug information is loaded, thus making them available without having to
11732do anything special.
11733
11734There are three places where a pretty-printer can be registered.
11735
11736@itemize @bullet
11737@item
11738Pretty-printers registered globally are available when debugging
11739all inferiors.
11740
11741@item
11742Pretty-printers registered with a program space are available only
11743when debugging that program.
11744@xref{Progspaces In Python}, for more details on program spaces in Python.
11745
11746@item
11747Pretty-printers registered with an objfile are loaded and unloaded
11748with the corresponding objfile (e.g., shared library).
11749@xref{Objfiles In Python}, for more details on objfiles in Python.
11750@end itemize
11751
11752@xref{Selecting Pretty-Printers}, for further information on how
11753pretty-printers are selected,
11754
11755@xref{Writing a Pretty-Printer}, for implementing pretty printers
11756for new types.
11757
11758@node Pretty-Printer Example
11759@subsection Pretty-Printer Example
11760
11761Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
4c374409
JK
11762
11763@smallexample
11764(@value{GDBP}) print s
11765$1 = @{
11766 static npos = 4294967295,
11767 _M_dataplus = @{
11768 <std::allocator<char>> = @{
11769 <__gnu_cxx::new_allocator<char>> = @{
11770 <No data fields>@}, <No data fields>
11771 @},
11772 members of std::basic_string<char, std::char_traits<char>,
11773 std::allocator<char> >::_Alloc_hider:
11774 _M_p = 0x804a014 "abcd"
11775 @}
11776@}
11777@end smallexample
11778
11779With a pretty-printer for @code{std::string} only the contents are printed:
11780
11781@smallexample
11782(@value{GDBP}) print s
11783$2 = "abcd"
11784@end smallexample
11785
7b51bc51
DE
11786@node Pretty-Printer Commands
11787@subsection Pretty-Printer Commands
11788@cindex pretty-printer commands
11789
11790@table @code
11791@kindex info pretty-printer
11792@item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11793Print the list of installed pretty-printers.
11794This includes disabled pretty-printers, which are marked as such.
11795
11796@var{object-regexp} is a regular expression matching the objects
11797whose pretty-printers to list.
11798Objects can be @code{global}, the program space's file
11799(@pxref{Progspaces In Python}),
11800and the object files within that program space (@pxref{Objfiles In Python}).
11801@xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
11802looks up a printer from these three objects.
11803
11804@var{name-regexp} is a regular expression matching the name of the printers
11805to list.
11806
11807@kindex disable pretty-printer
11808@item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11809Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11810A disabled pretty-printer is not forgotten, it may be enabled again later.
11811
11812@kindex enable pretty-printer
11813@item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11814Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11815@end table
11816
11817Example:
11818
11819Suppose we have three pretty-printers installed: one from library1.so
11820named @code{foo} that prints objects of type @code{foo}, and
11821another from library2.so named @code{bar} that prints two types of objects,
11822@code{bar1} and @code{bar2}.
11823
11824@smallexample
11825(gdb) info pretty-printer
11826library1.so:
11827 foo
11828library2.so:
11829 bar
11830 bar1
11831 bar2
11832(gdb) info pretty-printer library2
11833library2.so:
11834 bar
11835 bar1
11836 bar2
11837(gdb) disable pretty-printer library1
118381 printer disabled
118392 of 3 printers enabled
11840(gdb) info pretty-printer
11841library1.so:
11842 foo [disabled]
11843library2.so:
11844 bar
11845 bar1
11846 bar2
088a96da 11847(gdb) disable pretty-printer library2 bar;bar1
7b51bc51
DE
118481 printer disabled
118491 of 3 printers enabled
11850(gdb) info pretty-printer library2
11851library1.so:
11852 foo [disabled]
11853library2.so:
11854 bar
11855 bar1 [disabled]
11856 bar2
11857(gdb) disable pretty-printer library2 bar
118581 printer disabled
118590 of 3 printers enabled
11860(gdb) info pretty-printer library2
11861library1.so:
11862 foo [disabled]
11863library2.so:
11864 bar [disabled]
11865 bar1 [disabled]
11866 bar2
11867@end smallexample
11868
11869Note that for @code{bar} the entire printer can be disabled,
11870as can each individual subprinter.
4c374409 11871
d8edc8b7
PW
11872Printing values and frame arguments is done by default using
11873the enabled pretty printers.
11874
11875The print option @code{-raw-values} and @value{GDBN} setting
11876@code{set print raw-values} (@pxref{set print raw-values}) can be
11877used to print values without applying the enabled pretty printers.
11878
11879Similarly, the backtrace option @code{-raw-frame-arguments} and
11880@value{GDBN} setting @code{set print raw-frame-arguments}
11881(@pxref{set print raw-frame-arguments}) can be used to ignore the
11882enabled pretty printers when printing frame argument values.
11883
6d2ebf8b 11884@node Value History
79a6e687 11885@section Value History
c906108c
SS
11886
11887@cindex value history
9c16f35a 11888@cindex history of values printed by @value{GDBN}
5d161b24
DB
11889Values printed by the @code{print} command are saved in the @value{GDBN}
11890@dfn{value history}. This allows you to refer to them in other expressions.
11891Values are kept until the symbol table is re-read or discarded
11892(for example with the @code{file} or @code{symbol-file} commands).
11893When the symbol table changes, the value history is discarded,
11894since the values may contain pointers back to the types defined in the
c906108c
SS
11895symbol table.
11896
11897@cindex @code{$}
11898@cindex @code{$$}
11899@cindex history number
11900The values printed are given @dfn{history numbers} by which you can
11901refer to them. These are successive integers starting with one.
11902@code{print} shows you the history number assigned to a value by
11903printing @samp{$@var{num} = } before the value; here @var{num} is the
11904history number.
11905
11906To refer to any previous value, use @samp{$} followed by the value's
11907history number. The way @code{print} labels its output is designed to
11908remind you of this. Just @code{$} refers to the most recent value in
11909the history, and @code{$$} refers to the value before that.
11910@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
11911is the value just prior to @code{$$}, @code{$$1} is equivalent to
11912@code{$$}, and @code{$$0} is equivalent to @code{$}.
11913
11914For example, suppose you have just printed a pointer to a structure and
11915want to see the contents of the structure. It suffices to type
11916
474c8240 11917@smallexample
c906108c 11918p *$
474c8240 11919@end smallexample
c906108c
SS
11920
11921If you have a chain of structures where the component @code{next} points
11922to the next one, you can print the contents of the next one with this:
11923
474c8240 11924@smallexample
c906108c 11925p *$.next
474c8240 11926@end smallexample
c906108c
SS
11927
11928@noindent
11929You can print successive links in the chain by repeating this
11930command---which you can do by just typing @key{RET}.
11931
11932Note that the history records values, not expressions. If the value of
11933@code{x} is 4 and you type these commands:
11934
474c8240 11935@smallexample
c906108c
SS
11936print x
11937set x=5
474c8240 11938@end smallexample
c906108c
SS
11939
11940@noindent
11941then the value recorded in the value history by the @code{print} command
11942remains 4 even though the value of @code{x} has changed.
11943
11944@table @code
11945@kindex show values
11946@item show values
11947Print the last ten values in the value history, with their item numbers.
11948This is like @samp{p@ $$9} repeated ten times, except that @code{show
11949values} does not change the history.
11950
11951@item show values @var{n}
11952Print ten history values centered on history item number @var{n}.
11953
11954@item show values +
11955Print ten history values just after the values last printed. If no more
11956values are available, @code{show values +} produces no display.
11957@end table
11958
11959Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
11960same effect as @samp{show values +}.
11961
6d2ebf8b 11962@node Convenience Vars
79a6e687 11963@section Convenience Variables
c906108c
SS
11964
11965@cindex convenience variables
9c16f35a 11966@cindex user-defined variables
c906108c
SS
11967@value{GDBN} provides @dfn{convenience variables} that you can use within
11968@value{GDBN} to hold on to a value and refer to it later. These variables
11969exist entirely within @value{GDBN}; they are not part of your program, and
11970setting a convenience variable has no direct effect on further execution
11971of your program. That is why you can use them freely.
11972
11973Convenience variables are prefixed with @samp{$}. Any name preceded by
11974@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 11975the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c 11976(Value history references, in contrast, are @emph{numbers} preceded
79a6e687 11977by @samp{$}. @xref{Value History, ,Value History}.)
c906108c
SS
11978
11979You can save a value in a convenience variable with an assignment
11980expression, just as you would set a variable in your program.
11981For example:
11982
474c8240 11983@smallexample
c906108c 11984set $foo = *object_ptr
474c8240 11985@end smallexample
c906108c
SS
11986
11987@noindent
11988would save in @code{$foo} the value contained in the object pointed to by
11989@code{object_ptr}.
11990
11991Using a convenience variable for the first time creates it, but its
11992value is @code{void} until you assign a new value. You can alter the
11993value with another assignment at any time.
11994
11995Convenience variables have no fixed types. You can assign a convenience
11996variable any type of value, including structures and arrays, even if
11997that variable already has a value of a different type. The convenience
11998variable, when used as an expression, has the type of its current value.
11999
12000@table @code
12001@kindex show convenience
f47f77df 12002@cindex show all user variables and functions
c906108c 12003@item show convenience
f47f77df
DE
12004Print a list of convenience variables used so far, and their values,
12005as well as a list of the convenience functions.
d4f3574e 12006Abbreviated @code{show conv}.
53e5f3cf
AS
12007
12008@kindex init-if-undefined
12009@cindex convenience variables, initializing
12010@item init-if-undefined $@var{variable} = @var{expression}
12011Set a convenience variable if it has not already been set. This is useful
12012for user-defined commands that keep some state. It is similar, in concept,
12013to using local static variables with initializers in C (except that
12014convenience variables are global). It can also be used to allow users to
12015override default values used in a command script.
12016
12017If the variable is already defined then the expression is not evaluated so
12018any side-effects do not occur.
c906108c
SS
12019@end table
12020
12021One of the ways to use a convenience variable is as a counter to be
12022incremented or a pointer to be advanced. For example, to print
12023a field from successive elements of an array of structures:
12024
474c8240 12025@smallexample
c906108c
SS
12026set $i = 0
12027print bar[$i++]->contents
474c8240 12028@end smallexample
c906108c 12029
d4f3574e
SS
12030@noindent
12031Repeat that command by typing @key{RET}.
c906108c
SS
12032
12033Some convenience variables are created automatically by @value{GDBN} and given
12034values likely to be useful.
12035
12036@table @code
41afff9a 12037@vindex $_@r{, convenience variable}
c906108c
SS
12038@item $_
12039The variable @code{$_} is automatically set by the @code{x} command to
79a6e687 12040the last address examined (@pxref{Memory, ,Examining Memory}). Other
c906108c
SS
12041commands which provide a default address for @code{x} to examine also
12042set @code{$_} to that address; these commands include @code{info line}
12043and @code{info breakpoint}. The type of @code{$_} is @code{void *}
12044except when set by the @code{x} command, in which case it is a pointer
12045to the type of @code{$__}.
12046
41afff9a 12047@vindex $__@r{, convenience variable}
c906108c
SS
12048@item $__
12049The variable @code{$__} is automatically set by the @code{x} command
12050to the value found in the last address examined. Its type is chosen
12051to match the format in which the data was printed.
12052
12053@item $_exitcode
41afff9a 12054@vindex $_exitcode@r{, convenience variable}
0c557179
SDJ
12055When the program being debugged terminates normally, @value{GDBN}
12056automatically sets this variable to the exit code of the program, and
12057resets @code{$_exitsignal} to @code{void}.
12058
12059@item $_exitsignal
12060@vindex $_exitsignal@r{, convenience variable}
12061When the program being debugged dies due to an uncaught signal,
12062@value{GDBN} automatically sets this variable to that signal's number,
12063and resets @code{$_exitcode} to @code{void}.
12064
12065To distinguish between whether the program being debugged has exited
12066(i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
12067@code{$_exitsignal} is not @code{void}), the convenience function
12068@code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
12069Functions}). For example, considering the following source code:
12070
12071@smallexample
12072#include <signal.h>
12073
12074int
12075main (int argc, char *argv[])
12076@{
12077 raise (SIGALRM);
12078 return 0;
12079@}
12080@end smallexample
12081
12082A valid way of telling whether the program being debugged has exited
12083or signalled would be:
12084
12085@smallexample
12086(@value{GDBP}) define has_exited_or_signalled
12087Type commands for definition of ``has_exited_or_signalled''.
12088End with a line saying just ``end''.
12089>if $_isvoid ($_exitsignal)
12090 >echo The program has exited\n
12091 >else
12092 >echo The program has signalled\n
12093 >end
12094>end
12095(@value{GDBP}) run
12096Starting program:
12097
12098Program terminated with signal SIGALRM, Alarm clock.
12099The program no longer exists.
12100(@value{GDBP}) has_exited_or_signalled
12101The program has signalled
12102@end smallexample
12103
12104As can be seen, @value{GDBN} correctly informs that the program being
12105debugged has signalled, since it calls @code{raise} and raises a
12106@code{SIGALRM} signal. If the program being debugged had not called
12107@code{raise}, then @value{GDBN} would report a normal exit:
12108
12109@smallexample
12110(@value{GDBP}) has_exited_or_signalled
12111The program has exited
12112@end smallexample
4aa995e1 12113
72f1fe8a
TT
12114@item $_exception
12115The variable @code{$_exception} is set to the exception object being
12116thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
12117
37f6a7f4
TT
12118@item $_ada_exception
12119The variable @code{$_ada_exception} is set to the address of the
12120exception being caught or thrown at an Ada exception-related
12121catchpoint. @xref{Set Catchpoints}.
12122
62e5f89c
SDJ
12123@item $_probe_argc
12124@itemx $_probe_arg0@dots{}$_probe_arg11
12125Arguments to a static probe. @xref{Static Probe Points}.
12126
0fb4aa4b
PA
12127@item $_sdata
12128@vindex $_sdata@r{, inspect, convenience variable}
12129The variable @code{$_sdata} contains extra collected static tracepoint
12130data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
12131@code{$_sdata} could be empty, if not inspecting a trace buffer, or
12132if extra static tracepoint data has not been collected.
12133
4aa995e1
PA
12134@item $_siginfo
12135@vindex $_siginfo@r{, convenience variable}
ec7e75e7
PP
12136The variable @code{$_siginfo} contains extra signal information
12137(@pxref{extra signal information}). Note that @code{$_siginfo}
12138could be empty, if the application has not yet received any signals.
12139For example, it will be empty before you execute the @code{run} command.
711e434b
PM
12140
12141@item $_tlb
12142@vindex $_tlb@r{, convenience variable}
12143The variable @code{$_tlb} is automatically set when debugging
12144applications running on MS-Windows in native mode or connected to
7734102d 12145gdbserver that supports the @code{qGetTIBAddr} request.
711e434b
PM
12146@xref{General Query Packets}.
12147This variable contains the address of the thread information block.
12148
e3940304 12149@item $_inferior
65c574f6
PA
12150The number of the current inferior. @xref{Inferiors Connections and
12151Programs, ,Debugging Multiple Inferiors Connections and Programs}.
e3940304 12152
5d5658a1
PA
12153@item $_thread
12154The thread number of the current thread. @xref{thread numbers}.
12155
663f6d42
PA
12156@item $_gthread
12157The global number of the current thread. @xref{global thread numbers}.
12158
7734102d
EZ
12159@item $_gdb_major
12160@itemx $_gdb_minor
12161@vindex $_gdb_major@r{, convenience variable}
12162@vindex $_gdb_minor@r{, convenience variable}
12163The major and minor version numbers of the running @value{GDBN}.
12164Development snapshots and pretest versions have their minor version
12165incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
12166the value 12 for @code{$_gdb_minor}. These variables allow you to
12167write scripts that work with different versions of @value{GDBN}
12168without errors caused by features unavailable in some of those
12169versions.
e2c52041
PW
12170
12171@item $_shell_exitcode
12172@itemx $_shell_exitsignal
12173@vindex $_shell_exitcode@r{, convenience variable}
12174@vindex $_shell_exitsignal@r{, convenience variable}
12175@cindex shell command, exit code
12176@cindex shell command, exit signal
12177@cindex exit status of shell commands
12178@value{GDBN} commands such as @code{shell} and @code{|} are launching
12179shell commands. When a launched command terminates, @value{GDBN}
12180automatically maintains the variables @code{$_shell_exitcode}
12181and @code{$_shell_exitsignal} according to the exit status of the last
12182launched command. These variables are set and used similarly to
12183the variables @code{$_exitcode} and @code{$_exitsignal}.
12184
c906108c
SS
12185@end table
12186
a72c3253
DE
12187@node Convenience Funs
12188@section Convenience Functions
12189
bc3b79fd
TJB
12190@cindex convenience functions
12191@value{GDBN} also supplies some @dfn{convenience functions}. These
12192have a syntax similar to convenience variables. A convenience
12193function can be used in an expression just like an ordinary function;
12194however, a convenience function is implemented internally to
12195@value{GDBN}.
12196
a280dbd1
SDJ
12197These functions do not require @value{GDBN} to be configured with
12198@code{Python} support, which means that they are always available.
12199
12200@table @code
12201
12202@item $_isvoid (@var{expr})
12203@findex $_isvoid@r{, convenience function}
12204Return one if the expression @var{expr} is @code{void}. Otherwise it
12205returns zero.
12206
12207A @code{void} expression is an expression where the type of the result
12208is @code{void}. For example, you can examine a convenience variable
12209(see @ref{Convenience Vars,, Convenience Variables}) to check whether
12210it is @code{void}:
12211
12212@smallexample
12213(@value{GDBP}) print $_exitcode
12214$1 = void
12215(@value{GDBP}) print $_isvoid ($_exitcode)
12216$2 = 1
12217(@value{GDBP}) run
12218Starting program: ./a.out
12219[Inferior 1 (process 29572) exited normally]
12220(@value{GDBP}) print $_exitcode
12221$3 = 0
12222(@value{GDBP}) print $_isvoid ($_exitcode)
12223$4 = 0
12224@end smallexample
12225
12226In the example above, we used @code{$_isvoid} to check whether
12227@code{$_exitcode} is @code{void} before and after the execution of the
12228program being debugged. Before the execution there is no exit code to
12229be examined, therefore @code{$_exitcode} is @code{void}. After the
12230execution the program being debugged returned zero, therefore
12231@code{$_exitcode} is zero, which means that it is not @code{void}
12232anymore.
12233
12234The @code{void} expression can also be a call of a function from the
12235program being debugged. For example, given the following function:
12236
12237@smallexample
12238void
12239foo (void)
12240@{
12241@}
12242@end smallexample
12243
12244The result of calling it inside @value{GDBN} is @code{void}:
12245
12246@smallexample
12247(@value{GDBP}) print foo ()
12248$1 = void
12249(@value{GDBP}) print $_isvoid (foo ())
12250$2 = 1
12251(@value{GDBP}) set $v = foo ()
12252(@value{GDBP}) print $v
12253$3 = void
12254(@value{GDBP}) print $_isvoid ($v)
12255$4 = 1
12256@end smallexample
12257
aed61d02
PW
12258@item $_gdb_setting_str (@var{setting})
12259@findex $_gdb_setting_str@r{, convenience function}
12260Return the value of the @value{GDBN} @var{setting} as a string.
12261@var{setting} is any setting that can be used in a @code{set} or
12262@code{show} command (@pxref{Controlling GDB}).
12263
12264@smallexample
12265(@value{GDBP}) show print frame-arguments
12266Printing of non-scalar frame arguments is "scalars".
12267(@value{GDBP}) p $_gdb_setting_str("print frame-arguments")
12268$1 = "scalars"
12269(@value{GDBP}) p $_gdb_setting_str("height")
12270$2 = "30"
12271(@value{GDBP})
12272@end smallexample
12273
12274@item $_gdb_setting (@var{setting})
12275@findex $_gdb_setting@r{, convenience function}
12276Return the value of the @value{GDBN} @var{setting}.
12277The type of the returned value depends on the setting.
12278
12279The value type for boolean and auto boolean settings is @code{int}.
12280The boolean values @code{off} and @code{on} are converted to
12281the integer values @code{0} and @code{1}. The value @code{auto} is
12282converted to the value @code{-1}.
12283
12284The value type for integer settings is either @code{unsigned int}
12285or @code{int}, depending on the setting.
12286
12287Some integer settings accept an @code{unlimited} value.
12288Depending on the setting, the @code{set} command also accepts
12289the value @code{0} or the value @code{@minus{}1} as a synonym for
12290@code{unlimited}.
12291For example, @code{set height unlimited} is equivalent to
12292@code{set height 0}.
12293
12294Some other settings that accept the @code{unlimited} value
12295use the value @code{0} to literally mean zero.
12296For example, @code{set history size 0} indicates to not
12297record any @value{GDBN} commands in the command history.
12298For such settings, @code{@minus{}1} is the synonym
12299for @code{unlimited}.
12300
12301See the documentation of the corresponding @code{set} command for
12302the numerical value equivalent to @code{unlimited}.
12303
12304The @code{$_gdb_setting} function converts the unlimited value
12305to a @code{0} or a @code{@minus{}1} value according to what the
12306@code{set} command uses.
12307
12308@smallexample
12309@group
12310(@value{GDBP}) p $_gdb_setting_str("height")
12311$1 = "30"
12312(@value{GDBP}) p $_gdb_setting("height")
12313$2 = 30
12314(@value{GDBP}) set height unlimited
12315(@value{GDBP}) p $_gdb_setting_str("height")
12316$3 = "unlimited"
12317(@value{GDBP}) p $_gdb_setting("height")
12318$4 = 0
12319@end group
12320@group
12321(@value{GDBP}) p $_gdb_setting_str("history size")
12322$5 = "unlimited"
12323(@value{GDBP}) p $_gdb_setting("history size")
12324$6 = -1
12325(@value{GDBP}) p $_gdb_setting_str("disassemble-next-line")
12326$7 = "auto"
12327(@value{GDBP}) p $_gdb_setting("disassemble-next-line")
12328$8 = -1
12329(@value{GDBP})
12330@end group
12331@end smallexample
12332
12333Other setting types (enum, filename, optional filename, string, string noescape)
12334are returned as string values.
12335
12336
12337@item $_gdb_maint_setting_str (@var{setting})
12338@findex $_gdb_maint_setting_str@r{, convenience function}
12339Like the @code{$_gdb_setting_str} function, but works with
12340@code{maintenance set} variables.
12341
12342@item $_gdb_maint_setting (@var{setting})
12343@findex $_gdb_maint_setting@r{, convenience function}
12344Like the @code{$_gdb_setting} function, but works with
12345@code{maintenance set} variables.
12346
a280dbd1
SDJ
12347@end table
12348
aed61d02 12349The following functions require @value{GDBN} to be configured with
a72c3253
DE
12350@code{Python} support.
12351
12352@table @code
12353
12354@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
12355@findex $_memeq@r{, convenience function}
12356Returns one if the @var{length} bytes at the addresses given by
12357@var{buf1} and @var{buf2} are equal.
12358Otherwise it returns zero.
12359
12360@item $_regex(@var{str}, @var{regex})
12361@findex $_regex@r{, convenience function}
12362Returns one if the string @var{str} matches the regular expression
12363@var{regex}. Otherwise it returns zero.
12364The syntax of the regular expression is that specified by @code{Python}'s
12365regular expression support.
12366
12367@item $_streq(@var{str1}, @var{str2})
12368@findex $_streq@r{, convenience function}
12369Returns one if the strings @var{str1} and @var{str2} are equal.
12370Otherwise it returns zero.
12371
12372@item $_strlen(@var{str})
12373@findex $_strlen@r{, convenience function}
12374Returns the length of string @var{str}.
12375
faa42425
DE
12376@item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12377@findex $_caller_is@r{, convenience function}
12378Returns one if the calling function's name is equal to @var{name}.
12379Otherwise it returns zero.
12380
12381If the optional argument @var{number_of_frames} is provided,
12382it is the number of frames up in the stack to look.
12383The default is 1.
12384
12385Example:
12386
12387@smallexample
12388(gdb) backtrace
12389#0 bottom_func ()
12390 at testsuite/gdb.python/py-caller-is.c:21
12391#1 0x00000000004005a0 in middle_func ()
12392 at testsuite/gdb.python/py-caller-is.c:27
12393#2 0x00000000004005ab in top_func ()
12394 at testsuite/gdb.python/py-caller-is.c:33
12395#3 0x00000000004005b6 in main ()
12396 at testsuite/gdb.python/py-caller-is.c:39
12397(gdb) print $_caller_is ("middle_func")
12398$1 = 1
12399(gdb) print $_caller_is ("top_func", 2)
12400$1 = 1
12401@end smallexample
12402
12403@item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12404@findex $_caller_matches@r{, convenience function}
12405Returns one if the calling function's name matches the regular expression
12406@var{regexp}. Otherwise it returns zero.
12407
12408If the optional argument @var{number_of_frames} is provided,
12409it is the number of frames up in the stack to look.
12410The default is 1.
12411
12412@item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12413@findex $_any_caller_is@r{, convenience function}
12414Returns one if any calling function's name is equal to @var{name}.
12415Otherwise it returns zero.
12416
12417If the optional argument @var{number_of_frames} is provided,
12418it is the number of frames up in the stack to look.
12419The default is 1.
12420
12421This function differs from @code{$_caller_is} in that this function
12422checks all stack frames from the immediate caller to the frame specified
12423by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
12424frame specified by @var{number_of_frames}.
12425
12426@item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12427@findex $_any_caller_matches@r{, convenience function}
12428Returns one if any calling function's name matches the regular expression
12429@var{regexp}. Otherwise it returns zero.
12430
12431If the optional argument @var{number_of_frames} is provided,
12432it is the number of frames up in the stack to look.
12433The default is 1.
12434
12435This function differs from @code{$_caller_matches} in that this function
12436checks all stack frames from the immediate caller to the frame specified
12437by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
12438frame specified by @var{number_of_frames}.
12439
f2f3ccb9
SM
12440@item $_as_string(@var{value})
12441@findex $_as_string@r{, convenience function}
12442Return the string representation of @var{value}.
12443
12444This function is useful to obtain the textual label (enumerator) of an
12445enumeration value. For example, assuming the variable @var{node} is of
12446an enumerated type:
12447
12448@smallexample
12449(gdb) printf "Visiting node of type %s\n", $_as_string(node)
12450Visiting node of type NODE_INTEGER
12451@end smallexample
12452
8bdc1658
AB
12453@item $_cimag(@var{value})
12454@itemx $_creal(@var{value})
12455@findex $_cimag@r{, convenience function}
12456@findex $_creal@r{, convenience function}
12457Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
12458the complex number @var{value}.
12459
12460The type of the imaginary or real part depends on the type of the
12461complex number, e.g., using @code{$_cimag} on a @code{float complex}
12462will return an imaginary part of type @code{float}.
12463
a72c3253
DE
12464@end table
12465
12466@value{GDBN} provides the ability to list and get help on
12467convenience functions.
12468
bc3b79fd
TJB
12469@table @code
12470@item help function
12471@kindex help function
12472@cindex show all convenience functions
12473Print a list of all convenience functions.
12474@end table
12475
6d2ebf8b 12476@node Registers
c906108c
SS
12477@section Registers
12478
12479@cindex registers
12480You can refer to machine register contents, in expressions, as variables
12481with names starting with @samp{$}. The names of registers are different
12482for each machine; use @code{info registers} to see the names used on
12483your machine.
12484
12485@table @code
12486@kindex info registers
12487@item info registers
12488Print the names and values of all registers except floating-point
c85508ee 12489and vector registers (in the selected stack frame).
c906108c
SS
12490
12491@kindex info all-registers
12492@cindex floating point registers
12493@item info all-registers
12494Print the names and values of all registers, including floating-point
c85508ee 12495and vector registers (in the selected stack frame).
c906108c 12496
64cb3757 12497@anchor{info_registers_reggroup}
b67d92b0
SH
12498@item info registers @var{reggroup} @dots{}
12499Print the name and value of the registers in each of the specified
6b92c0d3 12500@var{reggroup}s. The @var{reggroup} can be any of those returned by
b67d92b0
SH
12501@code{maint print reggroups} (@pxref{Maintenance Commands}).
12502
c906108c
SS
12503@item info registers @var{regname} @dots{}
12504Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24 12505As discussed in detail below, register values are normally relative to
697aa1b7 12506the selected stack frame. The @var{regname} may be any register name valid on
c906108c
SS
12507the machine you are using, with or without the initial @samp{$}.
12508@end table
12509
f5b95c01 12510@anchor{standard registers}
e09f16f9
EZ
12511@cindex stack pointer register
12512@cindex program counter register
12513@cindex process status register
12514@cindex frame pointer register
12515@cindex standard registers
c906108c
SS
12516@value{GDBN} has four ``standard'' register names that are available (in
12517expressions) on most machines---whenever they do not conflict with an
12518architecture's canonical mnemonics for registers. The register names
12519@code{$pc} and @code{$sp} are used for the program counter register and
12520the stack pointer. @code{$fp} is used for a register that contains a
12521pointer to the current stack frame, and @code{$ps} is used for a
12522register that contains the processor status. For example,
12523you could print the program counter in hex with
12524
474c8240 12525@smallexample
c906108c 12526p/x $pc
474c8240 12527@end smallexample
c906108c
SS
12528
12529@noindent
12530or print the instruction to be executed next with
12531
474c8240 12532@smallexample
c906108c 12533x/i $pc
474c8240 12534@end smallexample
c906108c
SS
12535
12536@noindent
12537or add four to the stack pointer@footnote{This is a way of removing
12538one word from the stack, on machines where stacks grow downward in
12539memory (most machines, nowadays). This assumes that the innermost
12540stack frame is selected; setting @code{$sp} is not allowed when other
12541stack frames are selected. To pop entire frames off the stack,
12542regardless of machine architecture, use @code{return};
79a6e687 12543see @ref{Returning, ,Returning from a Function}.} with
c906108c 12544
474c8240 12545@smallexample
c906108c 12546set $sp += 4
474c8240 12547@end smallexample
c906108c
SS
12548
12549Whenever possible, these four standard register names are available on
12550your machine even though the machine has different canonical mnemonics,
12551so long as there is no conflict. The @code{info registers} command
12552shows the canonical names. For example, on the SPARC, @code{info
12553registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
12554can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
12555is an alias for the @sc{eflags} register.
c906108c
SS
12556
12557@value{GDBN} always considers the contents of an ordinary register as an
12558integer when the register is examined in this way. Some machines have
12559special registers which can hold nothing but floating point; these
12560registers are considered to have floating point values. There is no way
12561to refer to the contents of an ordinary register as floating point value
12562(although you can @emph{print} it as a floating point value with
12563@samp{print/f $@var{regname}}).
12564
12565Some registers have distinct ``raw'' and ``virtual'' data formats. This
12566means that the data format in which the register contents are saved by
12567the operating system is not the same one that your program normally
12568sees. For example, the registers of the 68881 floating point
12569coprocessor are always saved in ``extended'' (raw) format, but all C
12570programs expect to work with ``double'' (virtual) format. In such
5d161b24 12571cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
12572that makes sense for your program), but the @code{info registers} command
12573prints the data in both formats.
12574
36b80e65
EZ
12575@cindex SSE registers (x86)
12576@cindex MMX registers (x86)
12577Some machines have special registers whose contents can be interpreted
12578in several different ways. For example, modern x86-based machines
12579have SSE and MMX registers that can hold several values packed
12580together in several different formats. @value{GDBN} refers to such
12581registers in @code{struct} notation:
12582
12583@smallexample
12584(@value{GDBP}) print $xmm1
12585$1 = @{
12586 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
12587 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
12588 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
12589 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
12590 v4_int32 = @{0, 20657912, 11, 13@},
12591 v2_int64 = @{88725056443645952, 55834574859@},
12592 uint128 = 0x0000000d0000000b013b36f800000000
12593@}
12594@end smallexample
12595
12596@noindent
12597To set values of such registers, you need to tell @value{GDBN} which
12598view of the register you wish to change, as if you were assigning
12599value to a @code{struct} member:
12600
12601@smallexample
12602 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
12603@end smallexample
12604
c906108c 12605Normally, register values are relative to the selected stack frame
79a6e687 12606(@pxref{Selection, ,Selecting a Frame}). This means that you get the
c906108c
SS
12607value that the register would contain if all stack frames farther in
12608were exited and their saved registers restored. In order to see the
12609true contents of hardware registers, you must select the innermost
12610frame (with @samp{frame 0}).
12611
901461f8
PA
12612@cindex caller-saved registers
12613@cindex call-clobbered registers
12614@cindex volatile registers
12615@cindex <not saved> values
12616Usually ABIs reserve some registers as not needed to be saved by the
12617callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
12618registers). It may therefore not be possible for @value{GDBN} to know
12619the value a register had before the call (in other words, in the outer
12620frame), if the register value has since been changed by the callee.
12621@value{GDBN} tries to deduce where the inner frame saved
12622(``callee-saved'') registers, from the debug info, unwind info, or the
12623machine code generated by your compiler. If some register is not
12624saved, and @value{GDBN} knows the register is ``caller-saved'' (via
12625its own knowledge of the ABI, or because the debug/unwind info
12626explicitly says the register's value is undefined), @value{GDBN}
12627displays @w{@samp{<not saved>}} as the register's value. With targets
12628that @value{GDBN} has no knowledge of the register saving convention,
12629if a register was not saved by the callee, then its value and location
12630in the outer frame are assumed to be the same of the inner frame.
12631This is usually harmless, because if the register is call-clobbered,
12632the caller either does not care what is in the register after the
12633call, or has code to restore the value that it does care about. Note,
12634however, that if you change such a register in the outer frame, you
12635may also be affecting the inner frame. Also, the more ``outer'' the
12636frame is you're looking at, the more likely a call-clobbered
12637register's value is to be wrong, in the sense that it doesn't actually
12638represent the value the register had just before the call.
c906108c 12639
6d2ebf8b 12640@node Floating Point Hardware
79a6e687 12641@section Floating Point Hardware
c906108c
SS
12642@cindex floating point
12643
12644Depending on the configuration, @value{GDBN} may be able to give
12645you more information about the status of the floating point hardware.
12646
12647@table @code
12648@kindex info float
12649@item info float
12650Display hardware-dependent information about the floating
12651point unit. The exact contents and layout vary depending on the
12652floating point chip. Currently, @samp{info float} is supported on
12653the ARM and x86 machines.
12654@end table
c906108c 12655
e76f1f2e
AC
12656@node Vector Unit
12657@section Vector Unit
12658@cindex vector unit
12659
12660Depending on the configuration, @value{GDBN} may be able to give you
12661more information about the status of the vector unit.
12662
12663@table @code
12664@kindex info vector
12665@item info vector
12666Display information about the vector unit. The exact contents and
12667layout vary depending on the hardware.
12668@end table
12669
721c2651 12670@node OS Information
79a6e687 12671@section Operating System Auxiliary Information
721c2651
EZ
12672@cindex OS information
12673
12674@value{GDBN} provides interfaces to useful OS facilities that can help
12675you debug your program.
12676
b383017d
RM
12677@cindex auxiliary vector
12678@cindex vector, auxiliary
b383017d
RM
12679Some operating systems supply an @dfn{auxiliary vector} to programs at
12680startup. This is akin to the arguments and environment that you
12681specify for a program, but contains a system-dependent variety of
12682binary values that tell system libraries important details about the
12683hardware, operating system, and process. Each value's purpose is
12684identified by an integer tag; the meanings are well-known but system-specific.
12685Depending on the configuration and operating system facilities,
9c16f35a
EZ
12686@value{GDBN} may be able to show you this information. For remote
12687targets, this functionality may further depend on the remote stub's
427c3a89
DJ
12688support of the @samp{qXfer:auxv:read} packet, see
12689@ref{qXfer auxiliary vector read}.
b383017d
RM
12690
12691@table @code
12692@kindex info auxv
12693@item info auxv
12694Display the auxiliary vector of the inferior, which can be either a
e4937fc1 12695live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
12696numerically, and also shows names and text descriptions for recognized
12697tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 12698pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
12699most appropriate form for a recognized tag, and in hexadecimal for
12700an unrecognized tag.
12701@end table
12702
85d4a676
SS
12703On some targets, @value{GDBN} can access operating system-specific
12704information and show it to you. The types of information available
12705will differ depending on the type of operating system running on the
12706target. The mechanism used to fetch the data is described in
12707@ref{Operating System Information}. For remote targets, this
12708functionality depends on the remote stub's support of the
07e059b5
VP
12709@samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
12710
12711@table @code
a61408f8 12712@kindex info os
85d4a676
SS
12713@item info os @var{infotype}
12714
12715Display OS information of the requested type.
a61408f8 12716
85d4a676
SS
12717On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
12718
12719@anchor{linux info os infotypes}
12720@table @code
d33279b3
AT
12721@kindex info os cpus
12722@item cpus
12723Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
12724the available fields from /proc/cpuinfo. For each supported architecture
12725different fields are available. Two common entries are processor which gives
12726CPU number and bogomips; a system constant that is calculated during
12727kernel initialization.
12728
12729@kindex info os files
12730@item files
12731Display the list of open file descriptors on the target. For each
12732file descriptor, @value{GDBN} prints the identifier of the process
12733owning the descriptor, the command of the owning process, the value
12734of the descriptor, and the target of the descriptor.
12735
12736@kindex info os modules
12737@item modules
12738Display the list of all loaded kernel modules on the target. For each
12739module, @value{GDBN} prints the module name, the size of the module in
12740bytes, the number of times the module is used, the dependencies of the
12741module, the status of the module, and the address of the loaded module
12742in memory.
12743
12744@kindex info os msg
12745@item msg
12746Display the list of all System V message queues on the target. For each
12747message queue, @value{GDBN} prints the message queue key, the message
12748queue identifier, the access permissions, the current number of bytes
12749on the queue, the current number of messages on the queue, the processes
12750that last sent and received a message on the queue, the user and group
12751of the owner and creator of the message queue, the times at which a
12752message was last sent and received on the queue, and the time at which
12753the message queue was last changed.
12754
07e059b5 12755@kindex info os processes
85d4a676 12756@item processes
07e059b5 12757Display the list of processes on the target. For each process,
85d4a676
SS
12758@value{GDBN} prints the process identifier, the name of the user, the
12759command corresponding to the process, and the list of processor cores
12760that the process is currently running on. (To understand what these
12761properties mean, for this and the following info types, please consult
12762the general @sc{gnu}/Linux documentation.)
12763
12764@kindex info os procgroups
12765@item procgroups
12766Display the list of process groups on the target. For each process,
12767@value{GDBN} prints the identifier of the process group that it belongs
12768to, the command corresponding to the process group leader, the process
12769identifier, and the command line of the process. The list is sorted
12770first by the process group identifier, then by the process identifier,
12771so that processes belonging to the same process group are grouped together
12772and the process group leader is listed first.
12773
d33279b3
AT
12774@kindex info os semaphores
12775@item semaphores
12776Display the list of all System V semaphore sets on the target. For each
12777semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
12778set identifier, the access permissions, the number of semaphores in the
12779set, the user and group of the owner and creator of the semaphore set,
12780and the times at which the semaphore set was operated upon and changed.
85d4a676
SS
12781
12782@kindex info os shm
12783@item shm
12784Display the list of all System V shared-memory regions on the target.
12785For each shared-memory region, @value{GDBN} prints the region key,
12786the shared-memory identifier, the access permissions, the size of the
12787region, the process that created the region, the process that last
12788attached to or detached from the region, the current number of live
12789attaches to the region, and the times at which the region was last
12790attached to, detach from, and changed.
12791
d33279b3
AT
12792@kindex info os sockets
12793@item sockets
12794Display the list of Internet-domain sockets on the target. For each
12795socket, @value{GDBN} prints the address and port of the local and
12796remote endpoints, the current state of the connection, the creator of
12797the socket, the IP address family of the socket, and the type of the
12798connection.
85d4a676 12799
d33279b3
AT
12800@kindex info os threads
12801@item threads
12802Display the list of threads running on the target. For each thread,
12803@value{GDBN} prints the identifier of the process that the thread
12804belongs to, the command of the process, the thread identifier, and the
12805processor core that it is currently running on. The main thread of a
12806process is not listed.
85d4a676
SS
12807@end table
12808
12809@item info os
12810If @var{infotype} is omitted, then list the possible values for
12811@var{infotype} and the kind of OS information available for each
12812@var{infotype}. If the target does not return a list of possible
12813types, this command will report an error.
07e059b5 12814@end table
721c2651 12815
29e57380 12816@node Memory Region Attributes
79a6e687 12817@section Memory Region Attributes
29e57380
C
12818@cindex memory region attributes
12819
b383017d 12820@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
12821required by regions of your target's memory. @value{GDBN} uses
12822attributes to determine whether to allow certain types of memory
12823accesses; whether to use specific width accesses; and whether to cache
12824target memory. By default the description of memory regions is
12825fetched from the target (if the current target supports this), but the
12826user can override the fetched regions.
29e57380
C
12827
12828Defined memory regions can be individually enabled and disabled. When a
12829memory region is disabled, @value{GDBN} uses the default attributes when
12830accessing memory in that region. Similarly, if no memory regions have
12831been defined, @value{GDBN} uses the default attributes when accessing
12832all memory.
12833
b383017d 12834When a memory region is defined, it is given a number to identify it;
29e57380
C
12835to enable, disable, or remove a memory region, you specify that number.
12836
12837@table @code
12838@kindex mem
bfac230e 12839@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
12840Define a memory region bounded by @var{lower} and @var{upper} with
12841attributes @var{attributes}@dots{}, and add it to the list of regions
12842monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
d3e8051b 12843case: it is treated as the target's maximum memory address.
bfac230e 12844(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 12845
fd79ecee
DJ
12846@item mem auto
12847Discard any user changes to the memory regions and use target-supplied
12848regions, if available, or no regions if the target does not support.
12849
29e57380
C
12850@kindex delete mem
12851@item delete mem @var{nums}@dots{}
09d4efe1
EZ
12852Remove memory regions @var{nums}@dots{} from the list of regions
12853monitored by @value{GDBN}.
29e57380
C
12854
12855@kindex disable mem
12856@item disable mem @var{nums}@dots{}
09d4efe1 12857Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 12858A disabled memory region is not forgotten.
29e57380
C
12859It may be enabled again later.
12860
12861@kindex enable mem
12862@item enable mem @var{nums}@dots{}
09d4efe1 12863Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
12864
12865@kindex info mem
12866@item info mem
12867Print a table of all defined memory regions, with the following columns
09d4efe1 12868for each region:
29e57380
C
12869
12870@table @emph
12871@item Memory Region Number
12872@item Enabled or Disabled.
b383017d 12873Enabled memory regions are marked with @samp{y}.
29e57380
C
12874Disabled memory regions are marked with @samp{n}.
12875
12876@item Lo Address
12877The address defining the inclusive lower bound of the memory region.
12878
12879@item Hi Address
12880The address defining the exclusive upper bound of the memory region.
12881
12882@item Attributes
12883The list of attributes set for this memory region.
12884@end table
12885@end table
12886
12887
12888@subsection Attributes
12889
b383017d 12890@subsubsection Memory Access Mode
29e57380
C
12891The access mode attributes set whether @value{GDBN} may make read or
12892write accesses to a memory region.
12893
12894While these attributes prevent @value{GDBN} from performing invalid
12895memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 12896etc.@: from accessing memory.
29e57380
C
12897
12898@table @code
12899@item ro
12900Memory is read only.
12901@item wo
12902Memory is write only.
12903@item rw
6ca652b0 12904Memory is read/write. This is the default.
29e57380
C
12905@end table
12906
12907@subsubsection Memory Access Size
d3e8051b 12908The access size attribute tells @value{GDBN} to use specific sized
29e57380
C
12909accesses in the memory region. Often memory mapped device registers
12910require specific sized accesses. If no access size attribute is
12911specified, @value{GDBN} may use accesses of any size.
12912
12913@table @code
12914@item 8
12915Use 8 bit memory accesses.
12916@item 16
12917Use 16 bit memory accesses.
12918@item 32
12919Use 32 bit memory accesses.
12920@item 64
12921Use 64 bit memory accesses.
12922@end table
12923
12924@c @subsubsection Hardware/Software Breakpoints
12925@c The hardware/software breakpoint attributes set whether @value{GDBN}
12926@c will use hardware or software breakpoints for the internal breakpoints
12927@c used by the step, next, finish, until, etc. commands.
12928@c
12929@c @table @code
12930@c @item hwbreak
b383017d 12931@c Always use hardware breakpoints
29e57380
C
12932@c @item swbreak (default)
12933@c @end table
12934
12935@subsubsection Data Cache
12936The data cache attributes set whether @value{GDBN} will cache target
12937memory. While this generally improves performance by reducing debug
12938protocol overhead, it can lead to incorrect results because @value{GDBN}
12939does not know about volatile variables or memory mapped device
12940registers.
12941
12942@table @code
12943@item cache
b383017d 12944Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
12945@item nocache
12946Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
12947@end table
12948
4b5752d0
VP
12949@subsection Memory Access Checking
12950@value{GDBN} can be instructed to refuse accesses to memory that is
12951not explicitly described. This can be useful if accessing such
12952regions has undesired effects for a specific target, or to provide
12953better error checking. The following commands control this behaviour.
12954
12955@table @code
12956@kindex set mem inaccessible-by-default
12957@item set mem inaccessible-by-default [on|off]
12958If @code{on} is specified, make @value{GDBN} treat memory not
12959explicitly described by the memory ranges as non-existent and refuse accesses
12960to such memory. The checks are only performed if there's at least one
12961memory range defined. If @code{off} is specified, make @value{GDBN}
12962treat the memory not explicitly described by the memory ranges as RAM.
56cf5405 12963The default value is @code{on}.
4b5752d0
VP
12964@kindex show mem inaccessible-by-default
12965@item show mem inaccessible-by-default
12966Show the current handling of accesses to unknown memory.
12967@end table
12968
12969
29e57380 12970@c @subsubsection Memory Write Verification
b383017d 12971@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
12972@c will re-reads data after each write to verify the write was successful.
12973@c
12974@c @table @code
12975@c @item verify
12976@c @item noverify (default)
12977@c @end table
12978
16d9dec6 12979@node Dump/Restore Files
79a6e687 12980@section Copy Between Memory and a File
16d9dec6
MS
12981@cindex dump/restore files
12982@cindex append data to a file
12983@cindex dump data to a file
12984@cindex restore data from a file
16d9dec6 12985
df5215a6
JB
12986You can use the commands @code{dump}, @code{append}, and
12987@code{restore} to copy data between target memory and a file. The
12988@code{dump} and @code{append} commands write data to a file, and the
12989@code{restore} command reads data from a file back into the inferior's
cf75d6c3
AB
12990memory. Files may be in binary, Motorola S-record, Intel hex,
12991Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
12992append to binary files, and cannot read from Verilog Hex files.
df5215a6
JB
12993
12994@table @code
12995
12996@kindex dump
12997@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12998@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
12999Dump the contents of memory from @var{start_addr} to @var{end_addr},
13000or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 13001
df5215a6 13002The @var{format} parameter may be any one of:
16d9dec6 13003@table @code
df5215a6
JB
13004@item binary
13005Raw binary form.
13006@item ihex
13007Intel hex format.
13008@item srec
13009Motorola S-record format.
13010@item tekhex
13011Tektronix Hex format.
cf75d6c3
AB
13012@item verilog
13013Verilog Hex format.
df5215a6
JB
13014@end table
13015
13016@value{GDBN} uses the same definitions of these formats as the
13017@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
13018@var{format} is omitted, @value{GDBN} dumps the data in raw binary
13019form.
13020
13021@kindex append
13022@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
13023@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
13024Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 13025or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
13026(@value{GDBN} can only append data to files in raw binary form.)
13027
13028@kindex restore
13029@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
13030Restore the contents of file @var{filename} into memory. The
13031@code{restore} command can automatically recognize any known @sc{bfd}
13032file format, except for raw binary. To restore a raw binary file you
13033must specify the optional keyword @code{binary} after the filename.
16d9dec6 13034
b383017d 13035If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
13036contained in the file. Binary files always start at address zero, so
13037they will be restored at address @var{bias}. Other bfd files have
13038a built-in location; they will be restored at offset @var{bias}
13039from that location.
13040
13041If @var{start} and/or @var{end} are non-zero, then only data between
13042file offset @var{start} and file offset @var{end} will be restored.
b383017d 13043These offsets are relative to the addresses in the file, before
16d9dec6
MS
13044the @var{bias} argument is applied.
13045
13046@end table
13047
384ee23f
EZ
13048@node Core File Generation
13049@section How to Produce a Core File from Your Program
13050@cindex dump core from inferior
13051
13052A @dfn{core file} or @dfn{core dump} is a file that records the memory
13053image of a running process and its process status (register values
13054etc.). Its primary use is post-mortem debugging of a program that
13055crashed while it ran outside a debugger. A program that crashes
13056automatically produces a core file, unless this feature is disabled by
13057the user. @xref{Files}, for information on invoking @value{GDBN} in
13058the post-mortem debugging mode.
13059
13060Occasionally, you may wish to produce a core file of the program you
13061are debugging in order to preserve a snapshot of its state.
13062@value{GDBN} has a special command for that.
13063
13064@table @code
13065@kindex gcore
13066@kindex generate-core-file
13067@item generate-core-file [@var{file}]
13068@itemx gcore [@var{file}]
13069Produce a core dump of the inferior process. The optional argument
13070@var{file} specifies the file name where to put the core dump. If not
13071specified, the file name defaults to @file{core.@var{pid}}, where
13072@var{pid} is the inferior process ID.
13073
13074Note that this command is implemented only for some systems (as of
05b4bd79 13075this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
df8411da
SDJ
13076
13077On @sc{gnu}/Linux, this command can take into account the value of the
13078file @file{/proc/@var{pid}/coredump_filter} when generating the core
1e52e849
SL
13079dump (@pxref{set use-coredump-filter}), and by default honors the
13080@code{VM_DONTDUMP} flag for mappings where it is present in the file
13081@file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
df8411da
SDJ
13082
13083@kindex set use-coredump-filter
13084@anchor{set use-coredump-filter}
13085@item set use-coredump-filter on
13086@itemx set use-coredump-filter off
13087Enable or disable the use of the file
13088@file{/proc/@var{pid}/coredump_filter} when generating core dump
13089files. This file is used by the Linux kernel to decide what types of
13090memory mappings will be dumped or ignored when generating a core dump
13091file. @var{pid} is the process ID of a currently running process.
13092
13093To make use of this feature, you have to write in the
13094@file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
13095which is a bit mask representing the memory mapping types. If a bit
13096is set in the bit mask, then the memory mappings of the corresponding
13097types will be dumped; otherwise, they will be ignored. This
13098configuration is inherited by child processes. For more information
13099about the bits that can be set in the
13100@file{/proc/@var{pid}/coredump_filter} file, please refer to the
13101manpage of @code{core(5)}.
13102
13103By default, this option is @code{on}. If this option is turned
13104@code{off}, @value{GDBN} does not read the @file{coredump_filter} file
13105and instead uses the same default value as the Linux kernel in order
13106to decide which pages will be dumped in the core dump file. This
13107value is currently @code{0x33}, which means that bits @code{0}
13108(anonymous private mappings), @code{1} (anonymous shared mappings),
13109@code{4} (ELF headers) and @code{5} (private huge pages) are active.
13110This will cause these memory mappings to be dumped automatically.
1e52e849
SL
13111
13112@kindex set dump-excluded-mappings
13113@anchor{set dump-excluded-mappings}
13114@item set dump-excluded-mappings on
13115@itemx set dump-excluded-mappings off
13116If @code{on} is specified, @value{GDBN} will dump memory mappings
13117marked with the @code{VM_DONTDUMP} flag. This flag is represented in
13118the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
13119
13120The default value is @code{off}.
384ee23f
EZ
13121@end table
13122
a0eb71c5
KB
13123@node Character Sets
13124@section Character Sets
13125@cindex character sets
13126@cindex charset
13127@cindex translating between character sets
13128@cindex host character set
13129@cindex target character set
13130
13131If the program you are debugging uses a different character set to
13132represent characters and strings than the one @value{GDBN} uses itself,
13133@value{GDBN} can automatically translate between the character sets for
13134you. The character set @value{GDBN} uses we call the @dfn{host
13135character set}; the one the inferior program uses we call the
13136@dfn{target character set}.
13137
13138For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
13139uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
ea35711c 13140remote protocol (@pxref{Remote Debugging}) to debug a program
a0eb71c5
KB
13141running on an IBM mainframe, which uses the @sc{ebcdic} character set,
13142then the host character set is Latin-1, and the target character set is
13143@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 13144target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
13145@sc{ebcdic} and Latin 1 as you print character or string values, or use
13146character and string literals in expressions.
13147
13148@value{GDBN} has no way to automatically recognize which character set
13149the inferior program uses; you must tell it, using the @code{set
13150target-charset} command, described below.
13151
13152Here are the commands for controlling @value{GDBN}'s character set
13153support:
13154
13155@table @code
13156@item set target-charset @var{charset}
13157@kindex set target-charset
10af6951
EZ
13158Set the current target character set to @var{charset}. To display the
13159list of supported target character sets, type
13160@kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
a0eb71c5 13161
a0eb71c5
KB
13162@item set host-charset @var{charset}
13163@kindex set host-charset
13164Set the current host character set to @var{charset}.
13165
13166By default, @value{GDBN} uses a host character set appropriate to the
13167system it is running on; you can override that default using the
732f6a93
TT
13168@code{set host-charset} command. On some systems, @value{GDBN} cannot
13169automatically determine the appropriate host character set. In this
13170case, @value{GDBN} uses @samp{UTF-8}.
a0eb71c5
KB
13171
13172@value{GDBN} can only use certain character sets as its host character
c1b6b909 13173set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
10af6951 13174@value{GDBN} will list the host character sets it supports.
a0eb71c5
KB
13175
13176@item set charset @var{charset}
13177@kindex set charset
e33d66ec 13178Set the current host and target character sets to @var{charset}. As
10af6951
EZ
13179above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
13180@value{GDBN} will list the names of the character sets that can be used
e33d66ec
EZ
13181for both host and target.
13182
a0eb71c5 13183@item show charset
a0eb71c5 13184@kindex show charset
10af6951 13185Show the names of the current host and target character sets.
e33d66ec 13186
10af6951 13187@item show host-charset
a0eb71c5 13188@kindex show host-charset
10af6951 13189Show the name of the current host character set.
e33d66ec 13190
10af6951 13191@item show target-charset
a0eb71c5 13192@kindex show target-charset
10af6951 13193Show the name of the current target character set.
a0eb71c5 13194
10af6951
EZ
13195@item set target-wide-charset @var{charset}
13196@kindex set target-wide-charset
13197Set the current target's wide character set to @var{charset}. This is
13198the character set used by the target's @code{wchar_t} type. To
13199display the list of supported wide character sets, type
13200@kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
13201
13202@item show target-wide-charset
13203@kindex show target-wide-charset
13204Show the name of the current target's wide character set.
a0eb71c5
KB
13205@end table
13206
a0eb71c5
KB
13207Here is an example of @value{GDBN}'s character set support in action.
13208Assume that the following source code has been placed in the file
13209@file{charset-test.c}:
13210
13211@smallexample
13212#include <stdio.h>
13213
13214char ascii_hello[]
13215 = @{72, 101, 108, 108, 111, 44, 32, 119,
13216 111, 114, 108, 100, 33, 10, 0@};
13217char ibm1047_hello[]
13218 = @{200, 133, 147, 147, 150, 107, 64, 166,
13219 150, 153, 147, 132, 90, 37, 0@};
13220
13221main ()
13222@{
13223 printf ("Hello, world!\n");
13224@}
10998722 13225@end smallexample
a0eb71c5
KB
13226
13227In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
13228containing the string @samp{Hello, world!} followed by a newline,
13229encoded in the @sc{ascii} and @sc{ibm1047} character sets.
13230
13231We compile the program, and invoke the debugger on it:
13232
13233@smallexample
13234$ gcc -g charset-test.c -o charset-test
13235$ gdb -nw charset-test
13236GNU gdb 2001-12-19-cvs
13237Copyright 2001 Free Software Foundation, Inc.
13238@dots{}
f7dc1244 13239(@value{GDBP})
10998722 13240@end smallexample
a0eb71c5
KB
13241
13242We can use the @code{show charset} command to see what character sets
13243@value{GDBN} is currently using to interpret and display characters and
13244strings:
13245
13246@smallexample
f7dc1244 13247(@value{GDBP}) show charset
e33d66ec 13248The current host and target character set is `ISO-8859-1'.
f7dc1244 13249(@value{GDBP})
10998722 13250@end smallexample
a0eb71c5
KB
13251
13252For the sake of printing this manual, let's use @sc{ascii} as our
13253initial character set:
13254@smallexample
f7dc1244
EZ
13255(@value{GDBP}) set charset ASCII
13256(@value{GDBP}) show charset
e33d66ec 13257The current host and target character set is `ASCII'.
f7dc1244 13258(@value{GDBP})
10998722 13259@end smallexample
a0eb71c5
KB
13260
13261Let's assume that @sc{ascii} is indeed the correct character set for our
13262host system --- in other words, let's assume that if @value{GDBN} prints
13263characters using the @sc{ascii} character set, our terminal will display
13264them properly. Since our current target character set is also
13265@sc{ascii}, the contents of @code{ascii_hello} print legibly:
13266
13267@smallexample
f7dc1244 13268(@value{GDBP}) print ascii_hello
a0eb71c5 13269$1 = 0x401698 "Hello, world!\n"
f7dc1244 13270(@value{GDBP}) print ascii_hello[0]
a0eb71c5 13271$2 = 72 'H'
f7dc1244 13272(@value{GDBP})
10998722 13273@end smallexample
a0eb71c5
KB
13274
13275@value{GDBN} uses the target character set for character and string
13276literals you use in expressions:
13277
13278@smallexample
f7dc1244 13279(@value{GDBP}) print '+'
a0eb71c5 13280$3 = 43 '+'
f7dc1244 13281(@value{GDBP})
10998722 13282@end smallexample
a0eb71c5
KB
13283
13284The @sc{ascii} character set uses the number 43 to encode the @samp{+}
13285character.
13286
13287@value{GDBN} relies on the user to tell it which character set the
13288target program uses. If we print @code{ibm1047_hello} while our target
13289character set is still @sc{ascii}, we get jibberish:
13290
13291@smallexample
f7dc1244 13292(@value{GDBP}) print ibm1047_hello
a0eb71c5 13293$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 13294(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 13295$5 = 200 '\310'
f7dc1244 13296(@value{GDBP})
10998722 13297@end smallexample
a0eb71c5 13298
e33d66ec 13299If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
13300@value{GDBN} tells us the character sets it supports:
13301
13302@smallexample
f7dc1244 13303(@value{GDBP}) set target-charset
b383017d 13304ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 13305(@value{GDBP}) set target-charset
10998722 13306@end smallexample
a0eb71c5
KB
13307
13308We can select @sc{ibm1047} as our target character set, and examine the
13309program's strings again. Now the @sc{ascii} string is wrong, but
13310@value{GDBN} translates the contents of @code{ibm1047_hello} from the
13311target character set, @sc{ibm1047}, to the host character set,
13312@sc{ascii}, and they display correctly:
13313
13314@smallexample
f7dc1244
EZ
13315(@value{GDBP}) set target-charset IBM1047
13316(@value{GDBP}) show charset
e33d66ec
EZ
13317The current host character set is `ASCII'.
13318The current target character set is `IBM1047'.
f7dc1244 13319(@value{GDBP}) print ascii_hello
a0eb71c5 13320$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 13321(@value{GDBP}) print ascii_hello[0]
a0eb71c5 13322$7 = 72 '\110'
f7dc1244 13323(@value{GDBP}) print ibm1047_hello
a0eb71c5 13324$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 13325(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 13326$9 = 200 'H'
f7dc1244 13327(@value{GDBP})
10998722 13328@end smallexample
a0eb71c5
KB
13329
13330As above, @value{GDBN} uses the target character set for character and
13331string literals you use in expressions:
13332
13333@smallexample
f7dc1244 13334(@value{GDBP}) print '+'
a0eb71c5 13335$10 = 78 '+'
f7dc1244 13336(@value{GDBP})
10998722 13337@end smallexample
a0eb71c5 13338
e33d66ec 13339The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
13340character.
13341
b12039c6
YQ
13342@node Caching Target Data
13343@section Caching Data of Targets
13344@cindex caching data of targets
13345
13346@value{GDBN} caches data exchanged between the debugger and a target.
b26dfc9a 13347Each cache is associated with the address space of the inferior.
65c574f6 13348@xref{Inferiors Connections and Programs}, about inferior and address space.
b12039c6
YQ
13349Such caching generally improves performance in remote debugging
13350(@pxref{Remote Debugging}), because it reduces the overhead of the
13351remote protocol by bundling memory reads and writes into large chunks.
13352Unfortunately, simply caching everything would lead to incorrect results,
13353since @value{GDBN} does not necessarily know anything about volatile
13354values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
13355(@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
13356is executing.
29b090c0
DE
13357Therefore, by default, @value{GDBN} only caches data
13358known to be on the stack@footnote{In non-stop mode, it is moderately
13359rare for a running thread to modify the stack of a stopped thread
13360in a way that would interfere with a backtrace, and caching of
29453a14
YQ
13361stack reads provides a significant speed up of remote backtraces.} or
13362in the code segment.
29b090c0 13363Other regions of memory can be explicitly marked as
27b81af3 13364cacheable; @pxref{Memory Region Attributes}.
09d4efe1
EZ
13365
13366@table @code
13367@kindex set remotecache
13368@item set remotecache on
13369@itemx set remotecache off
4e5d721f
DE
13370This option no longer does anything; it exists for compatibility
13371with old scripts.
09d4efe1
EZ
13372
13373@kindex show remotecache
13374@item show remotecache
4e5d721f
DE
13375Show the current state of the obsolete remotecache flag.
13376
13377@kindex set stack-cache
13378@item set stack-cache on
13379@itemx set stack-cache off
6dd315ba
YQ
13380Enable or disable caching of stack accesses. When @code{on}, use
13381caching. By default, this option is @code{on}.
4e5d721f
DE
13382
13383@kindex show stack-cache
13384@item show stack-cache
13385Show the current state of data caching for memory accesses.
09d4efe1 13386
29453a14
YQ
13387@kindex set code-cache
13388@item set code-cache on
13389@itemx set code-cache off
13390Enable or disable caching of code segment accesses. When @code{on},
13391use caching. By default, this option is @code{on}. This improves
13392performance of disassembly in remote debugging.
13393
13394@kindex show code-cache
13395@item show code-cache
13396Show the current state of target memory cache for code segment
13397accesses.
13398
09d4efe1 13399@kindex info dcache
4e5d721f 13400@item info dcache @r{[}line@r{]}
b26dfc9a
YQ
13401Print the information about the performance of data cache of the
13402current inferior's address space. The information displayed
13403includes the dcache width and depth, and for each cache line, its
13404number, address, and how many times it was referenced. This
13405command is useful for debugging the data cache operation.
4e5d721f
DE
13406
13407If a line number is specified, the contents of that line will be
13408printed in hex.
1a532630
PP
13409
13410@item set dcache size @var{size}
13411@cindex dcache size
13412@kindex set dcache size
13413Set maximum number of entries in dcache (dcache depth above).
13414
13415@item set dcache line-size @var{line-size}
13416@cindex dcache line-size
13417@kindex set dcache line-size
13418Set number of bytes each dcache entry caches (dcache width above).
13419Must be a power of 2.
13420
13421@item show dcache size
13422@kindex show dcache size
b12039c6 13423Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
1a532630
PP
13424
13425@item show dcache line-size
13426@kindex show dcache line-size
b12039c6 13427Show default size of dcache lines.
1a532630 13428
ee9812a0
AB
13429@item maint flush dcache
13430@cindex dcache, flushing
13431@kindex maint flush dcache
13432Flush the contents (if any) of the dcache. This maintainer command is
13433useful when debugging the dcache implementation.
13434
09d4efe1
EZ
13435@end table
13436
08388c79
DE
13437@node Searching Memory
13438@section Search Memory
13439@cindex searching memory
13440
13441Memory can be searched for a particular sequence of bytes with the
13442@code{find} command.
13443
13444@table @code
13445@kindex find
13446@item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13447@itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13448Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
13449etc. The search begins at address @var{start_addr} and continues for either
13450@var{len} bytes or through to @var{end_addr} inclusive.
13451@end table
13452
13453@var{s} and @var{n} are optional parameters.
13454They may be specified in either order, apart or together.
13455
13456@table @r
13457@item @var{s}, search query size
13458The size of each search query value.
13459
13460@table @code
13461@item b
13462bytes
13463@item h
13464halfwords (two bytes)
13465@item w
13466words (four bytes)
13467@item g
13468giant words (eight bytes)
13469@end table
13470
13471All values are interpreted in the current language.
13472This means, for example, that if the current source language is C/C@t{++}
13473then searching for the string ``hello'' includes the trailing '\0'.
ee9a09e9
DC
13474The null terminator can be removed from searching by using casts,
13475e.g.: @samp{@{char[5]@}"hello"}.
08388c79
DE
13476
13477If the value size is not specified, it is taken from the
13478value's type in the current language.
13479This is useful when one wants to specify the search
13480pattern as a mixture of types.
13481Note that this means, for example, that in the case of C-like languages
13482a search for an untyped 0x42 will search for @samp{(int) 0x42}
13483which is typically four bytes.
13484
13485@item @var{n}, maximum number of finds
13486The maximum number of matches to print. The default is to print all finds.
13487@end table
13488
13489You can use strings as search values. Quote them with double-quotes
13490 (@code{"}).
13491The string value is copied into the search pattern byte by byte,
13492regardless of the endianness of the target and the size specification.
13493
13494The address of each match found is printed as well as a count of the
13495number of matches found.
13496
13497The address of the last value found is stored in convenience variable
13498@samp{$_}.
13499A count of the number of matches is stored in @samp{$numfound}.
13500
13501For example, if stopped at the @code{printf} in this function:
13502
13503@smallexample
13504void
13505hello ()
13506@{
13507 static char hello[] = "hello-hello";
13508 static struct @{ char c; short s; int i; @}
13509 __attribute__ ((packed)) mixed
13510 = @{ 'c', 0x1234, 0x87654321 @};
13511 printf ("%s\n", hello);
13512@}
13513@end smallexample
13514
13515@noindent
13516you get during debugging:
13517
13518@smallexample
13519(gdb) find &hello[0], +sizeof(hello), "hello"
135200x804956d <hello.1620+6>
135211 pattern found
13522(gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
135230x8049567 <hello.1620>
135240x804956d <hello.1620+6>
ee9a09e9
DC
135252 patterns found.
13526(gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
135270x8049567 <hello.1620>
135280x804956d <hello.1620+6>
135292 patterns found.
08388c79
DE
13530(gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
135310x8049567 <hello.1620>
135321 pattern found
13533(gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
135340x8049560 <mixed.1625>
135351 pattern found
13536(gdb) print $numfound
13537$1 = 1
13538(gdb) print $_
13539$2 = (void *) 0x8049560
13540@end smallexample
a0eb71c5 13541
5fdf6324
AB
13542@node Value Sizes
13543@section Value Sizes
13544
13545Whenever @value{GDBN} prints a value memory will be allocated within
13546@value{GDBN} to hold the contents of the value. It is possible in
13547some languages with dynamic typing systems, that an invalid program
13548may indicate a value that is incorrectly large, this in turn may cause
6b92c0d3 13549@value{GDBN} to try and allocate an overly large amount of memory.
5fdf6324
AB
13550
13551@table @code
13552@kindex set max-value-size
713cdcbf 13553@item set max-value-size @var{bytes}
5fdf6324
AB
13554@itemx set max-value-size unlimited
13555Set the maximum size of memory that @value{GDBN} will allocate for the
13556contents of a value to @var{bytes}, trying to display a value that
13557requires more memory than that will result in an error.
13558
13559Setting this variable does not effect values that have already been
13560allocated within @value{GDBN}, only future allocations.
13561
13562There's a minimum size that @code{max-value-size} can be set to in
13563order that @value{GDBN} can still operate correctly, this minimum is
13564currently 16 bytes.
13565
13566The limit applies to the results of some subexpressions as well as to
13567complete expressions. For example, an expression denoting a simple
13568integer component, such as @code{x.y.z}, may fail if the size of
13569@var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
13570@value{GDBN} is sometimes clever; the expression @code{A[i]}, where
13571@var{A} is an array variable with non-constant size, will generally
13572succeed regardless of the bounds on @var{A}, as long as the component
13573size is less than @var{bytes}.
13574
13575The default value of @code{max-value-size} is currently 64k.
13576
13577@kindex show max-value-size
13578@item show max-value-size
13579Show the maximum size of memory, in bytes, that @value{GDBN} will
13580allocate for the contents of a value.
13581@end table
13582
edb3359d
DJ
13583@node Optimized Code
13584@chapter Debugging Optimized Code
13585@cindex optimized code, debugging
13586@cindex debugging optimized code
13587
13588Almost all compilers support optimization. With optimization
13589disabled, the compiler generates assembly code that corresponds
13590directly to your source code, in a simplistic way. As the compiler
13591applies more powerful optimizations, the generated assembly code
13592diverges from your original source code. With help from debugging
13593information generated by the compiler, @value{GDBN} can map from
13594the running program back to constructs from your original source.
13595
13596@value{GDBN} is more accurate with optimization disabled. If you
13597can recompile without optimization, it is easier to follow the
13598progress of your program during debugging. But, there are many cases
13599where you may need to debug an optimized version.
13600
13601When you debug a program compiled with @samp{-g -O}, remember that the
13602optimizer has rearranged your code; the debugger shows you what is
13603really there. Do not be too surprised when the execution path does not
13604exactly match your source file! An extreme example: if you define a
13605variable, but never use it, @value{GDBN} never sees that
13606variable---because the compiler optimizes it out of existence.
13607
13608Some things do not work as well with @samp{-g -O} as with just
13609@samp{-g}, particularly on machines with instruction scheduling. If in
13610doubt, recompile with @samp{-g} alone, and if this fixes the problem,
13611please report it to us as a bug (including a test case!).
13612@xref{Variables}, for more information about debugging optimized code.
13613
13614@menu
13615* Inline Functions:: How @value{GDBN} presents inlining
111c6489 13616* Tail Call Frames:: @value{GDBN} analysis of jumps to functions
edb3359d
DJ
13617@end menu
13618
13619@node Inline Functions
13620@section Inline Functions
13621@cindex inline functions, debugging
13622
13623@dfn{Inlining} is an optimization that inserts a copy of the function
13624body directly at each call site, instead of jumping to a shared
13625routine. @value{GDBN} displays inlined functions just like
13626non-inlined functions. They appear in backtraces. You can view their
13627arguments and local variables, step into them with @code{step}, skip
13628them with @code{next}, and escape from them with @code{finish}.
13629You can check whether a function was inlined by using the
13630@code{info frame} command.
13631
13632For @value{GDBN} to support inlined functions, the compiler must
13633record information about inlining in the debug information ---
13634@value{NGCC} using the @sc{dwarf 2} format does this, and several
13635other compilers do also. @value{GDBN} only supports inlined functions
13636when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
13637do not emit two required attributes (@samp{DW_AT_call_file} and
13638@samp{DW_AT_call_line}); @value{GDBN} does not display inlined
13639function calls with earlier versions of @value{NGCC}. It instead
13640displays the arguments and local variables of inlined functions as
13641local variables in the caller.
13642
13643The body of an inlined function is directly included at its call site;
13644unlike a non-inlined function, there are no instructions devoted to
13645the call. @value{GDBN} still pretends that the call site and the
13646start of the inlined function are different instructions. Stepping to
13647the call site shows the call site, and then stepping again shows
13648the first line of the inlined function, even though no additional
13649instructions are executed.
13650
13651This makes source-level debugging much clearer; you can see both the
13652context of the call and then the effect of the call. Only stepping by
13653a single instruction using @code{stepi} or @code{nexti} does not do
13654this; single instruction steps always show the inlined body.
13655
13656There are some ways that @value{GDBN} does not pretend that inlined
13657function calls are the same as normal calls:
13658
13659@itemize @bullet
edb3359d
DJ
13660@item
13661Setting breakpoints at the call site of an inlined function may not
13662work, because the call site does not contain any code. @value{GDBN}
13663may incorrectly move the breakpoint to the next line of the enclosing
13664function, after the call. This limitation will be removed in a future
13665version of @value{GDBN}; until then, set a breakpoint on an earlier line
13666or inside the inlined function instead.
13667
13668@item
13669@value{GDBN} cannot locate the return value of inlined calls after
13670using the @code{finish} command. This is a limitation of compiler-generated
13671debugging information; after @code{finish}, you can step to the next line
13672and print a variable where your program stored the return value.
13673
13674@end itemize
13675
111c6489
JK
13676@node Tail Call Frames
13677@section Tail Call Frames
13678@cindex tail call frames, debugging
13679
13680Function @code{B} can call function @code{C} in its very last statement. In
13681unoptimized compilation the call of @code{C} is immediately followed by return
13682instruction at the end of @code{B} code. Optimizing compiler may replace the
13683call and return in function @code{B} into one jump to function @code{C}
13684instead. Such use of a jump instruction is called @dfn{tail call}.
13685
13686During execution of function @code{C}, there will be no indication in the
13687function call stack frames that it was tail-called from @code{B}. If function
13688@code{A} regularly calls function @code{B} which tail-calls function @code{C},
13689then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
13690some cases @value{GDBN} can determine that @code{C} was tail-called from
13691@code{B}, and it will then create fictitious call frame for that, with the
13692return address set up as if @code{B} called @code{C} normally.
13693
13694This functionality is currently supported only by DWARF 2 debugging format and
216f72a1 13695the compiler has to produce @samp{DW_TAG_call_site} tags. With
111c6489
JK
13696@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
13697this information.
13698
13699@kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
13700kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
13701
13702@smallexample
13703(gdb) x/i $pc - 2
13704 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
13705(gdb) info frame
13706Stack level 1, frame at 0x7fffffffda30:
13707 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
13708 tail call frame, caller of frame at 0x7fffffffda30
13709 source language c++.
13710 Arglist at unknown address.
13711 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
13712@end smallexample
13713
13714The detection of all the possible code path executions can find them ambiguous.
13715There is no execution history stored (possible @ref{Reverse Execution} is never
13716used for this purpose) and the last known caller could have reached the known
13717callee by multiple different jump sequences. In such case @value{GDBN} still
13718tries to show at least all the unambiguous top tail callers and all the
13719unambiguous bottom tail calees, if any.
13720
13721@table @code
e18b2753 13722@anchor{set debug entry-values}
111c6489
JK
13723@item set debug entry-values
13724@kindex set debug entry-values
13725When set to on, enables printing of analysis messages for both frame argument
13726values at function entry and tail calls. It will show all the possible valid
13727tail calls code paths it has considered. It will also print the intersection
13728of them with the final unambiguous (possibly partial or even empty) code path
13729result.
13730
13731@item show debug entry-values
13732@kindex show debug entry-values
13733Show the current state of analysis messages printing for both frame argument
13734values at function entry and tail calls.
13735@end table
13736
13737The analysis messages for tail calls can for example show why the virtual tail
13738call frame for function @code{c} has not been recognized (due to the indirect
13739reference by variable @code{x}):
13740
13741@smallexample
13742static void __attribute__((noinline, noclone)) c (void);
13743void (*x) (void) = c;
13744static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13745static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
13746int main (void) @{ x (); return 0; @}
13747
216f72a1
JK
13748Breakpoint 1, DW_OP_entry_value resolving cannot find
13749DW_TAG_call_site 0x40039a in main
111c6489
JK
13750a () at t.c:3
137513 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13752(gdb) bt
13753#0 a () at t.c:3
13754#1 0x000000000040039a in main () at t.c:5
13755@end smallexample
13756
13757Another possibility is an ambiguous virtual tail call frames resolution:
13758
13759@smallexample
13760int i;
13761static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
13762static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
13763static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
13764static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
13765static void __attribute__((noinline, noclone)) b (void)
13766@{ if (i) c (); else e (); @}
13767static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
13768int main (void) @{ a (); return 0; @}
13769
13770tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
13771tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
13772tailcall: reduced: 0x4004d2(a) |
13773(gdb) bt
13774#0 f () at t.c:2
13775#1 0x00000000004004d2 in a () at t.c:8
13776#2 0x0000000000400395 in main () at t.c:9
13777@end smallexample
13778
5048e516
JK
13779@set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
13780@set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
13781
13782@c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
13783@ifset HAVE_MAKEINFO_CLICK
13784@set ARROW @click{}
13785@set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
13786@set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
13787@end ifset
13788@ifclear HAVE_MAKEINFO_CLICK
13789@set ARROW ->
13790@set CALLSEQ1B @value{CALLSEQ1A}
13791@set CALLSEQ2B @value{CALLSEQ2A}
13792@end ifclear
13793
13794Frames #0 and #2 are real, #1 is a virtual tail call frame.
13795The code can have possible execution paths @value{CALLSEQ1B} or
13796@value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
111c6489
JK
13797
13798@code{initial:} state shows some random possible calling sequence @value{GDBN}
6b92c0d3 13799has found. It then finds another possible calling sequence - that one is
111c6489
JK
13800prefixed by @code{compare:}. The non-ambiguous intersection of these two is
13801printed as the @code{reduced:} calling sequence. That one could have many
6b92c0d3 13802further @code{compare:} and @code{reduced:} statements as long as there remain
111c6489
JK
13803any non-ambiguous sequence entries.
13804
13805For the frame of function @code{b} in both cases there are different possible
13806@code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
6b92c0d3 13807also ambiguous. The only non-ambiguous frame is the one for function @code{a},
111c6489
JK
13808therefore this one is displayed to the user while the ambiguous frames are
13809omitted.
edb3359d 13810
e18b2753
JK
13811There can be also reasons why printing of frame argument values at function
13812entry may fail:
13813
13814@smallexample
13815int v;
13816static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
13817static void __attribute__((noinline, noclone)) a (int i);
13818static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
13819static void __attribute__((noinline, noclone)) a (int i)
13820@{ if (i) b (i - 1); else c (0); @}
13821int main (void) @{ a (5); return 0; @}
13822
13823(gdb) bt
13824#0 c (i=i@@entry=0) at t.c:2
216f72a1 13825#1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
e18b2753
JK
13826function "a" at 0x400420 can call itself via tail calls
13827i=<optimized out>) at t.c:6
13828#2 0x000000000040036e in main () at t.c:7
13829@end smallexample
13830
13831@value{GDBN} cannot find out from the inferior state if and how many times did
13832function @code{a} call itself (via function @code{b}) as these calls would be
6b92c0d3 13833tail calls. Such tail calls would modify the @code{i} variable, therefore
e18b2753
JK
13834@value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
13835prints @code{<optimized out>} instead.
13836
e2e0bcd1
JB
13837@node Macros
13838@chapter C Preprocessor Macros
13839
49efadf5 13840Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
13841``preprocessor macros'' which expand into strings of tokens.
13842@value{GDBN} can evaluate expressions containing macro invocations, show
13843the result of macro expansion, and show a macro's definition, including
13844where it was defined.
13845
13846You may need to compile your program specially to provide @value{GDBN}
13847with information about preprocessor macros. Most compilers do not
13848include macros in their debugging information, even when you compile
13849with the @option{-g} flag. @xref{Compilation}.
13850
13851A program may define a macro at one point, remove that definition later,
13852and then provide a different definition after that. Thus, at different
13853points in the program, a macro may have different definitions, or have
13854no definition at all. If there is a current stack frame, @value{GDBN}
13855uses the macros in scope at that frame's source code line. Otherwise,
13856@value{GDBN} uses the macros in scope at the current listing location;
13857see @ref{List}.
13858
e2e0bcd1
JB
13859Whenever @value{GDBN} evaluates an expression, it always expands any
13860macro invocations present in the expression. @value{GDBN} also provides
13861the following commands for working with macros explicitly.
13862
13863@table @code
13864
13865@kindex macro expand
13866@cindex macro expansion, showing the results of preprocessor
13867@cindex preprocessor macro expansion, showing the results of
13868@cindex expanding preprocessor macros
13869@item macro expand @var{expression}
13870@itemx macro exp @var{expression}
13871Show the results of expanding all preprocessor macro invocations in
13872@var{expression}. Since @value{GDBN} simply expands macros, but does
13873not parse the result, @var{expression} need not be a valid expression;
13874it can be any string of tokens.
13875
09d4efe1 13876@kindex macro exp1
e2e0bcd1
JB
13877@item macro expand-once @var{expression}
13878@itemx macro exp1 @var{expression}
4644b6e3 13879@cindex expand macro once
e2e0bcd1
JB
13880@i{(This command is not yet implemented.)} Show the results of
13881expanding those preprocessor macro invocations that appear explicitly in
13882@var{expression}. Macro invocations appearing in that expansion are
13883left unchanged. This command allows you to see the effect of a
13884particular macro more clearly, without being confused by further
13885expansions. Since @value{GDBN} simply expands macros, but does not
13886parse the result, @var{expression} need not be a valid expression; it
13887can be any string of tokens.
13888
475b0867 13889@kindex info macro
e2e0bcd1 13890@cindex macro definition, showing
9b158ba0 13891@cindex definition of a macro, showing
13892@cindex macros, from debug info
71eba9c2 13893@item info macro [-a|-all] [--] @var{macro}
13894Show the current definition or all definitions of the named @var{macro},
13895and describe the source location or compiler command-line where that
13896definition was established. The optional double dash is to signify the end of
13897argument processing and the beginning of @var{macro} for non C-like macros where
13898the macro may begin with a hyphen.
e2e0bcd1 13899
9b158ba0 13900@kindex info macros
629500fa 13901@item info macros @var{location}
9b158ba0 13902Show all macro definitions that are in effect at the location specified
629500fa 13903by @var{location}, and describe the source location or compiler
9b158ba0 13904command-line where those definitions were established.
13905
e2e0bcd1
JB
13906@kindex macro define
13907@cindex user-defined macros
13908@cindex defining macros interactively
13909@cindex macros, user-defined
13910@item macro define @var{macro} @var{replacement-list}
13911@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
d7d9f01e
TT
13912Introduce a definition for a preprocessor macro named @var{macro},
13913invocations of which are replaced by the tokens given in
13914@var{replacement-list}. The first form of this command defines an
13915``object-like'' macro, which takes no arguments; the second form
13916defines a ``function-like'' macro, which takes the arguments given in
13917@var{arglist}.
13918
13919A definition introduced by this command is in scope in every
13920expression evaluated in @value{GDBN}, until it is removed with the
13921@code{macro undef} command, described below. The definition overrides
13922all definitions for @var{macro} present in the program being debugged,
13923as well as any previous user-supplied definition.
e2e0bcd1
JB
13924
13925@kindex macro undef
13926@item macro undef @var{macro}
d7d9f01e
TT
13927Remove any user-supplied definition for the macro named @var{macro}.
13928This command only affects definitions provided with the @code{macro
13929define} command, described above; it cannot remove definitions present
13930in the program being debugged.
e2e0bcd1 13931
09d4efe1
EZ
13932@kindex macro list
13933@item macro list
d7d9f01e 13934List all the macros defined using the @code{macro define} command.
e2e0bcd1
JB
13935@end table
13936
13937@cindex macros, example of debugging with
13938Here is a transcript showing the above commands in action. First, we
13939show our source files:
13940
13941@smallexample
13942$ cat sample.c
13943#include <stdio.h>
13944#include "sample.h"
13945
13946#define M 42
13947#define ADD(x) (M + x)
13948
13949main ()
13950@{
13951#define N 28
13952 printf ("Hello, world!\n");
13953#undef N
13954 printf ("We're so creative.\n");
13955#define N 1729
13956 printf ("Goodbye, world!\n");
13957@}
13958$ cat sample.h
13959#define Q <
13960$
13961@end smallexample
13962
e0f8f636
TT
13963Now, we compile the program using the @sc{gnu} C compiler,
13964@value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
13965minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
13966and @option{-gdwarf-4}; we recommend always choosing the most recent
13967version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
13968includes information about preprocessor macros in the debugging
e2e0bcd1
JB
13969information.
13970
13971@smallexample
13972$ gcc -gdwarf-2 -g3 sample.c -o sample
13973$
13974@end smallexample
13975
13976Now, we start @value{GDBN} on our sample program:
13977
13978@smallexample
13979$ gdb -nw sample
13980GNU gdb 2002-05-06-cvs
13981Copyright 2002 Free Software Foundation, Inc.
13982GDB is free software, @dots{}
f7dc1244 13983(@value{GDBP})
e2e0bcd1
JB
13984@end smallexample
13985
13986We can expand macros and examine their definitions, even when the
13987program is not running. @value{GDBN} uses the current listing position
13988to decide which macro definitions are in scope:
13989
13990@smallexample
f7dc1244 13991(@value{GDBP}) list main
e2e0bcd1
JB
139923
139934 #define M 42
139945 #define ADD(x) (M + x)
139956
139967 main ()
139978 @{
139989 #define N 28
1399910 printf ("Hello, world!\n");
1400011 #undef N
1400112 printf ("We're so creative.\n");
f7dc1244 14002(@value{GDBP}) info macro ADD
e2e0bcd1
JB
14003Defined at /home/jimb/gdb/macros/play/sample.c:5
14004#define ADD(x) (M + x)
f7dc1244 14005(@value{GDBP}) info macro Q
e2e0bcd1
JB
14006Defined at /home/jimb/gdb/macros/play/sample.h:1
14007 included at /home/jimb/gdb/macros/play/sample.c:2
14008#define Q <
f7dc1244 14009(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 14010expands to: (42 + 1)
f7dc1244 14011(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 14012expands to: once (M + 1)
f7dc1244 14013(@value{GDBP})
e2e0bcd1
JB
14014@end smallexample
14015
d7d9f01e 14016In the example above, note that @code{macro expand-once} expands only
e2e0bcd1
JB
14017the macro invocation explicit in the original text --- the invocation of
14018@code{ADD} --- but does not expand the invocation of the macro @code{M},
14019which was introduced by @code{ADD}.
14020
3f94c067
BW
14021Once the program is running, @value{GDBN} uses the macro definitions in
14022force at the source line of the current stack frame:
e2e0bcd1
JB
14023
14024@smallexample
f7dc1244 14025(@value{GDBP}) break main
e2e0bcd1 14026Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 14027(@value{GDBP}) run
b383017d 14028Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
14029
14030Breakpoint 1, main () at sample.c:10
1403110 printf ("Hello, world!\n");
f7dc1244 14032(@value{GDBP})
e2e0bcd1
JB
14033@end smallexample
14034
14035At line 10, the definition of the macro @code{N} at line 9 is in force:
14036
14037@smallexample
f7dc1244 14038(@value{GDBP}) info macro N
e2e0bcd1
JB
14039Defined at /home/jimb/gdb/macros/play/sample.c:9
14040#define N 28
f7dc1244 14041(@value{GDBP}) macro expand N Q M
e2e0bcd1 14042expands to: 28 < 42
f7dc1244 14043(@value{GDBP}) print N Q M
e2e0bcd1 14044$1 = 1
f7dc1244 14045(@value{GDBP})
e2e0bcd1
JB
14046@end smallexample
14047
14048As we step over directives that remove @code{N}'s definition, and then
14049give it a new definition, @value{GDBN} finds the definition (or lack
14050thereof) in force at each point:
14051
14052@smallexample
f7dc1244 14053(@value{GDBP}) next
e2e0bcd1
JB
14054Hello, world!
1405512 printf ("We're so creative.\n");
f7dc1244 14056(@value{GDBP}) info macro N
e2e0bcd1
JB
14057The symbol `N' has no definition as a C/C++ preprocessor macro
14058at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 14059(@value{GDBP}) next
e2e0bcd1
JB
14060We're so creative.
1406114 printf ("Goodbye, world!\n");
f7dc1244 14062(@value{GDBP}) info macro N
e2e0bcd1
JB
14063Defined at /home/jimb/gdb/macros/play/sample.c:13
14064#define N 1729
f7dc1244 14065(@value{GDBP}) macro expand N Q M
e2e0bcd1 14066expands to: 1729 < 42
f7dc1244 14067(@value{GDBP}) print N Q M
e2e0bcd1 14068$2 = 0
f7dc1244 14069(@value{GDBP})
e2e0bcd1
JB
14070@end smallexample
14071
484086b7
JK
14072In addition to source files, macros can be defined on the compilation command
14073line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
14074such a way, @value{GDBN} displays the location of their definition as line zero
14075of the source file submitted to the compiler.
14076
14077@smallexample
14078(@value{GDBP}) info macro __STDC__
14079Defined at /home/jimb/gdb/macros/play/sample.c:0
14080-D__STDC__=1
14081(@value{GDBP})
14082@end smallexample
14083
e2e0bcd1 14084
b37052ae
EZ
14085@node Tracepoints
14086@chapter Tracepoints
14087@c This chapter is based on the documentation written by Michael
14088@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
14089
14090@cindex tracepoints
14091In some applications, it is not feasible for the debugger to interrupt
14092the program's execution long enough for the developer to learn
14093anything helpful about its behavior. If the program's correctness
14094depends on its real-time behavior, delays introduced by a debugger
14095might cause the program to change its behavior drastically, or perhaps
14096fail, even when the code itself is correct. It is useful to be able
14097to observe the program's behavior without interrupting it.
14098
14099Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
14100specify locations in the program, called @dfn{tracepoints}, and
14101arbitrary expressions to evaluate when those tracepoints are reached.
14102Later, using the @code{tfind} command, you can examine the values
14103those expressions had when the program hit the tracepoints. The
14104expressions may also denote objects in memory---structures or arrays,
14105for example---whose values @value{GDBN} should record; while visiting
14106a particular tracepoint, you may inspect those objects as if they were
14107in memory at that moment. However, because @value{GDBN} records these
14108values without interacting with you, it can do so quickly and
14109unobtrusively, hopefully not disturbing the program's behavior.
14110
14111The tracepoint facility is currently available only for remote
9d29849a
JB
14112targets. @xref{Targets}. In addition, your remote target must know
14113how to collect trace data. This functionality is implemented in the
14114remote stub; however, none of the stubs distributed with @value{GDBN}
14115support tracepoints as of this writing. The format of the remote
14116packets used to implement tracepoints are described in @ref{Tracepoint
14117Packets}.
b37052ae 14118
00bf0b85
SS
14119It is also possible to get trace data from a file, in a manner reminiscent
14120of corefiles; you specify the filename, and use @code{tfind} to search
14121through the file. @xref{Trace Files}, for more details.
14122
b37052ae
EZ
14123This chapter describes the tracepoint commands and features.
14124
14125@menu
b383017d
RM
14126* Set Tracepoints::
14127* Analyze Collected Data::
14128* Tracepoint Variables::
00bf0b85 14129* Trace Files::
b37052ae
EZ
14130@end menu
14131
14132@node Set Tracepoints
14133@section Commands to Set Tracepoints
14134
14135Before running such a @dfn{trace experiment}, an arbitrary number of
1042e4c0
SS
14136tracepoints can be set. A tracepoint is actually a special type of
14137breakpoint (@pxref{Set Breaks}), so you can manipulate it using
14138standard breakpoint commands. For instance, as with breakpoints,
14139tracepoint numbers are successive integers starting from one, and many
14140of the commands associated with tracepoints take the tracepoint number
14141as their argument, to identify which tracepoint to work on.
b37052ae
EZ
14142
14143For each tracepoint, you can specify, in advance, some arbitrary set
14144of data that you want the target to collect in the trace buffer when
14145it hits that tracepoint. The collected data can include registers,
14146local variables, or global data. Later, you can use @value{GDBN}
14147commands to examine the values these data had at the time the
14148tracepoint was hit.
14149
7d13fe92
SS
14150Tracepoints do not support every breakpoint feature. Ignore counts on
14151tracepoints have no effect, and tracepoints cannot run @value{GDBN}
14152commands when they are hit. Tracepoints may not be thread-specific
14153either.
1042e4c0 14154
7a697b8d
SS
14155@cindex fast tracepoints
14156Some targets may support @dfn{fast tracepoints}, which are inserted in
14157a different way (such as with a jump instead of a trap), that is
14158faster but possibly restricted in where they may be installed.
14159
0fb4aa4b
PA
14160@cindex static tracepoints
14161@cindex markers, static tracepoints
14162@cindex probing markers, static tracepoints
14163Regular and fast tracepoints are dynamic tracing facilities, meaning
14164that they can be used to insert tracepoints at (almost) any location
14165in the target. Some targets may also support controlling @dfn{static
14166tracepoints} from @value{GDBN}. With static tracing, a set of
14167instrumentation points, also known as @dfn{markers}, are embedded in
14168the target program, and can be activated or deactivated by name or
14169address. These are usually placed at locations which facilitate
14170investigating what the target is actually doing. @value{GDBN}'s
14171support for static tracing includes being able to list instrumentation
14172points, and attach them with @value{GDBN} defined high level
14173tracepoints that expose the whole range of convenience of
8786b2bd 14174@value{GDBN}'s tracepoints support. Namely, support for collecting
0fb4aa4b
PA
14175registers values and values of global or local (to the instrumentation
14176point) variables; tracepoint conditions and trace state variables.
14177The act of installing a @value{GDBN} static tracepoint on an
14178instrumentation point, or marker, is referred to as @dfn{probing} a
14179static tracepoint marker.
14180
fa593d66
PA
14181@code{gdbserver} supports tracepoints on some target systems.
14182@xref{Server,,Tracepoints support in @code{gdbserver}}.
14183
b37052ae
EZ
14184This section describes commands to set tracepoints and associated
14185conditions and actions.
14186
14187@menu
b383017d
RM
14188* Create and Delete Tracepoints::
14189* Enable and Disable Tracepoints::
14190* Tracepoint Passcounts::
782b2b07 14191* Tracepoint Conditions::
f61e138d 14192* Trace State Variables::
b383017d
RM
14193* Tracepoint Actions::
14194* Listing Tracepoints::
0fb4aa4b 14195* Listing Static Tracepoint Markers::
79a6e687 14196* Starting and Stopping Trace Experiments::
c9429232 14197* Tracepoint Restrictions::
b37052ae
EZ
14198@end menu
14199
14200@node Create and Delete Tracepoints
14201@subsection Create and Delete Tracepoints
14202
14203@table @code
14204@cindex set tracepoint
14205@kindex trace
1042e4c0 14206@item trace @var{location}
b37052ae 14207The @code{trace} command is very similar to the @code{break} command.
629500fa
KS
14208Its argument @var{location} can be any valid location.
14209@xref{Specify Location}. The @code{trace} command defines a tracepoint,
14210which is a point in the target program where the debugger will briefly stop,
14211collect some data, and then allow the program to continue. Setting a tracepoint
14212or changing its actions takes effect immediately if the remote stub
1e4d1764
YQ
14213supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
14214in tracing}).
14215If remote stub doesn't support the @samp{InstallInTrace} feature, all
14216these changes don't take effect until the next @code{tstart}
1042e4c0 14217command, and once a trace experiment is running, further changes will
bfccc43c
YQ
14218not have any effect until the next trace experiment starts. In addition,
14219@value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
14220address is not yet resolved. (This is similar to pending breakpoints.)
14221Pending tracepoints are not downloaded to the target and not installed
14222until they are resolved. The resolution of pending tracepoints requires
14223@value{GDBN} support---when debugging with the remote target, and
14224@value{GDBN} disconnects from the remote stub (@pxref{disconnected
14225tracing}), pending tracepoints can not be resolved (and downloaded to
14226the remote stub) while @value{GDBN} is disconnected.
b37052ae
EZ
14227
14228Here are some examples of using the @code{trace} command:
14229
14230@smallexample
14231(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
14232
14233(@value{GDBP}) @b{trace +2} // 2 lines forward
14234
14235(@value{GDBP}) @b{trace my_function} // first source line of function
14236
14237(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
14238
14239(@value{GDBP}) @b{trace *0x2117c4} // an address
14240@end smallexample
14241
14242@noindent
14243You can abbreviate @code{trace} as @code{tr}.
14244
782b2b07
SS
14245@item trace @var{location} if @var{cond}
14246Set a tracepoint with condition @var{cond}; evaluate the expression
14247@var{cond} each time the tracepoint is reached, and collect data only
14248if the value is nonzero---that is, if @var{cond} evaluates as true.
14249@xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
14250information on tracepoint conditions.
14251
7a697b8d
SS
14252@item ftrace @var{location} [ if @var{cond} ]
14253@cindex set fast tracepoint
74c761c1 14254@cindex fast tracepoints, setting
7a697b8d
SS
14255@kindex ftrace
14256The @code{ftrace} command sets a fast tracepoint. For targets that
14257support them, fast tracepoints will use a more efficient but possibly
14258less general technique to trigger data collection, such as a jump
14259instruction instead of a trap, or some sort of hardware support. It
14260may not be possible to create a fast tracepoint at the desired
14261location, in which case the command will exit with an explanatory
14262message.
14263
14264@value{GDBN} handles arguments to @code{ftrace} exactly as for
14265@code{trace}.
14266
405f8e94
SS
14267On 32-bit x86-architecture systems, fast tracepoints normally need to
14268be placed at an instruction that is 5 bytes or longer, but can be
14269placed at 4-byte instructions if the low 64K of memory of the target
14270program is available to install trampolines. Some Unix-type systems,
14271such as @sc{gnu}/Linux, exclude low addresses from the program's
14272address space; but for instance with the Linux kernel it is possible
14273to let @value{GDBN} use this area by doing a @command{sysctl} command
14274to set the @code{mmap_min_addr} kernel parameter, as in
14275
14276@example
14277sudo sysctl -w vm.mmap_min_addr=32768
14278@end example
14279
14280@noindent
14281which sets the low address to 32K, which leaves plenty of room for
14282trampolines. The minimum address should be set to a page boundary.
14283
0fb4aa4b 14284@item strace @var{location} [ if @var{cond} ]
74c761c1
PA
14285@cindex set static tracepoint
14286@cindex static tracepoints, setting
14287@cindex probe static tracepoint marker
0fb4aa4b
PA
14288@kindex strace
14289The @code{strace} command sets a static tracepoint. For targets that
14290support it, setting a static tracepoint probes a static
14291instrumentation point, or marker, found at @var{location}. It may not
14292be possible to set a static tracepoint at the desired location, in
14293which case the command will exit with an explanatory message.
14294
14295@value{GDBN} handles arguments to @code{strace} exactly as for
14296@code{trace}, with the addition that the user can also specify
14297@code{-m @var{marker}} as @var{location}. This probes the marker
14298identified by the @var{marker} string identifier. This identifier
14299depends on the static tracepoint backend library your program is
14300using. You can find all the marker identifiers in the @samp{ID} field
14301of the @code{info static-tracepoint-markers} command output.
14302@xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
14303Markers}. For example, in the following small program using the UST
14304tracing engine:
14305
14306@smallexample
14307main ()
14308@{
14309 trace_mark(ust, bar33, "str %s", "FOOBAZ");
14310@}
14311@end smallexample
14312
14313@noindent
14314the marker id is composed of joining the first two arguments to the
14315@code{trace_mark} call with a slash, which translates to:
14316
14317@smallexample
14318(@value{GDBP}) info static-tracepoint-markers
14319Cnt Enb ID Address What
143201 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
14321 Data: "str %s"
14322[etc...]
14323@end smallexample
14324
14325@noindent
14326so you may probe the marker above with:
14327
14328@smallexample
14329(@value{GDBP}) strace -m ust/bar33
14330@end smallexample
14331
14332Static tracepoints accept an extra collect action --- @code{collect
14333$_sdata}. This collects arbitrary user data passed in the probe point
14334call to the tracing library. In the UST example above, you'll see
14335that the third argument to @code{trace_mark} is a printf-like format
6b92c0d3 14336string. The user data is then the result of running that formatting
0fb4aa4b
PA
14337string against the following arguments. Note that @code{info
14338static-tracepoint-markers} command output lists that format string in
14339the @samp{Data:} field.
14340
14341You can inspect this data when analyzing the trace buffer, by printing
14342the $_sdata variable like any other variable available to
14343@value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
14344
b37052ae
EZ
14345@vindex $tpnum
14346@cindex last tracepoint number
14347@cindex recent tracepoint number
14348@cindex tracepoint number
14349The convenience variable @code{$tpnum} records the tracepoint number
14350of the most recently set tracepoint.
14351
14352@kindex delete tracepoint
14353@cindex tracepoint deletion
14354@item delete tracepoint @r{[}@var{num}@r{]}
14355Permanently delete one or more tracepoints. With no argument, the
1042e4c0
SS
14356default is to delete all tracepoints. Note that the regular
14357@code{delete} command can remove tracepoints also.
b37052ae
EZ
14358
14359Examples:
14360
14361@smallexample
14362(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
14363
14364(@value{GDBP}) @b{delete trace} // remove all tracepoints
14365@end smallexample
14366
14367@noindent
14368You can abbreviate this command as @code{del tr}.
14369@end table
14370
14371@node Enable and Disable Tracepoints
14372@subsection Enable and Disable Tracepoints
14373
1042e4c0
SS
14374These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
14375
b37052ae
EZ
14376@table @code
14377@kindex disable tracepoint
14378@item disable tracepoint @r{[}@var{num}@r{]}
14379Disable tracepoint @var{num}, or all tracepoints if no argument
14380@var{num} is given. A disabled tracepoint will have no effect during
d248b706 14381a trace experiment, but it is not forgotten. You can re-enable
b37052ae 14382a disabled tracepoint using the @code{enable tracepoint} command.
d248b706
KY
14383If the command is issued during a trace experiment and the debug target
14384has support for disabling tracepoints during a trace experiment, then the
14385change will be effective immediately. Otherwise, it will be applied to the
14386next trace experiment.
b37052ae
EZ
14387
14388@kindex enable tracepoint
14389@item enable tracepoint @r{[}@var{num}@r{]}
d248b706
KY
14390Enable tracepoint @var{num}, or all tracepoints. If this command is
14391issued during a trace experiment and the debug target supports enabling
14392tracepoints during a trace experiment, then the enabled tracepoints will
14393become effective immediately. Otherwise, they will become effective the
14394next time a trace experiment is run.
b37052ae
EZ
14395@end table
14396
14397@node Tracepoint Passcounts
14398@subsection Tracepoint Passcounts
14399
14400@table @code
14401@kindex passcount
14402@cindex tracepoint pass count
14403@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
14404Set the @dfn{passcount} of a tracepoint. The passcount is a way to
14405automatically stop a trace experiment. If a tracepoint's passcount is
14406@var{n}, then the trace experiment will be automatically stopped on
14407the @var{n}'th time that tracepoint is hit. If the tracepoint number
14408@var{num} is not specified, the @code{passcount} command sets the
14409passcount of the most recently defined tracepoint. If no passcount is
14410given, the trace experiment will run until stopped explicitly by the
14411user.
14412
14413Examples:
14414
14415@smallexample
b383017d 14416(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 14417@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
14418
14419(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 14420@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
14421(@value{GDBP}) @b{trace foo}
14422(@value{GDBP}) @b{pass 3}
14423(@value{GDBP}) @b{trace bar}
14424(@value{GDBP}) @b{pass 2}
14425(@value{GDBP}) @b{trace baz}
14426(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
14427@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
14428@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
14429@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
14430@end smallexample
14431@end table
14432
782b2b07
SS
14433@node Tracepoint Conditions
14434@subsection Tracepoint Conditions
14435@cindex conditional tracepoints
14436@cindex tracepoint conditions
14437
14438The simplest sort of tracepoint collects data every time your program
14439reaches a specified place. You can also specify a @dfn{condition} for
14440a tracepoint. A condition is just a Boolean expression in your
14441programming language (@pxref{Expressions, ,Expressions}). A
14442tracepoint with a condition evaluates the expression each time your
14443program reaches it, and data collection happens only if the condition
14444is true.
14445
14446Tracepoint conditions can be specified when a tracepoint is set, by
14447using @samp{if} in the arguments to the @code{trace} command.
14448@xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
14449also be set or changed at any time with the @code{condition} command,
14450just as with breakpoints.
14451
14452Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
14453the conditional expression itself. Instead, @value{GDBN} encodes the
6dcd5565 14454expression into an agent expression (@pxref{Agent Expressions})
782b2b07
SS
14455suitable for execution on the target, independently of @value{GDBN}.
14456Global variables become raw memory locations, locals become stack
14457accesses, and so forth.
14458
14459For instance, suppose you have a function that is usually called
14460frequently, but should not be called after an error has occurred. You
14461could use the following tracepoint command to collect data about calls
14462of that function that happen while the error code is propagating
14463through the program; an unconditional tracepoint could end up
14464collecting thousands of useless trace frames that you would have to
14465search through.
14466
14467@smallexample
14468(@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
14469@end smallexample
14470
f61e138d
SS
14471@node Trace State Variables
14472@subsection Trace State Variables
14473@cindex trace state variables
14474
14475A @dfn{trace state variable} is a special type of variable that is
14476created and managed by target-side code. The syntax is the same as
14477that for GDB's convenience variables (a string prefixed with ``$''),
14478but they are stored on the target. They must be created explicitly,
14479using a @code{tvariable} command. They are always 64-bit signed
14480integers.
14481
14482Trace state variables are remembered by @value{GDBN}, and downloaded
14483to the target along with tracepoint information when the trace
14484experiment starts. There are no intrinsic limits on the number of
14485trace state variables, beyond memory limitations of the target.
14486
14487@cindex convenience variables, and trace state variables
14488Although trace state variables are managed by the target, you can use
14489them in print commands and expressions as if they were convenience
14490variables; @value{GDBN} will get the current value from the target
14491while the trace experiment is running. Trace state variables share
14492the same namespace as other ``$'' variables, which means that you
14493cannot have trace state variables with names like @code{$23} or
14494@code{$pc}, nor can you have a trace state variable and a convenience
14495variable with the same name.
14496
14497@table @code
14498
14499@item tvariable $@var{name} [ = @var{expression} ]
14500@kindex tvariable
14501The @code{tvariable} command creates a new trace state variable named
14502@code{$@var{name}}, and optionally gives it an initial value of
697aa1b7 14503@var{expression}. The @var{expression} is evaluated when this command is
f61e138d
SS
14504entered; the result will be converted to an integer if possible,
14505otherwise @value{GDBN} will report an error. A subsequent
14506@code{tvariable} command specifying the same name does not create a
14507variable, but instead assigns the supplied initial value to the
14508existing variable of that name, overwriting any previous initial
14509value. The default initial value is 0.
14510
14511@item info tvariables
14512@kindex info tvariables
14513List all the trace state variables along with their initial values.
14514Their current values may also be displayed, if the trace experiment is
14515currently running.
14516
14517@item delete tvariable @r{[} $@var{name} @dots{} @r{]}
14518@kindex delete tvariable
14519Delete the given trace state variables, or all of them if no arguments
14520are specified.
14521
14522@end table
14523
b37052ae
EZ
14524@node Tracepoint Actions
14525@subsection Tracepoint Action Lists
14526
14527@table @code
14528@kindex actions
14529@cindex tracepoint actions
14530@item actions @r{[}@var{num}@r{]}
14531This command will prompt for a list of actions to be taken when the
14532tracepoint is hit. If the tracepoint number @var{num} is not
14533specified, this command sets the actions for the one that was most
14534recently defined (so that you can define a tracepoint and then say
14535@code{actions} without bothering about its number). You specify the
14536actions themselves on the following lines, one action at a time, and
14537terminate the actions list with a line containing just @code{end}. So
7d13fe92 14538far, the only defined actions are @code{collect}, @code{teval}, and
b37052ae
EZ
14539@code{while-stepping}.
14540
5a9351ae
SS
14541@code{actions} is actually equivalent to @code{commands} (@pxref{Break
14542Commands, ,Breakpoint Command Lists}), except that only the defined
14543actions are allowed; any other @value{GDBN} command is rejected.
14544
b37052ae
EZ
14545@cindex remove actions from a tracepoint
14546To remove all actions from a tracepoint, type @samp{actions @var{num}}
14547and follow it immediately with @samp{end}.
14548
14549@smallexample
14550(@value{GDBP}) @b{collect @var{data}} // collect some data
14551
6826cf00 14552(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 14553
6826cf00 14554(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
14555@end smallexample
14556
14557In the following example, the action list begins with @code{collect}
14558commands indicating the things to be collected when the tracepoint is
14559hit. Then, in order to single-step and collect additional data
14560following the tracepoint, a @code{while-stepping} command is used,
7d13fe92
SS
14561followed by the list of things to be collected after each step in a
14562sequence of single steps. The @code{while-stepping} command is
14563terminated by its own separate @code{end} command. Lastly, the action
14564list is terminated by an @code{end} command.
b37052ae
EZ
14565
14566@smallexample
14567(@value{GDBP}) @b{trace foo}
14568(@value{GDBP}) @b{actions}
14569Enter actions for tracepoint 1, one per line:
14570> collect bar,baz
14571> collect $regs
14572> while-stepping 12
5a9351ae 14573 > collect $pc, arr[i]
b37052ae
EZ
14574 > end
14575end
14576@end smallexample
14577
14578@kindex collect @r{(tracepoints)}
3065dfb6 14579@item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
b37052ae
EZ
14580Collect values of the given expressions when the tracepoint is hit.
14581This command accepts a comma-separated list of any valid expressions.
14582In addition to global, static, or local variables, the following
14583special arguments are supported:
14584
14585@table @code
14586@item $regs
0fb4aa4b 14587Collect all registers.
b37052ae
EZ
14588
14589@item $args
0fb4aa4b 14590Collect all function arguments.
b37052ae
EZ
14591
14592@item $locals
0fb4aa4b
PA
14593Collect all local variables.
14594
6710bf39
SS
14595@item $_ret
14596Collect the return address. This is helpful if you want to see more
14597of a backtrace.
14598
2a60e18f 14599@emph{Note:} The return address location can not always be reliably
45fa2529
PA
14600determined up front, and the wrong address / registers may end up
14601collected instead. On some architectures the reliability is higher
14602for tracepoints at function entry, while on others it's the opposite.
14603When this happens, backtracing will stop because the return address is
14604found unavailable (unless another collect rule happened to match it).
14605
62e5f89c
SDJ
14606@item $_probe_argc
14607Collects the number of arguments from the static probe at which the
14608tracepoint is located.
14609@xref{Static Probe Points}.
14610
14611@item $_probe_arg@var{n}
14612@var{n} is an integer between 0 and 11. Collects the @var{n}th argument
14613from the static probe at which the tracepoint is located.
14614@xref{Static Probe Points}.
14615
0fb4aa4b
PA
14616@item $_sdata
14617@vindex $_sdata@r{, collect}
14618Collect static tracepoint marker specific data. Only available for
14619static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
14620Lists}. On the UST static tracepoints library backend, an
14621instrumentation point resembles a @code{printf} function call. The
14622tracing library is able to collect user specified data formatted to a
14623character string using the format provided by the programmer that
14624instrumented the program. Other backends have similar mechanisms.
14625Here's an example of a UST marker call:
14626
14627@smallexample
14628 const char master_name[] = "$your_name";
14629 trace_mark(channel1, marker1, "hello %s", master_name)
14630@end smallexample
14631
14632In this case, collecting @code{$_sdata} collects the string
14633@samp{hello $yourname}. When analyzing the trace buffer, you can
14634inspect @samp{$_sdata} like any other variable available to
14635@value{GDBN}.
b37052ae
EZ
14636@end table
14637
14638You can give several consecutive @code{collect} commands, each one
14639with a single argument, or one @code{collect} command with several
5a9351ae 14640arguments separated by commas; the effect is the same.
b37052ae 14641
3065dfb6
SS
14642The optional @var{mods} changes the usual handling of the arguments.
14643@code{s} requests that pointers to chars be handled as strings, in
14644particular collecting the contents of the memory being pointed at, up
14645to the first zero. The upper bound is by default the value of the
14646@code{print elements} variable; if @code{s} is followed by a decimal
14647number, that is the upper bound instead. So for instance
14648@samp{collect/s25 mystr} collects as many as 25 characters at
14649@samp{mystr}.
14650
f5c37c66
EZ
14651The command @code{info scope} (@pxref{Symbols, info scope}) is
14652particularly useful for figuring out what data to collect.
14653
6da95a67
SS
14654@kindex teval @r{(tracepoints)}
14655@item teval @var{expr1}, @var{expr2}, @dots{}
14656Evaluate the given expressions when the tracepoint is hit. This
14657command accepts a comma-separated list of expressions. The results
14658are discarded, so this is mainly useful for assigning values to trace
14659state variables (@pxref{Trace State Variables}) without adding those
14660values to the trace buffer, as would be the case if the @code{collect}
14661action were used.
14662
b37052ae
EZ
14663@kindex while-stepping @r{(tracepoints)}
14664@item while-stepping @var{n}
c9429232 14665Perform @var{n} single-step instruction traces after the tracepoint,
7d13fe92 14666collecting new data after each step. The @code{while-stepping}
c9429232
SS
14667command is followed by the list of what to collect while stepping
14668(followed by its own @code{end} command):
b37052ae
EZ
14669
14670@smallexample
14671> while-stepping 12
14672 > collect $regs, myglobal
14673 > end
14674>
14675@end smallexample
14676
14677@noindent
7d13fe92
SS
14678Note that @code{$pc} is not automatically collected by
14679@code{while-stepping}; you need to explicitly collect that register if
14680you need it. You may abbreviate @code{while-stepping} as @code{ws} or
b37052ae 14681@code{stepping}.
236f1d4d
SS
14682
14683@item set default-collect @var{expr1}, @var{expr2}, @dots{}
14684@kindex set default-collect
14685@cindex default collection action
14686This variable is a list of expressions to collect at each tracepoint
14687hit. It is effectively an additional @code{collect} action prepended
14688to every tracepoint action list. The expressions are parsed
14689individually for each tracepoint, so for instance a variable named
14690@code{xyz} may be interpreted as a global for one tracepoint, and a
14691local for another, as appropriate to the tracepoint's location.
14692
14693@item show default-collect
14694@kindex show default-collect
14695Show the list of expressions that are collected by default at each
14696tracepoint hit.
14697
b37052ae
EZ
14698@end table
14699
14700@node Listing Tracepoints
14701@subsection Listing Tracepoints
14702
14703@table @code
e5a67952
MS
14704@kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
14705@kindex info tp @r{[}@var{n}@dots{}@r{]}
b37052ae 14706@cindex information about tracepoints
e5a67952 14707@item info tracepoints @r{[}@var{num}@dots{}@r{]}
1042e4c0
SS
14708Display information about the tracepoint @var{num}. If you don't
14709specify a tracepoint number, displays information about all the
14710tracepoints defined so far. The format is similar to that used for
14711@code{info breakpoints}; in fact, @code{info tracepoints} is the same
14712command, simply restricting itself to tracepoints.
14713
14714A tracepoint's listing may include additional information specific to
14715tracing:
b37052ae
EZ
14716
14717@itemize @bullet
14718@item
b37052ae 14719its passcount as given by the @code{passcount @var{n}} command
f2a8bc8a
YQ
14720
14721@item
14722the state about installed on target of each location
b37052ae
EZ
14723@end itemize
14724
14725@smallexample
14726(@value{GDBP}) @b{info trace}
1042e4c0
SS
14727Num Type Disp Enb Address What
147281 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
5a9351ae
SS
14729 while-stepping 20
14730 collect globfoo, $regs
14731 end
14732 collect globfoo2
14733 end
1042e4c0 14734 pass count 1200
f2a8bc8a
YQ
147352 tracepoint keep y <MULTIPLE>
14736 collect $eip
147372.1 y 0x0804859c in func4 at change-loc.h:35
14738 installed on target
147392.2 y 0xb7ffc480 in func4 at change-loc.h:35
14740 installed on target
147412.3 y <PENDING> set_tracepoint
147423 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
14743 not installed on target
b37052ae
EZ
14744(@value{GDBP})
14745@end smallexample
14746
14747@noindent
14748This command can be abbreviated @code{info tp}.
14749@end table
14750
0fb4aa4b
PA
14751@node Listing Static Tracepoint Markers
14752@subsection Listing Static Tracepoint Markers
14753
14754@table @code
14755@kindex info static-tracepoint-markers
14756@cindex information about static tracepoint markers
14757@item info static-tracepoint-markers
14758Display information about all static tracepoint markers defined in the
14759program.
14760
14761For each marker, the following columns are printed:
14762
14763@table @emph
14764@item Count
14765An incrementing counter, output to help readability. This is not a
14766stable identifier.
14767@item ID
14768The marker ID, as reported by the target.
14769@item Enabled or Disabled
14770Probed markers are tagged with @samp{y}. @samp{n} identifies marks
14771that are not enabled.
14772@item Address
14773Where the marker is in your program, as a memory address.
14774@item What
14775Where the marker is in the source for your program, as a file and line
14776number. If the debug information included in the program does not
14777allow @value{GDBN} to locate the source of the marker, this column
14778will be left blank.
14779@end table
14780
14781@noindent
14782In addition, the following information may be printed for each marker:
14783
14784@table @emph
14785@item Data
14786User data passed to the tracing library by the marker call. In the
14787UST backend, this is the format string passed as argument to the
14788marker call.
14789@item Static tracepoints probing the marker
14790The list of static tracepoints attached to the marker.
14791@end table
14792
14793@smallexample
14794(@value{GDBP}) info static-tracepoint-markers
14795Cnt ID Enb Address What
147961 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
14797 Data: number1 %d number2 %d
14798 Probed by static tracepoints: #2
147992 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
14800 Data: str %s
14801(@value{GDBP})
14802@end smallexample
14803@end table
14804
79a6e687
BW
14805@node Starting and Stopping Trace Experiments
14806@subsection Starting and Stopping Trace Experiments
b37052ae
EZ
14807
14808@table @code
f196051f 14809@kindex tstart [ @var{notes} ]
b37052ae
EZ
14810@cindex start a new trace experiment
14811@cindex collected data discarded
14812@item tstart
f196051f
SS
14813This command starts the trace experiment, and begins collecting data.
14814It has the side effect of discarding all the data collected in the
14815trace buffer during the previous trace experiment. If any arguments
14816are supplied, they are taken as a note and stored with the trace
14817experiment's state. The notes may be arbitrary text, and are
14818especially useful with disconnected tracing in a multi-user context;
14819the notes can explain what the trace is doing, supply user contact
14820information, and so forth.
14821
14822@kindex tstop [ @var{notes} ]
b37052ae
EZ
14823@cindex stop a running trace experiment
14824@item tstop
f196051f
SS
14825This command stops the trace experiment. If any arguments are
14826supplied, they are recorded with the experiment as a note. This is
14827useful if you are stopping a trace started by someone else, for
14828instance if the trace is interfering with the system's behavior and
14829needs to be stopped quickly.
b37052ae 14830
68c71a2e 14831@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
14832automatically if any tracepoint's passcount is reached
14833(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
14834
14835@kindex tstatus
14836@cindex status of trace data collection
14837@cindex trace experiment, status of
14838@item tstatus
14839This command displays the status of the current trace data
14840collection.
14841@end table
14842
14843Here is an example of the commands we described so far:
14844
14845@smallexample
14846(@value{GDBP}) @b{trace gdb_c_test}
14847(@value{GDBP}) @b{actions}
14848Enter actions for tracepoint #1, one per line.
14849> collect $regs,$locals,$args
14850> while-stepping 11
14851 > collect $regs
14852 > end
14853> end
14854(@value{GDBP}) @b{tstart}
14855 [time passes @dots{}]
14856(@value{GDBP}) @b{tstop}
14857@end smallexample
14858
03f2bd59 14859@anchor{disconnected tracing}
d5551862
SS
14860@cindex disconnected tracing
14861You can choose to continue running the trace experiment even if
14862@value{GDBN} disconnects from the target, voluntarily or
14863involuntarily. For commands such as @code{detach}, the debugger will
14864ask what you want to do with the trace. But for unexpected
14865terminations (@value{GDBN} crash, network outage), it would be
14866unfortunate to lose hard-won trace data, so the variable
14867@code{disconnected-tracing} lets you decide whether the trace should
14868continue running without @value{GDBN}.
14869
14870@table @code
14871@item set disconnected-tracing on
14872@itemx set disconnected-tracing off
14873@kindex set disconnected-tracing
14874Choose whether a tracing run should continue to run if @value{GDBN}
14875has disconnected from the target. Note that @code{detach} or
14876@code{quit} will ask you directly what to do about a running trace no
14877matter what this variable's setting, so the variable is mainly useful
14878for handling unexpected situations, such as loss of the network.
14879
14880@item show disconnected-tracing
14881@kindex show disconnected-tracing
14882Show the current choice for disconnected tracing.
14883
14884@end table
14885
14886When you reconnect to the target, the trace experiment may or may not
14887still be running; it might have filled the trace buffer in the
14888meantime, or stopped for one of the other reasons. If it is running,
14889it will continue after reconnection.
14890
14891Upon reconnection, the target will upload information about the
14892tracepoints in effect. @value{GDBN} will then compare that
14893information to the set of tracepoints currently defined, and attempt
14894to match them up, allowing for the possibility that the numbers may
14895have changed due to creation and deletion in the meantime. If one of
14896the target's tracepoints does not match any in @value{GDBN}, the
14897debugger will create a new tracepoint, so that you have a number with
14898which to specify that tracepoint. This matching-up process is
14899necessarily heuristic, and it may result in useless tracepoints being
14900created; you may simply delete them if they are of no use.
b37052ae 14901
4daf5ac0
SS
14902@cindex circular trace buffer
14903If your target agent supports a @dfn{circular trace buffer}, then you
14904can run a trace experiment indefinitely without filling the trace
14905buffer; when space runs out, the agent deletes already-collected trace
14906frames, oldest first, until there is enough room to continue
14907collecting. This is especially useful if your tracepoints are being
14908hit too often, and your trace gets terminated prematurely because the
14909buffer is full. To ask for a circular trace buffer, simply set
81896e36 14910@samp{circular-trace-buffer} to on. You can set this at any time,
4daf5ac0
SS
14911including during tracing; if the agent can do it, it will change
14912buffer handling on the fly, otherwise it will not take effect until
14913the next run.
14914
14915@table @code
14916@item set circular-trace-buffer on
14917@itemx set circular-trace-buffer off
14918@kindex set circular-trace-buffer
14919Choose whether a tracing run should use a linear or circular buffer
14920for trace data. A linear buffer will not lose any trace data, but may
14921fill up prematurely, while a circular buffer will discard old trace
14922data, but it will have always room for the latest tracepoint hits.
14923
14924@item show circular-trace-buffer
14925@kindex show circular-trace-buffer
14926Show the current choice for the trace buffer. Note that this may not
14927match the agent's current buffer handling, nor is it guaranteed to
14928match the setting that might have been in effect during a past run,
14929for instance if you are looking at frames from a trace file.
14930
14931@end table
14932
f6f899bf
HAQ
14933@table @code
14934@item set trace-buffer-size @var{n}
f81d1120 14935@itemx set trace-buffer-size unlimited
f6f899bf
HAQ
14936@kindex set trace-buffer-size
14937Request that the target use a trace buffer of @var{n} bytes. Not all
14938targets will honor the request; they may have a compiled-in size for
14939the trace buffer, or some other limitation. Set to a value of
f81d1120
PA
14940@code{unlimited} or @code{-1} to let the target use whatever size it
14941likes. This is also the default.
f6f899bf
HAQ
14942
14943@item show trace-buffer-size
14944@kindex show trace-buffer-size
14945Show the current requested size for the trace buffer. Note that this
14946will only match the actual size if the target supports size-setting,
14947and was able to handle the requested size. For instance, if the
14948target can only change buffer size between runs, this variable will
14949not reflect the change until the next run starts. Use @code{tstatus}
14950to get a report of the actual buffer size.
14951@end table
14952
f196051f
SS
14953@table @code
14954@item set trace-user @var{text}
14955@kindex set trace-user
14956
14957@item show trace-user
14958@kindex show trace-user
14959
14960@item set trace-notes @var{text}
14961@kindex set trace-notes
14962Set the trace run's notes.
14963
14964@item show trace-notes
14965@kindex show trace-notes
14966Show the trace run's notes.
14967
14968@item set trace-stop-notes @var{text}
14969@kindex set trace-stop-notes
14970Set the trace run's stop notes. The handling of the note is as for
14971@code{tstop} arguments; the set command is convenient way to fix a
14972stop note that is mistaken or incomplete.
14973
14974@item show trace-stop-notes
14975@kindex show trace-stop-notes
14976Show the trace run's stop notes.
14977
14978@end table
14979
c9429232
SS
14980@node Tracepoint Restrictions
14981@subsection Tracepoint Restrictions
14982
14983@cindex tracepoint restrictions
14984There are a number of restrictions on the use of tracepoints. As
14985described above, tracepoint data gathering occurs on the target
14986without interaction from @value{GDBN}. Thus the full capabilities of
14987the debugger are not available during data gathering, and then at data
14988examination time, you will be limited by only having what was
14989collected. The following items describe some common problems, but it
14990is not exhaustive, and you may run into additional difficulties not
14991mentioned here.
14992
14993@itemize @bullet
14994
14995@item
14996Tracepoint expressions are intended to gather objects (lvalues). Thus
14997the full flexibility of GDB's expression evaluator is not available.
14998You cannot call functions, cast objects to aggregate types, access
14999convenience variables or modify values (except by assignment to trace
15000state variables). Some language features may implicitly call
15001functions (for instance Objective-C fields with accessors), and therefore
15002cannot be collected either.
15003
15004@item
15005Collection of local variables, either individually or in bulk with
15006@code{$locals} or @code{$args}, during @code{while-stepping} may
15007behave erratically. The stepping action may enter a new scope (for
15008instance by stepping into a function), or the location of the variable
15009may change (for instance it is loaded into a register). The
15010tracepoint data recorded uses the location information for the
15011variables that is correct for the tracepoint location. When the
15012tracepoint is created, it is not possible, in general, to determine
15013where the steps of a @code{while-stepping} sequence will advance the
15014program---particularly if a conditional branch is stepped.
15015
15016@item
15017Collection of an incompletely-initialized or partially-destroyed object
15018may result in something that @value{GDBN} cannot display, or displays
15019in a misleading way.
15020
15021@item
15022When @value{GDBN} displays a pointer to character it automatically
15023dereferences the pointer to also display characters of the string
15024being pointed to. However, collecting the pointer during tracing does
15025not automatically collect the string. You need to explicitly
15026dereference the pointer and provide size information if you want to
15027collect not only the pointer, but the memory pointed to. For example,
15028@code{*ptr@@50} can be used to collect the 50 element array pointed to
15029by @code{ptr}.
15030
15031@item
15032It is not possible to collect a complete stack backtrace at a
15033tracepoint. Instead, you may collect the registers and a few hundred
d99f7e48 15034bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
c9429232
SS
15035(adjust to use the name of the actual stack pointer register on your
15036target architecture, and the amount of stack you wish to capture).
15037Then the @code{backtrace} command will show a partial backtrace when
15038using a trace frame. The number of stack frames that can be examined
15039depends on the sizes of the frames in the collected stack. Note that
15040if you ask for a block so large that it goes past the bottom of the
15041stack, the target agent may report an error trying to read from an
15042invalid address.
15043
af54718e
SS
15044@item
15045If you do not collect registers at a tracepoint, @value{GDBN} can
15046infer that the value of @code{$pc} must be the same as the address of
15047the tracepoint and use that when you are looking at a trace frame
15048for that tracepoint. However, this cannot work if the tracepoint has
15049multiple locations (for instance if it was set in a function that was
15050inlined), or if it has a @code{while-stepping} loop. In those cases
15051@value{GDBN} will warn you that it can't infer @code{$pc}, and default
15052it to zero.
15053
c9429232
SS
15054@end itemize
15055
b37052ae 15056@node Analyze Collected Data
79a6e687 15057@section Using the Collected Data
b37052ae
EZ
15058
15059After the tracepoint experiment ends, you use @value{GDBN} commands
15060for examining the trace data. The basic idea is that each tracepoint
15061collects a trace @dfn{snapshot} every time it is hit and another
15062snapshot every time it single-steps. All these snapshots are
15063consecutively numbered from zero and go into a buffer, and you can
15064examine them later. The way you examine them is to @dfn{focus} on a
15065specific trace snapshot. When the remote stub is focused on a trace
15066snapshot, it will respond to all @value{GDBN} requests for memory and
15067registers by reading from the buffer which belongs to that snapshot,
15068rather than from @emph{real} memory or registers of the program being
15069debugged. This means that @strong{all} @value{GDBN} commands
15070(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
15071behave as if we were currently debugging the program state as it was
15072when the tracepoint occurred. Any requests for data that are not in
15073the buffer will fail.
15074
15075@menu
15076* tfind:: How to select a trace snapshot
15077* tdump:: How to display all data for a snapshot
6149aea9 15078* save tracepoints:: How to save tracepoints for a future run
b37052ae
EZ
15079@end menu
15080
15081@node tfind
15082@subsection @code{tfind @var{n}}
15083
15084@kindex tfind
15085@cindex select trace snapshot
15086@cindex find trace snapshot
15087The basic command for selecting a trace snapshot from the buffer is
15088@code{tfind @var{n}}, which finds trace snapshot number @var{n},
15089counting from zero. If no argument @var{n} is given, the next
15090snapshot is selected.
15091
15092Here are the various forms of using the @code{tfind} command.
15093
15094@table @code
15095@item tfind start
15096Find the first snapshot in the buffer. This is a synonym for
15097@code{tfind 0} (since 0 is the number of the first snapshot).
15098
15099@item tfind none
15100Stop debugging trace snapshots, resume @emph{live} debugging.
15101
15102@item tfind end
15103Same as @samp{tfind none}.
15104
15105@item tfind
310cdbb6
YQ
15106No argument means find the next trace snapshot or find the first
15107one if no trace snapshot is selected.
b37052ae
EZ
15108
15109@item tfind -
15110Find the previous trace snapshot before the current one. This permits
15111retracing earlier steps.
15112
15113@item tfind tracepoint @var{num}
15114Find the next snapshot associated with tracepoint @var{num}. Search
15115proceeds forward from the last examined trace snapshot. If no
15116argument @var{num} is given, it means find the next snapshot collected
15117for the same tracepoint as the current snapshot.
15118
15119@item tfind pc @var{addr}
15120Find the next snapshot associated with the value @var{addr} of the
15121program counter. Search proceeds forward from the last examined trace
15122snapshot. If no argument @var{addr} is given, it means find the next
15123snapshot with the same value of PC as the current snapshot.
15124
15125@item tfind outside @var{addr1}, @var{addr2}
15126Find the next snapshot whose PC is outside the given range of
081dfbf7 15127addresses (exclusive).
b37052ae
EZ
15128
15129@item tfind range @var{addr1}, @var{addr2}
15130Find the next snapshot whose PC is between @var{addr1} and
081dfbf7 15131@var{addr2} (inclusive).
b37052ae
EZ
15132
15133@item tfind line @r{[}@var{file}:@r{]}@var{n}
15134Find the next snapshot associated with the source line @var{n}. If
15135the optional argument @var{file} is given, refer to line @var{n} in
15136that source file. Search proceeds forward from the last examined
15137trace snapshot. If no argument @var{n} is given, it means find the
15138next line other than the one currently being examined; thus saying
15139@code{tfind line} repeatedly can appear to have the same effect as
15140stepping from line to line in a @emph{live} debugging session.
15141@end table
15142
15143The default arguments for the @code{tfind} commands are specifically
15144designed to make it easy to scan through the trace buffer. For
15145instance, @code{tfind} with no argument selects the next trace
15146snapshot, and @code{tfind -} with no argument selects the previous
15147trace snapshot. So, by giving one @code{tfind} command, and then
15148simply hitting @key{RET} repeatedly you can examine all the trace
15149snapshots in order. Or, by saying @code{tfind -} and then hitting
15150@key{RET} repeatedly you can examine the snapshots in reverse order.
15151The @code{tfind line} command with no argument selects the snapshot
15152for the next source line executed. The @code{tfind pc} command with
15153no argument selects the next snapshot with the same program counter
15154(PC) as the current frame. The @code{tfind tracepoint} command with
15155no argument selects the next trace snapshot collected by the same
15156tracepoint as the current one.
15157
15158In addition to letting you scan through the trace buffer manually,
15159these commands make it easy to construct @value{GDBN} scripts that
15160scan through the trace buffer and print out whatever collected data
15161you are interested in. Thus, if we want to examine the PC, FP, and SP
15162registers from each trace frame in the buffer, we can say this:
15163
15164@smallexample
15165(@value{GDBP}) @b{tfind start}
15166(@value{GDBP}) @b{while ($trace_frame != -1)}
15167> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
15168 $trace_frame, $pc, $sp, $fp
15169> tfind
15170> end
15171
15172Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
15173Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
15174Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
15175Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
15176Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
15177Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
15178Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
15179Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
15180Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
15181Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
15182Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
15183@end smallexample
15184
15185Or, if we want to examine the variable @code{X} at each source line in
15186the buffer:
15187
15188@smallexample
15189(@value{GDBP}) @b{tfind start}
15190(@value{GDBP}) @b{while ($trace_frame != -1)}
15191> printf "Frame %d, X == %d\n", $trace_frame, X
15192> tfind line
15193> end
15194
15195Frame 0, X = 1
15196Frame 7, X = 2
15197Frame 13, X = 255
15198@end smallexample
15199
15200@node tdump
15201@subsection @code{tdump}
15202@kindex tdump
15203@cindex dump all data collected at tracepoint
15204@cindex tracepoint data, display
15205
15206This command takes no arguments. It prints all the data collected at
15207the current trace snapshot.
15208
15209@smallexample
15210(@value{GDBP}) @b{trace 444}
15211(@value{GDBP}) @b{actions}
15212Enter actions for tracepoint #2, one per line:
15213> collect $regs, $locals, $args, gdb_long_test
15214> end
15215
15216(@value{GDBP}) @b{tstart}
15217
15218(@value{GDBP}) @b{tfind line 444}
15219#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
15220at gdb_test.c:444
15221444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
15222
15223(@value{GDBP}) @b{tdump}
15224Data collected at tracepoint 2, trace frame 1:
15225d0 0xc4aa0085 -995491707
15226d1 0x18 24
15227d2 0x80 128
15228d3 0x33 51
15229d4 0x71aea3d 119204413
15230d5 0x22 34
15231d6 0xe0 224
15232d7 0x380035 3670069
15233a0 0x19e24a 1696330
15234a1 0x3000668 50333288
15235a2 0x100 256
15236a3 0x322000 3284992
15237a4 0x3000698 50333336
15238a5 0x1ad3cc 1758156
15239fp 0x30bf3c 0x30bf3c
15240sp 0x30bf34 0x30bf34
15241ps 0x0 0
15242pc 0x20b2c8 0x20b2c8
15243fpcontrol 0x0 0
15244fpstatus 0x0 0
15245fpiaddr 0x0 0
15246p = 0x20e5b4 "gdb-test"
15247p1 = (void *) 0x11
15248p2 = (void *) 0x22
15249p3 = (void *) 0x33
15250p4 = (void *) 0x44
15251p5 = (void *) 0x55
15252p6 = (void *) 0x66
15253gdb_long_test = 17 '\021'
15254
15255(@value{GDBP})
15256@end smallexample
15257
af54718e
SS
15258@code{tdump} works by scanning the tracepoint's current collection
15259actions and printing the value of each expression listed. So
15260@code{tdump} can fail, if after a run, you change the tracepoint's
15261actions to mention variables that were not collected during the run.
15262
15263Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
15264uses the collected value of @code{$pc} to distinguish between trace
15265frames that were collected at the tracepoint hit, and frames that were
15266collected while stepping. This allows it to correctly choose whether
15267to display the basic list of collections, or the collections from the
15268body of the while-stepping loop. However, if @code{$pc} was not collected,
15269then @code{tdump} will always attempt to dump using the basic collection
15270list, and may fail if a while-stepping frame does not include all the
15271same data that is collected at the tracepoint hit.
15272@c This is getting pretty arcane, example would be good.
15273
6149aea9
PA
15274@node save tracepoints
15275@subsection @code{save tracepoints @var{filename}}
15276@kindex save tracepoints
b37052ae
EZ
15277@kindex save-tracepoints
15278@cindex save tracepoints for future sessions
15279
15280This command saves all current tracepoint definitions together with
15281their actions and passcounts, into a file @file{@var{filename}}
15282suitable for use in a later debugging session. To read the saved
15283tracepoint definitions, use the @code{source} command (@pxref{Command
6149aea9
PA
15284Files}). The @w{@code{save-tracepoints}} command is a deprecated
15285alias for @w{@code{save tracepoints}}
b37052ae
EZ
15286
15287@node Tracepoint Variables
15288@section Convenience Variables for Tracepoints
15289@cindex tracepoint variables
15290@cindex convenience variables for tracepoints
15291
15292@table @code
15293@vindex $trace_frame
15294@item (int) $trace_frame
15295The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
15296snapshot is selected.
15297
15298@vindex $tracepoint
15299@item (int) $tracepoint
15300The tracepoint for the current trace snapshot.
15301
15302@vindex $trace_line
15303@item (int) $trace_line
15304The line number for the current trace snapshot.
15305
15306@vindex $trace_file
15307@item (char []) $trace_file
15308The source file for the current trace snapshot.
15309
15310@vindex $trace_func
15311@item (char []) $trace_func
15312The name of the function containing @code{$tracepoint}.
15313@end table
15314
15315Note: @code{$trace_file} is not suitable for use in @code{printf},
15316use @code{output} instead.
15317
15318Here's a simple example of using these convenience variables for
15319stepping through all the trace snapshots and printing some of their
f61e138d
SS
15320data. Note that these are not the same as trace state variables,
15321which are managed by the target.
b37052ae
EZ
15322
15323@smallexample
15324(@value{GDBP}) @b{tfind start}
15325
15326(@value{GDBP}) @b{while $trace_frame != -1}
15327> output $trace_file
15328> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
15329> tfind
15330> end
15331@end smallexample
15332
00bf0b85
SS
15333@node Trace Files
15334@section Using Trace Files
15335@cindex trace files
15336
15337In some situations, the target running a trace experiment may no
15338longer be available; perhaps it crashed, or the hardware was needed
15339for a different activity. To handle these cases, you can arrange to
15340dump the trace data into a file, and later use that file as a source
15341of trace data, via the @code{target tfile} command.
15342
15343@table @code
15344
15345@kindex tsave
15346@item tsave [ -r ] @var{filename}
d0353e76 15347@itemx tsave [-ctf] @var{dirname}
00bf0b85
SS
15348Save the trace data to @var{filename}. By default, this command
15349assumes that @var{filename} refers to the host filesystem, so if
15350necessary @value{GDBN} will copy raw trace data up from the target and
15351then save it. If the target supports it, you can also supply the
15352optional argument @code{-r} (``remote'') to direct the target to save
15353the data directly into @var{filename} in its own filesystem, which may be
15354more efficient if the trace buffer is very large. (Note, however, that
15355@code{target tfile} can only read from files accessible to the host.)
d0353e76 15356By default, this command will save trace frame in tfile format.
be06ba8c 15357You can supply the optional argument @code{-ctf} to save data in CTF
d0353e76
YQ
15358format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
15359that can be shared by multiple debugging and tracing tools. Please go to
15360@indicateurl{http://www.efficios.com/ctf} to get more information.
00bf0b85
SS
15361
15362@kindex target tfile
15363@kindex tfile
393fd4c3
YQ
15364@kindex target ctf
15365@kindex ctf
00bf0b85 15366@item target tfile @var{filename}
393fd4c3
YQ
15367@itemx target ctf @var{dirname}
15368Use the file named @var{filename} or directory named @var{dirname} as
15369a source of trace data. Commands that examine data work as they do with
15370a live target, but it is not possible to run any new trace experiments.
15371@code{tstatus} will report the state of the trace run at the moment
15372the data was saved, as well as the current trace frame you are examining.
697aa1b7 15373Both @var{filename} and @var{dirname} must be on a filesystem accessible to
393fd4c3
YQ
15374the host.
15375
15376@smallexample
15377(@value{GDBP}) target ctf ctf.ctf
15378(@value{GDBP}) tfind
15379Found trace frame 0, tracepoint 2
1538039 ++a; /* set tracepoint 1 here */
15381(@value{GDBP}) tdump
15382Data collected at tracepoint 2, trace frame 0:
15383i = 0
15384a = 0
15385b = 1 '\001'
15386c = @{"123", "456", "789", "123", "456", "789"@}
15387d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
15388(@value{GDBP}) p b
15389$1 = 1
15390@end smallexample
00bf0b85
SS
15391
15392@end table
15393
df0cd8c5
JB
15394@node Overlays
15395@chapter Debugging Programs That Use Overlays
15396@cindex overlays
15397
15398If your program is too large to fit completely in your target system's
15399memory, you can sometimes use @dfn{overlays} to work around this
15400problem. @value{GDBN} provides some support for debugging programs that
15401use overlays.
15402
15403@menu
15404* How Overlays Work:: A general explanation of overlays.
15405* Overlay Commands:: Managing overlays in @value{GDBN}.
15406* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
15407 mapped by asking the inferior.
15408* Overlay Sample Program:: A sample program using overlays.
15409@end menu
15410
15411@node How Overlays Work
15412@section How Overlays Work
15413@cindex mapped overlays
15414@cindex unmapped overlays
15415@cindex load address, overlay's
15416@cindex mapped address
15417@cindex overlay area
15418
15419Suppose you have a computer whose instruction address space is only 64
15420kilobytes long, but which has much more memory which can be accessed by
15421other means: special instructions, segment registers, or memory
15422management hardware, for example. Suppose further that you want to
15423adapt a program which is larger than 64 kilobytes to run on this system.
15424
15425One solution is to identify modules of your program which are relatively
15426independent, and need not call each other directly; call these modules
15427@dfn{overlays}. Separate the overlays from the main program, and place
15428their machine code in the larger memory. Place your main program in
15429instruction memory, but leave at least enough space there to hold the
15430largest overlay as well.
15431
15432Now, to call a function located in an overlay, you must first copy that
15433overlay's machine code from the large memory into the space set aside
15434for it in the instruction memory, and then jump to its entry point
15435there.
15436
c928edc0
AC
15437@c NB: In the below the mapped area's size is greater or equal to the
15438@c size of all overlays. This is intentional to remind the developer
15439@c that overlays don't necessarily need to be the same size.
15440
474c8240 15441@smallexample
df0cd8c5 15442@group
c928edc0
AC
15443 Data Instruction Larger
15444Address Space Address Space Address Space
15445+-----------+ +-----------+ +-----------+
15446| | | | | |
15447+-----------+ +-----------+ +-----------+<-- overlay 1
15448| program | | main | .----| overlay 1 | load address
15449| variables | | program | | +-----------+
15450| and heap | | | | | |
15451+-----------+ | | | +-----------+<-- overlay 2
15452| | +-----------+ | | | load address
15453+-----------+ | | | .-| overlay 2 |
15454 | | | | | |
15455 mapped --->+-----------+ | | +-----------+
15456 address | | | | | |
15457 | overlay | <-' | | |
15458 | area | <---' +-----------+<-- overlay 3
15459 | | <---. | | load address
15460 +-----------+ `--| overlay 3 |
15461 | | | |
15462 +-----------+ | |
15463 +-----------+
15464 | |
15465 +-----------+
15466
15467 @anchor{A code overlay}A code overlay
df0cd8c5 15468@end group
474c8240 15469@end smallexample
df0cd8c5 15470
c928edc0
AC
15471The diagram (@pxref{A code overlay}) shows a system with separate data
15472and instruction address spaces. To map an overlay, the program copies
15473its code from the larger address space to the instruction address space.
15474Since the overlays shown here all use the same mapped address, only one
15475may be mapped at a time. For a system with a single address space for
15476data and instructions, the diagram would be similar, except that the
15477program variables and heap would share an address space with the main
15478program and the overlay area.
df0cd8c5
JB
15479
15480An overlay loaded into instruction memory and ready for use is called a
15481@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
15482instruction memory. An overlay not present (or only partially present)
15483in instruction memory is called @dfn{unmapped}; its @dfn{load address}
15484is its address in the larger memory. The mapped address is also called
15485the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
15486called the @dfn{load memory address}, or @dfn{LMA}.
15487
15488Unfortunately, overlays are not a completely transparent way to adapt a
15489program to limited instruction memory. They introduce a new set of
15490global constraints you must keep in mind as you design your program:
15491
15492@itemize @bullet
15493
15494@item
15495Before calling or returning to a function in an overlay, your program
15496must make sure that overlay is actually mapped. Otherwise, the call or
15497return will transfer control to the right address, but in the wrong
15498overlay, and your program will probably crash.
15499
15500@item
15501If the process of mapping an overlay is expensive on your system, you
15502will need to choose your overlays carefully to minimize their effect on
15503your program's performance.
15504
15505@item
15506The executable file you load onto your system must contain each
15507overlay's instructions, appearing at the overlay's load address, not its
15508mapped address. However, each overlay's instructions must be relocated
15509and its symbols defined as if the overlay were at its mapped address.
15510You can use GNU linker scripts to specify different load and relocation
15511addresses for pieces of your program; see @ref{Overlay Description,,,
15512ld.info, Using ld: the GNU linker}.
15513
15514@item
15515The procedure for loading executable files onto your system must be able
15516to load their contents into the larger address space as well as the
15517instruction and data spaces.
15518
15519@end itemize
15520
15521The overlay system described above is rather simple, and could be
15522improved in many ways:
15523
15524@itemize @bullet
15525
15526@item
15527If your system has suitable bank switch registers or memory management
15528hardware, you could use those facilities to make an overlay's load area
15529contents simply appear at their mapped address in instruction space.
15530This would probably be faster than copying the overlay to its mapped
15531area in the usual way.
15532
15533@item
15534If your overlays are small enough, you could set aside more than one
15535overlay area, and have more than one overlay mapped at a time.
15536
15537@item
15538You can use overlays to manage data, as well as instructions. In
15539general, data overlays are even less transparent to your design than
15540code overlays: whereas code overlays only require care when you call or
15541return to functions, data overlays require care every time you access
15542the data. Also, if you change the contents of a data overlay, you
15543must copy its contents back out to its load address before you can copy a
15544different data overlay into the same mapped area.
15545
15546@end itemize
15547
15548
15549@node Overlay Commands
15550@section Overlay Commands
15551
15552To use @value{GDBN}'s overlay support, each overlay in your program must
15553correspond to a separate section of the executable file. The section's
15554virtual memory address and load memory address must be the overlay's
15555mapped and load addresses. Identifying overlays with sections allows
15556@value{GDBN} to determine the appropriate address of a function or
15557variable, depending on whether the overlay is mapped or not.
15558
15559@value{GDBN}'s overlay commands all start with the word @code{overlay};
15560you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
15561
15562@table @code
15563@item overlay off
4644b6e3 15564@kindex overlay
df0cd8c5
JB
15565Disable @value{GDBN}'s overlay support. When overlay support is
15566disabled, @value{GDBN} assumes that all functions and variables are
15567always present at their mapped addresses. By default, @value{GDBN}'s
15568overlay support is disabled.
15569
15570@item overlay manual
df0cd8c5
JB
15571@cindex manual overlay debugging
15572Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
15573relies on you to tell it which overlays are mapped, and which are not,
15574using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
15575commands described below.
15576
15577@item overlay map-overlay @var{overlay}
15578@itemx overlay map @var{overlay}
df0cd8c5
JB
15579@cindex map an overlay
15580Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
15581be the name of the object file section containing the overlay. When an
15582overlay is mapped, @value{GDBN} assumes it can find the overlay's
15583functions and variables at their mapped addresses. @value{GDBN} assumes
15584that any other overlays whose mapped ranges overlap that of
15585@var{overlay} are now unmapped.
15586
15587@item overlay unmap-overlay @var{overlay}
15588@itemx overlay unmap @var{overlay}
df0cd8c5
JB
15589@cindex unmap an overlay
15590Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
15591must be the name of the object file section containing the overlay.
15592When an overlay is unmapped, @value{GDBN} assumes it can find the
15593overlay's functions and variables at their load addresses.
15594
15595@item overlay auto
df0cd8c5
JB
15596Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
15597consults a data structure the overlay manager maintains in the inferior
15598to see which overlays are mapped. For details, see @ref{Automatic
15599Overlay Debugging}.
15600
15601@item overlay load-target
15602@itemx overlay load
df0cd8c5
JB
15603@cindex reloading the overlay table
15604Re-read the overlay table from the inferior. Normally, @value{GDBN}
15605re-reads the table @value{GDBN} automatically each time the inferior
15606stops, so this command should only be necessary if you have changed the
15607overlay mapping yourself using @value{GDBN}. This command is only
15608useful when using automatic overlay debugging.
15609
15610@item overlay list-overlays
15611@itemx overlay list
15612@cindex listing mapped overlays
15613Display a list of the overlays currently mapped, along with their mapped
15614addresses, load addresses, and sizes.
15615
15616@end table
15617
15618Normally, when @value{GDBN} prints a code address, it includes the name
15619of the function the address falls in:
15620
474c8240 15621@smallexample
f7dc1244 15622(@value{GDBP}) print main
df0cd8c5 15623$3 = @{int ()@} 0x11a0 <main>
474c8240 15624@end smallexample
df0cd8c5
JB
15625@noindent
15626When overlay debugging is enabled, @value{GDBN} recognizes code in
15627unmapped overlays, and prints the names of unmapped functions with
15628asterisks around them. For example, if @code{foo} is a function in an
15629unmapped overlay, @value{GDBN} prints it this way:
15630
474c8240 15631@smallexample
f7dc1244 15632(@value{GDBP}) overlay list
df0cd8c5 15633No sections are mapped.
f7dc1244 15634(@value{GDBP}) print foo
df0cd8c5 15635$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 15636@end smallexample
df0cd8c5
JB
15637@noindent
15638When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
15639name normally:
15640
474c8240 15641@smallexample
f7dc1244 15642(@value{GDBP}) overlay list
b383017d 15643Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 15644 mapped at 0x1016 - 0x104a
f7dc1244 15645(@value{GDBP}) print foo
df0cd8c5 15646$6 = @{int (int)@} 0x1016 <foo>
474c8240 15647@end smallexample
df0cd8c5
JB
15648
15649When overlay debugging is enabled, @value{GDBN} can find the correct
15650address for functions and variables in an overlay, whether or not the
15651overlay is mapped. This allows most @value{GDBN} commands, like
15652@code{break} and @code{disassemble}, to work normally, even on unmapped
15653code. However, @value{GDBN}'s breakpoint support has some limitations:
15654
15655@itemize @bullet
15656@item
15657@cindex breakpoints in overlays
15658@cindex overlays, setting breakpoints in
15659You can set breakpoints in functions in unmapped overlays, as long as
15660@value{GDBN} can write to the overlay at its load address.
15661@item
15662@value{GDBN} can not set hardware or simulator-based breakpoints in
15663unmapped overlays. However, if you set a breakpoint at the end of your
15664overlay manager (and tell @value{GDBN} which overlays are now mapped, if
15665you are using manual overlay management), @value{GDBN} will re-set its
15666breakpoints properly.
15667@end itemize
15668
15669
15670@node Automatic Overlay Debugging
15671@section Automatic Overlay Debugging
15672@cindex automatic overlay debugging
15673
15674@value{GDBN} can automatically track which overlays are mapped and which
15675are not, given some simple co-operation from the overlay manager in the
15676inferior. If you enable automatic overlay debugging with the
15677@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
15678looks in the inferior's memory for certain variables describing the
15679current state of the overlays.
15680
15681Here are the variables your overlay manager must define to support
15682@value{GDBN}'s automatic overlay debugging:
15683
15684@table @asis
15685
15686@item @code{_ovly_table}:
15687This variable must be an array of the following structures:
15688
474c8240 15689@smallexample
df0cd8c5
JB
15690struct
15691@{
15692 /* The overlay's mapped address. */
15693 unsigned long vma;
15694
15695 /* The size of the overlay, in bytes. */
15696 unsigned long size;
15697
15698 /* The overlay's load address. */
15699 unsigned long lma;
15700
15701 /* Non-zero if the overlay is currently mapped;
15702 zero otherwise. */
15703 unsigned long mapped;
15704@}
474c8240 15705@end smallexample
df0cd8c5
JB
15706
15707@item @code{_novlys}:
15708This variable must be a four-byte signed integer, holding the total
15709number of elements in @code{_ovly_table}.
15710
15711@end table
15712
15713To decide whether a particular overlay is mapped or not, @value{GDBN}
15714looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
15715@code{lma} members equal the VMA and LMA of the overlay's section in the
15716executable file. When @value{GDBN} finds a matching entry, it consults
15717the entry's @code{mapped} member to determine whether the overlay is
15718currently mapped.
15719
81d46470 15720In addition, your overlay manager may define a function called
def71bfa 15721@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
15722will silently set a breakpoint there. If the overlay manager then
15723calls this function whenever it has changed the overlay table, this
15724will enable @value{GDBN} to accurately keep track of which overlays
15725are in program memory, and update any breakpoints that may be set
b383017d 15726in overlays. This will allow breakpoints to work even if the
81d46470
MS
15727overlays are kept in ROM or other non-writable memory while they
15728are not being executed.
df0cd8c5
JB
15729
15730@node Overlay Sample Program
15731@section Overlay Sample Program
15732@cindex overlay example program
15733
15734When linking a program which uses overlays, you must place the overlays
15735at their load addresses, while relocating them to run at their mapped
15736addresses. To do this, you must write a linker script (@pxref{Overlay
15737Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
15738since linker scripts are specific to a particular host system, target
15739architecture, and target memory layout, this manual cannot provide
15740portable sample code demonstrating @value{GDBN}'s overlay support.
15741
15742However, the @value{GDBN} source distribution does contain an overlaid
15743program, with linker scripts for a few systems, as part of its test
15744suite. The program consists of the following files from
15745@file{gdb/testsuite/gdb.base}:
15746
15747@table @file
15748@item overlays.c
15749The main program file.
15750@item ovlymgr.c
15751A simple overlay manager, used by @file{overlays.c}.
15752@item foo.c
15753@itemx bar.c
15754@itemx baz.c
15755@itemx grbx.c
15756Overlay modules, loaded and used by @file{overlays.c}.
15757@item d10v.ld
15758@itemx m32r.ld
15759Linker scripts for linking the test program on the @code{d10v-elf}
15760and @code{m32r-elf} targets.
15761@end table
15762
15763You can build the test program using the @code{d10v-elf} GCC
15764cross-compiler like this:
15765
474c8240 15766@smallexample
df0cd8c5
JB
15767$ d10v-elf-gcc -g -c overlays.c
15768$ d10v-elf-gcc -g -c ovlymgr.c
15769$ d10v-elf-gcc -g -c foo.c
15770$ d10v-elf-gcc -g -c bar.c
15771$ d10v-elf-gcc -g -c baz.c
15772$ d10v-elf-gcc -g -c grbx.c
15773$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
15774 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 15775@end smallexample
df0cd8c5
JB
15776
15777The build process is identical for any other architecture, except that
15778you must substitute the appropriate compiler and linker script for the
15779target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
15780
15781
6d2ebf8b 15782@node Languages
c906108c
SS
15783@chapter Using @value{GDBN} with Different Languages
15784@cindex languages
15785
c906108c
SS
15786Although programming languages generally have common aspects, they are
15787rarely expressed in the same manner. For instance, in ANSI C,
15788dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
15789Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 15790represented (and displayed) differently. Hex numbers in C appear as
c906108c 15791@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
15792
15793@cindex working language
15794Language-specific information is built into @value{GDBN} for some languages,
15795allowing you to express operations like the above in your program's
15796native language, and allowing @value{GDBN} to output values in a manner
15797consistent with the syntax of your program's native language. The
15798language you use to build expressions is called the @dfn{working
15799language}.
15800
15801@menu
15802* Setting:: Switching between source languages
15803* Show:: Displaying the language
c906108c 15804* Checks:: Type and range checks
79a6e687
BW
15805* Supported Languages:: Supported languages
15806* Unsupported Languages:: Unsupported languages
c906108c
SS
15807@end menu
15808
6d2ebf8b 15809@node Setting
79a6e687 15810@section Switching Between Source Languages
c906108c
SS
15811
15812There are two ways to control the working language---either have @value{GDBN}
15813set it automatically, or select it manually yourself. You can use the
15814@code{set language} command for either purpose. On startup, @value{GDBN}
15815defaults to setting the language automatically. The working language is
15816used to determine how expressions you type are interpreted, how values
15817are printed, etc.
15818
15819In addition to the working language, every source file that
15820@value{GDBN} knows about has its own working language. For some object
15821file formats, the compiler might indicate which language a particular
15822source file is in. However, most of the time @value{GDBN} infers the
15823language from the name of the file. The language of a source file
b37052ae 15824controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 15825show each frame appropriately for its own language. There is no way to
d4f3574e
SS
15826set the language of a source file from within @value{GDBN}, but you can
15827set the language associated with a filename extension. @xref{Show, ,
79a6e687 15828Displaying the Language}.
c906108c
SS
15829
15830This is most commonly a problem when you use a program, such
5d161b24 15831as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
15832another language. In that case, make the
15833program use @code{#line} directives in its C output; that way
15834@value{GDBN} will know the correct language of the source code of the original
15835program, and will display that source code, not the generated C code.
15836
15837@menu
15838* Filenames:: Filename extensions and languages.
15839* Manually:: Setting the working language manually
15840* Automatically:: Having @value{GDBN} infer the source language
15841@end menu
15842
6d2ebf8b 15843@node Filenames
79a6e687 15844@subsection List of Filename Extensions and Languages
c906108c
SS
15845
15846If a source file name ends in one of the following extensions, then
15847@value{GDBN} infers that its language is the one indicated.
15848
15849@table @file
e07c999f
PH
15850@item .ada
15851@itemx .ads
15852@itemx .adb
15853@itemx .a
15854Ada source file.
c906108c
SS
15855
15856@item .c
15857C source file
15858
15859@item .C
15860@itemx .cc
15861@itemx .cp
15862@itemx .cpp
15863@itemx .cxx
15864@itemx .c++
b37052ae 15865C@t{++} source file
c906108c 15866
6aecb9c2
JB
15867@item .d
15868D source file
15869
b37303ee
AF
15870@item .m
15871Objective-C source file
15872
c906108c
SS
15873@item .f
15874@itemx .F
15875Fortran source file
15876
c906108c
SS
15877@item .mod
15878Modula-2 source file
c906108c
SS
15879
15880@item .s
15881@itemx .S
15882Assembler source file. This actually behaves almost like C, but
15883@value{GDBN} does not skip over function prologues when stepping.
15884@end table
15885
15886In addition, you may set the language associated with a filename
79a6e687 15887extension. @xref{Show, , Displaying the Language}.
c906108c 15888
6d2ebf8b 15889@node Manually
79a6e687 15890@subsection Setting the Working Language
c906108c
SS
15891
15892If you allow @value{GDBN} to set the language automatically,
15893expressions are interpreted the same way in your debugging session and
15894your program.
15895
15896@kindex set language
15897If you wish, you may set the language manually. To do this, issue the
15898command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 15899a language, such as
c906108c 15900@code{c} or @code{modula-2}.
c906108c
SS
15901For a list of the supported languages, type @samp{set language}.
15902
c906108c
SS
15903Setting the language manually prevents @value{GDBN} from updating the working
15904language automatically. This can lead to confusion if you try
15905to debug a program when the working language is not the same as the
15906source language, when an expression is acceptable to both
15907languages---but means different things. For instance, if the current
15908source file were written in C, and @value{GDBN} was parsing Modula-2, a
15909command such as:
15910
474c8240 15911@smallexample
c906108c 15912print a = b + c
474c8240 15913@end smallexample
c906108c
SS
15914
15915@noindent
15916might not have the effect you intended. In C, this means to add
15917@code{b} and @code{c} and place the result in @code{a}. The result
15918printed would be the value of @code{a}. In Modula-2, this means to compare
15919@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 15920
6d2ebf8b 15921@node Automatically
79a6e687 15922@subsection Having @value{GDBN} Infer the Source Language
c906108c
SS
15923
15924To have @value{GDBN} set the working language automatically, use
15925@samp{set language local} or @samp{set language auto}. @value{GDBN}
15926then infers the working language. That is, when your program stops in a
15927frame (usually by encountering a breakpoint), @value{GDBN} sets the
15928working language to the language recorded for the function in that
15929frame. If the language for a frame is unknown (that is, if the function
15930or block corresponding to the frame was defined in a source file that
15931does not have a recognized extension), the current working language is
15932not changed, and @value{GDBN} issues a warning.
15933
15934This may not seem necessary for most programs, which are written
15935entirely in one source language. However, program modules and libraries
15936written in one source language can be used by a main program written in
15937a different source language. Using @samp{set language auto} in this
15938case frees you from having to set the working language manually.
15939
6d2ebf8b 15940@node Show
79a6e687 15941@section Displaying the Language
c906108c
SS
15942
15943The following commands help you find out which language is the
15944working language, and also what language source files were written in.
15945
c906108c
SS
15946@table @code
15947@item show language
403cb6b1 15948@anchor{show language}
9c16f35a 15949@kindex show language
c906108c
SS
15950Display the current working language. This is the
15951language you can use with commands such as @code{print} to
15952build and compute expressions that may involve variables in your program.
15953
15954@item info frame
4644b6e3 15955@kindex info frame@r{, show the source language}
5d161b24 15956Display the source language for this frame. This language becomes the
c906108c 15957working language if you use an identifier from this frame.
79a6e687 15958@xref{Frame Info, ,Information about a Frame}, to identify the other
c906108c
SS
15959information listed here.
15960
15961@item info source
4644b6e3 15962@kindex info source@r{, show the source language}
c906108c 15963Display the source language of this source file.
5d161b24 15964@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
15965information listed here.
15966@end table
15967
15968In unusual circumstances, you may have source files with extensions
15969not in the standard list. You can then set the extension associated
15970with a language explicitly:
15971
c906108c 15972@table @code
09d4efe1 15973@item set extension-language @var{ext} @var{language}
9c16f35a 15974@kindex set extension-language
09d4efe1
EZ
15975Tell @value{GDBN} that source files with extension @var{ext} are to be
15976assumed as written in the source language @var{language}.
c906108c
SS
15977
15978@item info extensions
9c16f35a 15979@kindex info extensions
c906108c
SS
15980List all the filename extensions and the associated languages.
15981@end table
15982
6d2ebf8b 15983@node Checks
79a6e687 15984@section Type and Range Checking
c906108c 15985
c906108c
SS
15986Some languages are designed to guard you against making seemingly common
15987errors through a series of compile- and run-time checks. These include
a451cb65 15988checking the type of arguments to functions and operators and making
c906108c
SS
15989sure mathematical overflows are caught at run time. Checks such as
15990these help to ensure a program's correctness once it has been compiled
a451cb65 15991by eliminating type mismatches and providing active checks for range
c906108c
SS
15992errors when your program is running.
15993
a451cb65
KS
15994By default @value{GDBN} checks for these errors according to the
15995rules of the current source language. Although @value{GDBN} does not check
15996the statements in your program, it can check expressions entered directly
15997into @value{GDBN} for evaluation via the @code{print} command, for example.
c906108c
SS
15998
15999@menu
16000* Type Checking:: An overview of type checking
16001* Range Checking:: An overview of range checking
16002@end menu
16003
16004@cindex type checking
16005@cindex checks, type
6d2ebf8b 16006@node Type Checking
79a6e687 16007@subsection An Overview of Type Checking
c906108c 16008
a451cb65 16009Some languages, such as C and C@t{++}, are strongly typed, meaning that the
c906108c
SS
16010arguments to operators and functions have to be of the correct type,
16011otherwise an error occurs. These checks prevent type mismatch
16012errors from ever causing any run-time problems. For example,
16013
16014@smallexample
a451cb65
KS
16015int klass::my_method(char *b) @{ return b ? 1 : 2; @}
16016
16017(@value{GDBP}) print obj.my_method (0)
16018$1 = 2
c906108c 16019@exdent but
a451cb65
KS
16020(@value{GDBP}) print obj.my_method (0x1234)
16021Cannot resolve method klass::my_method to any overloaded instance
c906108c
SS
16022@end smallexample
16023
a451cb65
KS
16024The second example fails because in C@t{++} the integer constant
16025@samp{0x1234} is not type-compatible with the pointer parameter type.
c906108c 16026
a451cb65
KS
16027For the expressions you use in @value{GDBN} commands, you can tell
16028@value{GDBN} to not enforce strict type checking or
5d161b24 16029to treat any mismatches as errors and abandon the expression;
a451cb65
KS
16030When type checking is disabled, @value{GDBN} successfully evaluates
16031expressions like the second example above.
c906108c 16032
a451cb65 16033Even if type checking is off, there may be other reasons
5d161b24
DB
16034related to type that prevent @value{GDBN} from evaluating an expression.
16035For instance, @value{GDBN} does not know how to add an @code{int} and
16036a @code{struct foo}. These particular type errors have nothing to do
a451cb65
KS
16037with the language in use and usually arise from expressions which make
16038little sense to evaluate anyway.
c906108c 16039
a451cb65 16040@value{GDBN} provides some additional commands for controlling type checking:
c906108c 16041
c906108c
SS
16042@kindex set check type
16043@kindex show check type
16044@table @code
c906108c
SS
16045@item set check type on
16046@itemx set check type off
a451cb65 16047Set strict type checking on or off. If any type mismatches occur in
d4f3574e 16048evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
16049message and aborts evaluation of the expression.
16050
a451cb65
KS
16051@item show check type
16052Show the current setting of type checking and whether @value{GDBN}
16053is enforcing strict type checking rules.
c906108c
SS
16054@end table
16055
16056@cindex range checking
16057@cindex checks, range
6d2ebf8b 16058@node Range Checking
79a6e687 16059@subsection An Overview of Range Checking
c906108c
SS
16060
16061In some languages (such as Modula-2), it is an error to exceed the
16062bounds of a type; this is enforced with run-time checks. Such range
16063checking is meant to ensure program correctness by making sure
16064computations do not overflow, or indices on an array element access do
16065not exceed the bounds of the array.
16066
16067For expressions you use in @value{GDBN} commands, you can tell
16068@value{GDBN} to treat range errors in one of three ways: ignore them,
16069always treat them as errors and abandon the expression, or issue
16070warnings but evaluate the expression anyway.
16071
16072A range error can result from numerical overflow, from exceeding an
16073array index bound, or when you type a constant that is not a member
16074of any type. Some languages, however, do not treat overflows as an
16075error. In many implementations of C, mathematical overflow causes the
16076result to ``wrap around'' to lower values---for example, if @var{m} is
16077the largest integer value, and @var{s} is the smallest, then
16078
474c8240 16079@smallexample
c906108c 16080@var{m} + 1 @result{} @var{s}
474c8240 16081@end smallexample
c906108c
SS
16082
16083This, too, is specific to individual languages, and in some cases
79a6e687
BW
16084specific to individual compilers or machines. @xref{Supported Languages, ,
16085Supported Languages}, for further details on specific languages.
c906108c
SS
16086
16087@value{GDBN} provides some additional commands for controlling the range checker:
16088
c906108c
SS
16089@kindex set check range
16090@kindex show check range
16091@table @code
16092@item set check range auto
16093Set range checking on or off based on the current working language.
79a6e687 16094@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
16095each language.
16096
16097@item set check range on
16098@itemx set check range off
16099Set range checking on or off, overriding the default setting for the
16100current working language. A warning is issued if the setting does not
c3f6f71d
JM
16101match the language default. If a range error occurs and range checking is on,
16102then a message is printed and evaluation of the expression is aborted.
c906108c
SS
16103
16104@item set check range warn
16105Output messages when the @value{GDBN} range checker detects a range error,
16106but attempt to evaluate the expression anyway. Evaluating the
16107expression may still be impossible for other reasons, such as accessing
16108memory that the process does not own (a typical example from many Unix
16109systems).
16110
85be4f5a 16111@item show check range
c906108c
SS
16112Show the current setting of the range checker, and whether or not it is
16113being set automatically by @value{GDBN}.
16114@end table
c906108c 16115
79a6e687
BW
16116@node Supported Languages
16117@section Supported Languages
c906108c 16118
9c37b5ae 16119@value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
0bdfa368 16120OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
cce74817 16121@c This is false ...
c906108c
SS
16122Some @value{GDBN} features may be used in expressions regardless of the
16123language you use: the @value{GDBN} @code{@@} and @code{::} operators,
16124and the @samp{@{type@}addr} construct (@pxref{Expressions,
16125,Expressions}) can be used with the constructs of any supported
16126language.
16127
16128The following sections detail to what degree each source language is
16129supported by @value{GDBN}. These sections are not meant to be language
16130tutorials or references, but serve only as a reference guide to what the
16131@value{GDBN} expression parser accepts, and what input and output
16132formats should look like for different languages. There are many good
16133books written on each of these languages; please look to these for a
16134language reference or tutorial.
16135
c906108c 16136@menu
b37303ee 16137* C:: C and C@t{++}
6aecb9c2 16138* D:: D
a766d390 16139* Go:: Go
b383017d 16140* Objective-C:: Objective-C
f4b8a18d 16141* OpenCL C:: OpenCL C
09d4efe1 16142* Fortran:: Fortran
9c16f35a 16143* Pascal:: Pascal
0bdfa368 16144* Rust:: Rust
b37303ee 16145* Modula-2:: Modula-2
e07c999f 16146* Ada:: Ada
c906108c
SS
16147@end menu
16148
6d2ebf8b 16149@node C
b37052ae 16150@subsection C and C@t{++}
7a292a7a 16151
b37052ae
EZ
16152@cindex C and C@t{++}
16153@cindex expressions in C or C@t{++}
c906108c 16154
b37052ae 16155Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
16156to both languages. Whenever this is the case, we discuss those languages
16157together.
16158
41afff9a
EZ
16159@cindex C@t{++}
16160@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
16161@cindex @sc{gnu} C@t{++}
16162The C@t{++} debugging facilities are jointly implemented by the C@t{++}
16163compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
16164effectively, you must compile your C@t{++} programs with a supported
16165C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
16166compiler (@code{aCC}).
16167
c906108c 16168@menu
b37052ae
EZ
16169* C Operators:: C and C@t{++} operators
16170* C Constants:: C and C@t{++} constants
79a6e687 16171* C Plus Plus Expressions:: C@t{++} expressions
b37052ae
EZ
16172* C Defaults:: Default settings for C and C@t{++}
16173* C Checks:: C and C@t{++} type and range checks
c906108c 16174* Debugging C:: @value{GDBN} and C
79a6e687 16175* Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
febe4383 16176* Decimal Floating Point:: Numbers in Decimal Floating Point format
c906108c 16177@end menu
c906108c 16178
6d2ebf8b 16179@node C Operators
79a6e687 16180@subsubsection C and C@t{++} Operators
7a292a7a 16181
b37052ae 16182@cindex C and C@t{++} operators
c906108c
SS
16183
16184Operators must be defined on values of specific types. For instance,
16185@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 16186often defined on groups of types.
c906108c 16187
b37052ae 16188For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
16189
16190@itemize @bullet
53a5351d 16191
c906108c 16192@item
c906108c 16193@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 16194specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
16195
16196@item
d4f3574e
SS
16197@emph{Floating-point types} include @code{float}, @code{double}, and
16198@code{long double} (if supported by the target platform).
c906108c
SS
16199
16200@item
53a5351d 16201@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
16202
16203@item
16204@emph{Scalar types} include all of the above.
53a5351d 16205
c906108c
SS
16206@end itemize
16207
16208@noindent
16209The following operators are supported. They are listed here
16210in order of increasing precedence:
16211
16212@table @code
16213@item ,
16214The comma or sequencing operator. Expressions in a comma-separated list
16215are evaluated from left to right, with the result of the entire
16216expression being the last expression evaluated.
16217
16218@item =
16219Assignment. The value of an assignment expression is the value
16220assigned. Defined on scalar types.
16221
16222@item @var{op}=
16223Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
16224and translated to @w{@code{@var{a} = @var{a op b}}}.
697aa1b7 16225@w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
c906108c
SS
16226@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
16227@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
16228
16229@item ?:
16230The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
697aa1b7
EZ
16231of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
16232should be of an integral type.
c906108c
SS
16233
16234@item ||
16235Logical @sc{or}. Defined on integral types.
16236
16237@item &&
16238Logical @sc{and}. Defined on integral types.
16239
16240@item |
16241Bitwise @sc{or}. Defined on integral types.
16242
16243@item ^
16244Bitwise exclusive-@sc{or}. Defined on integral types.
16245
16246@item &
16247Bitwise @sc{and}. Defined on integral types.
16248
16249@item ==@r{, }!=
16250Equality and inequality. Defined on scalar types. The value of these
16251expressions is 0 for false and non-zero for true.
16252
16253@item <@r{, }>@r{, }<=@r{, }>=
16254Less than, greater than, less than or equal, greater than or equal.
16255Defined on scalar types. The value of these expressions is 0 for false
16256and non-zero for true.
16257
16258@item <<@r{, }>>
16259left shift, and right shift. Defined on integral types.
16260
16261@item @@
16262The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16263
16264@item +@r{, }-
16265Addition and subtraction. Defined on integral types, floating-point types and
16266pointer types.
16267
16268@item *@r{, }/@r{, }%
16269Multiplication, division, and modulus. Multiplication and division are
16270defined on integral and floating-point types. Modulus is defined on
16271integral types.
16272
16273@item ++@r{, }--
16274Increment and decrement. When appearing before a variable, the
16275operation is performed before the variable is used in an expression;
16276when appearing after it, the variable's value is used before the
16277operation takes place.
16278
16279@item *
16280Pointer dereferencing. Defined on pointer types. Same precedence as
16281@code{++}.
16282
16283@item &
16284Address operator. Defined on variables. Same precedence as @code{++}.
16285
b37052ae
EZ
16286For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
16287allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
b17828ca 16288to examine the address
b37052ae 16289where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 16290stored.
c906108c
SS
16291
16292@item -
16293Negative. Defined on integral and floating-point types. Same
16294precedence as @code{++}.
16295
16296@item !
16297Logical negation. Defined on integral types. Same precedence as
16298@code{++}.
16299
16300@item ~
16301Bitwise complement operator. Defined on integral types. Same precedence as
16302@code{++}.
16303
16304
16305@item .@r{, }->
16306Structure member, and pointer-to-structure member. For convenience,
16307@value{GDBN} regards the two as equivalent, choosing whether to dereference a
16308pointer based on the stored type information.
16309Defined on @code{struct} and @code{union} data.
16310
c906108c
SS
16311@item .*@r{, }->*
16312Dereferences of pointers to members.
c906108c
SS
16313
16314@item []
16315Array indexing. @code{@var{a}[@var{i}]} is defined as
16316@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
16317
16318@item ()
16319Function parameter list. Same precedence as @code{->}.
16320
c906108c 16321@item ::
b37052ae 16322C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 16323and @code{class} types.
c906108c
SS
16324
16325@item ::
7a292a7a
SS
16326Doubled colons also represent the @value{GDBN} scope operator
16327(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
16328above.
c906108c
SS
16329@end table
16330
c906108c
SS
16331If an operator is redefined in the user code, @value{GDBN} usually
16332attempts to invoke the redefined version instead of using the operator's
16333predefined meaning.
c906108c 16334
6d2ebf8b 16335@node C Constants
79a6e687 16336@subsubsection C and C@t{++} Constants
c906108c 16337
b37052ae 16338@cindex C and C@t{++} constants
c906108c 16339
b37052ae 16340@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 16341following ways:
c906108c
SS
16342
16343@itemize @bullet
16344@item
16345Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
16346specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
16347by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
16348@samp{l}, specifying that the constant should be treated as a
16349@code{long} value.
16350
16351@item
16352Floating point constants are a sequence of digits, followed by a decimal
16353point, followed by a sequence of digits, and optionally followed by an
16354exponent. An exponent is of the form:
16355@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
16356sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
16357A floating-point constant may also end with a letter @samp{f} or
16358@samp{F}, specifying that the constant should be treated as being of
16359the @code{float} (as opposed to the default @code{double}) type; or with
16360a letter @samp{l} or @samp{L}, which specifies a @code{long double}
16361constant.
c906108c
SS
16362
16363@item
16364Enumerated constants consist of enumerated identifiers, or their
16365integral equivalents.
16366
16367@item
16368Character constants are a single character surrounded by single quotes
16369(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 16370(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
16371be represented by a letter or by @dfn{escape sequences}, which are of
16372the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
16373of the character's ordinal value; or of the form @samp{\@var{x}}, where
16374@samp{@var{x}} is a predefined special character---for example,
16375@samp{\n} for newline.
16376
e0f8f636
TT
16377Wide character constants can be written by prefixing a character
16378constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
16379form of @samp{x}. The target wide character set is used when
16380computing the value of this constant (@pxref{Character Sets}).
16381
c906108c 16382@item
96a2c332
SS
16383String constants are a sequence of character constants surrounded by
16384double quotes (@code{"}). Any valid character constant (as described
16385above) may appear. Double quotes within the string must be preceded by
16386a backslash, so for instance @samp{"a\"b'c"} is a string of five
16387characters.
c906108c 16388
e0f8f636
TT
16389Wide string constants can be written by prefixing a string constant
16390with @samp{L}, as in C. The target wide character set is used when
16391computing the value of this constant (@pxref{Character Sets}).
16392
c906108c
SS
16393@item
16394Pointer constants are an integral value. You can also write pointers
16395to constants using the C operator @samp{&}.
16396
16397@item
16398Array constants are comma-separated lists surrounded by braces @samp{@{}
16399and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
16400integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
16401and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
16402@end itemize
16403
79a6e687
BW
16404@node C Plus Plus Expressions
16405@subsubsection C@t{++} Expressions
b37052ae
EZ
16406
16407@cindex expressions in C@t{++}
16408@value{GDBN} expression handling can interpret most C@t{++} expressions.
16409
0179ffac
DC
16410@cindex debugging C@t{++} programs
16411@cindex C@t{++} compilers
16412@cindex debug formats and C@t{++}
16413@cindex @value{NGCC} and C@t{++}
c906108c 16414@quotation
e0f8f636
TT
16415@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
16416the proper compiler and the proper debug format. Currently,
16417@value{GDBN} works best when debugging C@t{++} code that is compiled
16418with the most recent version of @value{NGCC} possible. The DWARF
16419debugging format is preferred; @value{NGCC} defaults to this on most
16420popular platforms. Other compilers and/or debug formats are likely to
16421work badly or not at all when using @value{GDBN} to debug C@t{++}
16422code. @xref{Compilation}.
c906108c 16423@end quotation
c906108c
SS
16424
16425@enumerate
16426
16427@cindex member functions
16428@item
16429Member function calls are allowed; you can use expressions like
16430
474c8240 16431@smallexample
c906108c 16432count = aml->GetOriginal(x, y)
474c8240 16433@end smallexample
c906108c 16434
41afff9a 16435@vindex this@r{, inside C@t{++} member functions}
b37052ae 16436@cindex namespace in C@t{++}
c906108c
SS
16437@item
16438While a member function is active (in the selected stack frame), your
16439expressions have the same namespace available as the member function;
16440that is, @value{GDBN} allows implicit references to the class instance
e0f8f636
TT
16441pointer @code{this} following the same rules as C@t{++}. @code{using}
16442declarations in the current scope are also respected by @value{GDBN}.
c906108c 16443
c906108c 16444@cindex call overloaded functions
d4f3574e 16445@cindex overloaded functions, calling
b37052ae 16446@cindex type conversions in C@t{++}
c906108c
SS
16447@item
16448You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 16449call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
16450perform overload resolution involving user-defined type conversions,
16451calls to constructors, or instantiations of templates that do not exist
16452in the program. It also cannot handle ellipsis argument lists or
16453default arguments.
16454
16455It does perform integral conversions and promotions, floating-point
16456promotions, arithmetic conversions, pointer conversions, conversions of
16457class objects to base classes, and standard conversions such as those of
16458functions or arrays to pointers; it requires an exact match on the
16459number of function arguments.
16460
16461Overload resolution is always performed, unless you have specified
79a6e687
BW
16462@code{set overload-resolution off}. @xref{Debugging C Plus Plus,
16463,@value{GDBN} Features for C@t{++}}.
c906108c 16464
d4f3574e 16465You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
16466explicit function signature to call an overloaded function, as in
16467@smallexample
16468p 'foo(char,int)'('x', 13)
16469@end smallexample
d4f3574e 16470
c906108c 16471The @value{GDBN} command-completion facility can simplify this;
79a6e687 16472see @ref{Completion, ,Command Completion}.
c906108c 16473
c906108c
SS
16474@cindex reference declarations
16475@item
c0f55cc6
AV
16476@value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
16477references; you can use them in expressions just as you do in C@t{++}
16478source---they are automatically dereferenced.
c906108c
SS
16479
16480In the parameter list shown when @value{GDBN} displays a frame, the values of
16481reference variables are not displayed (unlike other variables); this
16482avoids clutter, since references are often used for large structures.
16483The @emph{address} of a reference variable is always shown, unless
16484you have specified @samp{set print address off}.
16485
16486@item
b37052ae 16487@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
16488expressions can use it just as expressions in your program do. Since
16489one scope may be defined in another, you can use @code{::} repeatedly if
16490necessary, for example in an expression like
16491@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 16492resolving name scope by reference to source files, in both C and C@t{++}
79a6e687 16493debugging (@pxref{Variables, ,Program Variables}).
c906108c 16494
e0f8f636
TT
16495@item
16496@value{GDBN} performs argument-dependent lookup, following the C@t{++}
16497specification.
16498@end enumerate
c906108c 16499
6d2ebf8b 16500@node C Defaults
79a6e687 16501@subsubsection C and C@t{++} Defaults
7a292a7a 16502
b37052ae 16503@cindex C and C@t{++} defaults
c906108c 16504
a451cb65
KS
16505If you allow @value{GDBN} to set range checking automatically, it
16506defaults to @code{off} whenever the working language changes to
b37052ae 16507C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 16508selects the working language.
c906108c
SS
16509
16510If you allow @value{GDBN} to set the language automatically, it
16511recognizes source files whose names end with @file{.c}, @file{.C}, or
16512@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 16513these files, it sets the working language to C or C@t{++}.
79a6e687 16514@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
c906108c
SS
16515for further details.
16516
6d2ebf8b 16517@node C Checks
79a6e687 16518@subsubsection C and C@t{++} Type and Range Checks
7a292a7a 16519
b37052ae 16520@cindex C and C@t{++} checks
c906108c 16521
a451cb65
KS
16522By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
16523checking is used. However, if you turn type checking off, @value{GDBN}
16524will allow certain non-standard conversions, such as promoting integer
16525constants to pointers.
c906108c
SS
16526
16527Range checking, if turned on, is done on mathematical operations. Array
16528indices are not checked, since they are often used to index a pointer
16529that is not itself an array.
c906108c 16530
6d2ebf8b 16531@node Debugging C
c906108c 16532@subsubsection @value{GDBN} and C
c906108c
SS
16533
16534The @code{set print union} and @code{show print union} commands apply to
16535the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
16536inside a @code{struct} or @code{class} is also printed. Otherwise, it
16537appears as @samp{@{...@}}.
c906108c
SS
16538
16539The @code{@@} operator aids in the debugging of dynamic arrays, formed
16540with pointers and a memory allocation function. @xref{Expressions,
16541,Expressions}.
16542
79a6e687
BW
16543@node Debugging C Plus Plus
16544@subsubsection @value{GDBN} Features for C@t{++}
c906108c 16545
b37052ae 16546@cindex commands for C@t{++}
7a292a7a 16547
b37052ae
EZ
16548Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
16549designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
16550
16551@table @code
16552@cindex break in overloaded functions
16553@item @r{breakpoint menus}
16554When you want a breakpoint in a function whose name is overloaded,
6ba66d6a
JB
16555@value{GDBN} has the capability to display a menu of possible breakpoint
16556locations to help you specify which function definition you want.
16557@xref{Ambiguous Expressions,,Ambiguous Expressions}.
c906108c 16558
b37052ae 16559@cindex overloading in C@t{++}
c906108c
SS
16560@item rbreak @var{regex}
16561Setting breakpoints using regular expressions is helpful for setting
16562breakpoints on overloaded functions that are not members of any special
16563classes.
79a6e687 16564@xref{Set Breaks, ,Setting Breakpoints}.
c906108c 16565
b37052ae 16566@cindex C@t{++} exception handling
c906108c 16567@item catch throw
591f19e8 16568@itemx catch rethrow
c906108c 16569@itemx catch catch
b37052ae 16570Debug C@t{++} exception handling using these commands. @xref{Set
79a6e687 16571Catchpoints, , Setting Catchpoints}.
c906108c
SS
16572
16573@cindex inheritance
16574@item ptype @var{typename}
16575Print inheritance relationships as well as other information for type
16576@var{typename}.
16577@xref{Symbols, ,Examining the Symbol Table}.
16578
c4aeac85
TT
16579@item info vtbl @var{expression}.
16580The @code{info vtbl} command can be used to display the virtual
16581method tables of the object computed by @var{expression}. This shows
16582one entry per virtual table; there may be multiple virtual tables when
16583multiple inheritance is in use.
16584
439250fb
DE
16585@cindex C@t{++} demangling
16586@item demangle @var{name}
16587Demangle @var{name}.
16588@xref{Symbols}, for a more complete description of the @code{demangle} command.
16589
b37052ae 16590@cindex C@t{++} symbol display
c906108c
SS
16591@item set print demangle
16592@itemx show print demangle
16593@itemx set print asm-demangle
16594@itemx show print asm-demangle
b37052ae
EZ
16595Control whether C@t{++} symbols display in their source form, both when
16596displaying code as C@t{++} source and when displaying disassemblies.
79a6e687 16597@xref{Print Settings, ,Print Settings}.
c906108c
SS
16598
16599@item set print object
16600@itemx show print object
16601Choose whether to print derived (actual) or declared types of objects.
79a6e687 16602@xref{Print Settings, ,Print Settings}.
c906108c
SS
16603
16604@item set print vtbl
16605@itemx show print vtbl
16606Control the format for printing virtual function tables.
79a6e687 16607@xref{Print Settings, ,Print Settings}.
c906108c 16608(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 16609ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
16610
16611@kindex set overload-resolution
d4f3574e 16612@cindex overloaded functions, overload resolution
c906108c 16613@item set overload-resolution on
b37052ae 16614Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
16615is on. For overloaded functions, @value{GDBN} evaluates the arguments
16616and searches for a function whose signature matches the argument types,
79a6e687
BW
16617using the standard C@t{++} conversion rules (see @ref{C Plus Plus
16618Expressions, ,C@t{++} Expressions}, for details).
16619If it cannot find a match, it emits a message.
c906108c
SS
16620
16621@item set overload-resolution off
b37052ae 16622Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
16623overloaded functions that are not class member functions, @value{GDBN}
16624chooses the first function of the specified name that it finds in the
16625symbol table, whether or not its arguments are of the correct type. For
16626overloaded functions that are class member functions, @value{GDBN}
16627searches for a function whose signature @emph{exactly} matches the
16628argument types.
c906108c 16629
9c16f35a
EZ
16630@kindex show overload-resolution
16631@item show overload-resolution
16632Show the current setting of overload resolution.
16633
c906108c
SS
16634@item @r{Overloaded symbol names}
16635You can specify a particular definition of an overloaded symbol, using
b37052ae 16636the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
16637@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
16638also use the @value{GDBN} command-line word completion facilities to list the
16639available choices, or to finish the type list for you.
79a6e687 16640@xref{Completion,, Command Completion}, for details on how to do this.
bd69330d
PA
16641
16642@item @r{Breakpoints in functions with ABI tags}
16643
16644The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
16645correspond to changes in the ABI of a type, function, or variable that
16646would not otherwise be reflected in a mangled name. See
16647@url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
16648for more detail.
16649
16650The ABI tags are visible in C@t{++} demangled names. For example, a
16651function that returns a std::string:
16652
16653@smallexample
16654std::string function(int);
16655@end smallexample
16656
16657@noindent
16658when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
16659tag, and @value{GDBN} displays the symbol like this:
16660
16661@smallexample
16662function[abi:cxx11](int)
16663@end smallexample
16664
16665You can set a breakpoint on such functions simply as if they had no
16666tag. For example:
16667
16668@smallexample
16669(gdb) b function(int)
16670Breakpoint 2 at 0x40060d: file main.cc, line 10.
16671(gdb) info breakpoints
16672Num Type Disp Enb Address What
166731 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
16674 at main.cc:10
16675@end smallexample
16676
16677On the rare occasion you need to disambiguate between different ABI
16678tags, you can do so by simply including the ABI tag in the function
16679name, like:
16680
16681@smallexample
16682(@value{GDBP}) b ambiguous[abi:other_tag](int)
16683@end smallexample
c906108c 16684@end table
c906108c 16685
febe4383
TJB
16686@node Decimal Floating Point
16687@subsubsection Decimal Floating Point format
16688@cindex decimal floating point format
16689
16690@value{GDBN} can examine, set and perform computations with numbers in
16691decimal floating point format, which in the C language correspond to the
16692@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
16693specified by the extension to support decimal floating-point arithmetic.
16694
16695There are two encodings in use, depending on the architecture: BID (Binary
16696Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
4ac33720
UW
16697PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
16698configured target.
febe4383
TJB
16699
16700Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
16701to manipulate decimal floating point numbers, it is not possible to convert
16702(using a cast, for example) integers wider than 32-bit to decimal float.
16703
16704In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
16705point computations, error checking in decimal float operations ignores
16706underflow, overflow and divide by zero exceptions.
16707
4acd40f3 16708In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
99e008fe
EZ
16709to inspect @code{_Decimal128} values stored in floating point registers.
16710See @ref{PowerPC,,PowerPC} for more details.
4acd40f3 16711
6aecb9c2
JB
16712@node D
16713@subsection D
16714
16715@cindex D
16716@value{GDBN} can be used to debug programs written in D and compiled with
16717GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
16718specific feature --- dynamic arrays.
16719
a766d390
DE
16720@node Go
16721@subsection Go
16722
16723@cindex Go (programming language)
16724@value{GDBN} can be used to debug programs written in Go and compiled with
16725@file{gccgo} or @file{6g} compilers.
16726
16727Here is a summary of the Go-specific features and restrictions:
16728
16729@table @code
16730@cindex current Go package
16731@item The current Go package
16732The name of the current package does not need to be specified when
16733specifying global variables and functions.
16734
16735For example, given the program:
16736
16737@example
16738package main
16739var myglob = "Shall we?"
16740func main () @{
16741 // ...
16742@}
16743@end example
16744
16745When stopped inside @code{main} either of these work:
16746
16747@example
16748(gdb) p myglob
16749(gdb) p main.myglob
16750@end example
16751
16752@cindex builtin Go types
16753@item Builtin Go types
16754The @code{string} type is recognized by @value{GDBN} and is printed
16755as a string.
16756
16757@cindex builtin Go functions
16758@item Builtin Go functions
16759The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
16760function and handles it internally.
a766d390
DE
16761
16762@cindex restrictions on Go expressions
16763@item Restrictions on Go expressions
16764All Go operators are supported except @code{&^}.
16765The Go @code{_} ``blank identifier'' is not supported.
16766Automatic dereferencing of pointers is not supported.
50f042b9 16767@end table
a766d390 16768
b37303ee
AF
16769@node Objective-C
16770@subsection Objective-C
16771
16772@cindex Objective-C
16773This section provides information about some commands and command
721c2651
EZ
16774options that are useful for debugging Objective-C code. See also
16775@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
16776few more commands specific to Objective-C support.
b37303ee
AF
16777
16778@menu
b383017d
RM
16779* Method Names in Commands::
16780* The Print Command with Objective-C::
b37303ee
AF
16781@end menu
16782
c8f4133a 16783@node Method Names in Commands
b37303ee
AF
16784@subsubsection Method Names in Commands
16785
16786The following commands have been extended to accept Objective-C method
16787names as line specifications:
16788
16789@kindex clear@r{, and Objective-C}
16790@kindex break@r{, and Objective-C}
16791@kindex info line@r{, and Objective-C}
16792@kindex jump@r{, and Objective-C}
16793@kindex list@r{, and Objective-C}
16794@itemize
16795@item @code{clear}
16796@item @code{break}
16797@item @code{info line}
16798@item @code{jump}
16799@item @code{list}
16800@end itemize
16801
16802A fully qualified Objective-C method name is specified as
16803
16804@smallexample
16805-[@var{Class} @var{methodName}]
16806@end smallexample
16807
c552b3bb
JM
16808where the minus sign is used to indicate an instance method and a
16809plus sign (not shown) is used to indicate a class method. The class
16810name @var{Class} and method name @var{methodName} are enclosed in
16811brackets, similar to the way messages are specified in Objective-C
16812source code. For example, to set a breakpoint at the @code{create}
16813instance method of class @code{Fruit} in the program currently being
16814debugged, enter:
b37303ee
AF
16815
16816@smallexample
16817break -[Fruit create]
16818@end smallexample
16819
16820To list ten program lines around the @code{initialize} class method,
16821enter:
16822
16823@smallexample
16824list +[NSText initialize]
16825@end smallexample
16826
c552b3bb
JM
16827In the current version of @value{GDBN}, the plus or minus sign is
16828required. In future versions of @value{GDBN}, the plus or minus
16829sign will be optional, but you can use it to narrow the search. It
16830is also possible to specify just a method name:
b37303ee
AF
16831
16832@smallexample
16833break create
16834@end smallexample
16835
16836You must specify the complete method name, including any colons. If
16837your program's source files contain more than one @code{create} method,
16838you'll be presented with a numbered list of classes that implement that
16839method. Indicate your choice by number, or type @samp{0} to exit if
16840none apply.
16841
16842As another example, to clear a breakpoint established at the
16843@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
16844
16845@smallexample
16846clear -[NSWindow makeKeyAndOrderFront:]
16847@end smallexample
16848
16849@node The Print Command with Objective-C
16850@subsubsection The Print Command With Objective-C
721c2651 16851@cindex Objective-C, print objects
c552b3bb
JM
16852@kindex print-object
16853@kindex po @r{(@code{print-object})}
b37303ee 16854
c552b3bb 16855The print command has also been extended to accept methods. For example:
b37303ee
AF
16856
16857@smallexample
c552b3bb 16858print -[@var{object} hash]
b37303ee
AF
16859@end smallexample
16860
16861@cindex print an Objective-C object description
c552b3bb
JM
16862@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
16863@noindent
16864will tell @value{GDBN} to send the @code{hash} message to @var{object}
16865and print the result. Also, an additional command has been added,
16866@code{print-object} or @code{po} for short, which is meant to print
16867the description of an object. However, this command may only work
16868with certain Objective-C libraries that have a particular hook
16869function, @code{_NSPrintForDebugger}, defined.
b37303ee 16870
f4b8a18d
KW
16871@node OpenCL C
16872@subsection OpenCL C
16873
16874@cindex OpenCL C
16875This section provides information about @value{GDBN}s OpenCL C support.
16876
16877@menu
16878* OpenCL C Datatypes::
16879* OpenCL C Expressions::
16880* OpenCL C Operators::
16881@end menu
16882
16883@node OpenCL C Datatypes
16884@subsubsection OpenCL C Datatypes
16885
16886@cindex OpenCL C Datatypes
16887@value{GDBN} supports the builtin scalar and vector datatypes specified
16888by OpenCL 1.1. In addition the half- and double-precision floating point
16889data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
16890extensions are also known to @value{GDBN}.
16891
16892@node OpenCL C Expressions
16893@subsubsection OpenCL C Expressions
16894
16895@cindex OpenCL C Expressions
16896@value{GDBN} supports accesses to vector components including the access as
16897lvalue where possible. Since OpenCL C is based on C99 most C expressions
16898supported by @value{GDBN} can be used as well.
16899
16900@node OpenCL C Operators
16901@subsubsection OpenCL C Operators
16902
16903@cindex OpenCL C Operators
16904@value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
16905vector data types.
16906
09d4efe1
EZ
16907@node Fortran
16908@subsection Fortran
16909@cindex Fortran-specific support in @value{GDBN}
16910
814e32d7
WZ
16911@value{GDBN} can be used to debug programs written in Fortran, but it
16912currently supports only the features of Fortran 77 language.
16913
16914@cindex trailing underscore, in Fortran symbols
16915Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
16916among them) append an underscore to the names of variables and
16917functions. When you debug programs compiled by those compilers, you
16918will need to refer to variables and functions with a trailing
16919underscore.
16920
16921@menu
16922* Fortran Operators:: Fortran operators and expressions
16923* Fortran Defaults:: Default settings for Fortran
79a6e687 16924* Special Fortran Commands:: Special @value{GDBN} commands for Fortran
814e32d7
WZ
16925@end menu
16926
16927@node Fortran Operators
79a6e687 16928@subsubsection Fortran Operators and Expressions
814e32d7
WZ
16929
16930@cindex Fortran operators and expressions
16931
16932Operators must be defined on values of specific types. For instance,
16933@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 16934arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
16935
16936@table @code
16937@item **
99e008fe 16938The exponentiation operator. It raises the first operand to the power
814e32d7
WZ
16939of the second one.
16940
16941@item :
16942The range operator. Normally used in the form of array(low:high) to
16943represent a section of array.
68837c9d
MD
16944
16945@item %
16946The access component operator. Normally used to access elements in derived
16947types. Also suitable for unions. As unions aren't part of regular Fortran,
16948this can only happen when accessing a register that uses a gdbarch-defined
16949union type.
0a4b0913
AB
16950@item ::
16951The scope operator. Normally used to access variables in modules or
16952to set breakpoints on subroutines nested in modules or in other
16953subroutines (internal subroutines).
814e32d7
WZ
16954@end table
16955
16956@node Fortran Defaults
16957@subsubsection Fortran Defaults
16958
16959@cindex Fortran Defaults
16960
16961Fortran symbols are usually case-insensitive, so @value{GDBN} by
16962default uses case-insensitive matches for Fortran symbols. You can
16963change that with the @samp{set case-insensitive} command, see
16964@ref{Symbols}, for the details.
16965
79a6e687
BW
16966@node Special Fortran Commands
16967@subsubsection Special Fortran Commands
814e32d7
WZ
16968
16969@cindex Special Fortran commands
16970
db2e3e2e
BW
16971@value{GDBN} has some commands to support Fortran-specific features,
16972such as displaying common blocks.
814e32d7 16973
09d4efe1
EZ
16974@table @code
16975@cindex @code{COMMON} blocks, Fortran
16976@kindex info common
16977@item info common @r{[}@var{common-name}@r{]}
16978This command prints the values contained in the Fortran @code{COMMON}
16979block whose name is @var{common-name}. With no argument, the names of
d52fb0e9 16980all @code{COMMON} blocks visible at the current program location are
09d4efe1 16981printed.
a5c641b5
AB
16982@cindex arrays slices (Fortran)
16983@kindex set fortran repack-array-slices
16984@kindex show fortran repack-array-slices
16985@item set fortran repack-array-slices [on|off]
16986@item show fortran repack-array-slices
16987When taking a slice from an array, a Fortran compiler can choose to
16988either produce an array descriptor that describes the slice in place,
16989or it may repack the slice, copying the elements of the slice into a
16990new region of memory.
16991
16992When this setting is on, then @value{GDBN} will also repack array
16993slices in some situations. When this setting is off, then
16994@value{GDBN} will create array descriptors for slices that reference
16995the original data in place.
16996
16997@value{GDBN} will never repack an array slice if the data for the
16998slice is contiguous within the original array.
16999
17000@value{GDBN} will always repack string slices if the data for the
17001slice is non-contiguous within the original string as @value{GDBN}
17002does not support printing non-contiguous strings.
17003
17004The default for this setting is @code{off}.
09d4efe1
EZ
17005@end table
17006
9c16f35a
EZ
17007@node Pascal
17008@subsection Pascal
17009
17010@cindex Pascal support in @value{GDBN}, limitations
17011Debugging Pascal programs which use sets, subranges, file variables, or
17012nested functions does not currently work. @value{GDBN} does not support
17013entering expressions, printing values, or similar features using Pascal
17014syntax.
17015
17016The Pascal-specific command @code{set print pascal_static-members}
17017controls whether static members of Pascal objects are displayed.
17018@xref{Print Settings, pascal_static-members}.
17019
0bdfa368
TT
17020@node Rust
17021@subsection Rust
17022
17023@value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
17024Programming Language}. Type- and value-printing, and expression
17025parsing, are reasonably complete. However, there are a few
17026peculiarities and holes to be aware of.
17027
17028@itemize @bullet
17029@item
17030Linespecs (@pxref{Specify Location}) are never relative to the current
17031crate. Instead, they act as if there were a global namespace of
17032crates, somewhat similar to the way @code{extern crate} behaves.
17033
17034That is, if @value{GDBN} is stopped at a breakpoint in a function in
17035crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
17036to set a breakpoint in a function named @samp{f} in a crate named
17037@samp{B}.
17038
17039As a consequence of this approach, linespecs also cannot refer to
17040items using @samp{self::} or @samp{super::}.
17041
17042@item
17043Because @value{GDBN} implements Rust name-lookup semantics in
17044expressions, it will sometimes prepend the current crate to a name.
17045For example, if @value{GDBN} is stopped at a breakpoint in the crate
17046@samp{K}, then @code{print ::x::y} will try to find the symbol
17047@samp{K::x::y}.
17048
17049However, since it is useful to be able to refer to other crates when
17050debugging, @value{GDBN} provides the @code{extern} extension to
17051circumvent this. To use the extension, just put @code{extern} before
17052a path expression to refer to the otherwise unavailable ``global''
17053scope.
17054
17055In the above example, if you wanted to refer to the symbol @samp{y} in
17056the crate @samp{x}, you would use @code{print extern x::y}.
17057
17058@item
17059The Rust expression evaluator does not support ``statement-like''
17060expressions such as @code{if} or @code{match}, or lambda expressions.
17061
17062@item
17063Tuple expressions are not implemented.
17064
17065@item
17066The Rust expression evaluator does not currently implement the
17067@code{Drop} trait. Objects that may be created by the evaluator will
17068never be destroyed.
17069
17070@item
17071@value{GDBN} does not implement type inference for generics. In order
17072to call generic functions or otherwise refer to generic items, you
17073will have to specify the type parameters manually.
17074
17075@item
17076@value{GDBN} currently uses the C@t{++} demangler for Rust. In most
17077cases this does not cause any problems. However, in an expression
17078context, completing a generic function name will give syntactically
17079invalid results. This happens because Rust requires the @samp{::}
17080operator between the function name and its generic arguments. For
17081example, @value{GDBN} might provide a completion like
17082@code{crate::f<u32>}, where the parser would require
17083@code{crate::f::<u32>}.
17084
17085@item
17086As of this writing, the Rust compiler (version 1.8) has a few holes in
17087the debugging information it generates. These holes prevent certain
17088features from being implemented by @value{GDBN}:
17089@itemize @bullet
17090
17091@item
17092Method calls cannot be made via traits.
17093
0bdfa368
TT
17094@item
17095Operator overloading is not implemented.
17096
17097@item
17098When debugging in a monomorphized function, you cannot use the generic
17099type names.
17100
17101@item
17102The type @code{Self} is not available.
17103
17104@item
17105@code{use} statements are not available, so some names may not be
17106available in the crate.
17107@end itemize
17108@end itemize
17109
09d4efe1 17110@node Modula-2
c906108c 17111@subsection Modula-2
7a292a7a 17112
d4f3574e 17113@cindex Modula-2, @value{GDBN} support
c906108c
SS
17114
17115The extensions made to @value{GDBN} to support Modula-2 only support
17116output from the @sc{gnu} Modula-2 compiler (which is currently being
17117developed). Other Modula-2 compilers are not currently supported, and
17118attempting to debug executables produced by them is most likely
17119to give an error as @value{GDBN} reads in the executable's symbol
17120table.
17121
17122@cindex expressions in Modula-2
17123@menu
17124* M2 Operators:: Built-in operators
17125* Built-In Func/Proc:: Built-in functions and procedures
17126* M2 Constants:: Modula-2 constants
72019c9c 17127* M2 Types:: Modula-2 types
c906108c
SS
17128* M2 Defaults:: Default settings for Modula-2
17129* Deviations:: Deviations from standard Modula-2
17130* M2 Checks:: Modula-2 type and range checks
17131* M2 Scope:: The scope operators @code{::} and @code{.}
17132* GDB/M2:: @value{GDBN} and Modula-2
17133@end menu
17134
6d2ebf8b 17135@node M2 Operators
c906108c
SS
17136@subsubsection Operators
17137@cindex Modula-2 operators
17138
17139Operators must be defined on values of specific types. For instance,
17140@code{+} is defined on numbers, but not on structures. Operators are
17141often defined on groups of types. For the purposes of Modula-2, the
17142following definitions hold:
17143
17144@itemize @bullet
17145
17146@item
17147@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
17148their subranges.
17149
17150@item
17151@emph{Character types} consist of @code{CHAR} and its subranges.
17152
17153@item
17154@emph{Floating-point types} consist of @code{REAL}.
17155
17156@item
17157@emph{Pointer types} consist of anything declared as @code{POINTER TO
17158@var{type}}.
17159
17160@item
17161@emph{Scalar types} consist of all of the above.
17162
17163@item
17164@emph{Set types} consist of @code{SET} and @code{BITSET} types.
17165
17166@item
17167@emph{Boolean types} consist of @code{BOOLEAN}.
17168@end itemize
17169
17170@noindent
17171The following operators are supported, and appear in order of
17172increasing precedence:
17173
17174@table @code
17175@item ,
17176Function argument or array index separator.
17177
17178@item :=
17179Assignment. The value of @var{var} @code{:=} @var{value} is
17180@var{value}.
17181
17182@item <@r{, }>
17183Less than, greater than on integral, floating-point, or enumerated
17184types.
17185
17186@item <=@r{, }>=
96a2c332 17187Less than or equal to, greater than or equal to
c906108c
SS
17188on integral, floating-point and enumerated types, or set inclusion on
17189set types. Same precedence as @code{<}.
17190
17191@item =@r{, }<>@r{, }#
17192Equality and two ways of expressing inequality, valid on scalar types.
17193Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
17194available for inequality, since @code{#} conflicts with the script
17195comment character.
17196
17197@item IN
17198Set membership. Defined on set types and the types of their members.
17199Same precedence as @code{<}.
17200
17201@item OR
17202Boolean disjunction. Defined on boolean types.
17203
17204@item AND@r{, }&
d4f3574e 17205Boolean conjunction. Defined on boolean types.
c906108c
SS
17206
17207@item @@
17208The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
17209
17210@item +@r{, }-
17211Addition and subtraction on integral and floating-point types, or union
17212and difference on set types.
17213
17214@item *
17215Multiplication on integral and floating-point types, or set intersection
17216on set types.
17217
17218@item /
17219Division on floating-point types, or symmetric set difference on set
17220types. Same precedence as @code{*}.
17221
17222@item DIV@r{, }MOD
17223Integer division and remainder. Defined on integral types. Same
17224precedence as @code{*}.
17225
17226@item -
99e008fe 17227Negative. Defined on @code{INTEGER} and @code{REAL} data.
c906108c
SS
17228
17229@item ^
17230Pointer dereferencing. Defined on pointer types.
17231
17232@item NOT
17233Boolean negation. Defined on boolean types. Same precedence as
17234@code{^}.
17235
17236@item .
17237@code{RECORD} field selector. Defined on @code{RECORD} data. Same
17238precedence as @code{^}.
17239
17240@item []
17241Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
17242
17243@item ()
17244Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
17245as @code{^}.
17246
17247@item ::@r{, }.
17248@value{GDBN} and Modula-2 scope operators.
17249@end table
17250
17251@quotation
72019c9c 17252@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
17253treats the use of the operator @code{IN}, or the use of operators
17254@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
17255@code{<=}, and @code{>=} on sets as an error.
17256@end quotation
17257
cb51c4e0 17258
6d2ebf8b 17259@node Built-In Func/Proc
79a6e687 17260@subsubsection Built-in Functions and Procedures
cb51c4e0 17261@cindex Modula-2 built-ins
c906108c
SS
17262
17263Modula-2 also makes available several built-in procedures and functions.
17264In describing these, the following metavariables are used:
17265
17266@table @var
17267
17268@item a
17269represents an @code{ARRAY} variable.
17270
17271@item c
17272represents a @code{CHAR} constant or variable.
17273
17274@item i
17275represents a variable or constant of integral type.
17276
17277@item m
17278represents an identifier that belongs to a set. Generally used in the
17279same function with the metavariable @var{s}. The type of @var{s} should
17280be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
17281
17282@item n
17283represents a variable or constant of integral or floating-point type.
17284
17285@item r
17286represents a variable or constant of floating-point type.
17287
17288@item t
17289represents a type.
17290
17291@item v
17292represents a variable.
17293
17294@item x
17295represents a variable or constant of one of many types. See the
17296explanation of the function for details.
17297@end table
17298
17299All Modula-2 built-in procedures also return a result, described below.
17300
17301@table @code
17302@item ABS(@var{n})
17303Returns the absolute value of @var{n}.
17304
17305@item CAP(@var{c})
17306If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 17307equivalent, otherwise it returns its argument.
c906108c
SS
17308
17309@item CHR(@var{i})
17310Returns the character whose ordinal value is @var{i}.
17311
17312@item DEC(@var{v})
c3f6f71d 17313Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
17314
17315@item DEC(@var{v},@var{i})
17316Decrements the value in the variable @var{v} by @var{i}. Returns the
17317new value.
17318
17319@item EXCL(@var{m},@var{s})
17320Removes the element @var{m} from the set @var{s}. Returns the new
17321set.
17322
17323@item FLOAT(@var{i})
17324Returns the floating point equivalent of the integer @var{i}.
17325
17326@item HIGH(@var{a})
17327Returns the index of the last member of @var{a}.
17328
17329@item INC(@var{v})
c3f6f71d 17330Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
17331
17332@item INC(@var{v},@var{i})
17333Increments the value in the variable @var{v} by @var{i}. Returns the
17334new value.
17335
17336@item INCL(@var{m},@var{s})
17337Adds the element @var{m} to the set @var{s} if it is not already
17338there. Returns the new set.
17339
17340@item MAX(@var{t})
17341Returns the maximum value of the type @var{t}.
17342
17343@item MIN(@var{t})
17344Returns the minimum value of the type @var{t}.
17345
17346@item ODD(@var{i})
17347Returns boolean TRUE if @var{i} is an odd number.
17348
17349@item ORD(@var{x})
17350Returns the ordinal value of its argument. For example, the ordinal
697aa1b7
EZ
17351value of a character is its @sc{ascii} value (on machines supporting
17352the @sc{ascii} character set). The argument @var{x} must be of an
17353ordered type, which include integral, character and enumerated types.
c906108c
SS
17354
17355@item SIZE(@var{x})
697aa1b7
EZ
17356Returns the size of its argument. The argument @var{x} can be a
17357variable or a type.
c906108c
SS
17358
17359@item TRUNC(@var{r})
17360Returns the integral part of @var{r}.
17361
844781a1 17362@item TSIZE(@var{x})
697aa1b7
EZ
17363Returns the size of its argument. The argument @var{x} can be a
17364variable or a type.
844781a1 17365
c906108c
SS
17366@item VAL(@var{t},@var{i})
17367Returns the member of the type @var{t} whose ordinal value is @var{i}.
17368@end table
17369
17370@quotation
17371@emph{Warning:} Sets and their operations are not yet supported, so
17372@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
17373an error.
17374@end quotation
17375
17376@cindex Modula-2 constants
6d2ebf8b 17377@node M2 Constants
c906108c
SS
17378@subsubsection Constants
17379
17380@value{GDBN} allows you to express the constants of Modula-2 in the following
17381ways:
17382
17383@itemize @bullet
17384
17385@item
17386Integer constants are simply a sequence of digits. When used in an
17387expression, a constant is interpreted to be type-compatible with the
17388rest of the expression. Hexadecimal integers are specified by a
17389trailing @samp{H}, and octal integers by a trailing @samp{B}.
17390
17391@item
17392Floating point constants appear as a sequence of digits, followed by a
17393decimal point and another sequence of digits. An optional exponent can
17394then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
17395@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
17396digits of the floating point constant must be valid decimal (base 10)
17397digits.
17398
17399@item
17400Character constants consist of a single character enclosed by a pair of
17401like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 17402also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
17403followed by a @samp{C}.
17404
17405@item
17406String constants consist of a sequence of characters enclosed by a
17407pair of like quotes, either single (@code{'}) or double (@code{"}).
17408Escape sequences in the style of C are also allowed. @xref{C
79a6e687 17409Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
c906108c
SS
17410sequences.
17411
17412@item
17413Enumerated constants consist of an enumerated identifier.
17414
17415@item
17416Boolean constants consist of the identifiers @code{TRUE} and
17417@code{FALSE}.
17418
17419@item
17420Pointer constants consist of integral values only.
17421
17422@item
17423Set constants are not yet supported.
17424@end itemize
17425
72019c9c
GM
17426@node M2 Types
17427@subsubsection Modula-2 Types
17428@cindex Modula-2 types
17429
17430Currently @value{GDBN} can print the following data types in Modula-2
17431syntax: array types, record types, set types, pointer types, procedure
17432types, enumerated types, subrange types and base types. You can also
17433print the contents of variables declared using these type.
17434This section gives a number of simple source code examples together with
17435sample @value{GDBN} sessions.
17436
17437The first example contains the following section of code:
17438
17439@smallexample
17440VAR
17441 s: SET OF CHAR ;
17442 r: [20..40] ;
17443@end smallexample
17444
17445@noindent
17446and you can request @value{GDBN} to interrogate the type and value of
17447@code{r} and @code{s}.
17448
17449@smallexample
17450(@value{GDBP}) print s
17451@{'A'..'C', 'Z'@}
17452(@value{GDBP}) ptype s
17453SET OF CHAR
17454(@value{GDBP}) print r
1745521
17456(@value{GDBP}) ptype r
17457[20..40]
17458@end smallexample
17459
17460@noindent
17461Likewise if your source code declares @code{s} as:
17462
17463@smallexample
17464VAR
17465 s: SET ['A'..'Z'] ;
17466@end smallexample
17467
17468@noindent
17469then you may query the type of @code{s} by:
17470
17471@smallexample
17472(@value{GDBP}) ptype s
17473type = SET ['A'..'Z']
17474@end smallexample
17475
17476@noindent
17477Note that at present you cannot interactively manipulate set
17478expressions using the debugger.
17479
17480The following example shows how you might declare an array in Modula-2
17481and how you can interact with @value{GDBN} to print its type and contents:
17482
17483@smallexample
17484VAR
17485 s: ARRAY [-10..10] OF CHAR ;
17486@end smallexample
17487
17488@smallexample
17489(@value{GDBP}) ptype s
17490ARRAY [-10..10] OF CHAR
17491@end smallexample
17492
17493Note that the array handling is not yet complete and although the type
17494is printed correctly, expression handling still assumes that all
17495arrays have a lower bound of zero and not @code{-10} as in the example
844781a1 17496above.
72019c9c
GM
17497
17498Here are some more type related Modula-2 examples:
17499
17500@smallexample
17501TYPE
17502 colour = (blue, red, yellow, green) ;
17503 t = [blue..yellow] ;
17504VAR
17505 s: t ;
17506BEGIN
17507 s := blue ;
17508@end smallexample
17509
17510@noindent
17511The @value{GDBN} interaction shows how you can query the data type
17512and value of a variable.
17513
17514@smallexample
17515(@value{GDBP}) print s
17516$1 = blue
17517(@value{GDBP}) ptype t
17518type = [blue..yellow]
17519@end smallexample
17520
17521@noindent
17522In this example a Modula-2 array is declared and its contents
17523displayed. Observe that the contents are written in the same way as
17524their @code{C} counterparts.
17525
17526@smallexample
17527VAR
17528 s: ARRAY [1..5] OF CARDINAL ;
17529BEGIN
17530 s[1] := 1 ;
17531@end smallexample
17532
17533@smallexample
17534(@value{GDBP}) print s
17535$1 = @{1, 0, 0, 0, 0@}
17536(@value{GDBP}) ptype s
17537type = ARRAY [1..5] OF CARDINAL
17538@end smallexample
17539
17540The Modula-2 language interface to @value{GDBN} also understands
17541pointer types as shown in this example:
17542
17543@smallexample
17544VAR
17545 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
17546BEGIN
17547 NEW(s) ;
17548 s^[1] := 1 ;
17549@end smallexample
17550
17551@noindent
17552and you can request that @value{GDBN} describes the type of @code{s}.
17553
17554@smallexample
17555(@value{GDBP}) ptype s
17556type = POINTER TO ARRAY [1..5] OF CARDINAL
17557@end smallexample
17558
17559@value{GDBN} handles compound types as we can see in this example.
17560Here we combine array types, record types, pointer types and subrange
17561types:
17562
17563@smallexample
17564TYPE
17565 foo = RECORD
17566 f1: CARDINAL ;
17567 f2: CHAR ;
17568 f3: myarray ;
17569 END ;
17570
17571 myarray = ARRAY myrange OF CARDINAL ;
17572 myrange = [-2..2] ;
17573VAR
17574 s: POINTER TO ARRAY myrange OF foo ;
17575@end smallexample
17576
17577@noindent
17578and you can ask @value{GDBN} to describe the type of @code{s} as shown
17579below.
17580
17581@smallexample
17582(@value{GDBP}) ptype s
17583type = POINTER TO ARRAY [-2..2] OF foo = RECORD
17584 f1 : CARDINAL;
17585 f2 : CHAR;
17586 f3 : ARRAY [-2..2] OF CARDINAL;
17587END
17588@end smallexample
17589
6d2ebf8b 17590@node M2 Defaults
79a6e687 17591@subsubsection Modula-2 Defaults
c906108c
SS
17592@cindex Modula-2 defaults
17593
17594If type and range checking are set automatically by @value{GDBN}, they
17595both default to @code{on} whenever the working language changes to
d4f3574e 17596Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
17597selected the working language.
17598
17599If you allow @value{GDBN} to set the language automatically, then entering
17600code compiled from a file whose name ends with @file{.mod} sets the
79a6e687
BW
17601working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
17602Infer the Source Language}, for further details.
c906108c 17603
6d2ebf8b 17604@node Deviations
79a6e687 17605@subsubsection Deviations from Standard Modula-2
c906108c
SS
17606@cindex Modula-2, deviations from
17607
17608A few changes have been made to make Modula-2 programs easier to debug.
17609This is done primarily via loosening its type strictness:
17610
17611@itemize @bullet
17612@item
17613Unlike in standard Modula-2, pointer constants can be formed by
17614integers. This allows you to modify pointer variables during
17615debugging. (In standard Modula-2, the actual address contained in a
17616pointer variable is hidden from you; it can only be modified
17617through direct assignment to another pointer variable or expression that
17618returned a pointer.)
17619
17620@item
17621C escape sequences can be used in strings and characters to represent
17622non-printable characters. @value{GDBN} prints out strings with these
17623escape sequences embedded. Single non-printable characters are
17624printed using the @samp{CHR(@var{nnn})} format.
17625
17626@item
17627The assignment operator (@code{:=}) returns the value of its right-hand
17628argument.
17629
17630@item
17631All built-in procedures both modify @emph{and} return their argument.
17632@end itemize
17633
6d2ebf8b 17634@node M2 Checks
79a6e687 17635@subsubsection Modula-2 Type and Range Checks
c906108c
SS
17636@cindex Modula-2 checks
17637
17638@quotation
17639@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
17640range checking.
17641@end quotation
17642@c FIXME remove warning when type/range checks added
17643
17644@value{GDBN} considers two Modula-2 variables type equivalent if:
17645
17646@itemize @bullet
17647@item
17648They are of types that have been declared equivalent via a @code{TYPE
17649@var{t1} = @var{t2}} statement
17650
17651@item
17652They have been declared on the same line. (Note: This is true of the
17653@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
17654@end itemize
17655
17656As long as type checking is enabled, any attempt to combine variables
17657whose types are not equivalent is an error.
17658
17659Range checking is done on all mathematical operations, assignment, array
17660index bounds, and all built-in functions and procedures.
17661
6d2ebf8b 17662@node M2 Scope
79a6e687 17663@subsubsection The Scope Operators @code{::} and @code{.}
c906108c 17664@cindex scope
41afff9a 17665@cindex @code{.}, Modula-2 scope operator
c906108c
SS
17666@cindex colon, doubled as scope operator
17667@ifinfo
41afff9a 17668@vindex colon-colon@r{, in Modula-2}
c906108c
SS
17669@c Info cannot handle :: but TeX can.
17670@end ifinfo
a67ec3f4 17671@ifnotinfo
41afff9a 17672@vindex ::@r{, in Modula-2}
a67ec3f4 17673@end ifnotinfo
c906108c
SS
17674
17675There are a few subtle differences between the Modula-2 scope operator
17676(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
17677similar syntax:
17678
474c8240 17679@smallexample
c906108c
SS
17680
17681@var{module} . @var{id}
17682@var{scope} :: @var{id}
474c8240 17683@end smallexample
c906108c
SS
17684
17685@noindent
17686where @var{scope} is the name of a module or a procedure,
17687@var{module} the name of a module, and @var{id} is any declared
17688identifier within your program, except another module.
17689
17690Using the @code{::} operator makes @value{GDBN} search the scope
17691specified by @var{scope} for the identifier @var{id}. If it is not
17692found in the specified scope, then @value{GDBN} searches all scopes
17693enclosing the one specified by @var{scope}.
17694
17695Using the @code{.} operator makes @value{GDBN} search the current scope for
17696the identifier specified by @var{id} that was imported from the
17697definition module specified by @var{module}. With this operator, it is
17698an error if the identifier @var{id} was not imported from definition
17699module @var{module}, or if @var{id} is not an identifier in
17700@var{module}.
17701
6d2ebf8b 17702@node GDB/M2
c906108c
SS
17703@subsubsection @value{GDBN} and Modula-2
17704
17705Some @value{GDBN} commands have little use when debugging Modula-2 programs.
17706Five subcommands of @code{set print} and @code{show print} apply
b37052ae 17707specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 17708@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 17709apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
17710analogue in Modula-2.
17711
17712The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 17713with any language, is not useful with Modula-2. Its
c906108c 17714intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 17715created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 17716address can be specified by an integral constant, the construct
d4f3574e 17717@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
17718
17719@cindex @code{#} in Modula-2
17720In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
17721interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 17722
e07c999f
PH
17723@node Ada
17724@subsection Ada
17725@cindex Ada
17726
17727The extensions made to @value{GDBN} for Ada only support
17728output from the @sc{gnu} Ada (GNAT) compiler.
17729Other Ada compilers are not currently supported, and
17730attempting to debug executables produced by them is most likely
17731to be difficult.
17732
17733
17734@cindex expressions in Ada
17735@menu
17736* Ada Mode Intro:: General remarks on the Ada syntax
17737 and semantics supported by Ada mode
17738 in @value{GDBN}.
17739* Omissions from Ada:: Restrictions on the Ada expression syntax.
17740* Additions to Ada:: Extensions of the Ada expression syntax.
3685b09f
PMR
17741* Overloading support for Ada:: Support for expressions involving overloaded
17742 subprograms.
e07c999f 17743* Stopping Before Main Program:: Debugging the program during elaboration.
58d06528 17744* Ada Exceptions:: Ada Exceptions
20924a55
JB
17745* Ada Tasks:: Listing and setting breakpoints in tasks.
17746* Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
6e1bb179
JB
17747* Ravenscar Profile:: Tasking Support when using the Ravenscar
17748 Profile
3fcded8f 17749* Ada Settings:: New settable GDB parameters for Ada.
e07c999f
PH
17750* Ada Glitches:: Known peculiarities of Ada mode.
17751@end menu
17752
17753@node Ada Mode Intro
17754@subsubsection Introduction
17755@cindex Ada mode, general
17756
17757The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
17758syntax, with some extensions.
17759The philosophy behind the design of this subset is
17760
17761@itemize @bullet
17762@item
17763That @value{GDBN} should provide basic literals and access to operations for
17764arithmetic, dereferencing, field selection, indexing, and subprogram calls,
17765leaving more sophisticated computations to subprograms written into the
17766program (which therefore may be called from @value{GDBN}).
17767
17768@item
17769That type safety and strict adherence to Ada language restrictions
17770are not particularly important to the @value{GDBN} user.
17771
17772@item
17773That brevity is important to the @value{GDBN} user.
17774@end itemize
17775
f3a2dd1a
JB
17776Thus, for brevity, the debugger acts as if all names declared in
17777user-written packages are directly visible, even if they are not visible
17778according to Ada rules, thus making it unnecessary to fully qualify most
17779names with their packages, regardless of context. Where this causes
17780ambiguity, @value{GDBN} asks the user's intent.
e07c999f
PH
17781
17782The debugger will start in Ada mode if it detects an Ada main program.
17783As for other languages, it will enter Ada mode when stopped in a program that
17784was translated from an Ada source file.
17785
17786While in Ada mode, you may use `@t{--}' for comments. This is useful
17787mostly for documenting command files. The standard @value{GDBN} comment
17788(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
17789middle (to allow based literals).
17790
e07c999f
PH
17791@node Omissions from Ada
17792@subsubsection Omissions from Ada
17793@cindex Ada, omissions from
17794
17795Here are the notable omissions from the subset:
17796
17797@itemize @bullet
17798@item
17799Only a subset of the attributes are supported:
17800
17801@itemize @minus
17802@item
17803@t{'First}, @t{'Last}, and @t{'Length}
17804 on array objects (not on types and subtypes).
17805
17806@item
17807@t{'Min} and @t{'Max}.
17808
17809@item
17810@t{'Pos} and @t{'Val}.
17811
17812@item
17813@t{'Tag}.
17814
17815@item
17816@t{'Range} on array objects (not subtypes), but only as the right
17817operand of the membership (@code{in}) operator.
17818
17819@item
17820@t{'Access}, @t{'Unchecked_Access}, and
17821@t{'Unrestricted_Access} (a GNAT extension).
17822
17823@item
17824@t{'Address}.
17825@end itemize
17826
17827@item
17828The names in
17829@code{Characters.Latin_1} are not available and
17830concatenation is not implemented. Thus, escape characters in strings are
17831not currently available.
17832
17833@item
17834Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
17835equality of representations. They will generally work correctly
17836for strings and arrays whose elements have integer or enumeration types.
17837They may not work correctly for arrays whose element
17838types have user-defined equality, for arrays of real values
17839(in particular, IEEE-conformant floating point, because of negative
17840zeroes and NaNs), and for arrays whose elements contain unused bits with
17841indeterminate values.
17842
17843@item
17844The other component-by-component array operations (@code{and}, @code{or},
17845@code{xor}, @code{not}, and relational tests other than equality)
17846are not implemented.
17847
17848@item
860701dc
PH
17849@cindex array aggregates (Ada)
17850@cindex record aggregates (Ada)
17851@cindex aggregates (Ada)
17852There is limited support for array and record aggregates. They are
17853permitted only on the right sides of assignments, as in these examples:
17854
17855@smallexample
077e0a52
JB
17856(@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
17857(@value{GDBP}) set An_Array := (1, others => 0)
17858(@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
17859(@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
17860(@value{GDBP}) set A_Record := (1, "Peter", True);
17861(@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
860701dc
PH
17862@end smallexample
17863
17864Changing a
17865discriminant's value by assigning an aggregate has an
17866undefined effect if that discriminant is used within the record.
17867However, you can first modify discriminants by directly assigning to
17868them (which normally would not be allowed in Ada), and then performing an
17869aggregate assignment. For example, given a variable @code{A_Rec}
17870declared to have a type such as:
17871
17872@smallexample
17873type Rec (Len : Small_Integer := 0) is record
17874 Id : Integer;
17875 Vals : IntArray (1 .. Len);
17876end record;
17877@end smallexample
17878
17879you can assign a value with a different size of @code{Vals} with two
17880assignments:
17881
17882@smallexample
077e0a52
JB
17883(@value{GDBP}) set A_Rec.Len := 4
17884(@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
860701dc
PH
17885@end smallexample
17886
17887As this example also illustrates, @value{GDBN} is very loose about the usual
17888rules concerning aggregates. You may leave out some of the
17889components of an array or record aggregate (such as the @code{Len}
17890component in the assignment to @code{A_Rec} above); they will retain their
17891original values upon assignment. You may freely use dynamic values as
17892indices in component associations. You may even use overlapping or
17893redundant component associations, although which component values are
17894assigned in such cases is not defined.
e07c999f
PH
17895
17896@item
17897Calls to dispatching subprograms are not implemented.
17898
17899@item
17900The overloading algorithm is much more limited (i.e., less selective)
ae21e955
BW
17901than that of real Ada. It makes only limited use of the context in
17902which a subexpression appears to resolve its meaning, and it is much
17903looser in its rules for allowing type matches. As a result, some
17904function calls will be ambiguous, and the user will be asked to choose
17905the proper resolution.
e07c999f
PH
17906
17907@item
17908The @code{new} operator is not implemented.
17909
17910@item
17911Entry calls are not implemented.
17912
17913@item
17914Aside from printing, arithmetic operations on the native VAX floating-point
17915formats are not supported.
17916
17917@item
17918It is not possible to slice a packed array.
158c7665
PH
17919
17920@item
17921The names @code{True} and @code{False}, when not part of a qualified name,
17922are interpreted as if implicitly prefixed by @code{Standard}, regardless of
17923context.
17924Should your program
17925redefine these names in a package or procedure (at best a dubious practice),
17926you will have to use fully qualified names to access their new definitions.
e07c999f
PH
17927@end itemize
17928
17929@node Additions to Ada
17930@subsubsection Additions to Ada
17931@cindex Ada, deviations from
17932
17933As it does for other languages, @value{GDBN} makes certain generic
17934extensions to Ada (@pxref{Expressions}):
17935
17936@itemize @bullet
17937@item
ae21e955
BW
17938If the expression @var{E} is a variable residing in memory (typically
17939a local variable or array element) and @var{N} is a positive integer,
17940then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
17941@var{N}-1 adjacent variables following it in memory as an array. In
17942Ada, this operator is generally not necessary, since its prime use is
17943in displaying parts of an array, and slicing will usually do this in
17944Ada. However, there are occasional uses when debugging programs in
17945which certain debugging information has been optimized away.
e07c999f
PH
17946
17947@item
ae21e955
BW
17948@code{@var{B}::@var{var}} means ``the variable named @var{var} that
17949appears in function or file @var{B}.'' When @var{B} is a file name,
17950you must typically surround it in single quotes.
e07c999f
PH
17951
17952@item
17953The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
17954@var{type} that appears at address @var{addr}.''
17955
17956@item
17957A name starting with @samp{$} is a convenience variable
17958(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
17959@end itemize
17960
ae21e955
BW
17961In addition, @value{GDBN} provides a few other shortcuts and outright
17962additions specific to Ada:
e07c999f
PH
17963
17964@itemize @bullet
17965@item
17966The assignment statement is allowed as an expression, returning
17967its right-hand operand as its value. Thus, you may enter
17968
17969@smallexample
077e0a52
JB
17970(@value{GDBP}) set x := y + 3
17971(@value{GDBP}) print A(tmp := y + 1)
e07c999f
PH
17972@end smallexample
17973
17974@item
17975The semicolon is allowed as an ``operator,'' returning as its value
17976the value of its right-hand operand.
17977This allows, for example,
17978complex conditional breaks:
17979
17980@smallexample
077e0a52
JB
17981(@value{GDBP}) break f
17982(@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
e07c999f
PH
17983@end smallexample
17984
17985@item
17986Rather than use catenation and symbolic character names to introduce special
17987characters into strings, one may instead use a special bracket notation,
17988which is also used to print strings. A sequence of characters of the form
17989@samp{["@var{XX}"]} within a string or character literal denotes the
17990(single) character whose numeric encoding is @var{XX} in hexadecimal. The
17991sequence of characters @samp{["""]} also denotes a single quotation mark
17992in strings. For example,
17993@smallexample
17994 "One line.["0a"]Next line.["0a"]"
17995@end smallexample
17996@noindent
ae21e955
BW
17997contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
17998after each period.
e07c999f
PH
17999
18000@item
18001The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
18002@t{'Max} is optional (and is ignored in any case). For example, it is valid
18003to write
18004
18005@smallexample
077e0a52 18006(@value{GDBP}) print 'max(x, y)
e07c999f
PH
18007@end smallexample
18008
18009@item
18010When printing arrays, @value{GDBN} uses positional notation when the
18011array has a lower bound of 1, and uses a modified named notation otherwise.
ae21e955
BW
18012For example, a one-dimensional array of three integers with a lower bound
18013of 3 might print as
e07c999f
PH
18014
18015@smallexample
18016(3 => 10, 17, 1)
18017@end smallexample
18018
18019@noindent
18020That is, in contrast to valid Ada, only the first component has a @code{=>}
18021clause.
18022
18023@item
18024You may abbreviate attributes in expressions with any unique,
18025multi-character subsequence of
18026their names (an exact match gets preference).
18027For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
18028in place of @t{a'length}.
18029
18030@item
18031@cindex quoting Ada internal identifiers
18032Since Ada is case-insensitive, the debugger normally maps identifiers you type
18033to lower case. The GNAT compiler uses upper-case characters for
18034some of its internal identifiers, which are normally of no interest to users.
18035For the rare occasions when you actually have to look at them,
18036enclose them in angle brackets to avoid the lower-case mapping.
18037For example,
18038@smallexample
077e0a52 18039(@value{GDBP}) print <JMPBUF_SAVE>[0]
e07c999f
PH
18040@end smallexample
18041
18042@item
18043Printing an object of class-wide type or dereferencing an
18044access-to-class-wide value will display all the components of the object's
18045specific type (as indicated by its run-time tag). Likewise, component
18046selection on such a value will operate on the specific type of the
18047object.
18048
18049@end itemize
18050
3685b09f
PMR
18051@node Overloading support for Ada
18052@subsubsection Overloading support for Ada
18053@cindex overloading, Ada
18054
18055The debugger supports limited overloading. Given a subprogram call in which
18056the function symbol has multiple definitions, it will use the number of
18057actual parameters and some information about their types to attempt to narrow
18058the set of definitions. It also makes very limited use of context, preferring
18059procedures to functions in the context of the @code{call} command, and
18060functions to procedures elsewhere.
18061
18062If, after narrowing, the set of matching definitions still contains more than
18063one definition, @value{GDBN} will display a menu to query which one it should
18064use, for instance:
18065
18066@smallexample
18067(@value{GDBP}) print f(1)
18068Multiple matches for f
18069[0] cancel
18070[1] foo.f (integer) return boolean at foo.adb:23
18071[2] foo.f (foo.new_integer) return boolean at foo.adb:28
18072>
18073@end smallexample
18074
18075In this case, just select one menu entry either to cancel expression evaluation
18076(type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
18077instance (type the corresponding number and press @key{RET}).
18078
18079Here are a couple of commands to customize @value{GDBN}'s behavior in this
18080case:
18081
18082@table @code
18083
18084@kindex set ada print-signatures
18085@item set ada print-signatures
18086Control whether parameter types and return types are displayed in overloads
18087selection menus. It is @code{on} by default.
18088@xref{Overloading support for Ada}.
18089
18090@kindex show ada print-signatures
18091@item show ada print-signatures
18092Show the current setting for displaying parameter types and return types in
18093overloads selection menu.
18094@xref{Overloading support for Ada}.
18095
18096@end table
18097
e07c999f
PH
18098@node Stopping Before Main Program
18099@subsubsection Stopping at the Very Beginning
18100
18101@cindex breakpointing Ada elaboration code
18102It is sometimes necessary to debug the program during elaboration, and
18103before reaching the main procedure.
18104As defined in the Ada Reference
18105Manual, the elaboration code is invoked from a procedure called
18106@code{adainit}. To run your program up to the beginning of
18107elaboration, simply use the following two commands:
18108@code{tbreak adainit} and @code{run}.
18109
58d06528
JB
18110@node Ada Exceptions
18111@subsubsection Ada Exceptions
18112
18113A command is provided to list all Ada exceptions:
18114
18115@table @code
18116@kindex info exceptions
18117@item info exceptions
18118@itemx info exceptions @var{regexp}
18119The @code{info exceptions} command allows you to list all Ada exceptions
18120defined within the program being debugged, as well as their addresses.
18121With a regular expression, @var{regexp}, as argument, only those exceptions
18122whose names match @var{regexp} are listed.
18123@end table
18124
18125Below is a small example, showing how the command can be used, first
18126without argument, and next with a regular expression passed as an
18127argument.
18128
18129@smallexample
18130(@value{GDBP}) info exceptions
18131All defined Ada exceptions:
18132constraint_error: 0x613da0
18133program_error: 0x613d20
18134storage_error: 0x613ce0
18135tasking_error: 0x613ca0
18136const.aint_global_e: 0x613b00
18137(@value{GDBP}) info exceptions const.aint
18138All Ada exceptions matching regular expression "const.aint":
18139constraint_error: 0x613da0
18140const.aint_global_e: 0x613b00
18141@end smallexample
18142
18143It is also possible to ask @value{GDBN} to stop your program's execution
18144when an exception is raised. For more details, see @ref{Set Catchpoints}.
18145
20924a55
JB
18146@node Ada Tasks
18147@subsubsection Extensions for Ada Tasks
18148@cindex Ada, tasking
18149
18150Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
18151@value{GDBN} provides the following task-related commands:
18152
18153@table @code
18154@kindex info tasks
18155@item info tasks
18156This command shows a list of current Ada tasks, as in the following example:
18157
18158
18159@smallexample
18160@iftex
18161@leftskip=0.5cm
18162@end iftex
18163(@value{GDBP}) info tasks
18164 ID TID P-ID Pri State Name
18165 1 8088000 0 15 Child Activation Wait main_task
18166 2 80a4000 1 15 Accept Statement b
18167 3 809a800 1 15 Child Activation Wait a
32cd1edc 18168* 4 80ae800 3 15 Runnable c
20924a55
JB
18169
18170@end smallexample
18171
18172@noindent
18173In this listing, the asterisk before the last task indicates it to be the
18174task currently being inspected.
18175
18176@table @asis
18177@item ID
18178Represents @value{GDBN}'s internal task number.
18179
18180@item TID
18181The Ada task ID.
18182
18183@item P-ID
18184The parent's task ID (@value{GDBN}'s internal task number).
18185
18186@item Pri
18187The base priority of the task.
18188
18189@item State
18190Current state of the task.
18191
18192@table @code
18193@item Unactivated
18194The task has been created but has not been activated. It cannot be
18195executing.
18196
20924a55
JB
18197@item Runnable
18198The task is not blocked for any reason known to Ada. (It may be waiting
18199for a mutex, though.) It is conceptually "executing" in normal mode.
18200
18201@item Terminated
18202The task is terminated, in the sense of ARM 9.3 (5). Any dependents
18203that were waiting on terminate alternatives have been awakened and have
18204terminated themselves.
18205
18206@item Child Activation Wait
18207The task is waiting for created tasks to complete activation.
18208
18209@item Accept Statement
18210The task is waiting on an accept or selective wait statement.
18211
18212@item Waiting on entry call
18213The task is waiting on an entry call.
18214
18215@item Async Select Wait
18216The task is waiting to start the abortable part of an asynchronous
18217select statement.
18218
18219@item Delay Sleep
18220The task is waiting on a select statement with only a delay
18221alternative open.
18222
18223@item Child Termination Wait
18224The task is sleeping having completed a master within itself, and is
18225waiting for the tasks dependent on that master to become terminated or
18226waiting on a terminate Phase.
18227
18228@item Wait Child in Term Alt
18229The task is sleeping waiting for tasks on terminate alternatives to
18230finish terminating.
18231
18232@item Accepting RV with @var{taskno}
18233The task is accepting a rendez-vous with the task @var{taskno}.
18234@end table
18235
18236@item Name
18237Name of the task in the program.
18238
18239@end table
18240
18241@kindex info task @var{taskno}
18242@item info task @var{taskno}
6b92c0d3 18243This command shows detailed informations on the specified task, as in
20924a55
JB
18244the following example:
18245@smallexample
18246@iftex
18247@leftskip=0.5cm
18248@end iftex
18249(@value{GDBP}) info tasks
18250 ID TID P-ID Pri State Name
18251 1 8077880 0 15 Child Activation Wait main_task
32cd1edc 18252* 2 807c468 1 15 Runnable task_1
20924a55
JB
18253(@value{GDBP}) info task 2
18254Ada Task: 0x807c468
4993045d 18255Name: "task_1"
87f7ab7b
JB
18256Thread: 0
18257LWP: 0x1fac
4993045d 18258Parent: 1 ("main_task")
20924a55
JB
18259Base Priority: 15
18260State: Runnable
18261@end smallexample
18262
18263@item task
18264@kindex task@r{ (Ada)}
18265@cindex current Ada task ID
4993045d 18266This command prints the ID and name of the current task.
20924a55
JB
18267
18268@smallexample
18269@iftex
18270@leftskip=0.5cm
18271@end iftex
18272(@value{GDBP}) info tasks
18273 ID TID P-ID Pri State Name
18274 1 8077870 0 15 Child Activation Wait main_task
4993045d 18275* 2 807c458 1 15 Runnable some_task
20924a55 18276(@value{GDBP}) task
4993045d 18277[Current task is 2 "some_task"]
20924a55
JB
18278@end smallexample
18279
18280@item task @var{taskno}
18281@cindex Ada task switching
5d5658a1 18282This command is like the @code{thread @var{thread-id}}
20924a55
JB
18283command (@pxref{Threads}). It switches the context of debugging
18284from the current task to the given task.
18285
18286@smallexample
18287@iftex
18288@leftskip=0.5cm
18289@end iftex
18290(@value{GDBP}) info tasks
18291 ID TID P-ID Pri State Name
18292 1 8077870 0 15 Child Activation Wait main_task
4993045d 18293* 2 807c458 1 15 Runnable some_task
20924a55 18294(@value{GDBP}) task 1
4993045d 18295[Switching to task 1 "main_task"]
20924a55
JB
18296#0 0x8067726 in pthread_cond_wait ()
18297(@value{GDBP}) bt
18298#0 0x8067726 in pthread_cond_wait ()
18299#1 0x8056714 in system.os_interface.pthread_cond_wait ()
18300#2 0x805cb63 in system.task_primitives.operations.sleep ()
18301#3 0x806153e in system.tasking.stages.activate_tasks ()
18302#4 0x804aacc in un () at un.adb:5
18303@end smallexample
18304
629500fa
KS
18305@item break @var{location} task @var{taskno}
18306@itemx break @var{location} task @var{taskno} if @dots{}
45ac276d
JB
18307@cindex breakpoints and tasks, in Ada
18308@cindex task breakpoints, in Ada
18309@kindex break @dots{} task @var{taskno}@r{ (Ada)}
18310These commands are like the @code{break @dots{} thread @dots{}}
697aa1b7 18311command (@pxref{Thread Stops}). The
629500fa 18312@var{location} argument specifies source lines, as described
45ac276d
JB
18313in @ref{Specify Location}.
18314
18315Use the qualifier @samp{task @var{taskno}} with a breakpoint command
18316to specify that you only want @value{GDBN} to stop the program when a
697aa1b7 18317particular Ada task reaches this breakpoint. The @var{taskno} is one of the
45ac276d
JB
18318numeric task identifiers assigned by @value{GDBN}, shown in the first
18319column of the @samp{info tasks} display.
18320
18321If you do not specify @samp{task @var{taskno}} when you set a
18322breakpoint, the breakpoint applies to @emph{all} tasks of your
18323program.
18324
18325You can use the @code{task} qualifier on conditional breakpoints as
18326well; in this case, place @samp{task @var{taskno}} before the
18327breakpoint condition (before the @code{if}).
18328
18329For example,
18330
18331@smallexample
18332@iftex
18333@leftskip=0.5cm
18334@end iftex
18335(@value{GDBP}) info tasks
18336 ID TID P-ID Pri State Name
18337 1 140022020 0 15 Child Activation Wait main_task
18338 2 140045060 1 15 Accept/Select Wait t2
18339 3 140044840 1 15 Runnable t1
18340* 4 140056040 1 15 Runnable t3
18341(@value{GDBP}) b 15 task 2
18342Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
18343(@value{GDBP}) cont
18344Continuing.
18345task # 1 running
18346task # 2 running
18347
18348Breakpoint 5, test_task_debug () at test_task_debug.adb:15
1834915 flush;
18350(@value{GDBP}) info tasks
18351 ID TID P-ID Pri State Name
18352 1 140022020 0 15 Child Activation Wait main_task
18353* 2 140045060 1 15 Runnable t2
18354 3 140044840 1 15 Runnable t1
18355 4 140056040 1 15 Delay Sleep t3
18356@end smallexample
20924a55
JB
18357@end table
18358
18359@node Ada Tasks and Core Files
18360@subsubsection Tasking Support when Debugging Core Files
18361@cindex Ada tasking and core file debugging
18362
18363When inspecting a core file, as opposed to debugging a live program,
18364tasking support may be limited or even unavailable, depending on
18365the platform being used.
18366For instance, on x86-linux, the list of tasks is available, but task
32a8097b 18367switching is not supported.
20924a55 18368
32a8097b 18369On certain platforms, the debugger needs to perform some
20924a55
JB
18370memory writes in order to provide Ada tasking support. When inspecting
18371a core file, this means that the core file must be opened with read-write
18372privileges, using the command @samp{"set write on"} (@pxref{Patching}).
18373Under these circumstances, you should make a backup copy of the core
18374file before inspecting it with @value{GDBN}.
18375
6e1bb179
JB
18376@node Ravenscar Profile
18377@subsubsection Tasking Support when using the Ravenscar Profile
18378@cindex Ravenscar Profile
18379
18380The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
18381specifically designed for systems with safety-critical real-time
18382requirements.
18383
18384@table @code
18385@kindex set ravenscar task-switching on
18386@cindex task switching with program using Ravenscar Profile
18387@item set ravenscar task-switching on
18388Allows task switching when debugging a program that uses the Ravenscar
18389Profile. This is the default.
18390
18391@kindex set ravenscar task-switching off
18392@item set ravenscar task-switching off
18393Turn off task switching when debugging a program that uses the Ravenscar
18394Profile. This is mostly intended to disable the code that adds support
18395for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
18396the Ravenscar runtime is preventing @value{GDBN} from working properly.
18397To be effective, this command should be run before the program is started.
18398
18399@kindex show ravenscar task-switching
18400@item show ravenscar task-switching
18401Show whether it is possible to switch from task to task in a program
18402using the Ravenscar Profile.
18403
18404@end table
18405
e09eef98
TT
18406@cindex Ravenscar thread
18407When Ravenscar task-switching is enabled, Ravenscar tasks are
18408announced by @value{GDBN} as if they were threads:
18409
18410@smallexample
18411(gdb) continue
18412[New Ravenscar Thread 0x2b8f0]
18413@end smallexample
18414
18415Both Ravenscar tasks and the underlying CPU threads will show up in
18416the output of @code{info threads}:
18417
18418@smallexample
18419(gdb) info threads
18420 Id Target Id Frame
18421 1 Thread 1 (CPU#0 [running]) simple () at simple.adb:10
18422 2 Thread 2 (CPU#1 [running]) 0x0000000000003d34 in __gnat_initialize_cpu_devices ()
18423 3 Thread 3 (CPU#2 [running]) 0x0000000000003d28 in __gnat_initialize_cpu_devices ()
18424 4 Thread 4 (CPU#3 [halted ]) 0x000000000000c6ec in system.task_primitives.operations.idle ()
18425* 5 Ravenscar Thread 0x2b8f0 simple () at simple.adb:10
18426 6 Ravenscar Thread 0x2f150 0x000000000000c6ec in system.task_primitives.operations.idle ()
18427@end smallexample
18428
18429One known limitation of the Ravenscar support in @value{GDBN} is that
18430it isn't currently possible to single-step through the runtime
18431initialization sequence. If you need to debug this code, you should
18432use @code{set ravenscar task-switching off}.
18433
3fcded8f
JB
18434@node Ada Settings
18435@subsubsection Ada Settings
18436@cindex Ada settings
18437
18438@table @code
18439@kindex set varsize-limit
18440@item set varsize-limit @var{size}
18441Prevent @value{GDBN} from attempting to evaluate objects whose size
18442is above the given limit (@var{size}) when those sizes are computed
18443from run-time quantities. This is typically the case when the object
18444has a variable size, such as an array whose bounds are not known at
18445compile time for example. Setting @var{size} to @code{unlimited}
18446removes the size limitation. By default, the limit is about 65KB.
18447
18448The purpose of having such a limit is to prevent @value{GDBN} from
18449trying to grab enormous chunks of virtual memory when asked to evaluate
18450a quantity whose bounds have been corrupted or have not yet been fully
18451initialized. The limit applies to the results of some subexpressions
18452as well as to complete expressions. For example, an expression denoting
18453a simple integer component, such as @code{x.y.z}, may fail if the size of
18454@code{x.y} is variable and exceeds @code{size}. On the other hand,
18455@value{GDBN} is sometimes clever; the expression @code{A(i)}, where
18456@code{A} is an array variable with non-constant size, will generally
18457succeed regardless of the bounds on @code{A}, as long as the component
18458size is less than @var{size}.
18459
18460@kindex show varsize-limit
18461@item show varsize-limit
18462Show the limit on types whose size is determined by run-time quantities.
18463@end table
18464
e07c999f
PH
18465@node Ada Glitches
18466@subsubsection Known Peculiarities of Ada Mode
18467@cindex Ada, problems
18468
18469Besides the omissions listed previously (@pxref{Omissions from Ada}),
18470we know of several problems with and limitations of Ada mode in
18471@value{GDBN},
18472some of which will be fixed with planned future releases of the debugger
18473and the GNU Ada compiler.
18474
18475@itemize @bullet
e07c999f
PH
18476@item
18477Static constants that the compiler chooses not to materialize as objects in
18478storage are invisible to the debugger.
18479
18480@item
18481Named parameter associations in function argument lists are ignored (the
18482argument lists are treated as positional).
18483
18484@item
18485Many useful library packages are currently invisible to the debugger.
18486
18487@item
18488Fixed-point arithmetic, conversions, input, and output is carried out using
18489floating-point arithmetic, and may give results that only approximate those on
18490the host machine.
18491
e07c999f
PH
18492@item
18493The GNAT compiler never generates the prefix @code{Standard} for any of
18494the standard symbols defined by the Ada language. @value{GDBN} knows about
18495this: it will strip the prefix from names when you use it, and will never
18496look for a name you have so qualified among local symbols, nor match against
18497symbols in other packages or subprograms. If you have
18498defined entities anywhere in your program other than parameters and
18499local variables whose simple names match names in @code{Standard},
18500GNAT's lack of qualification here can cause confusion. When this happens,
18501you can usually resolve the confusion
18502by qualifying the problematic names with package
18503@code{Standard} explicitly.
18504@end itemize
18505
95433b34
JB
18506Older versions of the compiler sometimes generate erroneous debugging
18507information, resulting in the debugger incorrectly printing the value
18508of affected entities. In some cases, the debugger is able to work
18509around an issue automatically. In other cases, the debugger is able
18510to work around the issue, but the work-around has to be specifically
18511enabled.
18512
18513@kindex set ada trust-PAD-over-XVS
18514@kindex show ada trust-PAD-over-XVS
18515@table @code
18516
18517@item set ada trust-PAD-over-XVS on
18518Configure GDB to strictly follow the GNAT encoding when computing the
18519value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
18520types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
18521a complete description of the encoding used by the GNAT compiler).
18522This is the default.
18523
18524@item set ada trust-PAD-over-XVS off
18525This is related to the encoding using by the GNAT compiler. If @value{GDBN}
18526sometimes prints the wrong value for certain entities, changing @code{ada
18527trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
18528the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
18529@code{off}, but this incurs a slight performance penalty, so it is
18530recommended to leave this setting to @code{on} unless necessary.
18531
18532@end table
18533
c6044dd1
JB
18534@cindex GNAT descriptive types
18535@cindex GNAT encoding
18536Internally, the debugger also relies on the compiler following a number
18537of conventions known as the @samp{GNAT Encoding}, all documented in
18538@file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
18539how the debugging information should be generated for certain types.
18540In particular, this convention makes use of @dfn{descriptive types},
18541which are artificial types generated purely to help the debugger.
18542
18543These encodings were defined at a time when the debugging information
18544format used was not powerful enough to describe some of the more complex
18545types available in Ada. Since DWARF allows us to express nearly all
18546Ada features, the long-term goal is to slowly replace these descriptive
18547types by their pure DWARF equivalent. To facilitate that transition,
18548a new maintenance option is available to force the debugger to ignore
18549those descriptive types. It allows the user to quickly evaluate how
18550well @value{GDBN} works without them.
18551
18552@table @code
18553
18554@kindex maint ada set ignore-descriptive-types
18555@item maintenance ada set ignore-descriptive-types [on|off]
18556Control whether the debugger should ignore descriptive types.
18557The default is not to ignore descriptives types (@code{off}).
18558
18559@kindex maint ada show ignore-descriptive-types
18560@item maintenance ada show ignore-descriptive-types
18561Show if descriptive types are ignored by @value{GDBN}.
18562
18563@end table
18564
79a6e687
BW
18565@node Unsupported Languages
18566@section Unsupported Languages
4e562065
JB
18567
18568@cindex unsupported languages
18569@cindex minimal language
18570In addition to the other fully-supported programming languages,
18571@value{GDBN} also provides a pseudo-language, called @code{minimal}.
18572It does not represent a real programming language, but provides a set
18573of capabilities close to what the C or assembly languages provide.
18574This should allow most simple operations to be performed while debugging
18575an application that uses a language currently not supported by @value{GDBN}.
18576
18577If the language is set to @code{auto}, @value{GDBN} will automatically
18578select this language if the current frame corresponds to an unsupported
18579language.
18580
6d2ebf8b 18581@node Symbols
c906108c
SS
18582@chapter Examining the Symbol Table
18583
d4f3574e 18584The commands described in this chapter allow you to inquire about the
c906108c
SS
18585symbols (names of variables, functions and types) defined in your
18586program. This information is inherent in the text of your program and
18587does not change as your program executes. @value{GDBN} finds it in your
18588program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
18589(@pxref{File Options, ,Choosing Files}), or by one of the
18590file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
18591
18592@cindex symbol names
18593@cindex names of symbols
18594@cindex quoting names
d044bac8 18595@anchor{quoting names}
c906108c
SS
18596Occasionally, you may need to refer to symbols that contain unusual
18597characters, which @value{GDBN} ordinarily treats as word delimiters. The
18598most frequent case is in referring to static variables in other
79a6e687 18599source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
18600are recorded in object files as debugging symbols, but @value{GDBN} would
18601ordinarily parse a typical file name, like @file{foo.c}, as the three words
18602@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
18603@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
18604
474c8240 18605@smallexample
c906108c 18606p 'foo.c'::x
474c8240 18607@end smallexample
c906108c
SS
18608
18609@noindent
18610looks up the value of @code{x} in the scope of the file @file{foo.c}.
18611
18612@table @code
a8f24a35
EZ
18613@cindex case-insensitive symbol names
18614@cindex case sensitivity in symbol names
18615@kindex set case-sensitive
18616@item set case-sensitive on
18617@itemx set case-sensitive off
18618@itemx set case-sensitive auto
18619Normally, when @value{GDBN} looks up symbols, it matches their names
18620with case sensitivity determined by the current source language.
18621Occasionally, you may wish to control that. The command @code{set
18622case-sensitive} lets you do that by specifying @code{on} for
18623case-sensitive matches or @code{off} for case-insensitive ones. If
18624you specify @code{auto}, case sensitivity is reset to the default
18625suitable for the source language. The default is case-sensitive
18626matches for all languages except for Fortran, for which the default is
18627case-insensitive matches.
18628
9c16f35a
EZ
18629@kindex show case-sensitive
18630@item show case-sensitive
a8f24a35
EZ
18631This command shows the current setting of case sensitivity for symbols
18632lookups.
18633
53342f27
TT
18634@kindex set print type methods
18635@item set print type methods
18636@itemx set print type methods on
18637@itemx set print type methods off
18638Normally, when @value{GDBN} prints a class, it displays any methods
18639declared in that class. You can control this behavior either by
18640passing the appropriate flag to @code{ptype}, or using @command{set
18641print type methods}. Specifying @code{on} will cause @value{GDBN} to
18642display the methods; this is the default. Specifying @code{off} will
18643cause @value{GDBN} to omit the methods.
18644
18645@kindex show print type methods
18646@item show print type methods
18647This command shows the current setting of method display when printing
18648classes.
18649
883fd55a
KS
18650@kindex set print type nested-type-limit
18651@item set print type nested-type-limit @var{limit}
18652@itemx set print type nested-type-limit unlimited
18653Set the limit of displayed nested types that the type printer will
18654show. A @var{limit} of @code{unlimited} or @code{-1} will show all
18655nested definitions. By default, the type printer will not show any nested
18656types defined in classes.
18657
18658@kindex show print type nested-type-limit
18659@item show print type nested-type-limit
18660This command shows the current display limit of nested types when
18661printing classes.
18662
53342f27
TT
18663@kindex set print type typedefs
18664@item set print type typedefs
18665@itemx set print type typedefs on
18666@itemx set print type typedefs off
18667
18668Normally, when @value{GDBN} prints a class, it displays any typedefs
18669defined in that class. You can control this behavior either by
18670passing the appropriate flag to @code{ptype}, or using @command{set
18671print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
18672display the typedef definitions; this is the default. Specifying
18673@code{off} will cause @value{GDBN} to omit the typedef definitions.
18674Note that this controls whether the typedef definition itself is
18675printed, not whether typedef names are substituted when printing other
18676types.
18677
18678@kindex show print type typedefs
18679@item show print type typedefs
18680This command shows the current setting of typedef display when
18681printing classes.
18682
c906108c 18683@kindex info address
b37052ae 18684@cindex address of a symbol
c906108c
SS
18685@item info address @var{symbol}
18686Describe where the data for @var{symbol} is stored. For a register
18687variable, this says which register it is kept in. For a non-register
18688local variable, this prints the stack-frame offset at which the variable
18689is always stored.
18690
18691Note the contrast with @samp{print &@var{symbol}}, which does not work
18692at all for a register variable, and for a stack local variable prints
18693the exact address of the current instantiation of the variable.
18694
3d67e040 18695@kindex info symbol
b37052ae 18696@cindex symbol from address
9c16f35a 18697@cindex closest symbol and offset for an address
3d67e040
EZ
18698@item info symbol @var{addr}
18699Print the name of a symbol which is stored at the address @var{addr}.
18700If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
18701nearest symbol and an offset from it:
18702
474c8240 18703@smallexample
3d67e040
EZ
18704(@value{GDBP}) info symbol 0x54320
18705_initialize_vx + 396 in section .text
474c8240 18706@end smallexample
3d67e040
EZ
18707
18708@noindent
18709This is the opposite of the @code{info address} command. You can use
18710it to find out the name of a variable or a function given its address.
18711
c14c28ba
PP
18712For dynamically linked executables, the name of executable or shared
18713library containing the symbol is also printed:
18714
18715@smallexample
18716(@value{GDBP}) info symbol 0x400225
18717_start + 5 in section .text of /tmp/a.out
18718(@value{GDBP}) info symbol 0x2aaaac2811cf
18719__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
18720@end smallexample
18721
439250fb
DE
18722@kindex demangle
18723@cindex demangle
18724@item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
18725Demangle @var{name}.
18726If @var{language} is provided it is the name of the language to demangle
18727@var{name} in. Otherwise @var{name} is demangled in the current language.
18728
18729The @samp{--} option specifies the end of options,
18730and is useful when @var{name} begins with a dash.
18731
18732The parameter @code{demangle-style} specifies how to interpret the kind
18733of mangling used. @xref{Print Settings}.
18734
c906108c 18735@kindex whatis
53342f27 18736@item whatis[/@var{flags}] [@var{arg}]
177bc839
JK
18737Print the data type of @var{arg}, which can be either an expression
18738or a name of a data type. With no argument, print the data type of
18739@code{$}, the last value in the value history.
18740
18741If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
18742is not actually evaluated, and any side-effecting operations (such as
18743assignments or function calls) inside it do not take place.
18744
18745If @var{arg} is a variable or an expression, @code{whatis} prints its
18746literal type as it is used in the source code. If the type was
18747defined using a @code{typedef}, @code{whatis} will @emph{not} print
18748the data type underlying the @code{typedef}. If the type of the
18749variable or the expression is a compound data type, such as
18750@code{struct} or @code{class}, @code{whatis} never prints their
18751fields or methods. It just prints the @code{struct}/@code{class}
18752name (a.k.a.@: its @dfn{tag}). If you want to see the members of
18753such a compound data type, use @code{ptype}.
18754
18755If @var{arg} is a type name that was defined using @code{typedef},
18756@code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
18757Unrolling means that @code{whatis} will show the underlying type used
18758in the @code{typedef} declaration of @var{arg}. However, if that
18759underlying type is also a @code{typedef}, @code{whatis} will not
18760unroll it.
18761
18762For C code, the type names may also have the form @samp{class
18763@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
18764@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 18765
53342f27
TT
18766@var{flags} can be used to modify how the type is displayed.
18767Available flags are:
18768
18769@table @code
18770@item r
18771Display in ``raw'' form. Normally, @value{GDBN} substitutes template
18772parameters and typedefs defined in a class when printing the class'
18773members. The @code{/r} flag disables this.
18774
18775@item m
18776Do not print methods defined in the class.
18777
18778@item M
18779Print methods defined in the class. This is the default, but the flag
18780exists in case you change the default with @command{set print type methods}.
18781
18782@item t
18783Do not print typedefs defined in the class. Note that this controls
18784whether the typedef definition itself is printed, not whether typedef
18785names are substituted when printing other types.
18786
18787@item T
18788Print typedefs defined in the class. This is the default, but the flag
18789exists in case you change the default with @command{set print type typedefs}.
7c161838
SDJ
18790
18791@item o
18792Print the offsets and sizes of fields in a struct, similar to what the
18793@command{pahole} tool does. This option implies the @code{/tm} flags.
18794
18795For example, given the following declarations:
18796
18797@smallexample
18798struct tuv
18799@{
18800 int a1;
18801 char *a2;
18802 int a3;
18803@};
18804
18805struct xyz
18806@{
18807 int f1;
18808 char f2;
18809 void *f3;
18810 struct tuv f4;
18811@};
18812
18813union qwe
18814@{
18815 struct tuv fff1;
18816 struct xyz fff2;
18817@};
18818
18819struct tyu
18820@{
18821 int a1 : 1;
18822 int a2 : 3;
18823 int a3 : 23;
18824 char a4 : 2;
18825 int64_t a5;
18826 int a6 : 5;
18827 int64_t a7 : 3;
18828@};
18829@end smallexample
18830
18831Issuing a @kbd{ptype /o struct tuv} command would print:
18832
18833@smallexample
18834(@value{GDBP}) ptype /o struct tuv
18835/* offset | size */ type = struct tuv @{
18836/* 0 | 4 */ int a1;
18837/* XXX 4-byte hole */
18838/* 8 | 8 */ char *a2;
18839/* 16 | 4 */ int a3;
18840
18841 /* total size (bytes): 24 */
18842 @}
18843@end smallexample
18844
18845Notice the format of the first column of comments. There, you can
18846find two parts separated by the @samp{|} character: the @emph{offset},
18847which indicates where the field is located inside the struct, in
18848bytes, and the @emph{size} of the field. Another interesting line is
18849the marker of a @emph{hole} in the struct, indicating that it may be
18850possible to pack the struct and make it use less space by reorganizing
18851its fields.
18852
18853It is also possible to print offsets inside an union:
18854
18855@smallexample
18856(@value{GDBP}) ptype /o union qwe
18857/* offset | size */ type = union qwe @{
18858/* 24 */ struct tuv @{
18859/* 0 | 4 */ int a1;
18860/* XXX 4-byte hole */
18861/* 8 | 8 */ char *a2;
18862/* 16 | 4 */ int a3;
18863
18864 /* total size (bytes): 24 */
18865 @} fff1;
18866/* 40 */ struct xyz @{
18867/* 0 | 4 */ int f1;
18868/* 4 | 1 */ char f2;
18869/* XXX 3-byte hole */
18870/* 8 | 8 */ void *f3;
18871/* 16 | 24 */ struct tuv @{
18872/* 16 | 4 */ int a1;
18873/* XXX 4-byte hole */
18874/* 24 | 8 */ char *a2;
18875/* 32 | 4 */ int a3;
18876
18877 /* total size (bytes): 24 */
18878 @} f4;
18879
18880 /* total size (bytes): 40 */
18881 @} fff2;
18882
18883 /* total size (bytes): 40 */
18884 @}
18885@end smallexample
18886
18887In this case, since @code{struct tuv} and @code{struct xyz} occupy the
18888same space (because we are dealing with an union), the offset is not
18889printed for them. However, you can still examine the offset of each
18890of these structures' fields.
18891
18892Another useful scenario is printing the offsets of a struct containing
18893bitfields:
18894
18895@smallexample
18896(@value{GDBP}) ptype /o struct tyu
18897/* offset | size */ type = struct tyu @{
18898/* 0:31 | 4 */ int a1 : 1;
18899/* 0:28 | 4 */ int a2 : 3;
18900/* 0: 5 | 4 */ int a3 : 23;
18901/* 3: 3 | 1 */ signed char a4 : 2;
18902/* XXX 3-bit hole */
18903/* XXX 4-byte hole */
18904/* 8 | 8 */ int64_t a5;
9d3421af
TT
18905/* 16: 0 | 4 */ int a6 : 5;
18906/* 16: 5 | 8 */ int64_t a7 : 3;
18907"/* XXX 7-byte padding */
7c161838
SDJ
18908
18909 /* total size (bytes): 24 */
18910 @}
18911@end smallexample
18912
9d3421af
TT
18913Note how the offset information is now extended to also include the
18914first bit of the bitfield.
53342f27
TT
18915@end table
18916
c906108c 18917@kindex ptype
53342f27 18918@item ptype[/@var{flags}] [@var{arg}]
62f3a2ba
FF
18919@code{ptype} accepts the same arguments as @code{whatis}, but prints a
18920detailed description of the type, instead of just the name of the type.
18921@xref{Expressions, ,Expressions}.
c906108c 18922
177bc839
JK
18923Contrary to @code{whatis}, @code{ptype} always unrolls any
18924@code{typedef}s in its argument declaration, whether the argument is
18925a variable, expression, or a data type. This means that @code{ptype}
18926of a variable or an expression will not print literally its type as
18927present in the source code---use @code{whatis} for that. @code{typedef}s at
18928the pointer or reference targets are also unrolled. Only @code{typedef}s of
18929fields, methods and inner @code{class typedef}s of @code{struct}s,
18930@code{class}es and @code{union}s are not unrolled even with @code{ptype}.
18931
c906108c
SS
18932For example, for this variable declaration:
18933
474c8240 18934@smallexample
177bc839
JK
18935typedef double real_t;
18936struct complex @{ real_t real; double imag; @};
18937typedef struct complex complex_t;
18938complex_t var;
18939real_t *real_pointer_var;
474c8240 18940@end smallexample
c906108c
SS
18941
18942@noindent
18943the two commands give this output:
18944
474c8240 18945@smallexample
c906108c 18946@group
177bc839
JK
18947(@value{GDBP}) whatis var
18948type = complex_t
18949(@value{GDBP}) ptype var
18950type = struct complex @{
18951 real_t real;
18952 double imag;
18953@}
18954(@value{GDBP}) whatis complex_t
18955type = struct complex
18956(@value{GDBP}) whatis struct complex
c906108c 18957type = struct complex
177bc839 18958(@value{GDBP}) ptype struct complex
c906108c 18959type = struct complex @{
177bc839 18960 real_t real;
c906108c
SS
18961 double imag;
18962@}
177bc839
JK
18963(@value{GDBP}) whatis real_pointer_var
18964type = real_t *
18965(@value{GDBP}) ptype real_pointer_var
18966type = double *
c906108c 18967@end group
474c8240 18968@end smallexample
c906108c
SS
18969
18970@noindent
18971As with @code{whatis}, using @code{ptype} without an argument refers to
18972the type of @code{$}, the last value in the value history.
18973
ab1adacd
EZ
18974@cindex incomplete type
18975Sometimes, programs use opaque data types or incomplete specifications
18976of complex data structure. If the debug information included in the
18977program does not allow @value{GDBN} to display a full declaration of
18978the data type, it will say @samp{<incomplete type>}. For example,
18979given these declarations:
18980
18981@smallexample
18982 struct foo;
18983 struct foo *fooptr;
18984@end smallexample
18985
18986@noindent
18987but no definition for @code{struct foo} itself, @value{GDBN} will say:
18988
18989@smallexample
ddb50cd7 18990 (@value{GDBP}) ptype foo
ab1adacd
EZ
18991 $1 = <incomplete type>
18992@end smallexample
18993
18994@noindent
18995``Incomplete type'' is C terminology for data types that are not
18996completely specified.
18997
d69cf9b2
PA
18998@cindex unknown type
18999Othertimes, information about a variable's type is completely absent
19000from the debug information included in the program. This most often
19001happens when the program or library where the variable is defined
19002includes no debug information at all. @value{GDBN} knows the variable
19003exists from inspecting the linker/loader symbol table (e.g., the ELF
19004dynamic symbol table), but such symbols do not contain type
19005information. Inspecting the type of a (global) variable for which
19006@value{GDBN} has no type information shows:
19007
19008@smallexample
19009 (@value{GDBP}) ptype var
19010 type = <data variable, no debug info>
19011@end smallexample
19012
19013@xref{Variables, no debug info variables}, for how to print the values
19014of such variables.
19015
c906108c 19016@kindex info types
a8eab7c6 19017@item info types [-q] [@var{regexp}]
09d4efe1
EZ
19018Print a brief description of all types whose names match the regular
19019expression @var{regexp} (or all types in your program, if you supply
19020no argument). Each complete typename is matched as though it were a
19021complete line; thus, @samp{i type value} gives information on all
19022types in your program whose names include the string @code{value}, but
19023@samp{i type ^value$} gives information only on types whose complete
19024name is @code{value}.
c906108c 19025
20813a0b
PW
19026In programs using different languages, @value{GDBN} chooses the syntax
19027to print the type description according to the
19028@samp{set language} value: using @samp{set language auto}
19029(see @ref{Automatically, ,Set Language Automatically}) means to use the
19030language of the type, other values mean to use
19031the manually specified language (see @ref{Manually, ,Set Language Manually}).
19032
c906108c
SS
19033This command differs from @code{ptype} in two ways: first, like
19034@code{whatis}, it does not print a detailed description; second, it
b744723f 19035lists all source files and line numbers where a type is defined.
c906108c 19036
a8eab7c6
AB
19037The output from @samp{into types} is proceeded with a header line
19038describing what types are being listed. The optional flag @samp{-q},
19039which stands for @samp{quiet}, disables printing this header
19040information.
19041
18a9fc12
TT
19042@kindex info type-printers
19043@item info type-printers
19044Versions of @value{GDBN} that ship with Python scripting enabled may
19045have ``type printers'' available. When using @command{ptype} or
19046@command{whatis}, these printers are consulted when the name of a type
19047is needed. @xref{Type Printing API}, for more information on writing
19048type printers.
19049
19050@code{info type-printers} displays all the available type printers.
19051
19052@kindex enable type-printer
19053@kindex disable type-printer
19054@item enable type-printer @var{name}@dots{}
19055@item disable type-printer @var{name}@dots{}
19056These commands can be used to enable or disable type printers.
19057
b37052ae
EZ
19058@kindex info scope
19059@cindex local variables
09d4efe1 19060@item info scope @var{location}
b37052ae 19061List all the variables local to a particular scope. This command
09d4efe1
EZ
19062accepts a @var{location} argument---a function name, a source line, or
19063an address preceded by a @samp{*}, and prints all the variables local
2a25a5ba
EZ
19064to the scope defined by that location. (@xref{Specify Location}, for
19065details about supported forms of @var{location}.) For example:
b37052ae
EZ
19066
19067@smallexample
19068(@value{GDBP}) @b{info scope command_line_handler}
19069Scope for command_line_handler:
19070Symbol rl is an argument at stack/frame offset 8, length 4.
19071Symbol linebuffer is in static storage at address 0x150a18, length 4.
19072Symbol linelength is in static storage at address 0x150a1c, length 4.
19073Symbol p is a local variable in register $esi, length 4.
19074Symbol p1 is a local variable in register $ebx, length 4.
19075Symbol nline is a local variable in register $edx, length 4.
19076Symbol repeat is a local variable at frame offset -8, length 4.
19077@end smallexample
19078
f5c37c66
EZ
19079@noindent
19080This command is especially useful for determining what data to collect
19081during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
19082collect}.
19083
c906108c
SS
19084@kindex info source
19085@item info source
919d772c
JB
19086Show information about the current source file---that is, the source file for
19087the function containing the current point of execution:
19088@itemize @bullet
19089@item
19090the name of the source file, and the directory containing it,
19091@item
19092the directory it was compiled in,
19093@item
19094its length, in lines,
19095@item
19096which programming language it is written in,
19097@item
b6577aab
DE
19098if the debug information provides it, the program that compiled the file
19099(which may include, e.g., the compiler version and command line arguments),
19100@item
919d772c
JB
19101whether the executable includes debugging information for that file, and
19102if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
19103@item
19104whether the debugging information includes information about
19105preprocessor macros.
19106@end itemize
19107
c906108c
SS
19108
19109@kindex info sources
19110@item info sources
19111Print the names of all source files in your program for which there is
19112debugging information, organized into two lists: files whose symbols
19113have already been read, and files whose symbols will be read when needed.
19114
ae60f04e
PW
19115@item info sources [-dirname | -basename] [--] [@var{regexp}]
19116Like @samp{info sources}, but only print the names of the files
19117matching the provided @var{regexp}.
19118By default, the @var{regexp} is used to match anywhere in the filename.
19119If @code{-dirname}, only files having a dirname matching @var{regexp} are shown.
19120If @code{-basename}, only files having a basename matching @var{regexp}
19121are shown.
19122The matching is case-sensitive, except on operating systems that
19123have case-insensitive filesystem (e.g., MS-Windows).
19124
c906108c 19125@kindex info functions
4acfdd20 19126@item info functions [-q] [-n]
c906108c 19127Print the names and data types of all defined functions.
b744723f
AA
19128Similarly to @samp{info types}, this command groups its output by source
19129files and annotates each function definition with its source line
19130number.
c906108c 19131
20813a0b
PW
19132In programs using different languages, @value{GDBN} chooses the syntax
19133to print the function name and type according to the
19134@samp{set language} value: using @samp{set language auto}
19135(see @ref{Automatically, ,Set Language Automatically}) means to use the
19136language of the function, other values mean to use
19137the manually specified language (see @ref{Manually, ,Set Language Manually}).
19138
4acfdd20
AB
19139The @samp{-n} flag excludes @dfn{non-debugging symbols} from the
19140results. A non-debugging symbol is a symbol that comes from the
19141executable's symbol table, not from the debug information (for
19142example, DWARF) associated with the executable.
19143
d321477b
PW
19144The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19145printing header information and messages explaining why no functions
19146have been printed.
19147
4acfdd20 19148@item info functions [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
d321477b
PW
19149Like @samp{info functions}, but only print the names and data types
19150of the functions selected with the provided regexp(s).
19151
19152If @var{regexp} is provided, print only the functions whose names
19153match the regular expression @var{regexp}.
19154Thus, @samp{info fun step} finds all functions whose
b744723f
AA
19155names include @code{step}; @samp{info fun ^step} finds those whose names
19156start with @code{step}. If a function name contains characters that
19157conflict with the regular expression language (e.g.@:
1c5dfdad 19158@samp{operator*()}), they may be quoted with a backslash.
c906108c 19159
d321477b
PW
19160If @var{type_regexp} is provided, print only the functions whose
19161types, as printed by the @code{whatis} command, match
19162the regular expression @var{type_regexp}.
19163If @var{type_regexp} contains space(s), it should be enclosed in
19164quote characters. If needed, use backslash to escape the meaning
19165of special characters or quotes.
19166Thus, @samp{info fun -t '^int ('} finds the functions that return
19167an integer; @samp{info fun -t '(.*int.*'} finds the functions that
19168have an argument type containing int; @samp{info fun -t '^int (' ^step}
19169finds the functions whose names start with @code{step} and that return
19170int.
19171
19172If both @var{regexp} and @var{type_regexp} are provided, a function
19173is printed only if its name matches @var{regexp} and its type matches
19174@var{type_regexp}.
19175
19176
c906108c 19177@kindex info variables
4acfdd20 19178@item info variables [-q] [-n]
0fe7935b 19179Print the names and data types of all variables that are defined
6ca652b0 19180outside of functions (i.e.@: excluding local variables).
b744723f
AA
19181The printed variables are grouped by source files and annotated with
19182their respective source line numbers.
c906108c 19183
20813a0b
PW
19184In programs using different languages, @value{GDBN} chooses the syntax
19185to print the variable name and type according to the
19186@samp{set language} value: using @samp{set language auto}
19187(see @ref{Automatically, ,Set Language Automatically}) means to use the
19188language of the variable, other values mean to use
19189the manually specified language (see @ref{Manually, ,Set Language Manually}).
19190
4acfdd20
AB
19191The @samp{-n} flag excludes non-debugging symbols from the results.
19192
d321477b
PW
19193The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19194printing header information and messages explaining why no variables
19195have been printed.
19196
4acfdd20 19197@item info variables [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
d321477b
PW
19198Like @kbd{info variables}, but only print the variables selected
19199with the provided regexp(s).
19200
19201If @var{regexp} is provided, print only the variables whose names
19202match the regular expression @var{regexp}.
19203
19204If @var{type_regexp} is provided, print only the variables whose
19205types, as printed by the @code{whatis} command, match
19206the regular expression @var{type_regexp}.
19207If @var{type_regexp} contains space(s), it should be enclosed in
19208quote characters. If needed, use backslash to escape the meaning
19209of special characters or quotes.
19210
19211If both @var{regexp} and @var{type_regexp} are provided, an argument
19212is printed only if its name matches @var{regexp} and its type matches
19213@var{type_regexp}.
c906108c 19214
59c35742
AB
19215@kindex info modules
19216@cindex modules
19217@item info modules @r{[}-q@r{]} @r{[}@var{regexp}@r{]}
19218List all Fortran modules in the program, or all modules matching the
19219optional regular expression @var{regexp}.
19220
19221The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19222printing header information and messages explaining why no modules
19223have been printed.
165f8965
AB
19224
19225@kindex info module
19226@cindex Fortran modules, information about
19227@cindex functions and variables by Fortran module
19228@cindex module functions and variables
19229@item info module functions @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19230@itemx info module variables @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19231List all functions or variables within all Fortran modules. The set
19232of functions or variables listed can be limited by providing some or
19233all of the optional regular expressions. If @var{module-regexp} is
19234provided, then only Fortran modules matching @var{module-regexp} will
19235be searched. Only functions or variables whose type matches the
19236optional regular expression @var{type-regexp} will be listed. And
19237only functions or variables whose name matches the optional regular
19238expression @var{regexp} will be listed.
19239
19240The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19241printing header information and messages explaining why no functions
19242or variables have been printed.
59c35742 19243
b37303ee 19244@kindex info classes
721c2651 19245@cindex Objective-C, classes and selectors
b37303ee
AF
19246@item info classes
19247@itemx info classes @var{regexp}
19248Display all Objective-C classes in your program, or
19249(with the @var{regexp} argument) all those matching a particular regular
19250expression.
19251
19252@kindex info selectors
19253@item info selectors
19254@itemx info selectors @var{regexp}
19255Display all Objective-C selectors in your program, or
19256(with the @var{regexp} argument) all those matching a particular regular
19257expression.
19258
c906108c
SS
19259@ignore
19260This was never implemented.
19261@kindex info methods
19262@item info methods
19263@itemx info methods @var{regexp}
19264The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
19265methods within C@t{++} program, or (with the @var{regexp} argument) a
19266specific set of methods found in the various C@t{++} classes. Many
19267C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
19268from the @code{ptype} command can be overwhelming and hard to use. The
19269@code{info-methods} command filters the methods, printing only those
19270which match the regular-expression @var{regexp}.
19271@end ignore
19272
9c16f35a 19273@cindex opaque data types
c906108c
SS
19274@kindex set opaque-type-resolution
19275@item set opaque-type-resolution on
19276Tell @value{GDBN} to resolve opaque types. An opaque type is a type
19277declared as a pointer to a @code{struct}, @code{class}, or
19278@code{union}---for example, @code{struct MyType *}---that is used in one
19279source file although the full declaration of @code{struct MyType} is in
19280another source file. The default is on.
19281
19282A change in the setting of this subcommand will not take effect until
19283the next time symbols for a file are loaded.
19284
19285@item set opaque-type-resolution off
19286Tell @value{GDBN} not to resolve opaque types. In this case, the type
19287is printed as follows:
19288@smallexample
19289@{<no data fields>@}
19290@end smallexample
19291
19292@kindex show opaque-type-resolution
19293@item show opaque-type-resolution
19294Show whether opaque types are resolved or not.
c906108c 19295
770e7fc7
DE
19296@kindex set print symbol-loading
19297@cindex print messages when symbols are loaded
19298@item set print symbol-loading
19299@itemx set print symbol-loading full
19300@itemx set print symbol-loading brief
19301@itemx set print symbol-loading off
19302The @code{set print symbol-loading} command allows you to control the
19303printing of messages when @value{GDBN} loads symbol information.
19304By default a message is printed for the executable and one for each
19305shared library, and normally this is what you want. However, when
19306debugging apps with large numbers of shared libraries these messages
19307can be annoying.
19308When set to @code{brief} a message is printed for each executable,
19309and when @value{GDBN} loads a collection of shared libraries at once
19310it will only print one message regardless of the number of shared
19311libraries. When set to @code{off} no messages are printed.
19312
19313@kindex show print symbol-loading
19314@item show print symbol-loading
19315Show whether messages will be printed when a @value{GDBN} command
19316entered from the keyboard causes symbol information to be loaded.
19317
c906108c
SS
19318@kindex maint print symbols
19319@cindex symbol dump
19320@kindex maint print psymbols
19321@cindex partial symbol dump
7c57fa1e
YQ
19322@kindex maint print msymbols
19323@cindex minimal symbol dump
34c41c68
DE
19324@item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
19325@itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19326@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19327@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19328@itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19329Write a dump of debugging symbol data into the file @var{filename} or
19330the terminal if @var{filename} is unspecified.
19331If @code{-objfile @var{objfile}} is specified, only dump symbols for
19332that objfile.
19333If @code{-pc @var{address}} is specified, only dump symbols for the file
19334with code at that address. Note that @var{address} may be a symbol like
19335@code{main}.
19336If @code{-source @var{source}} is specified, only dump symbols for that
19337source file.
19338
19339These commands are used to debug the @value{GDBN} symbol-reading code.
19340These commands do not modify internal @value{GDBN} state, therefore
19341@samp{maint print symbols} will only print symbols for already expanded symbol
19342tables.
19343You can use the command @code{info sources} to find out which files these are.
19344If you use @samp{maint print psymbols} instead, the dump shows information
19345about symbols that @value{GDBN} only knows partially---that is, symbols
19346defined in files that @value{GDBN} has skimmed, but not yet read completely.
19347Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
19348``ELF symbols''.
19349
79a6e687 19350@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 19351@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 19352
5e7b2f39
JB
19353@kindex maint info symtabs
19354@kindex maint info psymtabs
44ea7b70
JB
19355@cindex listing @value{GDBN}'s internal symbol tables
19356@cindex symbol tables, listing @value{GDBN}'s internal
19357@cindex full symbol tables, listing @value{GDBN}'s internal
19358@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
19359@item maint info symtabs @r{[} @var{regexp} @r{]}
19360@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
19361
19362List the @code{struct symtab} or @code{struct partial_symtab}
19363structures whose names match @var{regexp}. If @var{regexp} is not
19364given, list them all. The output includes expressions which you can
19365copy into a @value{GDBN} debugging this one to examine a particular
19366structure in more detail. For example:
19367
19368@smallexample
5e7b2f39 19369(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
19370@{ objfile /home/gnu/build/gdb/gdb
19371 ((struct objfile *) 0x82e69d0)
b383017d 19372 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
19373 ((struct partial_symtab *) 0x8474b10)
19374 readin no
19375 fullname (null)
19376 text addresses 0x814d3c8 -- 0x8158074
19377 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
19378 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
19379 dependencies (none)
19380 @}
19381@}
5e7b2f39 19382(@value{GDBP}) maint info symtabs
44ea7b70
JB
19383(@value{GDBP})
19384@end smallexample
19385@noindent
19386We see that there is one partial symbol table whose filename contains
19387the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
19388and we see that @value{GDBN} has not read in any symtabs yet at all.
19389If we set a breakpoint on a function, that will cause @value{GDBN} to
19390read the symtab for the compilation unit containing that function:
19391
19392@smallexample
19393(@value{GDBP}) break dwarf2_psymtab_to_symtab
19394Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
19395line 1574.
5e7b2f39 19396(@value{GDBP}) maint info symtabs
b383017d 19397@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 19398 ((struct objfile *) 0x82e69d0)
b383017d 19399 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
19400 ((struct symtab *) 0x86c1f38)
19401 dirname (null)
19402 fullname (null)
19403 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 19404 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
19405 debugformat DWARF 2
19406 @}
19407@}
b383017d 19408(@value{GDBP})
44ea7b70 19409@end smallexample
44ea7b70 19410
f2403c39
AB
19411@kindex maint info line-table
19412@cindex listing @value{GDBN}'s internal line tables
19413@cindex line tables, listing @value{GDBN}'s internal
19414@item maint info line-table @r{[} @var{regexp} @r{]}
19415
19416List the @code{struct linetable} from all @code{struct symtab}
19417instances whose name matches @var{regexp}. If @var{regexp} is not
19418given, list the @code{struct linetable} from all @code{struct symtab}.
19419
f57d2163
DE
19420@kindex maint set symbol-cache-size
19421@cindex symbol cache size
19422@item maint set symbol-cache-size @var{size}
19423Set the size of the symbol cache to @var{size}.
19424The default size is intended to be good enough for debugging
19425most applications. This option exists to allow for experimenting
19426with different sizes.
19427
19428@kindex maint show symbol-cache-size
19429@item maint show symbol-cache-size
19430Show the size of the symbol cache.
19431
19432@kindex maint print symbol-cache
19433@cindex symbol cache, printing its contents
19434@item maint print symbol-cache
19435Print the contents of the symbol cache.
19436This is useful when debugging symbol cache issues.
19437
19438@kindex maint print symbol-cache-statistics
19439@cindex symbol cache, printing usage statistics
19440@item maint print symbol-cache-statistics
19441Print symbol cache usage statistics.
19442This helps determine how well the cache is being utilized.
19443
50a5f187 19444@kindex maint flush symbol-cache
f57d2163
DE
19445@kindex maint flush-symbol-cache
19446@cindex symbol cache, flushing
50a5f187
AB
19447@item maint flush symbol-cache
19448@itemx maint flush-symbol-cache
19449Flush the contents of the symbol cache, all entries are removed. This
19450command is useful when debugging the symbol cache. It is also useful
19451when collecting performance data. The command @code{maint
19452flush-symbol-cache} is deprecated in favor of @code{maint flush
19453symbol-cache}..
f57d2163
DE
19454
19455@end table
6a3ca067 19456
6d2ebf8b 19457@node Altering
c906108c
SS
19458@chapter Altering Execution
19459
19460Once you think you have found an error in your program, you might want to
19461find out for certain whether correcting the apparent error would lead to
19462correct results in the rest of the run. You can find the answer by
19463experiment, using the @value{GDBN} features for altering execution of the
19464program.
19465
19466For example, you can store new values into variables or memory
7a292a7a
SS
19467locations, give your program a signal, restart it at a different
19468address, or even return prematurely from a function.
c906108c
SS
19469
19470@menu
19471* Assignment:: Assignment to variables
19472* Jumping:: Continuing at a different address
c906108c 19473* Signaling:: Giving your program a signal
c906108c
SS
19474* Returning:: Returning from a function
19475* Calling:: Calling your program's functions
19476* Patching:: Patching your program
bb2ec1b3 19477* Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
c906108c
SS
19478@end menu
19479
6d2ebf8b 19480@node Assignment
79a6e687 19481@section Assignment to Variables
c906108c
SS
19482
19483@cindex assignment
19484@cindex setting variables
19485To alter the value of a variable, evaluate an assignment expression.
19486@xref{Expressions, ,Expressions}. For example,
19487
474c8240 19488@smallexample
c906108c 19489print x=4
474c8240 19490@end smallexample
c906108c
SS
19491
19492@noindent
19493stores the value 4 into the variable @code{x}, and then prints the
5d161b24 19494value of the assignment expression (which is 4).
c906108c
SS
19495@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
19496information on operators in supported languages.
c906108c
SS
19497
19498@kindex set variable
19499@cindex variables, setting
19500If you are not interested in seeing the value of the assignment, use the
19501@code{set} command instead of the @code{print} command. @code{set} is
19502really the same as @code{print} except that the expression's value is
19503not printed and is not put in the value history (@pxref{Value History,
79a6e687 19504,Value History}). The expression is evaluated only for its effects.
c906108c 19505
c906108c
SS
19506If the beginning of the argument string of the @code{set} command
19507appears identical to a @code{set} subcommand, use the @code{set
19508variable} command instead of just @code{set}. This command is identical
19509to @code{set} except for its lack of subcommands. For example, if your
19510program has a variable @code{width}, you get an error if you try to set
19511a new value with just @samp{set width=13}, because @value{GDBN} has the
19512command @code{set width}:
19513
474c8240 19514@smallexample
c906108c
SS
19515(@value{GDBP}) whatis width
19516type = double
19517(@value{GDBP}) p width
19518$4 = 13
19519(@value{GDBP}) set width=47
19520Invalid syntax in expression.
474c8240 19521@end smallexample
c906108c
SS
19522
19523@noindent
19524The invalid expression, of course, is @samp{=47}. In
19525order to actually set the program's variable @code{width}, use
19526
474c8240 19527@smallexample
c906108c 19528(@value{GDBP}) set var width=47
474c8240 19529@end smallexample
53a5351d 19530
c906108c
SS
19531Because the @code{set} command has many subcommands that can conflict
19532with the names of program variables, it is a good idea to use the
19533@code{set variable} command instead of just @code{set}. For example, if
19534your program has a variable @code{g}, you run into problems if you try
19535to set a new value with just @samp{set g=4}, because @value{GDBN} has
19536the command @code{set gnutarget}, abbreviated @code{set g}:
19537
474c8240 19538@smallexample
c906108c
SS
19539@group
19540(@value{GDBP}) whatis g
19541type = double
19542(@value{GDBP}) p g
19543$1 = 1
19544(@value{GDBP}) set g=4
2df3850c 19545(@value{GDBP}) p g
c906108c
SS
19546$2 = 1
19547(@value{GDBP}) r
19548The program being debugged has been started already.
19549Start it from the beginning? (y or n) y
19550Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
19551"/home/smith/cc_progs/a.out": can't open to read symbols:
19552 Invalid bfd target.
c906108c
SS
19553(@value{GDBP}) show g
19554The current BFD target is "=4".
19555@end group
474c8240 19556@end smallexample
c906108c
SS
19557
19558@noindent
19559The program variable @code{g} did not change, and you silently set the
19560@code{gnutarget} to an invalid value. In order to set the variable
19561@code{g}, use
19562
474c8240 19563@smallexample
c906108c 19564(@value{GDBP}) set var g=4
474c8240 19565@end smallexample
c906108c
SS
19566
19567@value{GDBN} allows more implicit conversions in assignments than C; you can
19568freely store an integer value into a pointer variable or vice versa,
19569and you can convert any structure to any other structure that is the
19570same length or shorter.
19571@comment FIXME: how do structs align/pad in these conversions?
19572@comment /doc@cygnus.com 18dec1990
19573
19574To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
19575construct to generate a value of specified type at a specified address
19576(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
19577to memory location @code{0x83040} as an integer (which implies a certain size
19578and representation in memory), and
19579
474c8240 19580@smallexample
c906108c 19581set @{int@}0x83040 = 4
474c8240 19582@end smallexample
c906108c
SS
19583
19584@noindent
19585stores the value 4 into that memory location.
19586
6d2ebf8b 19587@node Jumping
79a6e687 19588@section Continuing at a Different Address
c906108c
SS
19589
19590Ordinarily, when you continue your program, you do so at the place where
19591it stopped, with the @code{continue} command. You can instead continue at
19592an address of your own choosing, with the following commands:
19593
19594@table @code
19595@kindex jump
c1d780c2 19596@kindex j @r{(@code{jump})}
629500fa 19597@item jump @var{location}
c1d780c2 19598@itemx j @var{location}
629500fa
KS
19599Resume execution at @var{location}. Execution stops again immediately
19600if there is a breakpoint there. @xref{Specify Location}, for a description
19601of the different forms of @var{location}. It is common
2a25a5ba
EZ
19602practice to use the @code{tbreak} command in conjunction with
19603@code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
c906108c
SS
19604
19605The @code{jump} command does not change the current stack frame, or
19606the stack pointer, or the contents of any memory location or any
629500fa 19607register other than the program counter. If @var{location} is in
c906108c
SS
19608a different function from the one currently executing, the results may
19609be bizarre if the two functions expect different patterns of arguments or
19610of local variables. For this reason, the @code{jump} command requests
19611confirmation if the specified line is not in the function currently
19612executing. However, even bizarre results are predictable if you are
19613well acquainted with the machine-language code of your program.
c906108c
SS
19614@end table
19615
53a5351d
JM
19616On many systems, you can get much the same effect as the @code{jump}
19617command by storing a new value into the register @code{$pc}. The
19618difference is that this does not start your program running; it only
19619changes the address of where it @emph{will} run when you continue. For
19620example,
c906108c 19621
474c8240 19622@smallexample
c906108c 19623set $pc = 0x485
474c8240 19624@end smallexample
c906108c
SS
19625
19626@noindent
19627makes the next @code{continue} command or stepping command execute at
19628address @code{0x485}, rather than at the address where your program stopped.
79a6e687 19629@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
19630
19631The most common occasion to use the @code{jump} command is to back
19632up---perhaps with more breakpoints set---over a portion of a program
19633that has already executed, in order to examine its execution in more
19634detail.
19635
c906108c 19636@c @group
6d2ebf8b 19637@node Signaling
79a6e687 19638@section Giving your Program a Signal
9c16f35a 19639@cindex deliver a signal to a program
c906108c
SS
19640
19641@table @code
19642@kindex signal
19643@item signal @var{signal}
70509625 19644Resume execution where your program is stopped, but immediately give it the
697aa1b7 19645signal @var{signal}. The @var{signal} can be the name or the number of a
c906108c
SS
19646signal. For example, on many systems @code{signal 2} and @code{signal
19647SIGINT} are both ways of sending an interrupt signal.
19648
19649Alternatively, if @var{signal} is zero, continue execution without
19650giving a signal. This is useful when your program stopped on account of
ae606bee 19651a signal and would ordinarily see the signal when resumed with the
c906108c
SS
19652@code{continue} command; @samp{signal 0} causes it to resume without a
19653signal.
19654
70509625
PA
19655@emph{Note:} When resuming a multi-threaded program, @var{signal} is
19656delivered to the currently selected thread, not the thread that last
19657reported a stop. This includes the situation where a thread was
19658stopped due to a signal. So if you want to continue execution
19659suppressing the signal that stopped a thread, you should select that
19660same thread before issuing the @samp{signal 0} command. If you issue
19661the @samp{signal 0} command with another thread as the selected one,
19662@value{GDBN} detects that and asks for confirmation.
19663
c906108c
SS
19664Invoking the @code{signal} command is not the same as invoking the
19665@code{kill} utility from the shell. Sending a signal with @code{kill}
19666causes @value{GDBN} to decide what to do with the signal depending on
19667the signal handling tables (@pxref{Signals}). The @code{signal} command
19668passes the signal directly to your program.
19669
81219e53
DE
19670@code{signal} does not repeat when you press @key{RET} a second time
19671after executing the command.
19672
19673@kindex queue-signal
19674@item queue-signal @var{signal}
19675Queue @var{signal} to be delivered immediately to the current thread
19676when execution of the thread resumes. The @var{signal} can be the name or
19677the number of a signal. For example, on many systems @code{signal 2} and
19678@code{signal SIGINT} are both ways of sending an interrupt signal.
19679The handling of the signal must be set to pass the signal to the program,
19680otherwise @value{GDBN} will report an error.
19681You can control the handling of signals from @value{GDBN} with the
19682@code{handle} command (@pxref{Signals}).
19683
19684Alternatively, if @var{signal} is zero, any currently queued signal
19685for the current thread is discarded and when execution resumes no signal
19686will be delivered. This is useful when your program stopped on account
19687of a signal and would ordinarily see the signal when resumed with the
19688@code{continue} command.
19689
19690This command differs from the @code{signal} command in that the signal
19691is just queued, execution is not resumed. And @code{queue-signal} cannot
19692be used to pass a signal whose handling state has been set to @code{nopass}
19693(@pxref{Signals}).
19694@end table
19695@c @end group
c906108c 19696
e5f8a7cc
PA
19697@xref{stepping into signal handlers}, for information on how stepping
19698commands behave when the thread has a signal queued.
19699
6d2ebf8b 19700@node Returning
79a6e687 19701@section Returning from a Function
c906108c
SS
19702
19703@table @code
19704@cindex returning from a function
19705@kindex return
19706@item return
19707@itemx return @var{expression}
19708You can cancel execution of a function call with the @code{return}
19709command. If you give an
19710@var{expression} argument, its value is used as the function's return
19711value.
19712@end table
19713
19714When you use @code{return}, @value{GDBN} discards the selected stack frame
19715(and all frames within it). You can think of this as making the
19716discarded frame return prematurely. If you wish to specify a value to
19717be returned, give that value as the argument to @code{return}.
19718
19719This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 19720Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
19721innermost remaining frame. That frame becomes selected. The
19722specified value is stored in the registers used for returning values
19723of functions.
19724
19725The @code{return} command does not resume execution; it leaves the
19726program stopped in the state that would exist if the function had just
19727returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 19728and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
19729selected stack frame returns naturally.
19730
61ff14c6
JK
19731@value{GDBN} needs to know how the @var{expression} argument should be set for
19732the inferior. The concrete registers assignment depends on the OS ABI and the
19733type being returned by the selected stack frame. For example it is common for
19734OS ABI to return floating point values in FPU registers while integer values in
19735CPU registers. Still some ABIs return even floating point values in CPU
19736registers. Larger integer widths (such as @code{long long int}) also have
19737specific placement rules. @value{GDBN} already knows the OS ABI from its
19738current target so it needs to find out also the type being returned to make the
19739assignment into the right register(s).
19740
19741Normally, the selected stack frame has debug info. @value{GDBN} will always
19742use the debug info instead of the implicit type of @var{expression} when the
19743debug info is available. For example, if you type @kbd{return -1}, and the
19744function in the current stack frame is declared to return a @code{long long
19745int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
19746into a @code{long long int}:
19747
19748@smallexample
19749Breakpoint 1, func () at gdb.base/return-nodebug.c:29
1975029 return 31;
19751(@value{GDBP}) return -1
19752Make func return now? (y or n) y
19753#0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
1975443 printf ("result=%lld\n", func ());
19755(@value{GDBP})
19756@end smallexample
19757
19758However, if the selected stack frame does not have a debug info, e.g., if the
19759function was compiled without debug info, @value{GDBN} has to find out the type
19760to return from user. Specifying a different type by mistake may set the value
19761in different inferior registers than the caller code expects. For example,
19762typing @kbd{return -1} with its implicit type @code{int} would set only a part
19763of a @code{long long int} result for a debug info less function (on 32-bit
19764architectures). Therefore the user is required to specify the return type by
19765an appropriate cast explicitly:
19766
19767@smallexample
19768Breakpoint 2, 0x0040050b in func ()
19769(@value{GDBP}) return -1
19770Return value type not available for selected stack frame.
19771Please use an explicit cast of the value to return.
19772(@value{GDBP}) return (long long int) -1
19773Make selected stack frame return now? (y or n) y
19774#0 0x00400526 in main ()
19775(@value{GDBP})
19776@end smallexample
19777
6d2ebf8b 19778@node Calling
79a6e687 19779@section Calling Program Functions
c906108c 19780
f8568604 19781@table @code
c906108c 19782@cindex calling functions
f8568604
EZ
19783@cindex inferior functions, calling
19784@item print @var{expr}
d3e8051b 19785Evaluate the expression @var{expr} and display the resulting value.
697aa1b7 19786The expression may include calls to functions in the program being
f8568604
EZ
19787debugged.
19788
c906108c 19789@kindex call
c906108c
SS
19790@item call @var{expr}
19791Evaluate the expression @var{expr} without displaying @code{void}
19792returned values.
c906108c
SS
19793
19794You can use this variant of the @code{print} command if you want to
f8568604
EZ
19795execute a function from your program that does not return anything
19796(a.k.a.@: @dfn{a void function}), but without cluttering the output
19797with @code{void} returned values that @value{GDBN} will otherwise
19798print. If the result is not void, it is printed and saved in the
19799value history.
19800@end table
19801
9c16f35a
EZ
19802It is possible for the function you call via the @code{print} or
19803@code{call} command to generate a signal (e.g., if there's a bug in
19804the function, or if you passed it incorrect arguments). What happens
19805in that case is controlled by the @code{set unwindonsignal} command.
19806
7cd1089b
PM
19807Similarly, with a C@t{++} program it is possible for the function you
19808call via the @code{print} or @code{call} command to generate an
19809exception that is not handled due to the constraints of the dummy
19810frame. In this case, any exception that is raised in the frame, but has
19811an out-of-frame exception handler will not be found. GDB builds a
19812dummy-frame for the inferior function call, and the unwinder cannot
19813seek for exception handlers outside of this dummy-frame. What happens
19814in that case is controlled by the
19815@code{set unwind-on-terminating-exception} command.
19816
9c16f35a
EZ
19817@table @code
19818@item set unwindonsignal
19819@kindex set unwindonsignal
19820@cindex unwind stack in called functions
19821@cindex call dummy stack unwinding
19822Set unwinding of the stack if a signal is received while in a function
19823that @value{GDBN} called in the program being debugged. If set to on,
19824@value{GDBN} unwinds the stack it created for the call and restores
19825the context to what it was before the call. If set to off (the
19826default), @value{GDBN} stops in the frame where the signal was
19827received.
19828
19829@item show unwindonsignal
19830@kindex show unwindonsignal
19831Show the current setting of stack unwinding in the functions called by
19832@value{GDBN}.
7cd1089b
PM
19833
19834@item set unwind-on-terminating-exception
19835@kindex set unwind-on-terminating-exception
19836@cindex unwind stack in called functions with unhandled exceptions
19837@cindex call dummy stack unwinding on unhandled exception.
19838Set unwinding of the stack if a C@t{++} exception is raised, but left
19839unhandled while in a function that @value{GDBN} called in the program being
19840debugged. If set to on (the default), @value{GDBN} unwinds the stack
19841it created for the call and restores the context to what it was before
19842the call. If set to off, @value{GDBN} the exception is delivered to
19843the default C@t{++} exception handler and the inferior terminated.
19844
19845@item show unwind-on-terminating-exception
19846@kindex show unwind-on-terminating-exception
19847Show the current setting of stack unwinding in the functions called by
19848@value{GDBN}.
19849
136afab8
PW
19850@item set may-call-functions
19851@kindex set may-call-functions
19852@cindex disabling calling functions in the program
19853@cindex calling functions in the program, disabling
19854Set permission to call functions in the program.
19855This controls whether @value{GDBN} will attempt to call functions in
19856the program, such as with expressions in the @code{print} command. It
19857defaults to @code{on}.
19858
19859To call a function in the program, @value{GDBN} has to temporarily
19860modify the state of the inferior. This has potentially undesired side
19861effects. Also, having @value{GDBN} call nested functions is likely to
19862be erroneous and may even crash the program being debugged. You can
19863avoid such hazards by forbidding @value{GDBN} from calling functions
19864in the program being debugged. If calling functions in the program
19865is forbidden, GDB will throw an error when a command (such as printing
19866an expression) starts a function call in the program.
19867
19868@item show may-call-functions
19869@kindex show may-call-functions
19870Show permission to call functions in the program.
19871
9c16f35a
EZ
19872@end table
19873
d69cf9b2
PA
19874@subsection Calling functions with no debug info
19875
19876@cindex no debug info functions
19877Sometimes, a function you wish to call is missing debug information.
19878In such case, @value{GDBN} does not know the type of the function,
19879including the types of the function's parameters. To avoid calling
19880the inferior function incorrectly, which could result in the called
19881function functioning erroneously and even crash, @value{GDBN} refuses
19882to call the function unless you tell it the type of the function.
19883
19884For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
19885to do that. The simplest is to cast the call to the function's
19886declared return type. For example:
19887
19888@smallexample
19889(@value{GDBP}) p getenv ("PATH")
19890'getenv' has unknown return type; cast the call to its declared return type
19891(@value{GDBP}) p (char *) getenv ("PATH")
19892$1 = 0x7fffffffe7ba "/usr/local/bin:/"...
19893@end smallexample
19894
19895Casting the return type of a no-debug function is equivalent to
19896casting the function to a pointer to a prototyped function that has a
19897prototype that matches the types of the passed-in arguments, and
19898calling that. I.e., the call above is equivalent to:
19899
19900@smallexample
19901(@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
19902@end smallexample
19903
19904@noindent
19905and given this prototyped C or C++ function with float parameters:
19906
19907@smallexample
19908float multiply (float v1, float v2) @{ return v1 * v2; @}
19909@end smallexample
19910
19911@noindent
19912these calls are equivalent:
19913
19914@smallexample
19915(@value{GDBP}) p (float) multiply (2.0f, 3.0f)
19916(@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
19917@end smallexample
19918
19919If the function you wish to call is declared as unprototyped (i.e.@:
19920old K&R style), you must use the cast-to-function-pointer syntax, so
19921that @value{GDBN} knows that it needs to apply default argument
19922promotions (promote float arguments to double). @xref{ABI, float
19923promotion}. For example, given this unprototyped C function with
19924float parameters, and no debug info:
19925
19926@smallexample
19927float
19928multiply_noproto (v1, v2)
19929 float v1, v2;
19930@{
19931 return v1 * v2;
19932@}
19933@end smallexample
19934
19935@noindent
19936you call it like this:
19937
19938@smallexample
19939 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
19940@end smallexample
c906108c 19941
6d2ebf8b 19942@node Patching
79a6e687 19943@section Patching Programs
7a292a7a 19944
c906108c
SS
19945@cindex patching binaries
19946@cindex writing into executables
c906108c 19947@cindex writing into corefiles
c906108c 19948
7a292a7a
SS
19949By default, @value{GDBN} opens the file containing your program's
19950executable code (or the corefile) read-only. This prevents accidental
19951alterations to machine code; but it also prevents you from intentionally
19952patching your program's binary.
c906108c
SS
19953
19954If you'd like to be able to patch the binary, you can specify that
19955explicitly with the @code{set write} command. For example, you might
19956want to turn on internal debugging flags, or even to make emergency
19957repairs.
19958
19959@table @code
19960@kindex set write
19961@item set write on
19962@itemx set write off
7a292a7a 19963If you specify @samp{set write on}, @value{GDBN} opens executable and
20924a55 19964core files for both reading and writing; if you specify @kbd{set write
c906108c
SS
19965off} (the default), @value{GDBN} opens them read-only.
19966
19967If you have already loaded a file, you must load it again (using the
7a292a7a
SS
19968@code{exec-file} or @code{core-file} command) after changing @code{set
19969write}, for your new setting to take effect.
c906108c
SS
19970
19971@item show write
19972@kindex show write
7a292a7a
SS
19973Display whether executable files and core files are opened for writing
19974as well as reading.
c906108c
SS
19975@end table
19976
bb2ec1b3
TT
19977@node Compiling and Injecting Code
19978@section Compiling and injecting code in @value{GDBN}
19979@cindex injecting code
19980@cindex writing into executables
19981@cindex compiling code
19982
19983@value{GDBN} supports on-demand compilation and code injection into
19984programs running under @value{GDBN}. GCC 5.0 or higher built with
19985@file{libcc1.so} must be installed for this functionality to be enabled.
19986This functionality is implemented with the following commands.
19987
19988@table @code
19989@kindex compile code
19990@item compile code @var{source-code}
19991@itemx compile code -raw @var{--} @var{source-code}
19992Compile @var{source-code} with the compiler language found as the current
19993language in @value{GDBN} (@pxref{Languages}). If compilation and
19994injection is not supported with the current language specified in
19995@value{GDBN}, or the compiler does not support this feature, an error
19996message will be printed. If @var{source-code} compiles and links
19997successfully, @value{GDBN} will load the object-code emitted,
19998and execute it within the context of the currently selected inferior.
19999It is important to note that the compiled code is executed immediately.
20000After execution, the compiled code is removed from @value{GDBN} and any
20001new types or variables you have defined will be deleted.
20002
20003The command allows you to specify @var{source-code} in two ways.
20004The simplest method is to provide a single line of code to the command.
20005E.g.:
20006
20007@smallexample
20008compile code printf ("hello world\n");
20009@end smallexample
20010
20011If you specify options on the command line as well as source code, they
20012may conflict. The @samp{--} delimiter can be used to separate options
20013from actual source code. E.g.:
20014
20015@smallexample
20016compile code -r -- printf ("hello world\n");
20017@end smallexample
20018
20019Alternatively you can enter source code as multiple lines of text. To
20020enter this mode, invoke the @samp{compile code} command without any text
20021following the command. This will start the multiple-line editor and
20022allow you to type as many lines of source code as required. When you
20023have completed typing, enter @samp{end} on its own line to exit the
20024editor.
20025
20026@smallexample
20027compile code
20028>printf ("hello\n");
20029>printf ("world\n");
20030>end
20031@end smallexample
20032
20033Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
20034provided @var{source-code} in a callable scope. In this case, you must
20035specify the entry point of the code by defining a function named
20036@code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
20037inferior. Using @samp{-raw} option may be needed for example when
20038@var{source-code} requires @samp{#include} lines which may conflict with
20039inferior symbols otherwise.
20040
20041@kindex compile file
20042@item compile file @var{filename}
20043@itemx compile file -raw @var{filename}
20044Like @code{compile code}, but take the source code from @var{filename}.
20045
20046@smallexample
20047compile file /home/user/example.c
20048@end smallexample
20049@end table
20050
36de76f9 20051@table @code
3345721a
PA
20052@item compile print [[@var{options}] --] @var{expr}
20053@itemx compile print [[@var{options}] --] /@var{f} @var{expr}
36de76f9
JK
20054Compile and execute @var{expr} with the compiler language found as the
20055current language in @value{GDBN} (@pxref{Languages}). By default the
20056value of @var{expr} is printed in a format appropriate to its data type;
20057you can choose a different format by specifying @samp{/@var{f}}, where
20058@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
3345721a
PA
20059Formats}. The @code{compile print} command accepts the same options
20060as the @code{print} command; see @ref{print options}.
36de76f9 20061
3345721a
PA
20062@item compile print [[@var{options}] --]
20063@itemx compile print [[@var{options}] --] /@var{f}
36de76f9
JK
20064@cindex reprint the last value
20065Alternatively you can enter the expression (source code producing it) as
20066multiple lines of text. To enter this mode, invoke the @samp{compile print}
20067command without any text following the command. This will start the
20068multiple-line editor.
20069@end table
20070
e7a8570f
JK
20071@noindent
20072The process of compiling and injecting the code can be inspected using:
20073
20074@table @code
20075@anchor{set debug compile}
20076@item set debug compile
20077@cindex compile command debugging info
20078Turns on or off display of @value{GDBN} process of compiling and
20079injecting the code. The default is off.
20080
20081@item show debug compile
20082Displays the current state of displaying @value{GDBN} process of
20083compiling and injecting the code.
078a0207
KS
20084
20085@anchor{set debug compile-cplus-types}
20086@item set debug compile-cplus-types
20087@cindex compile C@t{++} type conversion
20088Turns on or off the display of C@t{++} type conversion debugging information.
20089The default is off.
20090
20091@item show debug compile-cplus-types
20092Displays the current state of displaying debugging information for
20093C@t{++} type conversion.
e7a8570f
JK
20094@end table
20095
20096@subsection Compilation options for the @code{compile} command
20097
20098@value{GDBN} needs to specify the right compilation options for the code
20099to be injected, in part to make its ABI compatible with the inferior
20100and in part to make the injected code compatible with @value{GDBN}'s
20101injecting process.
20102
20103@noindent
20104The options used, in increasing precedence:
20105
20106@table @asis
20107@item target architecture and OS options (@code{gdbarch})
20108These options depend on target processor type and target operating
20109system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
20110(@code{-m64}) compilation option.
20111
20112@item compilation options recorded in the target
20113@value{NGCC} (since version 4.7) stores the options used for compilation
20114into @code{DW_AT_producer} part of DWARF debugging information according
20115to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
20116explicitly specify @code{-g} during inferior compilation otherwise
20117@value{NGCC} produces no DWARF. This feature is only relevant for
20118platforms where @code{-g} produces DWARF by default, otherwise one may
20119try to enforce DWARF by using @code{-gdwarf-4}.
20120
20121@item compilation options set by @code{set compile-args}
20122@end table
20123
20124@noindent
20125You can override compilation options using the following command:
20126
20127@table @code
20128@item set compile-args
20129@cindex compile command options override
20130Set compilation options used for compiling and injecting code with the
20131@code{compile} commands. These options override any conflicting ones
20132from the target architecture and/or options stored during inferior
20133compilation.
20134
20135@item show compile-args
20136Displays the current state of compilation options override.
20137This does not show all the options actually used during compilation,
20138use @ref{set debug compile} for that.
20139@end table
20140
bb2ec1b3
TT
20141@subsection Caveats when using the @code{compile} command
20142
20143There are a few caveats to keep in mind when using the @code{compile}
20144command. As the caveats are different per language, the table below
20145highlights specific issues on a per language basis.
20146
20147@table @asis
20148@item C code examples and caveats
20149When the language in @value{GDBN} is set to @samp{C}, the compiler will
20150attempt to compile the source code with a @samp{C} compiler. The source
20151code provided to the @code{compile} command will have much the same
20152access to variables and types as it normally would if it were part of
20153the program currently being debugged in @value{GDBN}.
20154
20155Below is a sample program that forms the basis of the examples that
20156follow. This program has been compiled and loaded into @value{GDBN},
20157much like any other normal debugging session.
20158
20159@smallexample
20160void function1 (void)
20161@{
20162 int i = 42;
20163 printf ("function 1\n");
20164@}
20165
20166void function2 (void)
20167@{
20168 int j = 12;
20169 function1 ();
20170@}
20171
20172int main(void)
20173@{
20174 int k = 6;
20175 int *p;
20176 function2 ();
20177 return 0;
20178@}
20179@end smallexample
20180
20181For the purposes of the examples in this section, the program above has
20182been compiled, loaded into @value{GDBN}, stopped at the function
20183@code{main}, and @value{GDBN} is awaiting input from the user.
20184
20185To access variables and types for any program in @value{GDBN}, the
20186program must be compiled and packaged with debug information. The
20187@code{compile} command is not an exception to this rule. Without debug
20188information, you can still use the @code{compile} command, but you will
20189be very limited in what variables and types you can access.
20190
20191So with that in mind, the example above has been compiled with debug
20192information enabled. The @code{compile} command will have access to
20193all variables and types (except those that may have been optimized
20194out). Currently, as @value{GDBN} has stopped the program in the
20195@code{main} function, the @code{compile} command would have access to
20196the variable @code{k}. You could invoke the @code{compile} command
20197and type some source code to set the value of @code{k}. You can also
20198read it, or do anything with that variable you would normally do in
20199@code{C}. Be aware that changes to inferior variables in the
20200@code{compile} command are persistent. In the following example:
20201
20202@smallexample
20203compile code k = 3;
20204@end smallexample
20205
20206@noindent
20207the variable @code{k} is now 3. It will retain that value until
20208something else in the example program changes it, or another
20209@code{compile} command changes it.
20210
20211Normal scope and access rules apply to source code compiled and
20212injected by the @code{compile} command. In the example, the variables
20213@code{j} and @code{k} are not accessible yet, because the program is
20214currently stopped in the @code{main} function, where these variables
20215are not in scope. Therefore, the following command
20216
20217@smallexample
20218compile code j = 3;
20219@end smallexample
20220
20221@noindent
20222will result in a compilation error message.
20223
20224Once the program is continued, execution will bring these variables in
20225scope, and they will become accessible; then the code you specify via
20226the @code{compile} command will be able to access them.
20227
20228You can create variables and types with the @code{compile} command as
20229part of your source code. Variables and types that are created as part
20230of the @code{compile} command are not visible to the rest of the program for
20231the duration of its run. This example is valid:
20232
20233@smallexample
20234compile code int ff = 5; printf ("ff is %d\n", ff);
20235@end smallexample
20236
20237However, if you were to type the following into @value{GDBN} after that
20238command has completed:
20239
20240@smallexample
20241compile code printf ("ff is %d\n'', ff);
20242@end smallexample
20243
20244@noindent
20245a compiler error would be raised as the variable @code{ff} no longer
20246exists. Object code generated and injected by the @code{compile}
20247command is removed when its execution ends. Caution is advised
20248when assigning to program variables values of variables created by the
20249code submitted to the @code{compile} command. This example is valid:
20250
20251@smallexample
20252compile code int ff = 5; k = ff;
20253@end smallexample
20254
20255The value of the variable @code{ff} is assigned to @code{k}. The variable
20256@code{k} does not require the existence of @code{ff} to maintain the value
20257it has been assigned. However, pointers require particular care in
20258assignment. If the source code compiled with the @code{compile} command
20259changed the address of a pointer in the example program, perhaps to a
20260variable created in the @code{compile} command, that pointer would point
20261to an invalid location when the command exits. The following example
20262would likely cause issues with your debugged program:
20263
20264@smallexample
20265compile code int ff = 5; p = &ff;
20266@end smallexample
20267
20268In this example, @code{p} would point to @code{ff} when the
20269@code{compile} command is executing the source code provided to it.
20270However, as variables in the (example) program persist with their
20271assigned values, the variable @code{p} would point to an invalid
20272location when the command exists. A general rule should be followed
20273in that you should either assign @code{NULL} to any assigned pointers,
20274or restore a valid location to the pointer before the command exits.
20275
20276Similar caution must be exercised with any structs, unions, and typedefs
20277defined in @code{compile} command. Types defined in the @code{compile}
20278command will no longer be available in the next @code{compile} command.
20279Therefore, if you cast a variable to a type defined in the
20280@code{compile} command, care must be taken to ensure that any future
20281need to resolve the type can be achieved.
20282
20283@smallexample
20284(gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
20285(gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
20286gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
20287Compilation failed.
20288(gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
2028942
20290@end smallexample
20291
20292Variables that have been optimized away by the compiler are not
20293accessible to the code submitted to the @code{compile} command.
20294Access to those variables will generate a compiler error which @value{GDBN}
20295will print to the console.
20296@end table
20297
e7a8570f
JK
20298@subsection Compiler search for the @code{compile} command
20299
6e41ddec
JK
20300@value{GDBN} needs to find @value{NGCC} for the inferior being debugged
20301which may not be obvious for remote targets of different architecture
20302than where @value{GDBN} is running. Environment variable @code{PATH} on
e7a8570f 20303@value{GDBN} host is searched for @value{NGCC} binary matching the
6e41ddec
JK
20304target architecture and operating system. This search can be overriden
20305by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is
20306taken from shell that executed @value{GDBN}, it is not the value set by
20307@value{GDBN} command @code{set environment}). @xref{Environment}.
20308
e7a8570f
JK
20309
20310Specifically @code{PATH} is searched for binaries matching regular expression
20311@code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
20312debugged. @var{arch} is processor name --- multiarch is supported, so for
20313example both @code{i386} and @code{x86_64} targets look for pattern
20314@code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
20315for pattern @code{s390x?}. @var{os} is currently supported only for
20316pattern @code{linux(-gnu)?}.
20317
6e41ddec
JK
20318On Posix hosts the compiler driver @value{GDBN} needs to find also
20319shared library @file{libcc1.so} from the compiler. It is searched in
20320default shared library search path (overridable with usual environment
20321variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set
20322compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
20323according to the installation of the found compiler --- as possibly
20324specified by the @code{set compile-gcc} command.
20325
20326@table @code
20327@item set compile-gcc
20328@cindex compile command driver filename override
20329Set compilation command used for compiling and injecting code with the
20330@code{compile} commands. If this option is not set (it is set to
20331an empty string), the search described above will occur --- that is the
20332default.
20333
20334@item show compile-gcc
20335Displays the current compile command @value{NGCC} driver filename.
20336If set, it is the main command @command{gcc}, found usually for example
20337under name @file{x86_64-linux-gnu-gcc}.
20338@end table
20339
6d2ebf8b 20340@node GDB Files
c906108c
SS
20341@chapter @value{GDBN} Files
20342
7a292a7a
SS
20343@value{GDBN} needs to know the file name of the program to be debugged,
20344both in order to read its symbol table and in order to start your
20345program. To debug a core dump of a previous run, you must also tell
20346@value{GDBN} the name of the core dump file.
c906108c
SS
20347
20348@menu
20349* Files:: Commands to specify files
2b4bf6af 20350* File Caching:: Information about @value{GDBN}'s file caching
5b5d99cf 20351* Separate Debug Files:: Debugging information in separate files
608e2dbb 20352* MiniDebugInfo:: Debugging information in a special section
9291a0cd 20353* Index Files:: Index files speed up GDB
c906108c 20354* Symbol Errors:: Errors reading symbol files
b14b1491 20355* Data Files:: GDB data files
c906108c
SS
20356@end menu
20357
6d2ebf8b 20358@node Files
79a6e687 20359@section Commands to Specify Files
c906108c 20360
7a292a7a 20361@cindex symbol table
c906108c 20362@cindex core dump file
7a292a7a
SS
20363
20364You may want to specify executable and core dump file names. The usual
20365way to do this is at start-up time, using the arguments to
20366@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
20367Out of @value{GDBN}}).
c906108c
SS
20368
20369Occasionally it is necessary to change to a different file during a
397ca115
EZ
20370@value{GDBN} session. Or you may run @value{GDBN} and forget to
20371specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
20372via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
20373Program}). In these situations the @value{GDBN} commands to specify
0869d01b 20374new files are useful.
c906108c
SS
20375
20376@table @code
20377@cindex executable file
20378@kindex file
20379@item file @var{filename}
20380Use @var{filename} as the program to be debugged. It is read for its
20381symbols and for the contents of pure memory. It is also the program
20382executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
20383directory and the file is not found in the @value{GDBN} working directory,
20384@value{GDBN} uses the environment variable @code{PATH} as a list of
20385directories to search, just as the shell does when looking for a program
20386to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
20387and your program, using the @code{path} command.
20388
fc8be69e
EZ
20389@cindex unlinked object files
20390@cindex patching object files
20391You can load unlinked object @file{.o} files into @value{GDBN} using
20392the @code{file} command. You will not be able to ``run'' an object
20393file, but you can disassemble functions and inspect variables. Also,
20394if the underlying BFD functionality supports it, you could use
20395@kbd{gdb -write} to patch object files using this technique. Note
20396that @value{GDBN} can neither interpret nor modify relocations in this
20397case, so branches and some initialized variables will appear to go to
20398the wrong place. But this feature is still handy from time to time.
20399
c906108c
SS
20400@item file
20401@code{file} with no argument makes @value{GDBN} discard any information it
20402has on both executable file and the symbol table.
20403
20404@kindex exec-file
20405@item exec-file @r{[} @var{filename} @r{]}
20406Specify that the program to be run (but not the symbol table) is found
20407in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
20408if necessary to locate your program. Omitting @var{filename} means to
20409discard information on the executable file.
20410
20411@kindex symbol-file
d4d429d5 20412@item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
c906108c
SS
20413Read symbol table information from file @var{filename}. @code{PATH} is
20414searched when necessary. Use the @code{file} command to get both symbol
20415table and program to run from the same file.
20416
d4d429d5
PT
20417If an optional @var{offset} is specified, it is added to the start
20418address of each section in the symbol file. This is useful if the
20419program is relocated at runtime, such as the Linux kernel with kASLR
20420enabled.
20421
c906108c
SS
20422@code{symbol-file} with no argument clears out @value{GDBN} information on your
20423program's symbol table.
20424
ae5a43e0
DJ
20425The @code{symbol-file} command causes @value{GDBN} to forget the contents of
20426some breakpoints and auto-display expressions. This is because they may
20427contain pointers to the internal data recording symbols and data types,
20428which are part of the old symbol table data being discarded inside
20429@value{GDBN}.
c906108c
SS
20430
20431@code{symbol-file} does not repeat if you press @key{RET} again after
20432executing it once.
20433
20434When @value{GDBN} is configured for a particular environment, it
20435understands debugging information in whatever format is the standard
20436generated for that environment; you may use either a @sc{gnu} compiler, or
20437other compilers that adhere to the local conventions.
c906108c 20438Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 20439using @code{@value{NGCC}} you can generate debugging information for
c906108c 20440optimized code.
c906108c
SS
20441
20442For most kinds of object files, with the exception of old SVR3 systems
20443using COFF, the @code{symbol-file} command does not normally read the
20444symbol table in full right away. Instead, it scans the symbol table
20445quickly to find which source files and which symbols are present. The
20446details are read later, one source file at a time, as they are needed.
20447
20448The purpose of this two-stage reading strategy is to make @value{GDBN}
20449start up faster. For the most part, it is invisible except for
20450occasional pauses while the symbol table details for a particular source
20451file are being read. (The @code{set verbose} command can turn these
20452pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 20453Warnings and Messages}.)
c906108c 20454
c906108c
SS
20455We have not implemented the two-stage strategy for COFF yet. When the
20456symbol table is stored in COFF format, @code{symbol-file} reads the
20457symbol table data in full right away. Note that ``stabs-in-COFF''
20458still does the two-stage strategy, since the debug info is actually
20459in stabs format.
20460
20461@kindex readnow
20462@cindex reading symbols immediately
20463@cindex symbols, reading immediately
6ac33a4e
TT
20464@item symbol-file @r{[} -readnow @r{]} @var{filename}
20465@itemx file @r{[} -readnow @r{]} @var{filename}
c906108c
SS
20466You can override the @value{GDBN} two-stage strategy for reading symbol
20467tables by using the @samp{-readnow} option with any of the commands that
20468load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 20469entire symbol table available.
c906108c 20470
97cbe998
SDJ
20471@cindex @code{-readnever}, option for symbol-file command
20472@cindex never read symbols
20473@cindex symbols, never read
20474@item symbol-file @r{[} -readnever @r{]} @var{filename}
20475@itemx file @r{[} -readnever @r{]} @var{filename}
20476You can instruct @value{GDBN} to never read the symbolic information
20477contained in @var{filename} by using the @samp{-readnever} option.
20478@xref{--readnever}.
20479
c906108c
SS
20480@c FIXME: for now no mention of directories, since this seems to be in
20481@c flux. 13mar1992 status is that in theory GDB would look either in
20482@c current dir or in same dir as myprog; but issues like competing
20483@c GDB's, or clutter in system dirs, mean that in practice right now
20484@c only current dir is used. FFish says maybe a special GDB hierarchy
20485@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
20486@c files.
20487
c906108c 20488@kindex core-file
09d4efe1 20489@item core-file @r{[}@var{filename}@r{]}
4644b6e3 20490@itemx core
c906108c
SS
20491Specify the whereabouts of a core dump file to be used as the ``contents
20492of memory''. Traditionally, core files contain only some parts of the
20493address space of the process that generated them; @value{GDBN} can access the
20494executable file itself for other parts.
20495
20496@code{core-file} with no argument specifies that no core file is
20497to be used.
20498
20499Note that the core file is ignored when your program is actually running
7a292a7a
SS
20500under @value{GDBN}. So, if you have been running your program and you
20501wish to debug a core file instead, you must kill the subprocess in which
20502the program is running. To do this, use the @code{kill} command
79a6e687 20503(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 20504
c906108c
SS
20505@kindex add-symbol-file
20506@cindex dynamic linking
291f9a96 20507@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
20508The @code{add-symbol-file} command reads additional symbol table
20509information from the file @var{filename}. You would use this command
20510when @var{filename} has been dynamically loaded (by some other means)
ed6dfe51
PT
20511into the program that is running. The @var{textaddress} parameter gives
20512the memory address at which the file's text section has been loaded.
20513You can additionally specify the base address of other sections using
20514an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
20515If a section is omitted, @value{GDBN} will use its default addresses
20516as found in @var{filename}. Any @var{address} or @var{textaddress}
20517can be given as an expression.
c906108c 20518
291f9a96
PT
20519If an optional @var{offset} is specified, it is added to the start
20520address of each section, except those for which the address was
20521specified explicitly.
20522
c906108c
SS
20523The symbol table of the file @var{filename} is added to the symbol table
20524originally read with the @code{symbol-file} command. You can use the
96a2c332 20525@code{add-symbol-file} command any number of times; the new symbol data
98297bf6
NB
20526thus read is kept in addition to the old.
20527
20528Changes can be reverted using the command @code{remove-symbol-file}.
c906108c 20529
17d9d558
JB
20530@cindex relocatable object files, reading symbols from
20531@cindex object files, relocatable, reading symbols from
20532@cindex reading symbols from relocatable object files
20533@cindex symbols, reading from relocatable object files
20534@cindex @file{.o} files, reading symbols from
20535Although @var{filename} is typically a shared library file, an
20536executable file, or some other object file which has been fully
20537relocated for loading into a process, you can also load symbolic
20538information from relocatable @file{.o} files, as long as:
20539
20540@itemize @bullet
20541@item
20542the file's symbolic information refers only to linker symbols defined in
20543that file, not to symbols defined by other object files,
20544@item
20545every section the file's symbolic information refers to has actually
20546been loaded into the inferior, as it appears in the file, and
20547@item
20548you can determine the address at which every section was loaded, and
20549provide these to the @code{add-symbol-file} command.
20550@end itemize
20551
20552@noindent
20553Some embedded operating systems, like Sun Chorus and VxWorks, can load
20554relocatable files into an already running program; such systems
20555typically make the requirements above easy to meet. However, it's
20556important to recognize that many native systems use complex link
49efadf5 20557procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
20558assembly, for example) that make the requirements difficult to meet. In
20559general, one cannot assume that using @code{add-symbol-file} to read a
20560relocatable object file's symbolic information will have the same effect
20561as linking the relocatable object file into the program in the normal
20562way.
20563
c906108c
SS
20564@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
20565
98297bf6
NB
20566@kindex remove-symbol-file
20567@item remove-symbol-file @var{filename}
20568@item remove-symbol-file -a @var{address}
20569Remove a symbol file added via the @code{add-symbol-file} command. The
20570file to remove can be identified by its @var{filename} or by an @var{address}
20571that lies within the boundaries of this symbol file in memory. Example:
20572
20573@smallexample
20574(gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
20575add symbol table from file "/home/user/gdb/mylib.so" at
20576 .text_addr = 0x7ffff7ff9480
20577(y or n) y
0bab6cf1 20578Reading symbols from /home/user/gdb/mylib.so...
98297bf6
NB
20579(gdb) remove-symbol-file -a 0x7ffff7ff9480
20580Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
20581(gdb)
20582@end smallexample
20583
20584
20585@code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
20586
c45da7e6
EZ
20587@kindex add-symbol-file-from-memory
20588@cindex @code{syscall DSO}
20589@cindex load symbols from memory
20590@item add-symbol-file-from-memory @var{address}
20591Load symbols from the given @var{address} in a dynamically loaded
20592object file whose image is mapped directly into the inferior's memory.
20593For example, the Linux kernel maps a @code{syscall DSO} into each
20594process's address space; this DSO provides kernel-specific code for
20595some system calls. The argument can be any expression whose
20596evaluation yields the address of the file's shared object file header.
20597For this command to work, you must have used @code{symbol-file} or
20598@code{exec-file} commands in advance.
20599
c906108c 20600@kindex section
09d4efe1
EZ
20601@item section @var{section} @var{addr}
20602The @code{section} command changes the base address of the named
20603@var{section} of the exec file to @var{addr}. This can be used if the
20604exec file does not contain section addresses, (such as in the
20605@code{a.out} format), or when the addresses specified in the file
20606itself are wrong. Each section must be changed separately. The
20607@code{info files} command, described below, lists all the sections and
20608their addresses.
c906108c
SS
20609
20610@kindex info files
20611@kindex info target
20612@item info files
20613@itemx info target
7a292a7a
SS
20614@code{info files} and @code{info target} are synonymous; both print the
20615current target (@pxref{Targets, ,Specifying a Debugging Target}),
20616including the names of the executable and core dump files currently in
20617use by @value{GDBN}, and the files from which symbols were loaded. The
20618command @code{help target} lists all possible targets rather than
20619current ones.
20620
fe95c787 20621@kindex maint info sections
bf3386f0 20622@item maint info sections @r{[}-all-objects@r{]} @r{[}@var{filter-list}@r{]}
fe95c787
MS
20623Another command that can give you extra information about program sections
20624is @code{maint info sections}. In addition to the section information
20625displayed by @code{info files}, this command displays the flags and file
bf3386f0
AB
20626offset of each section in the executable and core dump files.
20627
20628When @samp{-all-objects} is passed then sections from all loaded object
20629files, including shared libraries, are printed.
20630
20631The optional @var{filter-list} is a space separated list of filter
20632keywords. Sections that match any one of the filter criteria will be
20633printed. There are two types of filter:
fe95c787
MS
20634
20635@table @code
bf3386f0
AB
20636@item @var{section-name}
20637Display information about any section named @var{section-name}.
20638@item @var{section-flag}
20639Display information for any section with @var{section-flag}. The
20640section flags that @value{GDBN} currently knows about are:
fe95c787
MS
20641@table @code
20642@item ALLOC
20643Section will have space allocated in the process when loaded.
20644Set for all sections except those containing debug information.
20645@item LOAD
20646Section will be loaded from the file into the child process memory.
20647Set for pre-initialized code and data, clear for @code{.bss} sections.
20648@item RELOC
20649Section needs to be relocated before loading.
20650@item READONLY
20651Section cannot be modified by the child process.
20652@item CODE
20653Section contains executable code only.
6600abed 20654@item DATA
fe95c787
MS
20655Section contains data only (no executable code).
20656@item ROM
20657Section will reside in ROM.
20658@item CONSTRUCTOR
20659Section contains data for constructor/destructor lists.
20660@item HAS_CONTENTS
20661Section is not empty.
20662@item NEVER_LOAD
20663An instruction to the linker to not output the section.
20664@item COFF_SHARED_LIBRARY
20665A notification to the linker that the section contains
20666COFF shared library information.
20667@item IS_COMMON
20668Section contains common symbols.
20669@end table
20670@end table
02a79309
AB
20671
20672@kindex maint info target-sections
20673@item maint info target-sections
20674This command prints @value{GDBN}'s internal section table. For each
20675target @value{GDBN} maintains a table containing the allocatable
20676sections from all currently mapped objects, along with information
20677about where the section is mapped.
20678
6763aef9 20679@kindex set trust-readonly-sections
9c16f35a 20680@cindex read-only sections
6763aef9
MS
20681@item set trust-readonly-sections on
20682Tell @value{GDBN} that readonly sections in your object file
6ca652b0 20683really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
20684In that case, @value{GDBN} can fetch values from these sections
20685out of the object file, rather than from the target program.
20686For some targets (notably embedded ones), this can be a significant
20687enhancement to debugging performance.
20688
20689The default is off.
20690
20691@item set trust-readonly-sections off
15110bc3 20692Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
20693the contents of the section might change while the program is running,
20694and must therefore be fetched from the target when needed.
9c16f35a
EZ
20695
20696@item show trust-readonly-sections
20697Show the current setting of trusting readonly sections.
c906108c
SS
20698@end table
20699
20700All file-specifying commands allow both absolute and relative file names
20701as arguments. @value{GDBN} always converts the file name to an absolute file
20702name and remembers it that way.
20703
c906108c 20704@cindex shared libraries
9cceb671 20705@anchor{Shared Libraries}
b1236ac3
PA
20706@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
20707Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
20708DSBT (TIC6X) shared libraries.
53a5351d 20709
9cceb671
DJ
20710On MS-Windows @value{GDBN} must be linked with the Expat library to support
20711shared libraries. @xref{Expat}.
20712
c906108c
SS
20713@value{GDBN} automatically loads symbol definitions from shared libraries
20714when you use the @code{run} command, or when you examine a core file.
20715(Before you issue the @code{run} command, @value{GDBN} does not understand
20716references to a function in a shared library, however---unless you are
20717debugging a core file).
53a5351d 20718
c906108c
SS
20719@c FIXME: some @value{GDBN} release may permit some refs to undef
20720@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
20721@c FIXME...lib; check this from time to time when updating manual
20722
b7209cb4
FF
20723There are times, however, when you may wish to not automatically load
20724symbol definitions from shared libraries, such as when they are
20725particularly large or there are many of them.
20726
20727To control the automatic loading of shared library symbols, use the
20728commands:
20729
20730@table @code
20731@kindex set auto-solib-add
20732@item set auto-solib-add @var{mode}
20733If @var{mode} is @code{on}, symbols from all shared object libraries
20734will be loaded automatically when the inferior begins execution, you
20735attach to an independently started inferior, or when the dynamic linker
20736informs @value{GDBN} that a new library has been loaded. If @var{mode}
20737is @code{off}, symbols must be loaded manually, using the
20738@code{sharedlibrary} command. The default value is @code{on}.
20739
dcaf7c2c
EZ
20740@cindex memory used for symbol tables
20741If your program uses lots of shared libraries with debug info that
20742takes large amounts of memory, you can decrease the @value{GDBN}
20743memory footprint by preventing it from automatically loading the
20744symbols from shared libraries. To that end, type @kbd{set
20745auto-solib-add off} before running the inferior, then load each
20746library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 20747@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
20748the libraries whose symbols you want to be loaded.
20749
b7209cb4
FF
20750@kindex show auto-solib-add
20751@item show auto-solib-add
20752Display the current autoloading mode.
20753@end table
20754
c45da7e6 20755@cindex load shared library
b7209cb4
FF
20756To explicitly load shared library symbols, use the @code{sharedlibrary}
20757command:
20758
c906108c
SS
20759@table @code
20760@kindex info sharedlibrary
20761@kindex info share
55333a84
DE
20762@item info share @var{regex}
20763@itemx info sharedlibrary @var{regex}
20764Print the names of the shared libraries which are currently loaded
20765that match @var{regex}. If @var{regex} is omitted then print
20766all shared libraries that are loaded.
c906108c 20767
b30a0bc3
JB
20768@kindex info dll
20769@item info dll @var{regex}
20770This is an alias of @code{info sharedlibrary}.
20771
c906108c
SS
20772@kindex sharedlibrary
20773@kindex share
20774@item sharedlibrary @var{regex}
20775@itemx share @var{regex}
c906108c
SS
20776Load shared object library symbols for files matching a
20777Unix regular expression.
20778As with files loaded automatically, it only loads shared libraries
20779required by your program for a core file or after typing @code{run}. If
20780@var{regex} is omitted all shared libraries required by your program are
20781loaded.
c45da7e6
EZ
20782
20783@item nosharedlibrary
20784@kindex nosharedlibrary
20785@cindex unload symbols from shared libraries
20786Unload all shared object library symbols. This discards all symbols
20787that have been loaded from all shared libraries. Symbols from shared
20788libraries that were loaded by explicit user requests are not
20789discarded.
c906108c
SS
20790@end table
20791
721c2651 20792Sometimes you may wish that @value{GDBN} stops and gives you control
edcc5120
TT
20793when any of shared library events happen. The best way to do this is
20794to use @code{catch load} and @code{catch unload} (@pxref{Set
20795Catchpoints}).
20796
09f2921c 20797@value{GDBN} also supports the @code{set stop-on-solib-events}
edcc5120
TT
20798command for this. This command exists for historical reasons. It is
20799less useful than setting a catchpoint, because it does not allow for
20800conditions or commands as a catchpoint does.
721c2651
EZ
20801
20802@table @code
20803@item set stop-on-solib-events
20804@kindex set stop-on-solib-events
20805This command controls whether @value{GDBN} should give you control
20806when the dynamic linker notifies it about some shared library event.
20807The most common event of interest is loading or unloading of a new
20808shared library.
20809
20810@item show stop-on-solib-events
20811@kindex show stop-on-solib-events
20812Show whether @value{GDBN} stops and gives you control when shared
20813library events happen.
20814@end table
20815
f5ebfba0 20816Shared libraries are also supported in many cross or remote debugging
f1838a98
UW
20817configurations. @value{GDBN} needs to have access to the target's libraries;
20818this can be accomplished either by providing copies of the libraries
20819on the host system, or by asking @value{GDBN} to automatically retrieve the
20820libraries from the target. If copies of the target libraries are
20821provided, they need to be the same as the target libraries, although the
f5ebfba0
DJ
20822copies on the target can be stripped as long as the copies on the host are
20823not.
20824
59b7b46f
EZ
20825@cindex where to look for shared libraries
20826For remote debugging, you need to tell @value{GDBN} where the target
20827libraries are, so that it can load the correct copies---otherwise, it
20828may try to load the host's libraries. @value{GDBN} has two variables
20829to specify the search directories for target libraries.
f5ebfba0
DJ
20830
20831@table @code
a9a5a3d1 20832@cindex prefix for executable and shared library file names
f822c95b 20833@cindex system root, alternate
f5ebfba0 20834@kindex set solib-absolute-prefix
f822c95b
DJ
20835@kindex set sysroot
20836@item set sysroot @var{path}
20837Use @var{path} as the system root for the program being debugged. Any
20838absolute shared library paths will be prefixed with @var{path}; many
20839runtime loaders store the absolute paths to the shared library in the
a9a5a3d1
GB
20840target program's memory. When starting processes remotely, and when
20841attaching to already-running processes (local or remote), their
20842executable filenames will be prefixed with @var{path} if reported to
20843@value{GDBN} as absolute by the operating system. If you use
20844@code{set sysroot} to find executables and shared libraries, they need
20845to be laid out in the same way that they are on the target, with
20846e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
20847@var{path}.
f822c95b 20848
599bd15c
GB
20849If @var{path} starts with the sequence @file{target:} and the target
20850system is remote then @value{GDBN} will retrieve the target binaries
20851from the remote system. This is only supported when using a remote
20852target that supports the @code{remote get} command (@pxref{File
20853Transfer,,Sending files to a remote system}). The part of @var{path}
20854following the initial @file{target:} (if present) is used as system
20855root prefix on the remote file system. If @var{path} starts with the
20856sequence @file{remote:} this is converted to the sequence
20857@file{target:} by @code{set sysroot}@footnote{Historically the
20858functionality to retrieve binaries from the remote system was
20859provided by prefixing @var{path} with @file{remote:}}. If you want
20860to specify a local system root using a directory that happens to be
20861named @file{target:} or @file{remote:}, you need to use some
20862equivalent variant of the name like @file{./target:}.
f1838a98 20863
18b8df43
AM
20864For targets with an MS-DOS based filesystem, such as MS-Windows,
20865@value{GDBN} tries prefixing a few variants of the target
ab38a727
PA
20866absolute file name with @var{path}. But first, on Unix hosts,
20867@value{GDBN} converts all backslash directory separators into forward
20868slashes, because the backslash is not a directory separator on Unix:
20869
20870@smallexample
20871 c:\foo\bar.dll @result{} c:/foo/bar.dll
20872@end smallexample
20873
20874Then, @value{GDBN} attempts prefixing the target file name with
20875@var{path}, and looks for the resulting file name in the host file
20876system:
20877
20878@smallexample
20879 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
20880@end smallexample
20881
a9a5a3d1 20882If that does not find the binary, @value{GDBN} tries removing
ab38a727
PA
20883the @samp{:} character from the drive spec, both for convenience, and,
20884for the case of the host file system not supporting file names with
20885colons:
20886
20887@smallexample
20888 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
20889@end smallexample
20890
20891This makes it possible to have a system root that mirrors a target
20892with more than one drive. E.g., you may want to setup your local
20893copies of the target system shared libraries like so (note @samp{c} vs
20894@samp{z}):
20895
20896@smallexample
20897 @file{/path/to/sysroot/c/sys/bin/foo.dll}
20898 @file{/path/to/sysroot/c/sys/bin/bar.dll}
20899 @file{/path/to/sysroot/z/sys/bin/bar.dll}
20900@end smallexample
20901
20902@noindent
20903and point the system root at @file{/path/to/sysroot}, so that
20904@value{GDBN} can find the correct copies of both
20905@file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
20906
a9a5a3d1 20907If that still does not find the binary, @value{GDBN} tries
ab38a727
PA
20908removing the whole drive spec from the target file name:
20909
20910@smallexample
20911 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
20912@end smallexample
20913
20914This last lookup makes it possible to not care about the drive name,
20915if you don't want or need to.
20916
f822c95b
DJ
20917The @code{set solib-absolute-prefix} command is an alias for @code{set
20918sysroot}.
20919
20920@cindex default system root
59b7b46f 20921@cindex @samp{--with-sysroot}
f822c95b
DJ
20922You can set the default system root by using the configure-time
20923@samp{--with-sysroot} option. If the system root is inside
20924@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
20925@samp{--exec-prefix}), then the default system root will be updated
20926automatically if the installed @value{GDBN} is moved to a new
20927location.
20928
20929@kindex show sysroot
20930@item show sysroot
a9a5a3d1 20931Display the current executable and shared library prefix.
f5ebfba0
DJ
20932
20933@kindex set solib-search-path
20934@item set solib-search-path @var{path}
f822c95b
DJ
20935If this variable is set, @var{path} is a colon-separated list of
20936directories to search for shared libraries. @samp{solib-search-path}
20937is used after @samp{sysroot} fails to locate the library, or if the
20938path to the library is relative instead of absolute. If you want to
20939use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 20940@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 20941finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 20942it to a nonexistent directory may interfere with automatic loading
f822c95b 20943of shared library symbols.
f5ebfba0
DJ
20944
20945@kindex show solib-search-path
20946@item show solib-search-path
20947Display the current shared library search path.
ab38a727
PA
20948
20949@cindex DOS file-name semantics of file names.
20950@kindex set target-file-system-kind (unix|dos-based|auto)
20951@kindex show target-file-system-kind
20952@item set target-file-system-kind @var{kind}
20953Set assumed file system kind for target reported file names.
20954
20955Shared library file names as reported by the target system may not
20956make sense as is on the system @value{GDBN} is running on. For
20957example, when remote debugging a target that has MS-DOS based file
20958system semantics, from a Unix host, the target may be reporting to
20959@value{GDBN} a list of loaded shared libraries with file names such as
20960@file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
20961drive letters, so the @samp{c:\} prefix is not normally understood as
20962indicating an absolute file name, and neither is the backslash
20963normally considered a directory separator character. In that case,
20964the native file system would interpret this whole absolute file name
20965as a relative file name with no directory components. This would make
20966it impossible to point @value{GDBN} at a copy of the remote target's
20967shared libraries on the host using @code{set sysroot}, and impractical
20968with @code{set solib-search-path}. Setting
20969@code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
20970to interpret such file names similarly to how the target would, and to
20971map them to file names valid on @value{GDBN}'s native file system
20972semantics. The value of @var{kind} can be @code{"auto"}, in addition
20973to one of the supported file system kinds. In that case, @value{GDBN}
20974tries to determine the appropriate file system variant based on the
20975current target's operating system (@pxref{ABI, ,Configuring the
20976Current ABI}). The supported file system settings are:
20977
20978@table @code
20979@item unix
20980Instruct @value{GDBN} to assume the target file system is of Unix
20981kind. Only file names starting the forward slash (@samp{/}) character
20982are considered absolute, and the directory separator character is also
20983the forward slash.
20984
20985@item dos-based
20986Instruct @value{GDBN} to assume the target file system is DOS based.
20987File names starting with either a forward slash, or a drive letter
20988followed by a colon (e.g., @samp{c:}), are considered absolute, and
20989both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
20990considered directory separators.
20991
20992@item auto
20993Instruct @value{GDBN} to use the file system kind associated with the
20994target operating system (@pxref{ABI, ,Configuring the Current ABI}).
20995This is the default.
20996@end table
f5ebfba0
DJ
20997@end table
20998
c011a4f4
DE
20999@cindex file name canonicalization
21000@cindex base name differences
21001When processing file names provided by the user, @value{GDBN}
21002frequently needs to compare them to the file names recorded in the
21003program's debug info. Normally, @value{GDBN} compares just the
21004@dfn{base names} of the files as strings, which is reasonably fast
21005even for very large programs. (The base name of a file is the last
21006portion of its name, after stripping all the leading directories.)
21007This shortcut in comparison is based upon the assumption that files
21008cannot have more than one base name. This is usually true, but
21009references to files that use symlinks or similar filesystem
21010facilities violate that assumption. If your program records files
21011using such facilities, or if you provide file names to @value{GDBN}
21012using symlinks etc., you can set @code{basenames-may-differ} to
21013@code{true} to instruct @value{GDBN} to completely canonicalize each
21014pair of file names it needs to compare. This will make file-name
21015comparisons accurate, but at a price of a significant slowdown.
21016
21017@table @code
21018@item set basenames-may-differ
21019@kindex set basenames-may-differ
21020Set whether a source file may have multiple base names.
21021
21022@item show basenames-may-differ
21023@kindex show basenames-may-differ
21024Show whether a source file may have multiple base names.
21025@end table
5b5d99cf 21026
18989b3c
AB
21027@node File Caching
21028@section File Caching
21029@cindex caching of opened files
21030@cindex caching of bfd objects
21031
21032To speed up file loading, and reduce memory usage, @value{GDBN} will
21033reuse the @code{bfd} objects used to track open files. @xref{Top, ,
21034BFD, bfd, The Binary File Descriptor Library}. The following commands
21035allow visibility and control of the caching behavior.
21036
21037@table @code
21038@kindex maint info bfds
21039@item maint info bfds
21040This prints information about each @code{bfd} object that is known to
21041@value{GDBN}.
21042
21043@kindex maint set bfd-sharing
21044@kindex maint show bfd-sharing
21045@kindex bfd caching
21046@item maint set bfd-sharing
21047@item maint show bfd-sharing
21048Control whether @code{bfd} objects can be shared. When sharing is
21049enabled @value{GDBN} reuses already open @code{bfd} objects rather
21050than reopening the same file. Turning sharing off does not cause
21051already shared @code{bfd} objects to be unshared, but all future files
21052that are opened will create a new @code{bfd} object. Similarly,
21053re-enabling sharing does not cause multiple existing @code{bfd}
21054objects to be collapsed into a single shared @code{bfd} object.
566f5e3b
AB
21055
21056@kindex set debug bfd-cache @var{level}
21057@kindex bfd caching
21058@item set debug bfd-cache @var{level}
21059Turns on debugging of the bfd cache, setting the level to @var{level}.
21060
21061@kindex show debug bfd-cache
21062@kindex bfd caching
21063@item show debug bfd-cache
21064Show the current debugging level of the bfd cache.
18989b3c
AB
21065@end table
21066
5b5d99cf
JB
21067@node Separate Debug Files
21068@section Debugging Information in Separate Files
21069@cindex separate debugging information files
21070@cindex debugging information in separate files
21071@cindex @file{.debug} subdirectories
21072@cindex debugging information directory, global
f307c045 21073@cindex global debugging information directories
c7e83d54
EZ
21074@cindex build ID, and separate debugging files
21075@cindex @file{.build-id} directory
5b5d99cf
JB
21076
21077@value{GDBN} allows you to put a program's debugging information in a
21078file separate from the executable itself, in a way that allows
21079@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
21080Since debugging information can be very large---sometimes larger
21081than the executable code itself---some systems distribute debugging
5b5d99cf
JB
21082information for their executables in separate files, which users can
21083install only when they need to debug a problem.
21084
c7e83d54
EZ
21085@value{GDBN} supports two ways of specifying the separate debug info
21086file:
5b5d99cf
JB
21087
21088@itemize @bullet
21089@item
c7e83d54
EZ
21090The executable contains a @dfn{debug link} that specifies the name of
21091the separate debug info file. The separate debug file's name is
21092usually @file{@var{executable}.debug}, where @var{executable} is the
21093name of the corresponding executable file without leading directories
21094(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
99e008fe
EZ
21095debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
21096checksum for the debug file, which @value{GDBN} uses to validate that
21097the executable and the debug file came from the same build.
c7e83d54
EZ
21098
21099@item
98c59b52 21100@anchor{build ID}
7e27a47a 21101The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 21102also present in the corresponding debug info file. (This is supported
c74f7d1c 21103only on some operating systems, when using the ELF or PE file formats
7e27a47a
EZ
21104for binary files and the @sc{gnu} Binutils.) For more details about
21105this feature, see the description of the @option{--build-id}
f5a476a7 21106command-line option in @ref{Options, , Command Line Options, ld,
7e27a47a
EZ
21107The GNU Linker}. The debug info file's name is not specified
21108explicitly by the build ID, but can be computed from the build ID, see
21109below.
d3750b24
JK
21110@end itemize
21111
c7e83d54
EZ
21112Depending on the way the debug info file is specified, @value{GDBN}
21113uses two different methods of looking for the debug file:
d3750b24
JK
21114
21115@itemize @bullet
21116@item
c7e83d54
EZ
21117For the ``debug link'' method, @value{GDBN} looks up the named file in
21118the directory of the executable file, then in a subdirectory of that
5f2459c2
EZ
21119directory named @file{.debug}, and finally under each one of the
21120global debug directories, in a subdirectory whose name is identical to
21121the leading directories of the executable's absolute file name. (On
21122MS-Windows/MS-DOS, the drive letter of the executable's leading
21123directories is converted to a one-letter subdirectory, i.e.@:
21124@file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
21125filesystems disallow colons in file names.)
c7e83d54
EZ
21126
21127@item
83f83d7f 21128For the ``build ID'' method, @value{GDBN} looks in the
f307c045
JK
21129@file{.build-id} subdirectory of each one of the global debug directories for
21130a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
21131first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
21132are the rest of the bit string. (Real build ID strings are 32 or more
21133hex characters, not 10.)
c7e83d54
EZ
21134@end itemize
21135
21136So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
21137@file{/usr/bin/ls}, which has a debug link that specifies the
21138file @file{ls.debug}, and a build ID whose value in hex is
f307c045 21139@code{abcdef1234}. If the list of the global debug directories includes
c7e83d54
EZ
21140@file{/usr/lib/debug}, then @value{GDBN} will look for the following
21141debug information files, in the indicated order:
21142
21143@itemize @minus
21144@item
21145@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 21146@item
c7e83d54 21147@file{/usr/bin/ls.debug}
5b5d99cf 21148@item
c7e83d54 21149@file{/usr/bin/.debug/ls.debug}
5b5d99cf 21150@item
c7e83d54 21151@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 21152@end itemize
5b5d99cf 21153
1564a261
JK
21154@anchor{debug-file-directory}
21155Global debugging info directories default to what is set by @value{GDBN}
21156configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
21157you can also set the global debugging info directories, and view the list
21158@value{GDBN} is currently using.
5b5d99cf
JB
21159
21160@table @code
21161
21162@kindex set debug-file-directory
24ddea62
JK
21163@item set debug-file-directory @var{directories}
21164Set the directories which @value{GDBN} searches for separate debugging
d9242c17
JK
21165information files to @var{directory}. Multiple path components can be set
21166concatenating them by a path separator.
5b5d99cf
JB
21167
21168@kindex show debug-file-directory
21169@item show debug-file-directory
24ddea62 21170Show the directories @value{GDBN} searches for separate debugging
5b5d99cf
JB
21171information files.
21172
21173@end table
21174
21175@cindex @code{.gnu_debuglink} sections
c7e83d54 21176@cindex debug link sections
5b5d99cf
JB
21177A debug link is a special section of the executable file named
21178@code{.gnu_debuglink}. The section must contain:
21179
21180@itemize
21181@item
21182A filename, with any leading directory components removed, followed by
21183a zero byte,
21184@item
21185zero to three bytes of padding, as needed to reach the next four-byte
21186boundary within the section, and
21187@item
21188a four-byte CRC checksum, stored in the same endianness used for the
21189executable file itself. The checksum is computed on the debugging
21190information file's full contents by the function given below, passing
21191zero as the @var{crc} argument.
21192@end itemize
21193
21194Any executable file format can carry a debug link, as long as it can
21195contain a section named @code{.gnu_debuglink} with the contents
21196described above.
21197
d3750b24 21198@cindex @code{.note.gnu.build-id} sections
c7e83d54 21199@cindex build ID sections
7e27a47a
EZ
21200The build ID is a special section in the executable file (and in other
21201ELF binary files that @value{GDBN} may consider). This section is
21202often named @code{.note.gnu.build-id}, but that name is not mandatory.
21203It contains unique identification for the built files---the ID remains
21204the same across multiple builds of the same build tree. The default
21205algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
21206content for the build ID string. The same section with an identical
21207value is present in the original built binary with symbols, in its
21208stripped variant, and in the separate debugging information file.
d3750b24 21209
5b5d99cf
JB
21210The debugging information file itself should be an ordinary
21211executable, containing a full set of linker symbols, sections, and
21212debugging information. The sections of the debugging information file
c7e83d54
EZ
21213should have the same names, addresses, and sizes as the original file,
21214but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
21215in an ordinary executable.
21216
7e27a47a 21217The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
21218@samp{objcopy} utility that can produce
21219the separated executable / debugging information file pairs using the
21220following commands:
21221
21222@smallexample
21223@kbd{objcopy --only-keep-debug foo foo.debug}
21224@kbd{strip -g foo}
c7e83d54
EZ
21225@end smallexample
21226
21227@noindent
21228These commands remove the debugging
83f83d7f
JK
21229information from the executable file @file{foo} and place it in the file
21230@file{foo.debug}. You can use the first, second or both methods to link the
21231two files:
21232
21233@itemize @bullet
21234@item
21235The debug link method needs the following additional command to also leave
21236behind a debug link in @file{foo}:
21237
21238@smallexample
21239@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
21240@end smallexample
21241
21242Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 21243a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
21244foo.debug} has the same functionality as the two @code{objcopy} commands and
21245the @code{ln -s} command above, together.
21246
21247@item
21248Build ID gets embedded into the main executable using @code{ld --build-id} or
21249the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
21250compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 21251utilities (Binutils) package since version 2.18.
83f83d7f
JK
21252@end itemize
21253
21254@noindent
d3750b24 21255
99e008fe
EZ
21256@cindex CRC algorithm definition
21257The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
21258IEEE 802.3 using the polynomial:
21259
21260@c TexInfo requires naked braces for multi-digit exponents for Tex
21261@c output, but this causes HTML output to barf. HTML has to be set using
21262@c raw commands. So we end up having to specify this equation in 2
21263@c different ways!
21264@ifhtml
21265@display
21266@html
21267 <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>
21268 + <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
21269@end html
21270@end display
21271@end ifhtml
21272@ifnothtml
21273@display
21274 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
21275 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
21276@end display
21277@end ifnothtml
21278
21279The function is computed byte at a time, taking the least
21280significant bit of each byte first. The initial pattern
21281@code{0xffffffff} is used, to ensure leading zeros affect the CRC and
21282the final result is inverted to ensure trailing zeros also affect the
21283CRC.
21284
21285@emph{Note:} This is the same CRC polynomial as used in handling the
936d2992
PA
21286@dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
21287However in the case of the Remote Serial Protocol, the CRC is computed
21288@emph{most} significant bit first, and the result is not inverted, so
21289trailing zeros have no effect on the CRC value.
99e008fe
EZ
21290
21291To complete the description, we show below the code of the function
21292which produces the CRC used in @code{.gnu_debuglink}. Inverting the
21293initially supplied @code{crc} argument means that an initial call to
21294this function passing in zero will start computing the CRC using
21295@code{0xffffffff}.
5b5d99cf 21296
4644b6e3 21297@kindex gnu_debuglink_crc32
5b5d99cf
JB
21298@smallexample
21299unsigned long
21300gnu_debuglink_crc32 (unsigned long crc,
21301 unsigned char *buf, size_t len)
21302@{
21303 static const unsigned long crc32_table[256] =
21304 @{
21305 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
21306 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
21307 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
21308 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
21309 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
21310 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
21311 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
21312 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
21313 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
21314 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
21315 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
21316 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
21317 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
21318 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
21319 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
21320 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
21321 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
21322 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
21323 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
21324 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
21325 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
21326 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
21327 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
21328 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
21329 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
21330 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
21331 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
21332 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
21333 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
21334 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
21335 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
21336 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
21337 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
21338 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
21339 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
21340 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
21341 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
21342 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
21343 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
21344 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
21345 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
21346 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
21347 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
21348 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
21349 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
21350 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
21351 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
21352 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
21353 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
21354 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
21355 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
21356 0x2d02ef8d
21357 @};
21358 unsigned char *end;
21359
21360 crc = ~crc & 0xffffffff;
21361 for (end = buf + len; buf < end; ++buf)
21362 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 21363 return ~crc & 0xffffffff;
5b5d99cf
JB
21364@}
21365@end smallexample
21366
c7e83d54
EZ
21367@noindent
21368This computation does not apply to the ``build ID'' method.
21369
608e2dbb
TT
21370@node MiniDebugInfo
21371@section Debugging information in a special section
21372@cindex separate debug sections
21373@cindex @samp{.gnu_debugdata} section
21374
21375Some systems ship pre-built executables and libraries that have a
21376special @samp{.gnu_debugdata} section. This feature is called
21377@dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
21378is used to supply extra symbols for backtraces.
21379
21380The intent of this section is to provide extra minimal debugging
21381information for use in simple backtraces. It is not intended to be a
21382replacement for full separate debugging information (@pxref{Separate
21383Debug Files}). The example below shows the intended use; however,
21384@value{GDBN} does not currently put restrictions on what sort of
21385debugging information might be included in the section.
21386
21387@value{GDBN} has support for this extension. If the section exists,
21388then it is used provided that no other source of debugging information
21389can be found, and that @value{GDBN} was configured with LZMA support.
21390
21391This section can be easily created using @command{objcopy} and other
21392standard utilities:
21393
21394@smallexample
21395# Extract the dynamic symbols from the main binary, there is no need
5423b017 21396# to also have these in the normal symbol table.
608e2dbb
TT
21397nm -D @var{binary} --format=posix --defined-only \
21398 | awk '@{ print $1 @}' | sort > dynsyms
21399
5423b017 21400# Extract all the text (i.e. function) symbols from the debuginfo.
1d236d23
JK
21401# (Note that we actually also accept "D" symbols, for the benefit
21402# of platforms like PowerPC64 that use function descriptors.)
608e2dbb 21403nm @var{binary} --format=posix --defined-only \
1d236d23 21404 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
608e2dbb
TT
21405 | sort > funcsyms
21406
21407# Keep all the function symbols not already in the dynamic symbol
21408# table.
21409comm -13 dynsyms funcsyms > keep_symbols
21410
edf9f00c
JK
21411# Separate full debug info into debug binary.
21412objcopy --only-keep-debug @var{binary} debug
21413
608e2dbb
TT
21414# Copy the full debuginfo, keeping only a minimal set of symbols and
21415# removing some unnecessary sections.
21416objcopy -S --remove-section .gdb_index --remove-section .comment \
edf9f00c
JK
21417 --keep-symbols=keep_symbols debug mini_debuginfo
21418
21419# Drop the full debug info from the original binary.
21420strip --strip-all -R .comment @var{binary}
608e2dbb
TT
21421
21422# Inject the compressed data into the .gnu_debugdata section of the
21423# original binary.
21424xz mini_debuginfo
21425objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
21426@end smallexample
5b5d99cf 21427
9291a0cd
TT
21428@node Index Files
21429@section Index Files Speed Up @value{GDBN}
21430@cindex index files
21431@cindex @samp{.gdb_index} section
21432
21433When @value{GDBN} finds a symbol file, it scans the symbols in the
21434file in order to construct an internal symbol table. This lets most
21435@value{GDBN} operations work quickly---at the cost of a delay early
21436on. For large programs, this delay can be quite lengthy, so
21437@value{GDBN} provides a way to build an index, which speeds up
21438startup.
21439
ba643918
SDJ
21440For convenience, @value{GDBN} comes with a program,
21441@command{gdb-add-index}, which can be used to add the index to a
21442symbol file. It takes the symbol file as its only argument:
21443
21444@smallexample
21445$ gdb-add-index symfile
21446@end smallexample
21447
21448@xref{gdb-add-index}.
21449
21450It is also possible to do the work manually. Here is what
21451@command{gdb-add-index} does behind the curtains.
21452
9291a0cd
TT
21453The index is stored as a section in the symbol file. @value{GDBN} can
21454write the index to a file, then you can put it into the symbol file
21455using @command{objcopy}.
21456
21457To create an index file, use the @code{save gdb-index} command:
21458
21459@table @code
437afbb8 21460@item save gdb-index [-dwarf-5] @var{directory}
9291a0cd 21461@kindex save gdb-index
437afbb8
JK
21462Create index files for all symbol files currently known by
21463@value{GDBN}. For each known @var{symbol-file}, this command by
21464default creates it produces a single file
21465@file{@var{symbol-file}.gdb-index}. If you invoke this command with
21466the @option{-dwarf-5} option, it produces 2 files:
21467@file{@var{symbol-file}.debug_names} and
21468@file{@var{symbol-file}.debug_str}. The files are created in the
21469given @var{directory}.
9291a0cd
TT
21470@end table
21471
21472Once you have created an index file you can merge it into your symbol
21473file, here named @file{symfile}, using @command{objcopy}:
21474
21475@smallexample
21476$ objcopy --add-section .gdb_index=symfile.gdb-index \
21477 --set-section-flags .gdb_index=readonly symfile symfile
21478@end smallexample
21479
437afbb8
JK
21480Or for @code{-dwarf-5}:
21481
21482@smallexample
21483$ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
21484$ cat symfile.debug_str >>symfile.debug_str.new
21485$ objcopy --add-section .debug_names=symfile.gdb-index \
21486 --set-section-flags .debug_names=readonly \
21487 --update-section .debug_str=symfile.debug_str.new symfile symfile
21488@end smallexample
21489
e615022a
DE
21490@value{GDBN} will normally ignore older versions of @file{.gdb_index}
21491sections that have been deprecated. Usually they are deprecated because
21492they are missing a new feature or have performance issues.
21493To tell @value{GDBN} to use a deprecated index section anyway
21494specify @code{set use-deprecated-index-sections on}.
21495The default is @code{off}.
21496This can speed up startup, but may result in some functionality being lost.
21497@xref{Index Section Format}.
21498
21499@emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
21500must be done before gdb reads the file. The following will not work:
21501
21502@smallexample
21503$ gdb -ex "set use-deprecated-index-sections on" <program>
21504@end smallexample
21505
21506Instead you must do, for example,
21507
21508@smallexample
21509$ gdb -iex "set use-deprecated-index-sections on" <program>
21510@end smallexample
21511
914592f9 21512Indices only work when using DWARF debugging information, not stabs.
9291a0cd 21513
7d11235d
SM
21514@subsection Automatic symbol index cache
21515
a0a3a1e9 21516@cindex automatic symbol index cache
7d11235d
SM
21517It is possible for @value{GDBN} to automatically save a copy of this index in a
21518cache on disk and retrieve it from there when loading the same binary in the
21519future. This feature can be turned on with @kbd{set index-cache on}. The
21520following commands can be used to tweak the behavior of the index cache.
21521
21522@table @code
21523
a0a3a1e9 21524@kindex set index-cache
7d11235d
SM
21525@item set index-cache on
21526@itemx set index-cache off
21527Enable or disable the use of the symbol index cache.
21528
21529@item set index-cache directory @var{directory}
a0a3a1e9 21530@kindex show index-cache
7d11235d 21531@itemx show index-cache directory
e6cd1dc1
TT
21532Set/show the directory where index files will be saved.
21533
21534The default value for this directory depends on the host platform. On
21535most systems, the index is cached in the @file{gdb} subdirectory of
21536the directory pointed to by the @env{XDG_CACHE_HOME} environment
21537variable, if it is defined, else in the @file{.cache/gdb} subdirectory
21538of your home directory. However, on some systems, the default may
21539differ according to local convention.
7d11235d
SM
21540
21541There is no limit on the disk space used by index cache. It is perfectly safe
21542to delete the content of that directory to free up disk space.
21543
21544@item show index-cache stats
21545Print the number of cache hits and misses since the launch of @value{GDBN}.
21546
21547@end table
21548
6d2ebf8b 21549@node Symbol Errors
79a6e687 21550@section Errors Reading Symbol Files
c906108c
SS
21551
21552While reading a symbol file, @value{GDBN} occasionally encounters problems,
21553such as symbol types it does not recognize, or known bugs in compiler
21554output. By default, @value{GDBN} does not notify you of such problems, since
21555they are relatively common and primarily of interest to people
21556debugging compilers. If you are interested in seeing information
21557about ill-constructed symbol tables, you can either ask @value{GDBN} to print
21558only one message about each such type of problem, no matter how many
21559times the problem occurs; or you can ask @value{GDBN} to print more messages,
21560to see how many times the problems occur, with the @code{set
79a6e687
BW
21561complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
21562Messages}).
c906108c
SS
21563
21564The messages currently printed, and their meanings, include:
21565
21566@table @code
21567@item inner block not inside outer block in @var{symbol}
21568
21569The symbol information shows where symbol scopes begin and end
21570(such as at the start of a function or a block of statements). This
21571error indicates that an inner scope block is not fully contained
21572in its outer scope blocks.
21573
21574@value{GDBN} circumvents the problem by treating the inner block as if it had
21575the same scope as the outer block. In the error message, @var{symbol}
21576may be shown as ``@code{(don't know)}'' if the outer block is not a
21577function.
21578
21579@item block at @var{address} out of order
21580
21581The symbol information for symbol scope blocks should occur in
21582order of increasing addresses. This error indicates that it does not
21583do so.
21584
21585@value{GDBN} does not circumvent this problem, and has trouble
21586locating symbols in the source file whose symbols it is reading. (You
21587can often determine what source file is affected by specifying
79a6e687
BW
21588@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
21589Messages}.)
c906108c
SS
21590
21591@item bad block start address patched
21592
21593The symbol information for a symbol scope block has a start address
21594smaller than the address of the preceding source line. This is known
21595to occur in the SunOS 4.1.1 (and earlier) C compiler.
21596
21597@value{GDBN} circumvents the problem by treating the symbol scope block as
21598starting on the previous source line.
21599
21600@item bad string table offset in symbol @var{n}
21601
21602@cindex foo
21603Symbol number @var{n} contains a pointer into the string table which is
21604larger than the size of the string table.
21605
21606@value{GDBN} circumvents the problem by considering the symbol to have the
21607name @code{foo}, which may cause other problems if many symbols end up
21608with this name.
21609
21610@item unknown symbol type @code{0x@var{nn}}
21611
7a292a7a
SS
21612The symbol information contains new data types that @value{GDBN} does
21613not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 21614uncomprehended information, in hexadecimal.
c906108c 21615
7a292a7a
SS
21616@value{GDBN} circumvents the error by ignoring this symbol information.
21617This usually allows you to debug your program, though certain symbols
c906108c 21618are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
21619debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
21620on @code{complain}, then go up to the function @code{read_dbx_symtab}
21621and examine @code{*bufp} to see the symbol.
c906108c
SS
21622
21623@item stub type has NULL name
c906108c 21624
7a292a7a 21625@value{GDBN} could not find the full definition for a struct or class.
c906108c 21626
7a292a7a 21627@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 21628The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
21629information that recent versions of the compiler should have output for
21630it.
c906108c
SS
21631
21632@item info mismatch between compiler and debugger
21633
21634@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 21635
c906108c
SS
21636@end table
21637
b14b1491
TT
21638@node Data Files
21639@section GDB Data Files
21640
21641@cindex prefix for data files
21642@value{GDBN} will sometimes read an auxiliary data file. These files
21643are kept in a directory known as the @dfn{data directory}.
21644
21645You can set the data directory's name, and view the name @value{GDBN}
21646is currently using.
21647
21648@table @code
21649@kindex set data-directory
21650@item set data-directory @var{directory}
21651Set the directory which @value{GDBN} searches for auxiliary data files
21652to @var{directory}.
21653
21654@kindex show data-directory
21655@item show data-directory
21656Show the directory @value{GDBN} searches for auxiliary data files.
21657@end table
21658
21659@cindex default data directory
21660@cindex @samp{--with-gdb-datadir}
21661You can set the default data directory by using the configure-time
21662@samp{--with-gdb-datadir} option. If the data directory is inside
21663@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21664@samp{--exec-prefix}), then the default data directory will be updated
21665automatically if the installed @value{GDBN} is moved to a new
21666location.
21667
aae1c79a
DE
21668The data directory may also be specified with the
21669@code{--data-directory} command line option.
21670@xref{Mode Options}.
21671
6d2ebf8b 21672@node Targets
c906108c 21673@chapter Specifying a Debugging Target
7a292a7a 21674
c906108c 21675@cindex debugging target
c906108c 21676A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
21677
21678Often, @value{GDBN} runs in the same host environment as your program;
21679in that case, the debugging target is specified as a side effect when
21680you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
21681flexibility---for example, running @value{GDBN} on a physically separate
21682host, or controlling a standalone system over a serial port or a
53a5351d
JM
21683realtime system over a TCP/IP connection---you can use the @code{target}
21684command to specify one of the target types configured for @value{GDBN}
79a6e687 21685(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 21686
a8f24a35
EZ
21687@cindex target architecture
21688It is possible to build @value{GDBN} for several different @dfn{target
21689architectures}. When @value{GDBN} is built like that, you can choose
21690one of the available architectures with the @kbd{set architecture}
21691command.
21692
21693@table @code
21694@kindex set architecture
21695@kindex show architecture
21696@item set architecture @var{arch}
21697This command sets the current target architecture to @var{arch}. The
21698value of @var{arch} can be @code{"auto"}, in addition to one of the
21699supported architectures.
21700
21701@item show architecture
21702Show the current target architecture.
9c16f35a
EZ
21703
21704@item set processor
21705@itemx processor
21706@kindex set processor
21707@kindex show processor
21708These are alias commands for, respectively, @code{set architecture}
21709and @code{show architecture}.
a8f24a35
EZ
21710@end table
21711
c906108c
SS
21712@menu
21713* Active Targets:: Active targets
21714* Target Commands:: Commands for managing targets
c906108c 21715* Byte Order:: Choosing target byte order
c906108c
SS
21716@end menu
21717
6d2ebf8b 21718@node Active Targets
79a6e687 21719@section Active Targets
7a292a7a 21720
c906108c
SS
21721@cindex stacking targets
21722@cindex active targets
21723@cindex multiple targets
21724
8ea5bce5 21725There are multiple classes of targets such as: processes, executable files or
c0edd9ed
JK
21726recording sessions. Core files belong to the process class, making core file
21727and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
21728on multiple active targets, one in each class. This allows you to (for
21729example) start a process and inspect its activity, while still having access to
21730the executable file after the process finishes. Or if you start process
21731recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
21732presented a virtual layer of the recording target, while the process target
21733remains stopped at the chronologically last point of the process execution.
21734
21735Use the @code{core-file} and @code{exec-file} commands to select a new core
21736file or executable target (@pxref{Files, ,Commands to Specify Files}). To
21737specify as a target a process that is already running, use the @code{attach}
21738command (@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 21739
6d2ebf8b 21740@node Target Commands
79a6e687 21741@section Commands for Managing Targets
c906108c
SS
21742
21743@table @code
21744@item target @var{type} @var{parameters}
7a292a7a
SS
21745Connects the @value{GDBN} host environment to a target machine or
21746process. A target is typically a protocol for talking to debugging
21747facilities. You use the argument @var{type} to specify the type or
21748protocol of the target machine.
c906108c
SS
21749
21750Further @var{parameters} are interpreted by the target protocol, but
21751typically include things like device names or host names to connect
21752with, process numbers, and baud rates.
c906108c
SS
21753
21754The @code{target} command does not repeat if you press @key{RET} again
21755after executing the command.
21756
21757@kindex help target
21758@item help target
21759Displays the names of all targets available. To display targets
21760currently selected, use either @code{info target} or @code{info files}
79a6e687 21761(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
21762
21763@item help target @var{name}
21764Describe a particular target, including any parameters necessary to
21765select it.
21766
21767@kindex set gnutarget
21768@item set gnutarget @var{args}
5d161b24 21769@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 21770knows whether it is reading an @dfn{executable},
5d161b24
DB
21771a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
21772with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
21773with @code{gnutarget} the @code{target} refers to a program, not a machine.
21774
d4f3574e 21775@quotation
c906108c
SS
21776@emph{Warning:} To specify a file format with @code{set gnutarget},
21777you must know the actual BFD name.
d4f3574e 21778@end quotation
c906108c 21779
d4f3574e 21780@noindent
79a6e687 21781@xref{Files, , Commands to Specify Files}.
c906108c 21782
5d161b24 21783@kindex show gnutarget
c906108c
SS
21784@item show gnutarget
21785Use the @code{show gnutarget} command to display what file format
21786@code{gnutarget} is set to read. If you have not set @code{gnutarget},
21787@value{GDBN} will determine the file format for each file automatically,
c4957902 21788and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
c906108c
SS
21789@end table
21790
4644b6e3 21791@cindex common targets
c906108c
SS
21792Here are some common targets (available, or not, depending on the GDB
21793configuration):
c906108c
SS
21794
21795@table @code
4644b6e3 21796@kindex target
c906108c 21797@item target exec @var{program}
4644b6e3 21798@cindex executable file target
c906108c
SS
21799An executable file. @samp{target exec @var{program}} is the same as
21800@samp{exec-file @var{program}}.
21801
c906108c 21802@item target core @var{filename}
4644b6e3 21803@cindex core dump file target
c906108c
SS
21804A core dump file. @samp{target core @var{filename}} is the same as
21805@samp{core-file @var{filename}}.
c906108c 21806
1a10341b 21807@item target remote @var{medium}
4644b6e3 21808@cindex remote target
1a10341b
JB
21809A remote system connected to @value{GDBN} via a serial line or network
21810connection. This command tells @value{GDBN} to use its own remote
21811protocol over @var{medium} for debugging. @xref{Remote Debugging}.
21812
21813For example, if you have a board connected to @file{/dev/ttya} on the
21814machine running @value{GDBN}, you could say:
21815
21816@smallexample
21817target remote /dev/ttya
21818@end smallexample
21819
21820@code{target remote} supports the @code{load} command. This is only
21821useful if you have some other way of getting the stub to the target
21822system, and you can put it somewhere in memory where it won't get
21823clobbered by the download.
c906108c 21824
ee8e71d4 21825@item target sim @r{[}@var{simargs}@r{]} @dots{}
4644b6e3 21826@cindex built-in simulator target
2df3850c 21827Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 21828In general,
474c8240 21829@smallexample
104c1213
JM
21830 target sim
21831 load
21832 run
474c8240 21833@end smallexample
d4f3574e 21834@noindent
104c1213 21835works; however, you cannot assume that a specific memory map, device
d4f3574e 21836drivers, or even basic I/O is available, although some simulators do
104c1213
JM
21837provide these. For info about any processor-specific simulator details,
21838see the appropriate section in @ref{Embedded Processors, ,Embedded
21839Processors}.
21840
6a3cb8e8
PA
21841@item target native
21842@cindex native target
21843Setup for local/native process debugging. Useful to make the
21844@code{run} command spawn native processes (likewise @code{attach},
21845etc.@:) even when @code{set auto-connect-native-target} is @code{off}
21846(@pxref{set auto-connect-native-target}).
21847
c906108c
SS
21848@end table
21849
5d161b24 21850Different targets are available on different configurations of @value{GDBN};
c906108c 21851your configuration may have more or fewer targets.
c906108c 21852
721c2651
EZ
21853Many remote targets require you to download the executable's code once
21854you've successfully established a connection. You may wish to control
3d00d119
DJ
21855various aspects of this process.
21856
21857@table @code
721c2651
EZ
21858
21859@item set hash
21860@kindex set hash@r{, for remote monitors}
21861@cindex hash mark while downloading
21862This command controls whether a hash mark @samp{#} is displayed while
21863downloading a file to the remote monitor. If on, a hash mark is
21864displayed after each S-record is successfully downloaded to the
21865monitor.
21866
21867@item show hash
21868@kindex show hash@r{, for remote monitors}
21869Show the current status of displaying the hash mark.
21870
21871@item set debug monitor
21872@kindex set debug monitor
21873@cindex display remote monitor communications
21874Enable or disable display of communications messages between
21875@value{GDBN} and the remote monitor.
21876
21877@item show debug monitor
21878@kindex show debug monitor
21879Show the current status of displaying communications between
21880@value{GDBN} and the remote monitor.
a8f24a35 21881@end table
c906108c
SS
21882
21883@table @code
21884
5cf30ebf
LM
21885@kindex load @var{filename} @var{offset}
21886@item load @var{filename} @var{offset}
8edfe269 21887@anchor{load}
c906108c
SS
21888Depending on what remote debugging facilities are configured into
21889@value{GDBN}, the @code{load} command may be available. Where it exists, it
21890is meant to make @var{filename} (an executable) available for debugging
21891on the remote system---by downloading, or dynamic linking, for example.
21892@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
21893the @code{add-symbol-file} command.
21894
21895If your @value{GDBN} does not have a @code{load} command, attempting to
21896execute it gets the error message ``@code{You can't do that when your
21897target is @dots{}}''
c906108c
SS
21898
21899The file is loaded at whatever address is specified in the executable.
21900For some object file formats, you can specify the load address when you
21901link the program; for other formats, like a.out, the object file format
21902specifies a fixed address.
21903@c FIXME! This would be a good place for an xref to the GNU linker doc.
21904
5cf30ebf
LM
21905It is also possible to tell @value{GDBN} to load the executable file at a
21906specific offset described by the optional argument @var{offset}. When
21907@var{offset} is provided, @var{filename} must also be provided.
21908
68437a39
DJ
21909Depending on the remote side capabilities, @value{GDBN} may be able to
21910load programs into flash memory.
21911
c906108c
SS
21912@code{load} does not repeat if you press @key{RET} again after using it.
21913@end table
21914
78cbbba8
LM
21915@table @code
21916
21917@kindex flash-erase
21918@item flash-erase
21919@anchor{flash-erase}
21920
21921Erases all known flash memory regions on the target.
21922
21923@end table
21924
6d2ebf8b 21925@node Byte Order
79a6e687 21926@section Choosing Target Byte Order
7a292a7a 21927
c906108c
SS
21928@cindex choosing target byte order
21929@cindex target byte order
c906108c 21930
eb17f351 21931Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
c906108c
SS
21932offer the ability to run either big-endian or little-endian byte
21933orders. Usually the executable or symbol will include a bit to
21934designate the endian-ness, and you will not need to worry about
21935which to use. However, you may still find it useful to adjust
d4f3574e 21936@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
21937
21938@table @code
4644b6e3 21939@kindex set endian
c906108c
SS
21940@item set endian big
21941Instruct @value{GDBN} to assume the target is big-endian.
21942
c906108c
SS
21943@item set endian little
21944Instruct @value{GDBN} to assume the target is little-endian.
21945
c906108c
SS
21946@item set endian auto
21947Instruct @value{GDBN} to use the byte order associated with the
21948executable.
21949
21950@item show endian
21951Display @value{GDBN}'s current idea of the target byte order.
21952
21953@end table
21954
4b2dfa9d
MR
21955If the @code{set endian auto} mode is in effect and no executable has
21956been selected, then the endianness used is the last one chosen either
21957by one of the @code{set endian big} and @code{set endian little}
21958commands or by inferring from the last executable used. If no
21959endianness has been previously chosen, then the default for this mode
21960is inferred from the target @value{GDBN} has been built for, and is
21961@code{little} if the name of the target CPU has an @code{el} suffix
21962and @code{big} otherwise.
21963
c906108c
SS
21964Note that these commands merely adjust interpretation of symbolic
21965data on the host, and that they have absolutely no effect on the
21966target system.
21967
ea35711c
DJ
21968
21969@node Remote Debugging
21970@chapter Debugging Remote Programs
c906108c
SS
21971@cindex remote debugging
21972
21973If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
21974@value{GDBN} in the usual way, it is often useful to use remote debugging.
21975For example, you might use remote debugging on an operating system kernel,
c906108c
SS
21976or on a small system which does not have a general purpose operating system
21977powerful enough to run a full-featured debugger.
21978
21979Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
21980to make this work with particular debugging targets. In addition,
5d161b24 21981@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
21982but not specific to any particular target system) which you can use if you
21983write the remote stubs---the code that runs on the remote system to
21984communicate with @value{GDBN}.
21985
21986Other remote targets may be available in your
21987configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 21988
6b2f586d 21989@menu
07f31aa6 21990* Connecting:: Connecting to a remote target
a6b151f1 21991* File Transfer:: Sending files to a remote system
6b2f586d 21992* Server:: Using the gdbserver program
79a6e687
BW
21993* Remote Configuration:: Remote configuration
21994* Remote Stub:: Implementing a remote stub
6b2f586d
AC
21995@end menu
21996
07f31aa6 21997@node Connecting
79a6e687 21998@section Connecting to a Remote Target
19d9d4ef
DB
21999@cindex remote debugging, connecting
22000@cindex @code{gdbserver}, connecting
22001@cindex remote debugging, types of connections
22002@cindex @code{gdbserver}, types of connections
22003@cindex @code{gdbserver}, @code{target remote} mode
22004@cindex @code{gdbserver}, @code{target extended-remote} mode
22005
22006This section describes how to connect to a remote target, including the
22007types of connections and their differences, how to set up executable and
22008symbol files on the host and target, and the commands used for
22009connecting to and disconnecting from the remote target.
22010
22011@subsection Types of Remote Connections
22012
22013@value{GDBN} supports two types of remote connections, @code{target remote}
22014mode and @code{target extended-remote} mode. Note that many remote targets
22015support only @code{target remote} mode. There are several major
22016differences between the two types of connections, enumerated here:
22017
22018@table @asis
22019
22020@cindex remote debugging, detach and program exit
22021@item Result of detach or program exit
22022@strong{With target remote mode:} When the debugged program exits or you
22023detach from it, @value{GDBN} disconnects from the target. When using
22024@code{gdbserver}, @code{gdbserver} will exit.
22025
22026@strong{With target extended-remote mode:} When the debugged program exits or
22027you detach from it, @value{GDBN} remains connected to the target, even
22028though no program is running. You can rerun the program, attach to a
22029running program, or use @code{monitor} commands specific to the target.
22030
22031When using @code{gdbserver} in this case, it does not exit unless it was
22032invoked using the @option{--once} option. If the @option{--once} option
22033was not used, you can ask @code{gdbserver} to exit using the
22034@code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
22035
22036@item Specifying the program to debug
22037For both connection types you use the @code{file} command to specify the
22038program on the host system. If you are using @code{gdbserver} there are
22039some differences in how to specify the location of the program on the
22040target.
22041
22042@strong{With target remote mode:} You must either specify the program to debug
22043on the @code{gdbserver} command line or use the @option{--attach} option
22044(@pxref{Attaching to a program,,Attaching to a Running Program}).
22045
22046@cindex @option{--multi}, @code{gdbserver} option
22047@strong{With target extended-remote mode:} You may specify the program to debug
22048on the @code{gdbserver} command line, or you can load the program or attach
22049to it using @value{GDBN} commands after connecting to @code{gdbserver}.
22050
22051@anchor{--multi Option in Types of Remote Connnections}
22052You can start @code{gdbserver} without supplying an initial command to run
22053or process ID to attach. To do this, use the @option{--multi} command line
22054option. Then you can connect using @code{target extended-remote} and start
22055the program you want to debug (see below for details on using the
22056@code{run} command in this scenario). Note that the conditions under which
22057@code{gdbserver} terminates depend on how @value{GDBN} connects to it
22058(@code{target remote} or @code{target extended-remote}). The
22059@option{--multi} option to @code{gdbserver} has no influence on that.
07f31aa6 22060
19d9d4ef
DB
22061@item The @code{run} command
22062@strong{With target remote mode:} The @code{run} command is not
22063supported. Once a connection has been established, you can use all
22064the usual @value{GDBN} commands to examine and change data. The
22065remote program is already running, so you can use commands like
22066@kbd{step} and @kbd{continue}.
22067
22068@strong{With target extended-remote mode:} The @code{run} command is
22069supported. The @code{run} command uses the value set by
22070@code{set remote exec-file} (@pxref{set remote exec-file}) to select
22071the program to run. Command line arguments are supported, except for
22072wildcard expansion and I/O redirection (@pxref{Arguments}).
22073
22074If you specify the program to debug on the command line, then the
22075@code{run} command is not required to start execution, and you can
22076resume using commands like @kbd{step} and @kbd{continue} as with
22077@code{target remote} mode.
22078
22079@anchor{Attaching in Types of Remote Connections}
22080@item Attaching
22081@strong{With target remote mode:} The @value{GDBN} command @code{attach} is
22082not supported. To attach to a running program using @code{gdbserver}, you
22083must use the @option{--attach} option (@pxref{Running gdbserver}).
22084
22085@strong{With target extended-remote mode:} To attach to a running program,
22086you may use the @code{attach} command after the connection has been
22087established. If you are using @code{gdbserver}, you may also invoke
22088@code{gdbserver} using the @option{--attach} option
22089(@pxref{Running gdbserver}).
22090
e47e48f6
PW
22091Some remote targets allow @value{GDBN} to determine the executable file running
22092in the process the debugger is attaching to. In such a case, @value{GDBN}
22093uses the value of @code{exec-file-mismatch} to handle a possible mismatch
22094between the executable file name running in the process and the name of the
22095current exec-file loaded by @value{GDBN} (@pxref{set exec-file-mismatch}).
22096
19d9d4ef
DB
22097@end table
22098
22099@anchor{Host and target files}
22100@subsection Host and Target Files
22101@cindex remote debugging, symbol files
22102@cindex symbol files, remote debugging
22103
22104@value{GDBN}, running on the host, needs access to symbol and debugging
22105information for your program running on the target. This requires
22106access to an unstripped copy of your program, and possibly any associated
22107symbol files. Note that this section applies equally to both @code{target
22108remote} mode and @code{target extended-remote} mode.
22109
22110Some remote targets (@pxref{qXfer executable filename read}, and
22111@pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
22112the same connection used to communicate with @value{GDBN}. With such a
22113target, if the remote program is unstripped, the only command you need is
22114@code{target remote} (or @code{target extended-remote}).
22115
22116If the remote program is stripped, or the target does not support remote
22117program file access, start up @value{GDBN} using the name of the local
1b6e6f5c 22118unstripped copy of your program as the first argument, or use the
19d9d4ef
DB
22119@code{file} command. Use @code{set sysroot} to specify the location (on
22120the host) of target libraries (unless your @value{GDBN} was compiled with
22121the correct sysroot using @code{--with-sysroot}). Alternatively, you
22122may use @code{set solib-search-path} to specify how @value{GDBN} locates
22123target libraries.
22124
22125The symbol file and target libraries must exactly match the executable
22126and libraries on the target, with one exception: the files on the host
22127system should not be stripped, even if the files on the target system
22128are. Mismatched or missing files will lead to confusing results
22129during debugging. On @sc{gnu}/Linux targets, mismatched or missing
22130files may also prevent @code{gdbserver} from debugging multi-threaded
22131programs.
07f31aa6 22132
19d9d4ef
DB
22133@subsection Remote Connection Commands
22134@cindex remote connection commands
c1168a2f
JD
22135@value{GDBN} can communicate with the target over a serial line, a
22136local Unix domain socket, or
86941c27
JB
22137over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
22138each case, @value{GDBN} uses the same protocol for debugging your
22139program; only the medium carrying the debugging packets varies. The
19d9d4ef
DB
22140@code{target remote} and @code{target extended-remote} commands
22141establish a connection to the target. Both commands accept the same
22142arguments, which indicate the medium to use:
86941c27
JB
22143
22144@table @code
22145
22146@item target remote @var{serial-device}
19d9d4ef 22147@itemx target extended-remote @var{serial-device}
07f31aa6 22148@cindex serial line, @code{target remote}
86941c27
JB
22149Use @var{serial-device} to communicate with the target. For example,
22150to use a serial line connected to the device named @file{/dev/ttyb}:
22151
22152@smallexample
22153target remote /dev/ttyb
22154@end smallexample
22155
07f31aa6 22156If you're using a serial line, you may want to give @value{GDBN} the
2446f5ea 22157@samp{--baud} option, or use the @code{set serial baud} command
0d12017b 22158(@pxref{Remote Configuration, set serial baud}) before the
9c16f35a 22159@code{target} command.
07f31aa6 22160
c1168a2f
JD
22161@item target remote @var{local-socket}
22162@itemx target extended-remote @var{local-socket}
22163@cindex local socket, @code{target remote}
22164@cindex Unix domain socket
22165Use @var{local-socket} to communicate with the target. For example,
22166to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
22167
22168@smallexample
22169target remote /tmp/gdb-socket0
22170@end smallexample
22171
22172Note that this command has the same form as the command to connect
22173to a serial line. @value{GDBN} will automatically determine which
22174kind of file you have specified and will make the appropriate kind
22175of connection.
22176This feature is not available if the host system does not support
22177Unix domain sockets.
22178
86941c27 22179@item target remote @code{@var{host}:@var{port}}
0ca4866a 22180@itemx target remote @code{[@var{host}]:@var{port}}
86941c27 22181@itemx target remote @code{tcp:@var{host}:@var{port}}
0ca4866a 22182@itemx target remote @code{tcp:[@var{host}]:@var{port}}
c7ab0aef
SDJ
22183@itemx target remote @code{tcp4:@var{host}:@var{port}}
22184@itemx target remote @code{tcp6:@var{host}:@var{port}}
0ca4866a 22185@itemx target remote @code{tcp6:[@var{host}]:@var{port}}
19d9d4ef 22186@itemx target extended-remote @code{@var{host}:@var{port}}
0ca4866a 22187@itemx target extended-remote @code{[@var{host}]:@var{port}}
19d9d4ef 22188@itemx target extended-remote @code{tcp:@var{host}:@var{port}}
0ca4866a 22189@itemx target extended-remote @code{tcp:[@var{host}]:@var{port}}
c7ab0aef
SDJ
22190@itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
22191@itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
0ca4866a 22192@itemx target extended-remote @code{tcp6:[@var{host}]:@var{port}}
86941c27 22193@cindex @acronym{TCP} port, @code{target remote}
6a0b3457 22194Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
c7ab0aef
SDJ
22195The @var{host} may be either a host name, a numeric @acronym{IPv4}
22196address, or a numeric @acronym{IPv6} address (with or without the
22197square brackets to separate the address from the port); @var{port}
22198must be a decimal number. The @var{host} could be the target machine
22199itself, if it is directly connected to the net, or it might be a
22200terminal server which in turn has a serial line to the target.
07f31aa6 22201
86941c27
JB
22202For example, to connect to port 2828 on a terminal server named
22203@code{manyfarms}:
07f31aa6
DJ
22204
22205@smallexample
22206target remote manyfarms:2828
22207@end smallexample
22208
c7ab0aef
SDJ
22209To connect to port 2828 on a terminal server whose address is
22210@code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
22211square bracket syntax:
22212
22213@smallexample
22214target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
22215@end smallexample
22216
22217@noindent
22218or explicitly specify the @acronym{IPv6} protocol:
22219
22220@smallexample
22221target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
22222@end smallexample
22223
22224This last example may be confusing to the reader, because there is no
22225visible separation between the hostname and the port number.
22226Therefore, we recommend the user to provide @acronym{IPv6} addresses
22227using square brackets for clarity. However, it is important to
22228mention that for @value{GDBN} there is no ambiguity: the number after
22229the last colon is considered to be the port number.
22230
86941c27
JB
22231If your remote target is actually running on the same machine as your
22232debugger session (e.g.@: a simulator for your target running on the
22233same host), you can omit the hostname. For example, to connect to
22234port 1234 on your local machine:
07f31aa6
DJ
22235
22236@smallexample
22237target remote :1234
22238@end smallexample
22239@noindent
22240
22241Note that the colon is still required here.
22242
86941c27 22243@item target remote @code{udp:@var{host}:@var{port}}
0ca4866a 22244@itemx target remote @code{udp:[@var{host}]:@var{port}}
c7ab0aef 22245@itemx target remote @code{udp4:@var{host}:@var{port}}
0ca4866a 22246@itemx target remote @code{udp6:[@var{host}]:@var{port}}
c7ab0aef 22247@itemx target extended-remote @code{udp:@var{host}:@var{port}}
19d9d4ef 22248@itemx target extended-remote @code{udp:@var{host}:@var{port}}
0ca4866a 22249@itemx target extended-remote @code{udp:[@var{host}]:@var{port}}
c7ab0aef
SDJ
22250@itemx target extended-remote @code{udp4:@var{host}:@var{port}}
22251@itemx target extended-remote @code{udp6:@var{host}:@var{port}}
0ca4866a 22252@itemx target extended-remote @code{udp6:[@var{host}]:@var{port}}
86941c27
JB
22253@cindex @acronym{UDP} port, @code{target remote}
22254Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
22255connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
22256
22257@smallexample
22258target remote udp:manyfarms:2828
22259@end smallexample
22260
86941c27
JB
22261When using a @acronym{UDP} connection for remote debugging, you should
22262keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
22263can silently drop packets on busy or unreliable networks, which will
22264cause havoc with your debugging session.
22265
66b8c7f6 22266@item target remote | @var{command}
19d9d4ef 22267@itemx target extended-remote | @var{command}
66b8c7f6
JB
22268@cindex pipe, @code{target remote} to
22269Run @var{command} in the background and communicate with it using a
22270pipe. The @var{command} is a shell command, to be parsed and expanded
22271by the system's command shell, @code{/bin/sh}; it should expect remote
22272protocol packets on its standard input, and send replies on its
22273standard output. You could use this to run a stand-alone simulator
22274that speaks the remote debugging protocol, to make net connections
22275using programs like @code{ssh}, or for other similar tricks.
22276
22277If @var{command} closes its standard output (perhaps by exiting),
22278@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
22279program has already exited, this will have no effect.)
22280
86941c27 22281@end table
07f31aa6 22282
07f31aa6
DJ
22283@cindex interrupting remote programs
22284@cindex remote programs, interrupting
22285Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 22286interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
22287program. This may or may not succeed, depending in part on the hardware
22288and the serial drivers the remote system uses. If you type the
22289interrupt character once again, @value{GDBN} displays this prompt:
22290
22291@smallexample
22292Interrupted while waiting for the program.
22293Give up (and stop debugging it)? (y or n)
22294@end smallexample
22295
19d9d4ef
DB
22296In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
22297the remote debugging session. (If you decide you want to try again later,
22298you can use @kbd{target remote} again to connect once more.) If you type
22299@kbd{n}, @value{GDBN} goes back to waiting.
22300
22301In @code{target extended-remote} mode, typing @kbd{n} will leave
22302@value{GDBN} connected to the target.
07f31aa6
DJ
22303
22304@table @code
22305@kindex detach (remote)
22306@item detach
22307When you have finished debugging the remote program, you can use the
22308@code{detach} command to release it from @value{GDBN} control.
22309Detaching from the target normally resumes its execution, but the results
22310will depend on your particular remote stub. After the @code{detach}
19d9d4ef
DB
22311command in @code{target remote} mode, @value{GDBN} is free to connect to
22312another target. In @code{target extended-remote} mode, @value{GDBN} is
22313still connected to the target.
07f31aa6
DJ
22314
22315@kindex disconnect
22316@item disconnect
19d9d4ef 22317The @code{disconnect} command closes the connection to the target, and
07f31aa6
DJ
22318the target is generally not resumed. It will wait for @value{GDBN}
22319(this instance or another one) to connect and continue debugging. After
22320the @code{disconnect} command, @value{GDBN} is again free to connect to
22321another target.
09d4efe1
EZ
22322
22323@cindex send command to remote monitor
fad38dfa
EZ
22324@cindex extend @value{GDBN} for remote targets
22325@cindex add new commands for external monitor
09d4efe1
EZ
22326@kindex monitor
22327@item monitor @var{cmd}
fad38dfa
EZ
22328This command allows you to send arbitrary commands directly to the
22329remote monitor. Since @value{GDBN} doesn't care about the commands it
22330sends like this, this command is the way to extend @value{GDBN}---you
22331can add new commands that only the external monitor will understand
22332and implement.
07f31aa6
DJ
22333@end table
22334
a6b151f1
DJ
22335@node File Transfer
22336@section Sending files to a remote system
22337@cindex remote target, file transfer
22338@cindex file transfer
22339@cindex sending files to remote systems
22340
22341Some remote targets offer the ability to transfer files over the same
22342connection used to communicate with @value{GDBN}. This is convenient
22343for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
22344running @code{gdbserver} over a network interface. For other targets,
22345e.g.@: embedded devices with only a single serial port, this may be
22346the only way to upload or download files.
22347
22348Not all remote targets support these commands.
22349
22350@table @code
22351@kindex remote put
22352@item remote put @var{hostfile} @var{targetfile}
22353Copy file @var{hostfile} from the host system (the machine running
22354@value{GDBN}) to @var{targetfile} on the target system.
22355
22356@kindex remote get
22357@item remote get @var{targetfile} @var{hostfile}
22358Copy file @var{targetfile} from the target system to @var{hostfile}
22359on the host system.
22360
22361@kindex remote delete
22362@item remote delete @var{targetfile}
22363Delete @var{targetfile} from the target system.
22364
22365@end table
22366
6f05cf9f 22367@node Server
79a6e687 22368@section Using the @code{gdbserver} Program
6f05cf9f
AC
22369
22370@kindex gdbserver
22371@cindex remote connection without stubs
22372@code{gdbserver} is a control program for Unix-like systems, which
22373allows you to connect your program with a remote @value{GDBN} via
19d9d4ef
DB
22374@code{target remote} or @code{target extended-remote}---but without
22375linking in the usual debugging stub.
6f05cf9f
AC
22376
22377@code{gdbserver} is not a complete replacement for the debugging stubs,
22378because it requires essentially the same operating-system facilities
22379that @value{GDBN} itself does. In fact, a system that can run
22380@code{gdbserver} to connect to a remote @value{GDBN} could also run
22381@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
22382because it is a much smaller program than @value{GDBN} itself. It is
22383also easier to port than all of @value{GDBN}, so you may be able to get
22384started more quickly on a new system by using @code{gdbserver}.
22385Finally, if you develop code for real-time systems, you may find that
22386the tradeoffs involved in real-time operation make it more convenient to
22387do as much development work as possible on another system, for example
22388by cross-compiling. You can use @code{gdbserver} to make a similar
22389choice for debugging.
22390
22391@value{GDBN} and @code{gdbserver} communicate via either a serial line
22392or a TCP connection, using the standard @value{GDBN} remote serial
22393protocol.
22394
2d717e4f
DJ
22395@quotation
22396@emph{Warning:} @code{gdbserver} does not have any built-in security.
22397Do not run @code{gdbserver} connected to any public network; a
22398@value{GDBN} connection to @code{gdbserver} provides access to the
22399target system with the same privileges as the user running
22400@code{gdbserver}.
22401@end quotation
22402
19d9d4ef 22403@anchor{Running gdbserver}
2d717e4f
DJ
22404@subsection Running @code{gdbserver}
22405@cindex arguments, to @code{gdbserver}
d9b1a651 22406@cindex @code{gdbserver}, command-line arguments
2d717e4f
DJ
22407
22408Run @code{gdbserver} on the target system. You need a copy of the
22409program you want to debug, including any libraries it requires.
6f05cf9f
AC
22410@code{gdbserver} does not need your program's symbol table, so you can
22411strip the program if necessary to save space. @value{GDBN} on the host
22412system does all the symbol handling.
22413
22414To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 22415the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
22416syntax is:
22417
22418@smallexample
22419target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
22420@end smallexample
22421
6cf36756
SM
22422@var{comm} is either a device name (to use a serial line), or a TCP
22423hostname and portnumber, or @code{-} or @code{stdio} to use
22424stdin/stdout of @code{gdbserver}.
e0f9f062 22425For example, to debug Emacs with the argument
6f05cf9f
AC
22426@samp{foo.txt} and communicate with @value{GDBN} over the serial port
22427@file{/dev/com1}:
22428
22429@smallexample
22430target> gdbserver /dev/com1 emacs foo.txt
22431@end smallexample
22432
6cf36756
SM
22433@code{gdbserver} waits passively for the host @value{GDBN} to communicate
22434with it.
6f05cf9f
AC
22435
22436To use a TCP connection instead of a serial line:
22437
22438@smallexample
22439target> gdbserver host:2345 emacs foo.txt
22440@end smallexample
22441
22442The only difference from the previous example is the first argument,
22443specifying that you are communicating with the host @value{GDBN} via
22444TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
22445expect a TCP connection from machine @samp{host} to local TCP port 2345.
22446(Currently, the @samp{host} part is ignored.) You can choose any number
22447you want for the port number as long as it does not conflict with any
22448TCP ports already in use on the target system (for example, @code{23} is
22449reserved for @code{telnet}).@footnote{If you choose a port number that
22450conflicts with another service, @code{gdbserver} prints an error message
22451and exits.} You must use the same port number with the host @value{GDBN}
22452@code{target remote} command.
22453
6cf36756
SM
22454The @code{stdio} connection is useful when starting @code{gdbserver}
22455with ssh:
e0f9f062
DE
22456
22457@smallexample
6cf36756 22458(gdb) target remote | ssh -T hostname gdbserver - hello
e0f9f062
DE
22459@end smallexample
22460
6cf36756
SM
22461The @samp{-T} option to ssh is provided because we don't need a remote pty,
22462and we don't want escape-character handling. Ssh does this by default when
22463a command is provided, the flag is provided to make it explicit.
22464You could elide it if you want to.
e0f9f062 22465
6cf36756
SM
22466Programs started with stdio-connected gdbserver have @file{/dev/null} for
22467@code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
22468display through a pipe connected to gdbserver.
22469Both @code{stdout} and @code{stderr} use the same pipe.
e0f9f062 22470
19d9d4ef 22471@anchor{Attaching to a program}
2d717e4f 22472@subsubsection Attaching to a Running Program
d9b1a651
EZ
22473@cindex attach to a program, @code{gdbserver}
22474@cindex @option{--attach}, @code{gdbserver} option
2d717e4f 22475
56460a61
DJ
22476On some targets, @code{gdbserver} can also attach to running programs.
22477This is accomplished via the @code{--attach} argument. The syntax is:
22478
22479@smallexample
2d717e4f 22480target> gdbserver --attach @var{comm} @var{pid}
56460a61
DJ
22481@end smallexample
22482
19d9d4ef
DB
22483@var{pid} is the process ID of a currently running process. It isn't
22484necessary to point @code{gdbserver} at a binary for the running process.
22485
22486In @code{target extended-remote} mode, you can also attach using the
22487@value{GDBN} attach command
22488(@pxref{Attaching in Types of Remote Connections}).
56460a61 22489
b1fe9455 22490@pindex pidof
b1fe9455
DJ
22491You can debug processes by name instead of process ID if your target has the
22492@code{pidof} utility:
22493
22494@smallexample
2d717e4f 22495target> gdbserver --attach @var{comm} `pidof @var{program}`
b1fe9455
DJ
22496@end smallexample
22497
f822c95b 22498In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
22499has multiple threads, most versions of @code{pidof} support the
22500@code{-s} option to only return the first process ID.
22501
03f2bd59
JK
22502@subsubsection TCP port allocation lifecycle of @code{gdbserver}
22503
19d9d4ef
DB
22504This section applies only when @code{gdbserver} is run to listen on a TCP
22505port.
03f2bd59
JK
22506
22507@code{gdbserver} normally terminates after all of its debugged processes have
22508terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
22509extended-remote}, @code{gdbserver} stays running even with no processes left.
22510@value{GDBN} normally terminates the spawned debugged process on its exit,
22511which normally also terminates @code{gdbserver} in the @kbd{target remote}
22512mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
22513cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
22514stays running even in the @kbd{target remote} mode.
22515
22516When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
22517Such reconnecting is useful for features like @ref{disconnected tracing}. For
22518completeness, at most one @value{GDBN} can be connected at a time.
22519
22520@cindex @option{--once}, @code{gdbserver} option
22521By default, @code{gdbserver} keeps the listening TCP port open, so that
6e8c5661 22522subsequent connections are possible. However, if you start @code{gdbserver}
03f2bd59
JK
22523with the @option{--once} option, it will stop listening for any further
22524connection attempts after connecting to the first @value{GDBN} session. This
22525means no further connections to @code{gdbserver} will be possible after the
22526first one. It also means @code{gdbserver} will terminate after the first
22527connection with remote @value{GDBN} has closed, even for unexpectedly closed
22528connections and even in the @kbd{target extended-remote} mode. The
22529@option{--once} option allows reusing the same port number for connecting to
22530multiple instances of @code{gdbserver} running on the same host, since each
22531instance closes its port after the first connection.
2d717e4f 22532
87ce2a04 22533@anchor{Other Command-Line Arguments for gdbserver}
2d717e4f
DJ
22534@subsubsection Other Command-Line Arguments for @code{gdbserver}
22535
19d9d4ef
DB
22536You can use the @option{--multi} option to start @code{gdbserver} without
22537specifying a program to debug or a process to attach to. Then you can
22538attach in @code{target extended-remote} mode and run or attach to a
22539program. For more information,
22540@pxref{--multi Option in Types of Remote Connnections}.
22541
d9b1a651 22542@cindex @option{--debug}, @code{gdbserver} option
62709adf 22543The @option{--debug} option tells @code{gdbserver} to display extra
d9b1a651
EZ
22544status information about the debugging process.
22545@cindex @option{--remote-debug}, @code{gdbserver} option
22546The @option{--remote-debug} option tells @code{gdbserver} to display
aeb2e706
AH
22547remote protocol debug output.
22548@cindex @option{--debug-file}, @code{gdbserver} option
22549@cindex @code{gdbserver}, send all debug output to a single file
22550The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
22551write any debug output to the given @var{filename}. These options are intended
22552for @code{gdbserver} development and for bug reports to the developers.
2d717e4f 22553
87ce2a04
DE
22554@cindex @option{--debug-format}, @code{gdbserver} option
22555The @option{--debug-format=option1[,option2,...]} option tells
22556@code{gdbserver} to include additional information in each output.
22557Possible options are:
22558
22559@table @code
22560@item none
22561Turn off all extra information in debugging output.
22562@item all
22563Turn on all extra information in debugging output.
22564@item timestamps
22565Include a timestamp in each line of debugging output.
22566@end table
22567
22568Options are processed in order. Thus, for example, if @option{none}
22569appears last then no additional information is added to debugging output.
22570
d9b1a651 22571@cindex @option{--wrapper}, @code{gdbserver} option
ccd213ac
DJ
22572The @option{--wrapper} option specifies a wrapper to launch programs
22573for debugging. The option should be followed by the name of the
22574wrapper, then any command-line arguments to pass to the wrapper, then
22575@kbd{--} indicating the end of the wrapper arguments.
22576
22577@code{gdbserver} runs the specified wrapper program with a combined
22578command line including the wrapper arguments, then the name of the
22579program to debug, then any arguments to the program. The wrapper
22580runs until it executes your program, and then @value{GDBN} gains control.
22581
22582You can use any program that eventually calls @code{execve} with
22583its arguments as a wrapper. Several standard Unix utilities do
22584this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
22585with @code{exec "$@@"} will also work.
22586
22587For example, you can use @code{env} to pass an environment variable to
22588the debugged program, without setting the variable in @code{gdbserver}'s
22589environment:
22590
22591@smallexample
22592$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
22593@end smallexample
22594
6d580b63
YQ
22595@cindex @option{--selftest}
22596The @option{--selftest} option runs the self tests in @code{gdbserver}:
22597
22598@smallexample
22599$ gdbserver --selftest
22600Ran 2 unit tests, 0 failed
22601@end smallexample
22602
22603These tests are disabled in release.
2d717e4f
DJ
22604@subsection Connecting to @code{gdbserver}
22605
19d9d4ef
DB
22606The basic procedure for connecting to the remote target is:
22607@itemize
2d717e4f 22608
19d9d4ef
DB
22609@item
22610Run @value{GDBN} on the host system.
f822c95b 22611
19d9d4ef
DB
22612@item
22613Make sure you have the necessary symbol files
22614(@pxref{Host and target files}).
22615Load symbols for your application using the @code{file} command before you
22616connect. Use @code{set sysroot} to locate target libraries (unless your
22617@value{GDBN} was compiled with the correct sysroot using
22618@code{--with-sysroot}).
f822c95b 22619
19d9d4ef 22620@item
79a6e687 22621Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f 22622For TCP connections, you must start up @code{gdbserver} prior to using
19d9d4ef 22623the @code{target} command. Otherwise you may get an error whose
6f05cf9f 22624text depends on the host system, but which usually looks something like
2d717e4f 22625@samp{Connection refused}. Don't use the @code{load}
19d9d4ef
DB
22626command in @value{GDBN} when using @code{target remote} mode, since the
22627program is already on the target.
22628
22629@end itemize
07f31aa6 22630
19d9d4ef 22631@anchor{Monitor Commands for gdbserver}
79a6e687 22632@subsection Monitor Commands for @code{gdbserver}
c74d0ad8
DJ
22633@cindex monitor commands, for @code{gdbserver}
22634
22635During a @value{GDBN} session using @code{gdbserver}, you can use the
22636@code{monitor} command to send special requests to @code{gdbserver}.
2d717e4f 22637Here are the available commands.
c74d0ad8
DJ
22638
22639@table @code
22640@item monitor help
22641List the available monitor commands.
22642
22643@item monitor set debug 0
22644@itemx monitor set debug 1
22645Disable or enable general debugging messages.
22646
22647@item monitor set remote-debug 0
22648@itemx monitor set remote-debug 1
22649Disable or enable specific debugging messages associated with the remote
22650protocol (@pxref{Remote Protocol}).
22651
aeb2e706
AH
22652@item monitor set debug-file filename
22653@itemx monitor set debug-file
22654Send any debug output to the given file, or to stderr.
22655
87ce2a04
DE
22656@item monitor set debug-format option1@r{[},option2,...@r{]}
22657Specify additional text to add to debugging messages.
22658Possible options are:
22659
22660@table @code
22661@item none
22662Turn off all extra information in debugging output.
22663@item all
22664Turn on all extra information in debugging output.
22665@item timestamps
22666Include a timestamp in each line of debugging output.
22667@end table
22668
22669Options are processed in order. Thus, for example, if @option{none}
22670appears last then no additional information is added to debugging output.
22671
cdbfd419
PP
22672@item monitor set libthread-db-search-path [PATH]
22673@cindex gdbserver, search path for @code{libthread_db}
22674When this command is issued, @var{path} is a colon-separated list of
22675directories to search for @code{libthread_db} (@pxref{Threads,,set
22676libthread-db-search-path}). If you omit @var{path},
84e578fb 22677@samp{libthread-db-search-path} will be reset to its default value.
cdbfd419 22678
98a5dd13
DE
22679The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
22680not supported in @code{gdbserver}.
22681
2d717e4f
DJ
22682@item monitor exit
22683Tell gdbserver to exit immediately. This command should be followed by
22684@code{disconnect} to close the debugging session. @code{gdbserver} will
22685detach from any attached processes and kill any processes it created.
22686Use @code{monitor exit} to terminate @code{gdbserver} at the end
22687of a multi-process mode debug session.
22688
c74d0ad8
DJ
22689@end table
22690
fa593d66
PA
22691@subsection Tracepoints support in @code{gdbserver}
22692@cindex tracepoints support in @code{gdbserver}
22693
0fb4aa4b
PA
22694On some targets, @code{gdbserver} supports tracepoints, fast
22695tracepoints and static tracepoints.
fa593d66 22696
0fb4aa4b 22697For fast or static tracepoints to work, a special library called the
fa593d66
PA
22698@dfn{in-process agent} (IPA), must be loaded in the inferior process.
22699This library is built and distributed as an integral part of
0fb4aa4b
PA
22700@code{gdbserver}. In addition, support for static tracepoints
22701requires building the in-process agent library with static tracepoints
22702support. At present, the UST (LTTng Userspace Tracer,
22703@url{http://lttng.org/ust}) tracing engine is supported. This support
22704is automatically available if UST development headers are found in the
22705standard include path when @code{gdbserver} is built, or if
22706@code{gdbserver} was explicitly configured using @option{--with-ust}
22707to point at such headers. You can explicitly disable the support
22708using @option{--with-ust=no}.
fa593d66
PA
22709
22710There are several ways to load the in-process agent in your program:
22711
22712@table @code
22713@item Specifying it as dependency at link time
22714
22715You can link your program dynamically with the in-process agent
22716library. On most systems, this is accomplished by adding
22717@code{-linproctrace} to the link command.
22718
22719@item Using the system's preloading mechanisms
22720
22721You can force loading the in-process agent at startup time by using
22722your system's support for preloading shared libraries. Many Unixes
22723support the concept of preloading user defined libraries. In most
22724cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
22725in the environment. See also the description of @code{gdbserver}'s
22726@option{--wrapper} command line option.
22727
22728@item Using @value{GDBN} to force loading the agent at run time
22729
22730On some systems, you can force the inferior to load a shared library,
22731by calling a dynamic loader function in the inferior that takes care
22732of dynamically looking up and loading a shared library. On most Unix
22733systems, the function is @code{dlopen}. You'll use the @code{call}
22734command for that. For example:
22735
22736@smallexample
22737(@value{GDBP}) call dlopen ("libinproctrace.so", ...)
22738@end smallexample
22739
22740Note that on most Unix systems, for the @code{dlopen} function to be
22741available, the program needs to be linked with @code{-ldl}.
22742@end table
22743
22744On systems that have a userspace dynamic loader, like most Unix
22745systems, when you connect to @code{gdbserver} using @code{target
22746remote}, you'll find that the program is stopped at the dynamic
22747loader's entry point, and no shared library has been loaded in the
22748program's address space yet, including the in-process agent. In that
0fb4aa4b
PA
22749case, before being able to use any of the fast or static tracepoints
22750features, you need to let the loader run and load the shared
22751libraries. The simplest way to do that is to run the program to the
22752main procedure. E.g., if debugging a C or C@t{++} program, start
fa593d66
PA
22753@code{gdbserver} like so:
22754
22755@smallexample
22756$ gdbserver :9999 myprogram
22757@end smallexample
22758
22759Start GDB and connect to @code{gdbserver} like so, and run to main:
22760
22761@smallexample
22762$ gdb myprogram
22763(@value{GDBP}) target remote myhost:9999
227640x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
22765(@value{GDBP}) b main
22766(@value{GDBP}) continue
22767@end smallexample
22768
22769The in-process tracing agent library should now be loaded into the
22770process; you can confirm it with the @code{info sharedlibrary}
22771command, which will list @file{libinproctrace.so} as loaded in the
0fb4aa4b
PA
22772process. You are now ready to install fast tracepoints, list static
22773tracepoint markers, probe static tracepoints markers, and start
fa593d66
PA
22774tracing.
22775
79a6e687
BW
22776@node Remote Configuration
22777@section Remote Configuration
501eef12 22778
9c16f35a
EZ
22779@kindex set remote
22780@kindex show remote
22781This section documents the configuration options available when
22782debugging remote programs. For the options related to the File I/O
fc320d37 22783extensions of the remote protocol, see @ref{system,
9c16f35a 22784system-call-allowed}.
501eef12
AC
22785
22786@table @code
9c16f35a 22787@item set remoteaddresssize @var{bits}
d3e8051b 22788@cindex address size for remote targets
9c16f35a
EZ
22789@cindex bits in remote address
22790Set the maximum size of address in a memory packet to the specified
22791number of bits. @value{GDBN} will mask off the address bits above
22792that number, when it passes addresses to the remote target. The
22793default value is the number of bits in the target's address.
22794
22795@item show remoteaddresssize
22796Show the current value of remote address size in bits.
22797
0d12017b 22798@item set serial baud @var{n}
9c16f35a
EZ
22799@cindex baud rate for remote targets
22800Set the baud rate for the remote serial I/O to @var{n} baud. The
22801value is used to set the speed of the serial port used for debugging
22802remote targets.
22803
0d12017b 22804@item show serial baud
9c16f35a
EZ
22805Show the current speed of the remote connection.
22806
236af5e3
YG
22807@item set serial parity @var{parity}
22808Set the parity for the remote serial I/O. Supported values of @var{parity} are:
22809@code{even}, @code{none}, and @code{odd}. The default is @code{none}.
22810
22811@item show serial parity
22812Show the current parity of the serial port.
22813
9c16f35a
EZ
22814@item set remotebreak
22815@cindex interrupt remote programs
22816@cindex BREAK signal instead of Ctrl-C
9a6253be 22817@anchor{set remotebreak}
9c16f35a 22818If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 22819when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 22820on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
22821character instead. The default is off, since most remote systems
22822expect to see @samp{Ctrl-C} as the interrupt signal.
22823
22824@item show remotebreak
22825Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
22826interrupt the remote program.
22827
23776285
MR
22828@item set remoteflow on
22829@itemx set remoteflow off
22830@kindex set remoteflow
22831Enable or disable hardware flow control (@code{RTS}/@code{CTS})
22832on the serial port used to communicate to the remote target.
22833
22834@item show remoteflow
22835@kindex show remoteflow
22836Show the current setting of hardware flow control.
22837
9c16f35a
EZ
22838@item set remotelogbase @var{base}
22839Set the base (a.k.a.@: radix) of logging serial protocol
22840communications to @var{base}. Supported values of @var{base} are:
22841@code{ascii}, @code{octal}, and @code{hex}. The default is
22842@code{ascii}.
22843
22844@item show remotelogbase
22845Show the current setting of the radix for logging remote serial
22846protocol.
22847
22848@item set remotelogfile @var{file}
22849@cindex record serial communications on file
22850Record remote serial communications on the named @var{file}. The
22851default is not to record at all.
22852
2d8b6830 22853@item show remotelogfile
9c16f35a
EZ
22854Show the current setting of the file name on which to record the
22855serial communications.
22856
22857@item set remotetimeout @var{num}
22858@cindex timeout for serial communications
22859@cindex remote timeout
22860Set the timeout limit to wait for the remote target to respond to
22861@var{num} seconds. The default is 2 seconds.
22862
22863@item show remotetimeout
22864Show the current number of seconds to wait for the remote target
22865responses.
22866
22867@cindex limit hardware breakpoints and watchpoints
22868@cindex remote target, limit break- and watchpoints
501eef12
AC
22869@anchor{set remote hardware-watchpoint-limit}
22870@anchor{set remote hardware-breakpoint-limit}
22871@item set remote hardware-watchpoint-limit @var{limit}
22872@itemx set remote hardware-breakpoint-limit @var{limit}
055303e2
AB
22873Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
22874or breakpoints. The @var{limit} can be set to 0 to disable hardware
22875watchpoints or breakpoints, and @code{unlimited} for unlimited
22876watchpoints or breakpoints.
22877
22878@item show remote hardware-watchpoint-limit
22879@itemx show remote hardware-breakpoint-limit
22880Show the current limit for the number of hardware watchpoints or
22881breakpoints that @value{GDBN} can use.
2d717e4f 22882
480a3f21
PW
22883@cindex limit hardware watchpoints length
22884@cindex remote target, limit watchpoints length
22885@anchor{set remote hardware-watchpoint-length-limit}
22886@item set remote hardware-watchpoint-length-limit @var{limit}
055303e2
AB
22887Restrict @value{GDBN} to using @var{limit} bytes for the maximum
22888length of a remote hardware watchpoint. A @var{limit} of 0 disables
22889hardware watchpoints and @code{unlimited} allows watchpoints of any
22890length.
480a3f21
PW
22891
22892@item show remote hardware-watchpoint-length-limit
22893Show the current limit (in bytes) of the maximum length of
22894a remote hardware watchpoint.
22895
2d717e4f
DJ
22896@item set remote exec-file @var{filename}
22897@itemx show remote exec-file
22898@anchor{set remote exec-file}
22899@cindex executable file, for remote target
22900Select the file used for @code{run} with @code{target
22901extended-remote}. This should be set to a filename valid on the
22902target system. If it is not set, the target will use a default
22903filename (e.g.@: the last program run).
84603566 22904
9a7071a8
JB
22905@item set remote interrupt-sequence
22906@cindex interrupt remote programs
22907@cindex select Ctrl-C, BREAK or BREAK-g
22908Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
22909@samp{BREAK-g} as the
22910sequence to the remote target in order to interrupt the execution.
22911@samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
22912is high level of serial line for some certain time.
22913Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
22914It is @code{BREAK} signal followed by character @code{g}.
22915
22e6d16f 22916@item show remote interrupt-sequence
9a7071a8
JB
22917Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
22918is sent by @value{GDBN} to interrupt the remote program.
22919@code{BREAK-g} is BREAK signal followed by @code{g} and
22920also known as Magic SysRq g.
22921
22922@item set remote interrupt-on-connect
22923@cindex send interrupt-sequence on start
22924Specify whether interrupt-sequence is sent to remote target when
22925@value{GDBN} connects to it. This is mostly needed when you debug
22926Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
22927which is known as Magic SysRq g in order to connect @value{GDBN}.
22928
22e6d16f 22929@item show remote interrupt-on-connect
9a7071a8
JB
22930Show whether interrupt-sequence is sent
22931to remote target when @value{GDBN} connects to it.
22932
84603566
SL
22933@kindex set tcp
22934@kindex show tcp
22935@item set tcp auto-retry on
22936@cindex auto-retry, for remote TCP target
22937Enable auto-retry for remote TCP connections. This is useful if the remote
22938debugging agent is launched in parallel with @value{GDBN}; there is a race
22939condition because the agent may not become ready to accept the connection
22940before @value{GDBN} attempts to connect. When auto-retry is
22941enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
22942to establish the connection using the timeout specified by
22943@code{set tcp connect-timeout}.
22944
22945@item set tcp auto-retry off
22946Do not auto-retry failed TCP connections.
22947
22948@item show tcp auto-retry
22949Show the current auto-retry setting.
22950
22951@item set tcp connect-timeout @var{seconds}
f81d1120 22952@itemx set tcp connect-timeout unlimited
84603566
SL
22953@cindex connection timeout, for remote TCP target
22954@cindex timeout, for remote target connection
22955Set the timeout for establishing a TCP connection to the remote target to
22956@var{seconds}. The timeout affects both polling to retry failed connections
22957(enabled by @code{set tcp auto-retry on}) and waiting for connections
22958that are merely slow to complete, and represents an approximate cumulative
f81d1120
PA
22959value. If @var{seconds} is @code{unlimited}, there is no timeout and
22960@value{GDBN} will keep attempting to establish a connection forever,
22961unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
84603566
SL
22962
22963@item show tcp connect-timeout
22964Show the current connection timeout setting.
501eef12
AC
22965@end table
22966
427c3a89
DJ
22967@cindex remote packets, enabling and disabling
22968The @value{GDBN} remote protocol autodetects the packets supported by
22969your debugging stub. If you need to override the autodetection, you
22970can use these commands to enable or disable individual packets. Each
22971packet can be set to @samp{on} (the remote target supports this
22972packet), @samp{off} (the remote target does not support this packet),
22973or @samp{auto} (detect remote target support for this packet). They
22974all default to @samp{auto}. For more information about each packet,
22975see @ref{Remote Protocol}.
22976
22977During normal use, you should not have to use any of these commands.
22978If you do, that may be a bug in your remote debugging stub, or a bug
22979in @value{GDBN}. You may want to report the problem to the
22980@value{GDBN} developers.
22981
cfa9d6d9
DJ
22982For each packet @var{name}, the command to enable or disable the
22983packet is @code{set remote @var{name}-packet}. The available settings
22984are:
427c3a89 22985
cfa9d6d9 22986@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
22987@item Command Name
22988@tab Remote Packet
22989@tab Related Features
22990
cfa9d6d9 22991@item @code{fetch-register}
427c3a89
DJ
22992@tab @code{p}
22993@tab @code{info registers}
22994
cfa9d6d9 22995@item @code{set-register}
427c3a89
DJ
22996@tab @code{P}
22997@tab @code{set}
22998
cfa9d6d9 22999@item @code{binary-download}
427c3a89
DJ
23000@tab @code{X}
23001@tab @code{load}, @code{set}
23002
cfa9d6d9 23003@item @code{read-aux-vector}
427c3a89
DJ
23004@tab @code{qXfer:auxv:read}
23005@tab @code{info auxv}
23006
cfa9d6d9 23007@item @code{symbol-lookup}
427c3a89
DJ
23008@tab @code{qSymbol}
23009@tab Detecting multiple threads
23010
2d717e4f
DJ
23011@item @code{attach}
23012@tab @code{vAttach}
23013@tab @code{attach}
23014
cfa9d6d9 23015@item @code{verbose-resume}
427c3a89
DJ
23016@tab @code{vCont}
23017@tab Stepping or resuming multiple threads
23018
2d717e4f
DJ
23019@item @code{run}
23020@tab @code{vRun}
23021@tab @code{run}
23022
cfa9d6d9 23023@item @code{software-breakpoint}
427c3a89
DJ
23024@tab @code{Z0}
23025@tab @code{break}
23026
cfa9d6d9 23027@item @code{hardware-breakpoint}
427c3a89
DJ
23028@tab @code{Z1}
23029@tab @code{hbreak}
23030
cfa9d6d9 23031@item @code{write-watchpoint}
427c3a89
DJ
23032@tab @code{Z2}
23033@tab @code{watch}
23034
cfa9d6d9 23035@item @code{read-watchpoint}
427c3a89
DJ
23036@tab @code{Z3}
23037@tab @code{rwatch}
23038
cfa9d6d9 23039@item @code{access-watchpoint}
427c3a89
DJ
23040@tab @code{Z4}
23041@tab @code{awatch}
23042
c78fa86a
GB
23043@item @code{pid-to-exec-file}
23044@tab @code{qXfer:exec-file:read}
23045@tab @code{attach}, @code{run}
23046
cfa9d6d9
DJ
23047@item @code{target-features}
23048@tab @code{qXfer:features:read}
23049@tab @code{set architecture}
23050
23051@item @code{library-info}
23052@tab @code{qXfer:libraries:read}
23053@tab @code{info sharedlibrary}
23054
23055@item @code{memory-map}
23056@tab @code{qXfer:memory-map:read}
23057@tab @code{info mem}
23058
0fb4aa4b
PA
23059@item @code{read-sdata-object}
23060@tab @code{qXfer:sdata:read}
23061@tab @code{print $_sdata}
23062
4aa995e1
PA
23063@item @code{read-siginfo-object}
23064@tab @code{qXfer:siginfo:read}
23065@tab @code{print $_siginfo}
23066
23067@item @code{write-siginfo-object}
23068@tab @code{qXfer:siginfo:write}
23069@tab @code{set $_siginfo}
23070
dc146f7c
VP
23071@item @code{threads}
23072@tab @code{qXfer:threads:read}
23073@tab @code{info threads}
23074
cfa9d6d9 23075@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
23076@tab @code{qGetTLSAddr}
23077@tab Displaying @code{__thread} variables
23078
711e434b
PM
23079@item @code{get-thread-information-block-address}
23080@tab @code{qGetTIBAddr}
23081@tab Display MS-Windows Thread Information Block.
23082
08388c79
DE
23083@item @code{search-memory}
23084@tab @code{qSearch:memory}
23085@tab @code{find}
23086
427c3a89
DJ
23087@item @code{supported-packets}
23088@tab @code{qSupported}
23089@tab Remote communications parameters
23090
82075af2
JS
23091@item @code{catch-syscalls}
23092@tab @code{QCatchSyscalls}
23093@tab @code{catch syscall}
23094
cfa9d6d9 23095@item @code{pass-signals}
89be2091
DJ
23096@tab @code{QPassSignals}
23097@tab @code{handle @var{signal}}
23098
9b224c5e
PA
23099@item @code{program-signals}
23100@tab @code{QProgramSignals}
23101@tab @code{handle @var{signal}}
23102
a6b151f1
DJ
23103@item @code{hostio-close-packet}
23104@tab @code{vFile:close}
23105@tab @code{remote get}, @code{remote put}
23106
23107@item @code{hostio-open-packet}
23108@tab @code{vFile:open}
23109@tab @code{remote get}, @code{remote put}
23110
23111@item @code{hostio-pread-packet}
23112@tab @code{vFile:pread}
23113@tab @code{remote get}, @code{remote put}
23114
23115@item @code{hostio-pwrite-packet}
23116@tab @code{vFile:pwrite}
23117@tab @code{remote get}, @code{remote put}
23118
23119@item @code{hostio-unlink-packet}
23120@tab @code{vFile:unlink}
23121@tab @code{remote delete}
a6f3e723 23122
b9e7b9c3
UW
23123@item @code{hostio-readlink-packet}
23124@tab @code{vFile:readlink}
23125@tab Host I/O
23126
0a93529c
GB
23127@item @code{hostio-fstat-packet}
23128@tab @code{vFile:fstat}
23129@tab Host I/O
23130
15a201c8
GB
23131@item @code{hostio-setfs-packet}
23132@tab @code{vFile:setfs}
23133@tab Host I/O
23134
a6f3e723
SL
23135@item @code{noack-packet}
23136@tab @code{QStartNoAckMode}
23137@tab Packet acknowledgment
07e059b5
VP
23138
23139@item @code{osdata}
23140@tab @code{qXfer:osdata:read}
23141@tab @code{info os}
0b16c5cf
PA
23142
23143@item @code{query-attached}
23144@tab @code{qAttached}
23145@tab Querying remote process attach state.
b3b9301e 23146
a46c1e42
PA
23147@item @code{trace-buffer-size}
23148@tab @code{QTBuffer:size}
23149@tab @code{set trace-buffer-size}
23150
bd3eecc3
PA
23151@item @code{trace-status}
23152@tab @code{qTStatus}
23153@tab @code{tstatus}
23154
b3b9301e
PA
23155@item @code{traceframe-info}
23156@tab @code{qXfer:traceframe-info:read}
23157@tab Traceframe info
03583c20 23158
1e4d1764
YQ
23159@item @code{install-in-trace}
23160@tab @code{InstallInTrace}
23161@tab Install tracepoint in tracing
23162
03583c20
UW
23163@item @code{disable-randomization}
23164@tab @code{QDisableRandomization}
23165@tab @code{set disable-randomization}
83364271 23166
aefd8b33
SDJ
23167@item @code{startup-with-shell}
23168@tab @code{QStartupWithShell}
23169@tab @code{set startup-with-shell}
23170
0a2dde4a
SDJ
23171@item @code{environment-hex-encoded}
23172@tab @code{QEnvironmentHexEncoded}
23173@tab @code{set environment}
23174
23175@item @code{environment-unset}
23176@tab @code{QEnvironmentUnset}
23177@tab @code{unset environment}
23178
23179@item @code{environment-reset}
23180@tab @code{QEnvironmentReset}
23181@tab @code{Reset the inferior environment (i.e., unset user-set variables)}
23182
bc3b087d
SDJ
23183@item @code{set-working-dir}
23184@tab @code{QSetWorkingDir}
23185@tab @code{set cwd}
23186
83364271
LM
23187@item @code{conditional-breakpoints-packet}
23188@tab @code{Z0 and Z1}
23189@tab @code{Support for target-side breakpoint condition evaluation}
f7e6eed5 23190
73b8c1fd
PA
23191@item @code{multiprocess-extensions}
23192@tab @code{multiprocess extensions}
23193@tab Debug multiple processes and remote process PID awareness
23194
f7e6eed5
PA
23195@item @code{swbreak-feature}
23196@tab @code{swbreak stop reason}
23197@tab @code{break}
23198
23199@item @code{hwbreak-feature}
23200@tab @code{hwbreak stop reason}
23201@tab @code{hbreak}
23202
0d71eef5
DB
23203@item @code{fork-event-feature}
23204@tab @code{fork stop reason}
23205@tab @code{fork}
23206
23207@item @code{vfork-event-feature}
23208@tab @code{vfork stop reason}
23209@tab @code{vfork}
23210
b459a59b
DB
23211@item @code{exec-event-feature}
23212@tab @code{exec stop reason}
23213@tab @code{exec}
23214
65706a29
PA
23215@item @code{thread-events}
23216@tab @code{QThreadEvents}
23217@tab Tracking thread lifetime.
23218
f2faf941
PA
23219@item @code{no-resumed-stop-reply}
23220@tab @code{no resumed thread left stop reply}
23221@tab Tracking thread lifetime.
23222
427c3a89
DJ
23223@end multitable
23224
79a6e687
BW
23225@node Remote Stub
23226@section Implementing a Remote Stub
7a292a7a 23227
8e04817f
AC
23228@cindex debugging stub, example
23229@cindex remote stub, example
23230@cindex stub example, remote debugging
23231The stub files provided with @value{GDBN} implement the target side of the
23232communication protocol, and the @value{GDBN} side is implemented in the
23233@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
23234these subroutines to communicate, and ignore the details. (If you're
23235implementing your own stub file, you can still ignore the details: start
23236with one of the existing stub files. @file{sparc-stub.c} is the best
23237organized, and therefore the easiest to read.)
23238
104c1213
JM
23239@cindex remote serial debugging, overview
23240To debug a program running on another machine (the debugging
23241@dfn{target} machine), you must first arrange for all the usual
23242prerequisites for the program to run by itself. For example, for a C
23243program, you need:
c906108c 23244
104c1213
JM
23245@enumerate
23246@item
23247A startup routine to set up the C runtime environment; these usually
23248have a name like @file{crt0}. The startup routine may be supplied by
23249your hardware supplier, or you may have to write your own.
96baa820 23250
5d161b24 23251@item
d4f3574e 23252A C subroutine library to support your program's
104c1213 23253subroutine calls, notably managing input and output.
96baa820 23254
104c1213
JM
23255@item
23256A way of getting your program to the other machine---for example, a
23257download program. These are often supplied by the hardware
23258manufacturer, but you may have to write your own from hardware
23259documentation.
23260@end enumerate
96baa820 23261
104c1213
JM
23262The next step is to arrange for your program to use a serial port to
23263communicate with the machine where @value{GDBN} is running (the @dfn{host}
23264machine). In general terms, the scheme looks like this:
96baa820 23265
104c1213
JM
23266@table @emph
23267@item On the host,
23268@value{GDBN} already understands how to use this protocol; when everything
23269else is set up, you can simply use the @samp{target remote} command
23270(@pxref{Targets,,Specifying a Debugging Target}).
23271
23272@item On the target,
23273you must link with your program a few special-purpose subroutines that
23274implement the @value{GDBN} remote serial protocol. The file containing these
23275subroutines is called a @dfn{debugging stub}.
23276
23277On certain remote targets, you can use an auxiliary program
23278@code{gdbserver} instead of linking a stub into your program.
79a6e687 23279@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 23280@end table
96baa820 23281
104c1213
JM
23282The debugging stub is specific to the architecture of the remote
23283machine; for example, use @file{sparc-stub.c} to debug programs on
23284@sc{sparc} boards.
96baa820 23285
104c1213
JM
23286@cindex remote serial stub list
23287These working remote stubs are distributed with @value{GDBN}:
96baa820 23288
104c1213
JM
23289@table @code
23290
23291@item i386-stub.c
41afff9a 23292@cindex @file{i386-stub.c}
104c1213
JM
23293@cindex Intel
23294@cindex i386
23295For Intel 386 and compatible architectures.
23296
23297@item m68k-stub.c
41afff9a 23298@cindex @file{m68k-stub.c}
104c1213
JM
23299@cindex Motorola 680x0
23300@cindex m680x0
23301For Motorola 680x0 architectures.
23302
23303@item sh-stub.c
41afff9a 23304@cindex @file{sh-stub.c}
172c2a43 23305@cindex Renesas
104c1213 23306@cindex SH
172c2a43 23307For Renesas SH architectures.
104c1213
JM
23308
23309@item sparc-stub.c
41afff9a 23310@cindex @file{sparc-stub.c}
104c1213
JM
23311@cindex Sparc
23312For @sc{sparc} architectures.
23313
23314@item sparcl-stub.c
41afff9a 23315@cindex @file{sparcl-stub.c}
104c1213
JM
23316@cindex Fujitsu
23317@cindex SparcLite
23318For Fujitsu @sc{sparclite} architectures.
23319
23320@end table
23321
23322The @file{README} file in the @value{GDBN} distribution may list other
23323recently added stubs.
23324
23325@menu
23326* Stub Contents:: What the stub can do for you
23327* Bootstrapping:: What you must do for the stub
23328* Debug Session:: Putting it all together
104c1213
JM
23329@end menu
23330
6d2ebf8b 23331@node Stub Contents
79a6e687 23332@subsection What the Stub Can Do for You
104c1213
JM
23333
23334@cindex remote serial stub
23335The debugging stub for your architecture supplies these three
23336subroutines:
23337
23338@table @code
23339@item set_debug_traps
4644b6e3 23340@findex set_debug_traps
104c1213
JM
23341@cindex remote serial stub, initialization
23342This routine arranges for @code{handle_exception} to run when your
2fb860fc
PA
23343program stops. You must call this subroutine explicitly in your
23344program's startup code.
104c1213
JM
23345
23346@item handle_exception
4644b6e3 23347@findex handle_exception
104c1213
JM
23348@cindex remote serial stub, main routine
23349This is the central workhorse, but your program never calls it
23350explicitly---the setup code arranges for @code{handle_exception} to
23351run when a trap is triggered.
23352
23353@code{handle_exception} takes control when your program stops during
23354execution (for example, on a breakpoint), and mediates communications
23355with @value{GDBN} on the host machine. This is where the communications
23356protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 23357representative on the target machine. It begins by sending summary
104c1213
JM
23358information on the state of your program, then continues to execute,
23359retrieving and transmitting any information @value{GDBN} needs, until you
23360execute a @value{GDBN} command that makes your program resume; at that point,
23361@code{handle_exception} returns control to your own code on the target
5d161b24 23362machine.
104c1213
JM
23363
23364@item breakpoint
23365@cindex @code{breakpoint} subroutine, remote
23366Use this auxiliary subroutine to make your program contain a
23367breakpoint. Depending on the particular situation, this may be the only
23368way for @value{GDBN} to get control. For instance, if your target
23369machine has some sort of interrupt button, you won't need to call this;
23370pressing the interrupt button transfers control to
23371@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
23372simply receiving characters on the serial port may also trigger a trap;
23373again, in that situation, you don't need to call @code{breakpoint} from
23374your own program---simply running @samp{target remote} from the host
5d161b24 23375@value{GDBN} session gets control.
104c1213
JM
23376
23377Call @code{breakpoint} if none of these is true, or if you simply want
23378to make certain your program stops at a predetermined point for the
23379start of your debugging session.
23380@end table
23381
6d2ebf8b 23382@node Bootstrapping
79a6e687 23383@subsection What You Must Do for the Stub
104c1213
JM
23384
23385@cindex remote stub, support routines
23386The debugging stubs that come with @value{GDBN} are set up for a particular
23387chip architecture, but they have no information about the rest of your
23388debugging target machine.
23389
23390First of all you need to tell the stub how to communicate with the
23391serial port.
23392
23393@table @code
23394@item int getDebugChar()
4644b6e3 23395@findex getDebugChar
104c1213
JM
23396Write this subroutine to read a single character from the serial port.
23397It may be identical to @code{getchar} for your target system; a
23398different name is used to allow you to distinguish the two if you wish.
23399
23400@item void putDebugChar(int)
4644b6e3 23401@findex putDebugChar
104c1213 23402Write this subroutine to write a single character to the serial port.
5d161b24 23403It may be identical to @code{putchar} for your target system; a
104c1213
JM
23404different name is used to allow you to distinguish the two if you wish.
23405@end table
23406
23407@cindex control C, and remote debugging
23408@cindex interrupting remote targets
23409If you want @value{GDBN} to be able to stop your program while it is
23410running, you need to use an interrupt-driven serial driver, and arrange
23411for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
23412character). That is the character which @value{GDBN} uses to tell the
23413remote system to stop.
23414
23415Getting the debugging target to return the proper status to @value{GDBN}
23416probably requires changes to the standard stub; one quick and dirty way
23417is to just execute a breakpoint instruction (the ``dirty'' part is that
23418@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
23419
23420Other routines you need to supply are:
23421
23422@table @code
23423@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 23424@findex exceptionHandler
104c1213
JM
23425Write this function to install @var{exception_address} in the exception
23426handling tables. You need to do this because the stub does not have any
23427way of knowing what the exception handling tables on your target system
23428are like (for example, the processor's table might be in @sc{rom},
23429containing entries which point to a table in @sc{ram}).
697aa1b7 23430The @var{exception_number} specifies the exception which should be changed;
104c1213
JM
23431its meaning is architecture-dependent (for example, different numbers
23432might represent divide by zero, misaligned access, etc). When this
23433exception occurs, control should be transferred directly to
23434@var{exception_address}, and the processor state (stack, registers,
23435and so on) should be just as it is when a processor exception occurs. So if
23436you want to use a jump instruction to reach @var{exception_address}, it
23437should be a simple jump, not a jump to subroutine.
23438
23439For the 386, @var{exception_address} should be installed as an interrupt
23440gate so that interrupts are masked while the handler runs. The gate
23441should be at privilege level 0 (the most privileged level). The
23442@sc{sparc} and 68k stubs are able to mask interrupts themselves without
23443help from @code{exceptionHandler}.
23444
23445@item void flush_i_cache()
4644b6e3 23446@findex flush_i_cache
d4f3574e 23447On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
23448instruction cache, if any, on your target machine. If there is no
23449instruction cache, this subroutine may be a no-op.
23450
23451On target machines that have instruction caches, @value{GDBN} requires this
23452function to make certain that the state of your program is stable.
23453@end table
23454
23455@noindent
23456You must also make sure this library routine is available:
23457
23458@table @code
23459@item void *memset(void *, int, int)
4644b6e3 23460@findex memset
104c1213
JM
23461This is the standard library function @code{memset} that sets an area of
23462memory to a known value. If you have one of the free versions of
23463@code{libc.a}, @code{memset} can be found there; otherwise, you must
23464either obtain it from your hardware manufacturer, or write your own.
23465@end table
23466
23467If you do not use the GNU C compiler, you may need other standard
23468library subroutines as well; this varies from one stub to another,
23469but in general the stubs are likely to use any of the common library
e22ea452 23470subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
23471
23472
6d2ebf8b 23473@node Debug Session
79a6e687 23474@subsection Putting it All Together
104c1213
JM
23475
23476@cindex remote serial debugging summary
23477In summary, when your program is ready to debug, you must follow these
23478steps.
23479
23480@enumerate
23481@item
6d2ebf8b 23482Make sure you have defined the supporting low-level routines
79a6e687 23483(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
23484@display
23485@code{getDebugChar}, @code{putDebugChar},
23486@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
23487@end display
23488
23489@item
2fb860fc
PA
23490Insert these lines in your program's startup code, before the main
23491procedure is called:
104c1213 23492
474c8240 23493@smallexample
104c1213
JM
23494set_debug_traps();
23495breakpoint();
474c8240 23496@end smallexample
104c1213 23497
2fb860fc
PA
23498On some machines, when a breakpoint trap is raised, the hardware
23499automatically makes the PC point to the instruction after the
23500breakpoint. If your machine doesn't do that, you may need to adjust
23501@code{handle_exception} to arrange for it to return to the instruction
23502after the breakpoint on this first invocation, so that your program
23503doesn't keep hitting the initial breakpoint instead of making
23504progress.
23505
104c1213
JM
23506@item
23507For the 680x0 stub only, you need to provide a variable called
23508@code{exceptionHook}. Normally you just use:
23509
474c8240 23510@smallexample
104c1213 23511void (*exceptionHook)() = 0;
474c8240 23512@end smallexample
104c1213 23513
d4f3574e 23514@noindent
104c1213 23515but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 23516function in your program, that function is called when
104c1213
JM
23517@code{@value{GDBN}} continues after stopping on a trap (for example, bus
23518error). The function indicated by @code{exceptionHook} is called with
23519one parameter: an @code{int} which is the exception number.
23520
23521@item
23522Compile and link together: your program, the @value{GDBN} debugging stub for
23523your target architecture, and the supporting subroutines.
23524
23525@item
23526Make sure you have a serial connection between your target machine and
23527the @value{GDBN} host, and identify the serial port on the host.
23528
23529@item
23530@c The "remote" target now provides a `load' command, so we should
23531@c document that. FIXME.
23532Download your program to your target machine (or get it there by
23533whatever means the manufacturer provides), and start it.
23534
23535@item
07f31aa6 23536Start @value{GDBN} on the host, and connect to the target
79a6e687 23537(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 23538
104c1213
JM
23539@end enumerate
23540
8e04817f
AC
23541@node Configurations
23542@chapter Configuration-Specific Information
104c1213 23543
8e04817f
AC
23544While nearly all @value{GDBN} commands are available for all native and
23545cross versions of the debugger, there are some exceptions. This chapter
23546describes things that are only available in certain configurations.
104c1213 23547
8e04817f
AC
23548There are three major categories of configurations: native
23549configurations, where the host and target are the same, embedded
23550operating system configurations, which are usually the same for several
23551different processor architectures, and bare embedded processors, which
23552are quite different from each other.
104c1213 23553
8e04817f
AC
23554@menu
23555* Native::
23556* Embedded OS::
23557* Embedded Processors::
23558* Architectures::
23559@end menu
104c1213 23560
8e04817f
AC
23561@node Native
23562@section Native
104c1213 23563
8e04817f
AC
23564This section describes details specific to particular native
23565configurations.
6cf7e474 23566
8e04817f 23567@menu
7561d450 23568* BSD libkvm Interface:: Debugging BSD kernel memory images
2d97a5d9 23569* Process Information:: Process information
8e04817f 23570* DJGPP Native:: Features specific to the DJGPP port
78c47bea 23571* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 23572* Hurd Native:: Features specific to @sc{gnu} Hurd
a80b95ba 23573* Darwin:: Features specific to Darwin
e9076973 23574* FreeBSD:: Features specific to FreeBSD
8e04817f 23575@end menu
6cf7e474 23576
7561d450
MK
23577@node BSD libkvm Interface
23578@subsection BSD libkvm Interface
23579
23580@cindex libkvm
23581@cindex kernel memory image
23582@cindex kernel crash dump
23583
23584BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
23585interface that provides a uniform interface for accessing kernel virtual
23586memory images, including live systems and crash dumps. @value{GDBN}
23587uses this interface to allow you to debug live kernels and kernel crash
23588dumps on many native BSD configurations. This is implemented as a
23589special @code{kvm} debugging target. For debugging a live system, load
23590the currently running kernel into @value{GDBN} and connect to the
23591@code{kvm} target:
23592
23593@smallexample
23594(@value{GDBP}) @b{target kvm}
23595@end smallexample
23596
23597For debugging crash dumps, provide the file name of the crash dump as an
23598argument:
23599
23600@smallexample
23601(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
23602@end smallexample
23603
23604Once connected to the @code{kvm} target, the following commands are
23605available:
23606
23607@table @code
23608@kindex kvm
23609@item kvm pcb
721c2651 23610Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
23611
23612@item kvm proc
23613Set current context from proc address. This command isn't available on
23614modern FreeBSD systems.
23615@end table
23616
2d97a5d9
JB
23617@node Process Information
23618@subsection Process Information
60bf7e09
EZ
23619@cindex /proc
23620@cindex examine process image
23621@cindex process info via @file{/proc}
104c1213 23622
2d97a5d9
JB
23623Some operating systems provide interfaces to fetch additional
23624information about running processes beyond memory and per-thread
23625register state. If @value{GDBN} is configured for an operating system
23626with a supported interface, the command @code{info proc} is available
23627to report information about the process running your program, or about
23628any process running on your system.
451b7c33 23629
2d97a5d9
JB
23630One supported interface is a facility called @samp{/proc} that can be
23631used to examine the image of a running process using file-system
23632subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
23633systems.
451b7c33 23634
aa8509b4
KR
23635On FreeBSD and NetBSD systems, system control nodes are used to query
23636process information.
2d97a5d9
JB
23637
23638In addition, some systems may provide additional process information
23639in core files. Note that a core file may include a subset of the
23640information available from a live process. Process information is
6b92c0d3 23641currently available from cores created on @sc{gnu}/Linux and FreeBSD
2d97a5d9 23642systems.
104c1213 23643
8e04817f
AC
23644@table @code
23645@kindex info proc
60bf7e09 23646@cindex process ID
8e04817f 23647@item info proc
60bf7e09 23648@itemx info proc @var{process-id}
73f1bd76 23649Summarize available information about a process. If a
60bf7e09
EZ
23650process ID is specified by @var{process-id}, display information about
23651that process; otherwise display information about the program being
23652debugged. The summary includes the debugged process ID, the command
23653line used to invoke it, its current working directory, and its
23654executable file's absolute file name.
23655
23656On some systems, @var{process-id} can be of the form
23657@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
23658within a process. If the optional @var{pid} part is missing, it means
23659a thread from the process being debugged (the leading @samp{/} still
23660needs to be present, or else @value{GDBN} will interpret the number as
23661a process ID rather than a thread ID).
6cf7e474 23662
0c631110
TT
23663@item info proc cmdline
23664@cindex info proc cmdline
23665Show the original command line of the process. This command is
aa8509b4 23666supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
0c631110
TT
23667
23668@item info proc cwd
23669@cindex info proc cwd
23670Show the current working directory of the process. This command is
aa8509b4 23671supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
0c631110
TT
23672
23673@item info proc exe
23674@cindex info proc exe
2d97a5d9 23675Show the name of executable of the process. This command is supported
aa8509b4 23676on @sc{gnu}/Linux, FreeBSD and NetBSD.
0c631110 23677
8b113111
JB
23678@item info proc files
23679@cindex info proc files
23680Show the file descriptors open by the process. For each open file
23681descriptor, @value{GDBN} shows its number, type (file, directory,
23682character device, socket), file pointer offset, and the name of the
23683resource open on the descriptor. The resource name can be a file name
23684(for files, directories, and devices) or a protocol followed by socket
23685address (for network connections). This command is supported on
23686FreeBSD.
23687
23688This example shows the open file descriptors for a process using a
23689tty for standard input and output as well as two network sockets:
23690
23691@smallexample
23692(gdb) info proc files 22136
23693process 22136
23694Open files:
23695
23696 FD Type Offset Flags Name
23697 text file - r-------- /usr/bin/ssh
23698 ctty chr - rw------- /dev/pts/20
23699 cwd dir - r-------- /usr/home/john
23700 root dir - r-------- /
23701 0 chr 0x32933a4 rw------- /dev/pts/20
23702 1 chr 0x32933a4 rw------- /dev/pts/20
23703 2 chr 0x32933a4 rw------- /dev/pts/20
23704 3 socket 0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
23705 4 socket 0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
23706@end smallexample
23707
8e04817f 23708@item info proc mappings
60bf7e09 23709@cindex memory address space mappings
73f1bd76 23710Report the memory address space ranges accessible in a process. On
aa8509b4
KR
23711Solaris, FreeBSD and NetBSD systems, each memory range includes information
23712on whether the process has read, write, or execute access rights to each
23713range. On @sc{gnu}/Linux, FreeBSD and NetBSD systems, each memory range
2d97a5d9 23714includes the object file which is mapped to that range.
60bf7e09
EZ
23715
23716@item info proc stat
23717@itemx info proc status
23718@cindex process detailed status information
2d97a5d9
JB
23719Show additional process-related information, including the user ID and
23720group ID; virtual memory usage; the signals that are pending, blocked,
23721and ignored; its TTY; its consumption of system and user time; its
23722stack size; its @samp{nice} value; etc. These commands are supported
aa8509b4 23723on @sc{gnu}/Linux, FreeBSD and NetBSD.
2d97a5d9
JB
23724
23725For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
23726information (type @kbd{man 5 proc} from your shell prompt).
23727
aa8509b4
KR
23728For FreeBSD and NetBSD systems, @code{info proc stat} is an alias for
23729@code{info proc status}.
60bf7e09
EZ
23730
23731@item info proc all
23732Show all the information about the process described under all of the
23733above @code{info proc} subcommands.
23734
8e04817f
AC
23735@ignore
23736@comment These sub-options of 'info proc' were not included when
23737@comment procfs.c was re-written. Keep their descriptions around
23738@comment against the day when someone finds the time to put them back in.
23739@kindex info proc times
23740@item info proc times
23741Starting time, user CPU time, and system CPU time for your program and
23742its children.
6cf7e474 23743
8e04817f
AC
23744@kindex info proc id
23745@item info proc id
23746Report on the process IDs related to your program: its own process ID,
23747the ID of its parent, the process group ID, and the session ID.
8e04817f 23748@end ignore
721c2651
EZ
23749
23750@item set procfs-trace
23751@kindex set procfs-trace
23752@cindex @code{procfs} API calls
23753This command enables and disables tracing of @code{procfs} API calls.
23754
23755@item show procfs-trace
23756@kindex show procfs-trace
23757Show the current state of @code{procfs} API call tracing.
23758
23759@item set procfs-file @var{file}
23760@kindex set procfs-file
23761Tell @value{GDBN} to write @code{procfs} API trace to the named
23762@var{file}. @value{GDBN} appends the trace info to the previous
23763contents of the file. The default is to display the trace on the
23764standard output.
23765
23766@item show procfs-file
23767@kindex show procfs-file
23768Show the file to which @code{procfs} API trace is written.
23769
23770@item proc-trace-entry
23771@itemx proc-trace-exit
23772@itemx proc-untrace-entry
23773@itemx proc-untrace-exit
23774@kindex proc-trace-entry
23775@kindex proc-trace-exit
23776@kindex proc-untrace-entry
23777@kindex proc-untrace-exit
23778These commands enable and disable tracing of entries into and exits
23779from the @code{syscall} interface.
23780
23781@item info pidlist
23782@kindex info pidlist
23783@cindex process list, QNX Neutrino
23784For QNX Neutrino only, this command displays the list of all the
23785processes and all the threads within each process.
23786
23787@item info meminfo
23788@kindex info meminfo
23789@cindex mapinfo list, QNX Neutrino
23790For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 23791@end table
104c1213 23792
8e04817f
AC
23793@node DJGPP Native
23794@subsection Features for Debugging @sc{djgpp} Programs
23795@cindex @sc{djgpp} debugging
23796@cindex native @sc{djgpp} debugging
23797@cindex MS-DOS-specific commands
104c1213 23798
514c4d71
EZ
23799@cindex DPMI
23800@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
23801MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
23802that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
23803top of real-mode DOS systems and their emulations.
104c1213 23804
8e04817f
AC
23805@value{GDBN} supports native debugging of @sc{djgpp} programs, and
23806defines a few commands specific to the @sc{djgpp} port. This
23807subsection describes those commands.
104c1213 23808
8e04817f
AC
23809@table @code
23810@kindex info dos
23811@item info dos
23812This is a prefix of @sc{djgpp}-specific commands which print
23813information about the target system and important OS structures.
f1251bdd 23814
8e04817f
AC
23815@kindex sysinfo
23816@cindex MS-DOS system info
23817@cindex free memory information (MS-DOS)
23818@item info dos sysinfo
23819This command displays assorted information about the underlying
23820platform: the CPU type and features, the OS version and flavor, the
23821DPMI version, and the available conventional and DPMI memory.
104c1213 23822
8e04817f
AC
23823@cindex GDT
23824@cindex LDT
23825@cindex IDT
23826@cindex segment descriptor tables
23827@cindex descriptor tables display
23828@item info dos gdt
23829@itemx info dos ldt
23830@itemx info dos idt
23831These 3 commands display entries from, respectively, Global, Local,
23832and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
23833tables are data structures which store a descriptor for each segment
23834that is currently in use. The segment's selector is an index into a
23835descriptor table; the table entry for that index holds the
23836descriptor's base address and limit, and its attributes and access
23837rights.
104c1213 23838
8e04817f
AC
23839A typical @sc{djgpp} program uses 3 segments: a code segment, a data
23840segment (used for both data and the stack), and a DOS segment (which
23841allows access to DOS/BIOS data structures and absolute addresses in
23842conventional memory). However, the DPMI host will usually define
23843additional segments in order to support the DPMI environment.
d4f3574e 23844
8e04817f
AC
23845@cindex garbled pointers
23846These commands allow to display entries from the descriptor tables.
23847Without an argument, all entries from the specified table are
23848displayed. An argument, which should be an integer expression, means
23849display a single entry whose index is given by the argument. For
23850example, here's a convenient way to display information about the
23851debugged program's data segment:
104c1213 23852
8e04817f
AC
23853@smallexample
23854@exdent @code{(@value{GDBP}) info dos ldt $ds}
23855@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
23856@end smallexample
104c1213 23857
8e04817f
AC
23858@noindent
23859This comes in handy when you want to see whether a pointer is outside
23860the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 23861
8e04817f
AC
23862@cindex page tables display (MS-DOS)
23863@item info dos pde
23864@itemx info dos pte
23865These two commands display entries from, respectively, the Page
23866Directory and the Page Tables. Page Directories and Page Tables are
23867data structures which control how virtual memory addresses are mapped
23868into physical addresses. A Page Table includes an entry for every
23869page of memory that is mapped into the program's address space; there
23870may be several Page Tables, each one holding up to 4096 entries. A
23871Page Directory has up to 4096 entries, one each for every Page Table
23872that is currently in use.
104c1213 23873
8e04817f
AC
23874Without an argument, @kbd{info dos pde} displays the entire Page
23875Directory, and @kbd{info dos pte} displays all the entries in all of
23876the Page Tables. An argument, an integer expression, given to the
23877@kbd{info dos pde} command means display only that entry from the Page
23878Directory table. An argument given to the @kbd{info dos pte} command
23879means display entries from a single Page Table, the one pointed to by
23880the specified entry in the Page Directory.
104c1213 23881
8e04817f
AC
23882@cindex direct memory access (DMA) on MS-DOS
23883These commands are useful when your program uses @dfn{DMA} (Direct
23884Memory Access), which needs physical addresses to program the DMA
23885controller.
104c1213 23886
8e04817f 23887These commands are supported only with some DPMI servers.
104c1213 23888
8e04817f
AC
23889@cindex physical address from linear address
23890@item info dos address-pte @var{addr}
23891This command displays the Page Table entry for a specified linear
514c4d71
EZ
23892address. The argument @var{addr} is a linear address which should
23893already have the appropriate segment's base address added to it,
23894because this command accepts addresses which may belong to @emph{any}
23895segment. For example, here's how to display the Page Table entry for
23896the page where a variable @code{i} is stored:
104c1213 23897
b383017d 23898@smallexample
8e04817f
AC
23899@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
23900@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 23901@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 23902@end smallexample
104c1213 23903
8e04817f
AC
23904@noindent
23905This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 23906whose physical base address is @code{0x02698000}, and shows all the
8e04817f 23907attributes of that page.
104c1213 23908
8e04817f
AC
23909Note that you must cast the addresses of variables to a @code{char *},
23910since otherwise the value of @code{__djgpp_base_address}, the base
23911address of all variables and functions in a @sc{djgpp} program, will
23912be added using the rules of C pointer arithmetics: if @code{i} is
23913declared an @code{int}, @value{GDBN} will add 4 times the value of
23914@code{__djgpp_base_address} to the address of @code{i}.
104c1213 23915
8e04817f
AC
23916Here's another example, it displays the Page Table entry for the
23917transfer buffer:
104c1213 23918
8e04817f
AC
23919@smallexample
23920@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
23921@exdent @code{Page Table entry for address 0x29110:}
23922@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
23923@end smallexample
104c1213 23924
8e04817f
AC
23925@noindent
23926(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
239273rd member of the @code{_go32_info_block} structure.) The output
23928clearly shows that this DPMI server maps the addresses in conventional
23929memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
23930linear (@code{0x29110}) addresses are identical.
104c1213 23931
8e04817f
AC
23932This command is supported only with some DPMI servers.
23933@end table
104c1213 23934
c45da7e6 23935@cindex DOS serial data link, remote debugging
a8f24a35
EZ
23936In addition to native debugging, the DJGPP port supports remote
23937debugging via a serial data link. The following commands are specific
23938to remote serial debugging in the DJGPP port of @value{GDBN}.
23939
23940@table @code
23941@kindex set com1base
23942@kindex set com1irq
23943@kindex set com2base
23944@kindex set com2irq
23945@kindex set com3base
23946@kindex set com3irq
23947@kindex set com4base
23948@kindex set com4irq
23949@item set com1base @var{addr}
23950This command sets the base I/O port address of the @file{COM1} serial
23951port.
23952
23953@item set com1irq @var{irq}
23954This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
23955for the @file{COM1} serial port.
23956
23957There are similar commands @samp{set com2base}, @samp{set com3irq},
23958etc.@: for setting the port address and the @code{IRQ} lines for the
23959other 3 COM ports.
23960
23961@kindex show com1base
23962@kindex show com1irq
23963@kindex show com2base
23964@kindex show com2irq
23965@kindex show com3base
23966@kindex show com3irq
23967@kindex show com4base
23968@kindex show com4irq
23969The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
23970display the current settings of the base address and the @code{IRQ}
23971lines used by the COM ports.
c45da7e6
EZ
23972
23973@item info serial
23974@kindex info serial
23975@cindex DOS serial port status
23976This command prints the status of the 4 DOS serial ports. For each
23977port, it prints whether it's active or not, its I/O base address and
23978IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
23979counts of various errors encountered so far.
a8f24a35
EZ
23980@end table
23981
23982
78c47bea 23983@node Cygwin Native
79a6e687 23984@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
23985@cindex MS Windows debugging
23986@cindex native Cygwin debugging
23987@cindex Cygwin-specific commands
23988
be448670 23989@value{GDBN} supports native debugging of MS Windows programs, including
cbb8f428
EZ
23990DLLs with and without symbolic debugging information.
23991
23992@cindex Ctrl-BREAK, MS-Windows
23993@cindex interrupt debuggee on MS-Windows
23994MS-Windows programs that call @code{SetConsoleMode} to switch off the
23995special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
23996by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
23997supports @kbd{C-@key{BREAK}} as an alternative interrupt key
23998sequence, which can be used to interrupt the debuggee even if it
23999ignores @kbd{C-c}.
24000
24001There are various additional Cygwin-specific commands, described in
24002this section. Working with DLLs that have no debugging symbols is
24003described in @ref{Non-debug DLL Symbols}.
78c47bea
PM
24004
24005@table @code
24006@kindex info w32
24007@item info w32
db2e3e2e 24008This is a prefix of MS Windows-specific commands which print
78c47bea
PM
24009information about the target system and important OS structures.
24010
24011@item info w32 selector
24012This command displays information returned by
24013the Win32 API @code{GetThreadSelectorEntry} function.
24014It takes an optional argument that is evaluated to
24015a long value to give the information about this given selector.
24016Without argument, this command displays information
d3e8051b 24017about the six segment registers.
78c47bea 24018
711e434b
PM
24019@item info w32 thread-information-block
24020This command displays thread specific information stored in the
24021Thread Information Block (readable on the X86 CPU family using @code{$fs}
24022selector for 32-bit programs and @code{$gs} for 64-bit programs).
24023
463888ab
РИ
24024@kindex signal-event
24025@item signal-event @var{id}
24026This command signals an event with user-provided @var{id}. Used to resume
24027crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
24028
24029To use it, create or edit the following keys in
24030@code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
24031@code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
24032(for x86_64 versions):
24033
24034@itemize @minus
24035@item
24036@code{Debugger} (REG_SZ) --- a command to launch the debugger.
24037Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
24038"attach %ld" -ex "signal-event %ld" -ex "continue"}.
24039
24040The first @code{%ld} will be replaced by the process ID of the
24041crashing process, the second @code{%ld} will be replaced by the ID of
24042the event that blocks the crashing process, waiting for @value{GDBN}
24043to attach.
24044
24045@item
24046@code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
24047make the system run debugger specified by the Debugger key
24048automatically, @code{0} will cause a dialog box with ``OK'' and
24049``Cancel'' buttons to appear, which allows the user to either
24050terminate the crashing process (OK) or debug it (Cancel).
24051@end itemize
24052
be90c084 24053@kindex set cygwin-exceptions
e16b02ee
EZ
24054@cindex debugging the Cygwin DLL
24055@cindex Cygwin DLL, debugging
be90c084 24056@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
24057If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
24058happen inside the Cygwin DLL. If @var{mode} is @code{off},
24059@value{GDBN} will delay recognition of exceptions, and may ignore some
24060exceptions which seem to be caused by internal Cygwin DLL
24061``bookkeeping''. This option is meant primarily for debugging the
24062Cygwin DLL itself; the default value is @code{off} to avoid annoying
24063@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
24064
24065@kindex show cygwin-exceptions
24066@item show cygwin-exceptions
e16b02ee
EZ
24067Displays whether @value{GDBN} will break on exceptions that happen
24068inside the Cygwin DLL itself.
be90c084 24069
b383017d 24070@kindex set new-console
78c47bea 24071@item set new-console @var{mode}
b383017d 24072If @var{mode} is @code{on} the debuggee will
78c47bea 24073be started in a new console on next start.
e03e5e7b 24074If @var{mode} is @code{off}, the debuggee will
78c47bea
PM
24075be started in the same console as the debugger.
24076
24077@kindex show new-console
24078@item show new-console
24079Displays whether a new console is used
24080when the debuggee is started.
24081
24082@kindex set new-group
24083@item set new-group @var{mode}
24084This boolean value controls whether the debuggee should
24085start a new group or stay in the same group as the debugger.
24086This affects the way the Windows OS handles
c8aa23ab 24087@samp{Ctrl-C}.
78c47bea
PM
24088
24089@kindex show new-group
24090@item show new-group
24091Displays current value of new-group boolean.
24092
24093@kindex set debugevents
24094@item set debugevents
219eec71
EZ
24095This boolean value adds debug output concerning kernel events related
24096to the debuggee seen by the debugger. This includes events that
24097signal thread and process creation and exit, DLL loading and
24098unloading, console interrupts, and debugging messages produced by the
24099Windows @code{OutputDebugString} API call.
78c47bea
PM
24100
24101@kindex set debugexec
24102@item set debugexec
b383017d 24103This boolean value adds debug output concerning execute events
219eec71 24104(such as resume thread) seen by the debugger.
78c47bea
PM
24105
24106@kindex set debugexceptions
24107@item set debugexceptions
219eec71
EZ
24108This boolean value adds debug output concerning exceptions in the
24109debuggee seen by the debugger.
78c47bea
PM
24110
24111@kindex set debugmemory
24112@item set debugmemory
219eec71
EZ
24113This boolean value adds debug output concerning debuggee memory reads
24114and writes by the debugger.
78c47bea
PM
24115
24116@kindex set shell
24117@item set shell
24118This boolean values specifies whether the debuggee is called
24119via a shell or directly (default value is on).
24120
24121@kindex show shell
24122@item show shell
24123Displays if the debuggee will be started with a shell.
24124
24125@end table
24126
be448670 24127@menu
79a6e687 24128* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
24129@end menu
24130
79a6e687
BW
24131@node Non-debug DLL Symbols
24132@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
24133@cindex DLLs with no debugging symbols
24134@cindex Minimal symbols and DLLs
24135
24136Very often on windows, some of the DLLs that your program relies on do
24137not include symbolic debugging information (for example,
db2e3e2e 24138@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 24139symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 24140information contained in the DLL's export table. This section
be448670
CF
24141describes working with such symbols, known internally to @value{GDBN} as
24142``minimal symbols''.
24143
24144Note that before the debugged program has started execution, no DLLs
db2e3e2e 24145will have been loaded. The easiest way around this problem is simply to
be448670 24146start the program --- either by setting a breakpoint or letting the
95060284 24147program run once to completion.
be448670 24148
79a6e687 24149@subsubsection DLL Name Prefixes
be448670
CF
24150
24151In keeping with the naming conventions used by the Microsoft debugging
24152tools, DLL export symbols are made available with a prefix based on the
24153DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
24154also entered into the symbol table, so @code{CreateFileA} is often
99e008fe 24155sufficient. In some cases there will be name clashes within a program
be448670
CF
24156(particularly if the executable itself includes full debugging symbols)
24157necessitating the use of the fully qualified name when referring to the
99e008fe 24158contents of the DLL. Use single-quotes around the name to avoid the
be448670
CF
24159exclamation mark (``!'') being interpreted as a language operator.
24160
24161Note that the internal name of the DLL may be all upper-case, even
99e008fe 24162though the file name of the DLL is lower-case, or vice-versa. Since
be448670
CF
24163symbols within @value{GDBN} are @emph{case-sensitive} this may cause
24164some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
24165@code{info variables} commands or even @code{maint print msymbols}
24166(@pxref{Symbols}). Here's an example:
be448670
CF
24167
24168@smallexample
f7dc1244 24169(@value{GDBP}) info function CreateFileA
be448670
CF
24170All functions matching regular expression "CreateFileA":
24171
24172Non-debugging symbols:
241730x77e885f4 CreateFileA
241740x77e885f4 KERNEL32!CreateFileA
24175@end smallexample
24176
24177@smallexample
f7dc1244 24178(@value{GDBP}) info function !
be448670
CF
24179All functions matching regular expression "!":
24180
24181Non-debugging symbols:
241820x6100114c cygwin1!__assert
241830x61004034 cygwin1!_dll_crt0@@0
241840x61004240 cygwin1!dll_crt0(per_process *)
24185[etc...]
24186@end smallexample
24187
79a6e687 24188@subsubsection Working with Minimal Symbols
be448670
CF
24189
24190Symbols extracted from a DLL's export table do not contain very much
24191type information. All that @value{GDBN} can do is guess whether a symbol
24192refers to a function or variable depending on the linker section that
24193contains the symbol. Also note that the actual contents of the memory
24194contained in a DLL are not available unless the program is running. This
24195means that you cannot examine the contents of a variable or disassemble
24196a function within a DLL without a running program.
24197
24198Variables are generally treated as pointers and dereferenced
24199automatically. For this reason, it is often necessary to prefix a
24200variable name with the address-of operator (``&'') and provide explicit
24201type information in the command. Here's an example of the type of
24202problem:
24203
24204@smallexample
f7dc1244 24205(@value{GDBP}) print 'cygwin1!__argv'
d69cf9b2 24206'cygwin1!__argv' has unknown type; cast it to its declared type
be448670
CF
24207@end smallexample
24208
24209@smallexample
f7dc1244 24210(@value{GDBP}) x 'cygwin1!__argv'
d69cf9b2 24211'cygwin1!__argv' has unknown type; cast it to its declared type
be448670
CF
24212@end smallexample
24213
24214And two possible solutions:
24215
24216@smallexample
f7dc1244 24217(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
24218$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
24219@end smallexample
24220
24221@smallexample
f7dc1244 24222(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 242230x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 24224(@value{GDBP}) x/x 0x10021608
be448670 242250x10021608: 0x0022fd98
f7dc1244 24226(@value{GDBP}) x/s 0x0022fd98
be448670
CF
242270x22fd98: "/cygdrive/c/mydirectory/myprogram"
24228@end smallexample
24229
24230Setting a break point within a DLL is possible even before the program
24231starts execution. However, under these circumstances, @value{GDBN} can't
24232examine the initial instructions of the function in order to skip the
24233function's frame set-up code. You can work around this by using ``*&''
24234to set the breakpoint at a raw memory address:
24235
24236@smallexample
f7dc1244 24237(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
24238Breakpoint 1 at 0x1e04eff0
24239@end smallexample
24240
24241The author of these extensions is not entirely convinced that setting a
24242break point within a shared DLL like @file{kernel32.dll} is completely
24243safe.
24244
14d6dd68 24245@node Hurd Native
79a6e687 24246@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
24247@cindex @sc{gnu} Hurd debugging
24248
24249This subsection describes @value{GDBN} commands specific to the
24250@sc{gnu} Hurd native debugging.
24251
24252@table @code
24253@item set signals
24254@itemx set sigs
24255@kindex set signals@r{, Hurd command}
24256@kindex set sigs@r{, Hurd command}
24257This command toggles the state of inferior signal interception by
24258@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
24259affected by this command. @code{sigs} is a shorthand alias for
24260@code{signals}.
24261
24262@item show signals
24263@itemx show sigs
24264@kindex show signals@r{, Hurd command}
24265@kindex show sigs@r{, Hurd command}
24266Show the current state of intercepting inferior's signals.
24267
24268@item set signal-thread
24269@itemx set sigthread
24270@kindex set signal-thread
24271@kindex set sigthread
24272This command tells @value{GDBN} which thread is the @code{libc} signal
24273thread. That thread is run when a signal is delivered to a running
24274process. @code{set sigthread} is the shorthand alias of @code{set
24275signal-thread}.
24276
24277@item show signal-thread
24278@itemx show sigthread
24279@kindex show signal-thread
24280@kindex show sigthread
24281These two commands show which thread will run when the inferior is
24282delivered a signal.
24283
24284@item set stopped
24285@kindex set stopped@r{, Hurd command}
24286This commands tells @value{GDBN} that the inferior process is stopped,
24287as with the @code{SIGSTOP} signal. The stopped process can be
24288continued by delivering a signal to it.
24289
24290@item show stopped
24291@kindex show stopped@r{, Hurd command}
24292This command shows whether @value{GDBN} thinks the debuggee is
24293stopped.
24294
24295@item set exceptions
24296@kindex set exceptions@r{, Hurd command}
24297Use this command to turn off trapping of exceptions in the inferior.
24298When exception trapping is off, neither breakpoints nor
24299single-stepping will work. To restore the default, set exception
24300trapping on.
24301
24302@item show exceptions
24303@kindex show exceptions@r{, Hurd command}
24304Show the current state of trapping exceptions in the inferior.
24305
24306@item set task pause
24307@kindex set task@r{, Hurd commands}
24308@cindex task attributes (@sc{gnu} Hurd)
24309@cindex pause current task (@sc{gnu} Hurd)
24310This command toggles task suspension when @value{GDBN} has control.
24311Setting it to on takes effect immediately, and the task is suspended
24312whenever @value{GDBN} gets control. Setting it to off will take
24313effect the next time the inferior is continued. If this option is set
24314to off, you can use @code{set thread default pause on} or @code{set
24315thread pause on} (see below) to pause individual threads.
24316
24317@item show task pause
24318@kindex show task@r{, Hurd commands}
24319Show the current state of task suspension.
24320
24321@item set task detach-suspend-count
24322@cindex task suspend count
24323@cindex detach from task, @sc{gnu} Hurd
24324This command sets the suspend count the task will be left with when
24325@value{GDBN} detaches from it.
24326
24327@item show task detach-suspend-count
24328Show the suspend count the task will be left with when detaching.
24329
24330@item set task exception-port
24331@itemx set task excp
24332@cindex task exception port, @sc{gnu} Hurd
24333This command sets the task exception port to which @value{GDBN} will
24334forward exceptions. The argument should be the value of the @dfn{send
24335rights} of the task. @code{set task excp} is a shorthand alias.
24336
24337@item set noninvasive
24338@cindex noninvasive task options
24339This command switches @value{GDBN} to a mode that is the least
24340invasive as far as interfering with the inferior is concerned. This
24341is the same as using @code{set task pause}, @code{set exceptions}, and
24342@code{set signals} to values opposite to the defaults.
24343
24344@item info send-rights
24345@itemx info receive-rights
24346@itemx info port-rights
24347@itemx info port-sets
24348@itemx info dead-names
24349@itemx info ports
24350@itemx info psets
24351@cindex send rights, @sc{gnu} Hurd
24352@cindex receive rights, @sc{gnu} Hurd
24353@cindex port rights, @sc{gnu} Hurd
24354@cindex port sets, @sc{gnu} Hurd
24355@cindex dead names, @sc{gnu} Hurd
24356These commands display information about, respectively, send rights,
24357receive rights, port rights, port sets, and dead names of a task.
24358There are also shorthand aliases: @code{info ports} for @code{info
24359port-rights} and @code{info psets} for @code{info port-sets}.
24360
24361@item set thread pause
24362@kindex set thread@r{, Hurd command}
24363@cindex thread properties, @sc{gnu} Hurd
24364@cindex pause current thread (@sc{gnu} Hurd)
24365This command toggles current thread suspension when @value{GDBN} has
24366control. Setting it to on takes effect immediately, and the current
24367thread is suspended whenever @value{GDBN} gets control. Setting it to
24368off will take effect the next time the inferior is continued.
24369Normally, this command has no effect, since when @value{GDBN} has
24370control, the whole task is suspended. However, if you used @code{set
24371task pause off} (see above), this command comes in handy to suspend
24372only the current thread.
24373
24374@item show thread pause
24375@kindex show thread@r{, Hurd command}
24376This command shows the state of current thread suspension.
24377
24378@item set thread run
d3e8051b 24379This command sets whether the current thread is allowed to run.
14d6dd68
EZ
24380
24381@item show thread run
24382Show whether the current thread is allowed to run.
24383
24384@item set thread detach-suspend-count
24385@cindex thread suspend count, @sc{gnu} Hurd
24386@cindex detach from thread, @sc{gnu} Hurd
24387This command sets the suspend count @value{GDBN} will leave on a
24388thread when detaching. This number is relative to the suspend count
24389found by @value{GDBN} when it notices the thread; use @code{set thread
24390takeover-suspend-count} to force it to an absolute value.
24391
24392@item show thread detach-suspend-count
24393Show the suspend count @value{GDBN} will leave on the thread when
24394detaching.
24395
24396@item set thread exception-port
24397@itemx set thread excp
24398Set the thread exception port to which to forward exceptions. This
24399overrides the port set by @code{set task exception-port} (see above).
24400@code{set thread excp} is the shorthand alias.
24401
24402@item set thread takeover-suspend-count
24403Normally, @value{GDBN}'s thread suspend counts are relative to the
24404value @value{GDBN} finds when it notices each thread. This command
24405changes the suspend counts to be absolute instead.
24406
24407@item set thread default
24408@itemx show thread default
24409@cindex thread default settings, @sc{gnu} Hurd
24410Each of the above @code{set thread} commands has a @code{set thread
24411default} counterpart (e.g., @code{set thread default pause}, @code{set
24412thread default exception-port}, etc.). The @code{thread default}
24413variety of commands sets the default thread properties for all
24414threads; you can then change the properties of individual threads with
24415the non-default commands.
24416@end table
24417
a80b95ba
TG
24418@node Darwin
24419@subsection Darwin
24420@cindex Darwin
24421
24422@value{GDBN} provides the following commands specific to the Darwin target:
24423
24424@table @code
24425@item set debug darwin @var{num}
24426@kindex set debug darwin
24427When set to a non zero value, enables debugging messages specific to
24428the Darwin support. Higher values produce more verbose output.
24429
24430@item show debug darwin
24431@kindex show debug darwin
24432Show the current state of Darwin messages.
24433
24434@item set debug mach-o @var{num}
24435@kindex set debug mach-o
24436When set to a non zero value, enables debugging messages while
24437@value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
24438file format used on Darwin for object and executable files.) Higher
24439values produce more verbose output. This is a command to diagnose
24440problems internal to @value{GDBN} and should not be needed in normal
24441usage.
24442
24443@item show debug mach-o
24444@kindex show debug mach-o
24445Show the current state of Mach-O file messages.
24446
24447@item set mach-exceptions on
24448@itemx set mach-exceptions off
24449@kindex set mach-exceptions
24450On Darwin, faults are first reported as a Mach exception and are then
24451mapped to a Posix signal. Use this command to turn on trapping of
24452Mach exceptions in the inferior. This might be sometimes useful to
24453better understand the cause of a fault. The default is off.
24454
24455@item show mach-exceptions
24456@kindex show mach-exceptions
24457Show the current state of exceptions trapping.
24458@end table
24459
e9076973
JB
24460@node FreeBSD
24461@subsection FreeBSD
24462@cindex FreeBSD
24463
24464When the ABI of a system call is changed in the FreeBSD kernel, this
24465is implemented by leaving a compatibility system call using the old
24466ABI at the existing number and allocating a new system call number for
24467the version using the new ABI. As a convenience, when a system call
24468is caught by name (@pxref{catch syscall}), compatibility system calls
24469are also caught.
24470
24471For example, FreeBSD 12 introduced a new variant of the @code{kevent}
24472system call and catching the @code{kevent} system call by name catches
24473both variants:
24474
24475@smallexample
24476(@value{GDBP}) catch syscall kevent
24477Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
24478(@value{GDBP})
24479@end smallexample
24480
a64548ea 24481
8e04817f
AC
24482@node Embedded OS
24483@section Embedded Operating Systems
104c1213 24484
8e04817f
AC
24485This section describes configurations involving the debugging of
24486embedded operating systems that are available for several different
24487architectures.
d4f3574e 24488
8e04817f
AC
24489@value{GDBN} includes the ability to debug programs running on
24490various real-time operating systems.
104c1213 24491
6d2ebf8b 24492@node Embedded Processors
104c1213
JM
24493@section Embedded Processors
24494
24495This section goes into details specific to particular embedded
24496configurations.
24497
c45da7e6
EZ
24498@cindex send command to simulator
24499Whenever a specific embedded processor has a simulator, @value{GDBN}
24500allows to send an arbitrary command to the simulator.
24501
24502@table @code
24503@item sim @var{command}
24504@kindex sim@r{, a command}
24505Send an arbitrary @var{command} string to the simulator. Consult the
24506documentation for the specific simulator in use for information about
24507acceptable commands.
24508@end table
24509
7d86b5d5 24510
104c1213 24511@menu
ad0a504f 24512* ARC:: Synopsys ARC
bb615428 24513* ARM:: ARM
39791af2 24514* BPF:: eBPF
104c1213 24515* M68K:: Motorola M68K
08be9d71 24516* MicroBlaze:: Xilinx MicroBlaze
104c1213 24517* MIPS Embedded:: MIPS Embedded
a994fec4 24518* OpenRISC 1000:: OpenRISC 1000 (or1k)
4acd40f3 24519* PowerPC Embedded:: PowerPC Embedded
a64548ea
EZ
24520* AVR:: Atmel AVR
24521* CRIS:: CRIS
24522* Super-H:: Renesas Super-H
104c1213
JM
24523@end menu
24524
ad0a504f
AK
24525@node ARC
24526@subsection Synopsys ARC
24527@cindex Synopsys ARC
24528@cindex ARC specific commands
24529@cindex ARC600
24530@cindex ARC700
24531@cindex ARC EM
24532@cindex ARC HS
24533
24534@value{GDBN} provides the following ARC-specific commands:
24535
24536@table @code
24537@item set debug arc
24538@kindex set debug arc
24539Control the level of ARC specific debug messages. Use 0 for no messages (the
fe5f7374 24540default), 1 for debug messages, and 2 for even more debug messages.
ad0a504f
AK
24541
24542@item show debug arc
24543@kindex show debug arc
24544Show the level of ARC specific debugging in operation.
24545
eea78757
AK
24546@item maint print arc arc-instruction @var{address}
24547@kindex maint print arc arc-instruction
24548Print internal disassembler information about instruction at a given address.
24549
ad0a504f
AK
24550@end table
24551
6d2ebf8b 24552@node ARM
104c1213 24553@subsection ARM
8e04817f 24554
e2f4edfd
EZ
24555@value{GDBN} provides the following ARM-specific commands:
24556
24557@table @code
24558@item set arm disassembler
24559@kindex set arm
24560This commands selects from a list of disassembly styles. The
24561@code{"std"} style is the standard style.
24562
24563@item show arm disassembler
24564@kindex show arm
24565Show the current disassembly style.
24566
24567@item set arm apcs32
24568@cindex ARM 32-bit mode
24569This command toggles ARM operation mode between 32-bit and 26-bit.
24570
24571@item show arm apcs32
24572Display the current usage of the ARM 32-bit mode.
24573
24574@item set arm fpu @var{fputype}
24575This command sets the ARM floating-point unit (FPU) type. The
24576argument @var{fputype} can be one of these:
24577
24578@table @code
24579@item auto
24580Determine the FPU type by querying the OS ABI.
24581@item softfpa
24582Software FPU, with mixed-endian doubles on little-endian ARM
24583processors.
24584@item fpa
24585GCC-compiled FPA co-processor.
24586@item softvfp
24587Software FPU with pure-endian doubles.
24588@item vfp
24589VFP co-processor.
24590@end table
24591
24592@item show arm fpu
24593Show the current type of the FPU.
24594
24595@item set arm abi
24596This command forces @value{GDBN} to use the specified ABI.
24597
24598@item show arm abi
24599Show the currently used ABI.
24600
0428b8f5
DJ
24601@item set arm fallback-mode (arm|thumb|auto)
24602@value{GDBN} uses the symbol table, when available, to determine
24603whether instructions are ARM or Thumb. This command controls
24604@value{GDBN}'s default behavior when the symbol table is not
24605available. The default is @samp{auto}, which causes @value{GDBN} to
24606use the current execution mode (from the @code{T} bit in the @code{CPSR}
24607register).
24608
24609@item show arm fallback-mode
24610Show the current fallback instruction mode.
24611
24612@item set arm force-mode (arm|thumb|auto)
24613This command overrides use of the symbol table to determine whether
24614instructions are ARM or Thumb. The default is @samp{auto}, which
24615causes @value{GDBN} to use the symbol table and then the setting
24616of @samp{set arm fallback-mode}.
24617
24618@item show arm force-mode
24619Show the current forced instruction mode.
24620
e2f4edfd
EZ
24621@item set debug arm
24622Toggle whether to display ARM-specific debugging messages from the ARM
24623target support subsystem.
24624
24625@item show debug arm
24626Show whether ARM-specific debugging messages are enabled.
24627@end table
24628
ee8e71d4
EZ
24629@table @code
24630@item target sim @r{[}@var{simargs}@r{]} @dots{}
24631The @value{GDBN} ARM simulator accepts the following optional arguments.
24632
24633@table @code
24634@item --swi-support=@var{type}
697aa1b7 24635Tell the simulator which SWI interfaces to support. The argument
ee8e71d4
EZ
24636@var{type} may be a comma separated list of the following values.
24637The default value is @code{all}.
24638
24639@table @code
24640@item none
24641@item demon
24642@item angel
24643@item redboot
24644@item all
24645@end table
24646@end table
24647@end table
e2f4edfd 24648
39791af2
JM
24649@node BPF
24650@subsection BPF
24651
24652@table @code
24653@item target sim @r{[}@var{simargs}@r{]} @dots{}
24654The @value{GDBN} BPF simulator accepts the following optional arguments.
24655
24656@table @code
24657@item --skb-data-offset=@var{offset}
24658Tell the simulator the offset, measured in bytes, of the
24659@code{skb_data} field in the kernel @code{struct sk_buff} structure.
24660This offset is used by some BPF specific-purpose load/store
24661instructions. Defaults to 0.
24662@end table
24663@end table
24664
8e04817f
AC
24665@node M68K
24666@subsection M68k
24667
bb615428 24668The Motorola m68k configuration includes ColdFire support.
8e04817f 24669
08be9d71
ME
24670@node MicroBlaze
24671@subsection MicroBlaze
24672@cindex Xilinx MicroBlaze
24673@cindex XMD, Xilinx Microprocessor Debugger
24674
24675The MicroBlaze is a soft-core processor supported on various Xilinx
24676FPGAs, such as Spartan or Virtex series. Boards with these processors
24677usually have JTAG ports which connect to a host system running the Xilinx
24678Embedded Development Kit (EDK) or Software Development Kit (SDK).
24679This host system is used to download the configuration bitstream to
24680the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
24681communicates with the target board using the JTAG interface and
24682presents a @code{gdbserver} interface to the board. By default
24683@code{xmd} uses port @code{1234}. (While it is possible to change
24684this default port, it requires the use of undocumented @code{xmd}
24685commands. Contact Xilinx support if you need to do this.)
24686
24687Use these GDB commands to connect to the MicroBlaze target processor.
24688
24689@table @code
24690@item target remote :1234
24691Use this command to connect to the target if you are running @value{GDBN}
24692on the same system as @code{xmd}.
24693
24694@item target remote @var{xmd-host}:1234
24695Use this command to connect to the target if it is connected to @code{xmd}
24696running on a different system named @var{xmd-host}.
24697
24698@item load
24699Use this command to download a program to the MicroBlaze target.
24700
24701@item set debug microblaze @var{n}
24702Enable MicroBlaze-specific debugging messages if non-zero.
24703
24704@item show debug microblaze @var{n}
24705Show MicroBlaze-specific debugging level.
24706@end table
24707
8e04817f 24708@node MIPS Embedded
eb17f351 24709@subsection @acronym{MIPS} Embedded
8e04817f 24710
8e04817f 24711@noindent
f7c38292 24712@value{GDBN} supports these special commands for @acronym{MIPS} targets:
104c1213 24713
8e04817f 24714@table @code
8e04817f
AC
24715@item set mipsfpu double
24716@itemx set mipsfpu single
24717@itemx set mipsfpu none
a64548ea 24718@itemx set mipsfpu auto
8e04817f
AC
24719@itemx show mipsfpu
24720@kindex set mipsfpu
24721@kindex show mipsfpu
eb17f351
EZ
24722@cindex @acronym{MIPS} remote floating point
24723@cindex floating point, @acronym{MIPS} remote
24724If your target board does not support the @acronym{MIPS} floating point
8e04817f
AC
24725coprocessor, you should use the command @samp{set mipsfpu none} (if you
24726need this, you may wish to put the command in your @value{GDBN} init
24727file). This tells @value{GDBN} how to find the return value of
24728functions which return floating point values. It also allows
24729@value{GDBN} to avoid saving the floating point registers when calling
24730functions on the board. If you are using a floating point coprocessor
24731with only single precision floating point support, as on the @sc{r4650}
24732processor, use the command @samp{set mipsfpu single}. The default
24733double precision floating point coprocessor may be selected using
24734@samp{set mipsfpu double}.
104c1213 24735
8e04817f
AC
24736In previous versions the only choices were double precision or no
24737floating point, so @samp{set mipsfpu on} will select double precision
24738and @samp{set mipsfpu off} will select no floating point.
104c1213 24739
8e04817f
AC
24740As usual, you can inquire about the @code{mipsfpu} variable with
24741@samp{show mipsfpu}.
8e04817f 24742@end table
104c1213 24743
a994fec4
FJ
24744@node OpenRISC 1000
24745@subsection OpenRISC 1000
24746@cindex OpenRISC 1000
24747
24748@noindent
24749The OpenRISC 1000 provides a free RISC instruction set architecture. It is
24750mainly provided as a soft-core which can run on Xilinx, Altera and other
24751FPGA's.
24752
24753@value{GDBN} for OpenRISC supports the below commands when connecting to
24754a target:
24755
24756@table @code
24757
24758@kindex target sim
24759@item target sim
24760
24761Runs the builtin CPU simulator which can run very basic
24762programs but does not support most hardware functions like MMU.
24763For more complex use cases the user is advised to run an external
24764target, and connect using @samp{target remote}.
24765
24766Example: @code{target sim}
24767
24768@item set debug or1k
24769Toggle whether to display OpenRISC-specific debugging messages from the
24770OpenRISC target support subsystem.
24771
24772@item show debug or1k
24773Show whether OpenRISC-specific debugging messages are enabled.
24774@end table
24775
4acd40f3
TJB
24776@node PowerPC Embedded
24777@subsection PowerPC Embedded
104c1213 24778
66b73624
TJB
24779@cindex DVC register
24780@value{GDBN} supports using the DVC (Data Value Compare) register to
24781implement in hardware simple hardware watchpoint conditions of the form:
24782
24783@smallexample
cc4bc93e
AB
24784(@value{GDBP}) watch @var{address|variable} \
24785 if @var{address|variable} == @var{constant expression}
66b73624
TJB
24786@end smallexample
24787
e09342b5
TJB
24788The DVC register will be automatically used when @value{GDBN} detects
24789such pattern in a condition expression, and the created watchpoint uses one
24790debug register (either the @code{exact-watchpoints} option is on and the
24791variable is scalar, or the variable has a length of one byte). This feature
24792is available in native @value{GDBN} running on a Linux kernel version 2.6.34
24793or newer.
24794
24795When running on PowerPC embedded processors, @value{GDBN} automatically uses
24796ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
24797in which case watchpoints using only one debug register are created when
24798watching variables of scalar types.
24799
24800You can create an artificial array to watch an arbitrary memory
24801region using one of the following commands (@pxref{Expressions}):
24802
24803@smallexample
24804(@value{GDBP}) watch *((char *) @var{address})@@@var{length}
24805(@value{GDBP}) watch @{char[@var{length}]@} @var{address}
24806@end smallexample
66b73624 24807
9c06b0b4
TJB
24808PowerPC embedded processors support masked watchpoints. See the discussion
24809about the @code{mask} argument in @ref{Set Watchpoints}.
24810
f1310107
TJB
24811@cindex ranged breakpoint
24812PowerPC embedded processors support hardware accelerated
24813@dfn{ranged breakpoints}. A ranged breakpoint stops execution of
24814the inferior whenever it executes an instruction at any address within
24815the range it specifies. To set a ranged breakpoint in @value{GDBN},
24816use the @code{break-range} command.
24817
55eddb0f
DJ
24818@value{GDBN} provides the following PowerPC-specific commands:
24819
104c1213 24820@table @code
f1310107
TJB
24821@kindex break-range
24822@item break-range @var{start-location}, @var{end-location}
697aa1b7
EZ
24823Set a breakpoint for an address range given by
24824@var{start-location} and @var{end-location}, which can specify a function name,
f1310107
TJB
24825a line number, an offset of lines from the current line or from the start
24826location, or an address of an instruction (see @ref{Specify Location},
24827for a list of all the possible ways to specify a @var{location}.)
24828The breakpoint will stop execution of the inferior whenever it
24829executes an instruction at any address within the specified range,
24830(including @var{start-location} and @var{end-location}.)
24831
55eddb0f
DJ
24832@kindex set powerpc
24833@item set powerpc soft-float
24834@itemx show powerpc soft-float
24835Force @value{GDBN} to use (or not use) a software floating point calling
24836convention. By default, @value{GDBN} selects the calling convention based
24837on the selected architecture and the provided executable file.
24838
24839@item set powerpc vector-abi
24840@itemx show powerpc vector-abi
24841Force @value{GDBN} to use the specified calling convention for vector
24842arguments and return values. The valid options are @samp{auto};
24843@samp{generic}, to avoid vector registers even if they are present;
24844@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
24845registers. By default, @value{GDBN} selects the calling convention
24846based on the selected architecture and the provided executable file.
24847
e09342b5
TJB
24848@item set powerpc exact-watchpoints
24849@itemx show powerpc exact-watchpoints
24850Allow @value{GDBN} to use only one debug register when watching a variable
24851of scalar type, thus assuming that the variable is accessed through the
24852address of its first byte.
24853
104c1213
JM
24854@end table
24855
a64548ea
EZ
24856@node AVR
24857@subsection Atmel AVR
24858@cindex AVR
24859
24860When configured for debugging the Atmel AVR, @value{GDBN} supports the
24861following AVR-specific commands:
24862
24863@table @code
24864@item info io_registers
24865@kindex info io_registers@r{, AVR}
24866@cindex I/O registers (Atmel AVR)
24867This command displays information about the AVR I/O registers. For
24868each register, @value{GDBN} prints its number and value.
24869@end table
24870
24871@node CRIS
24872@subsection CRIS
24873@cindex CRIS
24874
24875When configured for debugging CRIS, @value{GDBN} provides the
24876following CRIS-specific commands:
24877
24878@table @code
24879@item set cris-version @var{ver}
24880@cindex CRIS version
e22e55c9
OF
24881Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
24882The CRIS version affects register names and sizes. This command is useful in
24883case autodetection of the CRIS version fails.
a64548ea
EZ
24884
24885@item show cris-version
24886Show the current CRIS version.
24887
24888@item set cris-dwarf2-cfi
24889@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
24890Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
24891Change to @samp{off} when using @code{gcc-cris} whose version is below
24892@code{R59}.
a64548ea
EZ
24893
24894@item show cris-dwarf2-cfi
24895Show the current state of using DWARF-2 CFI.
e22e55c9
OF
24896
24897@item set cris-mode @var{mode}
24898@cindex CRIS mode
24899Set the current CRIS mode to @var{mode}. It should only be changed when
24900debugging in guru mode, in which case it should be set to
24901@samp{guru} (the default is @samp{normal}).
24902
24903@item show cris-mode
24904Show the current CRIS mode.
a64548ea
EZ
24905@end table
24906
24907@node Super-H
24908@subsection Renesas Super-H
24909@cindex Super-H
24910
24911For the Renesas Super-H processor, @value{GDBN} provides these
24912commands:
24913
24914@table @code
c055b101
CV
24915@item set sh calling-convention @var{convention}
24916@kindex set sh calling-convention
24917Set the calling-convention used when calling functions from @value{GDBN}.
24918Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
24919With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
24920convention. If the DWARF-2 information of the called function specifies
24921that the function follows the Renesas calling convention, the function
24922is called using the Renesas calling convention. If the calling convention
24923is set to @samp{renesas}, the Renesas calling convention is always used,
24924regardless of the DWARF-2 information. This can be used to override the
24925default of @samp{gcc} if debug information is missing, or the compiler
24926does not emit the DWARF-2 calling convention entry for a function.
24927
24928@item show sh calling-convention
24929@kindex show sh calling-convention
24930Show the current calling convention setting.
24931
a64548ea
EZ
24932@end table
24933
24934
8e04817f
AC
24935@node Architectures
24936@section Architectures
104c1213 24937
8e04817f
AC
24938This section describes characteristics of architectures that affect
24939all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 24940
8e04817f 24941@menu
430ed3f0 24942* AArch64::
9c16f35a 24943* i386::
8e04817f
AC
24944* Alpha::
24945* MIPS::
a64548ea 24946* HPPA:: HP PA architecture
4acd40f3 24947* PowerPC::
a1217d97 24948* Nios II::
58afddc6 24949* Sparc64::
51d21d60 24950* S12Z::
8e04817f 24951@end menu
104c1213 24952
430ed3f0
MS
24953@node AArch64
24954@subsection AArch64
24955@cindex AArch64 support
24956
24957When @value{GDBN} is debugging the AArch64 architecture, it provides the
24958following special commands:
24959
24960@table @code
24961@item set debug aarch64
24962@kindex set debug aarch64
24963This command determines whether AArch64 architecture-specific debugging
24964messages are to be displayed.
24965
24966@item show debug aarch64
24967Show whether AArch64 debugging messages are displayed.
24968
24969@end table
24970
1461bdac
AH
24971@subsubsection AArch64 SVE.
24972@cindex AArch64 SVE.
24973
24974When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
24975Extension (SVE) is present, then @value{GDBN} will provide the vector registers
24976@code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
24977@code{$p15}, and the @code{$ffr} register. In addition, the pseudo register
24978@code{$vg} will be provided. This is the vector granule for the current thread
24979and represents the number of 64-bit chunks in an SVE @code{z} register.
24980
24981If the vector length changes, then the @code{$vg} register will be updated,
24982but the lengths of the @code{z} and @code{p} registers will not change. This
24983is a known limitation of @value{GDBN} and does not affect the execution of the
24984target process.
24985
3d31bc39
AH
24986@subsubsection AArch64 Pointer Authentication.
24987@cindex AArch64 Pointer Authentication.
24988
24989When @value{GDBN} is debugging the AArch64 architecture, and the program is
24990using the v8.3-A feature Pointer Authentication (PAC), then whenever the link
1ba7cdcd 24991register @code{$lr} is pointing to an PAC function its value will be masked.
3d31bc39 24992When GDB prints a backtrace, any addresses that required unmasking will be
aa7ca1bb
AH
24993postfixed with the marker [PAC]. When using the MI, this is printed as part
24994of the @code{addr_flags} field.
1461bdac 24995
9c16f35a 24996@node i386
db2e3e2e 24997@subsection x86 Architecture-specific Issues
9c16f35a
EZ
24998
24999@table @code
25000@item set struct-convention @var{mode}
25001@kindex set struct-convention
25002@cindex struct return convention
25003@cindex struct/union returned in registers
25004Set the convention used by the inferior to return @code{struct}s and
25005@code{union}s from functions to @var{mode}. Possible values of
25006@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
25007default). @code{"default"} or @code{"pcc"} means that @code{struct}s
25008are returned on the stack, while @code{"reg"} means that a
25009@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
25010be returned in a register.
25011
25012@item show struct-convention
25013@kindex show struct-convention
25014Show the current setting of the convention to return @code{struct}s
25015from functions.
966f0aef 25016@end table
29c1c244 25017
ca8941bb 25018
bc504a31
PA
25019@subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
25020@cindex Intel Memory Protection Extensions (MPX).
ca8941bb 25021
ca8941bb
WT
25022Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
25023@footnote{The register named with capital letters represent the architecture
25024registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
25025which are the lower bound and upper bound. Bounds are effective addresses or
25026memory locations. The upper bounds are architecturally represented in 1's
25027complement form. A bound having lower bound = 0, and upper bound = 0
25028(1's complement of all bits set) will allow access to the entire address space.
25029
25030@samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
25031through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
25032display the upper bound performing the complement of one operation on the
25033upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
25034@value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
25035can also be noted that the upper bounds are inclusive.
25036
25037As an example, assume that the register BND0 holds bounds for a pointer having
25038access allowed for the range between 0x32 and 0x71. The values present on
25039bnd0raw and bnd registers are presented as follows:
25040
25041@smallexample
25042 bnd0raw = @{0x32, 0xffffffff8e@}
25043 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
25044@end smallexample
25045
22f25c9d
EZ
25046This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
25047change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
25048counterpart. When the bnd0@dots{}bnd3 registers are displayed via
25049Python, the display includes the memory size, in bits, accessible to
25050the pointer.
9c16f35a 25051
29c1c244
WT
25052Bounds can also be stored in bounds tables, which are stored in
25053application memory. These tables store bounds for pointers by specifying
25054the bounds pointer's value along with its bounds. Evaluating and changing
25055bounds located in bound tables is therefore interesting while investigating
25056bugs on MPX context. @value{GDBN} provides commands for this purpose:
25057
966f0aef 25058@table @code
29c1c244
WT
25059@item show mpx bound @var{pointer}
25060@kindex show mpx bound
25061Display bounds of the given @var{pointer}.
25062
25063@item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
25064@kindex set mpx bound
25065Set the bounds of a pointer in the bound table.
25066This command takes three parameters: @var{pointer} is the pointers
25067whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
25068for lower and upper bounds respectively.
25069@end table
25070
4a612d6f
WT
25071When you call an inferior function on an Intel MPX enabled program,
25072GDB sets the inferior's bound registers to the init (disabled) state
25073before calling the function. As a consequence, bounds checks for the
25074pointer arguments passed to the function will always pass.
25075
25076This is necessary because when you call an inferior function, the
25077program is usually in the middle of the execution of other function.
25078Since at that point bound registers are in an arbitrary state, not
25079clearing them would lead to random bound violations in the called
25080function.
25081
25082You can still examine the influence of the bound registers on the
25083execution of the called function by stopping the execution of the
25084called function at its prologue, setting bound registers, and
25085continuing the execution. For example:
25086
25087@smallexample
25088 $ break *upper
25089 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
25090 $ print upper (a, b, c, d, 1)
25091 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
25092 $ print $bnd0
5cf70512 25093 @{lbound = 0x0, ubound = ffffffff@} : size -1
4a612d6f
WT
25094@end smallexample
25095
25096At this last step the value of bnd0 can be changed for investigation of bound
25097violations caused along the execution of the call. In order to know how to
25098set the bound registers or bound table for the call consult the ABI.
25099
8e04817f
AC
25100@node Alpha
25101@subsection Alpha
104c1213 25102
8e04817f 25103See the following section.
104c1213 25104
8e04817f 25105@node MIPS
eb17f351 25106@subsection @acronym{MIPS}
104c1213 25107
8e04817f 25108@cindex stack on Alpha
eb17f351 25109@cindex stack on @acronym{MIPS}
8e04817f 25110@cindex Alpha stack
eb17f351
EZ
25111@cindex @acronym{MIPS} stack
25112Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
8e04817f
AC
25113sometimes requires @value{GDBN} to search backward in the object code to
25114find the beginning of a function.
104c1213 25115
eb17f351 25116@cindex response time, @acronym{MIPS} debugging
8e04817f
AC
25117To improve response time (especially for embedded applications, where
25118@value{GDBN} may be restricted to a slow serial line for this search)
25119you may want to limit the size of this search, using one of these
25120commands:
104c1213 25121
8e04817f 25122@table @code
eb17f351 25123@cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
8e04817f
AC
25124@item set heuristic-fence-post @var{limit}
25125Restrict @value{GDBN} to examining at most @var{limit} bytes in its
25126search for the beginning of a function. A value of @var{0} (the
25127default) means there is no limit. However, except for @var{0}, the
25128larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
25129and therefore the longer it takes to run. You should only need to use
25130this command when debugging a stripped executable.
104c1213 25131
8e04817f
AC
25132@item show heuristic-fence-post
25133Display the current limit.
25134@end table
104c1213
JM
25135
25136@noindent
8e04817f 25137These commands are available @emph{only} when @value{GDBN} is configured
eb17f351 25138for debugging programs on Alpha or @acronym{MIPS} processors.
104c1213 25139
eb17f351 25140Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
a64548ea
EZ
25141programs:
25142
25143@table @code
a64548ea
EZ
25144@item set mips abi @var{arg}
25145@kindex set mips abi
eb17f351
EZ
25146@cindex set ABI for @acronym{MIPS}
25147Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
a64548ea
EZ
25148values of @var{arg} are:
25149
25150@table @samp
25151@item auto
25152The default ABI associated with the current binary (this is the
25153default).
25154@item o32
25155@item o64
25156@item n32
25157@item n64
25158@item eabi32
25159@item eabi64
a64548ea
EZ
25160@end table
25161
25162@item show mips abi
25163@kindex show mips abi
eb17f351 25164Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
a64548ea 25165
4cc0665f
MR
25166@item set mips compression @var{arg}
25167@kindex set mips compression
25168@cindex code compression, @acronym{MIPS}
25169Tell @value{GDBN} which @acronym{MIPS} compressed
25170@acronym{ISA, Instruction Set Architecture} encoding is used by the
25171inferior. @value{GDBN} uses this for code disassembly and other
25172internal interpretation purposes. This setting is only referred to
25173when no executable has been associated with the debugging session or
25174the executable does not provide information about the encoding it uses.
25175Otherwise this setting is automatically updated from information
25176provided by the executable.
25177
25178Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
25179The default compressed @acronym{ISA} encoding is @samp{mips16}, as
25180executables containing @acronym{MIPS16} code frequently are not
25181identified as such.
25182
25183This setting is ``sticky''; that is, it retains its value across
25184debugging sessions until reset either explicitly with this command or
25185implicitly from an executable.
25186
25187The compiler and/or assembler typically add symbol table annotations to
25188identify functions compiled for the @acronym{MIPS16} or
25189@acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
25190are present, @value{GDBN} uses them in preference to the global
25191compressed @acronym{ISA} encoding setting.
25192
25193@item show mips compression
25194@kindex show mips compression
25195Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
25196@value{GDBN} to debug the inferior.
25197
a64548ea
EZ
25198@item set mipsfpu
25199@itemx show mipsfpu
25200@xref{MIPS Embedded, set mipsfpu}.
25201
25202@item set mips mask-address @var{arg}
25203@kindex set mips mask-address
eb17f351 25204@cindex @acronym{MIPS} addresses, masking
a64548ea 25205This command determines whether the most-significant 32 bits of 64-bit
eb17f351 25206@acronym{MIPS} addresses are masked off. The argument @var{arg} can be
a64548ea
EZ
25207@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
25208setting, which lets @value{GDBN} determine the correct value.
25209
25210@item show mips mask-address
25211@kindex show mips mask-address
eb17f351 25212Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
a64548ea
EZ
25213not.
25214
25215@item set remote-mips64-transfers-32bit-regs
25216@kindex set remote-mips64-transfers-32bit-regs
eb17f351
EZ
25217This command controls compatibility with 64-bit @acronym{MIPS} targets that
25218transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
a64548ea
EZ
25219that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
25220and 64 bits for other registers, set this option to @samp{on}.
25221
25222@item show remote-mips64-transfers-32bit-regs
25223@kindex show remote-mips64-transfers-32bit-regs
eb17f351 25224Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
a64548ea
EZ
25225
25226@item set debug mips
25227@kindex set debug mips
eb17f351 25228This command turns on and off debugging messages for the @acronym{MIPS}-specific
a64548ea
EZ
25229target code in @value{GDBN}.
25230
25231@item show debug mips
25232@kindex show debug mips
eb17f351 25233Show the current setting of @acronym{MIPS} debugging messages.
a64548ea
EZ
25234@end table
25235
25236
25237@node HPPA
25238@subsection HPPA
25239@cindex HPPA support
25240
d3e8051b 25241When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
25242following special commands:
25243
25244@table @code
25245@item set debug hppa
25246@kindex set debug hppa
db2e3e2e 25247This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
25248messages are to be displayed.
25249
25250@item show debug hppa
25251Show whether HPPA debugging messages are displayed.
25252
25253@item maint print unwind @var{address}
25254@kindex maint print unwind@r{, HPPA}
25255This command displays the contents of the unwind table entry at the
25256given @var{address}.
25257
25258@end table
25259
104c1213 25260
4acd40f3
TJB
25261@node PowerPC
25262@subsection PowerPC
25263@cindex PowerPC architecture
25264
25265When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
25266pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
25267numbers stored in the floating point registers. These values must be stored
25268in two consecutive registers, always starting at an even register like
25269@code{f0} or @code{f2}.
25270
25271The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
25272by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
25273@code{f2} and @code{f3} for @code{$dl1} and so on.
25274
aeac0ff9 25275For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
677c5bb1
LM
25276wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
25277
a1217d97
SL
25278@node Nios II
25279@subsection Nios II
25280@cindex Nios II architecture
25281
25282When @value{GDBN} is debugging the Nios II architecture,
25283it provides the following special commands:
25284
25285@table @code
25286
25287@item set debug nios2
25288@kindex set debug nios2
25289This command turns on and off debugging messages for the Nios II
25290target code in @value{GDBN}.
25291
25292@item show debug nios2
25293@kindex show debug nios2
25294Show the current setting of Nios II debugging messages.
25295@end table
23d964e7 25296
58afddc6
WP
25297@node Sparc64
25298@subsection Sparc64
25299@cindex Sparc64 support
25300@cindex Application Data Integrity
25301@subsubsection ADI Support
25302
25303The M7 processor supports an Application Data Integrity (ADI) feature that
25304detects invalid data accesses. When software allocates memory and enables
25305ADI on the allocated memory, it chooses a 4-bit version number, sets the
25306version in the upper 4 bits of the 64-bit pointer to that data, and stores
25307the 4-bit version in every cacheline of that data. Hardware saves the latter
25308in spare bits in the cache and memory hierarchy. On each load and store,
25309the processor compares the upper 4 VA (virtual address) bits to the
25310cacheline's version. If there is a mismatch, the processor generates a
25311version mismatch trap which can be either precise or disrupting. The trap
25312is an error condition which the kernel delivers to the process as a SIGSEGV
25313signal.
25314
25315Note that only 64-bit applications can use ADI and need to be built with
25316ADI-enabled.
25317
25318Values of the ADI version tags, which are in granularity of a
25319cacheline (64 bytes), can be viewed or modified.
25320
25321
25322@table @code
25323@kindex adi examine
25324@item adi (examine | x) [ / @var{n} ] @var{addr}
25325
25326The @code{adi examine} command displays the value of one ADI version tag per
25327cacheline.
25328
25329@var{n} is a decimal integer specifying the number in bytes; the default
25330is 1. It specifies how much ADI version information, at the ratio of 1:ADI
25331block size, to display.
25332
25333@var{addr} is the address in user address space where you want @value{GDBN}
25334to begin displaying the ADI version tags.
25335
25336Below is an example of displaying ADI versions of variable "shmaddr".
25337
25338@smallexample
25339(@value{GDBP}) adi x/100 shmaddr
25340 0xfff800010002c000: 0 0
25341@end smallexample
25342
25343@kindex adi assign
25344@item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
25345
25346The @code{adi assign} command is used to assign new ADI version tag
25347to an address.
25348
25349@var{n} is a decimal integer specifying the number in bytes;
25350the default is 1. It specifies how much ADI version information, at the
25351ratio of 1:ADI block size, to modify.
25352
25353@var{addr} is the address in user address space where you want @value{GDBN}
25354to begin modifying the ADI version tags.
25355
25356@var{tag} is the new ADI version tag.
25357
25358For example, do the following to modify then verify ADI versions of
25359variable "shmaddr":
25360
25361@smallexample
25362(@value{GDBP}) adi a/100 shmaddr = 7
25363(@value{GDBP}) adi x/100 shmaddr
25364 0xfff800010002c000: 7 7
25365@end smallexample
25366
25367@end table
25368
51d21d60
JD
25369@node S12Z
25370@subsection S12Z
25371@cindex S12Z support
25372
25373When @value{GDBN} is debugging the S12Z architecture,
25374it provides the following special command:
25375
25376@table @code
25377@item maint info bdccsr
25378@kindex maint info bdccsr@r{, S12Z}
25379This command displays the current value of the microprocessor's
25380BDCCSR register.
25381@end table
25382
25383
8e04817f
AC
25384@node Controlling GDB
25385@chapter Controlling @value{GDBN}
25386
25387You can alter the way @value{GDBN} interacts with you by using the
25388@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 25389data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
25390described here.
25391
25392@menu
25393* Prompt:: Prompt
25394* Editing:: Command editing
d620b259 25395* Command History:: Command history
8e04817f 25396* Screen Size:: Screen size
140a4bc0 25397* Output Styling:: Output styling
8e04817f 25398* Numbers:: Numbers
1e698235 25399* ABI:: Configuring the current ABI
bf88dd68 25400* Auto-loading:: Automatically loading associated files
8e04817f
AC
25401* Messages/Warnings:: Optional warnings and messages
25402* Debugging Output:: Optional messages about internal happenings
14fb1bac 25403* Other Misc Settings:: Other Miscellaneous Settings
8e04817f
AC
25404@end menu
25405
25406@node Prompt
25407@section Prompt
104c1213 25408
8e04817f 25409@cindex prompt
104c1213 25410
8e04817f
AC
25411@value{GDBN} indicates its readiness to read a command by printing a string
25412called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
25413can change the prompt string with the @code{set prompt} command. For
25414instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
25415the prompt in one of the @value{GDBN} sessions so that you can always tell
25416which one you are talking to.
104c1213 25417
8e04817f
AC
25418@emph{Note:} @code{set prompt} does not add a space for you after the
25419prompt you set. This allows you to set a prompt which ends in a space
25420or a prompt that does not.
104c1213 25421
8e04817f
AC
25422@table @code
25423@kindex set prompt
25424@item set prompt @var{newprompt}
25425Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 25426
8e04817f
AC
25427@kindex show prompt
25428@item show prompt
25429Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
25430@end table
25431
fa3a4f15
PM
25432Versions of @value{GDBN} that ship with Python scripting enabled have
25433prompt extensions. The commands for interacting with these extensions
25434are:
25435
25436@table @code
25437@kindex set extended-prompt
25438@item set extended-prompt @var{prompt}
25439Set an extended prompt that allows for substitutions.
25440@xref{gdb.prompt}, for a list of escape sequences that can be used for
25441substitution. Any escape sequences specified as part of the prompt
25442string are replaced with the corresponding strings each time the prompt
25443is displayed.
25444
25445For example:
25446
25447@smallexample
25448set extended-prompt Current working directory: \w (gdb)
25449@end smallexample
25450
25451Note that when an extended-prompt is set, it takes control of the
25452@var{prompt_hook} hook. @xref{prompt_hook}, for further information.
25453
25454@kindex show extended-prompt
25455@item show extended-prompt
25456Prints the extended prompt. Any escape sequences specified as part of
25457the prompt string with @code{set extended-prompt}, are replaced with the
25458corresponding strings each time the prompt is displayed.
25459@end table
25460
8e04817f 25461@node Editing
79a6e687 25462@section Command Editing
8e04817f
AC
25463@cindex readline
25464@cindex command line editing
104c1213 25465
703663ab 25466@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
25467@sc{gnu} library provides consistent behavior for programs which provide a
25468command line interface to the user. Advantages are @sc{gnu} Emacs-style
25469or @dfn{vi}-style inline editing of commands, @code{csh}-like history
25470substitution, and a storage and recall of command history across
25471debugging sessions.
104c1213 25472
8e04817f
AC
25473You may control the behavior of command line editing in @value{GDBN} with the
25474command @code{set}.
104c1213 25475
8e04817f
AC
25476@table @code
25477@kindex set editing
25478@cindex editing
25479@item set editing
25480@itemx set editing on
25481Enable command line editing (enabled by default).
104c1213 25482
8e04817f
AC
25483@item set editing off
25484Disable command line editing.
104c1213 25485
8e04817f
AC
25486@kindex show editing
25487@item show editing
25488Show whether command line editing is enabled.
104c1213
JM
25489@end table
25490
39037522
TT
25491@ifset SYSTEM_READLINE
25492@xref{Command Line Editing, , , rluserman, GNU Readline Library},
25493@end ifset
25494@ifclear SYSTEM_READLINE
25495@xref{Command Line Editing},
25496@end ifclear
25497for more details about the Readline
703663ab
EZ
25498interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
25499encouraged to read that chapter.
25500
11061048
TT
25501@cindex Readline application name
25502@value{GDBN} sets the Readline application name to @samp{gdb}. This
25503is useful for conditions in @file{.inputrc}.
25504
c71acd15
TT
25505@cindex operate-and-get-next
25506@value{GDBN} defines a bindable Readline command,
25507@code{operate-and-get-next}. This is bound to @kbd{C-o} by default.
25508This command accepts the current line for execution and fetches the
25509next line relative to the current line from the history for editing.
25510Any argument is ignored.
25511
d620b259 25512@node Command History
79a6e687 25513@section Command History
703663ab 25514@cindex command history
8e04817f
AC
25515
25516@value{GDBN} can keep track of the commands you type during your
25517debugging sessions, so that you can be certain of precisely what
25518happened. Use these commands to manage the @value{GDBN} command
25519history facility.
104c1213 25520
703663ab 25521@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
39037522
TT
25522package, to provide the history facility.
25523@ifset SYSTEM_READLINE
25524@xref{Using History Interactively, , , history, GNU History Library},
25525@end ifset
25526@ifclear SYSTEM_READLINE
25527@xref{Using History Interactively},
25528@end ifclear
25529for the detailed description of the History library.
703663ab 25530
d620b259 25531To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
25532the state which is seen by users, prefix it with @samp{server }
25533(@pxref{Server Prefix}). This
d620b259
NR
25534means that this command will not affect the command history, nor will it
25535affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
25536pressed on a line by itself.
25537
25538@cindex @code{server}, command prefix
25539The server prefix does not affect the recording of values into the value
25540history; to print a value without recording it into the value history,
25541use the @code{output} command instead of the @code{print} command.
25542
703663ab
EZ
25543Here is the description of @value{GDBN} commands related to command
25544history.
25545
104c1213 25546@table @code
8e04817f
AC
25547@cindex history substitution
25548@cindex history file
25549@kindex set history filename
4644b6e3 25550@cindex @env{GDBHISTFILE}, environment variable
63e163f2 25551@item set history filename @r{[}@var{fname}@r{]}
8e04817f
AC
25552Set the name of the @value{GDBN} command history file to @var{fname}.
25553This is the file where @value{GDBN} reads an initial command history
25554list, and where it writes the command history from this session when it
25555exits. You can access this list through history expansion or through
25556the history command editing characters listed below. This file defaults
25557to the value of the environment variable @code{GDBHISTFILE}, or to
25558@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
25559is not set.
104c1213 25560
63e163f2
AB
25561The @code{GDBHISTFILE} environment variable is read after processing
25562any @value{GDBN} initialization files (@pxref{Startup}) and after
25563processing any commands passed using command line options (for
25564example, @code{-ex}).
25565
25566If the @var{fname} argument is not given, or if the @code{GDBHISTFILE}
25567is the empty string then @value{GDBN} will neither try to load an
25568existing history file, nor will it try to save the history on exit.
25569
9c16f35a
EZ
25570@cindex save command history
25571@kindex set history save
8e04817f
AC
25572@item set history save
25573@itemx set history save on
25574Record command history in a file, whose name may be specified with the
63e163f2
AB
25575@code{set history filename} command. By default, this option is
25576disabled. The command history will be recorded when @value{GDBN}
25577exits. If @code{set history filename} is set to the empty string then
25578history saving is disabled, even when @code{set history save} is
25579@code{on}.
104c1213 25580
8e04817f 25581@item set history save off
63e163f2
AB
25582Don't record the command history into the file specified by @code{set
25583history filename} when @value{GDBN} exits.
104c1213 25584
8e04817f 25585@cindex history size
9c16f35a 25586@kindex set history size
b58c513b 25587@cindex @env{GDBHISTSIZE}, environment variable
8e04817f 25588@item set history size @var{size}
f81d1120 25589@itemx set history size unlimited
8e04817f 25590Set the number of commands which @value{GDBN} keeps in its history list.
bc460514
PP
25591This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
25592to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
0eacb298
PP
25593are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
25594either a negative number or the empty string, then the number of commands
25595@value{GDBN} keeps in the history list is unlimited.
fc637f04 25596
63e163f2
AB
25597The @code{GDBHISTSIZE} environment variable is read after processing
25598any @value{GDBN} initialization files (@pxref{Startup}) and after
25599processing any commands passed using command line options (for
25600example, @code{-ex}).
25601
fc637f04
PP
25602@cindex remove duplicate history
25603@kindex set history remove-duplicates
25604@item set history remove-duplicates @var{count}
25605@itemx set history remove-duplicates unlimited
25606Control the removal of duplicate history entries in the command history list.
25607If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
25608history entries and remove the first entry that is a duplicate of the current
25609entry being added to the command history list. If @var{count} is
25610@code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
25611removal of duplicate history entries is disabled.
25612
25613Only history entries added during the current session are considered for
25614removal. This option is set to 0 by default.
25615
104c1213
JM
25616@end table
25617
8e04817f 25618History expansion assigns special meaning to the character @kbd{!}.
39037522
TT
25619@ifset SYSTEM_READLINE
25620@xref{Event Designators, , , history, GNU History Library},
25621@end ifset
25622@ifclear SYSTEM_READLINE
25623@xref{Event Designators},
25624@end ifclear
25625for more details.
8e04817f 25626
703663ab 25627@cindex history expansion, turn on/off
8e04817f
AC
25628Since @kbd{!} is also the logical not operator in C, history expansion
25629is off by default. If you decide to enable history expansion with the
25630@code{set history expansion on} command, you may sometimes need to
25631follow @kbd{!} (when it is used as logical not, in an expression) with
25632a space or a tab to prevent it from being expanded. The readline
25633history facilities do not attempt substitution on the strings
25634@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
25635
25636The commands to control history expansion are:
104c1213
JM
25637
25638@table @code
8e04817f
AC
25639@item set history expansion on
25640@itemx set history expansion
703663ab 25641@kindex set history expansion
8e04817f 25642Enable history expansion. History expansion is off by default.
104c1213 25643
8e04817f
AC
25644@item set history expansion off
25645Disable history expansion.
104c1213 25646
8e04817f
AC
25647@c @group
25648@kindex show history
25649@item show history
25650@itemx show history filename
25651@itemx show history save
25652@itemx show history size
25653@itemx show history expansion
25654These commands display the state of the @value{GDBN} history parameters.
25655@code{show history} by itself displays all four states.
25656@c @end group
25657@end table
25658
25659@table @code
9c16f35a
EZ
25660@kindex show commands
25661@cindex show last commands
25662@cindex display command history
8e04817f
AC
25663@item show commands
25664Display the last ten commands in the command history.
104c1213 25665
8e04817f
AC
25666@item show commands @var{n}
25667Print ten commands centered on command number @var{n}.
25668
25669@item show commands +
25670Print ten commands just after the commands last printed.
104c1213
JM
25671@end table
25672
8e04817f 25673@node Screen Size
79a6e687 25674@section Screen Size
8e04817f 25675@cindex size of screen
f179cf97
EZ
25676@cindex screen size
25677@cindex pagination
25678@cindex page size
8e04817f 25679@cindex pauses in output
104c1213 25680
8e04817f
AC
25681Certain commands to @value{GDBN} may produce large amounts of
25682information output to the screen. To help you read all of it,
25683@value{GDBN} pauses and asks you for input at the end of each page of
eb6af809
TT
25684output. Type @key{RET} when you want to see one more page of output,
25685@kbd{q} to discard the remaining output, or @kbd{c} to continue
25686without paging for the rest of the current command. Also, the screen
25687width setting determines when to wrap lines of output. Depending on
25688what is being printed, @value{GDBN} tries to break the line at a
25689readable place, rather than simply letting it overflow onto the
25690following line.
8e04817f
AC
25691
25692Normally @value{GDBN} knows the size of the screen from the terminal
25693driver software. For example, on Unix @value{GDBN} uses the termcap data base
25694together with the value of the @code{TERM} environment variable and the
25695@code{stty rows} and @code{stty cols} settings. If this is not correct,
25696you can override it with the @code{set height} and @code{set
25697width} commands:
25698
25699@table @code
25700@kindex set height
25701@kindex set width
25702@kindex show width
25703@kindex show height
25704@item set height @var{lpp}
f81d1120 25705@itemx set height unlimited
8e04817f
AC
25706@itemx show height
25707@itemx set width @var{cpl}
f81d1120 25708@itemx set width unlimited
8e04817f
AC
25709@itemx show width
25710These @code{set} commands specify a screen height of @var{lpp} lines and
25711a screen width of @var{cpl} characters. The associated @code{show}
25712commands display the current settings.
104c1213 25713
f81d1120
PA
25714If you specify a height of either @code{unlimited} or zero lines,
25715@value{GDBN} does not pause during output no matter how long the
25716output is. This is useful if output is to a file or to an editor
25717buffer.
104c1213 25718
f81d1120
PA
25719Likewise, you can specify @samp{set width unlimited} or @samp{set
25720width 0} to prevent @value{GDBN} from wrapping its output.
9c16f35a
EZ
25721
25722@item set pagination on
25723@itemx set pagination off
25724@kindex set pagination
25725Turn the output pagination on or off; the default is on. Turning
f81d1120 25726pagination off is the alternative to @code{set height unlimited}. Note that
7c953934
TT
25727running @value{GDBN} with the @option{--batch} option (@pxref{Mode
25728Options, -batch}) also automatically disables pagination.
9c16f35a
EZ
25729
25730@item show pagination
25731@kindex show pagination
25732Show the current pagination mode.
104c1213
JM
25733@end table
25734
140a4bc0
TT
25735@node Output Styling
25736@section Output Styling
25737@cindex styling
25738@cindex colors
25739
25740@kindex set style
25741@kindex show style
25742@value{GDBN} can style its output on a capable terminal. This is
7557a514
AH
25743enabled by default on most systems, but disabled by default when in
25744batch mode (@pxref{Mode Options}). Various style settings are available;
25745and styles can also be disabled entirely.
140a4bc0
TT
25746
25747@table @code
25748@item set style enabled @samp{on|off}
25749Enable or disable all styling. The default is host-dependent, with
25750most hosts defaulting to @samp{on}.
25751
25752@item show style enabled
25753Show the current state of styling.
d085f989
TT
25754
25755@item set style sources @samp{on|off}
25756Enable or disable source code styling. This affects whether source
25757code, such as the output of the @code{list} command, is styled. Note
25758that source styling only works if styling in general is enabled, and
25759if @value{GDBN} was linked with the GNU Source Highlight library. The
25760default is @samp{on}.
25761
25762@item show style sources
25763Show the current state of source code styling.
140a4bc0
TT
25764@end table
25765
25766Subcommands of @code{set style} control specific forms of styling.
25767These subcommands all follow the same pattern: each style-able object
25768can be styled with a foreground color, a background color, and an
25769intensity.
25770
25771For example, the style of file names can be controlled using the
25772@code{set style filename} group of commands:
25773
25774@table @code
25775@item set style filename background @var{color}
25776Set the background to @var{color}. Valid colors are @samp{none}
25777(meaning the terminal's default color), @samp{black}, @samp{red},
e3624a40 25778@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
140a4bc0
TT
25779and@samp{white}.
25780
25781@item set style filename foreground @var{color}
25782Set the foreground to @var{color}. Valid colors are @samp{none}
25783(meaning the terminal's default color), @samp{black}, @samp{red},
e3624a40 25784@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
140a4bc0
TT
25785and@samp{white}.
25786
25787@item set style filename intensity @var{value}
25788Set the intensity to @var{value}. Valid intensities are @samp{normal}
25789(the default), @samp{bold}, and @samp{dim}.
25790@end table
25791
e664d728
PW
25792The @code{show style} command and its subcommands are styling
25793a style name in their output using its own style.
25794So, use @command{show style} to see the complete list of styles,
25795their characteristics and the visual aspect of each style.
25796
140a4bc0
TT
25797The style-able objects are:
25798@table @code
25799@item filename
e3624a40
EZ
25800Control the styling of file names. By default, this style's
25801foreground color is green.
140a4bc0
TT
25802
25803@item function
25804Control the styling of function names. These are managed with the
e3624a40
EZ
25805@code{set style function} family of commands. By default, this
25806style's foreground color is yellow.
140a4bc0
TT
25807
25808@item variable
25809Control the styling of variable names. These are managed with the
e3624a40
EZ
25810@code{set style variable} family of commands. By default, this style's
25811foreground color is cyan.
140a4bc0
TT
25812
25813@item address
25814Control the styling of addresses. These are managed with the
e3624a40
EZ
25815@code{set style address} family of commands. By default, this style's
25816foreground color is blue.
e664d728 25817
9d2d8a16
AB
25818@item version
25819Control the styling of @value{GDBN}'s version number text. By
25820default, this style's foreground color is magenta and it has bold
25821intensity. The version number is displayed in two places, the output
25822of @command{show version}, and when @value{GDBN} starts up.
25823
25824Currently the version string displayed at startup is printed before
25825@value{GDBN} has parsed any command line options, or parsed any
25826command files, so there is currently no way to control the styling of
25827this string. However, @value{GDBN}'s @code{--quiet} command line option
25828can be used to disable printing of the version string on startup.
25829
e664d728
PW
25830@item title
25831Control the styling of titles. These are managed with the
25832@code{set style title} family of commands. By default, this style's
25833intensity is bold. Commands are using the title style to improve
6b92c0d3 25834the readability of large output. For example, the commands
e664d728
PW
25835@command{apropos} and @command{help} are using the title style
25836for the command names.
25837
25838@item highlight
25839Control the styling of highlightings. These are managed with the
25840@code{set style highlight} family of commands. By default, this style's
25841foreground color is red. Commands are using the highlight style to draw
25842the user attention to some specific parts of their output. For example,
25843the command @command{apropos -v REGEXP} uses the highlight style to
25844mark the documentation parts matching @var{regexp}.
25845
a2a7af0c
TT
25846@item tui-border
25847Control the styling of the TUI border. Note that, unlike other
25848styling options, only the color of the border can be controlled via
25849@code{set style}. This was done for compatibility reasons, as TUI
25850controls to set the border's intensity predated the addition of
25851general styling to @value{GDBN}. @xref{TUI Configuration}.
25852
25853@item tui-active-border
25854Control the styling of the active TUI border; that is, the TUI window
25855that has the focus.
25856
140a4bc0
TT
25857@end table
25858
8e04817f
AC
25859@node Numbers
25860@section Numbers
25861@cindex number representation
25862@cindex entering numbers
104c1213 25863
8e04817f
AC
25864You can always enter numbers in octal, decimal, or hexadecimal in
25865@value{GDBN} by the usual conventions: octal numbers begin with
25866@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
25867begin with @samp{0x}. Numbers that neither begin with @samp{0} or
25868@samp{0x}, nor end with a @samp{.} are, by default, entered in base
2586910; likewise, the default display for numbers---when no particular
25870format is specified---is base 10. You can change the default base for
25871both input and output with the commands described below.
104c1213 25872
8e04817f
AC
25873@table @code
25874@kindex set input-radix
25875@item set input-radix @var{base}
25876Set the default base for numeric input. Supported choices
697aa1b7 25877for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 25878specified either unambiguously or using the current input radix; for
8e04817f 25879example, any of
104c1213 25880
8e04817f 25881@smallexample
9c16f35a
EZ
25882set input-radix 012
25883set input-radix 10.
25884set input-radix 0xa
8e04817f 25885@end smallexample
104c1213 25886
8e04817f 25887@noindent
9c16f35a 25888sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
25889leaves the input radix unchanged, no matter what it was, since
25890@samp{10}, being without any leading or trailing signs of its base, is
25891interpreted in the current radix. Thus, if the current radix is 16,
25892@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
25893change the radix.
104c1213 25894
8e04817f
AC
25895@kindex set output-radix
25896@item set output-radix @var{base}
25897Set the default base for numeric display. Supported choices
697aa1b7 25898for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 25899specified either unambiguously or using the current input radix.
104c1213 25900
8e04817f
AC
25901@kindex show input-radix
25902@item show input-radix
25903Display the current default base for numeric input.
104c1213 25904
8e04817f
AC
25905@kindex show output-radix
25906@item show output-radix
25907Display the current default base for numeric display.
9c16f35a
EZ
25908
25909@item set radix @r{[}@var{base}@r{]}
25910@itemx show radix
25911@kindex set radix
25912@kindex show radix
25913These commands set and show the default base for both input and output
25914of numbers. @code{set radix} sets the radix of input and output to
25915the same base; without an argument, it resets the radix back to its
25916default value of 10.
25917
8e04817f 25918@end table
104c1213 25919
1e698235 25920@node ABI
79a6e687 25921@section Configuring the Current ABI
1e698235
DJ
25922
25923@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
25924application automatically. However, sometimes you need to override its
25925conclusions. Use these commands to manage @value{GDBN}'s view of the
25926current ABI.
25927
98b45e30
DJ
25928@cindex OS ABI
25929@kindex set osabi
b4e9345d 25930@kindex show osabi
430ed3f0 25931@cindex Newlib OS ABI and its influence on the longjmp handling
98b45e30
DJ
25932
25933One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 25934system targets, either via remote debugging or native emulation.
98b45e30
DJ
25935@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
25936but you can override its conclusion using the @code{set osabi} command.
25937One example where this is useful is in debugging of binaries which use
25938an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
25939not have the same identifying marks that the standard C library for your
25940platform provides.
25941
430ed3f0
MS
25942When @value{GDBN} is debugging the AArch64 architecture, it provides a
25943``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
25944@code{longjmp} when debugging binaries that use the @sc{newlib} C library.
25945The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
25946
98b45e30
DJ
25947@table @code
25948@item show osabi
25949Show the OS ABI currently in use.
25950
25951@item set osabi
25952With no argument, show the list of registered available OS ABI's.
25953
25954@item set osabi @var{abi}
25955Set the current OS ABI to @var{abi}.
25956@end table
25957
1e698235 25958@cindex float promotion
1e698235
DJ
25959
25960Generally, the way that an argument of type @code{float} is passed to a
25961function depends on whether the function is prototyped. For a prototyped
25962(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
25963according to the architecture's convention for @code{float}. For unprototyped
25964(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
25965@code{double} and then passed.
25966
25967Unfortunately, some forms of debug information do not reliably indicate whether
25968a function is prototyped. If @value{GDBN} calls a function that is not marked
25969as prototyped, it consults @kbd{set coerce-float-to-double}.
25970
25971@table @code
a8f24a35 25972@kindex set coerce-float-to-double
1e698235
DJ
25973@item set coerce-float-to-double
25974@itemx set coerce-float-to-double on
25975Arguments of type @code{float} will be promoted to @code{double} when passed
25976to an unprototyped function. This is the default setting.
25977
25978@item set coerce-float-to-double off
25979Arguments of type @code{float} will be passed directly to unprototyped
25980functions.
9c16f35a
EZ
25981
25982@kindex show coerce-float-to-double
25983@item show coerce-float-to-double
25984Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
25985@end table
25986
f1212245
DJ
25987@kindex set cp-abi
25988@kindex show cp-abi
25989@value{GDBN} needs to know the ABI used for your program's C@t{++}
25990objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
25991used to build your application. @value{GDBN} only fully supports
25992programs with a single C@t{++} ABI; if your program contains code using
25993multiple C@t{++} ABI's or if @value{GDBN} can not identify your
25994program's ABI correctly, you can tell @value{GDBN} which ABI to use.
25995Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
25996before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
25997``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
25998use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
25999``auto''.
26000
26001@table @code
26002@item show cp-abi
26003Show the C@t{++} ABI currently in use.
26004
26005@item set cp-abi
26006With no argument, show the list of supported C@t{++} ABI's.
26007
26008@item set cp-abi @var{abi}
26009@itemx set cp-abi auto
26010Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
26011@end table
26012
bf88dd68
JK
26013@node Auto-loading
26014@section Automatically loading associated files
26015@cindex auto-loading
26016
26017@value{GDBN} sometimes reads files with commands and settings automatically,
26018without being explicitly told so by the user. We call this feature
26019@dfn{auto-loading}. While auto-loading is useful for automatically adapting
26020@value{GDBN} to the needs of your project, it can sometimes produce unexpected
26021results or introduce security risks (e.g., if the file comes from untrusted
26022sources).
26023
71b8c845
DE
26024There are various kinds of files @value{GDBN} can automatically load.
26025In addition to these files, @value{GDBN} supports auto-loading code written
26026in various extension languages. @xref{Auto-loading extensions}.
26027
c1668e4e
JK
26028Note that loading of these associated files (including the local @file{.gdbinit}
26029file) requires accordingly configured @code{auto-load safe-path}
26030(@pxref{Auto-loading safe path}).
26031
bf88dd68
JK
26032For these reasons, @value{GDBN} includes commands and options to let you
26033control when to auto-load files and which files should be auto-loaded.
26034
26035@table @code
26036@anchor{set auto-load off}
26037@kindex set auto-load off
26038@item set auto-load off
26039Globally disable loading of all auto-loaded files.
26040You may want to use this command with the @samp{-iex} option
26041(@pxref{Option -init-eval-command}) such as:
26042@smallexample
26043$ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
26044@end smallexample
26045
26046Be aware that system init file (@pxref{System-wide configuration})
26047and init files from your home directory (@pxref{Home Directory Init File})
26048still get read (as they come from generally trusted directories).
26049To prevent @value{GDBN} from auto-loading even those init files, use the
26050@option{-nx} option (@pxref{Mode Options}), in addition to
26051@code{set auto-load no}.
26052
26053@anchor{show auto-load}
26054@kindex show auto-load
26055@item show auto-load
26056Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
26057or disabled.
26058
26059@smallexample
26060(gdb) show auto-load
26061gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
26062libthread-db: Auto-loading of inferior specific libthread_db is on.
1ccacbcd
JK
26063local-gdbinit: Auto-loading of .gdbinit script from current directory
26064 is on.
bf88dd68 26065python-scripts: Auto-loading of Python scripts is on.
bccbefd2 26066safe-path: List of directories from which it is safe to auto-load files
1564a261 26067 is $debugdir:$datadir/auto-load.
7349ff92 26068scripts-directory: List of directories from which to load auto-loaded scripts
1564a261 26069 is $debugdir:$datadir/auto-load.
bf88dd68
JK
26070@end smallexample
26071
26072@anchor{info auto-load}
26073@kindex info auto-load
26074@item info auto-load
26075Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
26076not.
26077
26078@smallexample
26079(gdb) info auto-load
26080gdb-scripts:
26081Loaded Script
26082Yes /home/user/gdb/gdb-gdb.gdb
26083libthread-db: No auto-loaded libthread-db.
1ccacbcd
JK
26084local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
26085 loaded.
bf88dd68
JK
26086python-scripts:
26087Loaded Script
26088Yes /home/user/gdb/gdb-gdb.py
26089@end smallexample
26090@end table
26091
bf88dd68
JK
26092These are @value{GDBN} control commands for the auto-loading:
26093
26094@multitable @columnfractions .5 .5
26095@item @xref{set auto-load off}.
26096@tab Disable auto-loading globally.
26097@item @xref{show auto-load}.
26098@tab Show setting of all kinds of files.
26099@item @xref{info auto-load}.
26100@tab Show state of all kinds of files.
26101@item @xref{set auto-load gdb-scripts}.
26102@tab Control for @value{GDBN} command scripts.
26103@item @xref{show auto-load gdb-scripts}.
26104@tab Show setting of @value{GDBN} command scripts.
26105@item @xref{info auto-load gdb-scripts}.
26106@tab Show state of @value{GDBN} command scripts.
26107@item @xref{set auto-load python-scripts}.
26108@tab Control for @value{GDBN} Python scripts.
26109@item @xref{show auto-load python-scripts}.
26110@tab Show setting of @value{GDBN} Python scripts.
26111@item @xref{info auto-load python-scripts}.
26112@tab Show state of @value{GDBN} Python scripts.
ed3ef339
DE
26113@item @xref{set auto-load guile-scripts}.
26114@tab Control for @value{GDBN} Guile scripts.
26115@item @xref{show auto-load guile-scripts}.
26116@tab Show setting of @value{GDBN} Guile scripts.
26117@item @xref{info auto-load guile-scripts}.
26118@tab Show state of @value{GDBN} Guile scripts.
7349ff92
JK
26119@item @xref{set auto-load scripts-directory}.
26120@tab Control for @value{GDBN} auto-loaded scripts location.
26121@item @xref{show auto-load scripts-directory}.
26122@tab Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
26123@item @xref{add-auto-load-scripts-directory}.
26124@tab Add directory for auto-loaded scripts location list.
bf88dd68
JK
26125@item @xref{set auto-load local-gdbinit}.
26126@tab Control for init file in the current directory.
26127@item @xref{show auto-load local-gdbinit}.
26128@tab Show setting of init file in the current directory.
26129@item @xref{info auto-load local-gdbinit}.
26130@tab Show state of init file in the current directory.
26131@item @xref{set auto-load libthread-db}.
26132@tab Control for thread debugging library.
26133@item @xref{show auto-load libthread-db}.
26134@tab Show setting of thread debugging library.
26135@item @xref{info auto-load libthread-db}.
26136@tab Show state of thread debugging library.
bccbefd2
JK
26137@item @xref{set auto-load safe-path}.
26138@tab Control directories trusted for automatic loading.
26139@item @xref{show auto-load safe-path}.
26140@tab Show directories trusted for automatic loading.
26141@item @xref{add-auto-load-safe-path}.
26142@tab Add directory trusted for automatic loading.
bf88dd68
JK
26143@end multitable
26144
04de9f3e
AB
26145@menu
26146* Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
26147* libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
26148
26149* Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
26150* Auto-loading verbose mode:: @samp{set/show debug auto-load}
26151@end menu
26152
bf88dd68
JK
26153@node Init File in the Current Directory
26154@subsection Automatically loading init file in the current directory
26155@cindex auto-loading init file in the current directory
26156
26157By default, @value{GDBN} reads and executes the canned sequences of commands
26158from init file (if any) in the current working directory,
26159see @ref{Init File in the Current Directory during Startup}.
26160
c1668e4e
JK
26161Note that loading of this local @file{.gdbinit} file also requires accordingly
26162configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26163
bf88dd68
JK
26164@table @code
26165@anchor{set auto-load local-gdbinit}
26166@kindex set auto-load local-gdbinit
26167@item set auto-load local-gdbinit [on|off]
26168Enable or disable the auto-loading of canned sequences of commands
26169(@pxref{Sequences}) found in init file in the current directory.
26170
26171@anchor{show auto-load local-gdbinit}
26172@kindex show auto-load local-gdbinit
26173@item show auto-load local-gdbinit
26174Show whether auto-loading of canned sequences of commands from init file in the
26175current directory is enabled or disabled.
26176
26177@anchor{info auto-load local-gdbinit}
26178@kindex info auto-load local-gdbinit
26179@item info auto-load local-gdbinit
26180Print whether canned sequences of commands from init file in the
26181current directory have been auto-loaded.
26182@end table
26183
26184@node libthread_db.so.1 file
26185@subsection Automatically loading thread debugging library
26186@cindex auto-loading libthread_db.so.1
26187
26188This feature is currently present only on @sc{gnu}/Linux native hosts.
26189
26190@value{GDBN} reads in some cases thread debugging library from places specific
26191to the inferior (@pxref{set libthread-db-search-path}).
26192
26193The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
26194without checking this @samp{set auto-load libthread-db} switch as system
26195libraries have to be trusted in general. In all other cases of
26196@samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
26197auto-load libthread-db} is enabled before trying to open such thread debugging
26198library.
26199
c1668e4e
JK
26200Note that loading of this debugging library also requires accordingly configured
26201@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26202
bf88dd68
JK
26203@table @code
26204@anchor{set auto-load libthread-db}
26205@kindex set auto-load libthread-db
26206@item set auto-load libthread-db [on|off]
26207Enable or disable the auto-loading of inferior specific thread debugging library.
26208
26209@anchor{show auto-load libthread-db}
26210@kindex show auto-load libthread-db
26211@item show auto-load libthread-db
26212Show whether auto-loading of inferior specific thread debugging library is
26213enabled or disabled.
26214
26215@anchor{info auto-load libthread-db}
26216@kindex info auto-load libthread-db
26217@item info auto-load libthread-db
26218Print the list of all loaded inferior specific thread debugging libraries and
26219for each such library print list of inferior @var{pid}s using it.
26220@end table
26221
bccbefd2
JK
26222@node Auto-loading safe path
26223@subsection Security restriction for auto-loading
26224@cindex auto-loading safe-path
26225
26226As the files of inferior can come from untrusted source (such as submitted by
26227an application user) @value{GDBN} does not always load any files automatically.
26228@value{GDBN} provides the @samp{set auto-load safe-path} setting to list
26229directories trusted for loading files not explicitly requested by user.
202cbf1c 26230Each directory can also be a shell wildcard pattern.
bccbefd2
JK
26231
26232If the path is not set properly you will see a warning and the file will not
26233get loaded:
26234
26235@smallexample
26236$ ./gdb -q ./gdb
0bab6cf1 26237Reading symbols from /home/user/gdb/gdb...
bccbefd2 26238warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
1564a261
JK
26239 declined by your `auto-load safe-path' set
26240 to "$debugdir:$datadir/auto-load".
bccbefd2 26241warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
1564a261
JK
26242 declined by your `auto-load safe-path' set
26243 to "$debugdir:$datadir/auto-load".
bccbefd2
JK
26244@end smallexample
26245
2c91021c
JK
26246@noindent
26247To instruct @value{GDBN} to go ahead and use the init files anyway,
26248invoke @value{GDBN} like this:
26249
26250@smallexample
26251$ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
26252@end smallexample
26253
bccbefd2
JK
26254The list of trusted directories is controlled by the following commands:
26255
26256@table @code
26257@anchor{set auto-load safe-path}
26258@kindex set auto-load safe-path
af2c1515 26259@item set auto-load safe-path @r{[}@var{directories}@r{]}
bccbefd2
JK
26260Set the list of directories (and their subdirectories) trusted for automatic
26261loading and execution of scripts. You can also enter a specific trusted file.
202cbf1c
JK
26262Each directory can also be a shell wildcard pattern; wildcards do not match
26263directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
26264(@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
af2c1515
JK
26265If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
26266its default value as specified during @value{GDBN} compilation.
26267
d9242c17 26268The list of directories uses path separator (@samp{:} on GNU and Unix
bccbefd2
JK
26269systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26270to the @env{PATH} environment variable.
26271
26272@anchor{show auto-load safe-path}
26273@kindex show auto-load safe-path
26274@item show auto-load safe-path
26275Show the list of directories trusted for automatic loading and execution of
26276scripts.
26277
26278@anchor{add-auto-load-safe-path}
26279@kindex add-auto-load-safe-path
26280@item add-auto-load-safe-path
413b59ae
JK
26281Add an entry (or list of entries) to the list of directories trusted for
26282automatic loading and execution of scripts. Multiple entries may be delimited
26283by the host platform path separator in use.
bccbefd2
JK
26284@end table
26285
7349ff92 26286This variable defaults to what @code{--with-auto-load-dir} has been configured
1564a261
JK
26287to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
26288substitution applies the same as for @ref{set auto-load scripts-directory}.
26289The default @code{set auto-load safe-path} value can be also overriden by
26290@value{GDBN} configuration option @option{--with-auto-load-safe-path}.
6dea1fbd 26291
6dea1fbd
JK
26292Setting this variable to @file{/} disables this security protection,
26293corresponding @value{GDBN} configuration option is
26294@option{--without-auto-load-safe-path}.
bccbefd2
JK
26295This variable is supposed to be set to the system directories writable by the
26296system superuser only. Users can add their source directories in init files in
26297their home directories (@pxref{Home Directory Init File}). See also deprecated
26298init file in the current directory
26299(@pxref{Init File in the Current Directory during Startup}).
26300
26301To force @value{GDBN} to load the files it declined to load in the previous
26302example, you could use one of the following ways:
26303
0511cc75
JK
26304@table @asis
26305@item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
bccbefd2
JK
26306Specify this trusted directory (or a file) as additional component of the list.
26307You have to specify also any existing directories displayed by
26308by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
26309
174bb630 26310@item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
bccbefd2
JK
26311Specify this directory as in the previous case but just for a single
26312@value{GDBN} session.
26313
af2c1515 26314@item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
bccbefd2
JK
26315Disable auto-loading safety for a single @value{GDBN} session.
26316This assumes all the files you debug during this @value{GDBN} session will come
26317from trusted sources.
26318
26319@item @kbd{./configure --without-auto-load-safe-path}
26320During compilation of @value{GDBN} you may disable any auto-loading safety.
26321This assumes all the files you will ever debug with this @value{GDBN} come from
26322trusted sources.
0511cc75 26323@end table
bccbefd2
JK
26324
26325On the other hand you can also explicitly forbid automatic files loading which
26326also suppresses any such warning messages:
26327
0511cc75 26328@table @asis
174bb630 26329@item @kbd{gdb -iex "set auto-load no" @dots{}}
bccbefd2
JK
26330You can use @value{GDBN} command-line option for a single @value{GDBN} session.
26331
0511cc75 26332@item @file{~/.gdbinit}: @samp{set auto-load no}
bccbefd2
JK
26333Disable auto-loading globally for the user
26334(@pxref{Home Directory Init File}). While it is improbable, you could also
26335use system init file instead (@pxref{System-wide configuration}).
0511cc75 26336@end table
bccbefd2
JK
26337
26338This setting applies to the file names as entered by user. If no entry matches
26339@value{GDBN} tries as a last resort to also resolve all the file names into
26340their canonical form (typically resolving symbolic links) and compare the
26341entries again. @value{GDBN} already canonicalizes most of the filenames on its
26342own before starting the comparison so a canonical form of directories is
26343recommended to be entered.
26344
4dc84fd1
JK
26345@node Auto-loading verbose mode
26346@subsection Displaying files tried for auto-load
26347@cindex auto-loading verbose mode
26348
26349For better visibility of all the file locations where you can place scripts to
26350be auto-loaded with inferior --- or to protect yourself against accidental
26351execution of untrusted scripts --- @value{GDBN} provides a feature for printing
26352all the files attempted to be loaded. Both existing and non-existing files may
26353be printed.
26354
26355For example the list of directories from which it is safe to auto-load files
26356(@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
26357may not be too obvious while setting it up.
26358
26359@smallexample
0070f25a 26360(gdb) set debug auto-load on
4dc84fd1
JK
26361(gdb) file ~/src/t/true
26362auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
26363 for objfile "/tmp/true".
26364auto-load: Updating directories of "/usr:/opt".
26365auto-load: Using directory "/usr".
26366auto-load: Using directory "/opt".
26367warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
26368 by your `auto-load safe-path' set to "/usr:/opt".
26369@end smallexample
26370
26371@table @code
26372@anchor{set debug auto-load}
26373@kindex set debug auto-load
26374@item set debug auto-load [on|off]
26375Set whether to print the filenames attempted to be auto-loaded.
26376
26377@anchor{show debug auto-load}
26378@kindex show debug auto-load
26379@item show debug auto-load
26380Show whether printing of the filenames attempted to be auto-loaded is turned
26381on or off.
26382@end table
26383
8e04817f 26384@node Messages/Warnings
79a6e687 26385@section Optional Warnings and Messages
104c1213 26386
9c16f35a
EZ
26387@cindex verbose operation
26388@cindex optional warnings
8e04817f
AC
26389By default, @value{GDBN} is silent about its inner workings. If you are
26390running on a slow machine, you may want to use the @code{set verbose}
26391command. This makes @value{GDBN} tell you when it does a lengthy
26392internal operation, so you will not think it has crashed.
104c1213 26393
8e04817f
AC
26394Currently, the messages controlled by @code{set verbose} are those
26395which announce that the symbol table for a source file is being read;
79a6e687 26396see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 26397
8e04817f
AC
26398@table @code
26399@kindex set verbose
26400@item set verbose on
26401Enables @value{GDBN} output of certain informational messages.
104c1213 26402
8e04817f
AC
26403@item set verbose off
26404Disables @value{GDBN} output of certain informational messages.
104c1213 26405
8e04817f
AC
26406@kindex show verbose
26407@item show verbose
26408Displays whether @code{set verbose} is on or off.
26409@end table
104c1213 26410
8e04817f
AC
26411By default, if @value{GDBN} encounters bugs in the symbol table of an
26412object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
26413find this information useful (@pxref{Symbol Errors, ,Errors Reading
26414Symbol Files}).
104c1213 26415
8e04817f 26416@table @code
104c1213 26417
8e04817f
AC
26418@kindex set complaints
26419@item set complaints @var{limit}
26420Permits @value{GDBN} to output @var{limit} complaints about each type of
26421unusual symbols before becoming silent about the problem. Set
26422@var{limit} to zero to suppress all complaints; set it to a large number
26423to prevent complaints from being suppressed.
104c1213 26424
8e04817f
AC
26425@kindex show complaints
26426@item show complaints
26427Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 26428
8e04817f 26429@end table
104c1213 26430
d837706a 26431@anchor{confirmation requests}
8e04817f
AC
26432By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
26433lot of stupid questions to confirm certain commands. For example, if
26434you try to run a program which is already running:
104c1213 26435
474c8240 26436@smallexample
8e04817f
AC
26437(@value{GDBP}) run
26438The program being debugged has been started already.
26439Start it from the beginning? (y or n)
474c8240 26440@end smallexample
104c1213 26441
8e04817f
AC
26442If you are willing to unflinchingly face the consequences of your own
26443commands, you can disable this ``feature'':
104c1213 26444
8e04817f 26445@table @code
104c1213 26446
8e04817f
AC
26447@kindex set confirm
26448@cindex flinching
26449@cindex confirmation
26450@cindex stupid questions
26451@item set confirm off
7c953934
TT
26452Disables confirmation requests. Note that running @value{GDBN} with
26453the @option{--batch} option (@pxref{Mode Options, -batch}) also
26454automatically disables confirmation requests.
104c1213 26455
8e04817f
AC
26456@item set confirm on
26457Enables confirmation requests (the default).
104c1213 26458
8e04817f
AC
26459@kindex show confirm
26460@item show confirm
26461Displays state of confirmation requests.
26462
26463@end table
104c1213 26464
16026cd7
AS
26465@cindex command tracing
26466If you need to debug user-defined commands or sourced files you may find it
26467useful to enable @dfn{command tracing}. In this mode each command will be
26468printed as it is executed, prefixed with one or more @samp{+} symbols, the
26469quantity denoting the call depth of each command.
26470
26471@table @code
26472@kindex set trace-commands
26473@cindex command scripts, debugging
26474@item set trace-commands on
26475Enable command tracing.
26476@item set trace-commands off
26477Disable command tracing.
26478@item show trace-commands
26479Display the current state of command tracing.
26480@end table
26481
8e04817f 26482@node Debugging Output
79a6e687 26483@section Optional Messages about Internal Happenings
4644b6e3
EZ
26484@cindex optional debugging messages
26485
da316a69
EZ
26486@value{GDBN} has commands that enable optional debugging messages from
26487various @value{GDBN} subsystems; normally these commands are of
26488interest to @value{GDBN} maintainers, or when reporting a bug. This
26489section documents those commands.
26490
104c1213 26491@table @code
a8f24a35
EZ
26492@kindex set exec-done-display
26493@item set exec-done-display
26494Turns on or off the notification of asynchronous commands'
26495completion. When on, @value{GDBN} will print a message when an
26496asynchronous command finishes its execution. The default is off.
26497@kindex show exec-done-display
26498@item show exec-done-display
26499Displays the current setting of asynchronous command completion
26500notification.
7b085b1c 26501
4644b6e3 26502@kindex set debug
be9a8770
PA
26503@cindex ARM AArch64
26504@item set debug aarch64
26505Turns on or off display of debugging messages related to ARM AArch64.
26506The default is off.
26507@kindex show debug
26508@item show debug aarch64
26509Displays the current state of displaying debugging messages related to
26510ARM AArch64.
7b085b1c 26511
4644b6e3 26512@cindex gdbarch debugging info
a8f24a35 26513@cindex architecture debugging info
8e04817f 26514@item set debug arch
a8f24a35 26515Turns on or off display of gdbarch debugging info. The default is off
8e04817f
AC
26516@item show debug arch
26517Displays the current state of displaying gdbarch debugging info.
7b085b1c 26518
9a005eb9
JB
26519@item set debug aix-solib
26520@cindex AIX shared library debugging
26521Control display of debugging messages from the AIX shared library
26522support module. The default is off.
7b085b1c 26523@item show debug aix-solib
9a005eb9 26524Show the current state of displaying AIX shared library debugging messages.
7b085b1c 26525
721c2651
EZ
26526@item set debug aix-thread
26527@cindex AIX threads
26528Display debugging messages about inner workings of the AIX thread
26529module.
26530@item show debug aix-thread
26531Show the current state of AIX thread debugging info display.
7b085b1c 26532
900e11f9
JK
26533@item set debug check-physname
26534@cindex physname
26535Check the results of the ``physname'' computation. When reading DWARF
26536debugging information for C@t{++}, @value{GDBN} attempts to compute
26537each entity's name. @value{GDBN} can do this computation in two
26538different ways, depending on exactly what information is present.
26539When enabled, this setting causes @value{GDBN} to compute the names
26540both ways and display any discrepancies.
26541@item show debug check-physname
26542Show the current state of ``physname'' checking.
7b085b1c 26543
be9a8770
PA
26544@item set debug coff-pe-read
26545@cindex COFF/PE exported symbols
26546Control display of debugging messages related to reading of COFF/PE
26547exported symbols. The default is off.
26548@item show debug coff-pe-read
26549Displays the current state of displaying debugging messages related to
26550reading of COFF/PE exported symbols.
7b085b1c 26551
b4f54984
DE
26552@item set debug dwarf-die
26553@cindex DWARF DIEs
26554Dump DWARF DIEs after they are read in.
d97bc12b
DE
26555The value is the number of nesting levels to print.
26556A value of zero turns off the display.
b4f54984
DE
26557@item show debug dwarf-die
26558Show the current state of DWARF DIE debugging.
7b085b1c 26559
27e0867f
DE
26560@item set debug dwarf-line
26561@cindex DWARF Line Tables
26562Turns on or off display of debugging messages related to reading
26563DWARF line tables. The default is 0 (off).
26564A value of 1 provides basic information.
26565A value greater than 1 provides more verbose information.
26566@item show debug dwarf-line
26567Show the current state of DWARF line table debugging.
7b085b1c 26568
b4f54984
DE
26569@item set debug dwarf-read
26570@cindex DWARF Reading
45cfd468 26571Turns on or off display of debugging messages related to reading
73be47f5
DE
26572DWARF debug info. The default is 0 (off).
26573A value of 1 provides basic information.
26574A value greater than 1 provides more verbose information.
b4f54984
DE
26575@item show debug dwarf-read
26576Show the current state of DWARF reader debugging.
7b085b1c 26577
237fc4c9
PA
26578@item set debug displaced
26579@cindex displaced stepping debugging info
26580Turns on or off display of @value{GDBN} debugging info for the
26581displaced stepping support. The default is off.
26582@item show debug displaced
26583Displays the current state of displaying @value{GDBN} debugging info
26584related to displaced stepping.
7b085b1c 26585
8e04817f 26586@item set debug event
4644b6e3 26587@cindex event debugging info
a8f24a35 26588Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 26589default is off.
8e04817f
AC
26590@item show debug event
26591Displays the current state of displaying @value{GDBN} event debugging
26592info.
7b085b1c 26593
8d378f27
SM
26594@item set debug event-loop
26595@cindex event-loop debugging
26596Controls output of debugging info about the event loop. The possible
26597values are @samp{off}, @samp{all} (shows all debugging info) and
26598@samp{all-except-ui} (shows all debugging info except those about
26599UI-related events).
26600@item show debug event-loop
26601Shows the current state of displaying debugging info about the event
26602loop.
26603
8e04817f 26604@item set debug expression
4644b6e3 26605@cindex expression debugging info
721c2651
EZ
26606Turns on or off display of debugging info about @value{GDBN}
26607expression parsing. The default is off.
8e04817f 26608@item show debug expression
721c2651
EZ
26609Displays the current state of displaying debugging info about
26610@value{GDBN} expression parsing.
7b085b1c 26611
6e9567fe
JB
26612@item set debug fbsd-lwp
26613@cindex FreeBSD LWP debug messages
26614Turns on or off debugging messages from the FreeBSD LWP debug support.
26615@item show debug fbsd-lwp
26616Show the current state of FreeBSD LWP debugging messages.
7b085b1c 26617
386a8676
JB
26618@item set debug fbsd-nat
26619@cindex FreeBSD native target debug messages
26620Turns on or off debugging messages from the FreeBSD native target.
26621@item show debug fbsd-nat
26622Show the current state of FreeBSD native target debugging messages.
7b085b1c 26623
a5c641b5
AB
26624@item set debug fortran-array-slicing
26625@cindex fortran array slicing debugging info
26626Turns on or off display of @value{GDBN} Fortran array slicing
26627debugging info. The default is off.
26628
26629@item show debug fortran-array-slicing
26630Displays the current state of displaying @value{GDBN} Fortran array
26631slicing debugging info.
26632
7453dc06 26633@item set debug frame
4644b6e3 26634@cindex frame debugging info
7453dc06
AC
26635Turns on or off display of @value{GDBN} frame debugging info. The
26636default is off.
7453dc06
AC
26637@item show debug frame
26638Displays the current state of displaying @value{GDBN} frame debugging
26639info.
7b085b1c 26640
cbe54154
PA
26641@item set debug gnu-nat
26642@cindex @sc{gnu}/Hurd debug messages
67ebd9cb 26643Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
cbe54154
PA
26644@item show debug gnu-nat
26645Show the current state of @sc{gnu}/Hurd debugging messages.
7b085b1c 26646
30e91e0b
RC
26647@item set debug infrun
26648@cindex inferior debugging info
26649Turns on or off display of @value{GDBN} debugging info for running the inferior.
26650The default is off. @file{infrun.c} contains GDB's runtime state machine used
26651for implementing operations such as single-stepping the inferior.
26652@item show debug infrun
26653Displays the current state of @value{GDBN} inferior debugging.
7b085b1c 26654
a255712f
PP
26655@item set debug jit
26656@cindex just-in-time compilation, debugging messages
67ebd9cb 26657Turn on or off debugging messages from JIT debug support.
a255712f
PP
26658@item show debug jit
26659Displays the current state of @value{GDBN} JIT debugging.
7b085b1c 26660
da316a69
EZ
26661@item set debug lin-lwp
26662@cindex @sc{gnu}/Linux LWP debug messages
26663@cindex Linux lightweight processes
67ebd9cb 26664Turn on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
26665@item show debug lin-lwp
26666Show the current state of Linux LWP debugging messages.
7b085b1c 26667
7a6a1731
GB
26668@item set debug linux-namespaces
26669@cindex @sc{gnu}/Linux namespaces debug messages
67ebd9cb 26670Turn on or off debugging messages from the Linux namespaces debug support.
7a6a1731
GB
26671@item show debug linux-namespaces
26672Show the current state of Linux namespaces debugging messages.
7b085b1c 26673
be9a8770
PA
26674@item set debug mach-o
26675@cindex Mach-O symbols processing
26676Control display of debugging messages related to Mach-O symbols
26677processing. The default is off.
26678@item show debug mach-o
26679Displays the current state of displaying debugging messages related to
26680reading of COFF/PE exported symbols.
7b085b1c 26681
c9b6281a
YQ
26682@item set debug notification
26683@cindex remote async notification debugging info
67ebd9cb 26684Turn on or off debugging messages about remote async notification.
c9b6281a
YQ
26685The default is off.
26686@item show debug notification
26687Displays the current state of remote async notification debugging messages.
7b085b1c 26688
2b4855ab 26689@item set debug observer
4644b6e3 26690@cindex observer debugging info
2b4855ab
AC
26691Turns on or off display of @value{GDBN} observer debugging. This
26692includes info such as the notification of observable events.
2b4855ab
AC
26693@item show debug observer
26694Displays the current state of observer debugging.
7b085b1c 26695
8e04817f 26696@item set debug overload
4644b6e3 26697@cindex C@t{++} overload debugging info
8e04817f 26698Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 26699info. This includes info such as ranking of functions, etc. The default
8e04817f 26700is off.
8e04817f
AC
26701@item show debug overload
26702Displays the current state of displaying @value{GDBN} C@t{++} overload
26703debugging info.
7b085b1c 26704
92981e24
TT
26705@cindex expression parser, debugging info
26706@cindex debug expression parser
26707@item set debug parser
26708Turns on or off the display of expression parser debugging output.
26709Internally, this sets the @code{yydebug} variable in the expression
26710parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
26711details. The default is off.
26712@item show debug parser
26713Show the current state of expression parser debugging.
7b085b1c 26714
8e04817f
AC
26715@cindex packets, reporting on stdout
26716@cindex serial connections, debugging
605a56cb
DJ
26717@cindex debug remote protocol
26718@cindex remote protocol debugging
26719@cindex display remote packets
8e04817f
AC
26720@item set debug remote
26721Turns on or off display of reports on all packets sent back and forth across
26722the serial line to the remote machine. The info is printed on the
26723@value{GDBN} standard output stream. The default is off.
8e04817f
AC
26724@item show debug remote
26725Displays the state of display of remote packets.
c4dcb155 26726
6cc8564b
LM
26727@item set debug remote-packet-max-chars
26728Sets the maximum number of characters to display for each remote packet when
26729@code{set debug remote} is on. This is useful to prevent @value{GDBN} from
26730displaying lengthy remote packets and polluting the console.
26731
26732The default value is @code{512}, which means @value{GDBN} will truncate each
26733remote packet after 512 bytes.
26734
26735Setting this option to @code{unlimited} will disable truncation and will output
26736the full length of the remote packets.
26737@item show debug remote-packet-max-chars
26738Displays the number of bytes to output for remote packet debugging.
26739
c4dcb155
SM
26740@item set debug separate-debug-file
26741Turns on or off display of debug output about separate debug file search.
26742@item show debug separate-debug-file
26743Displays the state of separate debug file search debug output.
26744
8e04817f
AC
26745@item set debug serial
26746Turns on or off display of @value{GDBN} serial debugging info. The
26747default is off.
8e04817f
AC
26748@item show debug serial
26749Displays the current state of displaying @value{GDBN} serial debugging
26750info.
7b085b1c 26751
c45da7e6
EZ
26752@item set debug solib-frv
26753@cindex FR-V shared-library debugging
67ebd9cb 26754Turn on or off debugging messages for FR-V shared-library code.
c45da7e6
EZ
26755@item show debug solib-frv
26756Display the current state of FR-V shared-library code debugging
26757messages.
7b085b1c 26758
cc485e62
DE
26759@item set debug symbol-lookup
26760@cindex symbol lookup
26761Turns on or off display of debugging messages related to symbol lookup.
26762The default is 0 (off).
26763A value of 1 provides basic information.
26764A value greater than 1 provides more verbose information.
26765@item show debug symbol-lookup
26766Show the current state of symbol lookup debugging messages.
7b085b1c 26767
8fb8eb5c
DE
26768@item set debug symfile
26769@cindex symbol file functions
26770Turns on or off display of debugging messages related to symbol file functions.
26771The default is off. @xref{Files}.
26772@item show debug symfile
26773Show the current state of symbol file debugging messages.
7b085b1c 26774
45cfd468
DE
26775@item set debug symtab-create
26776@cindex symbol table creation
26777Turns on or off display of debugging messages related to symbol table creation.
db0fec5c
DE
26778The default is 0 (off).
26779A value of 1 provides basic information.
26780A value greater than 1 provides more verbose information.
45cfd468
DE
26781@item show debug symtab-create
26782Show the current state of symbol table creation debugging.
7b085b1c 26783
8e04817f 26784@item set debug target
4644b6e3 26785@cindex target debugging info
8e04817f
AC
26786Turns on or off display of @value{GDBN} target debugging info. This info
26787includes what is going on at the target level of GDB, as it happens. The
701b08bb 26788default is 0. Set it to 1 to track events, and to 2 to also track the
3cecbbbe 26789value of large memory transfers.
8e04817f
AC
26790@item show debug target
26791Displays the current state of displaying @value{GDBN} target debugging
26792info.
7b085b1c 26793
75feb17d 26794@item set debug timestamp
6b92c0d3 26795@cindex timestamping debugging info
75feb17d
DJ
26796Turns on or off display of timestamps with @value{GDBN} debugging info.
26797When enabled, seconds and microseconds are displayed before each debugging
26798message.
26799@item show debug timestamp
26800Displays the current state of displaying timestamps with @value{GDBN}
26801debugging info.
7b085b1c 26802
f989a1c8 26803@item set debug varobj
4644b6e3 26804@cindex variable object debugging info
8e04817f
AC
26805Turns on or off display of @value{GDBN} variable object debugging
26806info. The default is off.
f989a1c8 26807@item show debug varobj
8e04817f
AC
26808Displays the current state of displaying @value{GDBN} variable object
26809debugging info.
7b085b1c 26810
e776119f
DJ
26811@item set debug xml
26812@cindex XML parser debugging
67ebd9cb 26813Turn on or off debugging messages for built-in XML parsers.
e776119f
DJ
26814@item show debug xml
26815Displays the current state of XML debugging messages.
8e04817f 26816@end table
104c1213 26817
14fb1bac
JB
26818@node Other Misc Settings
26819@section Other Miscellaneous Settings
26820@cindex miscellaneous settings
26821
26822@table @code
26823@kindex set interactive-mode
26824@item set interactive-mode
7bfc9434
JB
26825If @code{on}, forces @value{GDBN} to assume that GDB was started
26826in a terminal. In practice, this means that @value{GDBN} should wait
26827for the user to answer queries generated by commands entered at
26828the command prompt. If @code{off}, forces @value{GDBN} to operate
26829in the opposite mode, and it uses the default answers to all queries.
26830If @code{auto} (the default), @value{GDBN} tries to determine whether
26831its standard input is a terminal, and works in interactive-mode if it
26832is, non-interactively otherwise.
14fb1bac
JB
26833
26834In the vast majority of cases, the debugger should be able to guess
26835correctly which mode should be used. But this setting can be useful
26836in certain specific cases, such as running a MinGW @value{GDBN}
26837inside a cygwin window.
26838
26839@kindex show interactive-mode
26840@item show interactive-mode
26841Displays whether the debugger is operating in interactive mode or not.
26842@end table
26843
d57a3c85
TJB
26844@node Extending GDB
26845@chapter Extending @value{GDBN}
26846@cindex extending GDB
26847
71b8c845
DE
26848@value{GDBN} provides several mechanisms for extension.
26849@value{GDBN} also provides the ability to automatically load
26850extensions when it reads a file for debugging. This allows the
26851user to automatically customize @value{GDBN} for the program
26852being debugged.
d57a3c85 26853
71b8c845 26854To facilitate the use of extension languages, @value{GDBN} is capable
95433b34 26855of evaluating the contents of a file. When doing so, @value{GDBN}
71b8c845 26856can recognize which extension language is being used by looking at
95433b34
JB
26857the filename extension. Files with an unrecognized filename extension
26858are always treated as a @value{GDBN} Command Files.
26859@xref{Command Files,, Command files}.
26860
26861You can control how @value{GDBN} evaluates these files with the following
26862setting:
26863
26864@table @code
26865@kindex set script-extension
26866@kindex show script-extension
26867@item set script-extension off
26868All scripts are always evaluated as @value{GDBN} Command Files.
26869
26870@item set script-extension soft
26871The debugger determines the scripting language based on filename
26872extension. If this scripting language is supported, @value{GDBN}
26873evaluates the script using that language. Otherwise, it evaluates
26874the file as a @value{GDBN} Command File.
26875
26876@item set script-extension strict
26877The debugger determines the scripting language based on filename
26878extension, and evaluates the script using that language. If the
26879language is not supported, then the evaluation fails.
26880
26881@item show script-extension
26882Display the current value of the @code{script-extension} option.
26883
26884@end table
26885
ed2a2229
CB
26886@ifset SYSTEM_GDBINIT_DIR
26887This setting is not used for files in the system-wide gdbinit directory.
26888Files in that directory must have an extension matching their language,
26889or have a @file{.gdb} extension to be interpreted as regular @value{GDBN}
26890commands. @xref{Startup}.
26891@end ifset
26892
04de9f3e
AB
26893@menu
26894* Sequences:: Canned Sequences of @value{GDBN} Commands
26895* Aliases:: Command Aliases
26896* Python:: Extending @value{GDBN} using Python
26897* Guile:: Extending @value{GDBN} using Guile
26898* Auto-loading extensions:: Automatically loading extensions
26899* Multiple Extension Languages:: Working with multiple extension languages
26900@end menu
26901
8e04817f 26902@node Sequences
d57a3c85 26903@section Canned Sequences of Commands
104c1213 26904
8e04817f 26905Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 26906Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
26907commands for execution as a unit: user-defined commands and command
26908files.
104c1213 26909
8e04817f 26910@menu
fcc73fe3
EZ
26911* Define:: How to define your own commands
26912* Hooks:: Hooks for user-defined commands
26913* Command Files:: How to write scripts of commands to be stored in a file
26914* Output:: Commands for controlled output
71b8c845 26915* Auto-loading sequences:: Controlling auto-loaded command files
8e04817f 26916@end menu
104c1213 26917
8e04817f 26918@node Define
d57a3c85 26919@subsection User-defined Commands
104c1213 26920
8e04817f 26921@cindex user-defined command
fcc73fe3 26922@cindex arguments, to user-defined commands
8e04817f
AC
26923A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
26924which you assign a new name as a command. This is done with the
df3ee9ca 26925@code{define} command. User commands may accept an unlimited number of arguments
8e04817f 26926separated by whitespace. Arguments are accessed within the user command
df3ee9ca 26927via @code{$arg0@dots{}$argN}. A trivial example:
104c1213 26928
8e04817f
AC
26929@smallexample
26930define adder
26931 print $arg0 + $arg1 + $arg2
c03c782f 26932end
8e04817f 26933@end smallexample
104c1213
JM
26934
26935@noindent
8e04817f 26936To execute the command use:
104c1213 26937
8e04817f
AC
26938@smallexample
26939adder 1 2 3
26940@end smallexample
104c1213 26941
8e04817f
AC
26942@noindent
26943This defines the command @code{adder}, which prints the sum of
26944its three arguments. Note the arguments are text substitutions, so they may
26945reference variables, use complex expressions, or even perform inferior
26946functions calls.
104c1213 26947
fcc73fe3
EZ
26948@cindex argument count in user-defined commands
26949@cindex how many arguments (user-defined commands)
c03c782f 26950In addition, @code{$argc} may be used to find out how many arguments have
df3ee9ca 26951been passed.
c03c782f
AS
26952
26953@smallexample
26954define adder
26955 if $argc == 2
26956 print $arg0 + $arg1
26957 end
26958 if $argc == 3
26959 print $arg0 + $arg1 + $arg2
26960 end
26961end
26962@end smallexample
26963
01770bbd
PA
26964Combining with the @code{eval} command (@pxref{eval}) makes it easier
26965to process a variable number of arguments:
26966
26967@smallexample
26968define adder
26969 set $i = 0
26970 set $sum = 0
26971 while $i < $argc
26972 eval "set $sum = $sum + $arg%d", $i
26973 set $i = $i + 1
26974 end
26975 print $sum
26976end
26977@end smallexample
26978
104c1213 26979@table @code
104c1213 26980
8e04817f
AC
26981@kindex define
26982@item define @var{commandname}
26983Define a command named @var{commandname}. If there is already a command
26984by that name, you are asked to confirm that you want to redefine it.
697aa1b7 26985The argument @var{commandname} may be a bare command name consisting of letters,
bf498525
PW
26986numbers, dashes, dots, and underscores. It may also start with any
26987predefined or user-defined prefix command.
26988For example, @samp{define target my-target} creates
adb483fe 26989a user-defined @samp{target my-target} command.
104c1213 26990
8e04817f
AC
26991The definition of the command is made up of other @value{GDBN} command lines,
26992which are given following the @code{define} command. The end of these
26993commands is marked by a line containing @code{end}.
104c1213 26994
8e04817f 26995@kindex document
ca91424e 26996@kindex end@r{ (user-defined commands)}
8e04817f
AC
26997@item document @var{commandname}
26998Document the user-defined command @var{commandname}, so that it can be
26999accessed by @code{help}. The command @var{commandname} must already be
27000defined. This command reads lines of documentation just as @code{define}
27001reads the lines of the command definition, ending with @code{end}.
27002After the @code{document} command is finished, @code{help} on command
27003@var{commandname} displays the documentation you have written.
104c1213 27004
8e04817f
AC
27005You may use the @code{document} command again to change the
27006documentation of a command. Redefining the command with @code{define}
27007does not change the documentation.
104c1213 27008
bf498525
PW
27009@kindex define-prefix
27010@item define-prefix @var{commandname}
27011Define or mark the command @var{commandname} as a user-defined prefix
27012command. Once marked, @var{commandname} can be used as prefix command
27013by the @code{define} command.
27014Note that @code{define-prefix} can be used with a not yet defined
27015@var{commandname}. In such a case, @var{commandname} is defined as
27016an empty user-defined command.
27017In case you redefine a command that was marked as a user-defined
27018prefix command, the subcommands of the redefined command are kept
27019(and @value{GDBN} indicates so to the user).
27020
27021Example:
27022@example
27023(gdb) define-prefix abc
27024(gdb) define-prefix abc def
27025(gdb) define abc def
27026Type commands for definition of "abc def".
27027End with a line saying just "end".
27028>echo command initial def\n
27029>end
27030(gdb) define abc def ghi
27031Type commands for definition of "abc def ghi".
27032End with a line saying just "end".
27033>echo command ghi\n
27034>end
27035(gdb) define abc def
27036Keeping subcommands of prefix command "def".
27037Redefine command "def"? (y or n) y
27038Type commands for definition of "abc def".
27039End with a line saying just "end".
27040>echo command def\n
27041>end
27042(gdb) abc def ghi
27043command ghi
27044(gdb) abc def
27045command def
27046(gdb)
27047@end example
27048
c45da7e6
EZ
27049@kindex dont-repeat
27050@cindex don't repeat command
27051@item dont-repeat
27052Used inside a user-defined command, this tells @value{GDBN} that this
27053command should not be repeated when the user hits @key{RET}
27054(@pxref{Command Syntax, repeat last command}).
27055
8e04817f
AC
27056@kindex help user-defined
27057@item help user-defined
7d74f244 27058List all user-defined commands and all python commands defined in class
6b92c0d3 27059COMMAND_USER. The first line of the documentation or docstring is
7d74f244 27060included (if any).
104c1213 27061
8e04817f
AC
27062@kindex show user
27063@item show user
27064@itemx show user @var{commandname}
27065Display the @value{GDBN} commands used to define @var{commandname} (but
27066not its documentation). If no @var{commandname} is given, display the
27067definitions for all user-defined commands.
7d74f244 27068This does not work for user-defined python commands.
104c1213 27069
fcc73fe3 27070@cindex infinite recursion in user-defined commands
20f01a46
DH
27071@kindex show max-user-call-depth
27072@kindex set max-user-call-depth
27073@item show max-user-call-depth
5ca0cb28
DH
27074@itemx set max-user-call-depth
27075The value of @code{max-user-call-depth} controls how many recursion
3f94c067 27076levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 27077infinite recursion and aborts the command.
7d74f244 27078This does not apply to user-defined python commands.
104c1213
JM
27079@end table
27080
fcc73fe3
EZ
27081In addition to the above commands, user-defined commands frequently
27082use control flow commands, described in @ref{Command Files}.
27083
8e04817f
AC
27084When user-defined commands are executed, the
27085commands of the definition are not printed. An error in any command
27086stops execution of the user-defined command.
104c1213 27087
8e04817f
AC
27088If used interactively, commands that would ask for confirmation proceed
27089without asking when used inside a user-defined command. Many @value{GDBN}
27090commands that normally print messages to say what they are doing omit the
27091messages when used in a user-defined command.
104c1213 27092
8e04817f 27093@node Hooks
d57a3c85 27094@subsection User-defined Command Hooks
8e04817f
AC
27095@cindex command hooks
27096@cindex hooks, for commands
27097@cindex hooks, pre-command
104c1213 27098
8e04817f 27099@kindex hook
8e04817f
AC
27100You may define @dfn{hooks}, which are a special kind of user-defined
27101command. Whenever you run the command @samp{foo}, if the user-defined
27102command @samp{hook-foo} exists, it is executed (with no arguments)
27103before that command.
104c1213 27104
8e04817f
AC
27105@cindex hooks, post-command
27106@kindex hookpost
8e04817f
AC
27107A hook may also be defined which is run after the command you executed.
27108Whenever you run the command @samp{foo}, if the user-defined command
27109@samp{hookpost-foo} exists, it is executed (with no arguments) after
27110that command. Post-execution hooks may exist simultaneously with
27111pre-execution hooks, for the same command.
104c1213 27112
8e04817f 27113It is valid for a hook to call the command which it hooks. If this
9f1c6395 27114occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 27115
8e04817f
AC
27116@c It would be nice if hookpost could be passed a parameter indicating
27117@c if the command it hooks executed properly or not. FIXME!
104c1213 27118
8e04817f
AC
27119@kindex stop@r{, a pseudo-command}
27120In addition, a pseudo-command, @samp{stop} exists. Defining
27121(@samp{hook-stop}) makes the associated commands execute every time
27122execution stops in your program: before breakpoint commands are run,
27123displays are printed, or the stack frame is printed.
104c1213 27124
8e04817f
AC
27125For example, to ignore @code{SIGALRM} signals while
27126single-stepping, but treat them normally during normal execution,
27127you could define:
104c1213 27128
474c8240 27129@smallexample
8e04817f
AC
27130define hook-stop
27131handle SIGALRM nopass
27132end
104c1213 27133
8e04817f
AC
27134define hook-run
27135handle SIGALRM pass
27136end
104c1213 27137
8e04817f 27138define hook-continue
d3e8051b 27139handle SIGALRM pass
8e04817f 27140end
474c8240 27141@end smallexample
104c1213 27142
d3e8051b 27143As a further example, to hook at the beginning and end of the @code{echo}
b383017d 27144command, and to add extra text to the beginning and end of the message,
8e04817f 27145you could define:
104c1213 27146
474c8240 27147@smallexample
8e04817f
AC
27148define hook-echo
27149echo <<<---
27150end
104c1213 27151
8e04817f
AC
27152define hookpost-echo
27153echo --->>>\n
27154end
104c1213 27155
8e04817f
AC
27156(@value{GDBP}) echo Hello World
27157<<<---Hello World--->>>
27158(@value{GDBP})
104c1213 27159
474c8240 27160@end smallexample
104c1213 27161
8e04817f
AC
27162You can define a hook for any single-word command in @value{GDBN}, but
27163not for command aliases; you should define a hook for the basic command
c1468174 27164name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
27165@c FIXME! So how does Joe User discover whether a command is an alias
27166@c or not?
adb483fe
DJ
27167You can hook a multi-word command by adding @code{hook-} or
27168@code{hookpost-} to the last word of the command, e.g.@:
27169@samp{define target hook-remote} to add a hook to @samp{target remote}.
27170
8e04817f
AC
27171If an error occurs during the execution of your hook, execution of
27172@value{GDBN} commands stops and @value{GDBN} issues a prompt
27173(before the command that you actually typed had a chance to run).
104c1213 27174
8e04817f
AC
27175If you try to define a hook which does not match any known command, you
27176get a warning from the @code{define} command.
c906108c 27177
8e04817f 27178@node Command Files
d57a3c85 27179@subsection Command Files
c906108c 27180
8e04817f 27181@cindex command files
fcc73fe3 27182@cindex scripting commands
6fc08d32
EZ
27183A command file for @value{GDBN} is a text file made of lines that are
27184@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
27185also be included. An empty line in a command file does nothing; it
27186does not mean to repeat the last command, as it would from the
27187terminal.
c906108c 27188
6fc08d32 27189You can request the execution of a command file with the @code{source}
95433b34
JB
27190command. Note that the @code{source} command is also used to evaluate
27191scripts that are not Command Files. The exact behavior can be configured
27192using the @code{script-extension} setting.
27193@xref{Extending GDB,, Extending GDB}.
c906108c 27194
8e04817f
AC
27195@table @code
27196@kindex source
ca91424e 27197@cindex execute commands from a file
3f7b2faa 27198@item source [-s] [-v] @var{filename}
8e04817f 27199Execute the command file @var{filename}.
c906108c
SS
27200@end table
27201
fcc73fe3
EZ
27202The lines in a command file are generally executed sequentially,
27203unless the order of execution is changed by one of the
27204@emph{flow-control commands} described below. The commands are not
a71ec265
DH
27205printed as they are executed. An error in any command terminates
27206execution of the command file and control is returned to the console.
c906108c 27207
08001717
DE
27208@value{GDBN} first searches for @var{filename} in the current directory.
27209If the file is not found there, and @var{filename} does not specify a
27210directory, then @value{GDBN} also looks for the file on the source search path
27211(specified with the @samp{directory} command);
27212except that @file{$cdir} is not searched because the compilation directory
27213is not relevant to scripts.
4b505b12 27214
3f7b2faa
DE
27215If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
27216on the search path even if @var{filename} specifies a directory.
27217The search is done by appending @var{filename} to each element of the
27218search path. So, for example, if @var{filename} is @file{mylib/myscript}
27219and the search path contains @file{/home/user} then @value{GDBN} will
27220look for the script @file{/home/user/mylib/myscript}.
27221The search is also done if @var{filename} is an absolute path.
27222For example, if @var{filename} is @file{/tmp/myscript} and
27223the search path contains @file{/home/user} then @value{GDBN} will
27224look for the script @file{/home/user/tmp/myscript}.
27225For DOS-like systems, if @var{filename} contains a drive specification,
27226it is stripped before concatenation. For example, if @var{filename} is
27227@file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
27228will look for the script @file{c:/tmp/myscript}.
27229
16026cd7
AS
27230If @code{-v}, for verbose mode, is given then @value{GDBN} displays
27231each command as it is executed. The option must be given before
27232@var{filename}, and is interpreted as part of the filename anywhere else.
27233
8e04817f
AC
27234Commands that would ask for confirmation if used interactively proceed
27235without asking when used in a command file. Many @value{GDBN} commands that
27236normally print messages to say what they are doing omit the messages
27237when called from command files.
c906108c 27238
8e04817f
AC
27239@value{GDBN} also accepts command input from standard input. In this
27240mode, normal output goes to standard output and error output goes to
27241standard error. Errors in a command file supplied on standard input do
6fc08d32 27242not terminate execution of the command file---execution continues with
8e04817f 27243the next command.
c906108c 27244
474c8240 27245@smallexample
8e04817f 27246gdb < cmds > log 2>&1
474c8240 27247@end smallexample
c906108c 27248
8e04817f
AC
27249(The syntax above will vary depending on the shell used.) This example
27250will execute commands from the file @file{cmds}. All output and errors
27251would be directed to @file{log}.
c906108c 27252
fcc73fe3
EZ
27253Since commands stored on command files tend to be more general than
27254commands typed interactively, they frequently need to deal with
27255complicated situations, such as different or unexpected values of
27256variables and symbols, changes in how the program being debugged is
27257built, etc. @value{GDBN} provides a set of flow-control commands to
27258deal with these complexities. Using these commands, you can write
27259complex scripts that loop over data structures, execute commands
27260conditionally, etc.
27261
27262@table @code
27263@kindex if
27264@kindex else
27265@item if
27266@itemx else
27267This command allows to include in your script conditionally executed
27268commands. The @code{if} command takes a single argument, which is an
27269expression to evaluate. It is followed by a series of commands that
27270are executed only if the expression is true (its value is nonzero).
27271There can then optionally be an @code{else} line, followed by a series
27272of commands that are only executed if the expression was false. The
27273end of the list is marked by a line containing @code{end}.
27274
27275@kindex while
27276@item while
27277This command allows to write loops. Its syntax is similar to
27278@code{if}: the command takes a single argument, which is an expression
27279to evaluate, and must be followed by the commands to execute, one per
27280line, terminated by an @code{end}. These commands are called the
27281@dfn{body} of the loop. The commands in the body of @code{while} are
27282executed repeatedly as long as the expression evaluates to true.
27283
27284@kindex loop_break
27285@item loop_break
27286This command exits the @code{while} loop in whose body it is included.
27287Execution of the script continues after that @code{while}s @code{end}
27288line.
27289
27290@kindex loop_continue
27291@item loop_continue
27292This command skips the execution of the rest of the body of commands
27293in the @code{while} loop in whose body it is included. Execution
27294branches to the beginning of the @code{while} loop, where it evaluates
27295the controlling expression.
ca91424e
EZ
27296
27297@kindex end@r{ (if/else/while commands)}
27298@item end
27299Terminate the block of commands that are the body of @code{if},
27300@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
27301@end table
27302
27303
8e04817f 27304@node Output
d57a3c85 27305@subsection Commands for Controlled Output
c906108c 27306
8e04817f
AC
27307During the execution of a command file or a user-defined command, normal
27308@value{GDBN} output is suppressed; the only output that appears is what is
27309explicitly printed by the commands in the definition. This section
27310describes three commands useful for generating exactly the output you
27311want.
c906108c
SS
27312
27313@table @code
8e04817f
AC
27314@kindex echo
27315@item echo @var{text}
27316@c I do not consider backslash-space a standard C escape sequence
27317@c because it is not in ANSI.
27318Print @var{text}. Nonprinting characters can be included in
27319@var{text} using C escape sequences, such as @samp{\n} to print a
27320newline. @strong{No newline is printed unless you specify one.}
27321In addition to the standard C escape sequences, a backslash followed
27322by a space stands for a space. This is useful for displaying a
27323string with spaces at the beginning or the end, since leading and
27324trailing spaces are otherwise trimmed from all arguments.
27325To print @samp{@w{ }and foo =@w{ }}, use the command
27326@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 27327
8e04817f
AC
27328A backslash at the end of @var{text} can be used, as in C, to continue
27329the command onto subsequent lines. For example,
c906108c 27330
474c8240 27331@smallexample
8e04817f
AC
27332echo This is some text\n\
27333which is continued\n\
27334onto several lines.\n
474c8240 27335@end smallexample
c906108c 27336
8e04817f 27337produces the same output as
c906108c 27338
474c8240 27339@smallexample
8e04817f
AC
27340echo This is some text\n
27341echo which is continued\n
27342echo onto several lines.\n
474c8240 27343@end smallexample
c906108c 27344
8e04817f
AC
27345@kindex output
27346@item output @var{expression}
27347Print the value of @var{expression} and nothing but that value: no
27348newlines, no @samp{$@var{nn} = }. The value is not entered in the
27349value history either. @xref{Expressions, ,Expressions}, for more information
27350on expressions.
c906108c 27351
8e04817f
AC
27352@item output/@var{fmt} @var{expression}
27353Print the value of @var{expression} in format @var{fmt}. You can use
27354the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 27355Formats}, for more information.
c906108c 27356
8e04817f 27357@kindex printf
82160952
EZ
27358@item printf @var{template}, @var{expressions}@dots{}
27359Print the values of one or more @var{expressions} under the control of
27360the string @var{template}. To print several values, make
27361@var{expressions} be a comma-separated list of individual expressions,
27362which may be either numbers or pointers. Their values are printed as
27363specified by @var{template}, exactly as a C program would do by
27364executing the code below:
c906108c 27365
474c8240 27366@smallexample
82160952 27367printf (@var{template}, @var{expressions}@dots{});
474c8240 27368@end smallexample
c906108c 27369
82160952
EZ
27370As in @code{C} @code{printf}, ordinary characters in @var{template}
27371are printed verbatim, while @dfn{conversion specification} introduced
27372by the @samp{%} character cause subsequent @var{expressions} to be
27373evaluated, their values converted and formatted according to type and
27374style information encoded in the conversion specifications, and then
27375printed.
27376
8e04817f 27377For example, you can print two values in hex like this:
c906108c 27378
8e04817f
AC
27379@smallexample
27380printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
27381@end smallexample
c906108c 27382
82160952
EZ
27383@code{printf} supports all the standard @code{C} conversion
27384specifications, including the flags and modifiers between the @samp{%}
27385character and the conversion letter, with the following exceptions:
27386
27387@itemize @bullet
27388@item
27389The argument-ordering modifiers, such as @samp{2$}, are not supported.
27390
27391@item
27392The modifier @samp{*} is not supported for specifying precision or
27393width.
27394
27395@item
27396The @samp{'} flag (for separation of digits into groups according to
27397@code{LC_NUMERIC'}) is not supported.
27398
27399@item
27400The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
27401supported.
27402
27403@item
27404The conversion letter @samp{n} (as in @samp{%n}) is not supported.
27405
27406@item
27407The conversion letters @samp{a} and @samp{A} are not supported.
27408@end itemize
27409
27410@noindent
27411Note that the @samp{ll} type modifier is supported only if the
27412underlying @code{C} implementation used to build @value{GDBN} supports
27413the @code{long long int} type, and the @samp{L} type modifier is
27414supported only if @code{long double} type is available.
27415
27416As in @code{C}, @code{printf} supports simple backslash-escape
27417sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
27418@samp{\a}, and @samp{\f}, that consist of backslash followed by a
27419single character. Octal and hexadecimal escape sequences are not
27420supported.
1a619819
LM
27421
27422Additionally, @code{printf} supports conversion specifications for DFP
0aea4bf3
LM
27423(@dfn{Decimal Floating Point}) types using the following length modifiers
27424together with a floating point specifier.
1a619819
LM
27425letters:
27426
27427@itemize @bullet
27428@item
27429@samp{H} for printing @code{Decimal32} types.
27430
27431@item
27432@samp{D} for printing @code{Decimal64} types.
27433
27434@item
27435@samp{DD} for printing @code{Decimal128} types.
27436@end itemize
27437
27438If the underlying @code{C} implementation used to build @value{GDBN} has
0aea4bf3 27439support for the three length modifiers for DFP types, other modifiers
3b784c4f 27440such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
27441
27442In case there is no such @code{C} support, no additional modifiers will be
27443available and the value will be printed in the standard way.
27444
27445Here's an example of printing DFP types using the above conversion letters:
27446@smallexample
0aea4bf3 27447printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
1a619819
LM
27448@end smallexample
27449
01770bbd 27450@anchor{eval}
f1421989
HZ
27451@kindex eval
27452@item eval @var{template}, @var{expressions}@dots{}
27453Convert the values of one or more @var{expressions} under the control of
27454the string @var{template} to a command line, and call it.
27455
c906108c
SS
27456@end table
27457
71b8c845
DE
27458@node Auto-loading sequences
27459@subsection Controlling auto-loading native @value{GDBN} scripts
27460@cindex native script auto-loading
27461
27462When a new object file is read (for example, due to the @code{file}
27463command, or because the inferior has loaded a shared library),
27464@value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
27465@xref{Auto-loading extensions}.
27466
27467Auto-loading can be enabled or disabled,
27468and the list of auto-loaded scripts can be printed.
27469
27470@table @code
27471@anchor{set auto-load gdb-scripts}
27472@kindex set auto-load gdb-scripts
27473@item set auto-load gdb-scripts [on|off]
27474Enable or disable the auto-loading of canned sequences of commands scripts.
27475
27476@anchor{show auto-load gdb-scripts}
27477@kindex show auto-load gdb-scripts
27478@item show auto-load gdb-scripts
27479Show whether auto-loading of canned sequences of commands scripts is enabled or
27480disabled.
27481
27482@anchor{info auto-load gdb-scripts}
27483@kindex info auto-load gdb-scripts
27484@cindex print list of auto-loaded canned sequences of commands scripts
27485@item info auto-load gdb-scripts [@var{regexp}]
27486Print the list of all canned sequences of commands scripts that @value{GDBN}
27487auto-loaded.
27488@end table
27489
27490If @var{regexp} is supplied only canned sequences of commands scripts with
27491matching names are printed.
27492
a72d0f3d
AB
27493@node Aliases
27494@section Command Aliases
27495@cindex aliases for commands
27496
a72d0f3d
AB
27497Aliases allow you to define alternate spellings for existing commands.
27498For example, if a new @value{GDBN} command defined in Python
27499(@pxref{Python}) has a long name, it is handy to have an abbreviated
27500version of it that involves less typing.
27501
27502@value{GDBN} itself uses aliases. For example @samp{s} is an alias
27503of the @samp{step} command even though it is otherwise an ambiguous
27504abbreviation of other commands like @samp{set} and @samp{show}.
27505
27506Aliases are also used to provide shortened or more common versions
27507of multi-word commands. For example, @value{GDBN} provides the
27508@samp{tty} alias of the @samp{set inferior-tty} command.
27509
27510You can define a new alias with the @samp{alias} command.
27511
27512@table @code
27513
27514@kindex alias
27515@item alias [-a] [--] @var{alias} = @var{command} [@var{default-args}]
27516
27517@end table
27518
27519@var{alias} specifies the name of the new alias. Each word of
27520@var{alias} must consist of letters, numbers, dashes and underscores.
27521
27522@var{command} specifies the name of an existing command
27523that is being aliased.
27524
27525@var{command} can also be the name of an existing alias. In this
27526case, @var{command} cannot be an alias that has default arguments.
27527
27528The @samp{-a} option specifies that the new alias is an abbreviation
27529of the command. Abbreviations are not used in command completion.
27530
27531The @samp{--} option specifies the end of options,
27532and is useful when @var{alias} begins with a dash.
27533
27534You can specify @var{default-args} for your alias. These
27535@var{default-args} will be automatically added before the alias
27536arguments typed explicitly on the command line.
27537
27538For example, the below defines an alias @code{btfullall} that shows all local
27539variables and all frame arguments:
27540@smallexample
27541(@value{GDBP}) alias btfullall = backtrace -full -frame-arguments all
27542@end smallexample
27543
27544For more information about @var{default-args}, see @ref{Command
27545aliases default args, ,Default Arguments}.
27546
27547Here is a simple example showing how to make an abbreviation of a
27548command so that there is less to type. Suppose you were tired of
27549typing @samp{disas}, the current shortest unambiguous abbreviation of
27550the @samp{disassemble} command and you wanted an even shorter version
27551named @samp{di}. The following will accomplish this.
27552
27553@smallexample
27554(gdb) alias -a di = disas
27555@end smallexample
27556
27557Note that aliases are different from user-defined commands. With a
27558user-defined command, you also need to write documentation for it with
27559the @samp{document} command. An alias automatically picks up the
27560documentation of the existing command.
27561
27562Here is an example where we make @samp{elms} an abbreviation of
27563@samp{elements} in the @samp{set print elements} command.
27564This is to show that you can make an abbreviation of any part
27565of a command.
27566
27567@smallexample
27568(gdb) alias -a set print elms = set print elements
27569(gdb) alias -a show print elms = show print elements
27570(gdb) set p elms 20
27571(gdb) show p elms
27572Limit on string chars or array elements to print is 200.
27573@end smallexample
27574
27575Note that if you are defining an alias of a @samp{set} command,
27576and you want to have an alias for the corresponding @samp{show}
27577command, then you need to define the latter separately.
27578
27579Unambiguously abbreviated commands are allowed in @var{command} and
27580@var{alias}, just as they are normally.
27581
27582@smallexample
27583(gdb) alias -a set pr elms = set p ele
27584@end smallexample
27585
27586Finally, here is an example showing the creation of a one word
27587alias for a more complex command.
27588This creates alias @samp{spe} of the command @samp{set print elements}.
27589
27590@smallexample
27591(gdb) alias spe = set print elements
27592(gdb) spe 20
27593@end smallexample
27594
fe461d2f
AB
27595@menu
27596* Command aliases default args:: Default arguments for aliases
27597@end menu
27598
a72d0f3d
AB
27599@node Command aliases default args
27600@subsection Default Arguments
27601@cindex aliases for commands, default arguments
27602
27603You can tell @value{GDBN} to always prepend some default arguments to
27604the list of arguments provided explicitly by the user when using a
27605user-defined alias.
27606
27607If you repeatedly use the same arguments or options for a command, you
27608can define an alias for this command and tell @value{GDBN} to
27609automatically prepend these arguments or options to the list of
27610arguments you type explicitly when using the alias@footnote{@value{GDBN}
27611could easily accept default arguments for pre-defined commands and aliases,
27612but it was deemed this would be confusing, and so is not allowed.}.
27613
27614For example, if you often use the command @code{thread apply all}
27615specifying to work on the threads in ascending order and to continue in case it
27616encounters an error, you can tell @value{GDBN} to automatically preprend
27617the @code{-ascending} and @code{-c} options by using:
27618
27619@smallexample
27620(@value{GDBP}) alias thread apply asc-all = thread apply all -ascending -c
27621@end smallexample
27622
27623Once you have defined this alias with its default args, any time you type
27624the @code{thread apply asc-all} followed by @code{some arguments},
27625@value{GDBN} will execute @code{thread apply all -ascending -c some arguments}.
27626
27627To have even less to type, you can also define a one word alias:
27628@smallexample
27629(@value{GDBP}) alias t_a_c = thread apply all -ascending -c
27630@end smallexample
27631
27632As usual, unambiguous abbreviations can be used for @var{alias}
27633and @var{default-args}.
27634
27635The different aliases of a command do not share their default args.
27636For example, you define a new alias @code{bt_ALL} showing all possible
27637information and another alias @code{bt_SMALL} showing very limited information
27638using:
27639@smallexample
27640(@value{GDBP}) alias bt_ALL = backtrace -entry-values both -frame-arg all \
27641 -past-main -past-entry -full
27642(@value{GDBP}) alias bt_SMALL = backtrace -entry-values no -frame-arg none \
27643 -past-main off -past-entry off
27644@end smallexample
27645
27646(For more on using the @code{alias} command, see @ref{Aliases}.)
27647
27648Default args are not limited to the arguments and options of @var{command},
27649but can specify nested commands if @var{command} accepts such a nested command
27650as argument.
27651For example, the below defines @code{faalocalsoftype} that lists the
27652frames having locals of a certain type, together with the matching
27653local vars:
27654@smallexample
27655(@value{GDBP}) alias faalocalsoftype = frame apply all info locals -q -t
27656(@value{GDBP}) faalocalsoftype int
27657#1 0x55554f5e in sleeper_or_burner (v=0xdf50) at sleepers.c:86
27658i = 0
27659ret = 21845
27660@end smallexample
27661
27662This is also very useful to define an alias for a set of nested @code{with}
27663commands to have a particular combination of temporary settings. For example,
27664the below defines the alias @code{pp10} that pretty prints an expression
27665argument, with a maximum of 10 elements if the expression is a string or
27666an array:
27667@smallexample
27668(@value{GDBP}) alias pp10 = with print pretty -- with print elements 10 -- print
27669@end smallexample
27670This defines the alias @code{pp10} as being a sequence of 3 commands.
27671The first part @code{with print pretty --} temporarily activates the setting
27672@code{set print pretty}, then launches the command that follows the separator
27673@code{--}.
27674The command following the first part is also a @code{with} command that
27675temporarily changes the setting @code{set print elements} to 10, then
27676launches the command that follows the second separator @code{--}.
27677The third part @code{print} is the command the @code{pp10} alias will launch,
27678using the temporary values of the settings and the arguments explicitly given
27679by the user.
27680For more information about the @code{with} command usage,
27681see @ref{Command Settings}.
27682
329baa95
DE
27683@c Python docs live in a separate file.
27684@include python.texi
0e3509db 27685
ed3ef339
DE
27686@c Guile docs live in a separate file.
27687@include guile.texi
27688
71b8c845
DE
27689@node Auto-loading extensions
27690@section Auto-loading extensions
27691@cindex auto-loading extensions
27692
d8c4766d
AB
27693@value{GDBN} provides two mechanisms for automatically loading
27694extensions when a new object file is read (for example, due to the
27695@code{file} command, or because the inferior has loaded a shared
27696library): @file{@var{objfile}-gdb.@var{ext}} (@pxref{objfile-gdbdotext
27697file,,The @file{@var{objfile}-gdb.@var{ext}} file}) and the
27698@code{.debug_gdb_scripts} section of modern file formats like ELF
bb3c2d4d 27699(@pxref{dotdebug_gdb_scripts section,,The @code{.debug_gdb_scripts}
d8c4766d
AB
27700section}). For a discussion of the differences between these two
27701approaches see @ref{Which flavor to choose?}.
71b8c845
DE
27702
27703The auto-loading feature is useful for supplying application-specific
27704debugging commands and features.
27705
27706Auto-loading can be enabled or disabled,
27707and the list of auto-loaded scripts can be printed.
27708See the @samp{auto-loading} section of each extension language
27709for more information.
27710For @value{GDBN} command files see @ref{Auto-loading sequences}.
27711For Python files see @ref{Python Auto-loading}.
27712
27713Note that loading of this script file also requires accordingly configured
27714@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27715
d8c4766d
AB
27716@menu
27717* objfile-gdbdotext file:: The @file{@var{objfile}-gdb.@var{ext}} file
27718* dotdebug_gdb_scripts section:: The @code{.debug_gdb_scripts} section
27719* Which flavor to choose?:: Choosing between these approaches
27720@end menu
27721
71b8c845
DE
27722@node objfile-gdbdotext file
27723@subsection The @file{@var{objfile}-gdb.@var{ext}} file
27724@cindex @file{@var{objfile}-gdb.gdb}
27725@cindex @file{@var{objfile}-gdb.py}
27726@cindex @file{@var{objfile}-gdb.scm}
27727
27728When a new object file is read, @value{GDBN} looks for a file named
27729@file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
27730where @var{objfile} is the object file's name and
27731where @var{ext} is the file extension for the extension language:
27732
27733@table @code
27734@item @file{@var{objfile}-gdb.gdb}
27735GDB's own command language
27736@item @file{@var{objfile}-gdb.py}
27737Python
ed3ef339
DE
27738@item @file{@var{objfile}-gdb.scm}
27739Guile
71b8c845
DE
27740@end table
27741
27742@var{script-name} is formed by ensuring that the file name of @var{objfile}
27743is absolute, following all symlinks, and resolving @code{.} and @code{..}
27744components, and appending the @file{-gdb.@var{ext}} suffix.
27745If this file exists and is readable, @value{GDBN} will evaluate it as a
27746script in the specified extension language.
27747
27748If this file does not exist, then @value{GDBN} will look for
27749@var{script-name} file in all of the directories as specified below.
6e2469ff
HD
27750(On MS-Windows/MS-DOS, the drive letter of the executable's leading
27751directories is converted to a one-letter subdirectory, i.e.@:
27752@file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
27753filesystems disallow colons in file names.)
71b8c845
DE
27754
27755Note that loading of these files requires an accordingly configured
27756@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27757
27758For object files using @file{.exe} suffix @value{GDBN} tries to load first the
27759scripts normally according to its @file{.exe} filename. But if no scripts are
27760found @value{GDBN} also tries script filenames matching the object file without
27761its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
27762is attempted on any platform. This makes the script filenames compatible
27763between Unix and MS-Windows hosts.
27764
27765@table @code
27766@anchor{set auto-load scripts-directory}
27767@kindex set auto-load scripts-directory
27768@item set auto-load scripts-directory @r{[}@var{directories}@r{]}
27769Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
27770may be delimited by the host platform path separator in use
27771(@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
27772
27773Each entry here needs to be covered also by the security setting
27774@code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
27775
27776@anchor{with-auto-load-dir}
27777This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
27778@code{set auto-load safe-path} value can be also overriden by @value{GDBN}
27779configuration option @option{--with-auto-load-dir}.
27780
27781Any reference to @file{$debugdir} will get replaced by
27782@var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
27783reference to @file{$datadir} will get replaced by @var{data-directory} which is
27784determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
27785@file{$datadir} must be placed as a directory component --- either alone or
27786delimited by @file{/} or @file{\} directory separators, depending on the host
27787platform.
27788
27789The list of directories uses path separator (@samp{:} on GNU and Unix
27790systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
27791to the @env{PATH} environment variable.
27792
27793@anchor{show auto-load scripts-directory}
27794@kindex show auto-load scripts-directory
27795@item show auto-load scripts-directory
27796Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
27797
27798@anchor{add-auto-load-scripts-directory}
27799@kindex add-auto-load-scripts-directory
27800@item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
27801Add an entry (or list of entries) to the list of auto-loaded scripts locations.
27802Multiple entries may be delimited by the host platform path separator in use.
71b8c845
DE
27803@end table
27804
27805@value{GDBN} does not track which files it has already auto-loaded this way.
27806@value{GDBN} will load the associated script every time the corresponding
27807@var{objfile} is opened.
27808So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
27809is evaluated more than once.
27810
27811@node dotdebug_gdb_scripts section
27812@subsection The @code{.debug_gdb_scripts} section
27813@cindex @code{.debug_gdb_scripts} section
27814
27815For systems using file formats like ELF and COFF,
27816when @value{GDBN} loads a new object file
27817it will look for a special section named @code{.debug_gdb_scripts}.
9f050062
DE
27818If this section exists, its contents is a list of null-terminated entries
27819specifying scripts to load. Each entry begins with a non-null prefix byte that
27820specifies the kind of entry, typically the extension language and whether the
27821script is in a file or inlined in @code{.debug_gdb_scripts}.
71b8c845 27822
9f050062
DE
27823The following entries are supported:
27824
27825@table @code
27826@item SECTION_SCRIPT_ID_PYTHON_FILE = 1
27827@item SECTION_SCRIPT_ID_SCHEME_FILE = 3
27828@item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
27829@item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
27830@end table
27831
27832@subsubsection Script File Entries
27833
27834If the entry specifies a file, @value{GDBN} will look for the file first
27835in the current directory and then along the source search path
71b8c845
DE
27836(@pxref{Source Path, ,Specifying Source Directories}),
27837except that @file{$cdir} is not searched, since the compilation
27838directory is not relevant to scripts.
27839
9f050062 27840File entries can be placed in section @code{.debug_gdb_scripts} with,
71b8c845
DE
27841for example, this GCC macro for Python scripts.
27842
27843@example
27844/* Note: The "MS" section flags are to remove duplicates. */
27845#define DEFINE_GDB_PY_SCRIPT(script_name) \
27846 asm("\
27847.pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
27848.byte 1 /* Python */\n\
27849.asciz \"" script_name "\"\n\
27850.popsection \n\
27851");
27852@end example
27853
27854@noindent
ed3ef339 27855For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
71b8c845
DE
27856Then one can reference the macro in a header or source file like this:
27857
27858@example
27859DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
27860@end example
27861
27862The script name may include directories if desired.
27863
27864Note that loading of this script file also requires accordingly configured
27865@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27866
27867If the macro invocation is put in a header, any application or library
27868using this header will get a reference to the specified script,
27869and with the use of @code{"MS"} attributes on the section, the linker
27870will remove duplicates.
27871
9f050062
DE
27872@subsubsection Script Text Entries
27873
27874Script text entries allow to put the executable script in the entry
27875itself instead of loading it from a file.
27876The first line of the entry, everything after the prefix byte and up to
27877the first newline (@code{0xa}) character, is the script name, and must not
27878contain any kind of space character, e.g., spaces or tabs.
27879The rest of the entry, up to the trailing null byte, is the script to
27880execute in the specified language. The name needs to be unique among
27881all script names, as @value{GDBN} executes each script only once based
27882on its name.
27883
27884Here is an example from file @file{py-section-script.c} in the @value{GDBN}
27885testsuite.
27886
27887@example
27888#include "symcat.h"
27889#include "gdb/section-scripts.h"
27890asm(
27891".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
27892".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
27893".ascii \"gdb.inlined-script\\n\"\n"
27894".ascii \"class test_cmd (gdb.Command):\\n\"\n"
27895".ascii \" def __init__ (self):\\n\"\n"
27896".ascii \" super (test_cmd, self).__init__ ("
27897 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
27898".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
27899".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
27900".ascii \"test_cmd ()\\n\"\n"
27901".byte 0\n"
27902".popsection\n"
27903);
27904@end example
27905
27906Loading of inlined scripts requires a properly configured
27907@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27908The path to specify in @code{auto-load safe-path} is the path of the file
27909containing the @code{.debug_gdb_scripts} section.
27910
71b8c845
DE
27911@node Which flavor to choose?
27912@subsection Which flavor to choose?
27913
27914Given the multiple ways of auto-loading extensions, it might not always
27915be clear which one to choose. This section provides some guidance.
27916
27917@noindent
27918Benefits of the @file{-gdb.@var{ext}} way:
27919
27920@itemize @bullet
27921@item
27922Can be used with file formats that don't support multiple sections.
27923
27924@item
27925Ease of finding scripts for public libraries.
27926
27927Scripts specified in the @code{.debug_gdb_scripts} section are searched for
27928in the source search path.
27929For publicly installed libraries, e.g., @file{libstdc++}, there typically
27930isn't a source directory in which to find the script.
27931
27932@item
27933Doesn't require source code additions.
27934@end itemize
27935
27936@noindent
27937Benefits of the @code{.debug_gdb_scripts} way:
27938
27939@itemize @bullet
27940@item
27941Works with static linking.
27942
27943Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
27944trigger their loading. When an application is statically linked the only
27945objfile available is the executable, and it is cumbersome to attach all the
27946scripts from all the input libraries to the executable's
27947@file{-gdb.@var{ext}} script.
27948
27949@item
27950Works with classes that are entirely inlined.
27951
27952Some classes can be entirely inlined, and thus there may not be an associated
27953shared library to attach a @file{-gdb.@var{ext}} script to.
27954
27955@item
27956Scripts needn't be copied out of the source tree.
27957
27958In some circumstances, apps can be built out of large collections of internal
27959libraries, and the build infrastructure necessary to install the
27960@file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
27961cumbersome. It may be easier to specify the scripts in the
27962@code{.debug_gdb_scripts} section as relative paths, and add a path to the
27963top of the source tree to the source search path.
27964@end itemize
27965
ed3ef339
DE
27966@node Multiple Extension Languages
27967@section Multiple Extension Languages
27968
27969The Guile and Python extension languages do not share any state,
27970and generally do not interfere with each other.
27971There are some things to be aware of, however.
27972
27973@subsection Python comes first
27974
27975Python was @value{GDBN}'s first extension language, and to avoid breaking
27976existing behaviour Python comes first. This is generally solved by the
27977``first one wins'' principle. @value{GDBN} maintains a list of enabled
27978extension languages, and when it makes a call to an extension language,
27979(say to pretty-print a value), it tries each in turn until an extension
27980language indicates it has performed the request (e.g., has returned the
27981pretty-printed form of a value).
27982This extends to errors while performing such requests: If an error happens
27983while, for example, trying to pretty-print an object then the error is
27984reported and any following extension languages are not tried.
27985
21c294e6
AC
27986@node Interpreters
27987@chapter Command Interpreters
27988@cindex command interpreters
27989
27990@value{GDBN} supports multiple command interpreters, and some command
27991infrastructure to allow users or user interface writers to switch
27992between interpreters or run commands in other interpreters.
27993
27994@value{GDBN} currently supports two command interpreters, the console
27995interpreter (sometimes called the command-line interpreter or @sc{cli})
27996and the machine interface interpreter (or @sc{gdb/mi}). This manual
27997describes both of these interfaces in great detail.
27998
27999By default, @value{GDBN} will start with the console interpreter.
28000However, the user may choose to start @value{GDBN} with another
28001interpreter by specifying the @option{-i} or @option{--interpreter}
28002startup options. Defined interpreters include:
28003
28004@table @code
28005@item console
28006@cindex console interpreter
28007The traditional console or command-line interpreter. This is the most often
28008used interpreter with @value{GDBN}. With no interpreter specified at runtime,
28009@value{GDBN} will use this interpreter.
28010
28011@item mi
28012@cindex mi interpreter
b4be1b06 28013The newest @sc{gdb/mi} interface (currently @code{mi3}). Used primarily
21c294e6
AC
28014by programs wishing to use @value{GDBN} as a backend for a debugger GUI
28015or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
28016Interface}.
28017
b4be1b06
SM
28018@item mi3
28019@cindex mi3 interpreter
28020The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
28021
21c294e6
AC
28022@item mi2
28023@cindex mi2 interpreter
b4be1b06 28024The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
21c294e6
AC
28025
28026@item mi1
28027@cindex mi1 interpreter
b4be1b06 28028The @sc{gdb/mi} interface introduced in @value{GDBN} 5.1.
21c294e6
AC
28029
28030@end table
28031
28032@cindex invoke another interpreter
21c294e6
AC
28033
28034@kindex interpreter-exec
86f78169
PA
28035You may execute commands in any interpreter from the current
28036interpreter using the appropriate command. If you are running the
28037console interpreter, simply use the @code{interpreter-exec} command:
21c294e6
AC
28038
28039@smallexample
28040interpreter-exec mi "-data-list-register-names"
28041@end smallexample
28042
28043@sc{gdb/mi} has a similar command, although it is only available in versions of
28044@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
28045
86f78169
PA
28046Note that @code{interpreter-exec} only changes the interpreter for the
28047duration of the specified command. It does not change the interpreter
28048permanently.
28049
28050@cindex start a new independent interpreter
28051
28052Although you may only choose a single interpreter at startup, it is
28053possible to run an independent interpreter on a specified input/output
28054device (usually a tty).
28055
28056For example, consider a debugger GUI or IDE that wants to provide a
28057@value{GDBN} console view. It may do so by embedding a terminal
28058emulator widget in its GUI, starting @value{GDBN} in the traditional
28059command-line mode with stdin/stdout/stderr redirected to that
28060terminal, and then creating an MI interpreter running on a specified
28061input/output device. The console interpreter created by @value{GDBN}
28062at startup handles commands the user types in the terminal widget,
28063while the GUI controls and synchronizes state with @value{GDBN} using
28064the separate MI interpreter.
28065
28066To start a new secondary @dfn{user interface} running MI, use the
28067@code{new-ui} command:
28068
28069@kindex new-ui
28070@cindex new user interface
28071@smallexample
28072new-ui @var{interpreter} @var{tty}
28073@end smallexample
28074
28075The @var{interpreter} parameter specifies the interpreter to run.
28076This accepts the same values as the @code{interpreter-exec} command.
28077For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
28078@var{tty} parameter specifies the name of the bidirectional file the
28079interpreter uses for input/output, usually the name of a
28080pseudoterminal slave on Unix systems. For example:
28081
28082@smallexample
28083(@value{GDBP}) new-ui mi /dev/pts/9
28084@end smallexample
28085
28086@noindent
28087runs an MI interpreter on @file{/dev/pts/9}.
28088
8e04817f
AC
28089@node TUI
28090@chapter @value{GDBN} Text User Interface
28091@cindex TUI
d0d5df6f 28092@cindex Text User Interface
c906108c 28093
46ba6afa 28094The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
28095interface which uses the @code{curses} library to show the source
28096file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
28097commands in separate text windows. The TUI mode is supported only
28098on platforms where a suitable version of the @code{curses} library
28099is available.
d0d5df6f 28100
46ba6afa 28101The TUI mode is enabled by default when you invoke @value{GDBN} as
217bff3e 28102@samp{@value{GDBP} -tui}.
46ba6afa 28103You can also switch in and out of TUI mode while @value{GDBN} runs by
a4ea0946 28104using various TUI commands and key bindings, such as @command{tui
bcd8537c 28105enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
a4ea0946 28106@ref{TUI Keys, ,TUI Key Bindings}.
c906108c 28107
04de9f3e
AB
28108@menu
28109* TUI Overview:: TUI overview
28110* TUI Keys:: TUI key bindings
28111* TUI Single Key Mode:: TUI single key mode
28112* TUI Commands:: TUI-specific commands
28113* TUI Configuration:: TUI configuration variables
28114@end menu
28115
8e04817f 28116@node TUI Overview
79a6e687 28117@section TUI Overview
c906108c 28118
46ba6afa 28119In TUI mode, @value{GDBN} can display several text windows:
c906108c 28120
8e04817f
AC
28121@table @emph
28122@item command
28123This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
28124prompt and the @value{GDBN} output. The @value{GDBN} input is still
28125managed using readline.
c906108c 28126
8e04817f
AC
28127@item source
28128The source window shows the source file of the program. The current
46ba6afa 28129line and active breakpoints are displayed in this window.
c906108c 28130
8e04817f
AC
28131@item assembly
28132The assembly window shows the disassembly output of the program.
c906108c 28133
8e04817f 28134@item register
46ba6afa
BW
28135This window shows the processor registers. Registers are highlighted
28136when their values change.
c906108c
SS
28137@end table
28138
269c21fe 28139The source and assembly windows show the current program position
46ba6afa
BW
28140by highlighting the current line and marking it with a @samp{>} marker.
28141Breakpoints are indicated with two markers. The first marker
269c21fe
SC
28142indicates the breakpoint type:
28143
28144@table @code
28145@item B
28146Breakpoint which was hit at least once.
28147
28148@item b
28149Breakpoint which was never hit.
28150
28151@item H
28152Hardware breakpoint which was hit at least once.
28153
28154@item h
28155Hardware breakpoint which was never hit.
269c21fe
SC
28156@end table
28157
28158The second marker indicates whether the breakpoint is enabled or not:
28159
28160@table @code
28161@item +
28162Breakpoint is enabled.
28163
28164@item -
28165Breakpoint is disabled.
269c21fe
SC
28166@end table
28167
46ba6afa
BW
28168The source, assembly and register windows are updated when the current
28169thread changes, when the frame changes, or when the program counter
28170changes.
28171
28172These windows are not all visible at the same time. The command
28173window is always visible. The others can be arranged in several
28174layouts:
c906108c 28175
8e04817f
AC
28176@itemize @bullet
28177@item
46ba6afa 28178source only,
2df3850c 28179
8e04817f 28180@item
46ba6afa 28181assembly only,
8e04817f
AC
28182
28183@item
46ba6afa 28184source and assembly,
8e04817f
AC
28185
28186@item
46ba6afa 28187source and registers, or
c906108c 28188
8e04817f 28189@item
46ba6afa 28190assembly and registers.
8e04817f 28191@end itemize
c906108c 28192
ee325b61
TT
28193These are the standard layouts, but other layouts can be defined.
28194
46ba6afa 28195A status line above the command window shows the following information:
b7bb15bc
SC
28196
28197@table @emph
28198@item target
46ba6afa 28199Indicates the current @value{GDBN} target.
b7bb15bc
SC
28200(@pxref{Targets, ,Specifying a Debugging Target}).
28201
28202@item process
46ba6afa 28203Gives the current process or thread number.
b7bb15bc
SC
28204When no process is being debugged, this field is set to @code{No process}.
28205
28206@item function
28207Gives the current function name for the selected frame.
28208The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 28209When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
28210the string @code{??} is displayed.
28211
28212@item line
28213Indicates the current line number for the selected frame.
46ba6afa 28214When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
28215
28216@item pc
28217Indicates the current program counter address.
b7bb15bc
SC
28218@end table
28219
8e04817f
AC
28220@node TUI Keys
28221@section TUI Key Bindings
28222@cindex TUI key bindings
c906108c 28223
8e04817f 28224The TUI installs several key bindings in the readline keymaps
39037522
TT
28225@ifset SYSTEM_READLINE
28226(@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
28227@end ifset
28228@ifclear SYSTEM_READLINE
28229(@pxref{Command Line Editing}).
28230@end ifclear
28231The following key bindings are installed for both TUI mode and the
28232@value{GDBN} standard mode.
c906108c 28233
8e04817f
AC
28234@table @kbd
28235@kindex C-x C-a
28236@item C-x C-a
28237@kindex C-x a
28238@itemx C-x a
28239@kindex C-x A
28240@itemx C-x A
46ba6afa
BW
28241Enter or leave the TUI mode. When leaving the TUI mode,
28242the curses window management stops and @value{GDBN} operates using
28243its standard mode, writing on the terminal directly. When reentering
28244the TUI mode, control is given back to the curses windows.
8e04817f 28245The screen is then refreshed.
c906108c 28246
c86d74cc
TT
28247This key binding uses the bindable Readline function
28248@code{tui-switch-mode}.
28249
8e04817f
AC
28250@kindex C-x 1
28251@item C-x 1
28252Use a TUI layout with only one window. The layout will
28253either be @samp{source} or @samp{assembly}. When the TUI mode
28254is not active, it will switch to the TUI mode.
2df3850c 28255
8e04817f 28256Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 28257
c86d74cc
TT
28258This key binding uses the bindable Readline function
28259@code{tui-delete-other-windows}.
28260
8e04817f
AC
28261@kindex C-x 2
28262@item C-x 2
28263Use a TUI layout with at least two windows. When the current
46ba6afa 28264layout already has two windows, the next layout with two windows is used.
8e04817f
AC
28265When a new layout is chosen, one window will always be common to the
28266previous layout and the new one.
c906108c 28267
8e04817f 28268Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 28269
c86d74cc
TT
28270This key binding uses the bindable Readline function
28271@code{tui-change-windows}.
28272
72ffddc9
SC
28273@kindex C-x o
28274@item C-x o
28275Change the active window. The TUI associates several key bindings
46ba6afa 28276(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
28277gives the focus to the next TUI window.
28278
28279Think of it as the Emacs @kbd{C-x o} binding.
28280
c86d74cc
TT
28281This key binding uses the bindable Readline function
28282@code{tui-other-window}.
28283
7cf36c78
SC
28284@kindex C-x s
28285@item C-x s
46ba6afa
BW
28286Switch in and out of the TUI SingleKey mode that binds single
28287keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c86d74cc
TT
28288
28289This key binding uses the bindable Readline function
28290@code{next-keymap}.
c906108c
SS
28291@end table
28292
46ba6afa 28293The following key bindings only work in the TUI mode:
5d161b24 28294
46ba6afa 28295@table @asis
8e04817f 28296@kindex PgUp
46ba6afa 28297@item @key{PgUp}
8e04817f 28298Scroll the active window one page up.
c906108c 28299
8e04817f 28300@kindex PgDn
46ba6afa 28301@item @key{PgDn}
8e04817f 28302Scroll the active window one page down.
c906108c 28303
8e04817f 28304@kindex Up
46ba6afa 28305@item @key{Up}
8e04817f 28306Scroll the active window one line up.
c906108c 28307
8e04817f 28308@kindex Down
46ba6afa 28309@item @key{Down}
8e04817f 28310Scroll the active window one line down.
c906108c 28311
8e04817f 28312@kindex Left
46ba6afa 28313@item @key{Left}
8e04817f 28314Scroll the active window one column left.
c906108c 28315
8e04817f 28316@kindex Right
46ba6afa 28317@item @key{Right}
8e04817f 28318Scroll the active window one column right.
c906108c 28319
8e04817f 28320@kindex C-L
46ba6afa 28321@item @kbd{C-L}
8e04817f 28322Refresh the screen.
8e04817f 28323@end table
c906108c 28324
46ba6afa
BW
28325Because the arrow keys scroll the active window in the TUI mode, they
28326are not available for their normal use by readline unless the command
28327window has the focus. When another window is active, you must use
28328other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
28329and @kbd{C-f} to control the command window.
8e04817f 28330
7cf36c78
SC
28331@node TUI Single Key Mode
28332@section TUI Single Key Mode
28333@cindex TUI single key mode
28334
46ba6afa
BW
28335The TUI also provides a @dfn{SingleKey} mode, which binds several
28336frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
28337switch into this mode, where the following key bindings are used:
7cf36c78
SC
28338
28339@table @kbd
28340@kindex c @r{(SingleKey TUI key)}
28341@item c
28342continue
28343
28344@kindex d @r{(SingleKey TUI key)}
28345@item d
28346down
28347
28348@kindex f @r{(SingleKey TUI key)}
28349@item f
28350finish
28351
28352@kindex n @r{(SingleKey TUI key)}
28353@item n
28354next
28355
a5afdb16
RK
28356@kindex o @r{(SingleKey TUI key)}
28357@item o
28358nexti. The shortcut letter @samp{o} stands for ``step Over''.
28359
7cf36c78
SC
28360@kindex q @r{(SingleKey TUI key)}
28361@item q
46ba6afa 28362exit the SingleKey mode.
7cf36c78
SC
28363
28364@kindex r @r{(SingleKey TUI key)}
28365@item r
28366run
28367
28368@kindex s @r{(SingleKey TUI key)}
28369@item s
28370step
28371
a5afdb16
RK
28372@kindex i @r{(SingleKey TUI key)}
28373@item i
28374stepi. The shortcut letter @samp{i} stands for ``step Into''.
28375
7cf36c78
SC
28376@kindex u @r{(SingleKey TUI key)}
28377@item u
28378up
28379
28380@kindex v @r{(SingleKey TUI key)}
28381@item v
28382info locals
28383
28384@kindex w @r{(SingleKey TUI key)}
28385@item w
28386where
7cf36c78
SC
28387@end table
28388
28389Other keys temporarily switch to the @value{GDBN} command prompt.
28390The key that was pressed is inserted in the editing buffer so that
28391it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
28392with the TUI SingleKey mode. Once the command is entered the TUI
28393SingleKey mode is restored. The only way to permanently leave
7f9087cb 28394this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78 28395
11061048
TT
28396@cindex SingleKey keymap name
28397If @value{GDBN} was built with Readline 8.0 or later, the TUI
28398SingleKey keymap will be named @samp{SingleKey}. This can be used in
28399@file{.inputrc} to add additional bindings to this keymap.
7cf36c78 28400
8e04817f 28401@node TUI Commands
db2e3e2e 28402@section TUI-specific Commands
8e04817f
AC
28403@cindex TUI commands
28404
28405The TUI has specific commands to control the text windows.
46ba6afa
BW
28406These commands are always available, even when @value{GDBN} is not in
28407the TUI mode. When @value{GDBN} is in the standard mode, most
28408of these commands will automatically switch to the TUI mode.
c906108c 28409
ff12863f
PA
28410Note that if @value{GDBN}'s @code{stdout} is not connected to a
28411terminal, or @value{GDBN} has been started with the machine interface
28412interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
28413these commands will fail with an error, because it would not be
28414possible or desirable to enable curses window management.
28415
c906108c 28416@table @code
a4ea0946
AB
28417@item tui enable
28418@kindex tui enable
28419Activate TUI mode. The last active TUI window layout will be used if
760f7560 28420TUI mode has previously been used in the current debugging session,
a4ea0946
AB
28421otherwise a default layout is used.
28422
28423@item tui disable
28424@kindex tui disable
28425Disable TUI mode, returning to the console interpreter.
28426
3d757584
SC
28427@item info win
28428@kindex info win
28429List and give the size of all displayed windows.
28430
ee325b61
TT
28431@item tui new-layout @var{name} @var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}
28432@kindex tui new-layout
28433Create a new TUI layout. The new layout will be named @var{name}, and
28434can be accessed using the @code{layout} command (see below).
28435
7c043ba6
TT
28436Each @var{window} parameter is either the name of a window to display,
28437or a window description. The windows will be displayed from top to
28438bottom in the order listed.
28439
28440The names of the windows are the same as the ones given to the
ee325b61 28441@code{focus} command (see below); additional, the @code{status}
7c043ba6
TT
28442window can be specified. Note that, because it is of fixed height,
28443the weight assigned to the status window is of no importance. It is
28444conventional to use @samp{0} here.
28445
28446A window description looks a bit like an invocation of @code{tui
28447new-layout}, and is of the form
28448@{@r{[}@code{-horizontal}@r{]}@var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}@}.
28449
28450This specifies a sub-layout. If @code{-horizontal} is given, the
28451windows in this description will be arranged side-by-side, rather than
28452top-to-bottom.
ee325b61
TT
28453
28454Each @var{weight} is an integer. It is the weight of this window
28455relative to all the other windows in the layout. These numbers are
28456used to calculate how much of the screen is given to each window.
28457
28458For example:
28459
28460@example
28461(gdb) tui new-layout example src 1 regs 1 status 0 cmd 1
28462@end example
28463
28464Here, the new layout is called @samp{example}. It shows the source
28465and register windows, followed by the status window, and then finally
28466the command window. The non-status windows all have the same weight,
28467so the terminal will be split into three roughly equal sections.
28468
7c043ba6
TT
28469Here is a more complex example, showing a horizontal layout:
28470
28471@example
28472(gdb) tui new-layout example @{-horizontal src 1 asm 1@} 2 status 0 cmd 1
28473@end example
28474
28475This will result in side-by-side source and assembly windows; with the
28476status and command window being beneath these, filling the entire
28477width of the terminal. Because they have weight 2, the source and
28478assembly windows will be twice the height of the command window.
28479
6008fc5f 28480@item layout @var{name}
4644b6e3 28481@kindex layout
ee325b61
TT
28482Changes which TUI windows are displayed. The @var{name} parameter
28483controls which layout is shown. It can be either one of the built-in
28484layout names, or the name of a layout defined by the user using
28485@code{tui new-layout}.
28486
28487The built-in layouts are as follows:
6008fc5f
AB
28488
28489@table @code
28490@item next
8e04817f 28491Display the next layout.
2df3850c 28492
6008fc5f 28493@item prev
8e04817f 28494Display the previous layout.
c906108c 28495
6008fc5f
AB
28496@item src
28497Display the source and command windows.
c906108c 28498
6008fc5f
AB
28499@item asm
28500Display the assembly and command windows.
c906108c 28501
6008fc5f
AB
28502@item split
28503Display the source, assembly, and command windows.
c906108c 28504
6008fc5f
AB
28505@item regs
28506When in @code{src} layout display the register, source, and command
28507windows. When in @code{asm} or @code{split} layout display the
28508register, assembler, and command windows.
28509@end table
8e04817f 28510
6008fc5f 28511@item focus @var{name}
8e04817f 28512@kindex focus
6008fc5f
AB
28513Changes which TUI window is currently active for scrolling. The
28514@var{name} parameter can be any of the following:
28515
28516@table @code
28517@item next
46ba6afa
BW
28518Make the next window active for scrolling.
28519
6008fc5f 28520@item prev
46ba6afa
BW
28521Make the previous window active for scrolling.
28522
6008fc5f 28523@item src
46ba6afa
BW
28524Make the source window active for scrolling.
28525
6008fc5f 28526@item asm
46ba6afa
BW
28527Make the assembly window active for scrolling.
28528
6008fc5f 28529@item regs
46ba6afa
BW
28530Make the register window active for scrolling.
28531
6008fc5f 28532@item cmd
46ba6afa 28533Make the command window active for scrolling.
6008fc5f 28534@end table
c906108c 28535
8e04817f
AC
28536@item refresh
28537@kindex refresh
7f9087cb 28538Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 28539
51f0e40d 28540@item tui reg @var{group}
6a1b180d 28541@kindex tui reg
51f0e40d
AB
28542Changes the register group displayed in the tui register window to
28543@var{group}. If the register window is not currently displayed this
28544command will cause the register window to be displayed. The list of
28545register groups, as well as their order is target specific. The
28546following groups are available on most targets:
28547@table @code
28548@item next
28549Repeatedly selecting this group will cause the display to cycle
28550through all of the available register groups.
28551
28552@item prev
28553Repeatedly selecting this group will cause the display to cycle
28554through all of the available register groups in the reverse order to
28555@var{next}.
28556
28557@item general
28558Display the general registers.
28559@item float
28560Display the floating point registers.
28561@item system
28562Display the system registers.
28563@item vector
28564Display the vector registers.
28565@item all
28566Display all registers.
28567@end table
6a1b180d 28568
8e04817f
AC
28569@item update
28570@kindex update
28571Update the source window and the current execution point.
c906108c 28572
8e04817f
AC
28573@item winheight @var{name} +@var{count}
28574@itemx winheight @var{name} -@var{count}
28575@kindex winheight
28576Change the height of the window @var{name} by @var{count}
28577lines. Positive counts increase the height, while negative counts
bf555842
EZ
28578decrease it. The @var{name} parameter can be one of @code{src} (the
28579source window), @code{cmd} (the command window), @code{asm} (the
28580disassembly window), or @code{regs} (the register display window).
d6677607 28581@end table
2df3850c 28582
8e04817f 28583@node TUI Configuration
79a6e687 28584@section TUI Configuration Variables
8e04817f 28585@cindex TUI configuration variables
c906108c 28586
46ba6afa 28587Several configuration variables control the appearance of TUI windows.
c906108c 28588
8e04817f
AC
28589@table @code
28590@item set tui border-kind @var{kind}
28591@kindex set tui border-kind
28592Select the border appearance for the source, assembly and register windows.
28593The possible values are the following:
28594@table @code
28595@item space
28596Use a space character to draw the border.
c906108c 28597
8e04817f 28598@item ascii
46ba6afa 28599Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 28600
8e04817f
AC
28601@item acs
28602Use the Alternate Character Set to draw the border. The border is
28603drawn using character line graphics if the terminal supports them.
8e04817f 28604@end table
c78b4128 28605
8e04817f
AC
28606@item set tui border-mode @var{mode}
28607@kindex set tui border-mode
46ba6afa
BW
28608@itemx set tui active-border-mode @var{mode}
28609@kindex set tui active-border-mode
28610Select the display attributes for the borders of the inactive windows
28611or the active window. The @var{mode} can be one of the following:
8e04817f
AC
28612@table @code
28613@item normal
28614Use normal attributes to display the border.
c906108c 28615
8e04817f
AC
28616@item standout
28617Use standout mode.
c906108c 28618
8e04817f
AC
28619@item reverse
28620Use reverse video mode.
c906108c 28621
8e04817f
AC
28622@item half
28623Use half bright mode.
c906108c 28624
8e04817f
AC
28625@item half-standout
28626Use half bright and standout mode.
c906108c 28627
8e04817f
AC
28628@item bold
28629Use extra bright or bold mode.
c78b4128 28630
8e04817f
AC
28631@item bold-standout
28632Use extra bright or bold and standout mode.
8e04817f 28633@end table
7806cea7
TT
28634
28635@item set tui tab-width @var{nchars}
28636@kindex set tui tab-width
28637@kindex tabset
28638Set the width of tab stops to be @var{nchars} characters. This
28639setting affects the display of TAB characters in the source and
28640assembly windows.
d1da6b01
TT
28641
28642@item set tui compact-source @r{[}on@r{|}off@r{]}
28643@kindex set tui compact-source
28644Set whether the TUI source window is displayed in ``compact'' form.
28645The default display uses more space for line numbers and starts the
28646source text at the next tab stop; the compact display uses only as
28647much space as is needed for the line numbers in the current file, and
28648only a single space to separate the line numbers from the source.
7806cea7 28649@end table
c78b4128 28650
a2a7af0c
TT
28651Note that the colors of the TUI borders can be controlled using the
28652appropriate @code{set style} commands. @xref{Output Styling}.
28653
8e04817f
AC
28654@node Emacs
28655@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 28656
8e04817f
AC
28657@cindex Emacs
28658@cindex @sc{gnu} Emacs
28659A special interface allows you to use @sc{gnu} Emacs to view (and
28660edit) the source files for the program you are debugging with
28661@value{GDBN}.
c906108c 28662
8e04817f
AC
28663To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
28664executable file you want to debug as an argument. This command starts
28665@value{GDBN} as a subprocess of Emacs, with input and output through a newly
28666created Emacs buffer.
28667@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 28668
5e252a2e 28669Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 28670things:
c906108c 28671
8e04817f
AC
28672@itemize @bullet
28673@item
5e252a2e
NR
28674All ``terminal'' input and output goes through an Emacs buffer, called
28675the GUD buffer.
c906108c 28676
8e04817f
AC
28677This applies both to @value{GDBN} commands and their output, and to the input
28678and output done by the program you are debugging.
bf0184be 28679
8e04817f
AC
28680This is useful because it means that you can copy the text of previous
28681commands and input them again; you can even use parts of the output
28682in this way.
bf0184be 28683
8e04817f
AC
28684All the facilities of Emacs' Shell mode are available for interacting
28685with your program. In particular, you can send signals the usual
28686way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
28687stop.
bf0184be
ND
28688
28689@item
8e04817f 28690@value{GDBN} displays source code through Emacs.
bf0184be 28691
8e04817f
AC
28692Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
28693source file for that frame and puts an arrow (@samp{=>}) at the
28694left margin of the current line. Emacs uses a separate buffer for
28695source display, and splits the screen to show both your @value{GDBN} session
28696and the source.
bf0184be 28697
8e04817f
AC
28698Explicit @value{GDBN} @code{list} or search commands still produce output as
28699usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
28700@end itemize
28701
28702We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
28703a graphical mode, enabled by default, which provides further buffers
28704that can control the execution and describe the state of your program.
28705@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 28706
64fabec2
AC
28707If you specify an absolute file name when prompted for the @kbd{M-x
28708gdb} argument, then Emacs sets your current working directory to where
28709your program resides. If you only specify the file name, then Emacs
7a9dd1b2 28710sets your current working directory to the directory associated
64fabec2
AC
28711with the previous buffer. In this case, @value{GDBN} may find your
28712program by searching your environment's @code{PATH} variable, but on
28713some operating systems it might not find the source. So, although the
28714@value{GDBN} input and output session proceeds normally, the auxiliary
28715buffer does not display the current source and line of execution.
28716
28717The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
28718line of the GUD buffer and this serves as a default for the commands
28719that specify files for @value{GDBN} to operate on. @xref{Files,
28720,Commands to Specify Files}.
64fabec2
AC
28721
28722By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
28723need to call @value{GDBN} by a different name (for example, if you
28724keep several configurations around, with different names) you can
28725customize the Emacs variable @code{gud-gdb-command-name} to run the
28726one you want.
8e04817f 28727
5e252a2e 28728In the GUD buffer, you can use these special Emacs commands in
8e04817f 28729addition to the standard Shell mode commands:
c906108c 28730
8e04817f
AC
28731@table @kbd
28732@item C-h m
5e252a2e 28733Describe the features of Emacs' GUD Mode.
c906108c 28734
64fabec2 28735@item C-c C-s
8e04817f
AC
28736Execute to another source line, like the @value{GDBN} @code{step} command; also
28737update the display window to show the current file and location.
c906108c 28738
64fabec2 28739@item C-c C-n
8e04817f
AC
28740Execute to next source line in this function, skipping all function
28741calls, like the @value{GDBN} @code{next} command. Then update the display window
28742to show the current file and location.
c906108c 28743
64fabec2 28744@item C-c C-i
8e04817f
AC
28745Execute one instruction, like the @value{GDBN} @code{stepi} command; update
28746display window accordingly.
c906108c 28747
8e04817f
AC
28748@item C-c C-f
28749Execute until exit from the selected stack frame, like the @value{GDBN}
28750@code{finish} command.
c906108c 28751
64fabec2 28752@item C-c C-r
8e04817f
AC
28753Continue execution of your program, like the @value{GDBN} @code{continue}
28754command.
b433d00b 28755
64fabec2 28756@item C-c <
8e04817f
AC
28757Go up the number of frames indicated by the numeric argument
28758(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
28759like the @value{GDBN} @code{up} command.
b433d00b 28760
64fabec2 28761@item C-c >
8e04817f
AC
28762Go down the number of frames indicated by the numeric argument, like the
28763@value{GDBN} @code{down} command.
8e04817f 28764@end table
c906108c 28765
7f9087cb 28766In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 28767tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 28768
5e252a2e
NR
28769In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
28770separate frame which shows a backtrace when the GUD buffer is current.
28771Move point to any frame in the stack and type @key{RET} to make it
28772become the current frame and display the associated source in the
28773source buffer. Alternatively, click @kbd{Mouse-2} to make the
28774selected frame become the current one. In graphical mode, the
28775speedbar displays watch expressions.
64fabec2 28776
8e04817f
AC
28777If you accidentally delete the source-display buffer, an easy way to get
28778it back is to type the command @code{f} in the @value{GDBN} buffer, to
28779request a frame display; when you run under Emacs, this recreates
28780the source buffer if necessary to show you the context of the current
28781frame.
c906108c 28782
8e04817f
AC
28783The source files displayed in Emacs are in ordinary Emacs buffers
28784which are visiting the source files in the usual way. You can edit
28785the files with these buffers if you wish; but keep in mind that @value{GDBN}
28786communicates with Emacs in terms of line numbers. If you add or
28787delete lines from the text, the line numbers that @value{GDBN} knows cease
28788to correspond properly with the code.
b383017d 28789
5e252a2e
NR
28790A more detailed description of Emacs' interaction with @value{GDBN} is
28791given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
28792Emacs Manual}).
c906108c 28793
922fbb7b
AC
28794@node GDB/MI
28795@chapter The @sc{gdb/mi} Interface
28796
28797@unnumberedsec Function and Purpose
28798
28799@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
28800@sc{gdb/mi} is a line based machine oriented text interface to
28801@value{GDBN} and is activated by specifying using the
28802@option{--interpreter} command line option (@pxref{Mode Options}). It
28803is specifically intended to support the development of systems which
28804use the debugger as just one small component of a larger system.
922fbb7b
AC
28805
28806This chapter is a specification of the @sc{gdb/mi} interface. It is written
28807in the form of a reference manual.
28808
28809Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
28810features described below are incomplete and subject to change
28811(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
28812
28813@unnumberedsec Notation and Terminology
28814
28815@cindex notational conventions, for @sc{gdb/mi}
28816This chapter uses the following notation:
28817
28818@itemize @bullet
28819@item
28820@code{|} separates two alternatives.
28821
28822@item
28823@code{[ @var{something} ]} indicates that @var{something} is optional:
28824it may or may not be given.
28825
28826@item
28827@code{( @var{group} )*} means that @var{group} inside the parentheses
28828may repeat zero or more times.
28829
28830@item
28831@code{( @var{group} )+} means that @var{group} inside the parentheses
28832may repeat one or more times.
28833
28834@item
28835@code{"@var{string}"} means a literal @var{string}.
28836@end itemize
28837
28838@ignore
28839@heading Dependencies
28840@end ignore
28841
922fbb7b 28842@menu
c3b108f7 28843* GDB/MI General Design::
922fbb7b
AC
28844* GDB/MI Command Syntax::
28845* GDB/MI Compatibility with CLI::
af6eff6f 28846* GDB/MI Development and Front Ends::
922fbb7b 28847* GDB/MI Output Records::
ef21caaf 28848* GDB/MI Simple Examples::
922fbb7b 28849* GDB/MI Command Description Format::
ef21caaf 28850* GDB/MI Breakpoint Commands::
3fa7bf06 28851* GDB/MI Catchpoint Commands::
a2c02241
NR
28852* GDB/MI Program Context::
28853* GDB/MI Thread Commands::
5d77fe44 28854* GDB/MI Ada Tasking Commands::
a2c02241
NR
28855* GDB/MI Program Execution::
28856* GDB/MI Stack Manipulation::
28857* GDB/MI Variable Objects::
922fbb7b 28858* GDB/MI Data Manipulation::
a2c02241
NR
28859* GDB/MI Tracepoint Commands::
28860* GDB/MI Symbol Query::
351ff01a 28861* GDB/MI File Commands::
922fbb7b
AC
28862@ignore
28863* GDB/MI Kod Commands::
28864* GDB/MI Memory Overlay Commands::
28865* GDB/MI Signal Handling Commands::
28866@end ignore
922fbb7b 28867* GDB/MI Target Manipulation::
a6b151f1 28868* GDB/MI File Transfer Commands::
58d06528 28869* GDB/MI Ada Exceptions Commands::
d192b373 28870* GDB/MI Support Commands::
ef21caaf 28871* GDB/MI Miscellaneous Commands::
922fbb7b
AC
28872@end menu
28873
c3b108f7
VP
28874@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28875@node GDB/MI General Design
28876@section @sc{gdb/mi} General Design
28877@cindex GDB/MI General Design
28878
28879Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
28880parts---commands sent to @value{GDBN}, responses to those commands
28881and notifications. Each command results in exactly one response,
28882indicating either successful completion of the command, or an error.
28883For the commands that do not resume the target, the response contains the
28884requested information. For the commands that resume the target, the
28885response only indicates whether the target was successfully resumed.
28886Notifications is the mechanism for reporting changes in the state of the
28887target, or in @value{GDBN} state, that cannot conveniently be associated with
28888a command and reported as part of that command response.
28889
28890The important examples of notifications are:
28891@itemize @bullet
28892
28893@item
28894Exec notifications. These are used to report changes in
28895target state---when a target is resumed, or stopped. It would not
28896be feasible to include this information in response of resuming
28897commands, because one resume commands can result in multiple events in
28898different threads. Also, quite some time may pass before any event
28899happens in the target, while a frontend needs to know whether the resuming
28900command itself was successfully executed.
28901
28902@item
28903Console output, and status notifications. Console output
28904notifications are used to report output of CLI commands, as well as
28905diagnostics for other commands. Status notifications are used to
28906report the progress of a long-running operation. Naturally, including
28907this information in command response would mean no output is produced
28908until the command is finished, which is undesirable.
28909
28910@item
28911General notifications. Commands may have various side effects on
28912the @value{GDBN} or target state beyond their official purpose. For example,
28913a command may change the selected thread. Although such changes can
28914be included in command response, using notification allows for more
28915orthogonal frontend design.
28916
28917@end itemize
28918
28919There's no guarantee that whenever an MI command reports an error,
28920@value{GDBN} or the target are in any specific state, and especially,
28921the state is not reverted to the state before the MI command was
28922processed. Therefore, whenever an MI command results in an error,
28923we recommend that the frontend refreshes all the information shown in
28924the user interface.
28925
508094de
NR
28926
28927@menu
28928* Context management::
28929* Asynchronous and non-stop modes::
28930* Thread groups::
28931@end menu
28932
28933@node Context management
c3b108f7
VP
28934@subsection Context management
28935
403cb6b1
JB
28936@subsubsection Threads and Frames
28937
c3b108f7
VP
28938In most cases when @value{GDBN} accesses the target, this access is
28939done in context of a specific thread and frame (@pxref{Frames}).
28940Often, even when accessing global data, the target requires that a thread
28941be specified. The CLI interface maintains the selected thread and frame,
28942and supplies them to target on each command. This is convenient,
28943because a command line user would not want to specify that information
28944explicitly on each command, and because user interacts with
28945@value{GDBN} via a single terminal, so no confusion is possible as
28946to what thread and frame are the current ones.
28947
28948In the case of MI, the concept of selected thread and frame is less
28949useful. First, a frontend can easily remember this information
28950itself. Second, a graphical frontend can have more than one window,
28951each one used for debugging a different thread, and the frontend might
28952want to access additional threads for internal purposes. This
28953increases the risk that by relying on implicitly selected thread, the
28954frontend may be operating on a wrong one. Therefore, each MI command
28955should explicitly specify which thread and frame to operate on. To
28956make it possible, each MI command accepts the @samp{--thread} and
5d5658a1
PA
28957@samp{--frame} options, the value to each is @value{GDBN} global
28958identifier for thread and frame to operate on.
c3b108f7
VP
28959
28960Usually, each top-level window in a frontend allows the user to select
28961a thread and a frame, and remembers the user selection for further
28962operations. However, in some cases @value{GDBN} may suggest that the
4034d0ff
AT
28963current thread or frame be changed. For example, when stopping on a
28964breakpoint it is reasonable to switch to the thread where breakpoint is
28965hit. For another example, if the user issues the CLI @samp{thread} or
28966@samp{frame} commands via the frontend, it is desirable to change the
28967frontend's selection to the one specified by user. @value{GDBN}
28968communicates the suggestion to change current thread and frame using the
28969@samp{=thread-selected} notification.
c3b108f7
VP
28970
28971Note that historically, MI shares the selected thread with CLI, so
28972frontends used the @code{-thread-select} to execute commands in the
28973right context. However, getting this to work right is cumbersome. The
28974simplest way is for frontend to emit @code{-thread-select} command
28975before every command. This doubles the number of commands that need
28976to be sent. The alternative approach is to suppress @code{-thread-select}
28977if the selected thread in @value{GDBN} is supposed to be identical to the
28978thread the frontend wants to operate on. However, getting this
28979optimization right can be tricky. In particular, if the frontend
28980sends several commands to @value{GDBN}, and one of the commands changes the
28981selected thread, then the behaviour of subsequent commands will
28982change. So, a frontend should either wait for response from such
28983problematic commands, or explicitly add @code{-thread-select} for
28984all subsequent commands. No frontend is known to do this exactly
28985right, so it is suggested to just always pass the @samp{--thread} and
28986@samp{--frame} options.
28987
403cb6b1
JB
28988@subsubsection Language
28989
28990The execution of several commands depends on which language is selected.
28991By default, the current language (@pxref{show language}) is used.
28992But for commands known to be language-sensitive, it is recommended
28993to use the @samp{--language} option. This option takes one argument,
28994which is the name of the language to use while executing the command.
28995For instance:
28996
28997@smallexample
28998-data-evaluate-expression --language c "sizeof (void*)"
28999^done,value="4"
29000(gdb)
29001@end smallexample
29002
29003The valid language names are the same names accepted by the
29004@samp{set language} command (@pxref{Manually}), excluding @samp{auto},
29005@samp{local} or @samp{unknown}.
29006
508094de 29007@node Asynchronous and non-stop modes
c3b108f7
VP
29008@subsection Asynchronous command execution and non-stop mode
29009
29010On some targets, @value{GDBN} is capable of processing MI commands
29011even while the target is running. This is called @dfn{asynchronous
29012command execution} (@pxref{Background Execution}). The frontend may
6b92c0d3 29013specify a preference for asynchronous execution using the
329ea579 29014@code{-gdb-set mi-async 1} command, which should be emitted before
c3b108f7
VP
29015either running the executable or attaching to the target. After the
29016frontend has started the executable or attached to the target, it can
29017find if asynchronous execution is enabled using the
29018@code{-list-target-features} command.
29019
329ea579
PA
29020@table @code
29021@item -gdb-set mi-async on
29022@item -gdb-set mi-async off
29023Set whether MI is in asynchronous mode.
29024
29025When @code{off}, which is the default, MI execution commands (e.g.,
29026@code{-exec-continue}) are foreground commands, and @value{GDBN} waits
29027for the program to stop before processing further commands.
29028
29029When @code{on}, MI execution commands are background execution
29030commands (e.g., @code{-exec-continue} becomes the equivalent of the
29031@code{c&} CLI command), and so @value{GDBN} is capable of processing
29032MI commands even while the target is running.
29033
29034@item -gdb-show mi-async
29035Show whether MI asynchronous mode is enabled.
29036@end table
29037
29038Note: In @value{GDBN} version 7.7 and earlier, this option was called
29039@code{target-async} instead of @code{mi-async}, and it had the effect
29040of both putting MI in asynchronous mode and making CLI background
29041commands possible. CLI background commands are now always possible
29042``out of the box'' if the target supports them. The old spelling is
29043kept as a deprecated alias for backwards compatibility.
29044
c3b108f7
VP
29045Even if @value{GDBN} can accept a command while target is running,
29046many commands that access the target do not work when the target is
29047running. Therefore, asynchronous command execution is most useful
29048when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
29049it is possible to examine the state of one thread, while other threads
29050are running.
29051
29052When a given thread is running, MI commands that try to access the
29053target in the context of that thread may not work, or may work only on
29054some targets. In particular, commands that try to operate on thread's
29055stack will not work, on any target. Commands that read memory, or
29056modify breakpoints, may work or not work, depending on the target. Note
29057that even commands that operate on global state, such as @code{print},
29058@code{set}, and breakpoint commands, still access the target in the
29059context of a specific thread, so frontend should try to find a
29060stopped thread and perform the operation on that thread (using the
29061@samp{--thread} option).
29062
29063Which commands will work in the context of a running thread is
29064highly target dependent. However, the two commands
29065@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
29066to find the state of a thread, will always work.
29067
508094de 29068@node Thread groups
c3b108f7
VP
29069@subsection Thread groups
29070@value{GDBN} may be used to debug several processes at the same time.
6b92c0d3 29071On some platforms, @value{GDBN} may support debugging of several
c3b108f7
VP
29072hardware systems, each one having several cores with several different
29073processes running on each core. This section describes the MI
29074mechanism to support such debugging scenarios.
29075
29076The key observation is that regardless of the structure of the
29077target, MI can have a global list of threads, because most commands that
29078accept the @samp{--thread} option do not need to know what process that
29079thread belongs to. Therefore, it is not necessary to introduce
29080neither additional @samp{--process} option, nor an notion of the
29081current process in the MI interface. The only strictly new feature
29082that is required is the ability to find how the threads are grouped
29083into processes.
29084
29085To allow the user to discover such grouping, and to support arbitrary
29086hierarchy of machines/cores/processes, MI introduces the concept of a
29087@dfn{thread group}. Thread group is a collection of threads and other
29088thread groups. A thread group always has a string identifier, a type,
29089and may have additional attributes specific to the type. A new
29090command, @code{-list-thread-groups}, returns the list of top-level
29091thread groups, which correspond to processes that @value{GDBN} is
29092debugging at the moment. By passing an identifier of a thread group
29093to the @code{-list-thread-groups} command, it is possible to obtain
29094the members of specific thread group.
29095
29096To allow the user to easily discover processes, and other objects, he
29097wishes to debug, a concept of @dfn{available thread group} is
29098introduced. Available thread group is an thread group that
29099@value{GDBN} is not debugging, but that can be attached to, using the
29100@code{-target-attach} command. The list of available top-level thread
29101groups can be obtained using @samp{-list-thread-groups --available}.
29102In general, the content of a thread group may be only retrieved only
29103after attaching to that thread group.
29104
65c574f6 29105Thread groups are related to inferiors (@pxref{Inferiors Connections and
a79b8f6e
VP
29106Programs}). Each inferior corresponds to a thread group of a special
29107type @samp{process}, and some additional operations are permitted on
29108such thread groups.
29109
922fbb7b
AC
29110@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29111@node GDB/MI Command Syntax
29112@section @sc{gdb/mi} Command Syntax
29113
29114@menu
29115* GDB/MI Input Syntax::
29116* GDB/MI Output Syntax::
922fbb7b
AC
29117@end menu
29118
29119@node GDB/MI Input Syntax
29120@subsection @sc{gdb/mi} Input Syntax
29121
29122@cindex input syntax for @sc{gdb/mi}
29123@cindex @sc{gdb/mi}, input syntax
29124@table @code
29125@item @var{command} @expansion{}
29126@code{@var{cli-command} | @var{mi-command}}
29127
29128@item @var{cli-command} @expansion{}
29129@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
29130@var{cli-command} is any existing @value{GDBN} CLI command.
29131
29132@item @var{mi-command} @expansion{}
29133@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
29134@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
29135
29136@item @var{token} @expansion{}
29137"any sequence of digits"
29138
29139@item @var{option} @expansion{}
29140@code{"-" @var{parameter} [ " " @var{parameter} ]}
29141
29142@item @var{parameter} @expansion{}
29143@code{@var{non-blank-sequence} | @var{c-string}}
29144
29145@item @var{operation} @expansion{}
29146@emph{any of the operations described in this chapter}
29147
29148@item @var{non-blank-sequence} @expansion{}
29149@emph{anything, provided it doesn't contain special characters such as
29150"-", @var{nl}, """ and of course " "}
29151
29152@item @var{c-string} @expansion{}
29153@code{""" @var{seven-bit-iso-c-string-content} """}
29154
29155@item @var{nl} @expansion{}
29156@code{CR | CR-LF}
29157@end table
29158
29159@noindent
29160Notes:
29161
29162@itemize @bullet
29163@item
29164The CLI commands are still handled by the @sc{mi} interpreter; their
29165output is described below.
29166
29167@item
29168The @code{@var{token}}, when present, is passed back when the command
29169finishes.
29170
29171@item
29172Some @sc{mi} commands accept optional arguments as part of the parameter
29173list. Each option is identified by a leading @samp{-} (dash) and may be
29174followed by an optional argument parameter. Options occur first in the
29175parameter list and can be delimited from normal parameters using
29176@samp{--} (this is useful when some parameters begin with a dash).
29177@end itemize
29178
29179Pragmatics:
29180
29181@itemize @bullet
29182@item
29183We want easy access to the existing CLI syntax (for debugging).
29184
29185@item
29186We want it to be easy to spot a @sc{mi} operation.
29187@end itemize
29188
29189@node GDB/MI Output Syntax
29190@subsection @sc{gdb/mi} Output Syntax
29191
29192@cindex output syntax of @sc{gdb/mi}
29193@cindex @sc{gdb/mi}, output syntax
29194The output from @sc{gdb/mi} consists of zero or more out-of-band records
29195followed, optionally, by a single result record. This result record
29196is for the most recent command. The sequence of output records is
594fe323 29197terminated by @samp{(gdb)}.
922fbb7b
AC
29198
29199If an input command was prefixed with a @code{@var{token}} then the
29200corresponding output for that command will also be prefixed by that same
29201@var{token}.
29202
29203@table @code
29204@item @var{output} @expansion{}
594fe323 29205@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
29206
29207@item @var{result-record} @expansion{}
29208@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
29209
29210@item @var{out-of-band-record} @expansion{}
29211@code{@var{async-record} | @var{stream-record}}
29212
29213@item @var{async-record} @expansion{}
29214@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
29215
29216@item @var{exec-async-output} @expansion{}
dcf106f3 29217@code{[ @var{token} ] "*" @var{async-output nl}}
922fbb7b
AC
29218
29219@item @var{status-async-output} @expansion{}
dcf106f3 29220@code{[ @var{token} ] "+" @var{async-output nl}}
922fbb7b
AC
29221
29222@item @var{notify-async-output} @expansion{}
dcf106f3 29223@code{[ @var{token} ] "=" @var{async-output nl}}
922fbb7b
AC
29224
29225@item @var{async-output} @expansion{}
dcf106f3 29226@code{@var{async-class} ( "," @var{result} )*}
922fbb7b
AC
29227
29228@item @var{result-class} @expansion{}
29229@code{"done" | "running" | "connected" | "error" | "exit"}
29230
29231@item @var{async-class} @expansion{}
29232@code{"stopped" | @var{others}} (where @var{others} will be added
29233depending on the needs---this is still in development).
29234
29235@item @var{result} @expansion{}
29236@code{ @var{variable} "=" @var{value}}
29237
29238@item @var{variable} @expansion{}
29239@code{ @var{string} }
29240
29241@item @var{value} @expansion{}
29242@code{ @var{const} | @var{tuple} | @var{list} }
29243
29244@item @var{const} @expansion{}
29245@code{@var{c-string}}
29246
29247@item @var{tuple} @expansion{}
29248@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
29249
29250@item @var{list} @expansion{}
29251@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
29252@var{result} ( "," @var{result} )* "]" }
29253
29254@item @var{stream-record} @expansion{}
29255@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
29256
29257@item @var{console-stream-output} @expansion{}
dcf106f3 29258@code{"~" @var{c-string nl}}
922fbb7b
AC
29259
29260@item @var{target-stream-output} @expansion{}
dcf106f3 29261@code{"@@" @var{c-string nl}}
922fbb7b
AC
29262
29263@item @var{log-stream-output} @expansion{}
dcf106f3 29264@code{"&" @var{c-string nl}}
922fbb7b
AC
29265
29266@item @var{nl} @expansion{}
29267@code{CR | CR-LF}
29268
29269@item @var{token} @expansion{}
29270@emph{any sequence of digits}.
29271@end table
29272
29273@noindent
29274Notes:
29275
29276@itemize @bullet
29277@item
29278All output sequences end in a single line containing a period.
29279
29280@item
721c02de
VP
29281The @code{@var{token}} is from the corresponding request. Note that
29282for all async output, while the token is allowed by the grammar and
29283may be output by future versions of @value{GDBN} for select async
29284output messages, it is generally omitted. Frontends should treat
29285all async output as reporting general changes in the state of the
29286target and there should be no need to associate async output to any
29287prior command.
922fbb7b
AC
29288
29289@item
29290@cindex status output in @sc{gdb/mi}
29291@var{status-async-output} contains on-going status information about the
29292progress of a slow operation. It can be discarded. All status output is
29293prefixed by @samp{+}.
29294
29295@item
29296@cindex async output in @sc{gdb/mi}
29297@var{exec-async-output} contains asynchronous state change on the target
29298(stopped, started, disappeared). All async output is prefixed by
29299@samp{*}.
29300
29301@item
29302@cindex notify output in @sc{gdb/mi}
29303@var{notify-async-output} contains supplementary information that the
29304client should handle (e.g., a new breakpoint information). All notify
29305output is prefixed by @samp{=}.
29306
29307@item
29308@cindex console output in @sc{gdb/mi}
29309@var{console-stream-output} is output that should be displayed as is in the
29310console. It is the textual response to a CLI command. All the console
29311output is prefixed by @samp{~}.
29312
29313@item
29314@cindex target output in @sc{gdb/mi}
29315@var{target-stream-output} is the output produced by the target program.
29316All the target output is prefixed by @samp{@@}.
29317
29318@item
29319@cindex log output in @sc{gdb/mi}
29320@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
29321instance messages that should be displayed as part of an error log. All
29322the log output is prefixed by @samp{&}.
29323
29324@item
29325@cindex list output in @sc{gdb/mi}
29326New @sc{gdb/mi} commands should only output @var{lists} containing
29327@var{values}.
29328
29329
29330@end itemize
29331
29332@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
29333details about the various output records.
29334
922fbb7b
AC
29335@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29336@node GDB/MI Compatibility with CLI
29337@section @sc{gdb/mi} Compatibility with CLI
29338
29339@cindex compatibility, @sc{gdb/mi} and CLI
29340@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 29341
a2c02241
NR
29342For the developers convenience CLI commands can be entered directly,
29343but there may be some unexpected behaviour. For example, commands
29344that query the user will behave as if the user replied yes, breakpoint
29345command lists are not executed and some CLI commands, such as
29346@code{if}, @code{when} and @code{define}, prompt for further input with
29347@samp{>}, which is not valid MI output.
ef21caaf
NR
29348
29349This feature may be removed at some stage in the future and it is
a2c02241
NR
29350recommended that front ends use the @code{-interpreter-exec} command
29351(@pxref{-interpreter-exec}).
922fbb7b 29352
af6eff6f
NR
29353@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29354@node GDB/MI Development and Front Ends
29355@section @sc{gdb/mi} Development and Front Ends
29356@cindex @sc{gdb/mi} development
29357
29358The application which takes the MI output and presents the state of the
29359program being debugged to the user is called a @dfn{front end}.
29360
1fea0d53
SM
29361Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
29362to the MI interface may break existing usage. This section describes how the
29363protocol changes and how to request previous version of the protocol when it
29364does.
af6eff6f
NR
29365
29366Some changes in MI need not break a carefully designed front end, and
29367for these the MI version will remain unchanged. The following is a
29368list of changes that may occur within one level, so front ends should
29369parse MI output in a way that can handle them:
29370
29371@itemize @bullet
29372@item
29373New MI commands may be added.
29374
29375@item
29376New fields may be added to the output of any MI command.
29377
36ece8b3
NR
29378@item
29379The range of values for fields with specified values, e.g.,
9f708cb2 29380@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 29381
af6eff6f
NR
29382@c The format of field's content e.g type prefix, may change so parse it
29383@c at your own risk. Yes, in general?
29384
29385@c The order of fields may change? Shouldn't really matter but it might
29386@c resolve inconsistencies.
29387@end itemize
29388
29389If the changes are likely to break front ends, the MI version level
1fea0d53
SM
29390will be increased by one. The new versions of the MI protocol are not compatible
29391with the old versions. Old versions of MI remain available, allowing front ends
29392to keep using them until they are modified to use the latest MI version.
af6eff6f 29393
1fea0d53
SM
29394Since @code{--interpreter=mi} always points to the latest MI version, it is
29395recommended that front ends request a specific version of MI when launching
29396@value{GDBN} (e.g. @code{--interpreter=mi2}) to make sure they get an
29397interpreter with the MI version they expect.
29398
09f2921c 29399The following table gives a summary of the released versions of the MI
1fea0d53
SM
29400interface: the version number, the version of GDB in which it first appeared
29401and the breaking changes compared to the previous version.
29402
29403@multitable @columnfractions .05 .05 .9
29404@headitem MI version @tab GDB version @tab Breaking changes
29405
29406@item
29407@center 1
29408@tab
29409@center 5.1
29410@tab
29411None
29412
29413@item
29414@center 2
29415@tab
29416@center 6.0
29417@tab
29418
29419@itemize
29420@item
29421The @code{-environment-pwd}, @code{-environment-directory} and
29422@code{-environment-path} commands now returns values using the MI output
29423syntax, rather than CLI output syntax.
29424
29425@item
29426@code{-var-list-children}'s @code{children} result field is now a list, rather
29427than a tuple.
29428
29429@item
29430@code{-var-update}'s @code{changelist} result field is now a list, rather than
29431a tuple.
29432@end itemize
29433
b4be1b06
SM
29434@item
29435@center 3
29436@tab
29437@center 9.1
29438@tab
29439
29440@itemize
29441@item
29442The output of information about multi-location breakpoints has changed in the
29443responses to the @code{-break-insert} and @code{-break-info} commands, as well
29444as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
29445The multiple locations are now placed in a @code{locations} field, whose value
29446is a list.
29447@end itemize
29448
1fea0d53 29449@end multitable
af6eff6f 29450
b4be1b06
SM
29451If your front end cannot yet migrate to a more recent version of the
29452MI protocol, you can nevertheless selectively enable specific features
29453available in those recent MI versions, using the following commands:
29454
29455@table @code
29456
29457@item -fix-multi-location-breakpoint-output
29458Use the output for multi-location breakpoints which was introduced by
29459MI 3, even when using MI versions 2 or 1. This command has no
29460effect when using MI version 3 or later.
29461
5c85e20d 29462@end table
b4be1b06 29463
af6eff6f
NR
29464The best way to avoid unexpected changes in MI that might break your front
29465end is to make your project known to @value{GDBN} developers and
7a9a6b69 29466follow development on @email{gdb@@sourceware.org} and
fa0f268d 29467@email{gdb-patches@@sourceware.org}.
af6eff6f
NR
29468@cindex mailing lists
29469
922fbb7b
AC
29470@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29471@node GDB/MI Output Records
29472@section @sc{gdb/mi} Output Records
29473
29474@menu
29475* GDB/MI Result Records::
29476* GDB/MI Stream Records::
82f68b1c 29477* GDB/MI Async Records::
54516a0b 29478* GDB/MI Breakpoint Information::
c3b108f7 29479* GDB/MI Frame Information::
dc146f7c 29480* GDB/MI Thread Information::
4368ebeb 29481* GDB/MI Ada Exception Information::
922fbb7b
AC
29482@end menu
29483
29484@node GDB/MI Result Records
29485@subsection @sc{gdb/mi} Result Records
29486
29487@cindex result records in @sc{gdb/mi}
29488@cindex @sc{gdb/mi}, result records
29489In addition to a number of out-of-band notifications, the response to a
29490@sc{gdb/mi} command includes one of the following result indications:
29491
29492@table @code
29493@findex ^done
29494@item "^done" [ "," @var{results} ]
29495The synchronous operation was successful, @code{@var{results}} are the return
29496values.
29497
29498@item "^running"
29499@findex ^running
8e9c5e02
VP
29500This result record is equivalent to @samp{^done}. Historically, it
29501was output instead of @samp{^done} if the command has resumed the
29502target. This behaviour is maintained for backward compatibility, but
29503all frontends should treat @samp{^done} and @samp{^running}
29504identically and rely on the @samp{*running} output record to determine
29505which threads are resumed.
922fbb7b 29506
ef21caaf
NR
29507@item "^connected"
29508@findex ^connected
3f94c067 29509@value{GDBN} has connected to a remote target.
ef21caaf 29510
2ea126fa 29511@item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
922fbb7b 29512@findex ^error
2ea126fa
JB
29513The operation failed. The @code{msg=@var{c-string}} variable contains
29514the corresponding error message.
29515
29516If present, the @code{code=@var{c-string}} variable provides an error
29517code on which consumers can rely on to detect the corresponding
29518error condition. At present, only one error code is defined:
29519
29520@table @samp
29521@item "undefined-command"
29522Indicates that the command causing the error does not exist.
29523@end table
ef21caaf
NR
29524
29525@item "^exit"
29526@findex ^exit
3f94c067 29527@value{GDBN} has terminated.
ef21caaf 29528
922fbb7b
AC
29529@end table
29530
29531@node GDB/MI Stream Records
29532@subsection @sc{gdb/mi} Stream Records
29533
29534@cindex @sc{gdb/mi}, stream records
29535@cindex stream records in @sc{gdb/mi}
29536@value{GDBN} internally maintains a number of output streams: the console, the
29537target, and the log. The output intended for each of these streams is
29538funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
29539
29540Each stream record begins with a unique @dfn{prefix character} which
29541identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
29542Syntax}). In addition to the prefix, each stream record contains a
29543@code{@var{string-output}}. This is either raw text (with an implicit new
29544line) or a quoted C string (which does not contain an implicit newline).
29545
29546@table @code
29547@item "~" @var{string-output}
29548The console output stream contains text that should be displayed in the
29549CLI console window. It contains the textual responses to CLI commands.
29550
29551@item "@@" @var{string-output}
29552The target output stream contains any textual output from the running
ef21caaf
NR
29553target. This is only present when GDB's event loop is truly
29554asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
29555
29556@item "&" @var{string-output}
29557The log stream contains debugging messages being produced by @value{GDBN}'s
29558internals.
29559@end table
29560
82f68b1c
VP
29561@node GDB/MI Async Records
29562@subsection @sc{gdb/mi} Async Records
922fbb7b 29563
82f68b1c
VP
29564@cindex async records in @sc{gdb/mi}
29565@cindex @sc{gdb/mi}, async records
29566@dfn{Async} records are used to notify the @sc{gdb/mi} client of
922fbb7b 29567additional changes that have occurred. Those changes can either be a
82f68b1c 29568consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
922fbb7b
AC
29569target activity (e.g., target stopped).
29570
8eb41542 29571The following is the list of possible async records:
922fbb7b
AC
29572
29573@table @code
034dad6f 29574
e1ac3328 29575@item *running,thread-id="@var{thread}"
5d5658a1 29576The target is now running. The @var{thread} field can be the global
09f2921c 29577thread ID of the thread that is now running, and it can be
5d5658a1
PA
29578@samp{all} if all threads are running. The frontend should assume
29579that no interaction with a running thread is possible after this
29580notification is produced. The frontend should not assume that this
29581notification is output only once for any command. @value{GDBN} may
29582emit this notification several times, either for different threads,
29583because it cannot resume all threads together, or even for a single
29584thread, if the thread must be stepped though some code before letting
29585it run freely.
e1ac3328 29586
dc146f7c 29587@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
82f68b1c
VP
29588The target has stopped. The @var{reason} field can have one of the
29589following values:
034dad6f
BR
29590
29591@table @code
29592@item breakpoint-hit
29593A breakpoint was reached.
29594@item watchpoint-trigger
29595A watchpoint was triggered.
29596@item read-watchpoint-trigger
29597A read watchpoint was triggered.
29598@item access-watchpoint-trigger
29599An access watchpoint was triggered.
29600@item function-finished
29601An -exec-finish or similar CLI command was accomplished.
29602@item location-reached
29603An -exec-until or similar CLI command was accomplished.
29604@item watchpoint-scope
29605A watchpoint has gone out of scope.
29606@item end-stepping-range
29607An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
29608similar CLI command was accomplished.
29609@item exited-signalled
29610The inferior exited because of a signal.
29611@item exited
29612The inferior exited.
29613@item exited-normally
29614The inferior exited normally.
29615@item signal-received
29616A signal was received by the inferior.
36dfb11c
TT
29617@item solib-event
29618The inferior has stopped due to a library being loaded or unloaded.
edcc5120
TT
29619This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
29620set or when a @code{catch load} or @code{catch unload} catchpoint is
29621in use (@pxref{Set Catchpoints}).
36dfb11c
TT
29622@item fork
29623The inferior has forked. This is reported when @code{catch fork}
29624(@pxref{Set Catchpoints}) has been used.
29625@item vfork
29626The inferior has vforked. This is reported in when @code{catch vfork}
29627(@pxref{Set Catchpoints}) has been used.
29628@item syscall-entry
29629The inferior entered a system call. This is reported when @code{catch
29630syscall} (@pxref{Set Catchpoints}) has been used.
a64c9f7b 29631@item syscall-return
36dfb11c
TT
29632The inferior returned from a system call. This is reported when
29633@code{catch syscall} (@pxref{Set Catchpoints}) has been used.
29634@item exec
29635The inferior called @code{exec}. This is reported when @code{catch exec}
29636(@pxref{Set Catchpoints}) has been used.
922fbb7b
AC
29637@end table
29638
5d5658a1
PA
29639The @var{id} field identifies the global thread ID of the thread
29640that directly caused the stop -- for example by hitting a breakpoint.
29641Depending on whether all-stop
c3b108f7
VP
29642mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
29643stop all threads, or only the thread that directly triggered the stop.
29644If all threads are stopped, the @var{stopped} field will have the
29645value of @code{"all"}. Otherwise, the value of the @var{stopped}
29646field will be a list of thread identifiers. Presently, this list will
29647always include a single thread, but frontend should be prepared to see
dc146f7c
VP
29648several threads in the list. The @var{core} field reports the
29649processor core on which the stop event has happened. This field may be absent
29650if such information is not available.
c3b108f7 29651
a79b8f6e
VP
29652@item =thread-group-added,id="@var{id}"
29653@itemx =thread-group-removed,id="@var{id}"
29654A thread group was either added or removed. The @var{id} field
29655contains the @value{GDBN} identifier of the thread group. When a thread
29656group is added, it generally might not be associated with a running
29657process. When a thread group is removed, its id becomes invalid and
29658cannot be used in any way.
29659
29660@item =thread-group-started,id="@var{id}",pid="@var{pid}"
29661A thread group became associated with a running program,
29662either because the program was just started or the thread group
29663was attached to a program. The @var{id} field contains the
29664@value{GDBN} identifier of the thread group. The @var{pid} field
29665contains process identifier, specific to the operating system.
29666
8cf64490 29667@item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
a79b8f6e
VP
29668A thread group is no longer associated with a running program,
29669either because the program has exited, or because it was detached
c3b108f7 29670from. The @var{id} field contains the @value{GDBN} identifier of the
697aa1b7 29671thread group. The @var{code} field is the exit code of the inferior; it exists
8cf64490 29672only when the inferior exited with some code.
c3b108f7
VP
29673
29674@item =thread-created,id="@var{id}",group-id="@var{gid}"
29675@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
82f68b1c 29676A thread either was created, or has exited. The @var{id} field
5d5658a1 29677contains the global @value{GDBN} identifier of the thread. The @var{gid}
c3b108f7 29678field identifies the thread group this thread belongs to.
66bb093b 29679
4034d0ff
AT
29680@item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
29681Informs that the selected thread or frame were changed. This notification
29682is not emitted as result of the @code{-thread-select} or
29683@code{-stack-select-frame} commands, but is emitted whenever an MI command
29684that is not documented to change the selected thread and frame actually
29685changes them. In particular, invoking, directly or indirectly
29686(via user-defined command), the CLI @code{thread} or @code{frame} commands,
29687will generate this notification. Changing the thread or frame from another
29688user interface (see @ref{Interpreters}) will also generate this notification.
29689
29690The @var{frame} field is only present if the newly selected thread is
29691stopped. See @ref{GDB/MI Frame Information} for the format of its value.
66bb093b
VP
29692
29693We suggest that in response to this notification, front ends
29694highlight the selected thread and cause subsequent commands to apply to
29695that thread.
29696
c86cf029
VP
29697@item =library-loaded,...
29698Reports that a new library file was loaded by the program. This
51457a05
MAL
29699notification has 5 fields---@var{id}, @var{target-name},
29700@var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
c86cf029
VP
29701opaque identifier of the library. For remote debugging case,
29702@var{target-name} and @var{host-name} fields give the name of the
134eb42c
VP
29703library file on the target, and on the host respectively. For native
29704debugging, both those fields have the same value. The
f1cbe1d3
TT
29705@var{symbols-loaded} field is emitted only for backward compatibility
29706and should not be relied on to convey any useful information. The
29707@var{thread-group} field, if present, specifies the id of the thread
29708group in whose context the library was loaded. If the field is
29709absent, it means the library was loaded in the context of all present
51457a05
MAL
29710thread groups. The @var{ranges} field specifies the ranges of addresses belonging
29711to this library.
c86cf029
VP
29712
29713@item =library-unloaded,...
134eb42c 29714Reports that a library was unloaded by the program. This notification
c86cf029 29715has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
a79b8f6e
VP
29716the same meaning as for the @code{=library-loaded} notification.
29717The @var{thread-group} field, if present, specifies the id of the
29718thread group in whose context the library was unloaded. If the field is
29719absent, it means the library was unloaded in the context of all present
29720thread groups.
c86cf029 29721
201b4506
YQ
29722@item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
29723@itemx =traceframe-changed,end
29724Reports that the trace frame was changed and its new number is
29725@var{tfnum}. The number of the tracepoint associated with this trace
29726frame is @var{tpnum}.
29727
134a2066 29728@item =tsv-created,name=@var{name},initial=@var{initial}
bb25a15c 29729Reports that the new trace state variable @var{name} is created with
134a2066 29730initial value @var{initial}.
bb25a15c
YQ
29731
29732@item =tsv-deleted,name=@var{name}
29733@itemx =tsv-deleted
29734Reports that the trace state variable @var{name} is deleted or all
29735trace state variables are deleted.
29736
134a2066
YQ
29737@item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
29738Reports that the trace state variable @var{name} is modified with
29739the initial value @var{initial}. The current value @var{current} of
29740trace state variable is optional and is reported if the current
29741value of trace state variable is known.
29742
8d3788bd
VP
29743@item =breakpoint-created,bkpt=@{...@}
29744@itemx =breakpoint-modified,bkpt=@{...@}
d9f08f52 29745@itemx =breakpoint-deleted,id=@var{number}
8d3788bd
VP
29746Reports that a breakpoint was created, modified, or deleted,
29747respectively. Only user-visible breakpoints are reported to the MI
29748user.
29749
29750The @var{bkpt} argument is of the same form as returned by the various
d9f08f52
YQ
29751breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
29752@var{number} is the ordinal number of the breakpoint.
8d3788bd
VP
29753
29754Note that if a breakpoint is emitted in the result record of a
29755command, then it will not also be emitted in an async record.
29756
38b022b4 29757@item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
82a90ccf
YQ
29758@itemx =record-stopped,thread-group="@var{id}"
29759Execution log recording was either started or stopped on an
29760inferior. The @var{id} is the @value{GDBN} identifier of the thread
29761group corresponding to the affected inferior.
29762
38b022b4
SM
29763The @var{method} field indicates the method used to record execution. If the
29764method in use supports multiple recording formats, @var{format} will be present
8504e097 29765and contain the currently used format. @xref{Process Record and Replay},
38b022b4
SM
29766for existing method and format values.
29767
5b9afe8a
YQ
29768@item =cmd-param-changed,param=@var{param},value=@var{value}
29769Reports that a parameter of the command @code{set @var{param}} is
29770changed to @var{value}. In the multi-word @code{set} command,
29771the @var{param} is the whole parameter list to @code{set} command.
29772For example, In command @code{set check type on}, @var{param}
29773is @code{check type} and @var{value} is @code{on}.
8de0566d
YQ
29774
29775@item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
29776Reports that bytes from @var{addr} to @var{data} + @var{len} were
29777written in an inferior. The @var{id} is the identifier of the
29778thread group corresponding to the affected inferior. The optional
29779@code{type="code"} part is reported if the memory written to holds
29780executable code.
82f68b1c
VP
29781@end table
29782
54516a0b
TT
29783@node GDB/MI Breakpoint Information
29784@subsection @sc{gdb/mi} Breakpoint Information
29785
29786When @value{GDBN} reports information about a breakpoint, a
29787tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
29788following fields:
29789
29790@table @code
29791@item number
b4be1b06 29792The breakpoint number.
54516a0b
TT
29793
29794@item type
29795The type of the breakpoint. For ordinary breakpoints this will be
29796@samp{breakpoint}, but many values are possible.
29797
8ac3646f
TT
29798@item catch-type
29799If the type of the breakpoint is @samp{catchpoint}, then this
29800indicates the exact type of catchpoint.
29801
54516a0b
TT
29802@item disp
29803This is the breakpoint disposition---either @samp{del}, meaning that
29804the breakpoint will be deleted at the next stop, or @samp{keep},
29805meaning that the breakpoint will not be deleted.
29806
29807@item enabled
29808This indicates whether the breakpoint is enabled, in which case the
29809value is @samp{y}, or disabled, in which case the value is @samp{n}.
29810Note that this is not the same as the field @code{enable}.
29811
29812@item addr
29813The address of the breakpoint. This may be a hexidecimal number,
29814giving the address; or the string @samp{<PENDING>}, for a pending
29815breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
29816multiple locations. This field will not be present if no address can
29817be determined. For example, a watchpoint does not have an address.
29818
aa7ca1bb
AH
29819@item addr_flags
29820Optional field containing any flags related to the address. These flags are
29821architecture-dependent; see @ref{Architectures} for their meaning for a
29822particular CPU.
29823
54516a0b
TT
29824@item func
29825If known, the function in which the breakpoint appears.
29826If not known, this field is not present.
29827
29828@item filename
29829The name of the source file which contains this function, if known.
29830If not known, this field is not present.
29831
29832@item fullname
29833The full file name of the source file which contains this function, if
29834known. If not known, this field is not present.
29835
29836@item line
29837The line number at which this breakpoint appears, if known.
29838If not known, this field is not present.
29839
29840@item at
29841If the source file is not known, this field may be provided. If
29842provided, this holds the address of the breakpoint, possibly followed
29843by a symbol name.
29844
29845@item pending
29846If this breakpoint is pending, this field is present and holds the
29847text used to set the breakpoint, as entered by the user.
29848
29849@item evaluated-by
29850Where this breakpoint's condition is evaluated, either @samp{host} or
29851@samp{target}.
29852
29853@item thread
29854If this is a thread-specific breakpoint, then this identifies the
29855thread in which the breakpoint can trigger.
29856
29857@item task
29858If this breakpoint is restricted to a particular Ada task, then this
29859field will hold the task identifier.
29860
29861@item cond
29862If the breakpoint is conditional, this is the condition expression.
29863
29864@item ignore
29865The ignore count of the breakpoint.
29866
29867@item enable
29868The enable count of the breakpoint.
29869
29870@item traceframe-usage
29871FIXME.
29872
29873@item static-tracepoint-marker-string-id
29874For a static tracepoint, the name of the static tracepoint marker.
29875
29876@item mask
29877For a masked watchpoint, this is the mask.
29878
29879@item pass
29880A tracepoint's pass count.
29881
29882@item original-location
29883The location of the breakpoint as originally specified by the user.
29884This field is optional.
29885
29886@item times
29887The number of times the breakpoint has been hit.
29888
29889@item installed
29890This field is only given for tracepoints. This is either @samp{y},
29891meaning that the tracepoint is installed, or @samp{n}, meaning that it
29892is not.
29893
29894@item what
29895Some extra data, the exact contents of which are type-dependent.
29896
b4be1b06
SM
29897@item locations
29898This field is present if the breakpoint has multiple locations. It is also
29899exceptionally present if the breakpoint is enabled and has a single, disabled
29900location.
29901
6b92c0d3 29902The value is a list of locations. The format of a location is described below.
b4be1b06
SM
29903
29904@end table
29905
29906A location in a multi-location breakpoint is represented as a tuple with the
29907following fields:
29908
29909@table @code
29910
29911@item number
29912The location number as a dotted pair, like @samp{1.2}. The first digit is the
29913number of the parent breakpoint. The second digit is the number of the
29914location within that breakpoint.
29915
29916@item enabled
29917This indicates whether the location is enabled, in which case the
29918value is @samp{y}, or disabled, in which case the value is @samp{n}.
29919Note that this is not the same as the field @code{enable}.
29920
29921@item addr
29922The address of this location as an hexidecimal number.
29923
aa7ca1bb
AH
29924@item addr_flags
29925Optional field containing any flags related to the address. These flags are
29926architecture-dependent; see @ref{Architectures} for their meaning for a
29927particular CPU.
29928
b4be1b06
SM
29929@item func
29930If known, the function in which the location appears.
29931If not known, this field is not present.
29932
29933@item file
29934The name of the source file which contains this location, if known.
29935If not known, this field is not present.
29936
29937@item fullname
29938The full file name of the source file which contains this location, if
29939known. If not known, this field is not present.
29940
29941@item line
29942The line number at which this location appears, if known.
29943If not known, this field is not present.
29944
29945@item thread-groups
29946The thread groups this location is in.
29947
54516a0b
TT
29948@end table
29949
29950For example, here is what the output of @code{-break-insert}
29951(@pxref{GDB/MI Breakpoint Commands}) might be:
29952
29953@smallexample
29954-> -break-insert main
29955<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29956 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
29957 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29958 times="0"@}
54516a0b
TT
29959<- (gdb)
29960@end smallexample
29961
c3b108f7
VP
29962@node GDB/MI Frame Information
29963@subsection @sc{gdb/mi} Frame Information
29964
29965Response from many MI commands includes an information about stack
29966frame. This information is a tuple that may have the following
29967fields:
29968
29969@table @code
29970@item level
29971The level of the stack frame. The innermost frame has the level of
29972zero. This field is always present.
29973
29974@item func
29975The name of the function corresponding to the frame. This field may
29976be absent if @value{GDBN} is unable to determine the function name.
29977
29978@item addr
29979The code address for the frame. This field is always present.
29980
aa7ca1bb
AH
29981@item addr_flags
29982Optional field containing any flags related to the address. These flags are
29983architecture-dependent; see @ref{Architectures} for their meaning for a
29984particular CPU.
29985
c3b108f7
VP
29986@item file
29987The name of the source files that correspond to the frame's code
29988address. This field may be absent.
29989
29990@item line
29991The source line corresponding to the frames' code address. This field
29992may be absent.
29993
29994@item from
29995The name of the binary file (either executable or shared library) the
29996corresponds to the frame's code address. This field may be absent.
29997
29998@end table
82f68b1c 29999
dc146f7c
VP
30000@node GDB/MI Thread Information
30001@subsection @sc{gdb/mi} Thread Information
30002
30003Whenever @value{GDBN} has to report an information about a thread, it
ebe553db
SM
30004uses a tuple with the following fields. The fields are always present unless
30005stated otherwise.
dc146f7c
VP
30006
30007@table @code
30008@item id
ebe553db 30009The global numeric id assigned to the thread by @value{GDBN}.
dc146f7c
VP
30010
30011@item target-id
ebe553db 30012The target-specific string identifying the thread.
dc146f7c
VP
30013
30014@item details
30015Additional information about the thread provided by the target.
30016It is supposed to be human-readable and not interpreted by the
30017frontend. This field is optional.
30018
ebe553db
SM
30019@item name
30020The name of the thread. If the user specified a name using the
30021@code{thread name} command, then this name is given. Otherwise, if
30022@value{GDBN} can extract the thread name from the target, then that
30023name is given. If @value{GDBN} cannot find the thread name, then this
30024field is omitted.
30025
dc146f7c 30026@item state
ebe553db
SM
30027The execution state of the thread, either @samp{stopped} or @samp{running},
30028depending on whether the thread is presently running.
30029
30030@item frame
30031The stack frame currently executing in the thread. This field is only present
30032if the thread is stopped. Its format is documented in
30033@ref{GDB/MI Frame Information}.
dc146f7c
VP
30034
30035@item core
30036The value of this field is an integer number of the processor core the
30037thread was last seen on. This field is optional.
30038@end table
30039
956a9fb9
JB
30040@node GDB/MI Ada Exception Information
30041@subsection @sc{gdb/mi} Ada Exception Information
30042
30043Whenever a @code{*stopped} record is emitted because the program
30044stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
30045@value{GDBN} provides the name of the exception that was raised via
e547c119
JB
30046the @code{exception-name} field. Also, for exceptions that were raised
30047with an exception message, @value{GDBN} provides that message via
30048the @code{exception-message} field.
922fbb7b 30049
ef21caaf
NR
30050@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30051@node GDB/MI Simple Examples
30052@section Simple Examples of @sc{gdb/mi} Interaction
30053@cindex @sc{gdb/mi}, simple examples
30054
30055This subsection presents several simple examples of interaction using
30056the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
30057following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
30058the output received from @sc{gdb/mi}.
30059
d3e8051b 30060Note the line breaks shown in the examples are here only for
ef21caaf
NR
30061readability, they don't appear in the real output.
30062
79a6e687 30063@subheading Setting a Breakpoint
ef21caaf
NR
30064
30065Setting a breakpoint generates synchronous output which contains detailed
30066information of the breakpoint.
30067
30068@smallexample
30069-> -break-insert main
30070<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30071 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
30072 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
30073 times="0"@}
ef21caaf
NR
30074<- (gdb)
30075@end smallexample
30076
30077@subheading Program Execution
30078
30079Program execution generates asynchronous records and MI gives the
30080reason that execution stopped.
30081
30082@smallexample
30083-> -exec-run
30084<- ^running
30085<- (gdb)
a47ec5fe 30086<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
ef21caaf
NR
30087 frame=@{addr="0x08048564",func="main",
30088 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
6d52907e
JV
30089 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
30090 arch="i386:x86_64"@}
ef21caaf
NR
30091<- (gdb)
30092-> -exec-continue
30093<- ^running
30094<- (gdb)
30095<- *stopped,reason="exited-normally"
30096<- (gdb)
30097@end smallexample
30098
3f94c067 30099@subheading Quitting @value{GDBN}
ef21caaf 30100
3f94c067 30101Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
30102
30103@smallexample
30104-> (gdb)
30105<- -gdb-exit
30106<- ^exit
30107@end smallexample
30108
a6b29f87
VP
30109Please note that @samp{^exit} is printed immediately, but it might
30110take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
30111performs necessary cleanups, including killing programs being debugged
30112or disconnecting from debug hardware, so the frontend should wait till
30113@value{GDBN} exits and should only forcibly kill @value{GDBN} if it
30114fails to exit in reasonable time.
30115
a2c02241 30116@subheading A Bad Command
ef21caaf
NR
30117
30118Here's what happens if you pass a non-existent command:
30119
30120@smallexample
30121-> -rubbish
30122<- ^error,msg="Undefined MI command: rubbish"
594fe323 30123<- (gdb)
ef21caaf
NR
30124@end smallexample
30125
30126
922fbb7b
AC
30127@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30128@node GDB/MI Command Description Format
30129@section @sc{gdb/mi} Command Description Format
30130
30131The remaining sections describe blocks of commands. Each block of
30132commands is laid out in a fashion similar to this section.
30133
922fbb7b
AC
30134@subheading Motivation
30135
30136The motivation for this collection of commands.
30137
30138@subheading Introduction
30139
30140A brief introduction to this collection of commands as a whole.
30141
30142@subheading Commands
30143
30144For each command in the block, the following is described:
30145
30146@subsubheading Synopsis
30147
30148@smallexample
30149 -command @var{args}@dots{}
30150@end smallexample
30151
922fbb7b
AC
30152@subsubheading Result
30153
265eeb58 30154@subsubheading @value{GDBN} Command
922fbb7b 30155
265eeb58 30156The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
30157
30158@subsubheading Example
30159
ef21caaf
NR
30160Example(s) formatted for readability. Some of the described commands have
30161not been implemented yet and these are labeled N.A.@: (not available).
30162
30163
922fbb7b 30164@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
30165@node GDB/MI Breakpoint Commands
30166@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
30167
30168@cindex breakpoint commands for @sc{gdb/mi}
30169@cindex @sc{gdb/mi}, breakpoint commands
30170This section documents @sc{gdb/mi} commands for manipulating
30171breakpoints.
30172
30173@subheading The @code{-break-after} Command
30174@findex -break-after
30175
30176@subsubheading Synopsis
30177
30178@smallexample
30179 -break-after @var{number} @var{count}
30180@end smallexample
30181
30182The breakpoint number @var{number} is not in effect until it has been
30183hit @var{count} times. To see how this is reflected in the output of
30184the @samp{-break-list} command, see the description of the
30185@samp{-break-list} command below.
30186
30187@subsubheading @value{GDBN} Command
30188
30189The corresponding @value{GDBN} command is @samp{ignore}.
30190
30191@subsubheading Example
30192
30193@smallexample
594fe323 30194(gdb)
922fbb7b 30195-break-insert main
a47ec5fe
AR
30196^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30197enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
30198fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
30199times="0"@}
594fe323 30200(gdb)
922fbb7b
AC
30201-break-after 1 3
30202~
30203^done
594fe323 30204(gdb)
922fbb7b
AC
30205-break-list
30206^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30207hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30208@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30209@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30210@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30211@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30212@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30213body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 30214addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30215line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 30216(gdb)
922fbb7b
AC
30217@end smallexample
30218
30219@ignore
30220@subheading The @code{-break-catch} Command
30221@findex -break-catch
48cb2d85 30222@end ignore
922fbb7b
AC
30223
30224@subheading The @code{-break-commands} Command
30225@findex -break-commands
922fbb7b 30226
48cb2d85
VP
30227@subsubheading Synopsis
30228
30229@smallexample
30230 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
30231@end smallexample
30232
30233Specifies the CLI commands that should be executed when breakpoint
30234@var{number} is hit. The parameters @var{command1} to @var{commandN}
30235are the commands. If no command is specified, any previously-set
30236commands are cleared. @xref{Break Commands}. Typical use of this
30237functionality is tracing a program, that is, printing of values of
30238some variables whenever breakpoint is hit and then continuing.
30239
30240@subsubheading @value{GDBN} Command
30241
30242The corresponding @value{GDBN} command is @samp{commands}.
30243
30244@subsubheading Example
30245
30246@smallexample
30247(gdb)
30248-break-insert main
30249^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30250enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
30251fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
30252times="0"@}
48cb2d85
VP
30253(gdb)
30254-break-commands 1 "print v" "continue"
30255^done
30256(gdb)
30257@end smallexample
922fbb7b
AC
30258
30259@subheading The @code{-break-condition} Command
30260@findex -break-condition
30261
30262@subsubheading Synopsis
30263
30264@smallexample
30265 -break-condition @var{number} @var{expr}
30266@end smallexample
30267
30268Breakpoint @var{number} will stop the program only if the condition in
30269@var{expr} is true. The condition becomes part of the
30270@samp{-break-list} output (see the description of the @samp{-break-list}
30271command below).
30272
30273@subsubheading @value{GDBN} Command
30274
30275The corresponding @value{GDBN} command is @samp{condition}.
30276
30277@subsubheading Example
30278
30279@smallexample
594fe323 30280(gdb)
922fbb7b
AC
30281-break-condition 1 1
30282^done
594fe323 30283(gdb)
922fbb7b
AC
30284-break-list
30285^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30286hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30287@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30288@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30289@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30290@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30291@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30292body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 30293addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30294line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 30295(gdb)
922fbb7b
AC
30296@end smallexample
30297
30298@subheading The @code{-break-delete} Command
30299@findex -break-delete
30300
30301@subsubheading Synopsis
30302
30303@smallexample
30304 -break-delete ( @var{breakpoint} )+
30305@end smallexample
30306
30307Delete the breakpoint(s) whose number(s) are specified in the argument
30308list. This is obviously reflected in the breakpoint list.
30309
79a6e687 30310@subsubheading @value{GDBN} Command
922fbb7b
AC
30311
30312The corresponding @value{GDBN} command is @samp{delete}.
30313
30314@subsubheading Example
30315
30316@smallexample
594fe323 30317(gdb)
922fbb7b
AC
30318-break-delete 1
30319^done
594fe323 30320(gdb)
922fbb7b
AC
30321-break-list
30322^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30323hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30324@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30325@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30326@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30327@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30328@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30329body=[]@}
594fe323 30330(gdb)
922fbb7b
AC
30331@end smallexample
30332
30333@subheading The @code{-break-disable} Command
30334@findex -break-disable
30335
30336@subsubheading Synopsis
30337
30338@smallexample
30339 -break-disable ( @var{breakpoint} )+
30340@end smallexample
30341
30342Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
30343break list is now set to @samp{n} for the named @var{breakpoint}(s).
30344
30345@subsubheading @value{GDBN} Command
30346
30347The corresponding @value{GDBN} command is @samp{disable}.
30348
30349@subsubheading Example
30350
30351@smallexample
594fe323 30352(gdb)
922fbb7b
AC
30353-break-disable 2
30354^done
594fe323 30355(gdb)
922fbb7b
AC
30356-break-list
30357^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30358hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30359@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30360@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30361@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30362@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30363@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30364body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102 30365addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30366line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 30367(gdb)
922fbb7b
AC
30368@end smallexample
30369
30370@subheading The @code{-break-enable} Command
30371@findex -break-enable
30372
30373@subsubheading Synopsis
30374
30375@smallexample
30376 -break-enable ( @var{breakpoint} )+
30377@end smallexample
30378
30379Enable (previously disabled) @var{breakpoint}(s).
30380
30381@subsubheading @value{GDBN} Command
30382
30383The corresponding @value{GDBN} command is @samp{enable}.
30384
30385@subsubheading Example
30386
30387@smallexample
594fe323 30388(gdb)
922fbb7b
AC
30389-break-enable 2
30390^done
594fe323 30391(gdb)
922fbb7b
AC
30392-break-list
30393^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30394hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30395@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30396@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30397@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30398@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30399@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30400body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 30401addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30402line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 30403(gdb)
922fbb7b
AC
30404@end smallexample
30405
30406@subheading The @code{-break-info} Command
30407@findex -break-info
30408
30409@subsubheading Synopsis
30410
30411@smallexample
30412 -break-info @var{breakpoint}
30413@end smallexample
30414
30415@c REDUNDANT???
30416Get information about a single breakpoint.
30417
54516a0b
TT
30418The result is a table of breakpoints. @xref{GDB/MI Breakpoint
30419Information}, for details on the format of each breakpoint in the
30420table.
30421
79a6e687 30422@subsubheading @value{GDBN} Command
922fbb7b
AC
30423
30424The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
30425
30426@subsubheading Example
30427N.A.
30428
30429@subheading The @code{-break-insert} Command
30430@findex -break-insert
629500fa 30431@anchor{-break-insert}
922fbb7b
AC
30432
30433@subsubheading Synopsis
30434
30435@smallexample
6791b117 30436 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ] [ --qualified ]
922fbb7b 30437 [ -c @var{condition} ] [ -i @var{ignore-count} ]
472a2379 30438 [ -p @var{thread-id} ] [ @var{location} ]
922fbb7b
AC
30439@end smallexample
30440
30441@noindent
afe8ab22 30442If specified, @var{location}, can be one of:
922fbb7b 30443
629500fa
KS
30444@table @var
30445@item linespec location
30446A linespec location. @xref{Linespec Locations}.
30447
30448@item explicit location
30449An explicit location. @sc{gdb/mi} explicit locations are
30450analogous to the CLI's explicit locations using the option names
30451listed below. @xref{Explicit Locations}.
30452
30453@table @samp
30454@item --source @var{filename}
30455The source file name of the location. This option requires the use
30456of either @samp{--function} or @samp{--line}.
30457
30458@item --function @var{function}
30459The name of a function or method.
922fbb7b 30460
629500fa
KS
30461@item --label @var{label}
30462The name of a label.
30463
30464@item --line @var{lineoffset}
30465An absolute or relative line offset from the start of the location.
30466@end table
30467
30468@item address location
30469An address location, *@var{address}. @xref{Address Locations}.
30470@end table
30471
30472@noindent
922fbb7b
AC
30473The possible optional parameters of this command are:
30474
30475@table @samp
30476@item -t
948d5102 30477Insert a temporary breakpoint.
922fbb7b
AC
30478@item -h
30479Insert a hardware breakpoint.
afe8ab22
VP
30480@item -f
30481If @var{location} cannot be parsed (for example if it
30482refers to unknown files or functions), create a pending
30483breakpoint. Without this flag, @value{GDBN} will report
30484an error, and won't create a breakpoint, if @var{location}
30485cannot be parsed.
41447f92
VP
30486@item -d
30487Create a disabled breakpoint.
18148017
VP
30488@item -a
30489Create a tracepoint. @xref{Tracepoints}. When this parameter
30490is used together with @samp{-h}, a fast tracepoint is created.
472a2379
KS
30491@item -c @var{condition}
30492Make the breakpoint conditional on @var{condition}.
30493@item -i @var{ignore-count}
30494Initialize the @var{ignore-count}.
30495@item -p @var{thread-id}
5d5658a1
PA
30496Restrict the breakpoint to the thread with the specified global
30497@var{thread-id}.
6791b117
PA
30498@item --qualified
30499This option makes @value{GDBN} interpret a function name specified as
30500a complete fully-qualified name.
922fbb7b
AC
30501@end table
30502
30503@subsubheading Result
30504
54516a0b
TT
30505@xref{GDB/MI Breakpoint Information}, for details on the format of the
30506resulting breakpoint.
922fbb7b
AC
30507
30508Note: this format is open to change.
30509@c An out-of-band breakpoint instead of part of the result?
30510
30511@subsubheading @value{GDBN} Command
30512
30513The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
496ee73e 30514@samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
922fbb7b
AC
30515
30516@subsubheading Example
30517
30518@smallexample
594fe323 30519(gdb)
922fbb7b 30520-break-insert main
948d5102 30521^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
998580f1
MK
30522fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
30523times="0"@}
594fe323 30524(gdb)
922fbb7b 30525-break-insert -t foo
948d5102 30526^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
998580f1
MK
30527fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
30528times="0"@}
594fe323 30529(gdb)
922fbb7b
AC
30530-break-list
30531^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30532hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30533@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30534@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30535@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30536@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30537@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30538body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 30539addr="0x0001072c", func="main",file="recursive2.c",
998580f1
MK
30540fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
30541times="0"@},
922fbb7b 30542bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102 30543addr="0x00010774",func="foo",file="recursive2.c",
998580f1
MK
30544fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30545times="0"@}]@}
594fe323 30546(gdb)
496ee73e
KS
30547@c -break-insert -r foo.*
30548@c ~int foo(int, int);
30549@c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
998580f1
MK
30550@c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30551@c times="0"@}
496ee73e 30552@c (gdb)
922fbb7b
AC
30553@end smallexample
30554
c5867ab6
HZ
30555@subheading The @code{-dprintf-insert} Command
30556@findex -dprintf-insert
30557
30558@subsubheading Synopsis
30559
30560@smallexample
6791b117 30561 -dprintf-insert [ -t ] [ -f ] [ -d ] [ --qualified ]
c5867ab6
HZ
30562 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30563 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
30564 [ @var{argument} ]
30565@end smallexample
30566
30567@noindent
6791b117
PA
30568If supplied, @var{location} and @code{--qualified} may be specified
30569the same way as for the @code{-break-insert} command.
30570@xref{-break-insert}.
c5867ab6
HZ
30571
30572The possible optional parameters of this command are:
30573
30574@table @samp
30575@item -t
30576Insert a temporary breakpoint.
30577@item -f
30578If @var{location} cannot be parsed (for example, if it
30579refers to unknown files or functions), create a pending
30580breakpoint. Without this flag, @value{GDBN} will report
30581an error, and won't create a breakpoint, if @var{location}
30582cannot be parsed.
30583@item -d
30584Create a disabled breakpoint.
30585@item -c @var{condition}
30586Make the breakpoint conditional on @var{condition}.
30587@item -i @var{ignore-count}
30588Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
30589to @var{ignore-count}.
30590@item -p @var{thread-id}
5d5658a1
PA
30591Restrict the breakpoint to the thread with the specified global
30592@var{thread-id}.
c5867ab6
HZ
30593@end table
30594
30595@subsubheading Result
30596
30597@xref{GDB/MI Breakpoint Information}, for details on the format of the
30598resulting breakpoint.
30599
30600@c An out-of-band breakpoint instead of part of the result?
30601
30602@subsubheading @value{GDBN} Command
30603
30604The corresponding @value{GDBN} command is @samp{dprintf}.
30605
30606@subsubheading Example
30607
30608@smallexample
30609(gdb)
306104-dprintf-insert foo "At foo entry\n"
306114^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
30612addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
30613fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
30614times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
30615original-location="foo"@}
30616(gdb)
306175-dprintf-insert 26 "arg=%d, g=%d\n" arg g
306185^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
30619addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
30620fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
30621times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
30622original-location="mi-dprintf.c:26"@}
30623(gdb)
30624@end smallexample
30625
922fbb7b
AC
30626@subheading The @code{-break-list} Command
30627@findex -break-list
30628
30629@subsubheading Synopsis
30630
30631@smallexample
30632 -break-list
30633@end smallexample
30634
30635Displays the list of inserted breakpoints, showing the following fields:
30636
30637@table @samp
30638@item Number
30639number of the breakpoint
30640@item Type
30641type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
30642@item Disposition
30643should the breakpoint be deleted or disabled when it is hit: @samp{keep}
30644or @samp{nokeep}
30645@item Enabled
30646is the breakpoint enabled or no: @samp{y} or @samp{n}
30647@item Address
30648memory location at which the breakpoint is set
30649@item What
30650logical location of the breakpoint, expressed by function name, file
30651name, line number
998580f1
MK
30652@item Thread-groups
30653list of thread groups to which this breakpoint applies
922fbb7b
AC
30654@item Times
30655number of times the breakpoint has been hit
30656@end table
30657
30658If there are no breakpoints or watchpoints, the @code{BreakpointTable}
30659@code{body} field is an empty list.
30660
30661@subsubheading @value{GDBN} Command
30662
30663The corresponding @value{GDBN} command is @samp{info break}.
30664
30665@subsubheading Example
30666
30667@smallexample
594fe323 30668(gdb)
922fbb7b
AC
30669-break-list
30670^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30671hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30672@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30673@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30674@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30675@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30676@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30677body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
998580f1
MK
30678addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
30679times="0"@},
922fbb7b 30680bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 30681addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30682line="13",thread-groups=["i1"],times="0"@}]@}
594fe323 30683(gdb)
922fbb7b
AC
30684@end smallexample
30685
30686Here's an example of the result when there are no breakpoints:
30687
30688@smallexample
594fe323 30689(gdb)
922fbb7b
AC
30690-break-list
30691^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30692hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30693@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30694@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30695@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30696@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30697@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30698body=[]@}
594fe323 30699(gdb)
922fbb7b
AC
30700@end smallexample
30701
18148017
VP
30702@subheading The @code{-break-passcount} Command
30703@findex -break-passcount
30704
30705@subsubheading Synopsis
30706
30707@smallexample
30708 -break-passcount @var{tracepoint-number} @var{passcount}
30709@end smallexample
30710
30711Set the passcount for tracepoint @var{tracepoint-number} to
30712@var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
30713is not a tracepoint, error is emitted. This corresponds to CLI
30714command @samp{passcount}.
30715
922fbb7b
AC
30716@subheading The @code{-break-watch} Command
30717@findex -break-watch
30718
30719@subsubheading Synopsis
30720
30721@smallexample
30722 -break-watch [ -a | -r ]
30723@end smallexample
30724
30725Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 30726@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 30727read from or on a write to the memory location. With the @samp{-r}
d3e8051b 30728option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
30729trigger only when the memory location is accessed for reading. Without
30730either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 30731i.e., it will trigger when the memory location is accessed for writing.
79a6e687 30732@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
30733
30734Note that @samp{-break-list} will report a single list of watchpoints and
30735breakpoints inserted.
30736
30737@subsubheading @value{GDBN} Command
30738
30739The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
30740@samp{rwatch}.
30741
30742@subsubheading Example
30743
30744Setting a watchpoint on a variable in the @code{main} function:
30745
30746@smallexample
594fe323 30747(gdb)
922fbb7b
AC
30748-break-watch x
30749^done,wpt=@{number="2",exp="x"@}
594fe323 30750(gdb)
922fbb7b
AC
30751-exec-continue
30752^running
0869d01b
NR
30753(gdb)
30754*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 30755value=@{old="-268439212",new="55"@},
76ff342d 30756frame=@{func="main",args=[],file="recursive2.c",
6d52907e 30757fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
594fe323 30758(gdb)
922fbb7b
AC
30759@end smallexample
30760
30761Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
30762the program execution twice: first for the variable changing value, then
30763for the watchpoint going out of scope.
30764
30765@smallexample
594fe323 30766(gdb)
922fbb7b
AC
30767-break-watch C
30768^done,wpt=@{number="5",exp="C"@}
594fe323 30769(gdb)
922fbb7b
AC
30770-exec-continue
30771^running
0869d01b
NR
30772(gdb)
30773*stopped,reason="watchpoint-trigger",
922fbb7b
AC
30774wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
30775frame=@{func="callee4",args=[],
76ff342d 30776file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30777fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30778arch="i386:x86_64"@}
594fe323 30779(gdb)
922fbb7b
AC
30780-exec-continue
30781^running
0869d01b
NR
30782(gdb)
30783*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
30784frame=@{func="callee3",args=[@{name="strarg",
30785value="0x11940 \"A string argument.\""@}],
76ff342d 30786file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30787fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30788arch="i386:x86_64"@}
594fe323 30789(gdb)
922fbb7b
AC
30790@end smallexample
30791
30792Listing breakpoints and watchpoints, at different points in the program
30793execution. Note that once the watchpoint goes out of scope, it is
30794deleted.
30795
30796@smallexample
594fe323 30797(gdb)
922fbb7b
AC
30798-break-watch C
30799^done,wpt=@{number="2",exp="C"@}
594fe323 30800(gdb)
922fbb7b
AC
30801-break-list
30802^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30803hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30804@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30805@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30806@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30807@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30808@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30809body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30810addr="0x00010734",func="callee4",
948d5102 30811file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
30812fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
30813times="1"@},
922fbb7b 30814bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 30815enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
594fe323 30816(gdb)
922fbb7b
AC
30817-exec-continue
30818^running
0869d01b
NR
30819(gdb)
30820*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
30821value=@{old="-276895068",new="3"@},
30822frame=@{func="callee4",args=[],
76ff342d 30823file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30824fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30825arch="i386:x86_64"@}
594fe323 30826(gdb)
922fbb7b
AC
30827-break-list
30828^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30829hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30830@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30831@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30832@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30833@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30834@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30835body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30836addr="0x00010734",func="callee4",
948d5102 30837file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
30838fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
30839times="1"@},
922fbb7b 30840bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 30841enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
594fe323 30842(gdb)
922fbb7b
AC
30843-exec-continue
30844^running
30845^done,reason="watchpoint-scope",wpnum="2",
30846frame=@{func="callee3",args=[@{name="strarg",
30847value="0x11940 \"A string argument.\""@}],
76ff342d 30848file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30849fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30850arch="i386:x86_64"@}
594fe323 30851(gdb)
922fbb7b
AC
30852-break-list
30853^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30854hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30855@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30856@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30857@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30858@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30859@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30860body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30861addr="0x00010734",func="callee4",
948d5102
NR
30862file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30863fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
998580f1 30864thread-groups=["i1"],times="1"@}]@}
594fe323 30865(gdb)
922fbb7b
AC
30866@end smallexample
30867
3fa7bf06
MG
30868
30869@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30870@node GDB/MI Catchpoint Commands
30871@section @sc{gdb/mi} Catchpoint Commands
30872
30873This section documents @sc{gdb/mi} commands for manipulating
30874catchpoints.
30875
40555925
JB
30876@menu
30877* Shared Library GDB/MI Catchpoint Commands::
30878* Ada Exception GDB/MI Catchpoint Commands::
30056ea0 30879* C++ Exception GDB/MI Catchpoint Commands::
40555925
JB
30880@end menu
30881
30882@node Shared Library GDB/MI Catchpoint Commands
30883@subsection Shared Library @sc{gdb/mi} Catchpoints
30884
3fa7bf06
MG
30885@subheading The @code{-catch-load} Command
30886@findex -catch-load
30887
30888@subsubheading Synopsis
30889
30890@smallexample
30891 -catch-load [ -t ] [ -d ] @var{regexp}
30892@end smallexample
30893
30894Add a catchpoint for library load events. If the @samp{-t} option is used,
30895the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30896Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
30897in a disabled state. The @samp{regexp} argument is a regular
30898expression used to match the name of the loaded library.
30899
30900
30901@subsubheading @value{GDBN} Command
30902
30903The corresponding @value{GDBN} command is @samp{catch load}.
30904
30905@subsubheading Example
30906
30907@smallexample
30908-catch-load -t foo.so
30909^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
8ac3646f 30910what="load of library matching foo.so",catch-type="load",times="0"@}
3fa7bf06
MG
30911(gdb)
30912@end smallexample
30913
30914
30915@subheading The @code{-catch-unload} Command
30916@findex -catch-unload
30917
30918@subsubheading Synopsis
30919
30920@smallexample
30921 -catch-unload [ -t ] [ -d ] @var{regexp}
30922@end smallexample
30923
30924Add a catchpoint for library unload events. If the @samp{-t} option is
30925used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30926Breakpoints}). If the @samp{-d} option is used, the catchpoint is
30927created in a disabled state. The @samp{regexp} argument is a regular
30928expression used to match the name of the unloaded library.
30929
30930@subsubheading @value{GDBN} Command
30931
30932The corresponding @value{GDBN} command is @samp{catch unload}.
30933
30934@subsubheading Example
30935
30936@smallexample
30937-catch-unload -d bar.so
30938^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
8ac3646f 30939what="load of library matching bar.so",catch-type="unload",times="0"@}
3fa7bf06
MG
30940(gdb)
30941@end smallexample
30942
40555925
JB
30943@node Ada Exception GDB/MI Catchpoint Commands
30944@subsection Ada Exception @sc{gdb/mi} Catchpoints
30945
30946The following @sc{gdb/mi} commands can be used to create catchpoints
30947that stop the execution when Ada exceptions are being raised.
30948
30949@subheading The @code{-catch-assert} Command
30950@findex -catch-assert
30951
30952@subsubheading Synopsis
30953
30954@smallexample
30955 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
30956@end smallexample
30957
30958Add a catchpoint for failed Ada assertions.
30959
30960The possible optional parameters for this command are:
30961
30962@table @samp
30963@item -c @var{condition}
30964Make the catchpoint conditional on @var{condition}.
30965@item -d
30966Create a disabled catchpoint.
30967@item -t
30968Create a temporary catchpoint.
30969@end table
30970
30971@subsubheading @value{GDBN} Command
30972
30973The corresponding @value{GDBN} command is @samp{catch assert}.
30974
30975@subsubheading Example
30976
30977@smallexample
30978-catch-assert
30979^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
30980enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
30981thread-groups=["i1"],times="0",
30982original-location="__gnat_debug_raise_assert_failure"@}
30983(gdb)
30984@end smallexample
30985
30986@subheading The @code{-catch-exception} Command
30987@findex -catch-exception
30988
30989@subsubheading Synopsis
30990
30991@smallexample
30992 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30993 [ -t ] [ -u ]
30994@end smallexample
30995
30996Add a catchpoint stopping when Ada exceptions are raised.
30997By default, the command stops the program when any Ada exception
30998gets raised. But it is also possible, by using some of the
30999optional parameters described below, to create more selective
31000catchpoints.
31001
31002The possible optional parameters for this command are:
31003
31004@table @samp
31005@item -c @var{condition}
31006Make the catchpoint conditional on @var{condition}.
31007@item -d
31008Create a disabled catchpoint.
31009@item -e @var{exception-name}
31010Only stop when @var{exception-name} is raised. This option cannot
31011be used combined with @samp{-u}.
31012@item -t
31013Create a temporary catchpoint.
31014@item -u
31015Stop only when an unhandled exception gets raised. This option
31016cannot be used combined with @samp{-e}.
31017@end table
31018
31019@subsubheading @value{GDBN} Command
31020
31021The corresponding @value{GDBN} commands are @samp{catch exception}
31022and @samp{catch exception unhandled}.
31023
31024@subsubheading Example
31025
31026@smallexample
31027-catch-exception -e Program_Error
31028^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
31029enabled="y",addr="0x0000000000404874",
31030what="`Program_Error' Ada exception", thread-groups=["i1"],
31031times="0",original-location="__gnat_debug_raise_exception"@}
31032(gdb)
31033@end smallexample
3fa7bf06 31034
bea298f9
XR
31035@subheading The @code{-catch-handlers} Command
31036@findex -catch-handlers
31037
31038@subsubheading Synopsis
31039
31040@smallexample
31041 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
31042 [ -t ]
31043@end smallexample
31044
31045Add a catchpoint stopping when Ada exceptions are handled.
31046By default, the command stops the program when any Ada exception
31047gets handled. But it is also possible, by using some of the
31048optional parameters described below, to create more selective
31049catchpoints.
31050
31051The possible optional parameters for this command are:
31052
31053@table @samp
31054@item -c @var{condition}
31055Make the catchpoint conditional on @var{condition}.
31056@item -d
31057Create a disabled catchpoint.
31058@item -e @var{exception-name}
31059Only stop when @var{exception-name} is handled.
31060@item -t
31061Create a temporary catchpoint.
31062@end table
31063
31064@subsubheading @value{GDBN} Command
31065
31066The corresponding @value{GDBN} command is @samp{catch handlers}.
31067
31068@subsubheading Example
31069
31070@smallexample
31071-catch-handlers -e Constraint_Error
31072^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
31073enabled="y",addr="0x0000000000402f68",
31074what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
31075times="0",original-location="__gnat_begin_handler"@}
31076(gdb)
31077@end smallexample
31078
30056ea0
AB
31079@node C++ Exception GDB/MI Catchpoint Commands
31080@subsection C@t{++} Exception @sc{gdb/mi} Catchpoints
31081
31082The following @sc{gdb/mi} commands can be used to create catchpoints
31083that stop the execution when C@t{++} exceptions are being throw, rethrown,
31084or caught.
31085
31086@subheading The @code{-catch-throw} Command
31087@findex -catch-throw
31088
31089@subsubheading Synopsis
31090
31091@smallexample
31092 -catch-throw [ -t ] [ -r @var{regexp}]
31093@end smallexample
31094
31095Stop when the debuggee throws a C@t{++} exception. If @var{regexp} is
31096given, then only exceptions whose type matches the regular expression
31097will be caught.
31098
31099If @samp{-t} is given, then the catchpoint is enabled only for one
31100stop, the catchpoint is automatically deleted after stopping once for
31101the event.
31102
31103@subsubheading @value{GDBN} Command
31104
31105The corresponding @value{GDBN} commands are @samp{catch throw}
31106and @samp{tcatch throw} (@pxref{Set Catchpoints}).
31107
31108@subsubheading Example
31109
31110@smallexample
31111-catch-throw -r exception_type
cb1e4e32
PA
31112^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31113 what="exception throw",catch-type="throw",
31114 thread-groups=["i1"],
30056ea0
AB
31115 regexp="exception_type",times="0"@}
31116(gdb)
31117-exec-run
31118^running
31119(gdb)
31120~"\n"
31121~"Catchpoint 1 (exception thrown), 0x00007ffff7ae00ed
31122 in __cxa_throw () from /lib64/libstdc++.so.6\n"
31123*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31124 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_throw",
31125 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31126 thread-id="1",stopped-threads="all",core="6"
31127(gdb)
31128@end smallexample
31129
31130@subheading The @code{-catch-rethrow} Command
31131@findex -catch-rethrow
31132
31133@subsubheading Synopsis
31134
31135@smallexample
31136 -catch-rethrow [ -t ] [ -r @var{regexp}]
31137@end smallexample
31138
31139Stop when a C@t{++} exception is re-thrown. If @var{regexp} is given,
31140then only exceptions whose type matches the regular expression will be
31141caught.
31142
31143If @samp{-t} is given, then the catchpoint is enabled only for one
31144stop, the catchpoint is automatically deleted after the first event is
31145caught.
31146
31147@subsubheading @value{GDBN} Command
31148
31149The corresponding @value{GDBN} commands are @samp{catch rethrow}
31150and @samp{tcatch rethrow} (@pxref{Set Catchpoints}).
31151
31152@subsubheading Example
31153
31154@smallexample
31155-catch-rethrow -r exception_type
cb1e4e32
PA
31156^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31157 what="exception rethrow",catch-type="rethrow",
31158 thread-groups=["i1"],
30056ea0
AB
31159 regexp="exception_type",times="0"@}
31160(gdb)
31161-exec-run
31162^running
31163(gdb)
31164~"\n"
31165~"Catchpoint 1 (exception rethrown), 0x00007ffff7ae00ed
31166 in __cxa_rethrow () from /lib64/libstdc++.so.6\n"
31167*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31168 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_rethrow",
31169 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31170 thread-id="1",stopped-threads="all",core="6"
31171(gdb)
31172@end smallexample
31173
31174@subheading The @code{-catch-catch} Command
31175@findex -catch-catch
31176
31177@subsubheading Synopsis
31178
31179@smallexample
31180 -catch-catch [ -t ] [ -r @var{regexp}]
31181@end smallexample
31182
31183Stop when the debuggee catches a C@t{++} exception. If @var{regexp}
31184is given, then only exceptions whose type matches the regular
31185expression will be caught.
31186
31187If @samp{-t} is given, then the catchpoint is enabled only for one
31188stop, the catchpoint is automatically deleted after the first event is
31189caught.
31190
31191@subsubheading @value{GDBN} Command
31192
31193The corresponding @value{GDBN} commands are @samp{catch catch}
31194and @samp{tcatch catch} (@pxref{Set Catchpoints}).
31195
31196@subsubheading Example
31197
31198@smallexample
31199-catch-catch -r exception_type
cb1e4e32
PA
31200^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31201 what="exception catch",catch-type="catch",
31202 thread-groups=["i1"],
30056ea0
AB
31203 regexp="exception_type",times="0"@}
31204(gdb)
31205-exec-run
31206^running
31207(gdb)
31208~"\n"
31209~"Catchpoint 1 (exception caught), 0x00007ffff7ae00ed
31210 in __cxa_begin_catch () from /lib64/libstdc++.so.6\n"
31211*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31212 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_begin_catch",
31213 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31214 thread-id="1",stopped-threads="all",core="6"
31215(gdb)
31216@end smallexample
31217
922fbb7b 31218@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
31219@node GDB/MI Program Context
31220@section @sc{gdb/mi} Program Context
922fbb7b 31221
a2c02241
NR
31222@subheading The @code{-exec-arguments} Command
31223@findex -exec-arguments
922fbb7b 31224
922fbb7b
AC
31225
31226@subsubheading Synopsis
31227
31228@smallexample
a2c02241 31229 -exec-arguments @var{args}
922fbb7b
AC
31230@end smallexample
31231
a2c02241
NR
31232Set the inferior program arguments, to be used in the next
31233@samp{-exec-run}.
922fbb7b 31234
a2c02241 31235@subsubheading @value{GDBN} Command
922fbb7b 31236
a2c02241 31237The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 31238
a2c02241 31239@subsubheading Example
922fbb7b 31240
fbc5282e
MK
31241@smallexample
31242(gdb)
31243-exec-arguments -v word
31244^done
31245(gdb)
31246@end smallexample
922fbb7b 31247
a2c02241 31248
9901a55b 31249@ignore
a2c02241
NR
31250@subheading The @code{-exec-show-arguments} Command
31251@findex -exec-show-arguments
31252
31253@subsubheading Synopsis
31254
31255@smallexample
31256 -exec-show-arguments
31257@end smallexample
31258
31259Print the arguments of the program.
922fbb7b
AC
31260
31261@subsubheading @value{GDBN} Command
31262
a2c02241 31263The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
31264
31265@subsubheading Example
a2c02241 31266N.A.
9901a55b 31267@end ignore
922fbb7b 31268
922fbb7b 31269
a2c02241
NR
31270@subheading The @code{-environment-cd} Command
31271@findex -environment-cd
922fbb7b 31272
a2c02241 31273@subsubheading Synopsis
922fbb7b
AC
31274
31275@smallexample
a2c02241 31276 -environment-cd @var{pathdir}
922fbb7b
AC
31277@end smallexample
31278
a2c02241 31279Set @value{GDBN}'s working directory.
922fbb7b 31280
a2c02241 31281@subsubheading @value{GDBN} Command
922fbb7b 31282
a2c02241
NR
31283The corresponding @value{GDBN} command is @samp{cd}.
31284
31285@subsubheading Example
922fbb7b
AC
31286
31287@smallexample
594fe323 31288(gdb)
a2c02241
NR
31289-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31290^done
594fe323 31291(gdb)
922fbb7b
AC
31292@end smallexample
31293
31294
a2c02241
NR
31295@subheading The @code{-environment-directory} Command
31296@findex -environment-directory
922fbb7b
AC
31297
31298@subsubheading Synopsis
31299
31300@smallexample
a2c02241 31301 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
31302@end smallexample
31303
a2c02241
NR
31304Add directories @var{pathdir} to beginning of search path for source files.
31305If the @samp{-r} option is used, the search path is reset to the default
31306search path. If directories @var{pathdir} are supplied in addition to the
31307@samp{-r} option, the search path is first reset and then addition
31308occurs as normal.
31309Multiple directories may be specified, separated by blanks. Specifying
31310multiple directories in a single command
31311results in the directories added to the beginning of the
31312search path in the same order they were presented in the command.
31313If blanks are needed as
31314part of a directory name, double-quotes should be used around
31315the name. In the command output, the path will show up separated
d3e8051b 31316by the system directory-separator character. The directory-separator
a2c02241
NR
31317character must not be used
31318in any directory name.
31319If no directories are specified, the current search path is displayed.
922fbb7b
AC
31320
31321@subsubheading @value{GDBN} Command
31322
a2c02241 31323The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
31324
31325@subsubheading Example
31326
922fbb7b 31327@smallexample
594fe323 31328(gdb)
a2c02241
NR
31329-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31330^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 31331(gdb)
a2c02241
NR
31332-environment-directory ""
31333^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 31334(gdb)
a2c02241
NR
31335-environment-directory -r /home/jjohnstn/src/gdb /usr/src
31336^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 31337(gdb)
a2c02241
NR
31338-environment-directory -r
31339^done,source-path="$cdir:$cwd"
594fe323 31340(gdb)
922fbb7b
AC
31341@end smallexample
31342
31343
a2c02241
NR
31344@subheading The @code{-environment-path} Command
31345@findex -environment-path
922fbb7b
AC
31346
31347@subsubheading Synopsis
31348
31349@smallexample
a2c02241 31350 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
31351@end smallexample
31352
a2c02241
NR
31353Add directories @var{pathdir} to beginning of search path for object files.
31354If the @samp{-r} option is used, the search path is reset to the original
31355search path that existed at gdb start-up. If directories @var{pathdir} are
31356supplied in addition to the
31357@samp{-r} option, the search path is first reset and then addition
31358occurs as normal.
31359Multiple directories may be specified, separated by blanks. Specifying
31360multiple directories in a single command
31361results in the directories added to the beginning of the
31362search path in the same order they were presented in the command.
31363If blanks are needed as
31364part of a directory name, double-quotes should be used around
31365the name. In the command output, the path will show up separated
d3e8051b 31366by the system directory-separator character. The directory-separator
a2c02241
NR
31367character must not be used
31368in any directory name.
31369If no directories are specified, the current path is displayed.
31370
922fbb7b
AC
31371
31372@subsubheading @value{GDBN} Command
31373
a2c02241 31374The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
31375
31376@subsubheading Example
31377
922fbb7b 31378@smallexample
594fe323 31379(gdb)
a2c02241
NR
31380-environment-path
31381^done,path="/usr/bin"
594fe323 31382(gdb)
a2c02241
NR
31383-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
31384^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 31385(gdb)
a2c02241
NR
31386-environment-path -r /usr/local/bin
31387^done,path="/usr/local/bin:/usr/bin"
594fe323 31388(gdb)
922fbb7b
AC
31389@end smallexample
31390
31391
a2c02241
NR
31392@subheading The @code{-environment-pwd} Command
31393@findex -environment-pwd
922fbb7b
AC
31394
31395@subsubheading Synopsis
31396
31397@smallexample
a2c02241 31398 -environment-pwd
922fbb7b
AC
31399@end smallexample
31400
a2c02241 31401Show the current working directory.
922fbb7b 31402
79a6e687 31403@subsubheading @value{GDBN} Command
922fbb7b 31404
a2c02241 31405The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
31406
31407@subsubheading Example
31408
922fbb7b 31409@smallexample
594fe323 31410(gdb)
a2c02241
NR
31411-environment-pwd
31412^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 31413(gdb)
922fbb7b
AC
31414@end smallexample
31415
a2c02241
NR
31416@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31417@node GDB/MI Thread Commands
31418@section @sc{gdb/mi} Thread Commands
31419
31420
31421@subheading The @code{-thread-info} Command
31422@findex -thread-info
922fbb7b
AC
31423
31424@subsubheading Synopsis
31425
31426@smallexample
8e8901c5 31427 -thread-info [ @var{thread-id} ]
922fbb7b
AC
31428@end smallexample
31429
5d5658a1
PA
31430Reports information about either a specific thread, if the
31431@var{thread-id} parameter is present, or about all threads.
31432@var{thread-id} is the thread's global thread ID. When printing
31433information about all threads, also reports the global ID of the
31434current thread.
8e8901c5 31435
79a6e687 31436@subsubheading @value{GDBN} Command
922fbb7b 31437
8e8901c5
VP
31438The @samp{info thread} command prints the same information
31439about all threads.
922fbb7b 31440
4694da01 31441@subsubheading Result
922fbb7b 31442
ebe553db 31443The result contains the following attributes:
4694da01
TT
31444
31445@table @samp
ebe553db
SM
31446@item threads
31447A list of threads. The format of the elements of the list is described in
31448@ref{GDB/MI Thread Information}.
31449
31450@item current-thread-id
31451The global id of the currently selected thread. This field is omitted if there
31452is no selected thread (for example, when the selected inferior is not running,
31453and therefore has no threads) or if a @var{thread-id} argument was passed to
31454the command.
4694da01
TT
31455
31456@end table
31457
31458@subsubheading Example
31459
31460@smallexample
31461-thread-info
31462^done,threads=[
31463@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
31464 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
31465 args=[]@},state="running"@},
31466@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
31467 frame=@{level="0",addr="0x0804891f",func="foo",
31468 args=[@{name="i",value="10"@}],
6d52907e 31469 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
4694da01
TT
31470 state="running"@}],
31471current-thread-id="1"
31472(gdb)
31473@end smallexample
31474
a2c02241
NR
31475@subheading The @code{-thread-list-ids} Command
31476@findex -thread-list-ids
922fbb7b 31477
a2c02241 31478@subsubheading Synopsis
922fbb7b 31479
a2c02241
NR
31480@smallexample
31481 -thread-list-ids
31482@end smallexample
922fbb7b 31483
5d5658a1
PA
31484Produces a list of the currently known global @value{GDBN} thread ids.
31485At the end of the list it also prints the total number of such
31486threads.
922fbb7b 31487
c3b108f7
VP
31488This command is retained for historical reasons, the
31489@code{-thread-info} command should be used instead.
31490
922fbb7b
AC
31491@subsubheading @value{GDBN} Command
31492
a2c02241 31493Part of @samp{info threads} supplies the same information.
922fbb7b
AC
31494
31495@subsubheading Example
31496
922fbb7b 31497@smallexample
594fe323 31498(gdb)
a2c02241
NR
31499-thread-list-ids
31500^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
592375cd 31501current-thread-id="1",number-of-threads="3"
594fe323 31502(gdb)
922fbb7b
AC
31503@end smallexample
31504
a2c02241
NR
31505
31506@subheading The @code{-thread-select} Command
31507@findex -thread-select
922fbb7b
AC
31508
31509@subsubheading Synopsis
31510
31511@smallexample
5d5658a1 31512 -thread-select @var{thread-id}
922fbb7b
AC
31513@end smallexample
31514
5d5658a1
PA
31515Make thread with global thread number @var{thread-id} the current
31516thread. It prints the number of the new current thread, and the
31517topmost frame for that thread.
922fbb7b 31518
c3b108f7
VP
31519This command is deprecated in favor of explicitly using the
31520@samp{--thread} option to each command.
31521
922fbb7b
AC
31522@subsubheading @value{GDBN} Command
31523
a2c02241 31524The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
31525
31526@subsubheading Example
922fbb7b
AC
31527
31528@smallexample
594fe323 31529(gdb)
a2c02241
NR
31530-exec-next
31531^running
594fe323 31532(gdb)
a2c02241
NR
31533*stopped,reason="end-stepping-range",thread-id="2",line="187",
31534file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 31535(gdb)
a2c02241
NR
31536-thread-list-ids
31537^done,
31538thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31539number-of-threads="3"
594fe323 31540(gdb)
a2c02241
NR
31541-thread-select 3
31542^done,new-thread-id="3",
31543frame=@{level="0",func="vprintf",
31544args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
6d52907e 31545@{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
594fe323 31546(gdb)
922fbb7b
AC
31547@end smallexample
31548
5d77fe44
JB
31549@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31550@node GDB/MI Ada Tasking Commands
31551@section @sc{gdb/mi} Ada Tasking Commands
31552
31553@subheading The @code{-ada-task-info} Command
31554@findex -ada-task-info
31555
31556@subsubheading Synopsis
31557
31558@smallexample
31559 -ada-task-info [ @var{task-id} ]
31560@end smallexample
31561
31562Reports information about either a specific Ada task, if the
31563@var{task-id} parameter is present, or about all Ada tasks.
31564
31565@subsubheading @value{GDBN} Command
31566
31567The @samp{info tasks} command prints the same information
31568about all Ada tasks (@pxref{Ada Tasks}).
31569
31570@subsubheading Result
31571
31572The result is a table of Ada tasks. The following columns are
31573defined for each Ada task:
31574
31575@table @samp
31576@item current
31577This field exists only for the current thread. It has the value @samp{*}.
31578
31579@item id
31580The identifier that @value{GDBN} uses to refer to the Ada task.
31581
31582@item task-id
31583The identifier that the target uses to refer to the Ada task.
31584
31585@item thread-id
5d5658a1
PA
31586The global thread identifier of the thread corresponding to the Ada
31587task.
5d77fe44
JB
31588
31589This field should always exist, as Ada tasks are always implemented
31590on top of a thread. But if @value{GDBN} cannot find this corresponding
31591thread for any reason, the field is omitted.
31592
31593@item parent-id
31594This field exists only when the task was created by another task.
31595In this case, it provides the ID of the parent task.
31596
31597@item priority
31598The base priority of the task.
31599
31600@item state
31601The current state of the task. For a detailed description of the
31602possible states, see @ref{Ada Tasks}.
31603
31604@item name
31605The name of the task.
31606
31607@end table
31608
31609@subsubheading Example
31610
31611@smallexample
31612-ada-task-info
31613^done,tasks=@{nr_rows="3",nr_cols="8",
31614hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
31615@{width="3",alignment="1",col_name="id",colhdr="ID"@},
31616@{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
31617@{width="4",alignment="1",col_name="thread-id",colhdr=""@},
31618@{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
31619@{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
31620@{width="22",alignment="-1",col_name="state",colhdr="State"@},
31621@{width="1",alignment="2",col_name="name",colhdr="Name"@}],
31622body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
31623state="Child Termination Wait",name="main_task"@}]@}
31624(gdb)
31625@end smallexample
31626
a2c02241
NR
31627@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31628@node GDB/MI Program Execution
31629@section @sc{gdb/mi} Program Execution
922fbb7b 31630
ef21caaf 31631These are the asynchronous commands which generate the out-of-band
3f94c067 31632record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
31633asynchronously with remote targets and this interaction is mimicked in
31634other cases.
922fbb7b 31635
922fbb7b
AC
31636@subheading The @code{-exec-continue} Command
31637@findex -exec-continue
31638
31639@subsubheading Synopsis
31640
31641@smallexample
540aa8e7 31642 -exec-continue [--reverse] [--all|--thread-group N]
922fbb7b
AC
31643@end smallexample
31644
540aa8e7
MS
31645Resumes the execution of the inferior program, which will continue
31646to execute until it reaches a debugger stop event. If the
31647@samp{--reverse} option is specified, execution resumes in reverse until
31648it reaches a stop event. Stop events may include
31649@itemize @bullet
31650@item
31651breakpoints or watchpoints
31652@item
31653signals or exceptions
31654@item
31655the end of the process (or its beginning under @samp{--reverse})
31656@item
31657the end or beginning of a replay log if one is being used.
31658@end itemize
31659In all-stop mode (@pxref{All-Stop
31660Mode}), may resume only one thread, or all threads, depending on the
31661value of the @samp{scheduler-locking} variable. If @samp{--all} is
a79b8f6e 31662specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
540aa8e7
MS
31663ignored in all-stop mode. If the @samp{--thread-group} options is
31664specified, then all threads in that thread group are resumed.
922fbb7b
AC
31665
31666@subsubheading @value{GDBN} Command
31667
31668The corresponding @value{GDBN} corresponding is @samp{continue}.
31669
31670@subsubheading Example
31671
31672@smallexample
31673-exec-continue
31674^running
594fe323 31675(gdb)
922fbb7b 31676@@Hello world
a47ec5fe
AR
31677*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
31678func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
6d52907e 31679line="13",arch="i386:x86_64"@}
594fe323 31680(gdb)
922fbb7b
AC
31681@end smallexample
31682
31683
31684@subheading The @code{-exec-finish} Command
31685@findex -exec-finish
31686
31687@subsubheading Synopsis
31688
31689@smallexample
540aa8e7 31690 -exec-finish [--reverse]
922fbb7b
AC
31691@end smallexample
31692
ef21caaf
NR
31693Resumes the execution of the inferior program until the current
31694function is exited. Displays the results returned by the function.
540aa8e7
MS
31695If the @samp{--reverse} option is specified, resumes the reverse
31696execution of the inferior program until the point where current
31697function was called.
922fbb7b
AC
31698
31699@subsubheading @value{GDBN} Command
31700
31701The corresponding @value{GDBN} command is @samp{finish}.
31702
31703@subsubheading Example
31704
31705Function returning @code{void}.
31706
31707@smallexample
31708-exec-finish
31709^running
594fe323 31710(gdb)
922fbb7b
AC
31711@@hello from foo
31712*stopped,reason="function-finished",frame=@{func="main",args=[],
6d52907e 31713file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
594fe323 31714(gdb)
922fbb7b
AC
31715@end smallexample
31716
31717Function returning other than @code{void}. The name of the internal
31718@value{GDBN} variable storing the result is printed, together with the
31719value itself.
31720
31721@smallexample
31722-exec-finish
31723^running
594fe323 31724(gdb)
922fbb7b
AC
31725*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
31726args=[@{name="a",value="1"],@{name="b",value="9"@}@},
6d52907e
JV
31727file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31728arch="i386:x86_64"@},
922fbb7b 31729gdb-result-var="$1",return-value="0"
594fe323 31730(gdb)
922fbb7b
AC
31731@end smallexample
31732
31733
31734@subheading The @code{-exec-interrupt} Command
31735@findex -exec-interrupt
31736
31737@subsubheading Synopsis
31738
31739@smallexample
c3b108f7 31740 -exec-interrupt [--all|--thread-group N]
922fbb7b
AC
31741@end smallexample
31742
ef21caaf
NR
31743Interrupts the background execution of the target. Note how the token
31744associated with the stop message is the one for the execution command
31745that has been interrupted. The token for the interrupt itself only
31746appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
31747interrupt a non-running program, an error message will be printed.
31748
c3b108f7
VP
31749Note that when asynchronous execution is enabled, this command is
31750asynchronous just like other execution commands. That is, first the
31751@samp{^done} response will be printed, and the target stop will be
31752reported after that using the @samp{*stopped} notification.
31753
31754In non-stop mode, only the context thread is interrupted by default.
a79b8f6e
VP
31755All threads (in all inferiors) will be interrupted if the
31756@samp{--all} option is specified. If the @samp{--thread-group}
31757option is specified, all threads in that group will be interrupted.
c3b108f7 31758
922fbb7b
AC
31759@subsubheading @value{GDBN} Command
31760
31761The corresponding @value{GDBN} command is @samp{interrupt}.
31762
31763@subsubheading Example
31764
31765@smallexample
594fe323 31766(gdb)
922fbb7b
AC
31767111-exec-continue
31768111^running
31769
594fe323 31770(gdb)
922fbb7b
AC
31771222-exec-interrupt
31772222^done
594fe323 31773(gdb)
922fbb7b 31774111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 31775frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
6d52907e 31776fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
594fe323 31777(gdb)
922fbb7b 31778
594fe323 31779(gdb)
922fbb7b
AC
31780-exec-interrupt
31781^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 31782(gdb)
922fbb7b
AC
31783@end smallexample
31784
83eba9b7
VP
31785@subheading The @code{-exec-jump} Command
31786@findex -exec-jump
31787
31788@subsubheading Synopsis
31789
31790@smallexample
31791 -exec-jump @var{location}
31792@end smallexample
31793
31794Resumes execution of the inferior program at the location specified by
31795parameter. @xref{Specify Location}, for a description of the
31796different forms of @var{location}.
31797
31798@subsubheading @value{GDBN} Command
31799
31800The corresponding @value{GDBN} command is @samp{jump}.
31801
31802@subsubheading Example
31803
31804@smallexample
31805-exec-jump foo.c:10
31806*running,thread-id="all"
31807^running
31808@end smallexample
31809
922fbb7b
AC
31810
31811@subheading The @code{-exec-next} Command
31812@findex -exec-next
31813
31814@subsubheading Synopsis
31815
31816@smallexample
540aa8e7 31817 -exec-next [--reverse]
922fbb7b
AC
31818@end smallexample
31819
ef21caaf
NR
31820Resumes execution of the inferior program, stopping when the beginning
31821of the next source line is reached.
922fbb7b 31822
540aa8e7
MS
31823If the @samp{--reverse} option is specified, resumes reverse execution
31824of the inferior program, stopping at the beginning of the previous
31825source line. If you issue this command on the first line of a
31826function, it will take you back to the caller of that function, to the
31827source line where the function was called.
31828
31829
922fbb7b
AC
31830@subsubheading @value{GDBN} Command
31831
31832The corresponding @value{GDBN} command is @samp{next}.
31833
31834@subsubheading Example
31835
31836@smallexample
31837-exec-next
31838^running
594fe323 31839(gdb)
922fbb7b 31840*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 31841(gdb)
922fbb7b
AC
31842@end smallexample
31843
31844
31845@subheading The @code{-exec-next-instruction} Command
31846@findex -exec-next-instruction
31847
31848@subsubheading Synopsis
31849
31850@smallexample
540aa8e7 31851 -exec-next-instruction [--reverse]
922fbb7b
AC
31852@end smallexample
31853
ef21caaf
NR
31854Executes one machine instruction. If the instruction is a function
31855call, continues until the function returns. If the program stops at an
31856instruction in the middle of a source line, the address will be
31857printed as well.
922fbb7b 31858
540aa8e7
MS
31859If the @samp{--reverse} option is specified, resumes reverse execution
31860of the inferior program, stopping at the previous instruction. If the
31861previously executed instruction was a return from another function,
31862it will continue to execute in reverse until the call to that function
31863(from the current stack frame) is reached.
31864
922fbb7b
AC
31865@subsubheading @value{GDBN} Command
31866
31867The corresponding @value{GDBN} command is @samp{nexti}.
31868
31869@subsubheading Example
31870
31871@smallexample
594fe323 31872(gdb)
922fbb7b
AC
31873-exec-next-instruction
31874^running
31875
594fe323 31876(gdb)
922fbb7b
AC
31877*stopped,reason="end-stepping-range",
31878addr="0x000100d4",line="5",file="hello.c"
594fe323 31879(gdb)
922fbb7b
AC
31880@end smallexample
31881
31882
31883@subheading The @code{-exec-return} Command
31884@findex -exec-return
31885
31886@subsubheading Synopsis
31887
31888@smallexample
31889 -exec-return
31890@end smallexample
31891
31892Makes current function return immediately. Doesn't execute the inferior.
31893Displays the new current frame.
31894
31895@subsubheading @value{GDBN} Command
31896
31897The corresponding @value{GDBN} command is @samp{return}.
31898
31899@subsubheading Example
31900
31901@smallexample
594fe323 31902(gdb)
922fbb7b
AC
31903200-break-insert callee4
31904200^done,bkpt=@{number="1",addr="0x00010734",
31905file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 31906(gdb)
922fbb7b
AC
31907000-exec-run
31908000^running
594fe323 31909(gdb)
a47ec5fe 31910000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
922fbb7b 31911frame=@{func="callee4",args=[],
76ff342d 31912file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31913fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31914arch="i386:x86_64"@}
594fe323 31915(gdb)
922fbb7b
AC
31916205-break-delete
31917205^done
594fe323 31918(gdb)
922fbb7b
AC
31919111-exec-return
31920111^done,frame=@{level="0",func="callee3",
31921args=[@{name="strarg",
31922value="0x11940 \"A string argument.\""@}],
76ff342d 31923file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31924fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31925arch="i386:x86_64"@}
594fe323 31926(gdb)
922fbb7b
AC
31927@end smallexample
31928
31929
31930@subheading The @code{-exec-run} Command
31931@findex -exec-run
31932
31933@subsubheading Synopsis
31934
31935@smallexample
5713b9b5 31936 -exec-run [ --all | --thread-group N ] [ --start ]
922fbb7b
AC
31937@end smallexample
31938
ef21caaf
NR
31939Starts execution of the inferior from the beginning. The inferior
31940executes until either a breakpoint is encountered or the program
31941exits. In the latter case the output will include an exit code, if
31942the program has exited exceptionally.
922fbb7b 31943
5713b9b5
JB
31944When neither the @samp{--all} nor the @samp{--thread-group} option
31945is specified, the current inferior is started. If the
a79b8f6e
VP
31946@samp{--thread-group} option is specified, it should refer to a thread
31947group of type @samp{process}, and that thread group will be started.
31948If the @samp{--all} option is specified, then all inferiors will be started.
31949
5713b9b5
JB
31950Using the @samp{--start} option instructs the debugger to stop
31951the execution at the start of the inferior's main subprogram,
31952following the same behavior as the @code{start} command
31953(@pxref{Starting}).
31954
922fbb7b
AC
31955@subsubheading @value{GDBN} Command
31956
31957The corresponding @value{GDBN} command is @samp{run}.
31958
ef21caaf 31959@subsubheading Examples
922fbb7b
AC
31960
31961@smallexample
594fe323 31962(gdb)
922fbb7b
AC
31963-break-insert main
31964^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 31965(gdb)
922fbb7b
AC
31966-exec-run
31967^running
594fe323 31968(gdb)
a47ec5fe 31969*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
76ff342d 31970frame=@{func="main",args=[],file="recursive2.c",
6d52907e 31971fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
594fe323 31972(gdb)
922fbb7b
AC
31973@end smallexample
31974
ef21caaf
NR
31975@noindent
31976Program exited normally:
31977
31978@smallexample
594fe323 31979(gdb)
ef21caaf
NR
31980-exec-run
31981^running
594fe323 31982(gdb)
ef21caaf
NR
31983x = 55
31984*stopped,reason="exited-normally"
594fe323 31985(gdb)
ef21caaf
NR
31986@end smallexample
31987
31988@noindent
31989Program exited exceptionally:
31990
31991@smallexample
594fe323 31992(gdb)
ef21caaf
NR
31993-exec-run
31994^running
594fe323 31995(gdb)
ef21caaf
NR
31996x = 55
31997*stopped,reason="exited",exit-code="01"
594fe323 31998(gdb)
ef21caaf
NR
31999@end smallexample
32000
32001Another way the program can terminate is if it receives a signal such as
32002@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
32003
32004@smallexample
594fe323 32005(gdb)
ef21caaf
NR
32006*stopped,reason="exited-signalled",signal-name="SIGINT",
32007signal-meaning="Interrupt"
32008@end smallexample
32009
922fbb7b 32010
a2c02241
NR
32011@c @subheading -exec-signal
32012
32013
32014@subheading The @code{-exec-step} Command
32015@findex -exec-step
922fbb7b
AC
32016
32017@subsubheading Synopsis
32018
32019@smallexample
540aa8e7 32020 -exec-step [--reverse]
922fbb7b
AC
32021@end smallexample
32022
a2c02241
NR
32023Resumes execution of the inferior program, stopping when the beginning
32024of the next source line is reached, if the next source line is not a
32025function call. If it is, stop at the first instruction of the called
540aa8e7
MS
32026function. If the @samp{--reverse} option is specified, resumes reverse
32027execution of the inferior program, stopping at the beginning of the
32028previously executed source line.
922fbb7b
AC
32029
32030@subsubheading @value{GDBN} Command
32031
a2c02241 32032The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
32033
32034@subsubheading Example
32035
32036Stepping into a function:
32037
32038@smallexample
32039-exec-step
32040^running
594fe323 32041(gdb)
922fbb7b
AC
32042*stopped,reason="end-stepping-range",
32043frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 32044@{name="b",value="0"@}],file="recursive2.c",
6d52907e 32045fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
594fe323 32046(gdb)
922fbb7b
AC
32047@end smallexample
32048
32049Regular stepping:
32050
32051@smallexample
32052-exec-step
32053^running
594fe323 32054(gdb)
922fbb7b 32055*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 32056(gdb)
922fbb7b
AC
32057@end smallexample
32058
32059
32060@subheading The @code{-exec-step-instruction} Command
32061@findex -exec-step-instruction
32062
32063@subsubheading Synopsis
32064
32065@smallexample
540aa8e7 32066 -exec-step-instruction [--reverse]
922fbb7b
AC
32067@end smallexample
32068
540aa8e7
MS
32069Resumes the inferior which executes one machine instruction. If the
32070@samp{--reverse} option is specified, resumes reverse execution of the
32071inferior program, stopping at the previously executed instruction.
32072The output, once @value{GDBN} has stopped, will vary depending on
32073whether we have stopped in the middle of a source line or not. In the
32074former case, the address at which the program stopped will be printed
32075as well.
922fbb7b
AC
32076
32077@subsubheading @value{GDBN} Command
32078
32079The corresponding @value{GDBN} command is @samp{stepi}.
32080
32081@subsubheading Example
32082
32083@smallexample
594fe323 32084(gdb)
922fbb7b
AC
32085-exec-step-instruction
32086^running
32087
594fe323 32088(gdb)
922fbb7b 32089*stopped,reason="end-stepping-range",
76ff342d 32090frame=@{func="foo",args=[],file="try.c",
6d52907e 32091fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
594fe323 32092(gdb)
922fbb7b
AC
32093-exec-step-instruction
32094^running
32095
594fe323 32096(gdb)
922fbb7b 32097*stopped,reason="end-stepping-range",
76ff342d 32098frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
6d52907e 32099fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
594fe323 32100(gdb)
922fbb7b
AC
32101@end smallexample
32102
32103
32104@subheading The @code{-exec-until} Command
32105@findex -exec-until
32106
32107@subsubheading Synopsis
32108
32109@smallexample
32110 -exec-until [ @var{location} ]
32111@end smallexample
32112
ef21caaf
NR
32113Executes the inferior until the @var{location} specified in the
32114argument is reached. If there is no argument, the inferior executes
32115until a source line greater than the current one is reached. The
32116reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
32117
32118@subsubheading @value{GDBN} Command
32119
32120The corresponding @value{GDBN} command is @samp{until}.
32121
32122@subsubheading Example
32123
32124@smallexample
594fe323 32125(gdb)
922fbb7b
AC
32126-exec-until recursive2.c:6
32127^running
594fe323 32128(gdb)
922fbb7b
AC
32129x = 55
32130*stopped,reason="location-reached",frame=@{func="main",args=[],
6d52907e
JV
32131file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
32132arch="i386:x86_64"@}
594fe323 32133(gdb)
922fbb7b
AC
32134@end smallexample
32135
32136@ignore
32137@subheading -file-clear
32138Is this going away????
32139@end ignore
32140
351ff01a 32141@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
32142@node GDB/MI Stack Manipulation
32143@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 32144
1e611234
PM
32145@subheading The @code{-enable-frame-filters} Command
32146@findex -enable-frame-filters
32147
32148@smallexample
32149-enable-frame-filters
32150@end smallexample
32151
32152@value{GDBN} allows Python-based frame filters to affect the output of
32153the MI commands relating to stack traces. As there is no way to
32154implement this in a fully backward-compatible way, a front end must
32155request that this functionality be enabled.
32156
32157Once enabled, this feature cannot be disabled.
32158
32159Note that if Python support has not been compiled into @value{GDBN},
32160this command will still succeed (and do nothing).
922fbb7b 32161
a2c02241
NR
32162@subheading The @code{-stack-info-frame} Command
32163@findex -stack-info-frame
922fbb7b
AC
32164
32165@subsubheading Synopsis
32166
32167@smallexample
a2c02241 32168 -stack-info-frame
922fbb7b
AC
32169@end smallexample
32170
a2c02241 32171Get info on the selected frame.
922fbb7b
AC
32172
32173@subsubheading @value{GDBN} Command
32174
a2c02241
NR
32175The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
32176(without arguments).
922fbb7b
AC
32177
32178@subsubheading Example
32179
32180@smallexample
594fe323 32181(gdb)
a2c02241
NR
32182-stack-info-frame
32183^done,frame=@{level="1",addr="0x0001076c",func="callee3",
32184file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32185fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
32186arch="i386:x86_64"@}
594fe323 32187(gdb)
922fbb7b
AC
32188@end smallexample
32189
a2c02241
NR
32190@subheading The @code{-stack-info-depth} Command
32191@findex -stack-info-depth
922fbb7b
AC
32192
32193@subsubheading Synopsis
32194
32195@smallexample
a2c02241 32196 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
32197@end smallexample
32198
a2c02241
NR
32199Return the depth of the stack. If the integer argument @var{max-depth}
32200is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
32201
32202@subsubheading @value{GDBN} Command
32203
a2c02241 32204There's no equivalent @value{GDBN} command.
922fbb7b
AC
32205
32206@subsubheading Example
32207
a2c02241
NR
32208For a stack with frame levels 0 through 11:
32209
922fbb7b 32210@smallexample
594fe323 32211(gdb)
a2c02241
NR
32212-stack-info-depth
32213^done,depth="12"
594fe323 32214(gdb)
a2c02241
NR
32215-stack-info-depth 4
32216^done,depth="4"
594fe323 32217(gdb)
a2c02241
NR
32218-stack-info-depth 12
32219^done,depth="12"
594fe323 32220(gdb)
a2c02241
NR
32221-stack-info-depth 11
32222^done,depth="11"
594fe323 32223(gdb)
a2c02241
NR
32224-stack-info-depth 13
32225^done,depth="12"
594fe323 32226(gdb)
922fbb7b
AC
32227@end smallexample
32228
1e611234 32229@anchor{-stack-list-arguments}
a2c02241
NR
32230@subheading The @code{-stack-list-arguments} Command
32231@findex -stack-list-arguments
922fbb7b
AC
32232
32233@subsubheading Synopsis
32234
32235@smallexample
6211c335 32236 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
a2c02241 32237 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
32238@end smallexample
32239
a2c02241
NR
32240Display a list of the arguments for the frames between @var{low-frame}
32241and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
32242@var{high-frame} are not provided, list the arguments for the whole
32243call stack. If the two arguments are equal, show the single frame
32244at the corresponding level. It is an error if @var{low-frame} is
32245larger than the actual number of frames. On the other hand,
32246@var{high-frame} may be larger than the actual number of frames, in
32247which case only existing frames will be returned.
a2c02241 32248
3afae151
VP
32249If @var{print-values} is 0 or @code{--no-values}, print only the names of
32250the variables; if it is 1 or @code{--all-values}, print also their
32251values; and if it is 2 or @code{--simple-values}, print the name,
32252type and value for simple data types, and the name and type for arrays,
1e611234
PM
32253structures and unions. If the option @code{--no-frame-filters} is
32254supplied, then Python frame filters will not be executed.
32255
6211c335
YQ
32256If the @code{--skip-unavailable} option is specified, arguments that
32257are not available are not listed. Partially available arguments
32258are still displayed, however.
922fbb7b 32259
b3372f91
VP
32260Use of this command to obtain arguments in a single frame is
32261deprecated in favor of the @samp{-stack-list-variables} command.
32262
922fbb7b
AC
32263@subsubheading @value{GDBN} Command
32264
a2c02241
NR
32265@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
32266@samp{gdb_get_args} command which partially overlaps with the
32267functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
32268
32269@subsubheading Example
922fbb7b 32270
a2c02241 32271@smallexample
594fe323 32272(gdb)
a2c02241
NR
32273-stack-list-frames
32274^done,
32275stack=[
32276frame=@{level="0",addr="0x00010734",func="callee4",
32277file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32278fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
32279arch="i386:x86_64"@},
a2c02241
NR
32280frame=@{level="1",addr="0x0001076c",func="callee3",
32281file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32282fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
32283arch="i386:x86_64"@},
a2c02241
NR
32284frame=@{level="2",addr="0x0001078c",func="callee2",
32285file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32286fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
32287arch="i386:x86_64"@},
a2c02241
NR
32288frame=@{level="3",addr="0x000107b4",func="callee1",
32289file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32290fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
32291arch="i386:x86_64"@},
a2c02241
NR
32292frame=@{level="4",addr="0x000107e0",func="main",
32293file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32294fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
32295arch="i386:x86_64"@}]
594fe323 32296(gdb)
a2c02241
NR
32297-stack-list-arguments 0
32298^done,
32299stack-args=[
32300frame=@{level="0",args=[]@},
32301frame=@{level="1",args=[name="strarg"]@},
32302frame=@{level="2",args=[name="intarg",name="strarg"]@},
32303frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
32304frame=@{level="4",args=[]@}]
594fe323 32305(gdb)
a2c02241
NR
32306-stack-list-arguments 1
32307^done,
32308stack-args=[
32309frame=@{level="0",args=[]@},
32310frame=@{level="1",
32311 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32312frame=@{level="2",args=[
32313@{name="intarg",value="2"@},
32314@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32315@{frame=@{level="3",args=[
32316@{name="intarg",value="2"@},
32317@{name="strarg",value="0x11940 \"A string argument.\""@},
32318@{name="fltarg",value="3.5"@}]@},
32319frame=@{level="4",args=[]@}]
594fe323 32320(gdb)
a2c02241
NR
32321-stack-list-arguments 0 2 2
32322^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 32323(gdb)
a2c02241
NR
32324-stack-list-arguments 1 2 2
32325^done,stack-args=[frame=@{level="2",
32326args=[@{name="intarg",value="2"@},
32327@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 32328(gdb)
a2c02241
NR
32329@end smallexample
32330
32331@c @subheading -stack-list-exception-handlers
922fbb7b 32332
a2c02241 32333
1e611234 32334@anchor{-stack-list-frames}
a2c02241
NR
32335@subheading The @code{-stack-list-frames} Command
32336@findex -stack-list-frames
1abaf70c
BR
32337
32338@subsubheading Synopsis
32339
32340@smallexample
1e611234 32341 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
1abaf70c
BR
32342@end smallexample
32343
a2c02241
NR
32344List the frames currently on the stack. For each frame it displays the
32345following info:
32346
32347@table @samp
32348@item @var{level}
d3e8051b 32349The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
32350@item @var{addr}
32351The @code{$pc} value for that frame.
32352@item @var{func}
32353Function name.
32354@item @var{file}
32355File name of the source file where the function lives.
7d288aaa
TT
32356@item @var{fullname}
32357The full file name of the source file where the function lives.
a2c02241
NR
32358@item @var{line}
32359Line number corresponding to the @code{$pc}.
7d288aaa
TT
32360@item @var{from}
32361The shared library where this function is defined. This is only given
32362if the frame's function is not known.
6d52907e
JV
32363@item @var{arch}
32364Frame's architecture.
a2c02241
NR
32365@end table
32366
32367If invoked without arguments, this command prints a backtrace for the
32368whole stack. If given two integer arguments, it shows the frames whose
32369levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
32370are equal, it shows the single frame at the corresponding level. It is
32371an error if @var{low-frame} is larger than the actual number of
a5451f4e 32372frames. On the other hand, @var{high-frame} may be larger than the
1e611234
PM
32373actual number of frames, in which case only existing frames will be
32374returned. If the option @code{--no-frame-filters} is supplied, then
32375Python frame filters will not be executed.
1abaf70c
BR
32376
32377@subsubheading @value{GDBN} Command
32378
a2c02241 32379The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
32380
32381@subsubheading Example
32382
a2c02241
NR
32383Full stack backtrace:
32384
1abaf70c 32385@smallexample
594fe323 32386(gdb)
a2c02241
NR
32387-stack-list-frames
32388^done,stack=
32389[frame=@{level="0",addr="0x0001076c",func="foo",
6d52907e
JV
32390 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
32391 arch="i386:x86_64"@},
a2c02241 32392frame=@{level="1",addr="0x000107a4",func="foo",
6d52907e
JV
32393 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32394 arch="i386:x86_64"@},
a2c02241 32395frame=@{level="2",addr="0x000107a4",func="foo",
6d52907e
JV
32396 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32397 arch="i386:x86_64"@},
a2c02241 32398frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
32399 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32400 arch="i386:x86_64"@},
a2c02241 32401frame=@{level="4",addr="0x000107a4",func="foo",
6d52907e
JV
32402 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32403 arch="i386:x86_64"@},
a2c02241 32404frame=@{level="5",addr="0x000107a4",func="foo",
6d52907e
JV
32405 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32406 arch="i386:x86_64"@},
a2c02241 32407frame=@{level="6",addr="0x000107a4",func="foo",
6d52907e
JV
32408 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32409 arch="i386:x86_64"@},
a2c02241 32410frame=@{level="7",addr="0x000107a4",func="foo",
6d52907e
JV
32411 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32412 arch="i386:x86_64"@},
a2c02241 32413frame=@{level="8",addr="0x000107a4",func="foo",
6d52907e
JV
32414 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32415 arch="i386:x86_64"@},
a2c02241 32416frame=@{level="9",addr="0x000107a4",func="foo",
6d52907e
JV
32417 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32418 arch="i386:x86_64"@},
a2c02241 32419frame=@{level="10",addr="0x000107a4",func="foo",
6d52907e
JV
32420 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32421 arch="i386:x86_64"@},
a2c02241 32422frame=@{level="11",addr="0x00010738",func="main",
6d52907e
JV
32423 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
32424 arch="i386:x86_64"@}]
594fe323 32425(gdb)
1abaf70c
BR
32426@end smallexample
32427
a2c02241 32428Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 32429
a2c02241 32430@smallexample
594fe323 32431(gdb)
a2c02241
NR
32432-stack-list-frames 3 5
32433^done,stack=
32434[frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
32435 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32436 arch="i386:x86_64"@},
a2c02241 32437frame=@{level="4",addr="0x000107a4",func="foo",
6d52907e
JV
32438 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32439 arch="i386:x86_64"@},
a2c02241 32440frame=@{level="5",addr="0x000107a4",func="foo",
6d52907e
JV
32441 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32442 arch="i386:x86_64"@}]
594fe323 32443(gdb)
a2c02241 32444@end smallexample
922fbb7b 32445
a2c02241 32446Show a single frame:
922fbb7b
AC
32447
32448@smallexample
594fe323 32449(gdb)
a2c02241
NR
32450-stack-list-frames 3 3
32451^done,stack=
32452[frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
32453 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32454 arch="i386:x86_64"@}]
594fe323 32455(gdb)
922fbb7b
AC
32456@end smallexample
32457
922fbb7b 32458
a2c02241
NR
32459@subheading The @code{-stack-list-locals} Command
32460@findex -stack-list-locals
1e611234 32461@anchor{-stack-list-locals}
57c22c6c 32462
a2c02241 32463@subsubheading Synopsis
922fbb7b
AC
32464
32465@smallexample
6211c335 32466 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
922fbb7b
AC
32467@end smallexample
32468
a2c02241
NR
32469Display the local variable names for the selected frame. If
32470@var{print-values} is 0 or @code{--no-values}, print only the names of
32471the variables; if it is 1 or @code{--all-values}, print also their
32472values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 32473type and value for simple data types, and the name and type for arrays,
a2c02241
NR
32474structures and unions. In this last case, a frontend can immediately
32475display the value of simple data types and create variable objects for
d3e8051b 32476other data types when the user wishes to explore their values in
1e611234
PM
32477more detail. If the option @code{--no-frame-filters} is supplied, then
32478Python frame filters will not be executed.
922fbb7b 32479
6211c335
YQ
32480If the @code{--skip-unavailable} option is specified, local variables
32481that are not available are not listed. Partially available local
32482variables are still displayed, however.
32483
b3372f91
VP
32484This command is deprecated in favor of the
32485@samp{-stack-list-variables} command.
32486
922fbb7b
AC
32487@subsubheading @value{GDBN} Command
32488
a2c02241 32489@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
32490
32491@subsubheading Example
922fbb7b
AC
32492
32493@smallexample
594fe323 32494(gdb)
a2c02241
NR
32495-stack-list-locals 0
32496^done,locals=[name="A",name="B",name="C"]
594fe323 32497(gdb)
a2c02241
NR
32498-stack-list-locals --all-values
32499^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
32500 @{name="C",value="@{1, 2, 3@}"@}]
32501-stack-list-locals --simple-values
32502^done,locals=[@{name="A",type="int",value="1"@},
32503 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 32504(gdb)
922fbb7b
AC
32505@end smallexample
32506
1e611234 32507@anchor{-stack-list-variables}
b3372f91
VP
32508@subheading The @code{-stack-list-variables} Command
32509@findex -stack-list-variables
32510
32511@subsubheading Synopsis
32512
32513@smallexample
6211c335 32514 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
b3372f91
VP
32515@end smallexample
32516
32517Display the names of local variables and function arguments for the selected frame. If
32518@var{print-values} is 0 or @code{--no-values}, print only the names of
32519the variables; if it is 1 or @code{--all-values}, print also their
32520values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 32521type and value for simple data types, and the name and type for arrays,
1e611234
PM
32522structures and unions. If the option @code{--no-frame-filters} is
32523supplied, then Python frame filters will not be executed.
b3372f91 32524
6211c335
YQ
32525If the @code{--skip-unavailable} option is specified, local variables
32526and arguments that are not available are not listed. Partially
32527available arguments and local variables are still displayed, however.
32528
b3372f91
VP
32529@subsubheading Example
32530
32531@smallexample
32532(gdb)
32533-stack-list-variables --thread 1 --frame 0 --all-values
4f412fd0 32534^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
b3372f91
VP
32535(gdb)
32536@end smallexample
32537
922fbb7b 32538
a2c02241
NR
32539@subheading The @code{-stack-select-frame} Command
32540@findex -stack-select-frame
922fbb7b
AC
32541
32542@subsubheading Synopsis
32543
32544@smallexample
a2c02241 32545 -stack-select-frame @var{framenum}
922fbb7b
AC
32546@end smallexample
32547
a2c02241
NR
32548Change the selected frame. Select a different frame @var{framenum} on
32549the stack.
922fbb7b 32550
c3b108f7
VP
32551This command in deprecated in favor of passing the @samp{--frame}
32552option to every command.
32553
922fbb7b
AC
32554@subsubheading @value{GDBN} Command
32555
a2c02241
NR
32556The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
32557@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
32558
32559@subsubheading Example
32560
32561@smallexample
594fe323 32562(gdb)
a2c02241 32563-stack-select-frame 2
922fbb7b 32564^done
594fe323 32565(gdb)
922fbb7b
AC
32566@end smallexample
32567
32568@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
32569@node GDB/MI Variable Objects
32570@section @sc{gdb/mi} Variable Objects
922fbb7b 32571
a1b5960f 32572@ignore
922fbb7b 32573
a2c02241 32574@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 32575
a2c02241
NR
32576For the implementation of a variable debugger window (locals, watched
32577expressions, etc.), we are proposing the adaptation of the existing code
32578used by @code{Insight}.
922fbb7b 32579
a2c02241 32580The two main reasons for that are:
922fbb7b 32581
a2c02241
NR
32582@enumerate 1
32583@item
32584It has been proven in practice (it is already on its second generation).
922fbb7b 32585
a2c02241
NR
32586@item
32587It will shorten development time (needless to say how important it is
32588now).
32589@end enumerate
922fbb7b 32590
a2c02241
NR
32591The original interface was designed to be used by Tcl code, so it was
32592slightly changed so it could be used through @sc{gdb/mi}. This section
32593describes the @sc{gdb/mi} operations that will be available and gives some
32594hints about their use.
922fbb7b 32595
a2c02241
NR
32596@emph{Note}: In addition to the set of operations described here, we
32597expect the @sc{gui} implementation of a variable window to require, at
32598least, the following operations:
922fbb7b 32599
a2c02241
NR
32600@itemize @bullet
32601@item @code{-gdb-show} @code{output-radix}
32602@item @code{-stack-list-arguments}
32603@item @code{-stack-list-locals}
32604@item @code{-stack-select-frame}
32605@end itemize
922fbb7b 32606
a1b5960f
VP
32607@end ignore
32608
c8b2f53c 32609@subheading Introduction to Variable Objects
922fbb7b 32610
a2c02241 32611@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
32612
32613Variable objects are "object-oriented" MI interface for examining and
32614changing values of expressions. Unlike some other MI interfaces that
32615work with expressions, variable objects are specifically designed for
32616simple and efficient presentation in the frontend. A variable object
32617is identified by string name. When a variable object is created, the
32618frontend specifies the expression for that variable object. The
32619expression can be a simple variable, or it can be an arbitrary complex
32620expression, and can even involve CPU registers. After creating a
32621variable object, the frontend can invoke other variable object
32622operations---for example to obtain or change the value of a variable
32623object, or to change display format.
32624
32625Variable objects have hierarchical tree structure. Any variable object
32626that corresponds to a composite type, such as structure in C, has
32627a number of child variable objects, for example corresponding to each
32628element of a structure. A child variable object can itself have
32629children, recursively. Recursion ends when we reach
25d5ea92
VP
32630leaf variable objects, which always have built-in types. Child variable
32631objects are created only by explicit request, so if a frontend
32632is not interested in the children of a particular variable object, no
32633child will be created.
c8b2f53c
VP
32634
32635For a leaf variable object it is possible to obtain its value as a
32636string, or set the value from a string. String value can be also
32637obtained for a non-leaf variable object, but it's generally a string
32638that only indicates the type of the object, and does not list its
32639contents. Assignment to a non-leaf variable object is not allowed.
32640
32641A frontend does not need to read the values of all variable objects each time
32642the program stops. Instead, MI provides an update command that lists all
32643variable objects whose values has changed since the last update
32644operation. This considerably reduces the amount of data that must
25d5ea92
VP
32645be transferred to the frontend. As noted above, children variable
32646objects are created on demand, and only leaf variable objects have a
32647real value. As result, gdb will read target memory only for leaf
32648variables that frontend has created.
32649
32650The automatic update is not always desirable. For example, a frontend
32651might want to keep a value of some expression for future reference,
32652and never update it. For another example, fetching memory is
32653relatively slow for embedded targets, so a frontend might want
32654to disable automatic update for the variables that are either not
32655visible on the screen, or ``closed''. This is possible using so
32656called ``frozen variable objects''. Such variable objects are never
32657implicitly updated.
922fbb7b 32658
c3b108f7
VP
32659Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
32660fixed variable object, the expression is parsed when the variable
32661object is created, including associating identifiers to specific
32662variables. The meaning of expression never changes. For a floating
32663variable object the values of variables whose names appear in the
32664expressions are re-evaluated every time in the context of the current
32665frame. Consider this example:
32666
32667@smallexample
32668void do_work(...)
32669@{
32670 struct work_state state;
32671
32672 if (...)
32673 do_work(...);
32674@}
32675@end smallexample
32676
32677If a fixed variable object for the @code{state} variable is created in
7a9dd1b2 32678this function, and we enter the recursive call, the variable
c3b108f7
VP
32679object will report the value of @code{state} in the top-level
32680@code{do_work} invocation. On the other hand, a floating variable
32681object will report the value of @code{state} in the current frame.
32682
32683If an expression specified when creating a fixed variable object
32684refers to a local variable, the variable object becomes bound to the
32685thread and frame in which the variable object is created. When such
32686variable object is updated, @value{GDBN} makes sure that the
32687thread/frame combination the variable object is bound to still exists,
32688and re-evaluates the variable object in context of that thread/frame.
32689
a2c02241
NR
32690The following is the complete set of @sc{gdb/mi} operations defined to
32691access this functionality:
922fbb7b 32692
a2c02241
NR
32693@multitable @columnfractions .4 .6
32694@item @strong{Operation}
32695@tab @strong{Description}
922fbb7b 32696
0cc7d26f
TT
32697@item @code{-enable-pretty-printing}
32698@tab enable Python-based pretty-printing
a2c02241
NR
32699@item @code{-var-create}
32700@tab create a variable object
32701@item @code{-var-delete}
22d8a470 32702@tab delete the variable object and/or its children
a2c02241
NR
32703@item @code{-var-set-format}
32704@tab set the display format of this variable
32705@item @code{-var-show-format}
32706@tab show the display format of this variable
32707@item @code{-var-info-num-children}
32708@tab tells how many children this object has
32709@item @code{-var-list-children}
32710@tab return a list of the object's children
32711@item @code{-var-info-type}
32712@tab show the type of this variable object
32713@item @code{-var-info-expression}
02142340
VP
32714@tab print parent-relative expression that this variable object represents
32715@item @code{-var-info-path-expression}
32716@tab print full expression that this variable object represents
a2c02241
NR
32717@item @code{-var-show-attributes}
32718@tab is this variable editable? does it exist here?
32719@item @code{-var-evaluate-expression}
32720@tab get the value of this variable
32721@item @code{-var-assign}
32722@tab set the value of this variable
32723@item @code{-var-update}
32724@tab update the variable and its children
25d5ea92 32725@item @code{-var-set-frozen}
6b92c0d3 32726@tab set frozenness attribute
0cc7d26f
TT
32727@item @code{-var-set-update-range}
32728@tab set range of children to display on update
a2c02241 32729@end multitable
922fbb7b 32730
a2c02241
NR
32731In the next subsection we describe each operation in detail and suggest
32732how it can be used.
922fbb7b 32733
a2c02241 32734@subheading Description And Use of Operations on Variable Objects
922fbb7b 32735
0cc7d26f
TT
32736@subheading The @code{-enable-pretty-printing} Command
32737@findex -enable-pretty-printing
32738
32739@smallexample
32740-enable-pretty-printing
32741@end smallexample
32742
32743@value{GDBN} allows Python-based visualizers to affect the output of the
32744MI variable object commands. However, because there was no way to
32745implement this in a fully backward-compatible way, a front end must
32746request that this functionality be enabled.
32747
32748Once enabled, this feature cannot be disabled.
32749
32750Note that if Python support has not been compiled into @value{GDBN},
32751this command will still succeed (and do nothing).
32752
f43030c4
TT
32753This feature is currently (as of @value{GDBN} 7.0) experimental, and
32754may work differently in future versions of @value{GDBN}.
32755
a2c02241
NR
32756@subheading The @code{-var-create} Command
32757@findex -var-create
ef21caaf 32758
a2c02241 32759@subsubheading Synopsis
ef21caaf 32760
a2c02241
NR
32761@smallexample
32762 -var-create @{@var{name} | "-"@}
c3b108f7 32763 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
a2c02241
NR
32764@end smallexample
32765
32766This operation creates a variable object, which allows the monitoring of
32767a variable, the result of an expression, a memory cell or a CPU
32768register.
ef21caaf 32769
a2c02241
NR
32770The @var{name} parameter is the string by which the object can be
32771referenced. It must be unique. If @samp{-} is specified, the varobj
32772system will generate a string ``varNNNNNN'' automatically. It will be
c3b108f7 32773unique provided that one does not specify @var{name} of that format.
a2c02241 32774The command fails if a duplicate name is found.
ef21caaf 32775
a2c02241
NR
32776The frame under which the expression should be evaluated can be
32777specified by @var{frame-addr}. A @samp{*} indicates that the current
c3b108f7
VP
32778frame should be used. A @samp{@@} indicates that a floating variable
32779object must be created.
922fbb7b 32780
a2c02241
NR
32781@var{expression} is any expression valid on the current language set (must not
32782begin with a @samp{*}), or one of the following:
922fbb7b 32783
a2c02241
NR
32784@itemize @bullet
32785@item
32786@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 32787
a2c02241
NR
32788@item
32789@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 32790
a2c02241
NR
32791@item
32792@samp{$@var{regname}} --- a CPU register name
32793@end itemize
922fbb7b 32794
0cc7d26f
TT
32795@cindex dynamic varobj
32796A varobj's contents may be provided by a Python-based pretty-printer. In this
32797case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
32798have slightly different semantics in some cases. If the
32799@code{-enable-pretty-printing} command is not sent, then @value{GDBN}
32800will never create a dynamic varobj. This ensures backward
32801compatibility for existing clients.
32802
a2c02241 32803@subsubheading Result
922fbb7b 32804
0cc7d26f
TT
32805This operation returns attributes of the newly-created varobj. These
32806are:
32807
32808@table @samp
32809@item name
32810The name of the varobj.
32811
32812@item numchild
32813The number of children of the varobj. This number is not necessarily
32814reliable for a dynamic varobj. Instead, you must examine the
32815@samp{has_more} attribute.
32816
32817@item value
32818The varobj's scalar value. For a varobj whose type is some sort of
32819aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
32820will not be interesting.
32821
32822@item type
32823The varobj's type. This is a string representation of the type, as
8264ba82
AG
32824would be printed by the @value{GDBN} CLI. If @samp{print object}
32825(@pxref{Print Settings, set print object}) is set to @code{on}, the
32826@emph{actual} (derived) type of the object is shown rather than the
32827@emph{declared} one.
0cc7d26f
TT
32828
32829@item thread-id
32830If a variable object is bound to a specific thread, then this is the
5d5658a1 32831thread's global identifier.
0cc7d26f
TT
32832
32833@item has_more
32834For a dynamic varobj, this indicates whether there appear to be any
32835children available. For a non-dynamic varobj, this will be 0.
32836
32837@item dynamic
32838This attribute will be present and have the value @samp{1} if the
32839varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32840then this attribute will not be present.
32841
32842@item displayhint
32843A dynamic varobj can supply a display hint to the front end. The
32844value comes directly from the Python pretty-printer object's
4c374409 32845@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
32846@end table
32847
32848Typical output will look like this:
922fbb7b
AC
32849
32850@smallexample
0cc7d26f
TT
32851 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
32852 has_more="@var{has_more}"
dcaaae04
NR
32853@end smallexample
32854
a2c02241
NR
32855
32856@subheading The @code{-var-delete} Command
32857@findex -var-delete
922fbb7b
AC
32858
32859@subsubheading Synopsis
32860
32861@smallexample
22d8a470 32862 -var-delete [ -c ] @var{name}
922fbb7b
AC
32863@end smallexample
32864
a2c02241 32865Deletes a previously created variable object and all of its children.
22d8a470 32866With the @samp{-c} option, just deletes the children.
922fbb7b 32867
a2c02241 32868Returns an error if the object @var{name} is not found.
922fbb7b 32869
922fbb7b 32870
a2c02241
NR
32871@subheading The @code{-var-set-format} Command
32872@findex -var-set-format
922fbb7b 32873
a2c02241 32874@subsubheading Synopsis
922fbb7b
AC
32875
32876@smallexample
a2c02241 32877 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
32878@end smallexample
32879
a2c02241
NR
32880Sets the output format for the value of the object @var{name} to be
32881@var{format-spec}.
32882
de051565 32883@anchor{-var-set-format}
a2c02241
NR
32884The syntax for the @var{format-spec} is as follows:
32885
32886@smallexample
32887 @var{format-spec} @expansion{}
1c35a88f 32888 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
a2c02241
NR
32889@end smallexample
32890
c8b2f53c
VP
32891The natural format is the default format choosen automatically
32892based on the variable type (like decimal for an @code{int}, hex
32893for pointers, etc.).
32894
1c35a88f
LM
32895The zero-hexadecimal format has a representation similar to hexadecimal
32896but with padding zeroes to the left of the value. For example, a 32-bit
32897hexadecimal value of 0x1234 would be represented as 0x00001234 in the
32898zero-hexadecimal format.
32899
c8b2f53c
VP
32900For a variable with children, the format is set only on the
32901variable itself, and the children are not affected.
a2c02241
NR
32902
32903@subheading The @code{-var-show-format} Command
32904@findex -var-show-format
922fbb7b
AC
32905
32906@subsubheading Synopsis
32907
32908@smallexample
a2c02241 32909 -var-show-format @var{name}
922fbb7b
AC
32910@end smallexample
32911
a2c02241 32912Returns the format used to display the value of the object @var{name}.
922fbb7b 32913
a2c02241
NR
32914@smallexample
32915 @var{format} @expansion{}
32916 @var{format-spec}
32917@end smallexample
922fbb7b 32918
922fbb7b 32919
a2c02241
NR
32920@subheading The @code{-var-info-num-children} Command
32921@findex -var-info-num-children
32922
32923@subsubheading Synopsis
32924
32925@smallexample
32926 -var-info-num-children @var{name}
32927@end smallexample
32928
32929Returns the number of children of a variable object @var{name}:
32930
32931@smallexample
32932 numchild=@var{n}
32933@end smallexample
32934
0cc7d26f
TT
32935Note that this number is not completely reliable for a dynamic varobj.
32936It will return the current number of children, but more children may
32937be available.
32938
a2c02241
NR
32939
32940@subheading The @code{-var-list-children} Command
32941@findex -var-list-children
32942
32943@subsubheading Synopsis
32944
32945@smallexample
0cc7d26f 32946 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
a2c02241 32947@end smallexample
b569d230 32948@anchor{-var-list-children}
a2c02241
NR
32949
32950Return a list of the children of the specified variable object and
32951create variable objects for them, if they do not already exist. With
f5011d11 32952a single argument or if @var{print-values} has a value of 0 or
a2c02241
NR
32953@code{--no-values}, print only the names of the variables; if
32954@var{print-values} is 1 or @code{--all-values}, also print their
32955values; and if it is 2 or @code{--simple-values} print the name and
32956value for simple data types and just the name for arrays, structures
32957and unions.
922fbb7b 32958
0cc7d26f
TT
32959@var{from} and @var{to}, if specified, indicate the range of children
32960to report. If @var{from} or @var{to} is less than zero, the range is
32961reset and all children will be reported. Otherwise, children starting
32962at @var{from} (zero-based) and up to and excluding @var{to} will be
32963reported.
32964
32965If a child range is requested, it will only affect the current call to
32966@code{-var-list-children}, but not future calls to @code{-var-update}.
32967For this, you must instead use @code{-var-set-update-range}. The
32968intent of this approach is to enable a front end to implement any
32969update approach it likes; for example, scrolling a view may cause the
32970front end to request more children with @code{-var-list-children}, and
32971then the front end could call @code{-var-set-update-range} with a
32972different range to ensure that future updates are restricted to just
32973the visible items.
32974
b569d230
EZ
32975For each child the following results are returned:
32976
32977@table @var
32978
32979@item name
32980Name of the variable object created for this child.
32981
32982@item exp
32983The expression to be shown to the user by the front end to designate this child.
32984For example this may be the name of a structure member.
32985
0cc7d26f
TT
32986For a dynamic varobj, this value cannot be used to form an
32987expression. There is no way to do this at all with a dynamic varobj.
32988
b569d230
EZ
32989For C/C@t{++} structures there are several pseudo children returned to
32990designate access qualifiers. For these pseudo children @var{exp} is
32991@samp{public}, @samp{private}, or @samp{protected}. In this case the
32992type and value are not present.
32993
0cc7d26f
TT
32994A dynamic varobj will not report the access qualifying
32995pseudo-children, regardless of the language. This information is not
32996available at all with a dynamic varobj.
32997
b569d230 32998@item numchild
0cc7d26f
TT
32999Number of children this child has. For a dynamic varobj, this will be
330000.
b569d230
EZ
33001
33002@item type
8264ba82
AG
33003The type of the child. If @samp{print object}
33004(@pxref{Print Settings, set print object}) is set to @code{on}, the
33005@emph{actual} (derived) type of the object is shown rather than the
33006@emph{declared} one.
b569d230
EZ
33007
33008@item value
33009If values were requested, this is the value.
33010
33011@item thread-id
5d5658a1
PA
33012If this variable object is associated with a thread, this is the
33013thread's global thread id. Otherwise this result is not present.
b569d230
EZ
33014
33015@item frozen
33016If the variable object is frozen, this variable will be present with a value of 1.
c78feb39 33017
9df9dbe0
YQ
33018@item displayhint
33019A dynamic varobj can supply a display hint to the front end. The
33020value comes directly from the Python pretty-printer object's
33021@code{display_hint} method. @xref{Pretty Printing API}.
33022
c78feb39
YQ
33023@item dynamic
33024This attribute will be present and have the value @samp{1} if the
33025varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33026then this attribute will not be present.
33027
b569d230
EZ
33028@end table
33029
0cc7d26f
TT
33030The result may have its own attributes:
33031
33032@table @samp
33033@item displayhint
33034A dynamic varobj can supply a display hint to the front end. The
33035value comes directly from the Python pretty-printer object's
4c374409 33036@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
33037
33038@item has_more
33039This is an integer attribute which is nonzero if there are children
33040remaining after the end of the selected range.
33041@end table
33042
922fbb7b
AC
33043@subsubheading Example
33044
33045@smallexample
594fe323 33046(gdb)
a2c02241 33047 -var-list-children n
b569d230 33048 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 33049 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 33050(gdb)
a2c02241 33051 -var-list-children --all-values n
b569d230 33052 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 33053 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
33054@end smallexample
33055
922fbb7b 33056
a2c02241
NR
33057@subheading The @code{-var-info-type} Command
33058@findex -var-info-type
922fbb7b 33059
a2c02241
NR
33060@subsubheading Synopsis
33061
33062@smallexample
33063 -var-info-type @var{name}
33064@end smallexample
33065
33066Returns the type of the specified variable @var{name}. The type is
33067returned as a string in the same format as it is output by the
33068@value{GDBN} CLI:
33069
33070@smallexample
33071 type=@var{typename}
33072@end smallexample
33073
33074
33075@subheading The @code{-var-info-expression} Command
33076@findex -var-info-expression
922fbb7b
AC
33077
33078@subsubheading Synopsis
33079
33080@smallexample
a2c02241 33081 -var-info-expression @var{name}
922fbb7b
AC
33082@end smallexample
33083
02142340
VP
33084Returns a string that is suitable for presenting this
33085variable object in user interface. The string is generally
33086not valid expression in the current language, and cannot be evaluated.
33087
33088For example, if @code{a} is an array, and variable object
33089@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 33090
a2c02241 33091@smallexample
02142340
VP
33092(gdb) -var-info-expression A.1
33093^done,lang="C",exp="1"
a2c02241 33094@end smallexample
922fbb7b 33095
a2c02241 33096@noindent
fa4d0c40
YQ
33097Here, the value of @code{lang} is the language name, which can be
33098found in @ref{Supported Languages}.
02142340
VP
33099
33100Note that the output of the @code{-var-list-children} command also
33101includes those expressions, so the @code{-var-info-expression} command
33102is of limited use.
33103
33104@subheading The @code{-var-info-path-expression} Command
33105@findex -var-info-path-expression
33106
33107@subsubheading Synopsis
33108
33109@smallexample
33110 -var-info-path-expression @var{name}
33111@end smallexample
33112
33113Returns an expression that can be evaluated in the current
33114context and will yield the same value that a variable object has.
33115Compare this with the @code{-var-info-expression} command, which
33116result can be used only for UI presentation. Typical use of
33117the @code{-var-info-path-expression} command is creating a
33118watchpoint from a variable object.
33119
0cc7d26f
TT
33120This command is currently not valid for children of a dynamic varobj,
33121and will give an error when invoked on one.
33122
02142340
VP
33123For example, suppose @code{C} is a C@t{++} class, derived from class
33124@code{Base}, and that the @code{Base} class has a member called
33125@code{m_size}. Assume a variable @code{c} is has the type of
33126@code{C} and a variable object @code{C} was created for variable
33127@code{c}. Then, we'll get this output:
33128@smallexample
33129(gdb) -var-info-path-expression C.Base.public.m_size
33130^done,path_expr=((Base)c).m_size)
33131@end smallexample
922fbb7b 33132
a2c02241
NR
33133@subheading The @code{-var-show-attributes} Command
33134@findex -var-show-attributes
922fbb7b 33135
a2c02241 33136@subsubheading Synopsis
922fbb7b 33137
a2c02241
NR
33138@smallexample
33139 -var-show-attributes @var{name}
33140@end smallexample
922fbb7b 33141
a2c02241 33142List attributes of the specified variable object @var{name}:
922fbb7b
AC
33143
33144@smallexample
a2c02241 33145 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
33146@end smallexample
33147
a2c02241
NR
33148@noindent
33149where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
33150
33151@subheading The @code{-var-evaluate-expression} Command
33152@findex -var-evaluate-expression
33153
33154@subsubheading Synopsis
33155
33156@smallexample
de051565 33157 -var-evaluate-expression [-f @var{format-spec}] @var{name}
a2c02241
NR
33158@end smallexample
33159
33160Evaluates the expression that is represented by the specified variable
de051565
MK
33161object and returns its value as a string. The format of the string
33162can be specified with the @samp{-f} option. The possible values of
33163this option are the same as for @code{-var-set-format}
33164(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
33165the current display format will be used. The current display format
33166can be changed using the @code{-var-set-format} command.
a2c02241
NR
33167
33168@smallexample
33169 value=@var{value}
33170@end smallexample
33171
33172Note that one must invoke @code{-var-list-children} for a variable
33173before the value of a child variable can be evaluated.
33174
33175@subheading The @code{-var-assign} Command
33176@findex -var-assign
33177
33178@subsubheading Synopsis
33179
33180@smallexample
33181 -var-assign @var{name} @var{expression}
33182@end smallexample
33183
33184Assigns the value of @var{expression} to the variable object specified
33185by @var{name}. The object must be @samp{editable}. If the variable's
33186value is altered by the assign, the variable will show up in any
33187subsequent @code{-var-update} list.
33188
33189@subsubheading Example
922fbb7b
AC
33190
33191@smallexample
594fe323 33192(gdb)
a2c02241
NR
33193-var-assign var1 3
33194^done,value="3"
594fe323 33195(gdb)
a2c02241
NR
33196-var-update *
33197^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 33198(gdb)
922fbb7b
AC
33199@end smallexample
33200
a2c02241
NR
33201@subheading The @code{-var-update} Command
33202@findex -var-update
33203
33204@subsubheading Synopsis
33205
33206@smallexample
33207 -var-update [@var{print-values}] @{@var{name} | "*"@}
33208@end smallexample
33209
c8b2f53c
VP
33210Reevaluate the expressions corresponding to the variable object
33211@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
33212list of variable objects whose values have changed; @var{name} must
33213be a root variable object. Here, ``changed'' means that the result of
33214@code{-var-evaluate-expression} before and after the
33215@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
33216object names, all existing variable objects are updated, except
33217for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3 33218@var{print-values} determines whether both names and values, or just
de051565 33219names are printed. The possible values of this option are the same
36ece8b3
NR
33220as for @code{-var-list-children} (@pxref{-var-list-children}). It is
33221recommended to use the @samp{--all-values} option, to reduce the
33222number of MI commands needed on each program stop.
c8b2f53c 33223
c3b108f7
VP
33224With the @samp{*} parameter, if a variable object is bound to a
33225currently running thread, it will not be updated, without any
33226diagnostic.
a2c02241 33227
0cc7d26f
TT
33228If @code{-var-set-update-range} was previously used on a varobj, then
33229only the selected range of children will be reported.
922fbb7b 33230
0cc7d26f
TT
33231@code{-var-update} reports all the changed varobjs in a tuple named
33232@samp{changelist}.
33233
33234Each item in the change list is itself a tuple holding:
33235
33236@table @samp
33237@item name
33238The name of the varobj.
33239
33240@item value
33241If values were requested for this update, then this field will be
33242present and will hold the value of the varobj.
922fbb7b 33243
0cc7d26f 33244@item in_scope
9f708cb2 33245@anchor{-var-update}
0cc7d26f 33246This field is a string which may take one of three values:
36ece8b3
NR
33247
33248@table @code
33249@item "true"
33250The variable object's current value is valid.
33251
33252@item "false"
33253The variable object does not currently hold a valid value but it may
33254hold one in the future if its associated expression comes back into
33255scope.
33256
33257@item "invalid"
33258The variable object no longer holds a valid value.
33259This can occur when the executable file being debugged has changed,
33260either through recompilation or by using the @value{GDBN} @code{file}
33261command. The front end should normally choose to delete these variable
33262objects.
33263@end table
33264
33265In the future new values may be added to this list so the front should
33266be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
33267
0cc7d26f
TT
33268@item type_changed
33269This is only present if the varobj is still valid. If the type
33270changed, then this will be the string @samp{true}; otherwise it will
33271be @samp{false}.
33272
7191c139
JB
33273When a varobj's type changes, its children are also likely to have
33274become incorrect. Therefore, the varobj's children are automatically
33275deleted when this attribute is @samp{true}. Also, the varobj's update
33276range, when set using the @code{-var-set-update-range} command, is
33277unset.
33278
0cc7d26f
TT
33279@item new_type
33280If the varobj's type changed, then this field will be present and will
33281hold the new type.
33282
33283@item new_num_children
33284For a dynamic varobj, if the number of children changed, or if the
33285type changed, this will be the new number of children.
33286
33287The @samp{numchild} field in other varobj responses is generally not
33288valid for a dynamic varobj -- it will show the number of children that
33289@value{GDBN} knows about, but because dynamic varobjs lazily
33290instantiate their children, this will not reflect the number of
33291children which may be available.
33292
33293The @samp{new_num_children} attribute only reports changes to the
33294number of children known by @value{GDBN}. This is the only way to
33295detect whether an update has removed children (which necessarily can
33296only happen at the end of the update range).
33297
33298@item displayhint
33299The display hint, if any.
33300
33301@item has_more
33302This is an integer value, which will be 1 if there are more children
33303available outside the varobj's update range.
33304
33305@item dynamic
33306This attribute will be present and have the value @samp{1} if the
33307varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33308then this attribute will not be present.
33309
33310@item new_children
33311If new children were added to a dynamic varobj within the selected
33312update range (as set by @code{-var-set-update-range}), then they will
33313be listed in this attribute.
33314@end table
33315
33316@subsubheading Example
33317
33318@smallexample
33319(gdb)
33320-var-assign var1 3
33321^done,value="3"
33322(gdb)
33323-var-update --all-values var1
33324^done,changelist=[@{name="var1",value="3",in_scope="true",
33325type_changed="false"@}]
33326(gdb)
33327@end smallexample
33328
25d5ea92
VP
33329@subheading The @code{-var-set-frozen} Command
33330@findex -var-set-frozen
9f708cb2 33331@anchor{-var-set-frozen}
25d5ea92
VP
33332
33333@subsubheading Synopsis
33334
33335@smallexample
9f708cb2 33336 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
33337@end smallexample
33338
9f708cb2 33339Set the frozenness flag on the variable object @var{name}. The
25d5ea92 33340@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 33341frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 33342frozen, then neither itself, nor any of its children, are
9f708cb2 33343implicitly updated by @code{-var-update} of
25d5ea92
VP
33344a parent variable or by @code{-var-update *}. Only
33345@code{-var-update} of the variable itself will update its value and
33346values of its children. After a variable object is unfrozen, it is
33347implicitly updated by all subsequent @code{-var-update} operations.
33348Unfreezing a variable does not update it, only subsequent
33349@code{-var-update} does.
33350
33351@subsubheading Example
33352
33353@smallexample
33354(gdb)
33355-var-set-frozen V 1
33356^done
33357(gdb)
33358@end smallexample
33359
0cc7d26f
TT
33360@subheading The @code{-var-set-update-range} command
33361@findex -var-set-update-range
33362@anchor{-var-set-update-range}
33363
33364@subsubheading Synopsis
33365
33366@smallexample
33367 -var-set-update-range @var{name} @var{from} @var{to}
33368@end smallexample
33369
33370Set the range of children to be returned by future invocations of
33371@code{-var-update}.
33372
33373@var{from} and @var{to} indicate the range of children to report. If
33374@var{from} or @var{to} is less than zero, the range is reset and all
33375children will be reported. Otherwise, children starting at @var{from}
33376(zero-based) and up to and excluding @var{to} will be reported.
33377
33378@subsubheading Example
33379
33380@smallexample
33381(gdb)
33382-var-set-update-range V 1 2
33383^done
33384@end smallexample
33385
b6313243
TT
33386@subheading The @code{-var-set-visualizer} command
33387@findex -var-set-visualizer
33388@anchor{-var-set-visualizer}
33389
33390@subsubheading Synopsis
33391
33392@smallexample
33393 -var-set-visualizer @var{name} @var{visualizer}
33394@end smallexample
33395
33396Set a visualizer for the variable object @var{name}.
33397
33398@var{visualizer} is the visualizer to use. The special value
33399@samp{None} means to disable any visualizer in use.
33400
33401If not @samp{None}, @var{visualizer} must be a Python expression.
33402This expression must evaluate to a callable object which accepts a
33403single argument. @value{GDBN} will call this object with the value of
33404the varobj @var{name} as an argument (this is done so that the same
33405Python pretty-printing code can be used for both the CLI and MI).
33406When called, this object must return an object which conforms to the
4c374409 33407pretty-printing interface (@pxref{Pretty Printing API}).
b6313243
TT
33408
33409The pre-defined function @code{gdb.default_visualizer} may be used to
33410select a visualizer by following the built-in process
33411(@pxref{Selecting Pretty-Printers}). This is done automatically when
33412a varobj is created, and so ordinarily is not needed.
33413
33414This feature is only available if Python support is enabled. The MI
d192b373 33415command @code{-list-features} (@pxref{GDB/MI Support Commands})
b6313243
TT
33416can be used to check this.
33417
33418@subsubheading Example
33419
33420Resetting the visualizer:
33421
33422@smallexample
33423(gdb)
33424-var-set-visualizer V None
33425^done
33426@end smallexample
33427
33428Reselecting the default (type-based) visualizer:
33429
33430@smallexample
33431(gdb)
33432-var-set-visualizer V gdb.default_visualizer
33433^done
33434@end smallexample
33435
33436Suppose @code{SomeClass} is a visualizer class. A lambda expression
33437can be used to instantiate this class for a varobj:
33438
33439@smallexample
33440(gdb)
33441-var-set-visualizer V "lambda val: SomeClass()"
33442^done
33443@end smallexample
25d5ea92 33444
a2c02241
NR
33445@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33446@node GDB/MI Data Manipulation
33447@section @sc{gdb/mi} Data Manipulation
922fbb7b 33448
a2c02241
NR
33449@cindex data manipulation, in @sc{gdb/mi}
33450@cindex @sc{gdb/mi}, data manipulation
33451This section describes the @sc{gdb/mi} commands that manipulate data:
33452examine memory and registers, evaluate expressions, etc.
33453
a86c90e6
SM
33454For details about what an addressable memory unit is,
33455@pxref{addressable memory unit}.
33456
a2c02241
NR
33457@c REMOVED FROM THE INTERFACE.
33458@c @subheading -data-assign
33459@c Change the value of a program variable. Plenty of side effects.
79a6e687 33460@c @subsubheading GDB Command
a2c02241
NR
33461@c set variable
33462@c @subsubheading Example
33463@c N.A.
33464
33465@subheading The @code{-data-disassemble} Command
33466@findex -data-disassemble
922fbb7b
AC
33467
33468@subsubheading Synopsis
33469
33470@smallexample
a2c02241
NR
33471 -data-disassemble
33472 [ -s @var{start-addr} -e @var{end-addr} ]
26fb3983 33473 | [ -a @var{addr} ]
a2c02241
NR
33474 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
33475 -- @var{mode}
922fbb7b
AC
33476@end smallexample
33477
a2c02241
NR
33478@noindent
33479Where:
33480
33481@table @samp
33482@item @var{start-addr}
33483is the beginning address (or @code{$pc})
33484@item @var{end-addr}
33485is the end address
26fb3983
JV
33486@item @var{addr}
33487is an address anywhere within (or the name of) the function to
33488disassemble. If an address is specified, the whole function
33489surrounding that address will be disassembled. If a name is
33490specified, the whole function with that name will be disassembled.
a2c02241
NR
33491@item @var{filename}
33492is the name of the file to disassemble
33493@item @var{linenum}
33494is the line number to disassemble around
33495@item @var{lines}
d3e8051b 33496is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
33497the whole function will be disassembled, in case no @var{end-addr} is
33498specified. If @var{end-addr} is specified as a non-zero value, and
33499@var{lines} is lower than the number of disassembly lines between
33500@var{start-addr} and @var{end-addr}, only @var{lines} lines are
33501displayed; if @var{lines} is higher than the number of lines between
33502@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
33503are displayed.
33504@item @var{mode}
6ff0ba5f
DE
33505is one of:
33506@itemize @bullet
33507@item 0 disassembly only
33508@item 1 mixed source and disassembly (deprecated)
33509@item 2 disassembly with raw opcodes
33510@item 3 mixed source and disassembly with raw opcodes (deprecated)
33511@item 4 mixed source and disassembly
33512@item 5 mixed source and disassembly with raw opcodes
33513@end itemize
33514
33515Modes 1 and 3 are deprecated. The output is ``source centric''
33516which hasn't proved useful in practice.
33517@xref{Machine Code}, for a discussion of the difference between
33518@code{/m} and @code{/s} output of the @code{disassemble} command.
a2c02241
NR
33519@end table
33520
33521@subsubheading Result
33522
ed8a1c2d
AB
33523The result of the @code{-data-disassemble} command will be a list named
33524@samp{asm_insns}, the contents of this list depend on the @var{mode}
33525used with the @code{-data-disassemble} command.
a2c02241 33526
ed8a1c2d
AB
33527For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
33528following fields:
33529
33530@table @code
33531@item address
33532The address at which this instruction was disassembled.
33533
33534@item func-name
33535The name of the function this instruction is within.
33536
33537@item offset
33538The decimal offset in bytes from the start of @samp{func-name}.
33539
33540@item inst
33541The text disassembly for this @samp{address}.
33542
33543@item opcodes
6ff0ba5f 33544This field is only present for modes 2, 3 and 5. This contains the raw opcode
ed8a1c2d
AB
33545bytes for the @samp{inst} field.
33546
33547@end table
33548
6ff0ba5f 33549For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
ed8a1c2d 33550@samp{src_and_asm_line}, each of which has the following fields:
a2c02241 33551
ed8a1c2d
AB
33552@table @code
33553@item line
33554The line number within @samp{file}.
33555
33556@item file
33557The file name from the compilation unit. This might be an absolute
33558file name or a relative file name depending on the compile command
33559used.
33560
33561@item fullname
f35a17b5
JK
33562Absolute file name of @samp{file}. It is converted to a canonical form
33563using the source file search path
33564(@pxref{Source Path, ,Specifying Source Directories})
33565and after resolving all the symbolic links.
33566
33567If the source file is not found this field will contain the path as
33568present in the debug information.
ed8a1c2d
AB
33569
33570@item line_asm_insn
33571This is a list of tuples containing the disassembly for @samp{line} in
33572@samp{file}. The fields of each tuple are the same as for
33573@code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
33574@samp{func-name}, @samp{offset}, @samp{inst}, and optionally
33575@samp{opcodes}.
33576
33577@end table
33578
33579Note that whatever included in the @samp{inst} field, is not
33580manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
33581adjust its format.
922fbb7b
AC
33582
33583@subsubheading @value{GDBN} Command
33584
ed8a1c2d 33585The corresponding @value{GDBN} command is @samp{disassemble}.
922fbb7b
AC
33586
33587@subsubheading Example
33588
a2c02241
NR
33589Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
33590
922fbb7b 33591@smallexample
594fe323 33592(gdb)
a2c02241
NR
33593-data-disassemble -s $pc -e "$pc + 20" -- 0
33594^done,
33595asm_insns=[
33596@{address="0x000107c0",func-name="main",offset="4",
33597inst="mov 2, %o0"@},
33598@{address="0x000107c4",func-name="main",offset="8",
33599inst="sethi %hi(0x11800), %o2"@},
33600@{address="0x000107c8",func-name="main",offset="12",
33601inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
33602@{address="0x000107cc",func-name="main",offset="16",
33603inst="sethi %hi(0x11800), %o2"@},
33604@{address="0x000107d0",func-name="main",offset="20",
33605inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 33606(gdb)
a2c02241
NR
33607@end smallexample
33608
33609Disassemble the whole @code{main} function. Line 32 is part of
33610@code{main}.
33611
33612@smallexample
33613-data-disassemble -f basics.c -l 32 -- 0
33614^done,asm_insns=[
33615@{address="0x000107bc",func-name="main",offset="0",
33616inst="save %sp, -112, %sp"@},
33617@{address="0x000107c0",func-name="main",offset="4",
33618inst="mov 2, %o0"@},
33619@{address="0x000107c4",func-name="main",offset="8",
33620inst="sethi %hi(0x11800), %o2"@},
33621[@dots{}]
33622@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
33623@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 33624(gdb)
922fbb7b
AC
33625@end smallexample
33626
a2c02241 33627Disassemble 3 instructions from the start of @code{main}:
922fbb7b 33628
a2c02241 33629@smallexample
594fe323 33630(gdb)
a2c02241
NR
33631-data-disassemble -f basics.c -l 32 -n 3 -- 0
33632^done,asm_insns=[
33633@{address="0x000107bc",func-name="main",offset="0",
33634inst="save %sp, -112, %sp"@},
33635@{address="0x000107c0",func-name="main",offset="4",
33636inst="mov 2, %o0"@},
33637@{address="0x000107c4",func-name="main",offset="8",
33638inst="sethi %hi(0x11800), %o2"@}]
594fe323 33639(gdb)
a2c02241
NR
33640@end smallexample
33641
33642Disassemble 3 instructions from the start of @code{main} in mixed mode:
33643
33644@smallexample
594fe323 33645(gdb)
a2c02241
NR
33646-data-disassemble -f basics.c -l 32 -n 3 -- 1
33647^done,asm_insns=[
33648src_and_asm_line=@{line="31",
ed8a1c2d
AB
33649file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33650fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33651line_asm_insn=[@{address="0x000107bc",
33652func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
a2c02241 33653src_and_asm_line=@{line="32",
ed8a1c2d
AB
33654file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33655fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33656line_asm_insn=[@{address="0x000107c0",
33657func-name="main",offset="4",inst="mov 2, %o0"@},
a2c02241
NR
33658@{address="0x000107c4",func-name="main",offset="8",
33659inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 33660(gdb)
a2c02241
NR
33661@end smallexample
33662
33663
33664@subheading The @code{-data-evaluate-expression} Command
33665@findex -data-evaluate-expression
922fbb7b
AC
33666
33667@subsubheading Synopsis
33668
33669@smallexample
a2c02241 33670 -data-evaluate-expression @var{expr}
922fbb7b
AC
33671@end smallexample
33672
a2c02241
NR
33673Evaluate @var{expr} as an expression. The expression could contain an
33674inferior function call. The function call will execute synchronously.
33675If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
33676
33677@subsubheading @value{GDBN} Command
33678
a2c02241
NR
33679The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
33680@samp{call}. In @code{gdbtk} only, there's a corresponding
33681@samp{gdb_eval} command.
922fbb7b
AC
33682
33683@subsubheading Example
33684
a2c02241
NR
33685In the following example, the numbers that precede the commands are the
33686@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
33687Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
33688output.
33689
922fbb7b 33690@smallexample
a2c02241
NR
33691211-data-evaluate-expression A
33692211^done,value="1"
594fe323 33693(gdb)
a2c02241
NR
33694311-data-evaluate-expression &A
33695311^done,value="0xefffeb7c"
594fe323 33696(gdb)
a2c02241
NR
33697411-data-evaluate-expression A+3
33698411^done,value="4"
594fe323 33699(gdb)
a2c02241
NR
33700511-data-evaluate-expression "A + 3"
33701511^done,value="4"
594fe323 33702(gdb)
a2c02241 33703@end smallexample
922fbb7b
AC
33704
33705
a2c02241
NR
33706@subheading The @code{-data-list-changed-registers} Command
33707@findex -data-list-changed-registers
922fbb7b
AC
33708
33709@subsubheading Synopsis
33710
33711@smallexample
a2c02241 33712 -data-list-changed-registers
922fbb7b
AC
33713@end smallexample
33714
a2c02241 33715Display a list of the registers that have changed.
922fbb7b
AC
33716
33717@subsubheading @value{GDBN} Command
33718
a2c02241
NR
33719@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
33720has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
33721
33722@subsubheading Example
922fbb7b 33723
a2c02241 33724On a PPC MBX board:
922fbb7b
AC
33725
33726@smallexample
594fe323 33727(gdb)
a2c02241
NR
33728-exec-continue
33729^running
922fbb7b 33730
594fe323 33731(gdb)
a47ec5fe
AR
33732*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
33733func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
6d52907e 33734line="5",arch="powerpc"@}
594fe323 33735(gdb)
a2c02241
NR
33736-data-list-changed-registers
33737^done,changed-registers=["0","1","2","4","5","6","7","8","9",
33738"10","11","13","14","15","16","17","18","19","20","21","22","23",
33739"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 33740(gdb)
a2c02241 33741@end smallexample
922fbb7b
AC
33742
33743
a2c02241
NR
33744@subheading The @code{-data-list-register-names} Command
33745@findex -data-list-register-names
922fbb7b
AC
33746
33747@subsubheading Synopsis
33748
33749@smallexample
a2c02241 33750 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
33751@end smallexample
33752
a2c02241
NR
33753Show a list of register names for the current target. If no arguments
33754are given, it shows a list of the names of all the registers. If
33755integer numbers are given as arguments, it will print a list of the
33756names of the registers corresponding to the arguments. To ensure
33757consistency between a register name and its number, the output list may
33758include empty register names.
922fbb7b
AC
33759
33760@subsubheading @value{GDBN} Command
33761
a2c02241
NR
33762@value{GDBN} does not have a command which corresponds to
33763@samp{-data-list-register-names}. In @code{gdbtk} there is a
33764corresponding command @samp{gdb_regnames}.
922fbb7b
AC
33765
33766@subsubheading Example
922fbb7b 33767
a2c02241
NR
33768For the PPC MBX board:
33769@smallexample
594fe323 33770(gdb)
a2c02241
NR
33771-data-list-register-names
33772^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
33773"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
33774"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
33775"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
33776"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
33777"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
33778"", "pc","ps","cr","lr","ctr","xer"]
594fe323 33779(gdb)
a2c02241
NR
33780-data-list-register-names 1 2 3
33781^done,register-names=["r1","r2","r3"]
594fe323 33782(gdb)
a2c02241 33783@end smallexample
922fbb7b 33784
a2c02241
NR
33785@subheading The @code{-data-list-register-values} Command
33786@findex -data-list-register-values
922fbb7b
AC
33787
33788@subsubheading Synopsis
33789
33790@smallexample
c898adb7
YQ
33791 -data-list-register-values
33792 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
33793@end smallexample
33794
697aa1b7
EZ
33795Display the registers' contents. The format according to which the
33796registers' contents are to be returned is given by @var{fmt}, followed
33797by an optional list of numbers specifying the registers to display. A
33798missing list of numbers indicates that the contents of all the
33799registers must be returned. The @code{--skip-unavailable} option
33800indicates that only the available registers are to be returned.
a2c02241
NR
33801
33802Allowed formats for @var{fmt} are:
33803
33804@table @code
33805@item x
33806Hexadecimal
33807@item o
33808Octal
33809@item t
33810Binary
33811@item d
33812Decimal
33813@item r
33814Raw
33815@item N
33816Natural
33817@end table
922fbb7b
AC
33818
33819@subsubheading @value{GDBN} Command
33820
a2c02241
NR
33821The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
33822all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
33823
33824@subsubheading Example
922fbb7b 33825
a2c02241
NR
33826For a PPC MBX board (note: line breaks are for readability only, they
33827don't appear in the actual output):
33828
33829@smallexample
594fe323 33830(gdb)
a2c02241
NR
33831-data-list-register-values r 64 65
33832^done,register-values=[@{number="64",value="0xfe00a300"@},
33833@{number="65",value="0x00029002"@}]
594fe323 33834(gdb)
a2c02241
NR
33835-data-list-register-values x
33836^done,register-values=[@{number="0",value="0xfe0043c8"@},
33837@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
33838@{number="3",value="0x0"@},@{number="4",value="0xa"@},
33839@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
33840@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
33841@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
33842@{number="11",value="0x1"@},@{number="12",value="0x0"@},
33843@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
33844@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
33845@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
33846@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
33847@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
33848@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
33849@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
33850@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
33851@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
33852@{number="31",value="0x0"@},@{number="32",value="0x0"@},
33853@{number="33",value="0x0"@},@{number="34",value="0x0"@},
33854@{number="35",value="0x0"@},@{number="36",value="0x0"@},
33855@{number="37",value="0x0"@},@{number="38",value="0x0"@},
33856@{number="39",value="0x0"@},@{number="40",value="0x0"@},
33857@{number="41",value="0x0"@},@{number="42",value="0x0"@},
33858@{number="43",value="0x0"@},@{number="44",value="0x0"@},
33859@{number="45",value="0x0"@},@{number="46",value="0x0"@},
33860@{number="47",value="0x0"@},@{number="48",value="0x0"@},
33861@{number="49",value="0x0"@},@{number="50",value="0x0"@},
33862@{number="51",value="0x0"@},@{number="52",value="0x0"@},
33863@{number="53",value="0x0"@},@{number="54",value="0x0"@},
33864@{number="55",value="0x0"@},@{number="56",value="0x0"@},
33865@{number="57",value="0x0"@},@{number="58",value="0x0"@},
33866@{number="59",value="0x0"@},@{number="60",value="0x0"@},
33867@{number="61",value="0x0"@},@{number="62",value="0x0"@},
33868@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
33869@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
33870@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
33871@{number="69",value="0x20002b03"@}]
594fe323 33872(gdb)
a2c02241 33873@end smallexample
922fbb7b 33874
a2c02241
NR
33875
33876@subheading The @code{-data-read-memory} Command
33877@findex -data-read-memory
922fbb7b 33878
8dedea02
VP
33879This command is deprecated, use @code{-data-read-memory-bytes} instead.
33880
922fbb7b
AC
33881@subsubheading Synopsis
33882
33883@smallexample
a2c02241
NR
33884 -data-read-memory [ -o @var{byte-offset} ]
33885 @var{address} @var{word-format} @var{word-size}
33886 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
33887@end smallexample
33888
a2c02241
NR
33889@noindent
33890where:
922fbb7b 33891
a2c02241
NR
33892@table @samp
33893@item @var{address}
33894An expression specifying the address of the first memory word to be
33895read. Complex expressions containing embedded white space should be
33896quoted using the C convention.
922fbb7b 33897
a2c02241
NR
33898@item @var{word-format}
33899The format to be used to print the memory words. The notation is the
33900same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 33901,Output Formats}).
922fbb7b 33902
a2c02241
NR
33903@item @var{word-size}
33904The size of each memory word in bytes.
922fbb7b 33905
a2c02241
NR
33906@item @var{nr-rows}
33907The number of rows in the output table.
922fbb7b 33908
a2c02241
NR
33909@item @var{nr-cols}
33910The number of columns in the output table.
922fbb7b 33911
a2c02241
NR
33912@item @var{aschar}
33913If present, indicates that each row should include an @sc{ascii} dump. The
33914value of @var{aschar} is used as a padding character when a byte is not a
33915member of the printable @sc{ascii} character set (printable @sc{ascii}
33916characters are those whose code is between 32 and 126, inclusively).
922fbb7b 33917
a2c02241
NR
33918@item @var{byte-offset}
33919An offset to add to the @var{address} before fetching memory.
33920@end table
922fbb7b 33921
a2c02241
NR
33922This command displays memory contents as a table of @var{nr-rows} by
33923@var{nr-cols} words, each word being @var{word-size} bytes. In total,
33924@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
33925(returned as @samp{total-bytes}). Should less than the requested number
33926of bytes be returned by the target, the missing words are identified
33927using @samp{N/A}. The number of bytes read from the target is returned
33928in @samp{nr-bytes} and the starting address used to read memory in
33929@samp{addr}.
33930
33931The address of the next/previous row or page is available in
33932@samp{next-row} and @samp{prev-row}, @samp{next-page} and
33933@samp{prev-page}.
922fbb7b
AC
33934
33935@subsubheading @value{GDBN} Command
33936
a2c02241
NR
33937The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
33938@samp{gdb_get_mem} memory read command.
922fbb7b
AC
33939
33940@subsubheading Example
32e7087d 33941
a2c02241
NR
33942Read six bytes of memory starting at @code{bytes+6} but then offset by
33943@code{-6} bytes. Format as three rows of two columns. One byte per
33944word. Display each word in hex.
32e7087d
JB
33945
33946@smallexample
594fe323 33947(gdb)
a2c02241
NR
339489-data-read-memory -o -6 -- bytes+6 x 1 3 2
339499^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
33950next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
33951prev-page="0x0000138a",memory=[
33952@{addr="0x00001390",data=["0x00","0x01"]@},
33953@{addr="0x00001392",data=["0x02","0x03"]@},
33954@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 33955(gdb)
32e7087d
JB
33956@end smallexample
33957
a2c02241
NR
33958Read two bytes of memory starting at address @code{shorts + 64} and
33959display as a single word formatted in decimal.
32e7087d 33960
32e7087d 33961@smallexample
594fe323 33962(gdb)
a2c02241
NR
339635-data-read-memory shorts+64 d 2 1 1
339645^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
33965next-row="0x00001512",prev-row="0x0000150e",
33966next-page="0x00001512",prev-page="0x0000150e",memory=[
33967@{addr="0x00001510",data=["128"]@}]
594fe323 33968(gdb)
32e7087d
JB
33969@end smallexample
33970
a2c02241
NR
33971Read thirty two bytes of memory starting at @code{bytes+16} and format
33972as eight rows of four columns. Include a string encoding with @samp{x}
33973used as the non-printable character.
922fbb7b
AC
33974
33975@smallexample
594fe323 33976(gdb)
a2c02241
NR
339774-data-read-memory bytes+16 x 1 8 4 x
339784^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
33979next-row="0x000013c0",prev-row="0x0000139c",
33980next-page="0x000013c0",prev-page="0x00001380",memory=[
33981@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
33982@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
33983@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
33984@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
33985@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
33986@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
33987@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
33988@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 33989(gdb)
922fbb7b
AC
33990@end smallexample
33991
8dedea02
VP
33992@subheading The @code{-data-read-memory-bytes} Command
33993@findex -data-read-memory-bytes
33994
33995@subsubheading Synopsis
33996
33997@smallexample
a86c90e6 33998 -data-read-memory-bytes [ -o @var{offset} ]
8dedea02
VP
33999 @var{address} @var{count}
34000@end smallexample
34001
34002@noindent
34003where:
34004
34005@table @samp
34006@item @var{address}
a86c90e6
SM
34007An expression specifying the address of the first addressable memory unit
34008to be read. Complex expressions containing embedded white space should be
8dedea02
VP
34009quoted using the C convention.
34010
34011@item @var{count}
a86c90e6
SM
34012The number of addressable memory units to read. This should be an integer
34013literal.
8dedea02 34014
a86c90e6
SM
34015@item @var{offset}
34016The offset relative to @var{address} at which to start reading. This
34017should be an integer literal. This option is provided so that a frontend
34018is not required to first evaluate address and then perform address
34019arithmetics itself.
8dedea02
VP
34020
34021@end table
34022
34023This command attempts to read all accessible memory regions in the
34024specified range. First, all regions marked as unreadable in the memory
34025map (if one is defined) will be skipped. @xref{Memory Region
34026Attributes}. Second, @value{GDBN} will attempt to read the remaining
34027regions. For each one, if reading full region results in an errors,
34028@value{GDBN} will try to read a subset of the region.
34029
a86c90e6
SM
34030In general, every single memory unit in the region may be readable or not,
34031and the only way to read every readable unit is to try a read at
8dedea02 34032every address, which is not practical. Therefore, @value{GDBN} will
a86c90e6 34033attempt to read all accessible memory units at either beginning or the end
8dedea02 34034of the region, using a binary division scheme. This heuristic works
6b92c0d3 34035well for reading across a memory map boundary. Note that if a region
8dedea02
VP
34036has a readable range that is neither at the beginning or the end,
34037@value{GDBN} will not read it.
34038
34039The result record (@pxref{GDB/MI Result Records}) that is output of
34040the command includes a field named @samp{memory} whose content is a
34041list of tuples. Each tuple represent a successfully read memory block
34042and has the following fields:
34043
34044@table @code
34045@item begin
34046The start address of the memory block, as hexadecimal literal.
34047
34048@item end
34049The end address of the memory block, as hexadecimal literal.
34050
34051@item offset
34052The offset of the memory block, as hexadecimal literal, relative to
34053the start address passed to @code{-data-read-memory-bytes}.
34054
34055@item contents
34056The contents of the memory block, in hex.
34057
34058@end table
34059
34060
34061
34062@subsubheading @value{GDBN} Command
34063
34064The corresponding @value{GDBN} command is @samp{x}.
34065
34066@subsubheading Example
34067
34068@smallexample
34069(gdb)
34070-data-read-memory-bytes &a 10
34071^done,memory=[@{begin="0xbffff154",offset="0x00000000",
34072 end="0xbffff15e",
34073 contents="01000000020000000300"@}]
34074(gdb)
34075@end smallexample
34076
34077
34078@subheading The @code{-data-write-memory-bytes} Command
34079@findex -data-write-memory-bytes
34080
34081@subsubheading Synopsis
34082
34083@smallexample
34084 -data-write-memory-bytes @var{address} @var{contents}
62747a60 34085 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
8dedea02
VP
34086@end smallexample
34087
34088@noindent
34089where:
34090
34091@table @samp
34092@item @var{address}
a86c90e6
SM
34093An expression specifying the address of the first addressable memory unit
34094to be written. Complex expressions containing embedded white space should
34095be quoted using the C convention.
8dedea02
VP
34096
34097@item @var{contents}
a86c90e6
SM
34098The hex-encoded data to write. It is an error if @var{contents} does
34099not represent an integral number of addressable memory units.
8dedea02 34100
62747a60 34101@item @var{count}
a86c90e6
SM
34102Optional argument indicating the number of addressable memory units to be
34103written. If @var{count} is greater than @var{contents}' length,
34104@value{GDBN} will repeatedly write @var{contents} until it fills
34105@var{count} memory units.
62747a60 34106
8dedea02
VP
34107@end table
34108
34109@subsubheading @value{GDBN} Command
34110
34111There's no corresponding @value{GDBN} command.
34112
34113@subsubheading Example
34114
34115@smallexample
34116(gdb)
34117-data-write-memory-bytes &a "aabbccdd"
34118^done
34119(gdb)
34120@end smallexample
34121
62747a60
TT
34122@smallexample
34123(gdb)
34124-data-write-memory-bytes &a "aabbccdd" 16e
34125^done
34126(gdb)
34127@end smallexample
8dedea02 34128
a2c02241
NR
34129@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34130@node GDB/MI Tracepoint Commands
34131@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 34132
18148017
VP
34133The commands defined in this section implement MI support for
34134tracepoints. For detailed introduction, see @ref{Tracepoints}.
34135
34136@subheading The @code{-trace-find} Command
34137@findex -trace-find
34138
34139@subsubheading Synopsis
34140
34141@smallexample
34142 -trace-find @var{mode} [@var{parameters}@dots{}]
34143@end smallexample
34144
34145Find a trace frame using criteria defined by @var{mode} and
34146@var{parameters}. The following table lists permissible
34147modes and their parameters. For details of operation, see @ref{tfind}.
34148
34149@table @samp
34150
34151@item none
34152No parameters are required. Stops examining trace frames.
34153
34154@item frame-number
34155An integer is required as parameter. Selects tracepoint frame with
34156that index.
34157
34158@item tracepoint-number
34159An integer is required as parameter. Finds next
34160trace frame that corresponds to tracepoint with the specified number.
34161
34162@item pc
34163An address is required as parameter. Finds
34164next trace frame that corresponds to any tracepoint at the specified
34165address.
34166
34167@item pc-inside-range
34168Two addresses are required as parameters. Finds next trace
34169frame that corresponds to a tracepoint at an address inside the
34170specified range. Both bounds are considered to be inside the range.
34171
34172@item pc-outside-range
34173Two addresses are required as parameters. Finds
34174next trace frame that corresponds to a tracepoint at an address outside
34175the specified range. Both bounds are considered to be inside the range.
34176
34177@item line
34178Line specification is required as parameter. @xref{Specify Location}.
34179Finds next trace frame that corresponds to a tracepoint at
34180the specified location.
34181
34182@end table
34183
34184If @samp{none} was passed as @var{mode}, the response does not
34185have fields. Otherwise, the response may have the following fields:
34186
34187@table @samp
34188@item found
34189This field has either @samp{0} or @samp{1} as the value, depending
34190on whether a matching tracepoint was found.
34191
34192@item traceframe
34193The index of the found traceframe. This field is present iff
34194the @samp{found} field has value of @samp{1}.
34195
34196@item tracepoint
34197The index of the found tracepoint. This field is present iff
34198the @samp{found} field has value of @samp{1}.
34199
34200@item frame
34201The information about the frame corresponding to the found trace
34202frame. This field is present only if a trace frame was found.
cd64ee31 34203@xref{GDB/MI Frame Information}, for description of this field.
18148017
VP
34204
34205@end table
34206
7d13fe92
SS
34207@subsubheading @value{GDBN} Command
34208
34209The corresponding @value{GDBN} command is @samp{tfind}.
34210
18148017
VP
34211@subheading -trace-define-variable
34212@findex -trace-define-variable
34213
34214@subsubheading Synopsis
34215
34216@smallexample
34217 -trace-define-variable @var{name} [ @var{value} ]
34218@end smallexample
34219
34220Create trace variable @var{name} if it does not exist. If
34221@var{value} is specified, sets the initial value of the specified
34222trace variable to that value. Note that the @var{name} should start
34223with the @samp{$} character.
34224
7d13fe92
SS
34225@subsubheading @value{GDBN} Command
34226
34227The corresponding @value{GDBN} command is @samp{tvariable}.
34228
dc673c81
YQ
34229@subheading The @code{-trace-frame-collected} Command
34230@findex -trace-frame-collected
34231
34232@subsubheading Synopsis
34233
34234@smallexample
34235 -trace-frame-collected
34236 [--var-print-values @var{var_pval}]
34237 [--comp-print-values @var{comp_pval}]
34238 [--registers-format @var{regformat}]
34239 [--memory-contents]
34240@end smallexample
34241
34242This command returns the set of collected objects, register names,
34243trace state variable names, memory ranges and computed expressions
34244that have been collected at a particular trace frame. The optional
34245parameters to the command affect the output format in different ways.
34246See the output description table below for more details.
34247
34248The reported names can be used in the normal manner to create
34249varobjs and inspect the objects themselves. The items returned by
34250this command are categorized so that it is clear which is a variable,
34251which is a register, which is a trace state variable, which is a
34252memory range and which is a computed expression.
34253
34254For instance, if the actions were
34255@smallexample
34256collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
34257collect *(int*)0xaf02bef0@@40
34258@end smallexample
34259
34260@noindent
34261the object collected in its entirety would be @code{myVar}. The
34262object @code{myArray} would be partially collected, because only the
34263element at index @code{myIndex} would be collected. The remaining
34264objects would be computed expressions.
34265
34266An example output would be:
34267
34268@smallexample
34269(gdb)
34270-trace-frame-collected
34271^done,
34272 explicit-variables=[@{name="myVar",value="1"@}],
34273 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
34274 @{name="myObj.field",value="0"@},
34275 @{name="myPtr->field",value="1"@},
34276 @{name="myCount + 2",value="3"@},
34277 @{name="$tvar1 + 1",value="43970027"@}],
34278 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
34279 @{number="1",value="0x0"@},
34280 @{number="2",value="0x4"@},
34281 ...
34282 @{number="125",value="0x0"@}],
34283 tvars=[@{name="$tvar1",current="43970026"@}],
34284 memory=[@{address="0x0000000000602264",length="4"@},
34285 @{address="0x0000000000615bc0",length="4"@}]
34286(gdb)
34287@end smallexample
34288
34289Where:
34290
34291@table @code
34292@item explicit-variables
34293The set of objects that have been collected in their entirety (as
34294opposed to collecting just a few elements of an array or a few struct
34295members). For each object, its name and value are printed.
34296The @code{--var-print-values} option affects how or whether the value
34297field is output. If @var{var_pval} is 0, then print only the names;
34298if it is 1, print also their values; and if it is 2, print the name,
34299type and value for simple data types, and the name and type for
34300arrays, structures and unions.
34301
34302@item computed-expressions
34303The set of computed expressions that have been collected at the
34304current trace frame. The @code{--comp-print-values} option affects
34305this set like the @code{--var-print-values} option affects the
34306@code{explicit-variables} set. See above.
34307
34308@item registers
34309The registers that have been collected at the current trace frame.
34310For each register collected, the name and current value are returned.
34311The value is formatted according to the @code{--registers-format}
34312option. See the @command{-data-list-register-values} command for a
34313list of the allowed formats. The default is @samp{x}.
34314
34315@item tvars
34316The trace state variables that have been collected at the current
34317trace frame. For each trace state variable collected, the name and
34318current value are returned.
34319
34320@item memory
34321The set of memory ranges that have been collected at the current trace
34322frame. Its content is a list of tuples. Each tuple represents a
34323collected memory range and has the following fields:
34324
34325@table @code
34326@item address
34327The start address of the memory range, as hexadecimal literal.
34328
34329@item length
34330The length of the memory range, as decimal literal.
34331
34332@item contents
34333The contents of the memory block, in hex. This field is only present
34334if the @code{--memory-contents} option is specified.
34335
34336@end table
34337
34338@end table
34339
34340@subsubheading @value{GDBN} Command
34341
34342There is no corresponding @value{GDBN} command.
34343
34344@subsubheading Example
34345
18148017
VP
34346@subheading -trace-list-variables
34347@findex -trace-list-variables
922fbb7b 34348
18148017 34349@subsubheading Synopsis
922fbb7b 34350
18148017
VP
34351@smallexample
34352 -trace-list-variables
34353@end smallexample
922fbb7b 34354
18148017
VP
34355Return a table of all defined trace variables. Each element of the
34356table has the following fields:
922fbb7b 34357
18148017
VP
34358@table @samp
34359@item name
34360The name of the trace variable. This field is always present.
922fbb7b 34361
18148017
VP
34362@item initial
34363The initial value. This is a 64-bit signed integer. This
34364field is always present.
922fbb7b 34365
18148017
VP
34366@item current
34367The value the trace variable has at the moment. This is a 64-bit
34368signed integer. This field is absent iff current value is
34369not defined, for example if the trace was never run, or is
34370presently running.
922fbb7b 34371
18148017 34372@end table
922fbb7b 34373
7d13fe92
SS
34374@subsubheading @value{GDBN} Command
34375
34376The corresponding @value{GDBN} command is @samp{tvariables}.
34377
18148017 34378@subsubheading Example
922fbb7b 34379
18148017
VP
34380@smallexample
34381(gdb)
34382-trace-list-variables
34383^done,trace-variables=@{nr_rows="1",nr_cols="3",
34384hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
34385 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
34386 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
34387body=[variable=@{name="$trace_timestamp",initial="0"@}
34388 variable=@{name="$foo",initial="10",current="15"@}]@}
34389(gdb)
34390@end smallexample
922fbb7b 34391
18148017
VP
34392@subheading -trace-save
34393@findex -trace-save
922fbb7b 34394
18148017
VP
34395@subsubheading Synopsis
34396
34397@smallexample
99e61eda 34398 -trace-save [ -r ] [ -ctf ] @var{filename}
18148017
VP
34399@end smallexample
34400
34401Saves the collected trace data to @var{filename}. Without the
34402@samp{-r} option, the data is downloaded from the target and saved
34403in a local file. With the @samp{-r} option the target is asked
34404to perform the save.
34405
99e61eda
SM
34406By default, this command will save the trace in the tfile format. You can
34407supply the optional @samp{-ctf} argument to save it the CTF format. See
34408@ref{Trace Files} for more information about CTF.
34409
7d13fe92
SS
34410@subsubheading @value{GDBN} Command
34411
34412The corresponding @value{GDBN} command is @samp{tsave}.
34413
18148017
VP
34414
34415@subheading -trace-start
34416@findex -trace-start
34417
34418@subsubheading Synopsis
34419
34420@smallexample
34421 -trace-start
34422@end smallexample
922fbb7b 34423
be06ba8c 34424Starts a tracing experiment. The result of this command does not
18148017 34425have any fields.
922fbb7b 34426
7d13fe92
SS
34427@subsubheading @value{GDBN} Command
34428
34429The corresponding @value{GDBN} command is @samp{tstart}.
34430
18148017
VP
34431@subheading -trace-status
34432@findex -trace-status
922fbb7b 34433
18148017
VP
34434@subsubheading Synopsis
34435
34436@smallexample
34437 -trace-status
34438@end smallexample
34439
a97153c7 34440Obtains the status of a tracing experiment. The result may include
18148017
VP
34441the following fields:
34442
34443@table @samp
34444
34445@item supported
34446May have a value of either @samp{0}, when no tracing operations are
34447supported, @samp{1}, when all tracing operations are supported, or
34448@samp{file} when examining trace file. In the latter case, examining
34449of trace frame is possible but new tracing experiement cannot be
34450started. This field is always present.
34451
34452@item running
34453May have a value of either @samp{0} or @samp{1} depending on whether
34454tracing experiement is in progress on target. This field is present
34455if @samp{supported} field is not @samp{0}.
34456
34457@item stop-reason
34458Report the reason why the tracing was stopped last time. This field
34459may be absent iff tracing was never stopped on target yet. The
34460value of @samp{request} means the tracing was stopped as result of
34461the @code{-trace-stop} command. The value of @samp{overflow} means
34462the tracing buffer is full. The value of @samp{disconnection} means
34463tracing was automatically stopped when @value{GDBN} has disconnected.
34464The value of @samp{passcount} means tracing was stopped when a
34465tracepoint was passed a maximal number of times for that tracepoint.
34466This field is present if @samp{supported} field is not @samp{0}.
34467
34468@item stopping-tracepoint
34469The number of tracepoint whose passcount as exceeded. This field is
34470present iff the @samp{stop-reason} field has the value of
34471@samp{passcount}.
34472
34473@item frames
87290684
SS
34474@itemx frames-created
34475The @samp{frames} field is a count of the total number of trace frames
34476in the trace buffer, while @samp{frames-created} is the total created
34477during the run, including ones that were discarded, such as when a
34478circular trace buffer filled up. Both fields are optional.
18148017
VP
34479
34480@item buffer-size
34481@itemx buffer-free
34482These fields tell the current size of the tracing buffer and the
87290684 34483remaining space. These fields are optional.
18148017 34484
a97153c7
PA
34485@item circular
34486The value of the circular trace buffer flag. @code{1} means that the
34487trace buffer is circular and old trace frames will be discarded if
34488necessary to make room, @code{0} means that the trace buffer is linear
34489and may fill up.
34490
34491@item disconnected
34492The value of the disconnected tracing flag. @code{1} means that
34493tracing will continue after @value{GDBN} disconnects, @code{0} means
34494that the trace run will stop.
34495
f5911ea1
HAQ
34496@item trace-file
34497The filename of the trace file being examined. This field is
34498optional, and only present when examining a trace file.
34499
18148017
VP
34500@end table
34501
7d13fe92
SS
34502@subsubheading @value{GDBN} Command
34503
34504The corresponding @value{GDBN} command is @samp{tstatus}.
34505
18148017
VP
34506@subheading -trace-stop
34507@findex -trace-stop
34508
34509@subsubheading Synopsis
34510
34511@smallexample
34512 -trace-stop
34513@end smallexample
922fbb7b 34514
18148017
VP
34515Stops a tracing experiment. The result of this command has the same
34516fields as @code{-trace-status}, except that the @samp{supported} and
34517@samp{running} fields are not output.
922fbb7b 34518
7d13fe92
SS
34519@subsubheading @value{GDBN} Command
34520
34521The corresponding @value{GDBN} command is @samp{tstop}.
34522
922fbb7b 34523
a2c02241
NR
34524@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34525@node GDB/MI Symbol Query
34526@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
34527
34528
9901a55b 34529@ignore
a2c02241
NR
34530@subheading The @code{-symbol-info-address} Command
34531@findex -symbol-info-address
922fbb7b
AC
34532
34533@subsubheading Synopsis
34534
34535@smallexample
a2c02241 34536 -symbol-info-address @var{symbol}
922fbb7b
AC
34537@end smallexample
34538
a2c02241 34539Describe where @var{symbol} is stored.
922fbb7b
AC
34540
34541@subsubheading @value{GDBN} Command
34542
a2c02241 34543The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
34544
34545@subsubheading Example
34546N.A.
34547
34548
a2c02241
NR
34549@subheading The @code{-symbol-info-file} Command
34550@findex -symbol-info-file
922fbb7b
AC
34551
34552@subsubheading Synopsis
34553
34554@smallexample
a2c02241 34555 -symbol-info-file
922fbb7b
AC
34556@end smallexample
34557
a2c02241 34558Show the file for the symbol.
922fbb7b 34559
a2c02241 34560@subsubheading @value{GDBN} Command
922fbb7b 34561
a2c02241
NR
34562There's no equivalent @value{GDBN} command. @code{gdbtk} has
34563@samp{gdb_find_file}.
922fbb7b
AC
34564
34565@subsubheading Example
34566N.A.
7dc42066
AB
34567@end ignore
34568
34569@subheading The @code{-symbol-info-functions} Command
34570@findex -symbol-info-functions
34571@anchor{-symbol-info-functions}
34572
34573@subsubheading Synopsis
34574
34575@smallexample
34576 -symbol-info-functions [--include-nondebug]
34577 [--type @var{type_regexp}]
34578 [--name @var{name_regexp}]
c2512106 34579 [--max-results @var{limit}]
7dc42066
AB
34580@end smallexample
34581
34582@noindent
34583Return a list containing the names and types for all global functions
34584taken from the debug information. The functions are grouped by source
34585file, and shown with the line number on which each function is
34586defined.
922fbb7b 34587
7dc42066
AB
34588The @code{--include-nondebug} option causes the output to include
34589code symbols from the symbol table.
922fbb7b 34590
7dc42066
AB
34591The options @code{--type} and @code{--name} allow the symbols returned
34592to be filtered based on either the name of the function, or the type
34593signature of the function.
34594
c2512106
AB
34595The option @code{--max-results} restricts the command to return no
34596more than @var{limit} results. If exactly @var{limit} results are
34597returned then there might be additional results available if a higher
34598limit is used.
34599
7dc42066
AB
34600@subsubheading @value{GDBN} Command
34601
34602The corresponding @value{GDBN} command is @samp{info functions}.
34603
34604@subsubheading Example
34605@smallexample
34606@group
34607(gdb)
34608-symbol-info-functions
34609^done,symbols=
34610 @{debug=
34611 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34612 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34613 symbols=[@{line="36", name="f4", type="void (int *)",
34614 description="void f4(int *);"@},
34615 @{line="42", name="main", type="int ()",
34616 description="int main();"@},
34617 @{line="30", name="f1", type="my_int_t (int, int)",
34618 description="static my_int_t f1(int, int);"@}]@},
34619 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34620 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34621 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34622 description="float f2(another_float_t);"@},
34623 @{line="39", name="f3", type="int (another_int_t)",
34624 description="int f3(another_int_t);"@},
34625 @{line="27", name="f1", type="another_float_t (int)",
34626 description="static another_float_t f1(int);"@}]@}]@}
34627@end group
34628@group
34629(gdb)
34630-symbol-info-functions --name f1
34631^done,symbols=
34632 @{debug=
34633 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34634 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34635 symbols=[@{line="30", name="f1", type="my_int_t (int, int)",
34636 description="static my_int_t f1(int, int);"@}]@},
34637 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34638 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34639 symbols=[@{line="27", name="f1", type="another_float_t (int)",
34640 description="static another_float_t f1(int);"@}]@}]@}
34641@end group
34642@group
34643(gdb)
34644-symbol-info-functions --type void
34645^done,symbols=
34646 @{debug=
34647 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34648 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34649 symbols=[@{line="36", name="f4", type="void (int *)",
34650 description="void f4(int *);"@}]@}]@}
34651@end group
34652@group
34653(gdb)
34654-symbol-info-functions --include-nondebug
34655^done,symbols=
34656 @{debug=
34657 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34658 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34659 symbols=[@{line="36", name="f4", type="void (int *)",
34660 description="void f4(int *);"@},
34661 @{line="42", name="main", type="int ()",
34662 description="int main();"@},
34663 @{line="30", name="f1", type="my_int_t (int, int)",
34664 description="static my_int_t f1(int, int);"@}]@},
34665 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34666 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34667 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34668 description="float f2(another_float_t);"@},
34669 @{line="39", name="f3", type="int (another_int_t)",
34670 description="int f3(another_int_t);"@},
34671 @{line="27", name="f1", type="another_float_t (int)",
34672 description="static another_float_t f1(int);"@}]@}],
34673 nondebug=
34674 [@{address="0x0000000000400398",name="_init"@},
34675 @{address="0x00000000004003b0",name="_start"@},
34676 ...
34677 ]@}
34678@end group
34679@end smallexample
34680
293b38d6
AB
34681@subheading The @code{-symbol-info-module-functions} Command
34682@findex -symbol-info-module-functions
34683@anchor{-symbol-info-module-functions}
34684
34685@subsubheading Synopsis
34686
34687@smallexample
34688 -symbol-info-module-functions [--module @var{module_regexp}]
34689 [--name @var{name_regexp}]
34690 [--type @var{type_regexp}]
34691@end smallexample
34692
34693@noindent
34694Return a list containing the names of all known functions within all
34695know Fortran modules. The functions are grouped by source file and
34696containing module, and shown with the line number on which each
34697function is defined.
34698
34699The option @code{--module} only returns results for modules matching
34700@var{module_regexp}. The option @code{--name} only returns functions
34701whose name matches @var{name_regexp}, and @code{--type} only returns
34702functions whose type matches @var{type_regexp}.
34703
34704@subsubheading @value{GDBN} Command
34705
34706The corresponding @value{GDBN} command is @samp{info module functions}.
34707
34708@subsubheading Example
34709
34710@smallexample
34711@group
34712(gdb)
34713-symbol-info-module-functions
34714^done,symbols=
34715 [@{module="mod1",
34716 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34717 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34718 symbols=[@{line="21",name="mod1::check_all",type="void (void)",
34719 description="void mod1::check_all(void);"@}]@}]@},
34720 @{module="mod2",
34721 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34722 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34723 symbols=[@{line="30",name="mod2::check_var_i",type="void (void)",
34724 description="void mod2::check_var_i(void);"@}]@}]@},
34725 @{module="mod3",
34726 files=[@{filename="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34727 fullname="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34728 symbols=[@{line="21",name="mod3::check_all",type="void (void)",
34729 description="void mod3::check_all(void);"@},
34730 @{line="27",name="mod3::check_mod2",type="void (void)",
34731 description="void mod3::check_mod2(void);"@}]@}]@},
34732 @{module="modmany",
34733 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34734 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34735 symbols=[@{line="35",name="modmany::check_some",type="void (void)",
34736 description="void modmany::check_some(void);"@}]@}]@},
34737 @{module="moduse",
34738 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34739 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34740 symbols=[@{line="44",name="moduse::check_all",type="void (void)",
34741 description="void moduse::check_all(void);"@},
34742 @{line="49",name="moduse::check_var_x",type="void (void)",
34743 description="void moduse::check_var_x(void);"@}]@}]@}]
34744@end group
34745@end smallexample
34746
34747@subheading The @code{-symbol-info-module-variables} Command
34748@findex -symbol-info-module-variables
34749@anchor{-symbol-info-module-variables}
34750
34751@subsubheading Synopsis
34752
34753@smallexample
34754 -symbol-info-module-variables [--module @var{module_regexp}]
34755 [--name @var{name_regexp}]
34756 [--type @var{type_regexp}]
34757@end smallexample
34758
34759@noindent
34760Return a list containing the names of all known variables within all
34761know Fortran modules. The variables are grouped by source file and
34762containing module, and shown with the line number on which each
34763variable is defined.
34764
34765The option @code{--module} only returns results for modules matching
34766@var{module_regexp}. The option @code{--name} only returns variables
34767whose name matches @var{name_regexp}, and @code{--type} only returns
34768variables whose type matches @var{type_regexp}.
34769
34770@subsubheading @value{GDBN} Command
34771
34772The corresponding @value{GDBN} command is @samp{info module variables}.
34773
34774@subsubheading Example
34775
34776@smallexample
34777@group
34778(gdb)
34779-symbol-info-module-variables
34780^done,symbols=
34781 [@{module="mod1",
34782 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34783 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34784 symbols=[@{line="18",name="mod1::var_const",type="integer(kind=4)",
34785 description="integer(kind=4) mod1::var_const;"@},
34786 @{line="17",name="mod1::var_i",type="integer(kind=4)",
34787 description="integer(kind=4) mod1::var_i;"@}]@}]@},
34788 @{module="mod2",
34789 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34790 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34791 symbols=[@{line="28",name="mod2::var_i",type="integer(kind=4)",
34792 description="integer(kind=4) mod2::var_i;"@}]@}]@},
34793 @{module="mod3",
34794 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34795 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34796 symbols=[@{line="18",name="mod3::mod1",type="integer(kind=4)",
34797 description="integer(kind=4) mod3::mod1;"@},
34798 @{line="17",name="mod3::mod2",type="integer(kind=4)",
34799 description="integer(kind=4) mod3::mod2;"@},
34800 @{line="19",name="mod3::var_i",type="integer(kind=4)",
34801 description="integer(kind=4) mod3::var_i;"@}]@}]@},
34802 @{module="modmany",
34803 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34804 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34805 symbols=[@{line="33",name="modmany::var_a",type="integer(kind=4)",
34806 description="integer(kind=4) modmany::var_a;"@},
34807 @{line="33",name="modmany::var_b",type="integer(kind=4)",
34808 description="integer(kind=4) modmany::var_b;"@},
34809 @{line="33",name="modmany::var_c",type="integer(kind=4)",
34810 description="integer(kind=4) modmany::var_c;"@},
34811 @{line="33",name="modmany::var_i",type="integer(kind=4)",
34812 description="integer(kind=4) modmany::var_i;"@}]@}]@},
34813 @{module="moduse",
34814 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34815 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34816 symbols=[@{line="42",name="moduse::var_x",type="integer(kind=4)",
34817 description="integer(kind=4) moduse::var_x;"@},
34818 @{line="42",name="moduse::var_y",type="integer(kind=4)",
34819 description="integer(kind=4) moduse::var_y;"@}]@}]@}]
34820@end group
34821@end smallexample
34822
db5960b4
AB
34823@subheading The @code{-symbol-info-modules} Command
34824@findex -symbol-info-modules
34825@anchor{-symbol-info-modules}
34826
34827@subsubheading Synopsis
34828
34829@smallexample
34830 -symbol-info-modules [--name @var{name_regexp}]
c2512106
AB
34831 [--max-results @var{limit}]
34832
db5960b4
AB
34833@end smallexample
34834
34835@noindent
34836Return a list containing the names of all known Fortran modules. The
34837modules are grouped by source file, and shown with the line number on
34838which each modules is defined.
34839
34840The option @code{--name} allows the modules returned to be filtered
34841based the name of the module.
34842
c2512106
AB
34843The option @code{--max-results} restricts the command to return no
34844more than @var{limit} results. If exactly @var{limit} results are
34845returned then there might be additional results available if a higher
34846limit is used.
34847
db5960b4
AB
34848@subsubheading @value{GDBN} Command
34849
34850The corresponding @value{GDBN} command is @samp{info modules}.
34851
34852@subsubheading Example
34853@smallexample
34854@group
34855(gdb)
34856-symbol-info-modules
34857^done,symbols=
34858 @{debug=
34859 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34860 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34861 symbols=[@{line="16",name="mod1"@},
34862 @{line="22",name="mod2"@}]@},
34863 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34864 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34865 symbols=[@{line="16",name="mod3"@},
34866 @{line="22",name="modmany"@},
34867 @{line="26",name="moduse"@}]@}]@}
34868@end group
34869@group
34870(gdb)
34871-symbol-info-modules --name mod[123]
34872^done,symbols=
34873 @{debug=
34874 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34875 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34876 symbols=[@{line="16",name="mod1"@},
34877 @{line="22",name="mod2"@}]@},
34878 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34879 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34880 symbols=[@{line="16",name="mod3"@}]@}]@}
34881@end group
34882@end smallexample
34883
7dc42066
AB
34884@subheading The @code{-symbol-info-types} Command
34885@findex -symbol-info-types
34886@anchor{-symbol-info-types}
922fbb7b
AC
34887
34888@subsubheading Synopsis
34889
34890@smallexample
7dc42066 34891 -symbol-info-types [--name @var{name_regexp}]
c2512106
AB
34892 [--max-results @var{limit}]
34893
922fbb7b
AC
34894@end smallexample
34895
7dc42066
AB
34896@noindent
34897Return a list of all defined types. The types are grouped by source
34898file, and shown with the line number on which each user defined type
34899is defined. Some base types are not defined in the source code but
34900are added to the debug information by the compiler, for example
34901@code{int}, @code{float}, etc.; these types do not have an associated
34902line number.
34903
34904The option @code{--name} allows the list of types returned to be
34905filtered by name.
922fbb7b 34906
c2512106
AB
34907The option @code{--max-results} restricts the command to return no
34908more than @var{limit} results. If exactly @var{limit} results are
34909returned then there might be additional results available if a higher
34910limit is used.
34911
922fbb7b
AC
34912@subsubheading @value{GDBN} Command
34913
7dc42066 34914The corresponding @value{GDBN} command is @samp{info types}.
922fbb7b
AC
34915
34916@subsubheading Example
7dc42066
AB
34917@smallexample
34918@group
34919(gdb)
34920-symbol-info-types
34921^done,symbols=
34922 @{debug=
34923 [@{filename="gdb.mi/mi-sym-info-1.c",
34924 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34925 symbols=[@{name="float"@},
34926 @{name="int"@},
34927 @{line="27",name="typedef int my_int_t;"@}]@},
34928 @{filename="gdb.mi/mi-sym-info-2.c",
34929 fullname="/project/gdb.mi/mi-sym-info-2.c",
34930 symbols=[@{line="24",name="typedef float another_float_t;"@},
34931 @{line="23",name="typedef int another_int_t;"@},
34932 @{name="float"@},
34933 @{name="int"@}]@}]@}
34934@end group
34935@group
34936(gdb)
34937-symbol-info-types --name _int_
34938^done,symbols=
34939 @{debug=
34940 [@{filename="gdb.mi/mi-sym-info-1.c",
34941 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34942 symbols=[@{line="27",name="typedef int my_int_t;"@}]@},
34943 @{filename="gdb.mi/mi-sym-info-2.c",
34944 fullname="/project/gdb.mi/mi-sym-info-2.c",
34945 symbols=[@{line="23",name="typedef int another_int_t;"@}]@}]@}
34946@end group
34947@end smallexample
34948
34949@subheading The @code{-symbol-info-variables} Command
34950@findex -symbol-info-variables
34951@anchor{-symbol-info-variables}
34952
34953@subsubheading Synopsis
34954
34955@smallexample
34956 -symbol-info-variables [--include-nondebug]
34957 [--type @var{type_regexp}]
34958 [--name @var{name_regexp}]
c2512106
AB
34959 [--max-results @var{limit}]
34960
7dc42066
AB
34961@end smallexample
34962
34963@noindent
34964Return a list containing the names and types for all global variables
34965taken from the debug information. The variables are grouped by source
34966file, and shown with the line number on which each variable is
34967defined.
34968
34969The @code{--include-nondebug} option causes the output to include
34970data symbols from the symbol table.
34971
34972The options @code{--type} and @code{--name} allow the symbols returned
34973to be filtered based on either the name of the variable, or the type
34974of the variable.
34975
c2512106
AB
34976The option @code{--max-results} restricts the command to return no
34977more than @var{limit} results. If exactly @var{limit} results are
34978returned then there might be additional results available if a higher
34979limit is used.
34980
7dc42066 34981@subsubheading @value{GDBN} Command
922fbb7b 34982
7dc42066 34983The corresponding @value{GDBN} command is @samp{info variables}.
922fbb7b 34984
7dc42066
AB
34985@subsubheading Example
34986@smallexample
34987@group
34988(gdb)
34989-symbol-info-variables
34990^done,symbols=
34991 @{debug=
34992 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34993 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34994 symbols=[@{line="25",name="global_f1",type="float",
34995 description="static float global_f1;"@},
34996 @{line="24",name="global_i1",type="int",
34997 description="static int global_i1;"@}]@},
34998 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34999 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35000 symbols=[@{line="21",name="global_f2",type="int",
35001 description="int global_f2;"@},
35002 @{line="20",name="global_i2",type="int",
35003 description="int global_i2;"@},
35004 @{line="19",name="global_f1",type="float",
35005 description="static float global_f1;"@},
35006 @{line="18",name="global_i1",type="int",
35007 description="static int global_i1;"@}]@}]@}
35008@end group
35009@group
35010(gdb)
35011-symbol-info-variables --name f1
35012^done,symbols=
35013 @{debug=
35014 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35015 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35016 symbols=[@{line="25",name="global_f1",type="float",
35017 description="static float global_f1;"@}]@},
35018 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35019 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35020 symbols=[@{line="19",name="global_f1",type="float",
35021 description="static float global_f1;"@}]@}]@}
35022@end group
35023@group
35024(gdb)
35025-symbol-info-variables --type float
35026^done,symbols=
35027 @{debug=
35028 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35029 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35030 symbols=[@{line="25",name="global_f1",type="float",
35031 description="static float global_f1;"@}]@},
35032 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35033 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35034 symbols=[@{line="19",name="global_f1",type="float",
35035 description="static float global_f1;"@}]@}]@}
35036@end group
35037@group
35038(gdb)
35039-symbol-info-variables --include-nondebug
35040^done,symbols=
35041 @{debug=
35042 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35043 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35044 symbols=[@{line="25",name="global_f1",type="float",
35045 description="static float global_f1;"@},
35046 @{line="24",name="global_i1",type="int",
35047 description="static int global_i1;"@}]@},
35048 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35049 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35050 symbols=[@{line="21",name="global_f2",type="int",
35051 description="int global_f2;"@},
35052 @{line="20",name="global_i2",type="int",
35053 description="int global_i2;"@},
35054 @{line="19",name="global_f1",type="float",
35055 description="static float global_f1;"@},
35056 @{line="18",name="global_i1",type="int",
35057 description="static int global_i1;"@}]@}],
35058 nondebug=
35059 [@{address="0x00000000004005d0",name="_IO_stdin_used"@},
35060 @{address="0x00000000004005d8",name="__dso_handle"@}
35061 ...
35062 ]@}
35063@end group
35064@end smallexample
35065
35066@ignore
a2c02241
NR
35067@subheading The @code{-symbol-info-line} Command
35068@findex -symbol-info-line
922fbb7b
AC
35069
35070@subsubheading Synopsis
35071
35072@smallexample
a2c02241 35073 -symbol-info-line
922fbb7b
AC
35074@end smallexample
35075
a2c02241 35076Show the core addresses of the code for a source line.
922fbb7b 35077
a2c02241 35078@subsubheading @value{GDBN} Command
922fbb7b 35079
a2c02241
NR
35080The corresponding @value{GDBN} command is @samp{info line}.
35081@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
35082
35083@subsubheading Example
a2c02241 35084N.A.
922fbb7b
AC
35085
35086
a2c02241
NR
35087@subheading The @code{-symbol-info-symbol} Command
35088@findex -symbol-info-symbol
07f31aa6
DJ
35089
35090@subsubheading Synopsis
35091
a2c02241
NR
35092@smallexample
35093 -symbol-info-symbol @var{addr}
35094@end smallexample
07f31aa6 35095
a2c02241 35096Describe what symbol is at location @var{addr}.
07f31aa6 35097
a2c02241 35098@subsubheading @value{GDBN} Command
07f31aa6 35099
a2c02241 35100The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
35101
35102@subsubheading Example
a2c02241 35103N.A.
07f31aa6
DJ
35104
35105
a2c02241
NR
35106@subheading The @code{-symbol-list-functions} Command
35107@findex -symbol-list-functions
922fbb7b
AC
35108
35109@subsubheading Synopsis
35110
35111@smallexample
a2c02241 35112 -symbol-list-functions
922fbb7b
AC
35113@end smallexample
35114
a2c02241 35115List the functions in the executable.
922fbb7b
AC
35116
35117@subsubheading @value{GDBN} Command
35118
a2c02241
NR
35119@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
35120@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
35121
35122@subsubheading Example
a2c02241 35123N.A.
9901a55b 35124@end ignore
922fbb7b
AC
35125
35126
a2c02241
NR
35127@subheading The @code{-symbol-list-lines} Command
35128@findex -symbol-list-lines
922fbb7b
AC
35129
35130@subsubheading Synopsis
35131
35132@smallexample
a2c02241 35133 -symbol-list-lines @var{filename}
922fbb7b
AC
35134@end smallexample
35135
a2c02241
NR
35136Print the list of lines that contain code and their associated program
35137addresses for the given source filename. The entries are sorted in
35138ascending PC order.
922fbb7b
AC
35139
35140@subsubheading @value{GDBN} Command
35141
a2c02241 35142There is no corresponding @value{GDBN} command.
922fbb7b
AC
35143
35144@subsubheading Example
a2c02241 35145@smallexample
594fe323 35146(gdb)
a2c02241
NR
35147-symbol-list-lines basics.c
35148^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 35149(gdb)
a2c02241 35150@end smallexample
922fbb7b
AC
35151
35152
9901a55b 35153@ignore
a2c02241
NR
35154@subheading The @code{-symbol-list-types} Command
35155@findex -symbol-list-types
922fbb7b
AC
35156
35157@subsubheading Synopsis
35158
35159@smallexample
a2c02241 35160 -symbol-list-types
922fbb7b
AC
35161@end smallexample
35162
a2c02241 35163List all the type names.
922fbb7b
AC
35164
35165@subsubheading @value{GDBN} Command
35166
a2c02241
NR
35167The corresponding commands are @samp{info types} in @value{GDBN},
35168@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
35169
35170@subsubheading Example
35171N.A.
35172
35173
a2c02241
NR
35174@subheading The @code{-symbol-list-variables} Command
35175@findex -symbol-list-variables
922fbb7b
AC
35176
35177@subsubheading Synopsis
35178
35179@smallexample
a2c02241 35180 -symbol-list-variables
922fbb7b
AC
35181@end smallexample
35182
a2c02241 35183List all the global and static variable names.
922fbb7b
AC
35184
35185@subsubheading @value{GDBN} Command
35186
a2c02241 35187@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
35188
35189@subsubheading Example
35190N.A.
35191
35192
a2c02241
NR
35193@subheading The @code{-symbol-locate} Command
35194@findex -symbol-locate
922fbb7b
AC
35195
35196@subsubheading Synopsis
35197
35198@smallexample
a2c02241 35199 -symbol-locate
922fbb7b
AC
35200@end smallexample
35201
922fbb7b
AC
35202@subsubheading @value{GDBN} Command
35203
a2c02241 35204@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
35205
35206@subsubheading Example
35207N.A.
35208
35209
a2c02241
NR
35210@subheading The @code{-symbol-type} Command
35211@findex -symbol-type
922fbb7b
AC
35212
35213@subsubheading Synopsis
35214
35215@smallexample
a2c02241 35216 -symbol-type @var{variable}
922fbb7b
AC
35217@end smallexample
35218
a2c02241 35219Show type of @var{variable}.
922fbb7b 35220
a2c02241 35221@subsubheading @value{GDBN} Command
922fbb7b 35222
a2c02241
NR
35223The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
35224@samp{gdb_obj_variable}.
35225
35226@subsubheading Example
35227N.A.
9901a55b 35228@end ignore
a2c02241
NR
35229
35230
35231@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35232@node GDB/MI File Commands
35233@section @sc{gdb/mi} File Commands
35234
35235This section describes the GDB/MI commands to specify executable file names
35236and to read in and obtain symbol table information.
35237
35238@subheading The @code{-file-exec-and-symbols} Command
35239@findex -file-exec-and-symbols
35240
35241@subsubheading Synopsis
922fbb7b
AC
35242
35243@smallexample
a2c02241 35244 -file-exec-and-symbols @var{file}
922fbb7b
AC
35245@end smallexample
35246
a2c02241
NR
35247Specify the executable file to be debugged. This file is the one from
35248which the symbol table is also read. If no file is specified, the
35249command clears the executable and symbol information. If breakpoints
35250are set when using this command with no arguments, @value{GDBN} will produce
35251error messages. Otherwise, no output is produced, except a completion
35252notification.
35253
922fbb7b
AC
35254@subsubheading @value{GDBN} Command
35255
a2c02241 35256The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
35257
35258@subsubheading Example
35259
35260@smallexample
594fe323 35261(gdb)
a2c02241
NR
35262-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35263^done
594fe323 35264(gdb)
922fbb7b
AC
35265@end smallexample
35266
922fbb7b 35267
a2c02241
NR
35268@subheading The @code{-file-exec-file} Command
35269@findex -file-exec-file
922fbb7b
AC
35270
35271@subsubheading Synopsis
35272
35273@smallexample
a2c02241 35274 -file-exec-file @var{file}
922fbb7b
AC
35275@end smallexample
35276
a2c02241
NR
35277Specify the executable file to be debugged. Unlike
35278@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
35279from this file. If used without argument, @value{GDBN} clears the information
35280about the executable file. No output is produced, except a completion
35281notification.
922fbb7b 35282
a2c02241
NR
35283@subsubheading @value{GDBN} Command
35284
35285The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
35286
35287@subsubheading Example
a2c02241
NR
35288
35289@smallexample
594fe323 35290(gdb)
a2c02241
NR
35291-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35292^done
594fe323 35293(gdb)
a2c02241 35294@end smallexample
922fbb7b
AC
35295
35296
9901a55b 35297@ignore
a2c02241
NR
35298@subheading The @code{-file-list-exec-sections} Command
35299@findex -file-list-exec-sections
922fbb7b
AC
35300
35301@subsubheading Synopsis
35302
35303@smallexample
a2c02241 35304 -file-list-exec-sections
922fbb7b
AC
35305@end smallexample
35306
a2c02241
NR
35307List the sections of the current executable file.
35308
922fbb7b
AC
35309@subsubheading @value{GDBN} Command
35310
a2c02241
NR
35311The @value{GDBN} command @samp{info file} shows, among the rest, the same
35312information as this command. @code{gdbtk} has a corresponding command
35313@samp{gdb_load_info}.
922fbb7b
AC
35314
35315@subsubheading Example
35316N.A.
9901a55b 35317@end ignore
922fbb7b
AC
35318
35319
a2c02241
NR
35320@subheading The @code{-file-list-exec-source-file} Command
35321@findex -file-list-exec-source-file
922fbb7b
AC
35322
35323@subsubheading Synopsis
35324
35325@smallexample
a2c02241 35326 -file-list-exec-source-file
922fbb7b
AC
35327@end smallexample
35328
a2c02241 35329List the line number, the current source file, and the absolute path
44288b44
NR
35330to the current source file for the current executable. The macro
35331information field has a value of @samp{1} or @samp{0} depending on
35332whether or not the file includes preprocessor macro information.
922fbb7b
AC
35333
35334@subsubheading @value{GDBN} Command
35335
a2c02241 35336The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
35337
35338@subsubheading Example
35339
922fbb7b 35340@smallexample
594fe323 35341(gdb)
a2c02241 35342123-file-list-exec-source-file
44288b44 35343123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
594fe323 35344(gdb)
922fbb7b
AC
35345@end smallexample
35346
35347
a2c02241
NR
35348@subheading The @code{-file-list-exec-source-files} Command
35349@findex -file-list-exec-source-files
922fbb7b
AC
35350
35351@subsubheading Synopsis
35352
35353@smallexample
a2c02241 35354 -file-list-exec-source-files
922fbb7b
AC
35355@end smallexample
35356
a2c02241
NR
35357List the source files for the current executable.
35358
f35a17b5
JK
35359It will always output both the filename and fullname (absolute file
35360name) of a source file.
922fbb7b
AC
35361
35362@subsubheading @value{GDBN} Command
35363
a2c02241
NR
35364The @value{GDBN} equivalent is @samp{info sources}.
35365@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
35366
35367@subsubheading Example
922fbb7b 35368@smallexample
594fe323 35369(gdb)
a2c02241
NR
35370-file-list-exec-source-files
35371^done,files=[
35372@{file=foo.c,fullname=/home/foo.c@},
35373@{file=/home/bar.c,fullname=/home/bar.c@},
35374@{file=gdb_could_not_find_fullpath.c@}]
594fe323 35375(gdb)
922fbb7b
AC
35376@end smallexample
35377
a2c02241
NR
35378@subheading The @code{-file-list-shared-libraries} Command
35379@findex -file-list-shared-libraries
922fbb7b 35380
a2c02241 35381@subsubheading Synopsis
922fbb7b 35382
a2c02241 35383@smallexample
51457a05 35384 -file-list-shared-libraries [ @var{regexp} ]
a2c02241 35385@end smallexample
922fbb7b 35386
a2c02241 35387List the shared libraries in the program.
51457a05
MAL
35388With a regular expression @var{regexp}, only those libraries whose
35389names match @var{regexp} are listed.
922fbb7b 35390
a2c02241 35391@subsubheading @value{GDBN} Command
922fbb7b 35392
51457a05
MAL
35393The corresponding @value{GDBN} command is @samp{info shared}. The fields
35394have a similar meaning to the @code{=library-loaded} notification.
35395The @code{ranges} field specifies the multiple segments belonging to this
35396library. Each range has the following fields:
35397
35398@table @samp
35399@item from
35400The address defining the inclusive lower bound of the segment.
35401@item to
35402The address defining the exclusive upper bound of the segment.
35403@end table
922fbb7b 35404
a2c02241 35405@subsubheading Example
51457a05
MAL
35406@smallexample
35407(gdb)
35408-file-list-exec-source-files
35409^done,shared-libraries=[
35410@{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"@}]@},
35411@{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"@}]@}]
35412(gdb)
35413@end smallexample
922fbb7b
AC
35414
35415
51457a05 35416@ignore
a2c02241
NR
35417@subheading The @code{-file-list-symbol-files} Command
35418@findex -file-list-symbol-files
922fbb7b 35419
a2c02241 35420@subsubheading Synopsis
922fbb7b 35421
a2c02241
NR
35422@smallexample
35423 -file-list-symbol-files
35424@end smallexample
922fbb7b 35425
a2c02241 35426List symbol files.
922fbb7b 35427
a2c02241 35428@subsubheading @value{GDBN} Command
922fbb7b 35429
a2c02241 35430The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 35431
a2c02241
NR
35432@subsubheading Example
35433N.A.
9901a55b 35434@end ignore
922fbb7b 35435
922fbb7b 35436
a2c02241
NR
35437@subheading The @code{-file-symbol-file} Command
35438@findex -file-symbol-file
922fbb7b 35439
a2c02241 35440@subsubheading Synopsis
922fbb7b 35441
a2c02241
NR
35442@smallexample
35443 -file-symbol-file @var{file}
35444@end smallexample
922fbb7b 35445
a2c02241
NR
35446Read symbol table info from the specified @var{file} argument. When
35447used without arguments, clears @value{GDBN}'s symbol table info. No output is
35448produced, except for a completion notification.
922fbb7b 35449
a2c02241 35450@subsubheading @value{GDBN} Command
922fbb7b 35451
a2c02241 35452The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 35453
a2c02241 35454@subsubheading Example
922fbb7b 35455
a2c02241 35456@smallexample
594fe323 35457(gdb)
a2c02241
NR
35458-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35459^done
594fe323 35460(gdb)
a2c02241 35461@end smallexample
922fbb7b 35462
a2c02241 35463@ignore
a2c02241
NR
35464@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35465@node GDB/MI Memory Overlay Commands
35466@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 35467
a2c02241 35468The memory overlay commands are not implemented.
922fbb7b 35469
a2c02241 35470@c @subheading -overlay-auto
922fbb7b 35471
a2c02241 35472@c @subheading -overlay-list-mapping-state
922fbb7b 35473
a2c02241 35474@c @subheading -overlay-list-overlays
922fbb7b 35475
a2c02241 35476@c @subheading -overlay-map
922fbb7b 35477
a2c02241 35478@c @subheading -overlay-off
922fbb7b 35479
a2c02241 35480@c @subheading -overlay-on
922fbb7b 35481
a2c02241 35482@c @subheading -overlay-unmap
922fbb7b 35483
a2c02241
NR
35484@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35485@node GDB/MI Signal Handling Commands
35486@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 35487
a2c02241 35488Signal handling commands are not implemented.
922fbb7b 35489
a2c02241 35490@c @subheading -signal-handle
922fbb7b 35491
a2c02241 35492@c @subheading -signal-list-handle-actions
922fbb7b 35493
a2c02241
NR
35494@c @subheading -signal-list-signal-types
35495@end ignore
922fbb7b 35496
922fbb7b 35497
a2c02241
NR
35498@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35499@node GDB/MI Target Manipulation
35500@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
35501
35502
a2c02241
NR
35503@subheading The @code{-target-attach} Command
35504@findex -target-attach
922fbb7b
AC
35505
35506@subsubheading Synopsis
35507
35508@smallexample
c3b108f7 35509 -target-attach @var{pid} | @var{gid} | @var{file}
922fbb7b
AC
35510@end smallexample
35511
c3b108f7
VP
35512Attach to a process @var{pid} or a file @var{file} outside of
35513@value{GDBN}, or a thread group @var{gid}. If attaching to a thread
35514group, the id previously returned by
35515@samp{-list-thread-groups --available} must be used.
922fbb7b 35516
79a6e687 35517@subsubheading @value{GDBN} Command
922fbb7b 35518
a2c02241 35519The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 35520
a2c02241 35521@subsubheading Example
b56e7235
VP
35522@smallexample
35523(gdb)
35524-target-attach 34
35525=thread-created,id="1"
5ae4183a 35526*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
b56e7235
VP
35527^done
35528(gdb)
35529@end smallexample
a2c02241 35530
9901a55b 35531@ignore
a2c02241
NR
35532@subheading The @code{-target-compare-sections} Command
35533@findex -target-compare-sections
922fbb7b
AC
35534
35535@subsubheading Synopsis
35536
35537@smallexample
a2c02241 35538 -target-compare-sections [ @var{section} ]
922fbb7b
AC
35539@end smallexample
35540
a2c02241
NR
35541Compare data of section @var{section} on target to the exec file.
35542Without the argument, all sections are compared.
922fbb7b 35543
a2c02241 35544@subsubheading @value{GDBN} Command
922fbb7b 35545
a2c02241 35546The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 35547
a2c02241
NR
35548@subsubheading Example
35549N.A.
9901a55b 35550@end ignore
a2c02241
NR
35551
35552
35553@subheading The @code{-target-detach} Command
35554@findex -target-detach
922fbb7b
AC
35555
35556@subsubheading Synopsis
35557
35558@smallexample
c3b108f7 35559 -target-detach [ @var{pid} | @var{gid} ]
922fbb7b
AC
35560@end smallexample
35561
a2c02241 35562Detach from the remote target which normally resumes its execution.
c3b108f7
VP
35563If either @var{pid} or @var{gid} is specified, detaches from either
35564the specified process, or specified thread group. There's no output.
a2c02241 35565
79a6e687 35566@subsubheading @value{GDBN} Command
a2c02241
NR
35567
35568The corresponding @value{GDBN} command is @samp{detach}.
35569
35570@subsubheading Example
922fbb7b
AC
35571
35572@smallexample
594fe323 35573(gdb)
a2c02241
NR
35574-target-detach
35575^done
594fe323 35576(gdb)
922fbb7b
AC
35577@end smallexample
35578
35579
a2c02241
NR
35580@subheading The @code{-target-disconnect} Command
35581@findex -target-disconnect
922fbb7b
AC
35582
35583@subsubheading Synopsis
35584
123dc839 35585@smallexample
a2c02241 35586 -target-disconnect
123dc839 35587@end smallexample
922fbb7b 35588
a2c02241
NR
35589Disconnect from the remote target. There's no output and the target is
35590generally not resumed.
35591
79a6e687 35592@subsubheading @value{GDBN} Command
a2c02241
NR
35593
35594The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
35595
35596@subsubheading Example
922fbb7b
AC
35597
35598@smallexample
594fe323 35599(gdb)
a2c02241
NR
35600-target-disconnect
35601^done
594fe323 35602(gdb)
922fbb7b
AC
35603@end smallexample
35604
35605
a2c02241
NR
35606@subheading The @code{-target-download} Command
35607@findex -target-download
922fbb7b
AC
35608
35609@subsubheading Synopsis
35610
35611@smallexample
a2c02241 35612 -target-download
922fbb7b
AC
35613@end smallexample
35614
a2c02241
NR
35615Loads the executable onto the remote target.
35616It prints out an update message every half second, which includes the fields:
35617
35618@table @samp
35619@item section
35620The name of the section.
35621@item section-sent
35622The size of what has been sent so far for that section.
35623@item section-size
35624The size of the section.
35625@item total-sent
35626The total size of what was sent so far (the current and the previous sections).
35627@item total-size
35628The size of the overall executable to download.
35629@end table
35630
35631@noindent
35632Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
35633@sc{gdb/mi} Output Syntax}).
35634
35635In addition, it prints the name and size of the sections, as they are
35636downloaded. These messages include the following fields:
35637
35638@table @samp
35639@item section
35640The name of the section.
35641@item section-size
35642The size of the section.
35643@item total-size
35644The size of the overall executable to download.
35645@end table
35646
35647@noindent
35648At the end, a summary is printed.
35649
35650@subsubheading @value{GDBN} Command
35651
35652The corresponding @value{GDBN} command is @samp{load}.
35653
35654@subsubheading Example
35655
35656Note: each status message appears on a single line. Here the messages
35657have been broken down so that they can fit onto a page.
922fbb7b
AC
35658
35659@smallexample
594fe323 35660(gdb)
a2c02241
NR
35661-target-download
35662+download,@{section=".text",section-size="6668",total-size="9880"@}
35663+download,@{section=".text",section-sent="512",section-size="6668",
35664total-sent="512",total-size="9880"@}
35665+download,@{section=".text",section-sent="1024",section-size="6668",
35666total-sent="1024",total-size="9880"@}
35667+download,@{section=".text",section-sent="1536",section-size="6668",
35668total-sent="1536",total-size="9880"@}
35669+download,@{section=".text",section-sent="2048",section-size="6668",
35670total-sent="2048",total-size="9880"@}
35671+download,@{section=".text",section-sent="2560",section-size="6668",
35672total-sent="2560",total-size="9880"@}
35673+download,@{section=".text",section-sent="3072",section-size="6668",
35674total-sent="3072",total-size="9880"@}
35675+download,@{section=".text",section-sent="3584",section-size="6668",
35676total-sent="3584",total-size="9880"@}
35677+download,@{section=".text",section-sent="4096",section-size="6668",
35678total-sent="4096",total-size="9880"@}
35679+download,@{section=".text",section-sent="4608",section-size="6668",
35680total-sent="4608",total-size="9880"@}
35681+download,@{section=".text",section-sent="5120",section-size="6668",
35682total-sent="5120",total-size="9880"@}
35683+download,@{section=".text",section-sent="5632",section-size="6668",
35684total-sent="5632",total-size="9880"@}
35685+download,@{section=".text",section-sent="6144",section-size="6668",
35686total-sent="6144",total-size="9880"@}
35687+download,@{section=".text",section-sent="6656",section-size="6668",
35688total-sent="6656",total-size="9880"@}
35689+download,@{section=".init",section-size="28",total-size="9880"@}
35690+download,@{section=".fini",section-size="28",total-size="9880"@}
35691+download,@{section=".data",section-size="3156",total-size="9880"@}
35692+download,@{section=".data",section-sent="512",section-size="3156",
35693total-sent="7236",total-size="9880"@}
35694+download,@{section=".data",section-sent="1024",section-size="3156",
35695total-sent="7748",total-size="9880"@}
35696+download,@{section=".data",section-sent="1536",section-size="3156",
35697total-sent="8260",total-size="9880"@}
35698+download,@{section=".data",section-sent="2048",section-size="3156",
35699total-sent="8772",total-size="9880"@}
35700+download,@{section=".data",section-sent="2560",section-size="3156",
35701total-sent="9284",total-size="9880"@}
35702+download,@{section=".data",section-sent="3072",section-size="3156",
35703total-sent="9796",total-size="9880"@}
35704^done,address="0x10004",load-size="9880",transfer-rate="6586",
35705write-rate="429"
594fe323 35706(gdb)
922fbb7b
AC
35707@end smallexample
35708
35709
9901a55b 35710@ignore
a2c02241
NR
35711@subheading The @code{-target-exec-status} Command
35712@findex -target-exec-status
922fbb7b
AC
35713
35714@subsubheading Synopsis
35715
35716@smallexample
a2c02241 35717 -target-exec-status
922fbb7b
AC
35718@end smallexample
35719
a2c02241
NR
35720Provide information on the state of the target (whether it is running or
35721not, for instance).
922fbb7b 35722
a2c02241 35723@subsubheading @value{GDBN} Command
922fbb7b 35724
a2c02241
NR
35725There's no equivalent @value{GDBN} command.
35726
35727@subsubheading Example
35728N.A.
922fbb7b 35729
a2c02241
NR
35730
35731@subheading The @code{-target-list-available-targets} Command
35732@findex -target-list-available-targets
922fbb7b
AC
35733
35734@subsubheading Synopsis
35735
35736@smallexample
a2c02241 35737 -target-list-available-targets
922fbb7b
AC
35738@end smallexample
35739
a2c02241 35740List the possible targets to connect to.
922fbb7b 35741
a2c02241 35742@subsubheading @value{GDBN} Command
922fbb7b 35743
a2c02241 35744The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 35745
a2c02241
NR
35746@subsubheading Example
35747N.A.
35748
35749
35750@subheading The @code{-target-list-current-targets} Command
35751@findex -target-list-current-targets
922fbb7b
AC
35752
35753@subsubheading Synopsis
35754
35755@smallexample
a2c02241 35756 -target-list-current-targets
922fbb7b
AC
35757@end smallexample
35758
a2c02241 35759Describe the current target.
922fbb7b 35760
a2c02241 35761@subsubheading @value{GDBN} Command
922fbb7b 35762
a2c02241
NR
35763The corresponding information is printed by @samp{info file} (among
35764other things).
922fbb7b 35765
a2c02241
NR
35766@subsubheading Example
35767N.A.
35768
35769
35770@subheading The @code{-target-list-parameters} Command
35771@findex -target-list-parameters
922fbb7b
AC
35772
35773@subsubheading Synopsis
35774
35775@smallexample
a2c02241 35776 -target-list-parameters
922fbb7b
AC
35777@end smallexample
35778
a2c02241 35779@c ????
9901a55b 35780@end ignore
a2c02241
NR
35781
35782@subsubheading @value{GDBN} Command
35783
35784No equivalent.
922fbb7b
AC
35785
35786@subsubheading Example
a2c02241
NR
35787N.A.
35788
78cbbba8
LM
35789@subheading The @code{-target-flash-erase} Command
35790@findex -target-flash-erase
35791
35792@subsubheading Synopsis
35793
35794@smallexample
35795 -target-flash-erase
35796@end smallexample
35797
35798Erases all known flash memory regions on the target.
35799
35800The corresponding @value{GDBN} command is @samp{flash-erase}.
35801
35802The output is a list of flash regions that have been erased, with starting
35803addresses and memory region sizes.
35804
35805@smallexample
35806(gdb)
35807-target-flash-erase
35808^done,erased-regions=@{address="0x0",size="0x40000"@}
35809(gdb)
35810@end smallexample
a2c02241
NR
35811
35812@subheading The @code{-target-select} Command
35813@findex -target-select
35814
35815@subsubheading Synopsis
922fbb7b
AC
35816
35817@smallexample
a2c02241 35818 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
35819@end smallexample
35820
a2c02241 35821Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 35822
a2c02241
NR
35823@table @samp
35824@item @var{type}
75c99385 35825The type of target, for instance @samp{remote}, etc.
a2c02241
NR
35826@item @var{parameters}
35827Device names, host names and the like. @xref{Target Commands, ,
79a6e687 35828Commands for Managing Targets}, for more details.
a2c02241
NR
35829@end table
35830
35831The output is a connection notification, followed by the address at
35832which the target program is, in the following form:
922fbb7b
AC
35833
35834@smallexample
a2c02241
NR
35835^connected,addr="@var{address}",func="@var{function name}",
35836 args=[@var{arg list}]
922fbb7b
AC
35837@end smallexample
35838
a2c02241
NR
35839@subsubheading @value{GDBN} Command
35840
35841The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
35842
35843@subsubheading Example
922fbb7b 35844
265eeb58 35845@smallexample
594fe323 35846(gdb)
75c99385 35847-target-select remote /dev/ttya
a2c02241 35848^connected,addr="0xfe00a300",func="??",args=[]
594fe323 35849(gdb)
265eeb58 35850@end smallexample
ef21caaf 35851
a6b151f1
DJ
35852@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35853@node GDB/MI File Transfer Commands
35854@section @sc{gdb/mi} File Transfer Commands
35855
35856
35857@subheading The @code{-target-file-put} Command
35858@findex -target-file-put
35859
35860@subsubheading Synopsis
35861
35862@smallexample
35863 -target-file-put @var{hostfile} @var{targetfile}
35864@end smallexample
35865
35866Copy file @var{hostfile} from the host system (the machine running
35867@value{GDBN}) to @var{targetfile} on the target system.
35868
35869@subsubheading @value{GDBN} Command
35870
35871The corresponding @value{GDBN} command is @samp{remote put}.
35872
35873@subsubheading Example
35874
35875@smallexample
35876(gdb)
35877-target-file-put localfile remotefile
35878^done
35879(gdb)
35880@end smallexample
35881
35882
1763a388 35883@subheading The @code{-target-file-get} Command
a6b151f1
DJ
35884@findex -target-file-get
35885
35886@subsubheading Synopsis
35887
35888@smallexample
35889 -target-file-get @var{targetfile} @var{hostfile}
35890@end smallexample
35891
35892Copy file @var{targetfile} from the target system to @var{hostfile}
35893on the host system.
35894
35895@subsubheading @value{GDBN} Command
35896
35897The corresponding @value{GDBN} command is @samp{remote get}.
35898
35899@subsubheading Example
35900
35901@smallexample
35902(gdb)
35903-target-file-get remotefile localfile
35904^done
35905(gdb)
35906@end smallexample
35907
35908
35909@subheading The @code{-target-file-delete} Command
35910@findex -target-file-delete
35911
35912@subsubheading Synopsis
35913
35914@smallexample
35915 -target-file-delete @var{targetfile}
35916@end smallexample
35917
35918Delete @var{targetfile} from the target system.
35919
35920@subsubheading @value{GDBN} Command
35921
35922The corresponding @value{GDBN} command is @samp{remote delete}.
35923
35924@subsubheading Example
35925
35926@smallexample
35927(gdb)
35928-target-file-delete remotefile
35929^done
35930(gdb)
35931@end smallexample
35932
35933
58d06528
JB
35934@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35935@node GDB/MI Ada Exceptions Commands
35936@section Ada Exceptions @sc{gdb/mi} Commands
35937
35938@subheading The @code{-info-ada-exceptions} Command
35939@findex -info-ada-exceptions
35940
35941@subsubheading Synopsis
35942
35943@smallexample
35944 -info-ada-exceptions [ @var{regexp}]
35945@end smallexample
35946
35947List all Ada exceptions defined within the program being debugged.
35948With a regular expression @var{regexp}, only those exceptions whose
35949names match @var{regexp} are listed.
35950
35951@subsubheading @value{GDBN} Command
35952
35953The corresponding @value{GDBN} command is @samp{info exceptions}.
35954
35955@subsubheading Result
35956
35957The result is a table of Ada exceptions. The following columns are
35958defined for each exception:
35959
35960@table @samp
35961@item name
35962The name of the exception.
35963
35964@item address
35965The address of the exception.
35966
35967@end table
35968
35969@subsubheading Example
35970
35971@smallexample
35972-info-ada-exceptions aint
35973^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
35974hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
35975@{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
35976body=[@{name="constraint_error",address="0x0000000000613da0"@},
35977@{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
35978@end smallexample
35979
35980@subheading Catching Ada Exceptions
35981
35982The commands describing how to ask @value{GDBN} to stop when a program
35983raises an exception are described at @ref{Ada Exception GDB/MI
35984Catchpoint Commands}.
35985
35986
ef21caaf 35987@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d192b373
JB
35988@node GDB/MI Support Commands
35989@section @sc{gdb/mi} Support Commands
ef21caaf 35990
d192b373
JB
35991Since new commands and features get regularly added to @sc{gdb/mi},
35992some commands are available to help front-ends query the debugger
35993about support for these capabilities. Similarly, it is also possible
35994to query @value{GDBN} about target support of certain features.
ef21caaf 35995
6b7cbff1
JB
35996@subheading The @code{-info-gdb-mi-command} Command
35997@cindex @code{-info-gdb-mi-command}
35998@findex -info-gdb-mi-command
35999
36000@subsubheading Synopsis
36001
36002@smallexample
36003 -info-gdb-mi-command @var{cmd_name}
36004@end smallexample
36005
36006Query support for the @sc{gdb/mi} command named @var{cmd_name}.
36007
36008Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
36009is technically not part of the command name (@pxref{GDB/MI Input
36010Syntax}), and thus should be omitted in @var{cmd_name}. However,
36011for ease of use, this command also accepts the form with the leading
36012dash.
36013
36014@subsubheading @value{GDBN} Command
36015
36016There is no corresponding @value{GDBN} command.
36017
36018@subsubheading Result
36019
36020The result is a tuple. There is currently only one field:
36021
36022@table @samp
36023@item exists
36024This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
36025@code{"false"} otherwise.
36026
36027@end table
36028
36029@subsubheading Example
36030
36031Here is an example where the @sc{gdb/mi} command does not exist:
36032
36033@smallexample
36034-info-gdb-mi-command unsupported-command
36035^done,command=@{exists="false"@}
36036@end smallexample
36037
36038@noindent
36039And here is an example where the @sc{gdb/mi} command is known
36040to the debugger:
36041
36042@smallexample
36043-info-gdb-mi-command symbol-list-lines
36044^done,command=@{exists="true"@}
36045@end smallexample
36046
084344da
VP
36047@subheading The @code{-list-features} Command
36048@findex -list-features
9b26f0fb 36049@cindex supported @sc{gdb/mi} features, list
084344da
VP
36050
36051Returns a list of particular features of the MI protocol that
36052this version of gdb implements. A feature can be a command,
36053or a new field in an output of some command, or even an
36054important bugfix. While a frontend can sometimes detect presence
36055of a feature at runtime, it is easier to perform detection at debugger
d192b373 36056startup.
084344da
VP
36057
36058The command returns a list of strings, with each string naming an
36059available feature. Each returned string is just a name, it does not
d192b373 36060have any internal structure. The list of possible feature names
084344da
VP
36061is given below.
36062
36063Example output:
36064
36065@smallexample
36066(gdb) -list-features
36067^done,result=["feature1","feature2"]
36068@end smallexample
36069
36070The current list of features is:
36071
edef6000 36072@ftable @samp
30e026bb 36073@item frozen-varobjs
a05336a1 36074Indicates support for the @code{-var-set-frozen} command, as well
6b92c0d3 36075as possible presence of the @code{frozen} field in the output
30e026bb
VP
36076of @code{-varobj-create}.
36077@item pending-breakpoints
a05336a1
JB
36078Indicates support for the @option{-f} option to the @code{-break-insert}
36079command.
b6313243 36080@item python
a05336a1 36081Indicates Python scripting support, Python-based
b6313243
TT
36082pretty-printing commands, and possible presence of the
36083@samp{display_hint} field in the output of @code{-var-list-children}
30e026bb 36084@item thread-info
a05336a1 36085Indicates support for the @code{-thread-info} command.
8dedea02 36086@item data-read-memory-bytes
a05336a1 36087Indicates support for the @code{-data-read-memory-bytes} and the
8dedea02 36088@code{-data-write-memory-bytes} commands.
39c4d40a
TT
36089@item breakpoint-notifications
36090Indicates that changes to breakpoints and breakpoints created via the
36091CLI will be announced via async records.
5d77fe44 36092@item ada-task-info
6adcee18 36093Indicates support for the @code{-ada-task-info} command.
422ad5c2
JB
36094@item language-option
36095Indicates that all @sc{gdb/mi} commands accept the @option{--language}
36096option (@pxref{Context management}).
6b7cbff1
JB
36097@item info-gdb-mi-command
36098Indicates support for the @code{-info-gdb-mi-command} command.
2ea126fa
JB
36099@item undefined-command-error-code
36100Indicates support for the "undefined-command" error code in error result
36101records, produced when trying to execute an undefined @sc{gdb/mi} command
36102(@pxref{GDB/MI Result Records}).
72bfa06c
JB
36103@item exec-run-start-option
36104Indicates that the @code{-exec-run} command supports the @option{--start}
36105option (@pxref{GDB/MI Program Execution}).
26fb3983
JV
36106@item data-disassemble-a-option
36107Indicates that the @code{-data-disassemble} command supports the @option{-a}
36108option (@pxref{GDB/MI Data Manipulation}).
edef6000 36109@end ftable
084344da 36110
c6ebd6cf
VP
36111@subheading The @code{-list-target-features} Command
36112@findex -list-target-features
36113
36114Returns a list of particular features that are supported by the
36115target. Those features affect the permitted MI commands, but
36116unlike the features reported by the @code{-list-features} command, the
36117features depend on which target GDB is using at the moment. Whenever
36118a target can change, due to commands such as @code{-target-select},
36119@code{-target-attach} or @code{-exec-run}, the list of target features
36120may change, and the frontend should obtain it again.
36121Example output:
36122
36123@smallexample
b3d3b4bd 36124(gdb) -list-target-features
c6ebd6cf
VP
36125^done,result=["async"]
36126@end smallexample
36127
36128The current list of features is:
36129
36130@table @samp
36131@item async
36132Indicates that the target is capable of asynchronous command
36133execution, which means that @value{GDBN} will accept further commands
36134while the target is running.
36135
f75d858b
MK
36136@item reverse
36137Indicates that the target is capable of reverse execution.
36138@xref{Reverse Execution}, for more information.
36139
c6ebd6cf
VP
36140@end table
36141
d192b373
JB
36142@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36143@node GDB/MI Miscellaneous Commands
36144@section Miscellaneous @sc{gdb/mi} Commands
36145
36146@c @subheading -gdb-complete
36147
36148@subheading The @code{-gdb-exit} Command
36149@findex -gdb-exit
36150
36151@subsubheading Synopsis
36152
36153@smallexample
36154 -gdb-exit
36155@end smallexample
36156
36157Exit @value{GDBN} immediately.
36158
36159@subsubheading @value{GDBN} Command
36160
36161Approximately corresponds to @samp{quit}.
36162
36163@subsubheading Example
36164
36165@smallexample
36166(gdb)
36167-gdb-exit
36168^exit
36169@end smallexample
36170
36171
36172@ignore
36173@subheading The @code{-exec-abort} Command
36174@findex -exec-abort
36175
36176@subsubheading Synopsis
36177
36178@smallexample
36179 -exec-abort
36180@end smallexample
36181
36182Kill the inferior running program.
36183
36184@subsubheading @value{GDBN} Command
36185
36186The corresponding @value{GDBN} command is @samp{kill}.
36187
36188@subsubheading Example
36189N.A.
36190@end ignore
36191
36192
36193@subheading The @code{-gdb-set} Command
36194@findex -gdb-set
36195
36196@subsubheading Synopsis
36197
36198@smallexample
36199 -gdb-set
36200@end smallexample
36201
36202Set an internal @value{GDBN} variable.
36203@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
36204
36205@subsubheading @value{GDBN} Command
36206
36207The corresponding @value{GDBN} command is @samp{set}.
36208
36209@subsubheading Example
36210
36211@smallexample
36212(gdb)
36213-gdb-set $foo=3
36214^done
36215(gdb)
36216@end smallexample
36217
36218
36219@subheading The @code{-gdb-show} Command
36220@findex -gdb-show
36221
36222@subsubheading Synopsis
36223
36224@smallexample
36225 -gdb-show
36226@end smallexample
36227
36228Show the current value of a @value{GDBN} variable.
36229
36230@subsubheading @value{GDBN} Command
36231
36232The corresponding @value{GDBN} command is @samp{show}.
36233
36234@subsubheading Example
36235
36236@smallexample
36237(gdb)
36238-gdb-show annotate
36239^done,value="0"
36240(gdb)
36241@end smallexample
36242
36243@c @subheading -gdb-source
36244
36245
36246@subheading The @code{-gdb-version} Command
36247@findex -gdb-version
36248
36249@subsubheading Synopsis
36250
36251@smallexample
36252 -gdb-version
36253@end smallexample
36254
36255Show version information for @value{GDBN}. Used mostly in testing.
36256
36257@subsubheading @value{GDBN} Command
36258
36259The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
36260default shows this information when you start an interactive session.
36261
36262@subsubheading Example
36263
36264@c This example modifies the actual output from GDB to avoid overfull
36265@c box in TeX.
36266@smallexample
36267(gdb)
36268-gdb-version
36269~GNU gdb 5.2.1
36270~Copyright 2000 Free Software Foundation, Inc.
36271~GDB is free software, covered by the GNU General Public License, and
36272~you are welcome to change it and/or distribute copies of it under
36273~ certain conditions.
36274~Type "show copying" to see the conditions.
36275~There is absolutely no warranty for GDB. Type "show warranty" for
36276~ details.
36277~This GDB was configured as
36278 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
36279^done
36280(gdb)
36281@end smallexample
36282
c3b108f7
VP
36283@subheading The @code{-list-thread-groups} Command
36284@findex -list-thread-groups
36285
36286@subheading Synopsis
36287
36288@smallexample
dc146f7c 36289-list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
c3b108f7
VP
36290@end smallexample
36291
dc146f7c
VP
36292Lists thread groups (@pxref{Thread groups}). When a single thread
36293group is passed as the argument, lists the children of that group.
36294When several thread group are passed, lists information about those
36295thread groups. Without any parameters, lists information about all
36296top-level thread groups.
36297
36298Normally, thread groups that are being debugged are reported.
36299With the @samp{--available} option, @value{GDBN} reports thread groups
36300available on the target.
36301
36302The output of this command may have either a @samp{threads} result or
36303a @samp{groups} result. The @samp{thread} result has a list of tuples
36304as value, with each tuple describing a thread (@pxref{GDB/MI Thread
36305Information}). The @samp{groups} result has a list of tuples as value,
36306each tuple describing a thread group. If top-level groups are
36307requested (that is, no parameter is passed), or when several groups
36308are passed, the output always has a @samp{groups} result. The format
36309of the @samp{group} result is described below.
36310
36311To reduce the number of roundtrips it's possible to list thread groups
36312together with their children, by passing the @samp{--recurse} option
36313and the recursion depth. Presently, only recursion depth of 1 is
36314permitted. If this option is present, then every reported thread group
36315will also include its children, either as @samp{group} or
36316@samp{threads} field.
36317
36318In general, any combination of option and parameters is permitted, with
36319the following caveats:
36320
36321@itemize @bullet
36322@item
36323When a single thread group is passed, the output will typically
36324be the @samp{threads} result. Because threads may not contain
36325anything, the @samp{recurse} option will be ignored.
36326
36327@item
36328When the @samp{--available} option is passed, limited information may
36329be available. In particular, the list of threads of a process might
36330be inaccessible. Further, specifying specific thread groups might
36331not give any performance advantage over listing all thread groups.
36332The frontend should assume that @samp{-list-thread-groups --available}
36333is always an expensive operation and cache the results.
36334
36335@end itemize
36336
36337The @samp{groups} result is a list of tuples, where each tuple may
36338have the following fields:
36339
36340@table @code
36341@item id
36342Identifier of the thread group. This field is always present.
a79b8f6e
VP
36343The identifier is an opaque string; frontends should not try to
36344convert it to an integer, even though it might look like one.
dc146f7c
VP
36345
36346@item type
36347The type of the thread group. At present, only @samp{process} is a
36348valid type.
36349
36350@item pid
36351The target-specific process identifier. This field is only present
a79b8f6e 36352for thread groups of type @samp{process} and only if the process exists.
c3b108f7 36353
2ddf4301
SM
36354@item exit-code
36355The exit code of this group's last exited thread, formatted in octal.
36356This field is only present for thread groups of type @samp{process} and
36357only if the process is not running.
36358
dc146f7c
VP
36359@item num_children
36360The number of children this thread group has. This field may be
36361absent for an available thread group.
36362
36363@item threads
36364This field has a list of tuples as value, each tuple describing a
36365thread. It may be present if the @samp{--recurse} option is
36366specified, and it's actually possible to obtain the threads.
36367
36368@item cores
36369This field is a list of integers, each identifying a core that one
36370thread of the group is running on. This field may be absent if
36371such information is not available.
36372
a79b8f6e
VP
36373@item executable
36374The name of the executable file that corresponds to this thread group.
36375The field is only present for thread groups of type @samp{process},
36376and only if there is a corresponding executable file.
36377
dc146f7c 36378@end table
c3b108f7
VP
36379
36380@subheading Example
36381
36382@smallexample
36383@value{GDBP}
36384-list-thread-groups
36385^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
36386-list-thread-groups 17
36387^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
36388 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
36389@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
36390 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
6d52907e 36391 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
dc146f7c
VP
36392-list-thread-groups --available
36393^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
36394-list-thread-groups --available --recurse 1
36395 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36396 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36397 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
36398-list-thread-groups --available --recurse 1 17 18
36399^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36400 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36401 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
c3b108f7 36402@end smallexample
c6ebd6cf 36403
f3e0e960
SS
36404@subheading The @code{-info-os} Command
36405@findex -info-os
36406
36407@subsubheading Synopsis
36408
36409@smallexample
36410-info-os [ @var{type} ]
36411@end smallexample
36412
36413If no argument is supplied, the command returns a table of available
36414operating-system-specific information types. If one of these types is
36415supplied as an argument @var{type}, then the command returns a table
36416of data of that type.
36417
36418The types of information available depend on the target operating
36419system.
36420
36421@subsubheading @value{GDBN} Command
36422
36423The corresponding @value{GDBN} command is @samp{info os}.
36424
36425@subsubheading Example
36426
36427When run on a @sc{gnu}/Linux system, the output will look something
36428like this:
36429
36430@smallexample
36431@value{GDBP}
36432-info-os
d33279b3 36433^done,OSDataTable=@{nr_rows="10",nr_cols="3",
f3e0e960 36434hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
71caed83
SS
36435 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
36436 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
d33279b3
AT
36437body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
36438 col2="CPUs"@},
36439 item=@{col0="files",col1="Listing of all file descriptors",
36440 col2="File descriptors"@},
36441 item=@{col0="modules",col1="Listing of all loaded kernel modules",
36442 col2="Kernel modules"@},
36443 item=@{col0="msg",col1="Listing of all message queues",
36444 col2="Message queues"@},
36445 item=@{col0="processes",col1="Listing of all processes",
71caed83
SS
36446 col2="Processes"@},
36447 item=@{col0="procgroups",col1="Listing of all process groups",
36448 col2="Process groups"@},
71caed83
SS
36449 item=@{col0="semaphores",col1="Listing of all semaphores",
36450 col2="Semaphores"@},
d33279b3
AT
36451 item=@{col0="shm",col1="Listing of all shared-memory regions",
36452 col2="Shared-memory regions"@},
36453 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
36454 col2="Sockets"@},
36455 item=@{col0="threads",col1="Listing of all threads",
36456 col2="Threads"@}]
f3e0e960
SS
36457@value{GDBP}
36458-info-os processes
36459^done,OSDataTable=@{nr_rows="190",nr_cols="4",
36460hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
36461 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
36462 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
36463 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
36464body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
36465 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
36466 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
36467 ...
36468 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
36469 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
36470(gdb)
36471@end smallexample
a79b8f6e 36472
71caed83
SS
36473(Note that the MI output here includes a @code{"Title"} column that
36474does not appear in command-line @code{info os}; this column is useful
36475for MI clients that want to enumerate the types of data, such as in a
36476popup menu, but is needless clutter on the command line, and
36477@code{info os} omits it.)
36478
a79b8f6e
VP
36479@subheading The @code{-add-inferior} Command
36480@findex -add-inferior
36481
36482@subheading Synopsis
36483
36484@smallexample
36485-add-inferior
36486@end smallexample
36487
65c574f6 36488Creates a new inferior (@pxref{Inferiors Connections and Programs}). The created
a79b8f6e
VP
36489inferior is not associated with any executable. Such association may
36490be established with the @samp{-file-exec-and-symbols} command
36491(@pxref{GDB/MI File Commands}). The command response has a single
b7742092 36492field, @samp{inferior}, whose value is the identifier of the
a79b8f6e
VP
36493thread group corresponding to the new inferior.
36494
36495@subheading Example
36496
36497@smallexample
36498@value{GDBP}
36499-add-inferior
b7742092 36500^done,inferior="i3"
a79b8f6e
VP
36501@end smallexample
36502
ef21caaf
NR
36503@subheading The @code{-interpreter-exec} Command
36504@findex -interpreter-exec
36505
36506@subheading Synopsis
36507
36508@smallexample
36509-interpreter-exec @var{interpreter} @var{command}
36510@end smallexample
a2c02241 36511@anchor{-interpreter-exec}
ef21caaf
NR
36512
36513Execute the specified @var{command} in the given @var{interpreter}.
36514
36515@subheading @value{GDBN} Command
36516
36517The corresponding @value{GDBN} command is @samp{interpreter-exec}.
36518
36519@subheading Example
36520
36521@smallexample
594fe323 36522(gdb)
ef21caaf
NR
36523-interpreter-exec console "break main"
36524&"During symbol reading, couldn't parse type; debugger out of date?.\n"
36525&"During symbol reading, bad structure-type format.\n"
36526~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
36527^done
594fe323 36528(gdb)
ef21caaf
NR
36529@end smallexample
36530
36531@subheading The @code{-inferior-tty-set} Command
36532@findex -inferior-tty-set
36533
36534@subheading Synopsis
36535
36536@smallexample
36537-inferior-tty-set /dev/pts/1
36538@end smallexample
36539
36540Set terminal for future runs of the program being debugged.
36541
36542@subheading @value{GDBN} Command
36543
36544The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
36545
36546@subheading Example
36547
36548@smallexample
594fe323 36549(gdb)
ef21caaf
NR
36550-inferior-tty-set /dev/pts/1
36551^done
594fe323 36552(gdb)
ef21caaf
NR
36553@end smallexample
36554
36555@subheading The @code{-inferior-tty-show} Command
36556@findex -inferior-tty-show
36557
36558@subheading Synopsis
36559
36560@smallexample
36561-inferior-tty-show
36562@end smallexample
36563
36564Show terminal for future runs of program being debugged.
36565
36566@subheading @value{GDBN} Command
36567
36568The corresponding @value{GDBN} command is @samp{show inferior-tty}.
36569
36570@subheading Example
36571
36572@smallexample
594fe323 36573(gdb)
ef21caaf
NR
36574-inferior-tty-set /dev/pts/1
36575^done
594fe323 36576(gdb)
ef21caaf
NR
36577-inferior-tty-show
36578^done,inferior_tty_terminal="/dev/pts/1"
594fe323 36579(gdb)
ef21caaf 36580@end smallexample
922fbb7b 36581
a4eefcd8
NR
36582@subheading The @code{-enable-timings} Command
36583@findex -enable-timings
36584
36585@subheading Synopsis
36586
36587@smallexample
36588-enable-timings [yes | no]
36589@end smallexample
36590
36591Toggle the printing of the wallclock, user and system times for an MI
36592command as a field in its output. This command is to help frontend
36593developers optimize the performance of their code. No argument is
36594equivalent to @samp{yes}.
36595
36596@subheading @value{GDBN} Command
36597
36598No equivalent.
36599
36600@subheading Example
36601
36602@smallexample
36603(gdb)
36604-enable-timings
36605^done
36606(gdb)
36607-break-insert main
36608^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
36609addr="0x080484ed",func="main",file="myprog.c",
998580f1
MK
36610fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
36611times="0"@},
a4eefcd8
NR
36612time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
36613(gdb)
36614-enable-timings no
36615^done
36616(gdb)
36617-exec-run
36618^running
36619(gdb)
a47ec5fe 36620*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
a4eefcd8
NR
36621frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
36622@{name="argv",value="0xbfb60364"@}],file="myprog.c",
6d52907e 36623fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
a4eefcd8
NR
36624(gdb)
36625@end smallexample
36626
26648588
JV
36627@subheading The @code{-complete} Command
36628@findex -complete
36629
36630@subheading Synopsis
36631
36632@smallexample
36633-complete @var{command}
36634@end smallexample
36635
36636Show a list of completions for partially typed CLI @var{command}.
36637
36638This command is intended for @sc{gdb/mi} frontends that cannot use two separate
7166f90a 36639CLI and MI channels --- for example: because of lack of PTYs like on Windows or
26648588
JV
36640because @value{GDBN} is used remotely via a SSH connection.
36641
36642@subheading Result
36643
36644The result consists of two or three fields:
36645
36646@table @samp
36647@item completion
36648This field contains the completed @var{command}. If @var{command}
36649has no known completions, this field is omitted.
36650
36651@item matches
36652This field contains a (possibly empty) array of matches. It is always present.
36653
36654@item max_completions_reached
36655This field contains @code{1} if number of known completions is above
7166f90a 36656@code{max-completions} limit (@pxref{Completion}), otherwise it contains
26648588
JV
36657@code{0}. It is always present.
36658
36659@end table
36660
36661@subheading @value{GDBN} Command
36662
36663The corresponding @value{GDBN} command is @samp{complete}.
36664
36665@subheading Example
36666
36667@smallexample
36668(gdb)
36669-complete br
36670^done,completion="break",
36671 matches=["break","break-range"],
36672 max_completions_reached="0"
36673(gdb)
36674-complete "b ma"
36675^done,completion="b ma",
36676 matches=["b madvise","b main"],max_completions_reached="0"
36677(gdb)
36678-complete "b push_b"
36679^done,completion="b push_back(",
36680 matches=[
36681 "b A::push_back(void*)",
36682 "b std::string::push_back(char)",
36683 "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
36684 max_completions_reached="0"
36685(gdb)
36686-complete "nonexist"
36687^done,matches=[],max_completions_reached="0"
36688(gdb)
36689
36690@end smallexample
36691
922fbb7b
AC
36692@node Annotations
36693@chapter @value{GDBN} Annotations
36694
086432e2
AC
36695This chapter describes annotations in @value{GDBN}. Annotations were
36696designed to interface @value{GDBN} to graphical user interfaces or other
36697similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
36698relatively high level.
36699
d3e8051b 36700The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
36701(@pxref{GDB/MI}).
36702
922fbb7b
AC
36703@ignore
36704This is Edition @value{EDITION}, @value{DATE}.
36705@end ignore
36706
36707@menu
36708* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 36709* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
36710* Prompting:: Annotations marking @value{GDBN}'s need for input.
36711* Errors:: Annotations for error messages.
922fbb7b
AC
36712* Invalidation:: Some annotations describe things now invalid.
36713* Annotations for Running::
36714 Whether the program is running, how it stopped, etc.
36715* Source Annotations:: Annotations describing source code.
922fbb7b
AC
36716@end menu
36717
36718@node Annotations Overview
36719@section What is an Annotation?
36720@cindex annotations
36721
922fbb7b
AC
36722Annotations start with a newline character, two @samp{control-z}
36723characters, and the name of the annotation. If there is no additional
36724information associated with this annotation, the name of the annotation
36725is followed immediately by a newline. If there is additional
36726information, the name of the annotation is followed by a space, the
36727additional information, and a newline. The additional information
36728cannot contain newline characters.
36729
36730Any output not beginning with a newline and two @samp{control-z}
36731characters denotes literal output from @value{GDBN}. Currently there is
36732no need for @value{GDBN} to output a newline followed by two
36733@samp{control-z} characters, but if there was such a need, the
36734annotations could be extended with an @samp{escape} annotation which
36735means those three characters as output.
36736
086432e2
AC
36737The annotation @var{level}, which is specified using the
36738@option{--annotate} command line option (@pxref{Mode Options}), controls
36739how much information @value{GDBN} prints together with its prompt,
36740values of expressions, source lines, and other types of output. Level 0
d3e8051b 36741is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
36742subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
36743for programs that control @value{GDBN}, and level 2 annotations have
36744been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
36745Interface, annotate, GDB's Obsolete Annotations}).
36746
36747@table @code
36748@kindex set annotate
36749@item set annotate @var{level}
e09f16f9 36750The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 36751annotations to the specified @var{level}.
9c16f35a
EZ
36752
36753@item show annotate
36754@kindex show annotate
36755Show the current annotation level.
09d4efe1
EZ
36756@end table
36757
36758This chapter describes level 3 annotations.
086432e2 36759
922fbb7b
AC
36760A simple example of starting up @value{GDBN} with annotations is:
36761
36762@smallexample
086432e2
AC
36763$ @kbd{gdb --annotate=3}
36764GNU gdb 6.0
36765Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
36766GDB is free software, covered by the GNU General Public License,
36767and you are welcome to change it and/or distribute copies of it
36768under certain conditions.
36769Type "show copying" to see the conditions.
36770There is absolutely no warranty for GDB. Type "show warranty"
36771for details.
086432e2 36772This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
36773
36774^Z^Zpre-prompt
f7dc1244 36775(@value{GDBP})
922fbb7b 36776^Z^Zprompt
086432e2 36777@kbd{quit}
922fbb7b
AC
36778
36779^Z^Zpost-prompt
b383017d 36780$
922fbb7b
AC
36781@end smallexample
36782
36783Here @samp{quit} is input to @value{GDBN}; the rest is output from
36784@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
36785denotes a @samp{control-z} character) are annotations; the rest is
36786output from @value{GDBN}.
36787
9e6c4bd5
NR
36788@node Server Prefix
36789@section The Server Prefix
36790@cindex server prefix
36791
36792If you prefix a command with @samp{server } then it will not affect
36793the command history, nor will it affect @value{GDBN}'s notion of which
36794command to repeat if @key{RET} is pressed on a line by itself. This
36795means that commands can be run behind a user's back by a front-end in
36796a transparent manner.
36797
d837706a
NR
36798The @code{server } prefix does not affect the recording of values into
36799the value history; to print a value without recording it into the
36800value history, use the @code{output} command instead of the
36801@code{print} command.
36802
36803Using this prefix also disables confirmation requests
36804(@pxref{confirmation requests}).
9e6c4bd5 36805
922fbb7b
AC
36806@node Prompting
36807@section Annotation for @value{GDBN} Input
36808
36809@cindex annotations for prompts
36810When @value{GDBN} prompts for input, it annotates this fact so it is possible
36811to know when to send output, when the output from a given command is
36812over, etc.
36813
36814Different kinds of input each have a different @dfn{input type}. Each
36815input type has three annotations: a @code{pre-} annotation, which
36816denotes the beginning of any prompt which is being output, a plain
36817annotation, which denotes the end of the prompt, and then a @code{post-}
36818annotation which denotes the end of any echo which may (or may not) be
36819associated with the input. For example, the @code{prompt} input type
36820features the following annotations:
36821
36822@smallexample
36823^Z^Zpre-prompt
36824^Z^Zprompt
36825^Z^Zpost-prompt
36826@end smallexample
36827
36828The input types are
36829
36830@table @code
e5ac9b53
EZ
36831@findex pre-prompt annotation
36832@findex prompt annotation
36833@findex post-prompt annotation
922fbb7b
AC
36834@item prompt
36835When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
36836
e5ac9b53
EZ
36837@findex pre-commands annotation
36838@findex commands annotation
36839@findex post-commands annotation
922fbb7b
AC
36840@item commands
36841When @value{GDBN} prompts for a set of commands, like in the @code{commands}
36842command. The annotations are repeated for each command which is input.
36843
e5ac9b53
EZ
36844@findex pre-overload-choice annotation
36845@findex overload-choice annotation
36846@findex post-overload-choice annotation
922fbb7b
AC
36847@item overload-choice
36848When @value{GDBN} wants the user to select between various overloaded functions.
36849
e5ac9b53
EZ
36850@findex pre-query annotation
36851@findex query annotation
36852@findex post-query annotation
922fbb7b
AC
36853@item query
36854When @value{GDBN} wants the user to confirm a potentially dangerous operation.
36855
e5ac9b53
EZ
36856@findex pre-prompt-for-continue annotation
36857@findex prompt-for-continue annotation
36858@findex post-prompt-for-continue annotation
922fbb7b
AC
36859@item prompt-for-continue
36860When @value{GDBN} is asking the user to press return to continue. Note: Don't
36861expect this to work well; instead use @code{set height 0} to disable
36862prompting. This is because the counting of lines is buggy in the
36863presence of annotations.
36864@end table
36865
36866@node Errors
36867@section Errors
36868@cindex annotations for errors, warnings and interrupts
36869
e5ac9b53 36870@findex quit annotation
922fbb7b
AC
36871@smallexample
36872^Z^Zquit
36873@end smallexample
36874
36875This annotation occurs right before @value{GDBN} responds to an interrupt.
36876
e5ac9b53 36877@findex error annotation
922fbb7b
AC
36878@smallexample
36879^Z^Zerror
36880@end smallexample
36881
36882This annotation occurs right before @value{GDBN} responds to an error.
36883
36884Quit and error annotations indicate that any annotations which @value{GDBN} was
36885in the middle of may end abruptly. For example, if a
36886@code{value-history-begin} annotation is followed by a @code{error}, one
36887cannot expect to receive the matching @code{value-history-end}. One
36888cannot expect not to receive it either, however; an error annotation
36889does not necessarily mean that @value{GDBN} is immediately returning all the way
36890to the top level.
36891
e5ac9b53 36892@findex error-begin annotation
922fbb7b
AC
36893A quit or error annotation may be preceded by
36894
36895@smallexample
36896^Z^Zerror-begin
36897@end smallexample
36898
36899Any output between that and the quit or error annotation is the error
36900message.
36901
36902Warning messages are not yet annotated.
36903@c If we want to change that, need to fix warning(), type_error(),
36904@c range_error(), and possibly other places.
36905
922fbb7b
AC
36906@node Invalidation
36907@section Invalidation Notices
36908
36909@cindex annotations for invalidation messages
36910The following annotations say that certain pieces of state may have
36911changed.
36912
36913@table @code
e5ac9b53 36914@findex frames-invalid annotation
922fbb7b
AC
36915@item ^Z^Zframes-invalid
36916
36917The frames (for example, output from the @code{backtrace} command) may
36918have changed.
36919
e5ac9b53 36920@findex breakpoints-invalid annotation
922fbb7b
AC
36921@item ^Z^Zbreakpoints-invalid
36922
36923The breakpoints may have changed. For example, the user just added or
36924deleted a breakpoint.
36925@end table
36926
36927@node Annotations for Running
36928@section Running the Program
36929@cindex annotations for running programs
36930
e5ac9b53
EZ
36931@findex starting annotation
36932@findex stopping annotation
922fbb7b 36933When the program starts executing due to a @value{GDBN} command such as
b383017d 36934@code{step} or @code{continue},
922fbb7b
AC
36935
36936@smallexample
36937^Z^Zstarting
36938@end smallexample
36939
b383017d 36940is output. When the program stops,
922fbb7b
AC
36941
36942@smallexample
36943^Z^Zstopped
36944@end smallexample
36945
36946is output. Before the @code{stopped} annotation, a variety of
36947annotations describe how the program stopped.
36948
36949@table @code
e5ac9b53 36950@findex exited annotation
922fbb7b
AC
36951@item ^Z^Zexited @var{exit-status}
36952The program exited, and @var{exit-status} is the exit status (zero for
36953successful exit, otherwise nonzero).
36954
e5ac9b53
EZ
36955@findex signalled annotation
36956@findex signal-name annotation
36957@findex signal-name-end annotation
36958@findex signal-string annotation
36959@findex signal-string-end annotation
922fbb7b
AC
36960@item ^Z^Zsignalled
36961The program exited with a signal. After the @code{^Z^Zsignalled}, the
36962annotation continues:
36963
36964@smallexample
36965@var{intro-text}
36966^Z^Zsignal-name
36967@var{name}
36968^Z^Zsignal-name-end
36969@var{middle-text}
36970^Z^Zsignal-string
36971@var{string}
36972^Z^Zsignal-string-end
36973@var{end-text}
36974@end smallexample
36975
36976@noindent
36977where @var{name} is the name of the signal, such as @code{SIGILL} or
36978@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
697aa1b7 36979as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
922fbb7b
AC
36980@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
36981user's benefit and have no particular format.
36982
e5ac9b53 36983@findex signal annotation
922fbb7b
AC
36984@item ^Z^Zsignal
36985The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
36986just saying that the program received the signal, not that it was
36987terminated with it.
36988
e5ac9b53 36989@findex breakpoint annotation
922fbb7b
AC
36990@item ^Z^Zbreakpoint @var{number}
36991The program hit breakpoint number @var{number}.
36992
e5ac9b53 36993@findex watchpoint annotation
922fbb7b
AC
36994@item ^Z^Zwatchpoint @var{number}
36995The program hit watchpoint number @var{number}.
36996@end table
36997
36998@node Source Annotations
36999@section Displaying Source
37000@cindex annotations for source display
37001
e5ac9b53 37002@findex source annotation
922fbb7b
AC
37003The following annotation is used instead of displaying source code:
37004
37005@smallexample
37006^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
37007@end smallexample
37008
37009where @var{filename} is an absolute file name indicating which source
37010file, @var{line} is the line number within that file (where 1 is the
37011first line in the file), @var{character} is the character position
37012within the file (where 0 is the first character in the file) (for most
37013debug formats this will necessarily point to the beginning of a line),
37014@var{middle} is @samp{middle} if @var{addr} is in the middle of the
37015line, or @samp{beg} if @var{addr} is at the beginning of the line, and
37016@var{addr} is the address in the target program associated with the
697aa1b7 37017source which is being displayed. The @var{addr} is in the form @samp{0x}
922fbb7b
AC
37018followed by one or more lowercase hex digits (note that this does not
37019depend on the language).
37020
4efc6507
DE
37021@node JIT Interface
37022@chapter JIT Compilation Interface
37023@cindex just-in-time compilation
37024@cindex JIT compilation interface
37025
37026This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
37027interface. A JIT compiler is a program or library that generates native
37028executable code at runtime and executes it, usually in order to achieve good
37029performance while maintaining platform independence.
37030
37031Programs that use JIT compilation are normally difficult to debug because
37032portions of their code are generated at runtime, instead of being loaded from
37033object files, which is where @value{GDBN} normally finds the program's symbols
37034and debug information. In order to debug programs that use JIT compilation,
37035@value{GDBN} has an interface that allows the program to register in-memory
37036symbol files with @value{GDBN} at runtime.
37037
37038If you are using @value{GDBN} to debug a program that uses this interface, then
37039it should work transparently so long as you have not stripped the binary. If
37040you are developing a JIT compiler, then the interface is documented in the rest
37041of this chapter. At this time, the only known client of this interface is the
37042LLVM JIT.
37043
37044Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
37045JIT compiler communicates with @value{GDBN} by writing data into a global
6b92c0d3 37046variable and calling a function at a well-known symbol. When @value{GDBN}
4efc6507
DE
37047attaches, it reads a linked list of symbol files from the global variable to
37048find existing code, and puts a breakpoint in the function so that it can find
37049out about additional code.
37050
37051@menu
37052* Declarations:: Relevant C struct declarations
37053* Registering Code:: Steps to register code
37054* Unregistering Code:: Steps to unregister code
f85b53f8 37055* Custom Debug Info:: Emit debug information in a custom format
4efc6507
DE
37056@end menu
37057
37058@node Declarations
37059@section JIT Declarations
37060
37061These are the relevant struct declarations that a C program should include to
37062implement the interface:
37063
37064@smallexample
37065typedef enum
37066@{
37067 JIT_NOACTION = 0,
37068 JIT_REGISTER_FN,
37069 JIT_UNREGISTER_FN
37070@} jit_actions_t;
37071
37072struct jit_code_entry
37073@{
37074 struct jit_code_entry *next_entry;
37075 struct jit_code_entry *prev_entry;
37076 const char *symfile_addr;
37077 uint64_t symfile_size;
37078@};
37079
37080struct jit_descriptor
37081@{
37082 uint32_t version;
37083 /* This type should be jit_actions_t, but we use uint32_t
37084 to be explicit about the bitwidth. */
37085 uint32_t action_flag;
37086 struct jit_code_entry *relevant_entry;
37087 struct jit_code_entry *first_entry;
37088@};
37089
37090/* GDB puts a breakpoint in this function. */
37091void __attribute__((noinline)) __jit_debug_register_code() @{ @};
37092
37093/* Make sure to specify the version statically, because the
37094 debugger may check the version before we can set it. */
37095struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
37096@end smallexample
37097
37098If the JIT is multi-threaded, then it is important that the JIT synchronize any
37099modifications to this global data properly, which can easily be done by putting
37100a global mutex around modifications to these structures.
37101
37102@node Registering Code
37103@section Registering Code
37104
37105To register code with @value{GDBN}, the JIT should follow this protocol:
37106
37107@itemize @bullet
37108@item
37109Generate an object file in memory with symbols and other desired debug
37110information. The file must include the virtual addresses of the sections.
37111
37112@item
37113Create a code entry for the file, which gives the start and size of the symbol
37114file.
37115
37116@item
37117Add it to the linked list in the JIT descriptor.
37118
37119@item
37120Point the relevant_entry field of the descriptor at the entry.
37121
37122@item
37123Set @code{action_flag} to @code{JIT_REGISTER} and call
37124@code{__jit_debug_register_code}.
37125@end itemize
37126
37127When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
37128@code{relevant_entry} pointer so it doesn't have to walk the list looking for
37129new code. However, the linked list must still be maintained in order to allow
37130@value{GDBN} to attach to a running process and still find the symbol files.
37131
37132@node Unregistering Code
37133@section Unregistering Code
37134
37135If code is freed, then the JIT should use the following protocol:
37136
37137@itemize @bullet
37138@item
37139Remove the code entry corresponding to the code from the linked list.
37140
37141@item
37142Point the @code{relevant_entry} field of the descriptor at the code entry.
37143
37144@item
37145Set @code{action_flag} to @code{JIT_UNREGISTER} and call
37146@code{__jit_debug_register_code}.
37147@end itemize
37148
37149If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
37150and the JIT will leak the memory used for the associated symbol files.
37151
f85b53f8
SD
37152@node Custom Debug Info
37153@section Custom Debug Info
37154@cindex custom JIT debug info
37155@cindex JIT debug info reader
37156
37157Generating debug information in platform-native file formats (like ELF
37158or COFF) may be an overkill for JIT compilers; especially if all the
37159debug info is used for is displaying a meaningful backtrace. The
37160issue can be resolved by having the JIT writers decide on a debug info
37161format and also provide a reader that parses the debug info generated
37162by the JIT compiler. This section gives a brief overview on writing
37163such a parser. More specific details can be found in the source file
37164@file{gdb/jit-reader.in}, which is also installed as a header at
37165@file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
37166
37167The reader is implemented as a shared object (so this functionality is
37168not available on platforms which don't allow loading shared objects at
37169runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
37170@code{jit-reader-unload} are provided, to be used to load and unload
37171the readers from a preconfigured directory. Once loaded, the shared
37172object is used the parse the debug information emitted by the JIT
37173compiler.
37174
37175@menu
37176* Using JIT Debug Info Readers:: How to use supplied readers correctly
37177* Writing JIT Debug Info Readers:: Creating a debug-info reader
37178@end menu
37179
37180@node Using JIT Debug Info Readers
37181@subsection Using JIT Debug Info Readers
37182@kindex jit-reader-load
37183@kindex jit-reader-unload
37184
37185Readers can be loaded and unloaded using the @code{jit-reader-load}
37186and @code{jit-reader-unload} commands.
37187
37188@table @code
c9fb1240 37189@item jit-reader-load @var{reader}
697aa1b7 37190Load the JIT reader named @var{reader}, which is a shared
c9fb1240
SD
37191object specified as either an absolute or a relative file name. In
37192the latter case, @value{GDBN} will try to load the reader from a
37193pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
37194system (here @var{libdir} is the system library directory, often
37195@file{/usr/local/lib}).
37196
37197Only one reader can be active at a time; trying to load a second
37198reader when one is already loaded will result in @value{GDBN}
37199reporting an error. A new JIT reader can be loaded by first unloading
37200the current one using @code{jit-reader-unload} and then invoking
37201@code{jit-reader-load}.
f85b53f8
SD
37202
37203@item jit-reader-unload
37204Unload the currently loaded JIT reader.
37205
37206@end table
37207
37208@node Writing JIT Debug Info Readers
37209@subsection Writing JIT Debug Info Readers
37210@cindex writing JIT debug info readers
37211
37212As mentioned, a reader is essentially a shared object conforming to a
37213certain ABI. This ABI is described in @file{jit-reader.h}.
37214
37215@file{jit-reader.h} defines the structures, macros and functions
37216required to write a reader. It is installed (along with
37217@value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
37218the system include directory.
37219
37220Readers need to be released under a GPL compatible license. A reader
37221can be declared as released under such a license by placing the macro
37222@code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
37223
37224The entry point for readers is the symbol @code{gdb_init_reader},
37225which is expected to be a function with the prototype
37226
37227@findex gdb_init_reader
37228@smallexample
37229extern struct gdb_reader_funcs *gdb_init_reader (void);
37230@end smallexample
37231
37232@cindex @code{struct gdb_reader_funcs}
37233
37234@code{struct gdb_reader_funcs} contains a set of pointers to callback
37235functions. These functions are executed to read the debug info
37236generated by the JIT compiler (@code{read}), to unwind stack frames
37237(@code{unwind}) and to create canonical frame IDs
27f7b2f6 37238(@code{get_frame_id}). It also has a callback that is called when the
f85b53f8
SD
37239reader is being unloaded (@code{destroy}). The struct looks like this
37240
37241@smallexample
37242struct gdb_reader_funcs
37243@{
37244 /* Must be set to GDB_READER_INTERFACE_VERSION. */
37245 int reader_version;
37246
37247 /* For use by the reader. */
37248 void *priv_data;
37249
37250 gdb_read_debug_info *read;
37251 gdb_unwind_frame *unwind;
37252 gdb_get_frame_id *get_frame_id;
37253 gdb_destroy_reader *destroy;
37254@};
37255@end smallexample
37256
37257@cindex @code{struct gdb_symbol_callbacks}
37258@cindex @code{struct gdb_unwind_callbacks}
37259
37260The callbacks are provided with another set of callbacks by
37261@value{GDBN} to do their job. For @code{read}, these callbacks are
37262passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
37263and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
37264@code{struct gdb_symbol_callbacks} has callbacks to create new object
37265files and new symbol tables inside those object files. @code{struct
37266gdb_unwind_callbacks} has callbacks to read registers off the current
37267frame and to write out the values of the registers in the previous
37268frame. Both have a callback (@code{target_read}) to read bytes off the
37269target's address space.
37270
d1feda86
YQ
37271@node In-Process Agent
37272@chapter In-Process Agent
37273@cindex debugging agent
37274The traditional debugging model is conceptually low-speed, but works fine,
37275because most bugs can be reproduced in debugging-mode execution. However,
37276as multi-core or many-core processors are becoming mainstream, and
37277multi-threaded programs become more and more popular, there should be more
37278and more bugs that only manifest themselves at normal-mode execution, for
37279example, thread races, because debugger's interference with the program's
37280timing may conceal the bugs. On the other hand, in some applications,
37281it is not feasible for the debugger to interrupt the program's execution
37282long enough for the developer to learn anything helpful about its behavior.
37283If the program's correctness depends on its real-time behavior, delays
37284introduced by a debugger might cause the program to fail, even when the
37285code itself is correct. It is useful to be able to observe the program's
37286behavior without interrupting it.
37287
37288Therefore, traditional debugging model is too intrusive to reproduce
37289some bugs. In order to reduce the interference with the program, we can
37290reduce the number of operations performed by debugger. The
37291@dfn{In-Process Agent}, a shared library, is running within the same
37292process with inferior, and is able to perform some debugging operations
37293itself. As a result, debugger is only involved when necessary, and
37294performance of debugging can be improved accordingly. Note that
37295interference with program can be reduced but can't be removed completely,
37296because the in-process agent will still stop or slow down the program.
37297
37298The in-process agent can interpret and execute Agent Expressions
37299(@pxref{Agent Expressions}) during performing debugging operations. The
37300agent expressions can be used for different purposes, such as collecting
37301data in tracepoints, and condition evaluation in breakpoints.
37302
37303@anchor{Control Agent}
37304You can control whether the in-process agent is used as an aid for
37305debugging with the following commands:
37306
37307@table @code
37308@kindex set agent on
37309@item set agent on
37310Causes the in-process agent to perform some operations on behalf of the
37311debugger. Just which operations requested by the user will be done
37312by the in-process agent depends on the its capabilities. For example,
37313if you request to evaluate breakpoint conditions in the in-process agent,
37314and the in-process agent has such capability as well, then breakpoint
37315conditions will be evaluated in the in-process agent.
37316
37317@kindex set agent off
37318@item set agent off
37319Disables execution of debugging operations by the in-process agent. All
37320of the operations will be performed by @value{GDBN}.
37321
37322@kindex show agent
37323@item show agent
37324Display the current setting of execution of debugging operations by
37325the in-process agent.
37326@end table
37327
16bdd41f
YQ
37328@menu
37329* In-Process Agent Protocol::
37330@end menu
37331
37332@node In-Process Agent Protocol
37333@section In-Process Agent Protocol
37334@cindex in-process agent protocol
37335
37336The in-process agent is able to communicate with both @value{GDBN} and
37337GDBserver (@pxref{In-Process Agent}). This section documents the protocol
37338used for communications between @value{GDBN} or GDBserver and the IPA.
37339In general, @value{GDBN} or GDBserver sends commands
37340(@pxref{IPA Protocol Commands}) and data to in-process agent, and then
37341in-process agent replies back with the return result of the command, or
37342some other information. The data sent to in-process agent is composed
37343of primitive data types, such as 4-byte or 8-byte type, and composite
37344types, which are called objects (@pxref{IPA Protocol Objects}).
37345
37346@menu
37347* IPA Protocol Objects::
37348* IPA Protocol Commands::
37349@end menu
37350
37351@node IPA Protocol Objects
37352@subsection IPA Protocol Objects
37353@cindex ipa protocol objects
37354
37355The commands sent to and results received from agent may contain some
37356complex data types called @dfn{objects}.
37357
37358The in-process agent is running on the same machine with @value{GDBN}
37359or GDBserver, so it doesn't have to handle as much differences between
37360two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
37361However, there are still some differences of two ends in two processes:
37362
37363@enumerate
37364@item
37365word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
37366compiled as a 64-bit executable, while in-process agent is a 32-bit one.
37367@item
37368ABI. Some machines may have multiple types of ABI, @value{GDBN} or
37369GDBserver is compiled with one, and in-process agent is compiled with
37370the other one.
37371@end enumerate
37372
37373Here are the IPA Protocol Objects:
37374
37375@enumerate
37376@item
37377agent expression object. It represents an agent expression
37378(@pxref{Agent Expressions}).
37379@anchor{agent expression object}
37380@item
37381tracepoint action object. It represents a tracepoint action
37382(@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
37383memory, static trace data and to evaluate expression.
37384@anchor{tracepoint action object}
37385@item
37386tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
37387@anchor{tracepoint object}
37388
37389@end enumerate
37390
37391The following table describes important attributes of each IPA protocol
37392object:
37393
37394@multitable @columnfractions .30 .20 .50
37395@headitem Name @tab Size @tab Description
37396@item @emph{agent expression object} @tab @tab
37397@item length @tab 4 @tab length of bytes code
37398@item byte code @tab @var{length} @tab contents of byte code
37399@item @emph{tracepoint action for collecting memory} @tab @tab
37400@item 'M' @tab 1 @tab type of tracepoint action
37401@item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
37402address of the lowest byte to collect, otherwise @var{addr} is the offset
37403of @var{basereg} for memory collecting.
37404@item len @tab 8 @tab length of memory for collecting
37405@item basereg @tab 4 @tab the register number containing the starting
37406memory address for collecting.
37407@item @emph{tracepoint action for collecting registers} @tab @tab
37408@item 'R' @tab 1 @tab type of tracepoint action
37409@item @emph{tracepoint action for collecting static trace data} @tab @tab
37410@item 'L' @tab 1 @tab type of tracepoint action
37411@item @emph{tracepoint action for expression evaluation} @tab @tab
37412@item 'X' @tab 1 @tab type of tracepoint action
37413@item agent expression @tab length of @tab @ref{agent expression object}
37414@item @emph{tracepoint object} @tab @tab
37415@item number @tab 4 @tab number of tracepoint
37416@item address @tab 8 @tab address of tracepoint inserted on
37417@item type @tab 4 @tab type of tracepoint
37418@item enabled @tab 1 @tab enable or disable of tracepoint
37419@item step_count @tab 8 @tab step
37420@item pass_count @tab 8 @tab pass
37421@item numactions @tab 4 @tab number of tracepoint actions
37422@item hit count @tab 8 @tab hit count
37423@item trace frame usage @tab 8 @tab trace frame usage
37424@item compiled_cond @tab 8 @tab compiled condition
37425@item orig_size @tab 8 @tab orig size
37426@item condition @tab 4 if condition is NULL otherwise length of
37427@ref{agent expression object}
37428@tab zero if condition is NULL, otherwise is
37429@ref{agent expression object}
37430@item actions @tab variable
37431@tab numactions number of @ref{tracepoint action object}
37432@end multitable
37433
37434@node IPA Protocol Commands
37435@subsection IPA Protocol Commands
37436@cindex ipa protocol commands
37437
37438The spaces in each command are delimiters to ease reading this commands
37439specification. They don't exist in real commands.
37440
37441@table @samp
37442
37443@item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
37444Installs a new fast tracepoint described by @var{tracepoint_object}
697aa1b7 37445(@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
16bdd41f
YQ
37446head of @dfn{jumppad}, which is used to jump to data collection routine
37447in IPA finally.
37448
37449Replies:
37450@table @samp
37451@item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
37452@var{target_address} is address of tracepoint in the inferior.
697aa1b7 37453The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
16bdd41f 37454@var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
697aa1b7
EZ
37455The @var{fjump} contains a sequence of instructions jump to jumppad entry.
37456The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
16bdd41f
YQ
37457@item E @var{NN}
37458for an error
37459
37460@end table
37461
7255706c
YQ
37462@item close
37463Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
37464is about to kill inferiors.
37465
16bdd41f
YQ
37466@item qTfSTM
37467@xref{qTfSTM}.
37468@item qTsSTM
37469@xref{qTsSTM}.
37470@item qTSTMat
37471@xref{qTSTMat}.
37472@item probe_marker_at:@var{address}
37473Asks in-process agent to probe the marker at @var{address}.
37474
37475Replies:
37476@table @samp
37477@item E @var{NN}
37478for an error
37479@end table
37480@item unprobe_marker_at:@var{address}
37481Asks in-process agent to unprobe the marker at @var{address}.
37482@end table
37483
8e04817f
AC
37484@node GDB Bugs
37485@chapter Reporting Bugs in @value{GDBN}
37486@cindex bugs in @value{GDBN}
37487@cindex reporting bugs in @value{GDBN}
c906108c 37488
8e04817f 37489Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 37490
8e04817f
AC
37491Reporting a bug may help you by bringing a solution to your problem, or it
37492may not. But in any case the principal function of a bug report is to help
37493the entire community by making the next version of @value{GDBN} work better. Bug
37494reports are your contribution to the maintenance of @value{GDBN}.
c906108c 37495
8e04817f
AC
37496In order for a bug report to serve its purpose, you must include the
37497information that enables us to fix the bug.
c4555f82
SC
37498
37499@menu
8e04817f
AC
37500* Bug Criteria:: Have you found a bug?
37501* Bug Reporting:: How to report bugs
c4555f82
SC
37502@end menu
37503
8e04817f 37504@node Bug Criteria
79a6e687 37505@section Have You Found a Bug?
8e04817f 37506@cindex bug criteria
c4555f82 37507
8e04817f 37508If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
37509
37510@itemize @bullet
8e04817f
AC
37511@cindex fatal signal
37512@cindex debugger crash
37513@cindex crash of debugger
c4555f82 37514@item
8e04817f
AC
37515If the debugger gets a fatal signal, for any input whatever, that is a
37516@value{GDBN} bug. Reliable debuggers never crash.
37517
37518@cindex error on valid input
37519@item
37520If @value{GDBN} produces an error message for valid input, that is a
37521bug. (Note that if you're cross debugging, the problem may also be
37522somewhere in the connection to the target.)
c4555f82 37523
8e04817f 37524@cindex invalid input
c4555f82 37525@item
8e04817f
AC
37526If @value{GDBN} does not produce an error message for invalid input,
37527that is a bug. However, you should note that your idea of
37528``invalid input'' might be our idea of ``an extension'' or ``support
37529for traditional practice''.
37530
37531@item
37532If you are an experienced user of debugging tools, your suggestions
37533for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
37534@end itemize
37535
8e04817f 37536@node Bug Reporting
79a6e687 37537@section How to Report Bugs
8e04817f
AC
37538@cindex bug reports
37539@cindex @value{GDBN} bugs, reporting
37540
37541A number of companies and individuals offer support for @sc{gnu} products.
37542If you obtained @value{GDBN} from a support organization, we recommend you
37543contact that organization first.
37544
37545You can find contact information for many support companies and
37546individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
37547distribution.
37548@c should add a web page ref...
37549
c16158bc
JM
37550@ifset BUGURL
37551@ifset BUGURL_DEFAULT
129188f6 37552In any event, we also recommend that you submit bug reports for
d3e8051b 37553@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
37554@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
37555page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
37556be used.
8e04817f
AC
37557
37558@strong{Do not send bug reports to @samp{info-gdb}, or to
37559@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
37560not want to receive bug reports. Those that do have arranged to receive
37561@samp{bug-gdb}.
37562
37563The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
37564serves as a repeater. The mailing list and the newsgroup carry exactly
37565the same messages. Often people think of posting bug reports to the
37566newsgroup instead of mailing them. This appears to work, but it has one
37567problem which can be crucial: a newsgroup posting often lacks a mail
37568path back to the sender. Thus, if we need to ask for more information,
37569we may be unable to reach you. For this reason, it is better to send
37570bug reports to the mailing list.
c16158bc
JM
37571@end ifset
37572@ifclear BUGURL_DEFAULT
37573In any event, we also recommend that you submit bug reports for
37574@value{GDBN} to @value{BUGURL}.
37575@end ifclear
37576@end ifset
c4555f82 37577
8e04817f
AC
37578The fundamental principle of reporting bugs usefully is this:
37579@strong{report all the facts}. If you are not sure whether to state a
37580fact or leave it out, state it!
c4555f82 37581
8e04817f
AC
37582Often people omit facts because they think they know what causes the
37583problem and assume that some details do not matter. Thus, you might
37584assume that the name of the variable you use in an example does not matter.
37585Well, probably it does not, but one cannot be sure. Perhaps the bug is a
37586stray memory reference which happens to fetch from the location where that
37587name is stored in memory; perhaps, if the name were different, the contents
37588of that location would fool the debugger into doing the right thing despite
37589the bug. Play it safe and give a specific, complete example. That is the
37590easiest thing for you to do, and the most helpful.
c4555f82 37591
8e04817f
AC
37592Keep in mind that the purpose of a bug report is to enable us to fix the
37593bug. It may be that the bug has been reported previously, but neither
37594you nor we can know that unless your bug report is complete and
37595self-contained.
c4555f82 37596
8e04817f
AC
37597Sometimes people give a few sketchy facts and ask, ``Does this ring a
37598bell?'' Those bug reports are useless, and we urge everyone to
37599@emph{refuse to respond to them} except to chide the sender to report
37600bugs properly.
37601
37602To enable us to fix the bug, you should include all these things:
c4555f82
SC
37603
37604@itemize @bullet
37605@item
8e04817f
AC
37606The version of @value{GDBN}. @value{GDBN} announces it if you start
37607with no arguments; you can also print it at any time using @code{show
37608version}.
c4555f82 37609
8e04817f
AC
37610Without this, we will not know whether there is any point in looking for
37611the bug in the current version of @value{GDBN}.
c4555f82
SC
37612
37613@item
8e04817f
AC
37614The type of machine you are using, and the operating system name and
37615version number.
c4555f82 37616
6eaaf48b
EZ
37617@item
37618The details of the @value{GDBN} build-time configuration.
37619@value{GDBN} shows these details if you invoke it with the
37620@option{--configuration} command-line option, or if you type
37621@code{show configuration} at @value{GDBN}'s prompt.
37622
c4555f82 37623@item
c1468174 37624What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 37625``@value{GCC}--2.8.1''.
c4555f82
SC
37626
37627@item
8e04817f 37628What compiler (and its version) was used to compile the program you are
c1468174 37629debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
37630C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
37631to get this information; for other compilers, see the documentation for
37632those compilers.
c4555f82 37633
8e04817f
AC
37634@item
37635The command arguments you gave the compiler to compile your example and
37636observe the bug. For example, did you use @samp{-O}? To guarantee
37637you will not omit something important, list them all. A copy of the
37638Makefile (or the output from make) is sufficient.
c4555f82 37639
8e04817f
AC
37640If we were to try to guess the arguments, we would probably guess wrong
37641and then we might not encounter the bug.
c4555f82 37642
8e04817f
AC
37643@item
37644A complete input script, and all necessary source files, that will
37645reproduce the bug.
c4555f82 37646
8e04817f
AC
37647@item
37648A description of what behavior you observe that you believe is
37649incorrect. For example, ``It gets a fatal signal.''
c4555f82 37650
8e04817f
AC
37651Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
37652will certainly notice it. But if the bug is incorrect output, we might
37653not notice unless it is glaringly wrong. You might as well not give us
37654a chance to make a mistake.
c4555f82 37655
8e04817f
AC
37656Even if the problem you experience is a fatal signal, you should still
37657say so explicitly. Suppose something strange is going on, such as, your
37658copy of @value{GDBN} is out of synch, or you have encountered a bug in
37659the C library on your system. (This has happened!) Your copy might
37660crash and ours would not. If you told us to expect a crash, then when
37661ours fails to crash, we would know that the bug was not happening for
37662us. If you had not told us to expect a crash, then we would not be able
37663to draw any conclusion from our observations.
c4555f82 37664
e0c07bf0
MC
37665@pindex script
37666@cindex recording a session script
37667To collect all this information, you can use a session recording program
37668such as @command{script}, which is available on many Unix systems.
37669Just run your @value{GDBN} session inside @command{script} and then
37670include the @file{typescript} file with your bug report.
37671
37672Another way to record a @value{GDBN} session is to run @value{GDBN}
37673inside Emacs and then save the entire buffer to a file.
37674
8e04817f
AC
37675@item
37676If you wish to suggest changes to the @value{GDBN} source, send us context
37677diffs. If you even discuss something in the @value{GDBN} source, refer to
37678it by context, not by line number.
c4555f82 37679
8e04817f
AC
37680The line numbers in our development sources will not match those in your
37681sources. Your line numbers would convey no useful information to us.
c4555f82 37682
8e04817f 37683@end itemize
c4555f82 37684
8e04817f 37685Here are some things that are not necessary:
c4555f82 37686
8e04817f
AC
37687@itemize @bullet
37688@item
37689A description of the envelope of the bug.
c4555f82 37690
8e04817f
AC
37691Often people who encounter a bug spend a lot of time investigating
37692which changes to the input file will make the bug go away and which
37693changes will not affect it.
c4555f82 37694
8e04817f
AC
37695This is often time consuming and not very useful, because the way we
37696will find the bug is by running a single example under the debugger
37697with breakpoints, not by pure deduction from a series of examples.
37698We recommend that you save your time for something else.
c4555f82 37699
8e04817f
AC
37700Of course, if you can find a simpler example to report @emph{instead}
37701of the original one, that is a convenience for us. Errors in the
37702output will be easier to spot, running under the debugger will take
37703less time, and so on.
c4555f82 37704
8e04817f
AC
37705However, simplification is not vital; if you do not want to do this,
37706report the bug anyway and send us the entire test case you used.
c4555f82 37707
8e04817f
AC
37708@item
37709A patch for the bug.
c4555f82 37710
8e04817f
AC
37711A patch for the bug does help us if it is a good one. But do not omit
37712the necessary information, such as the test case, on the assumption that
37713a patch is all we need. We might see problems with your patch and decide
37714to fix the problem another way, or we might not understand it at all.
c4555f82 37715
8e04817f
AC
37716Sometimes with a program as complicated as @value{GDBN} it is very hard to
37717construct an example that will make the program follow a certain path
37718through the code. If you do not send us the example, we will not be able
37719to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 37720
8e04817f
AC
37721And if we cannot understand what bug you are trying to fix, or why your
37722patch should be an improvement, we will not install it. A test case will
37723help us to understand.
c4555f82 37724
8e04817f
AC
37725@item
37726A guess about what the bug is or what it depends on.
c4555f82 37727
8e04817f
AC
37728Such guesses are usually wrong. Even we cannot guess right about such
37729things without first using the debugger to find the facts.
37730@end itemize
c4555f82 37731
8e04817f
AC
37732@c The readline documentation is distributed with the readline code
37733@c and consists of the two following files:
cc88a640
JK
37734@c rluser.texi
37735@c hsuser.texi
8e04817f
AC
37736@c Use -I with makeinfo to point to the appropriate directory,
37737@c environment var TEXINPUTS with TeX.
39037522 37738@ifclear SYSTEM_READLINE
5bdf8622 37739@include rluser.texi
cc88a640 37740@include hsuser.texi
39037522 37741@end ifclear
c4555f82 37742
4ceed123
JB
37743@node In Memoriam
37744@appendix In Memoriam
37745
9ed350ad
JB
37746The @value{GDBN} project mourns the loss of the following long-time
37747contributors:
4ceed123
JB
37748
37749@table @code
37750@item Fred Fish
9ed350ad
JB
37751Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
37752to Free Software in general. Outside of @value{GDBN}, he was known in
37753the Amiga world for his series of Fish Disks, and the GeekGadget project.
4ceed123
JB
37754
37755@item Michael Snyder
9ed350ad
JB
37756Michael was one of the Global Maintainers of the @value{GDBN} project,
37757with contributions recorded as early as 1996, until 2011. In addition
37758to his day to day participation, he was a large driving force behind
37759adding Reverse Debugging to @value{GDBN}.
4ceed123
JB
37760@end table
37761
37762Beyond their technical contributions to the project, they were also
37763enjoyable members of the Free Software Community. We will miss them.
c4555f82 37764
8e04817f
AC
37765@node Formatting Documentation
37766@appendix Formatting Documentation
c4555f82 37767
8e04817f
AC
37768@cindex @value{GDBN} reference card
37769@cindex reference card
37770The @value{GDBN} 4 release includes an already-formatted reference card, ready
37771for printing with PostScript or Ghostscript, in the @file{gdb}
37772subdirectory of the main source directory@footnote{In
37773@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
37774release.}. If you can use PostScript or Ghostscript with your printer,
37775you can print the reference card immediately with @file{refcard.ps}.
c4555f82 37776
8e04817f
AC
37777The release also includes the source for the reference card. You
37778can format it, using @TeX{}, by typing:
c4555f82 37779
474c8240 37780@smallexample
8e04817f 37781make refcard.dvi
474c8240 37782@end smallexample
c4555f82 37783
8e04817f
AC
37784The @value{GDBN} reference card is designed to print in @dfn{landscape}
37785mode on US ``letter'' size paper;
37786that is, on a sheet 11 inches wide by 8.5 inches
37787high. You will need to specify this form of printing as an option to
37788your @sc{dvi} output program.
c4555f82 37789
8e04817f 37790@cindex documentation
c4555f82 37791
8e04817f
AC
37792All the documentation for @value{GDBN} comes as part of the machine-readable
37793distribution. The documentation is written in Texinfo format, which is
37794a documentation system that uses a single source file to produce both
37795on-line information and a printed manual. You can use one of the Info
37796formatting commands to create the on-line version of the documentation
37797and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 37798
8e04817f
AC
37799@value{GDBN} includes an already formatted copy of the on-line Info
37800version of this manual in the @file{gdb} subdirectory. The main Info
37801file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
37802subordinate files matching @samp{gdb.info*} in the same directory. If
37803necessary, you can print out these files, or read them with any editor;
37804but they are easier to read using the @code{info} subsystem in @sc{gnu}
37805Emacs or the standalone @code{info} program, available as part of the
37806@sc{gnu} Texinfo distribution.
c4555f82 37807
8e04817f
AC
37808If you want to format these Info files yourself, you need one of the
37809Info formatting programs, such as @code{texinfo-format-buffer} or
37810@code{makeinfo}.
c4555f82 37811
8e04817f
AC
37812If you have @code{makeinfo} installed, and are in the top level
37813@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
37814version @value{GDBVN}), you can make the Info file by typing:
c4555f82 37815
474c8240 37816@smallexample
8e04817f
AC
37817cd gdb
37818make gdb.info
474c8240 37819@end smallexample
c4555f82 37820
8e04817f
AC
37821If you want to typeset and print copies of this manual, you need @TeX{},
37822a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
37823Texinfo definitions file.
c4555f82 37824
8e04817f
AC
37825@TeX{} is a typesetting program; it does not print files directly, but
37826produces output files called @sc{dvi} files. To print a typeset
37827document, you need a program to print @sc{dvi} files. If your system
37828has @TeX{} installed, chances are it has such a program. The precise
37829command to use depends on your system; @kbd{lpr -d} is common; another
37830(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
37831require a file name without any extension or a @samp{.dvi} extension.
c4555f82 37832
8e04817f
AC
37833@TeX{} also requires a macro definitions file called
37834@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
37835written in Texinfo format. On its own, @TeX{} cannot either read or
37836typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
37837and is located in the @file{gdb-@var{version-number}/texinfo}
37838directory.
c4555f82 37839
8e04817f 37840If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 37841typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
37842subdirectory of the main source directory (for example, to
37843@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 37844
474c8240 37845@smallexample
8e04817f 37846make gdb.dvi
474c8240 37847@end smallexample
c4555f82 37848
8e04817f 37849Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 37850
8e04817f
AC
37851@node Installing GDB
37852@appendix Installing @value{GDBN}
8e04817f 37853@cindex installation
c4555f82 37854
7fa2210b
DJ
37855@menu
37856* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 37857* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
37858* Separate Objdir:: Compiling @value{GDBN} in another directory
37859* Config Names:: Specifying names for hosts and targets
37860* Configure Options:: Summary of options for configure
098b41a6 37861* System-wide configuration:: Having a system-wide init file
7fa2210b
DJ
37862@end menu
37863
37864@node Requirements
79a6e687 37865@section Requirements for Building @value{GDBN}
7fa2210b
DJ
37866@cindex building @value{GDBN}, requirements for
37867
37868Building @value{GDBN} requires various tools and packages to be available.
37869Other packages will be used only if they are found.
37870
79a6e687 37871@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b 37872@table @asis
7f0bd420
TT
37873@item C@t{++}11 compiler
37874@value{GDBN} is written in C@t{++}11. It should be buildable with any
37875recent C@t{++}11 compiler, e.g.@: GCC.
7fa2210b 37876
7f0bd420
TT
37877@item GNU make
37878@value{GDBN}'s build system relies on features only found in the GNU
37879make program. Other variants of @code{make} will not work.
904cb749
JB
37880
37881@item GMP (The GNU Multiple Precision Arithmetic Library)
37882@value{GDBN} now uses GMP to perform some of its arithmetics.
37883This library may be included with your operating system distribution;
37884if it is not, you can get the latest version from
37885@url{https://gmplib.org/}. If GMP is installed at an unusual path,
37886you can use the @option{--with-libgmp-prefix} option to specify
37887its location.
37888
7fa2210b
DJ
37889@end table
37890
79a6e687 37891@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
37892@table @asis
37893@item Expat
123dc839 37894@anchor{Expat}
7fa2210b
DJ
37895@value{GDBN} can use the Expat XML parsing library. This library may be
37896included with your operating system distribution; if it is not, you
37897can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 37898The @file{configure} script will search for this library in several
7fa2210b
DJ
37899standard locations; if it is installed in an unusual path, you can
37900use the @option{--with-libexpat-prefix} option to specify its location.
37901
9cceb671
DJ
37902Expat is used for:
37903
37904@itemize @bullet
37905@item
37906Remote protocol memory maps (@pxref{Memory Map Format})
37907@item
37908Target descriptions (@pxref{Target Descriptions})
37909@item
2268b414
JK
37910Remote shared library lists (@xref{Library List Format},
37911or alternatively @pxref{Library List Format for SVR4 Targets})
9cceb671
DJ
37912@item
37913MS-Windows shared libraries (@pxref{Shared Libraries})
b3b9301e
PA
37914@item
37915Traceframe info (@pxref{Traceframe Info Format})
2ae8c8e7 37916@item
f4abbc16
MM
37917Branch trace (@pxref{Branch Trace Format},
37918@pxref{Branch Trace Configuration Format})
9cceb671 37919@end itemize
7fa2210b 37920
7f0bd420
TT
37921@item Guile
37922@value{GDBN} can be scripted using GNU Guile. @xref{Guile}. By
37923default, @value{GDBN} will be compiled if the Guile libraries are
37924installed and are found by @file{configure}. You can use the
37925@code{--with-guile} option to request Guile, and pass either the Guile
37926version number or the file name of the relevant @code{pkg-config}
37927program to choose a particular version of Guile.
37928
37929@item iconv
37930@value{GDBN}'s features related to character sets (@pxref{Character
37931Sets}) require a functioning @code{iconv} implementation. If you are
37932on a GNU system, then this is provided by the GNU C Library. Some
37933other systems also provide a working @code{iconv}.
37934
37935If @value{GDBN} is using the @code{iconv} program which is installed
37936in a non-standard place, you will need to tell @value{GDBN} where to
37937find it. This is done with @option{--with-iconv-bin} which specifies
37938the directory that contains the @code{iconv} program. This program is
37939run in order to make a list of the available character sets.
37940
37941On systems without @code{iconv}, you can install GNU Libiconv. If
37942Libiconv is installed in a standard place, @value{GDBN} will
37943automatically use it if it is needed. If you have previously
37944installed Libiconv in a non-standard place, you can use the
37945@option{--with-libiconv-prefix} option to @file{configure}.
37946
37947@value{GDBN}'s top-level @file{configure} and @file{Makefile} will
37948arrange to build Libiconv if a directory named @file{libiconv} appears
37949in the top-most source directory. If Libiconv is built this way, and
37950if the operating system does not provide a suitable @code{iconv}
37951implementation, then the just-built library will automatically be used
37952by @value{GDBN}. One easy way to set this up is to download GNU
37953Libiconv, unpack it inside the top-level directory of the @value{GDBN}
37954source tree, and then rename the directory holding the Libiconv source
37955code to @samp{libiconv}.
37956
37957@item lzma
37958@value{GDBN} can support debugging sections that are compressed with
37959the LZMA library. @xref{MiniDebugInfo}. If this library is not
37960included with your operating system, you can find it in the xz package
37961at @url{http://tukaani.org/xz/}. If the LZMA library is available in
37962the usual place, then the @file{configure} script will use it
37963automatically. If it is installed in an unusual path, you can use the
37964@option{--with-lzma-prefix} option to specify its location.
37965
2400729e
UW
37966@item MPFR
37967@anchor{MPFR}
37968@value{GDBN} can use the GNU MPFR multiple-precision floating-point
37969library. This library may be included with your operating system
37970distribution; if it is not, you can get the latest version from
37971@url{http://www.mpfr.org}. The @file{configure} script will search
37972for this library in several standard locations; if it is installed
37973in an unusual path, you can use the @option{--with-libmpfr-prefix}
37974option to specify its location.
37975
37976GNU MPFR is used to emulate target floating-point arithmetic during
37977expression evaluation when the target uses different floating-point
37978formats than the host. If GNU MPFR it is not available, @value{GDBN}
37979will fall back to using host floating-point arithmetic.
37980
7f0bd420
TT
37981@item Python
37982@value{GDBN} can be scripted using Python language. @xref{Python}.
37983By default, @value{GDBN} will be compiled if the Python libraries are
37984installed and are found by @file{configure}. You can use the
37985@code{--with-python} option to request Python, and pass either the
37986file name of the relevant @code{python} executable, or the name of the
37987directory in which Python is installed, to choose a particular
37988installation of Python.
37989
31fffb02
CS
37990@item zlib
37991@cindex compressed debug sections
37992@value{GDBN} will use the @samp{zlib} library, if available, to read
37993compressed debug sections. Some linkers, such as GNU gold, are capable
37994of producing binaries with compressed debug sections. If @value{GDBN}
37995is compiled with @samp{zlib}, it will be able to read the debug
37996information in such binaries.
37997
37998The @samp{zlib} library is likely included with your operating system
37999distribution; if it is not, you can get the latest version from
38000@url{http://zlib.net}.
7fa2210b
DJ
38001@end table
38002
38003@node Running Configure
db2e3e2e 38004@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 38005@cindex configuring @value{GDBN}
db2e3e2e 38006@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
38007of preparing @value{GDBN} for installation; you can then use @code{make} to
38008build the @code{gdb} program.
38009@iftex
38010@c irrelevant in info file; it's as current as the code it lives with.
38011@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
38012look at the @file{README} file in the sources; we may have improved the
38013installation procedures since publishing this manual.}
38014@end iftex
c4555f82 38015
8e04817f
AC
38016The @value{GDBN} distribution includes all the source code you need for
38017@value{GDBN} in a single directory, whose name is usually composed by
38018appending the version number to @samp{gdb}.
c4555f82 38019
8e04817f
AC
38020For example, the @value{GDBN} version @value{GDBVN} distribution is in the
38021@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 38022
8e04817f
AC
38023@table @code
38024@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
38025script for configuring @value{GDBN} and all its supporting libraries
c4555f82 38026
8e04817f
AC
38027@item gdb-@value{GDBVN}/gdb
38028the source specific to @value{GDBN} itself
c4555f82 38029
8e04817f
AC
38030@item gdb-@value{GDBVN}/bfd
38031source for the Binary File Descriptor library
c906108c 38032
8e04817f
AC
38033@item gdb-@value{GDBVN}/include
38034@sc{gnu} include files
c906108c 38035
8e04817f
AC
38036@item gdb-@value{GDBVN}/libiberty
38037source for the @samp{-liberty} free software library
c906108c 38038
8e04817f
AC
38039@item gdb-@value{GDBVN}/opcodes
38040source for the library of opcode tables and disassemblers
c906108c 38041
8e04817f
AC
38042@item gdb-@value{GDBVN}/readline
38043source for the @sc{gnu} command-line interface
8e04817f 38044@end table
c906108c 38045
7f0bd420
TT
38046There may be other subdirectories as well.
38047
db2e3e2e 38048The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
38049from the @file{gdb-@var{version-number}} source directory, which in
38050this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 38051
8e04817f 38052First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 38053if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
38054identifier for the platform on which @value{GDBN} will run as an
38055argument.
c906108c 38056
8e04817f 38057For example:
c906108c 38058
474c8240 38059@smallexample
8e04817f 38060cd gdb-@value{GDBVN}
7f0bd420 38061./configure
8e04817f 38062make
474c8240 38063@end smallexample
c906108c 38064
7f0bd420
TT
38065Running @samp{configure} and then running @code{make} builds the
38066included supporting libraries, then @code{gdb} itself. The configured
38067source files, and the binaries, are left in the corresponding source
38068directories.
c906108c 38069
8e04817f 38070@need 750
db2e3e2e 38071@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
38072system does not recognize this automatically when you run a different
38073shell, you may need to run @code{sh} on it explicitly:
c906108c 38074
474c8240 38075@smallexample
7f0bd420 38076sh configure
474c8240 38077@end smallexample
c906108c 38078
db2e3e2e 38079You should run the @file{configure} script from the top directory in the
94e91d6d 38080source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 38081@file{configure} from one of the subdirectories, you will configure only
94e91d6d 38082that subdirectory. That is usually not what you want. In particular,
db2e3e2e 38083if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
38084of the @file{gdb-@var{version-number}} directory, you will omit the
38085configuration of @file{bfd}, @file{readline}, and other sibling
38086directories of the @file{gdb} subdirectory. This leads to build errors
38087about missing include files such as @file{bfd/bfd.h}.
c906108c 38088
7f0bd420
TT
38089You can install @code{@value{GDBN}} anywhere. The best way to do this
38090is to pass the @code{--prefix} option to @code{configure}, and then
38091install it with @code{make install}.
c906108c 38092
8e04817f 38093@node Separate Objdir
79a6e687 38094@section Compiling @value{GDBN} in Another Directory
c906108c 38095
8e04817f
AC
38096If you want to run @value{GDBN} versions for several host or target machines,
38097you need a different @code{gdb} compiled for each combination of
db2e3e2e 38098host and target. @file{configure} is designed to make this easy by
8e04817f
AC
38099allowing you to generate each configuration in a separate subdirectory,
38100rather than in the source directory. If your @code{make} program
38101handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
38102@code{make} in each of these directories builds the @code{gdb}
38103program specified there.
c906108c 38104
db2e3e2e 38105To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 38106with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
38107(You also need to specify a path to find @file{configure}
38108itself from your working directory. If the path to @file{configure}
8e04817f
AC
38109would be the same as the argument to @samp{--srcdir}, you can leave out
38110the @samp{--srcdir} option; it is assumed.)
c906108c 38111
8e04817f
AC
38112For example, with version @value{GDBVN}, you can build @value{GDBN} in a
38113separate directory for a Sun 4 like this:
c906108c 38114
474c8240 38115@smallexample
8e04817f
AC
38116@group
38117cd gdb-@value{GDBVN}
38118mkdir ../gdb-sun4
38119cd ../gdb-sun4
7f0bd420 38120../gdb-@value{GDBVN}/configure
8e04817f
AC
38121make
38122@end group
474c8240 38123@end smallexample
c906108c 38124
db2e3e2e 38125When @file{configure} builds a configuration using a remote source
8e04817f
AC
38126directory, it creates a tree for the binaries with the same structure
38127(and using the same names) as the tree under the source directory. In
38128the example, you'd find the Sun 4 library @file{libiberty.a} in the
38129directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
38130@file{gdb-sun4/gdb}.
c906108c 38131
94e91d6d
MC
38132Make sure that your path to the @file{configure} script has just one
38133instance of @file{gdb} in it. If your path to @file{configure} looks
38134like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
38135one subdirectory of @value{GDBN}, not the whole package. This leads to
38136build errors about missing include files such as @file{bfd/bfd.h}.
38137
8e04817f
AC
38138One popular reason to build several @value{GDBN} configurations in separate
38139directories is to configure @value{GDBN} for cross-compiling (where
38140@value{GDBN} runs on one machine---the @dfn{host}---while debugging
38141programs that run on another machine---the @dfn{target}).
38142You specify a cross-debugging target by
db2e3e2e 38143giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 38144
8e04817f
AC
38145When you run @code{make} to build a program or library, you must run
38146it in a configured directory---whatever directory you were in when you
db2e3e2e 38147called @file{configure} (or one of its subdirectories).
c906108c 38148
db2e3e2e 38149The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
38150directory also runs recursively. If you type @code{make} in a source
38151directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
38152directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
38153will build all the required libraries, and then build GDB.
c906108c 38154
8e04817f
AC
38155When you have multiple hosts or targets configured in separate
38156directories, you can run @code{make} on them in parallel (for example,
38157if they are NFS-mounted on each of the hosts); they will not interfere
38158with each other.
c906108c 38159
8e04817f 38160@node Config Names
79a6e687 38161@section Specifying Names for Hosts and Targets
c906108c 38162
db2e3e2e 38163The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
38164script are based on a three-part naming scheme, but some short predefined
38165aliases are also supported. The full naming scheme encodes three pieces
38166of information in the following pattern:
c906108c 38167
474c8240 38168@smallexample
8e04817f 38169@var{architecture}-@var{vendor}-@var{os}
474c8240 38170@end smallexample
c906108c 38171
8e04817f
AC
38172For example, you can use the alias @code{sun4} as a @var{host} argument,
38173or as the value for @var{target} in a @code{--target=@var{target}}
38174option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 38175
db2e3e2e 38176The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 38177any query facility to list all supported host and target names or
db2e3e2e 38178aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
38179@code{config.sub} to map abbreviations to full names; you can read the
38180script, if you wish, or you can use it to test your guesses on
38181abbreviations---for example:
c906108c 38182
8e04817f
AC
38183@smallexample
38184% sh config.sub i386-linux
38185i386-pc-linux-gnu
38186% sh config.sub alpha-linux
38187alpha-unknown-linux-gnu
38188% sh config.sub hp9k700
38189hppa1.1-hp-hpux
38190% sh config.sub sun4
38191sparc-sun-sunos4.1.1
38192% sh config.sub sun3
38193m68k-sun-sunos4.1.1
38194% sh config.sub i986v
38195Invalid configuration `i986v': machine `i986v' not recognized
38196@end smallexample
c906108c 38197
8e04817f
AC
38198@noindent
38199@code{config.sub} is also distributed in the @value{GDBN} source
38200directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 38201
8e04817f 38202@node Configure Options
db2e3e2e 38203@section @file{configure} Options
c906108c 38204
db2e3e2e 38205Here is a summary of the @file{configure} options and arguments that
7f0bd420
TT
38206are most often useful for building @value{GDBN}. @file{configure}
38207also has several other options not listed here. @inforef{Running
38208configure scripts,,autoconf.info}, for a full
38209explanation of @file{configure}.
c906108c 38210
474c8240 38211@smallexample
8e04817f
AC
38212configure @r{[}--help@r{]}
38213 @r{[}--prefix=@var{dir}@r{]}
38214 @r{[}--exec-prefix=@var{dir}@r{]}
38215 @r{[}--srcdir=@var{dirname}@r{]}
8e04817f 38216 @r{[}--target=@var{target}@r{]}
474c8240 38217@end smallexample
c906108c 38218
8e04817f
AC
38219@noindent
38220You may introduce options with a single @samp{-} rather than
38221@samp{--} if you prefer; but you may abbreviate option names if you use
38222@samp{--}.
c906108c 38223
8e04817f
AC
38224@table @code
38225@item --help
db2e3e2e 38226Display a quick summary of how to invoke @file{configure}.
c906108c 38227
8e04817f
AC
38228@item --prefix=@var{dir}
38229Configure the source to install programs and files under directory
38230@file{@var{dir}}.
c906108c 38231
8e04817f
AC
38232@item --exec-prefix=@var{dir}
38233Configure the source to install programs under directory
38234@file{@var{dir}}.
c906108c 38235
8e04817f
AC
38236@c avoid splitting the warning from the explanation:
38237@need 2000
38238@item --srcdir=@var{dirname}
8e04817f
AC
38239Use this option to make configurations in directories separate from the
38240@value{GDBN} source directories. Among other things, you can use this to
38241build (or maintain) several configurations simultaneously, in separate
db2e3e2e 38242directories. @file{configure} writes configuration-specific files in
8e04817f 38243the current directory, but arranges for them to use the source in the
db2e3e2e 38244directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
38245the working directory in parallel to the source directories below
38246@var{dirname}.
c906108c 38247
8e04817f
AC
38248@item --target=@var{target}
38249Configure @value{GDBN} for cross-debugging programs running on the specified
38250@var{target}. Without this option, @value{GDBN} is configured to debug
38251programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 38252
a95746f9
TT
38253There is no convenient way to generate a list of all available
38254targets. Also see the @code{--enable-targets} option, below.
8e04817f 38255@end table
c906108c 38256
a95746f9
TT
38257There are many other options that are specific to @value{GDBN}. This
38258lists just the most common ones; there are some very specialized
38259options not described here.
38260
38261@table @code
38262@item --enable-targets=@r{[}@var{target}@r{]}@dots{}
38263@itemx --enable-targets=all
38264Configure @value{GDBN} for cross-debugging programs running on the
38265specified list of targets. The special value @samp{all} configures
38266@value{GDBN} for debugging programs running on any target it supports.
38267
38268@item --with-gdb-datadir=@var{path}
38269Set the @value{GDBN}-specific data directory. @value{GDBN} will look
38270here for certain supporting files or scripts. This defaults to the
6b92c0d3 38271@file{gdb} subdirectory of @samp{datadir} (which can be set using
a95746f9
TT
38272@code{--datadir}).
38273
38274@item --with-relocated-sources=@var{dir}
38275Sets up the default source path substitution rule so that directory
38276names recorded in debug information will be automatically adjusted for
38277any directory under @var{dir}. @var{dir} should be a subdirectory of
38278@value{GDBN}'s configured prefix, the one mentioned in the
38279@code{--prefix} or @code{--exec-prefix} options to configure. This
38280option is useful if GDB is supposed to be moved to a different place
38281after it is built.
38282
38283@item --enable-64-bit-bfd
38284Enable 64-bit support in BFD on 32-bit hosts.
38285
38286@item --disable-gdbmi
38287Build @value{GDBN} without the GDB/MI machine interface
38288(@pxref{GDB/MI}).
38289
38290@item --enable-tui
38291Build @value{GDBN} with the text-mode full-screen user interface
38292(TUI). Requires a curses library (ncurses and cursesX are also
38293supported).
38294
38295@item --with-curses
38296Use the curses library instead of the termcap library, for text-mode
38297terminal operations.
38298
0d79cdc4
AM
38299@item --with-debuginfod
38300Build @value{GDBN} with libdebuginfod, the debuginfod client library.
38301Used to automatically fetch source files and separate debug files from
38302debuginfod servers using the associated executable's build ID. Enabled
38303by default if libdebuginfod is installed and found at configure time.
38304debuginfod is packaged with elfutils, starting with version 0.178. You
38305can get the latest version from `https://sourceware.org/elfutils/'.
38306
a95746f9
TT
38307@item --with-libunwind-ia64
38308Use the libunwind library for unwinding function call stack on ia64
38309target platforms. See http://www.nongnu.org/libunwind/index.html for
38310details.
38311
38312@item --with-system-readline
38313Use the readline library installed on the host, rather than the
86c6b807
TT
38314library supplied as part of @value{GDBN}. Readline 7 or newer is
38315required; this is enforced by the build system.
a95746f9
TT
38316
38317@item --with-system-zlib
38318Use the zlib library installed on the host, rather than the library
38319supplied as part of @value{GDBN}.
38320
38321@item --with-expat
38322Build @value{GDBN} with Expat, a library for XML parsing. (Done by
38323default if libexpat is installed and found at configure time.) This
38324library is used to read XML files supplied with @value{GDBN}. If it
38325is unavailable, some features, such as remote protocol memory maps,
38326target descriptions, and shared library lists, that are based on XML
38327files, will not be available in @value{GDBN}. If your host does not
38328have libexpat installed, you can get the latest version from
38329`http://expat.sourceforge.net'.
38330
38331@item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
38332
38333Build @value{GDBN} with GNU libiconv, a character set encoding
38334conversion library. This is not done by default, as on GNU systems
38335the @code{iconv} that is built in to the C library is sufficient. If
38336your host does not have a working @code{iconv}, you can get the latest
38337version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
38338
38339@value{GDBN}'s build system also supports building GNU libiconv as
38340part of the overall build. @xref{Requirements}.
38341
38342@item --with-lzma
38343Build @value{GDBN} with LZMA, a compression library. (Done by default
38344if liblzma is installed and found at configure time.) LZMA is used by
38345@value{GDBN}'s "mini debuginfo" feature, which is only useful on
38346platforms using the ELF object file format. If your host does not
38347have liblzma installed, you can get the latest version from
38348`https://tukaani.org/xz/'.
38349
38350@item --with-mpfr
38351Build @value{GDBN} with GNU MPFR, a library for multiple-precision
38352floating-point computation with correct rounding. (Done by default if
38353GNU MPFR is installed and found at configure time.) This library is
38354used to emulate target floating-point arithmetic during expression
38355evaluation when the target uses different floating-point formats than
38356the host. If GNU MPFR is not available, @value{GDBN} will fall back
38357to using host floating-point arithmetic. If your host does not have
38358GNU MPFR installed, you can get the latest version from
38359`http://www.mpfr.org'.
38360
38361@item --with-python@r{[}=@var{python}@r{]}
38362Build @value{GDBN} with Python scripting support. (Done by default if
38363libpython is present and found at configure time.) Python makes
38364@value{GDBN} scripting much more powerful than the restricted CLI
38365scripting language. If your host does not have Python installed, you
38366can find it on `http://www.python.org/download/'. The oldest version
2c3fc25d 38367of Python supported by GDB is 2.6. The optional argument @var{python}
a95746f9
TT
38368is used to find the Python headers and libraries. It can be either
38369the name of a Python executable, or the name of the directory in which
38370Python is installed.
38371
38372@item --with-guile[=GUILE]'
38373Build @value{GDBN} with GNU Guile scripting support. (Done by default
38374if libguile is present and found at configure time.) If your host
38375does not have Guile installed, you can find it at
38376`https://www.gnu.org/software/guile/'. The optional argument GUILE
38377can be a version number, which will cause @code{configure} to try to
38378use that version of Guile; or the file name of a @code{pkg-config}
38379executable, which will be queried to find the information needed to
38380compile and link against Guile.
38381
38382@item --without-included-regex
38383Don't use the regex library included with @value{GDBN} (as part of the
38384libiberty library). This is the default on hosts with version 2 of
38385the GNU C library.
38386
38387@item --with-sysroot=@var{dir}
38388Use @var{dir} as the default system root directory for libraries whose
38389file names begin with @file{/lib}' or @file{/usr/lib'}. (The value of
38390@var{dir} can be modified at run time by using the @command{set
38391sysroot} command.) If @var{dir} is under the @value{GDBN} configured
38392prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
38393default system root will be automatically adjusted if and when
38394@value{GDBN} is moved to a different location.
38395
38396@item --with-system-gdbinit=@var{file}
38397Configure @value{GDBN} to automatically load a system-wide init file.
38398@var{file} should be an absolute file name. If @var{file} is in a
38399directory under the configured prefix, and @value{GDBN} is moved to
38400another location after being built, the location of the system-wide
38401init file will be adjusted accordingly.
38402
ed2a2229
CB
38403@item --with-system-gdbinit-dir=@var{directory}
38404Configure @value{GDBN} to automatically load init files from a
38405system-wide directory. @var{directory} should be an absolute directory
38406name. If @var{directory} is in a directory under the configured
38407prefix, and @value{GDBN} is moved to another location after being
38408built, the location of the system-wide init directory will be
38409adjusted accordingly.
38410
a95746f9
TT
38411@item --enable-build-warnings
38412When building the @value{GDBN} sources, ask the compiler to warn about
38413any code which looks even vaguely suspicious. It passes many
38414different warning flags, depending on the exact version of the
38415compiler you are using.
38416
38417@item --enable-werror
38418Treat compiler warnings as werrors. It adds the @code{-Werror} flag
38419to the compiler, which will fail the compilation if the compiler
38420outputs any warning messages.
f35d5ade
TT
38421
38422@item --enable-ubsan
eff98030
TT
38423Enable the GCC undefined behavior sanitizer. This is disabled by
38424default, but passing @code{--enable-ubsan=yes} or
38425@code{--enable-ubsan=auto} to @code{configure} will enable it. The
38426undefined behavior sanitizer checks for C@t{++} undefined behavior.
38427It has a performance cost, so if you are looking at @value{GDBN}'s
38428performance, you should disable it. The undefined behavior sanitizer
38429was first introduced in GCC 4.9.
a95746f9 38430@end table
c906108c 38431
098b41a6
JG
38432@node System-wide configuration
38433@section System-wide configuration and settings
38434@cindex system-wide init file
38435
ed2a2229
CB
38436@value{GDBN} can be configured to have a system-wide init file and a
38437system-wide init file directory; this file and files in that directory
38438(if they have a recognized file extension) will be read and executed at
38439startup (@pxref{Startup, , What @value{GDBN} does during startup}).
098b41a6 38440
ed2a2229 38441Here are the corresponding configure options:
098b41a6
JG
38442
38443@table @code
38444@item --with-system-gdbinit=@var{file}
38445Specify that the default location of the system-wide init file is
38446@var{file}.
ed2a2229
CB
38447@item --with-system-gdbinit-dir=@var{directory}
38448Specify that the default location of the system-wide init file directory
38449is @var{directory}.
098b41a6
JG
38450@end table
38451
38452If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
ed2a2229 38453they may be subject to relocation. Two possible cases:
098b41a6
JG
38454
38455@itemize @bullet
38456@item
ed2a2229 38457If the default location of this init file/directory contains @file{$prefix},
098b41a6
JG
38458it will be subject to relocation. Suppose that the configure options
38459are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
38460if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
38461init file is looked for as @file{$install/etc/gdbinit} instead of
38462@file{$prefix/etc/gdbinit}.
38463
38464@item
38465By contrast, if the default location does not contain the prefix,
38466it will not be relocated. E.g.@: if @value{GDBN} has been configured with
38467@option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
38468then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
38469wherever @value{GDBN} is installed.
38470@end itemize
38471
e64e0392
DE
38472If the configured location of the system-wide init file (as given by the
38473@option{--with-system-gdbinit} option at configure time) is in the
38474data-directory (as specified by @option{--with-gdb-datadir} at configure
38475time) or in one of its subdirectories, then @value{GDBN} will look for the
38476system-wide init file in the directory specified by the
38477@option{--data-directory} command-line option.
38478Note that the system-wide init file is only read once, during @value{GDBN}
38479initialization. If the data-directory is changed after @value{GDBN} has
38480started with the @code{set data-directory} command, the file will not be
38481reread.
38482
ed2a2229
CB
38483This applies similarly to the system-wide directory specified in
38484@option{--with-system-gdbinit-dir}.
38485
38486Any supported scripting language can be used for these init files, as long
38487as the file extension matches the scripting language. To be interpreted
38488as regular @value{GDBN} commands, the files needs to have a @file{.gdb}
38489extension.
38490
5901af59
JB
38491@menu
38492* System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
38493@end menu
38494
38495@node System-wide Configuration Scripts
0201faac
JB
38496@subsection Installed System-wide Configuration Scripts
38497@cindex system-wide configuration scripts
38498
38499The @file{system-gdbinit} directory, located inside the data-directory
38500(as specified by @option{--with-gdb-datadir} at configure time) contains
38501a number of scripts which can be used as system-wide init files. To
38502automatically source those scripts at startup, @value{GDBN} should be
38503configured with @option{--with-system-gdbinit}. Otherwise, any user
38504should be able to source them by hand as needed.
38505
38506The following scripts are currently available:
38507@itemize @bullet
38508
38509@item @file{elinos.py}
38510@pindex elinos.py
38511@cindex ELinOS system-wide configuration script
38512This script is useful when debugging a program on an ELinOS target.
38513It takes advantage of the environment variables defined in a standard
38514ELinOS environment in order to determine the location of the system
38515shared libraries, and then sets the @samp{solib-absolute-prefix}
38516and @samp{solib-search-path} variables appropriately.
38517
38518@item @file{wrs-linux.py}
38519@pindex wrs-linux.py
38520@cindex Wind River Linux system-wide configuration script
38521This script is useful when debugging a program on a target running
38522Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
38523the host-side sysroot used by the target system.
38524
38525@end itemize
38526
8e04817f
AC
38527@node Maintenance Commands
38528@appendix Maintenance Commands
38529@cindex maintenance commands
38530@cindex internal commands
c906108c 38531
8e04817f 38532In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
38533includes a number of commands intended for @value{GDBN} developers,
38534that are not documented elsewhere in this manual. These commands are
da316a69
EZ
38535provided here for reference. (For commands that turn on debugging
38536messages, see @ref{Debugging Output}.)
c906108c 38537
8e04817f 38538@table @code
09d4efe1 38539@kindex maint agent
782b2b07 38540@kindex maint agent-eval
f77cc5f0
HZ
38541@item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38542@itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
09d4efe1
EZ
38543Translate the given @var{expression} into remote agent bytecodes.
38544This command is useful for debugging the Agent Expression mechanism
782b2b07
SS
38545(@pxref{Agent Expressions}). The @samp{agent} version produces an
38546expression useful for data collection, such as by tracepoints, while
38547@samp{maint agent-eval} produces an expression that evaluates directly
38548to a result. For instance, a collection expression for @code{globa +
38549globb} will include bytecodes to record four bytes of memory at each
38550of the addresses of @code{globa} and @code{globb}, while discarding
38551the result of the addition, while an evaluation expression will do the
38552addition and return the sum.
f77cc5f0
HZ
38553If @code{-at} is given, generate remote agent bytecode for @var{location}.
38554If not, generate remote agent bytecode for current frame PC address.
09d4efe1 38555
d3ce09f5
SS
38556@kindex maint agent-printf
38557@item maint agent-printf @var{format},@var{expr},...
38558Translate the given format string and list of argument expressions
38559into remote agent bytecodes and display them as a disassembled list.
38560This command is useful for debugging the agent version of dynamic
6dd24dfa 38561printf (@pxref{Dynamic Printf}).
d3ce09f5 38562
8e04817f
AC
38563@kindex maint info breakpoints
38564@item @anchor{maint info breakpoints}maint info breakpoints
38565Using the same format as @samp{info breakpoints}, display both the
38566breakpoints you've set explicitly, and those @value{GDBN} is using for
38567internal purposes. Internal breakpoints are shown with negative
38568breakpoint numbers. The type column identifies what kind of breakpoint
38569is shown:
c906108c 38570
8e04817f
AC
38571@table @code
38572@item breakpoint
38573Normal, explicitly set breakpoint.
c906108c 38574
8e04817f
AC
38575@item watchpoint
38576Normal, explicitly set watchpoint.
c906108c 38577
8e04817f
AC
38578@item longjmp
38579Internal breakpoint, used to handle correctly stepping through
38580@code{longjmp} calls.
c906108c 38581
8e04817f
AC
38582@item longjmp resume
38583Internal breakpoint at the target of a @code{longjmp}.
c906108c 38584
8e04817f
AC
38585@item until
38586Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 38587
8e04817f
AC
38588@item finish
38589Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 38590
8e04817f
AC
38591@item shlib events
38592Shared library events.
c906108c 38593
8e04817f 38594@end table
c906108c 38595
b0627500
MM
38596@kindex maint info btrace
38597@item maint info btrace
38598Pint information about raw branch tracing data.
38599
38600@kindex maint btrace packet-history
38601@item maint btrace packet-history
38602Print the raw branch trace packets that are used to compute the
38603execution history for the @samp{record btrace} command. Both the
38604information and the format in which it is printed depend on the btrace
38605recording format.
38606
38607@table @code
38608@item bts
38609For the BTS recording format, print a list of blocks of sequential
38610code. For each block, the following information is printed:
38611
38612@table @asis
38613@item Block number
38614Newer blocks have higher numbers. The oldest block has number zero.
38615@item Lowest @samp{PC}
38616@item Highest @samp{PC}
38617@end table
38618
38619@item pt
bc504a31
PA
38620For the Intel Processor Trace recording format, print a list of
38621Intel Processor Trace packets. For each packet, the following
b0627500
MM
38622information is printed:
38623
38624@table @asis
38625@item Packet number
38626Newer packets have higher numbers. The oldest packet has number zero.
38627@item Trace offset
38628The packet's offset in the trace stream.
38629@item Packet opcode and payload
38630@end table
38631@end table
38632
38633@kindex maint btrace clear-packet-history
38634@item maint btrace clear-packet-history
38635Discards the cached packet history printed by the @samp{maint btrace
38636packet-history} command. The history will be computed again when
38637needed.
38638
38639@kindex maint btrace clear
38640@item maint btrace clear
38641Discard the branch trace data. The data will be fetched anew and the
38642branch trace will be recomputed when needed.
38643
38644This implicitly truncates the branch trace to a single branch trace
38645buffer. When updating branch trace incrementally, the branch trace
38646available to @value{GDBN} may be bigger than a single branch trace
38647buffer.
38648
38649@kindex maint set btrace pt skip-pad
38650@item maint set btrace pt skip-pad
38651@kindex maint show btrace pt skip-pad
38652@item maint show btrace pt skip-pad
38653Control whether @value{GDBN} will skip PAD packets when computing the
38654packet history.
38655
fff08868
HZ
38656@kindex set displaced-stepping
38657@kindex show displaced-stepping
237fc4c9
PA
38658@cindex displaced stepping support
38659@cindex out-of-line single-stepping
fff08868
HZ
38660@item set displaced-stepping
38661@itemx show displaced-stepping
237fc4c9 38662Control whether or not @value{GDBN} will do @dfn{displaced stepping}
fff08868
HZ
38663if the target supports it. Displaced stepping is a way to single-step
38664over breakpoints without removing them from the inferior, by executing
38665an out-of-line copy of the instruction that was originally at the
38666breakpoint location. It is also known as out-of-line single-stepping.
38667
38668@table @code
38669@item set displaced-stepping on
38670If the target architecture supports it, @value{GDBN} will use
38671displaced stepping to step over breakpoints.
38672
38673@item set displaced-stepping off
38674@value{GDBN} will not use displaced stepping to step over breakpoints,
38675even if such is supported by the target architecture.
38676
38677@cindex non-stop mode, and @samp{set displaced-stepping}
38678@item set displaced-stepping auto
38679This is the default mode. @value{GDBN} will use displaced stepping
38680only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
38681architecture supports displaced stepping.
38682@end table
237fc4c9 38683
7d0c9981
DE
38684@kindex maint check-psymtabs
38685@item maint check-psymtabs
38686Check the consistency of currently expanded psymtabs versus symtabs.
38687Use this to check, for example, whether a symbol is in one but not the other.
38688
09d4efe1
EZ
38689@kindex maint check-symtabs
38690@item maint check-symtabs
7d0c9981
DE
38691Check the consistency of currently expanded symtabs.
38692
38693@kindex maint expand-symtabs
38694@item maint expand-symtabs [@var{regexp}]
38695Expand symbol tables.
38696If @var{regexp} is specified, only expand symbol tables for file
38697names matching @var{regexp}.
09d4efe1 38698
992c7d70
GB
38699@kindex maint set catch-demangler-crashes
38700@kindex maint show catch-demangler-crashes
38701@cindex demangler crashes
38702@item maint set catch-demangler-crashes [on|off]
38703@itemx maint show catch-demangler-crashes
38704Control whether @value{GDBN} should attempt to catch crashes in the
38705symbol name demangler. The default is to attempt to catch crashes.
38706If enabled, the first time a crash is caught, a core file is created,
38707the offending symbol is displayed and the user is presented with the
38708option to terminate the current session.
38709
09d4efe1
EZ
38710@kindex maint cplus first_component
38711@item maint cplus first_component @var{name}
38712Print the first C@t{++} class/namespace component of @var{name}.
38713
38714@kindex maint cplus namespace
38715@item maint cplus namespace
38716Print the list of possible C@t{++} namespaces.
38717
09d4efe1
EZ
38718@kindex maint deprecate
38719@kindex maint undeprecate
38720@cindex deprecated commands
38721@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
38722@itemx maint undeprecate @var{command}
38723Deprecate or undeprecate the named @var{command}. Deprecated commands
38724cause @value{GDBN} to issue a warning when you use them. The optional
38725argument @var{replacement} says which newer command should be used in
38726favor of the deprecated one; if it is given, @value{GDBN} will mention
38727the replacement as part of the warning.
38728
38729@kindex maint dump-me
38730@item maint dump-me
721c2651 38731@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 38732Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
38733This is supported only on systems which support aborting a program
38734with the @code{SIGQUIT} signal.
09d4efe1 38735
8d30a00d
AC
38736@kindex maint internal-error
38737@kindex maint internal-warning
57fcfb1b
GB
38738@kindex maint demangler-warning
38739@cindex demangler crashes
09d4efe1
EZ
38740@item maint internal-error @r{[}@var{message-text}@r{]}
38741@itemx maint internal-warning @r{[}@var{message-text}@r{]}
57fcfb1b
GB
38742@itemx maint demangler-warning @r{[}@var{message-text}@r{]}
38743
38744Cause @value{GDBN} to call the internal function @code{internal_error},
38745@code{internal_warning} or @code{demangler_warning} and hence behave
7ee67ee4 38746as though an internal problem has been detected. In addition to
57fcfb1b
GB
38747reporting the internal problem, these functions give the user the
38748opportunity to either quit @value{GDBN} or (for @code{internal_error}
38749and @code{internal_warning}) create a core file of the current
8d30a00d
AC
38750@value{GDBN} session.
38751
09d4efe1
EZ
38752These commands take an optional parameter @var{message-text} that is
38753used as the text of the error or warning message.
38754
d3e8051b 38755Here's an example of using @code{internal-error}:
09d4efe1 38756
8d30a00d 38757@smallexample
f7dc1244 38758(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
38759@dots{}/maint.c:121: internal-error: testing, 1, 2
38760A problem internal to GDB has been detected. Further
38761debugging may prove unreliable.
38762Quit this debugging session? (y or n) @kbd{n}
38763Create a core file? (y or n) @kbd{n}
f7dc1244 38764(@value{GDBP})
8d30a00d
AC
38765@end smallexample
38766
3c16cced
PA
38767@cindex @value{GDBN} internal error
38768@cindex internal errors, control of @value{GDBN} behavior
57fcfb1b 38769@cindex demangler crashes
3c16cced
PA
38770
38771@kindex maint set internal-error
38772@kindex maint show internal-error
38773@kindex maint set internal-warning
38774@kindex maint show internal-warning
57fcfb1b
GB
38775@kindex maint set demangler-warning
38776@kindex maint show demangler-warning
3c16cced
PA
38777@item maint set internal-error @var{action} [ask|yes|no]
38778@itemx maint show internal-error @var{action}
38779@itemx maint set internal-warning @var{action} [ask|yes|no]
38780@itemx maint show internal-warning @var{action}
57fcfb1b
GB
38781@itemx maint set demangler-warning @var{action} [ask|yes|no]
38782@itemx maint show demangler-warning @var{action}
3c16cced
PA
38783When @value{GDBN} reports an internal problem (error or warning) it
38784gives the user the opportunity to both quit @value{GDBN} and create a
38785core file of the current @value{GDBN} session. These commands let you
38786override the default behaviour for each particular @var{action},
38787described in the table below.
38788
38789@table @samp
38790@item quit
38791You can specify that @value{GDBN} should always (yes) or never (no)
38792quit. The default is to ask the user what to do.
38793
38794@item corefile
38795You can specify that @value{GDBN} should always (yes) or never (no)
57fcfb1b
GB
38796create a core file. The default is to ask the user what to do. Note
38797that there is no @code{corefile} option for @code{demangler-warning}:
38798demangler warnings always create a core file and this cannot be
38799disabled.
3c16cced
PA
38800@end table
38801
09d4efe1
EZ
38802@kindex maint packet
38803@item maint packet @var{text}
38804If @value{GDBN} is talking to an inferior via the serial protocol,
38805then this command sends the string @var{text} to the inferior, and
38806displays the response packet. @value{GDBN} supplies the initial
38807@samp{$} character, the terminating @samp{#} character, and the
38808checksum.
38809
38810@kindex maint print architecture
38811@item maint print architecture @r{[}@var{file}@r{]}
38812Print the entire architecture configuration. The optional argument
38813@var{file} names the file where the output goes.
8d30a00d 38814
ab33b152
AB
38815@kindex maint print c-tdesc
38816@item maint print c-tdesc @r{[}-single-feature@r{]} @r{[}@var{file}@r{]}
8e2141c6
YQ
38817Print the target description (@pxref{Target Descriptions}) as
38818a C source file. By default, the target description is for the current
38819target, but if the optional argument @var{file} is provided, that file
38820is used to produce the description. The @var{file} should be an XML
38821document, of the form described in @ref{Target Description Format}.
38822The created source file is built into @value{GDBN} when @value{GDBN} is
38823built again. This command is used by developers after they add or
38824modify XML target descriptions.
81adfced 38825
ab33b152
AB
38826When the optional flag @samp{-single-feature} is provided then the
38827target description being processed (either the default, or from
38828@var{file}) must only contain a single feature. The source file
38829produced is different in this case.
38830
caa7fd04
AB
38831@kindex maint print xml-tdesc
38832@item maint print xml-tdesc @r{[}@var{file}@r{]}
38833Print the target description (@pxref{Target Descriptions}) as an XML
38834file. By default print the target description for the current target,
38835but if the optional argument @var{file} is provided, then that file is
38836read in by GDB and then used to produce the description. The
38837@var{file} should be an XML document, of the form described in
38838@ref{Target Description Format}.
38839
27d41eac
YQ
38840@kindex maint check xml-descriptions
38841@item maint check xml-descriptions @var{dir}
38842Check that the target descriptions dynamically created by @value{GDBN}
38843equal the descriptions created from XML files found in @var{dir}.
38844
41fc26a2 38845@anchor{maint check libthread-db}
5045b3d7
GB
38846@kindex maint check libthread-db
38847@item maint check libthread-db
38848Run integrity checks on the current inferior's thread debugging
38849library. This exercises all @code{libthread_db} functionality used by
38850@value{GDBN} on GNU/Linux systems, and by extension also exercises the
38851@code{proc_service} functions provided by @value{GDBN} that
38852@code{libthread_db} uses. Note that parts of the test may be skipped
38853on some platforms when debugging core files.
38854
b089853a
KB
38855@kindex maint print core-file-backed-mappings
38856@cindex memory address space mappings
38857@item maint print core-file-backed-mappings
38858Print the file-backed mappings which were loaded from a core file note.
38859This output represents state internal to @value{GDBN} and should be
38860similar to the mappings displayed by the @code{info proc mappings}
38861command.
38862
00905d52
AC
38863@kindex maint print dummy-frames
38864@item maint print dummy-frames
00905d52
AC
38865Prints the contents of @value{GDBN}'s internal dummy-frame stack.
38866
38867@smallexample
f7dc1244 38868(@value{GDBP}) @kbd{b add}
00905d52 38869@dots{}
f7dc1244 38870(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
38871Breakpoint 2, add (a=2, b=3) at @dots{}
3887258 return (a + b);
38873The program being debugged stopped while in a function called from GDB.
38874@dots{}
f7dc1244 38875(@value{GDBP}) @kbd{maint print dummy-frames}
b67a2c6f 388760xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
f7dc1244 38877(@value{GDBP})
00905d52
AC
38878@end smallexample
38879
38880Takes an optional file parameter.
38881
0680b120
AC
38882@kindex maint print registers
38883@kindex maint print raw-registers
38884@kindex maint print cooked-registers
617073a9 38885@kindex maint print register-groups
c21236dc 38886@kindex maint print remote-registers
09d4efe1
EZ
38887@item maint print registers @r{[}@var{file}@r{]}
38888@itemx maint print raw-registers @r{[}@var{file}@r{]}
38889@itemx maint print cooked-registers @r{[}@var{file}@r{]}
38890@itemx maint print register-groups @r{[}@var{file}@r{]}
c21236dc 38891@itemx maint print remote-registers @r{[}@var{file}@r{]}
0680b120
AC
38892Print @value{GDBN}'s internal register data structures.
38893
617073a9 38894The command @code{maint print raw-registers} includes the contents of
c21236dc
PA
38895the raw register cache; the command @code{maint print
38896cooked-registers} includes the (cooked) value of all registers,
38897including registers which aren't available on the target nor visible
38898to user; the command @code{maint print register-groups} includes the
38899groups that each register is a member of; and the command @code{maint
38900print remote-registers} includes the remote target's register numbers
0a7cfe2c 38901and offsets in the `G' packets.
0680b120 38902
09d4efe1
EZ
38903These commands take an optional parameter, a file name to which to
38904write the information.
0680b120 38905
617073a9 38906@kindex maint print reggroups
09d4efe1
EZ
38907@item maint print reggroups @r{[}@var{file}@r{]}
38908Print @value{GDBN}'s internal register group data structures. The
38909optional argument @var{file} tells to what file to write the
38910information.
617073a9 38911
09d4efe1 38912The register groups info looks like this:
617073a9
AC
38913
38914@smallexample
f7dc1244 38915(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
38916 Group Type
38917 general user
38918 float user
38919 all user
38920 vector user
38921 system user
38922 save internal
38923 restore internal
617073a9
AC
38924@end smallexample
38925
50a5f187 38926@kindex maint flush register-cache
09d4efe1 38927@kindex flushregs
50a5f187
AB
38928@cindex register cache, flushing
38929@item maint flush register-cache
38930@itemx flushregs
38931Flush the contents of the register cache and as a consequence the
38932frame cache. This command is useful when debugging issues related to
38933register fetching, or frame unwinding. The command @code{flushregs}
38934is deprecated in favor of @code{maint flush register-cache}.
09d4efe1
EZ
38935
38936@kindex maint print objfiles
38937@cindex info for known object files
52e260a3
DE
38938@item maint print objfiles @r{[}@var{regexp}@r{]}
38939Print a dump of all known object files.
38940If @var{regexp} is specified, only print object files whose names
38941match @var{regexp}. For each object file, this command prints its name,
38942address in memory, and all of its psymtabs and symtabs.
09d4efe1 38943
f5b95c01
AA
38944@kindex maint print user-registers
38945@cindex user registers
38946@item maint print user-registers
38947List all currently available @dfn{user registers}. User registers
38948typically provide alternate names for actual hardware registers. They
38949include the four ``standard'' registers @code{$fp}, @code{$pc},
38950@code{$sp}, and @code{$ps}. @xref{standard registers}. User
38951registers can be used in expressions in the same way as the canonical
38952register names, but only the latter are listed by the @code{info
38953registers} and @code{maint print registers} commands.
38954
8a1ea21f
DE
38955@kindex maint print section-scripts
38956@cindex info for known .debug_gdb_scripts-loaded scripts
38957@item maint print section-scripts [@var{regexp}]
38958Print a dump of scripts specified in the @code{.debug_gdb_section} section.
38959If @var{regexp} is specified, only print scripts loaded by object files
38960matching @var{regexp}.
38961For each script, this command prints its name as specified in the objfile,
38962and the full path if known.
8e0583c8 38963@xref{dotdebug_gdb_scripts section}.
8a1ea21f 38964
09d4efe1
EZ
38965@kindex maint print statistics
38966@cindex bcache statistics
38967@item maint print statistics
38968This command prints, for each object file in the program, various data
38969about that object file followed by the byte cache (@dfn{bcache})
38970statistics for the object file. The objfile data includes the number
d3e8051b 38971of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
38972defined by the objfile, the number of as yet unexpanded psym tables,
38973the number of line tables and string tables, and the amount of memory
38974used by the various tables. The bcache statistics include the counts,
38975sizes, and counts of duplicates of all and unique objects, max,
38976average, and median entry size, total memory used and its overhead and
38977savings, and various measures of the hash table size and chain
38978lengths.
38979
c7ba131e
JB
38980@kindex maint print target-stack
38981@cindex target stack description
38982@item maint print target-stack
38983A @dfn{target} is an interface between the debugger and a particular
38984kind of file or process. Targets can be stacked in @dfn{strata},
38985so that more than one target can potentially respond to a request.
38986In particular, memory accesses will walk down the stack of targets
38987until they find a target that is interested in handling that particular
38988address.
38989
38990This command prints a short description of each layer that was pushed on
38991the @dfn{target stack}, starting from the top layer down to the bottom one.
38992
09d4efe1
EZ
38993@kindex maint print type
38994@cindex type chain of a data type
38995@item maint print type @var{expr}
38996Print the type chain for a type specified by @var{expr}. The argument
38997can be either a type name or a symbol. If it is a symbol, the type of
38998that symbol is described. The type chain produced by this command is
38999a recursive definition of the data type as stored in @value{GDBN}'s
39000data structures, including its flags and contained types.
39001
dcd1f979
TT
39002@kindex maint selftest
39003@cindex self tests
1526853e 39004@item maint selftest @r{[}@var{filter}@r{]}
dcd1f979
TT
39005Run any self tests that were compiled in to @value{GDBN}. This will
39006print a message showing how many tests were run, and how many failed.
1526853e
SM
39007If a @var{filter} is passed, only the tests with @var{filter} in their
39008name will by ran.
39009
3c2fcaf9 39010@kindex maint info selftests
1526853e
SM
39011@cindex self tests
39012@item maint info selftests
39013List the selftests compiled in to @value{GDBN}.
dcd1f979 39014
b4f54984
DE
39015@kindex maint set dwarf always-disassemble
39016@kindex maint show dwarf always-disassemble
39017@item maint set dwarf always-disassemble
39018@item maint show dwarf always-disassemble
9eae7c52
TT
39019Control the behavior of @code{info address} when using DWARF debugging
39020information.
39021
39022The default is @code{off}, which means that @value{GDBN} should try to
39023describe a variable's location in an easily readable format. When
39024@code{on}, @value{GDBN} will instead display the DWARF location
39025expression in an assembly-like format. Note that some locations are
39026too complex for @value{GDBN} to describe simply; in this case you will
39027always see the disassembly form.
39028
39029Here is an example of the resulting disassembly:
39030
39031@smallexample
39032(gdb) info addr argc
39033Symbol "argc" is a complex DWARF expression:
39034 1: DW_OP_fbreg 0
39035@end smallexample
39036
39037For more information on these expressions, see
39038@uref{http://www.dwarfstd.org/, the DWARF standard}.
39039
b4f54984
DE
39040@kindex maint set dwarf max-cache-age
39041@kindex maint show dwarf max-cache-age
39042@item maint set dwarf max-cache-age
39043@itemx maint show dwarf max-cache-age
39044Control the DWARF compilation unit cache.
09d4efe1 39045
b4f54984 39046@cindex DWARF compilation units cache
09d4efe1 39047In object files with inter-compilation-unit references, such as those
b4f54984 39048produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
09d4efe1
EZ
39049reader needs to frequently refer to previously read compilation units.
39050This setting controls how long a compilation unit will remain in the
39051cache if it is not referenced. A higher limit means that cached
39052compilation units will be stored in memory longer, and more total
39053memory will be used. Setting it to zero disables caching, which will
39054slow down @value{GDBN} startup, but reduce memory consumption.
39055
3c3bb058
AB
39056@kindex maint set dwarf unwinders
39057@kindex maint show dwarf unwinders
39058@item maint set dwarf unwinders
39059@itemx maint show dwarf unwinders
39060Control use of the DWARF frame unwinders.
39061
39062@cindex DWARF frame unwinders
39063Many targets that support DWARF debugging use @value{GDBN}'s DWARF
39064frame unwinders to build the backtrace. Many of these targets will
39065also have a second mechanism for building the backtrace for use in
39066cases where DWARF information is not available, this second mechanism
39067is often an analysis of a function's prologue.
39068
39069In order to extend testing coverage of the second level stack
39070unwinding mechanisms it is helpful to be able to disable the DWARF
39071stack unwinders, this can be done with this switch.
39072
39073In normal use of @value{GDBN} disabling the DWARF unwinders is not
39074advisable, there are cases that are better handled through DWARF than
39075prologue analysis, and the debug experience is likely to be better
39076with the DWARF frame unwinders enabled.
39077
39078If DWARF frame unwinders are not supported for a particular target
39079architecture, then enabling this flag does not cause them to be used.
22138db6
TT
39080
39081@kindex maint set worker-threads
39082@kindex maint show worker-threads
39083@item maint set worker-threads
39084@item maint show worker-threads
39085Control the number of worker threads that may be used by @value{GDBN}.
39086On capable hosts, @value{GDBN} may use multiple threads to speed up
39087certain CPU-intensive operations, such as demangling symbol names.
39088While the number of threads used by @value{GDBN} may vary, this
39089command can be used to set an upper bound on this number. The default
39090is @code{unlimited}, which lets @value{GDBN} choose a reasonable
39091number. Note that this only controls worker threads started by
39092@value{GDBN} itself; libraries used by @value{GDBN} may start threads
39093of their own.
39094
e7ba9c65
DJ
39095@kindex maint set profile
39096@kindex maint show profile
39097@cindex profiling GDB
39098@item maint set profile
39099@itemx maint show profile
39100Control profiling of @value{GDBN}.
39101
39102Profiling will be disabled until you use the @samp{maint set profile}
39103command to enable it. When you enable profiling, the system will begin
39104collecting timing and execution count data; when you disable profiling or
39105exit @value{GDBN}, the results will be written to a log file. Remember that
39106if you use profiling, @value{GDBN} will overwrite the profiling log file
39107(often called @file{gmon.out}). If you have a record of important profiling
39108data in a @file{gmon.out} file, be sure to move it to a safe location.
39109
39110Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 39111compiled with the @samp{-pg} compiler option.
e7ba9c65 39112
cbe54154
PA
39113@kindex maint set show-debug-regs
39114@kindex maint show show-debug-regs
eac35c4e 39115@cindex hardware debug registers
cbe54154
PA
39116@item maint set show-debug-regs
39117@itemx maint show show-debug-regs
eac35c4e 39118Control whether to show variables that mirror the hardware debug
6dd315ba 39119registers. Use @code{on} to enable, @code{off} to disable. If
3f94c067 39120enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
39121removes a hardware breakpoint or watchpoint, and when the inferior
39122triggers a hardware-assisted breakpoint or watchpoint.
39123
711e434b
PM
39124@kindex maint set show-all-tib
39125@kindex maint show show-all-tib
39126@item maint set show-all-tib
39127@itemx maint show show-all-tib
39128Control whether to show all non zero areas within a 1k block starting
39129at thread local base, when using the @samp{info w32 thread-information-block}
39130command.
39131
329ea579
PA
39132@kindex maint set target-async
39133@kindex maint show target-async
39134@item maint set target-async
39135@itemx maint show target-async
39136This controls whether @value{GDBN} targets operate in synchronous or
39137asynchronous mode (@pxref{Background Execution}). Normally the
39138default is asynchronous, if it is available; but this can be changed
39139to more easily debug problems occurring only in synchronous mode.
39140
fbea99ea
PA
39141@kindex maint set target-non-stop @var{mode} [on|off|auto]
39142@kindex maint show target-non-stop
39143@item maint set target-non-stop
39144@itemx maint show target-non-stop
39145
39146This controls whether @value{GDBN} targets always operate in non-stop
39147mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
39148Mode}). The default is @code{auto}, meaning non-stop mode is enabled
39149if supported by the target.
39150
39151@table @code
39152@item maint set target-non-stop auto
39153This is the default mode. @value{GDBN} controls the target in
39154non-stop mode if the target supports it.
39155
39156@item maint set target-non-stop on
39157@value{GDBN} controls the target in non-stop mode even if the target
39158does not indicate support.
39159
39160@item maint set target-non-stop off
39161@value{GDBN} does not control the target in non-stop mode even if the
39162target supports it.
39163@end table
39164
45e42163
TT
39165@kindex maint set tui-resize-message
39166@kindex maint show tui-resize-message
39167@item maint set tui-resize-message
39168@item maint show tui-resize-message
39169Control whether @value{GDBN} displays a message each time the terminal
39170is resized when in TUI mode. The default is @code{off}, which means
39171that @value{GDBN} is silent during resizes. When @code{on},
39172@value{GDBN} will display a message after a resize is completed; the
39173message will include a number indicating how many times the terminal
39174has been resized. This setting is intended for use by the test suite,
39175where it would otherwise be difficult to determine when a resize and
39176refresh has been completed.
39177
bd712aed
DE
39178@kindex maint set per-command
39179@kindex maint show per-command
39180@item maint set per-command
39181@itemx maint show per-command
39182@cindex resources used by commands
09d4efe1 39183
bd712aed
DE
39184@value{GDBN} can display the resources used by each command.
39185This is useful in debugging performance problems.
39186
39187@table @code
39188@item maint set per-command space [on|off]
39189@itemx maint show per-command space
39190Enable or disable the printing of the memory used by GDB for each command.
39191If enabled, @value{GDBN} will display how much memory each command
39192took, following the command's own output.
39193This can also be requested by invoking @value{GDBN} with the
39194@option{--statistics} command-line switch (@pxref{Mode Options}).
39195
39196@item maint set per-command time [on|off]
39197@itemx maint show per-command time
39198Enable or disable the printing of the execution time of @value{GDBN}
39199for each command.
39200If enabled, @value{GDBN} will display how much time it
09d4efe1 39201took to execute each command, following the command's own output.
0a1c4d10
DE
39202Both CPU time and wallclock time are printed.
39203Printing both is useful when trying to determine whether the cost is
bd712aed 39204CPU or, e.g., disk/network latency.
0a1c4d10
DE
39205Note that the CPU time printed is for @value{GDBN} only, it does not include
39206the execution time of the inferior because there's no mechanism currently
39207to compute how much time was spent by @value{GDBN} and how much time was
39208spent by the program been debugged.
09d4efe1
EZ
39209This can also be requested by invoking @value{GDBN} with the
39210@option{--statistics} command-line switch (@pxref{Mode Options}).
39211
bd712aed
DE
39212@item maint set per-command symtab [on|off]
39213@itemx maint show per-command symtab
39214Enable or disable the printing of basic symbol table statistics
39215for each command.
39216If enabled, @value{GDBN} will display the following information:
39217
215b9f98
EZ
39218@enumerate a
39219@item
39220number of symbol tables
39221@item
39222number of primary symbol tables
39223@item
39224number of blocks in the blockvector
39225@end enumerate
bd712aed
DE
39226@end table
39227
5045b3d7
GB
39228@kindex maint set check-libthread-db
39229@kindex maint show check-libthread-db
39230@item maint set check-libthread-db [on|off]
39231@itemx maint show check-libthread-db
39232Control whether @value{GDBN} should run integrity checks on inferior
39233specific thread debugging libraries as they are loaded. The default
39234is not to perform such checks. If any check fails @value{GDBN} will
39235unload the library and continue searching for a suitable candidate as
39236described in @ref{set libthread-db-search-path}. For more information
39237about the tests, see @ref{maint check libthread-db}.
39238
bd712aed
DE
39239@kindex maint space
39240@cindex memory used by commands
39241@item maint space @var{value}
39242An alias for @code{maint set per-command space}.
39243A non-zero value enables it, zero disables it.
39244
39245@kindex maint time
39246@cindex time of command execution
39247@item maint time @var{value}
39248An alias for @code{maint set per-command time}.
39249A non-zero value enables it, zero disables it.
39250
09d4efe1
EZ
39251@kindex maint translate-address
39252@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
39253Find the symbol stored at the location specified by the address
39254@var{addr} and an optional section name @var{section}. If found,
39255@value{GDBN} prints the name of the closest symbol and an offset from
39256the symbol's location to the specified address. This is similar to
39257the @code{info address} command (@pxref{Symbols}), except that this
39258command also allows to find symbols in other sections.
ae038cb0 39259
c14c28ba
PP
39260If section was not specified, the section in which the symbol was found
39261is also printed. For dynamically linked executables, the name of
39262executable or shared library containing the symbol is printed as well.
39263
3345721a
PA
39264@kindex maint test-options
39265@item maint test-options require-delimiter
39266@itemx maint test-options unknown-is-error
39267@itemx maint test-options unknown-is-operand
39268These commands are used by the testsuite to validate the command
39269options framework. The @code{require-delimiter} variant requires a
39270double-dash delimiter to indicate end of options. The
39271@code{unknown-is-error} and @code{unknown-is-operand} do not. The
39272@code{unknown-is-error} variant throws an error on unknown option,
39273while @code{unknown-is-operand} treats unknown options as the start of
39274the command's operands. When run, the commands output the result of
39275the processed options. When completed, the commands store the
39276internal result of completion in a variable exposed by the @code{maint
39277show test-options-completion-result} command.
39278
39279@kindex maint show test-options-completion-result
39280@item maint show test-options-completion-result
39281Shows the result of completing the @code{maint test-options}
39282subcommands. This is used by the testsuite to validate completion
39283support in the command options framework.
39284
c6ac8931
PA
39285@kindex maint set test-settings
39286@kindex maint show test-settings
39287@item maint set test-settings @var{kind}
39288@itemx maint show test-settings @var{kind}
dca0f6c0
PA
39289These are representative commands for each @var{kind} of setting type
39290@value{GDBN} supports. They are used by the testsuite for exercising
39291the settings infrastructure.
fdbc9870
PA
39292
39293@kindex maint with
39294@item maint with @var{setting} [@var{value}] [-- @var{command}]
39295Like the @code{with} command, but works with @code{maintenance set}
39296variables. This is used by the testsuite to exercise the @code{with}
39297command's infrastructure.
39298
8e04817f 39299@end table
c906108c 39300
9c16f35a
EZ
39301The following command is useful for non-interactive invocations of
39302@value{GDBN}, such as in the test suite.
39303
39304@table @code
39305@item set watchdog @var{nsec}
39306@kindex set watchdog
39307@cindex watchdog timer
39308@cindex timeout for commands
39309Set the maximum number of seconds @value{GDBN} will wait for the
39310target operation to finish. If this time expires, @value{GDBN}
39311reports and error and the command is aborted.
39312
39313@item show watchdog
39314Show the current setting of the target wait timeout.
39315@end table
c906108c 39316
e0ce93ac 39317@node Remote Protocol
8e04817f 39318@appendix @value{GDBN} Remote Serial Protocol
c906108c 39319
ee2d5c50
AC
39320@menu
39321* Overview::
39322* Packets::
39323* Stop Reply Packets::
39324* General Query Packets::
a1dcb23a 39325* Architecture-Specific Protocol Details::
9d29849a 39326* Tracepoint Packets::
a6b151f1 39327* Host I/O Packets::
9a6253be 39328* Interrupts::
8b23ecc4
SL
39329* Notification Packets::
39330* Remote Non-Stop::
a6f3e723 39331* Packet Acknowledgment::
ee2d5c50 39332* Examples::
79a6e687 39333* File-I/O Remote Protocol Extension::
cfa9d6d9 39334* Library List Format::
2268b414 39335* Library List Format for SVR4 Targets::
79a6e687 39336* Memory Map Format::
dc146f7c 39337* Thread List Format::
b3b9301e 39338* Traceframe Info Format::
2ae8c8e7 39339* Branch Trace Format::
f4abbc16 39340* Branch Trace Configuration Format::
ee2d5c50
AC
39341@end menu
39342
39343@node Overview
39344@section Overview
39345
8e04817f
AC
39346There may be occasions when you need to know something about the
39347protocol---for example, if there is only one serial port to your target
39348machine, you might want your program to do something special if it
39349recognizes a packet meant for @value{GDBN}.
c906108c 39350
d2c6833e 39351In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 39352transmitted and received data, respectively.
c906108c 39353
8e04817f
AC
39354@cindex protocol, @value{GDBN} remote serial
39355@cindex serial protocol, @value{GDBN} remote
39356@cindex remote serial protocol
8b23ecc4
SL
39357All @value{GDBN} commands and responses (other than acknowledgments
39358and notifications, see @ref{Notification Packets}) are sent as a
39359@var{packet}. A @var{packet} is introduced with the character
8e04817f
AC
39360@samp{$}, the actual @var{packet-data}, and the terminating character
39361@samp{#} followed by a two-digit @var{checksum}:
c906108c 39362
474c8240 39363@smallexample
8e04817f 39364@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 39365@end smallexample
8e04817f 39366@noindent
c906108c 39367
8e04817f
AC
39368@cindex checksum, for @value{GDBN} remote
39369@noindent
39370The two-digit @var{checksum} is computed as the modulo 256 sum of all
39371characters between the leading @samp{$} and the trailing @samp{#} (an
39372eight bit unsigned checksum).
c906108c 39373
8e04817f
AC
39374Implementors should note that prior to @value{GDBN} 5.0 the protocol
39375specification also included an optional two-digit @var{sequence-id}:
c906108c 39376
474c8240 39377@smallexample
8e04817f 39378@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 39379@end smallexample
c906108c 39380
8e04817f
AC
39381@cindex sequence-id, for @value{GDBN} remote
39382@noindent
39383That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
39384has never output @var{sequence-id}s. Stubs that handle packets added
39385since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 39386
8e04817f
AC
39387When either the host or the target machine receives a packet, the first
39388response expected is an acknowledgment: either @samp{+} (to indicate
39389the package was received correctly) or @samp{-} (to request
39390retransmission):
c906108c 39391
474c8240 39392@smallexample
d2c6833e
AC
39393-> @code{$}@var{packet-data}@code{#}@var{checksum}
39394<- @code{+}
474c8240 39395@end smallexample
8e04817f 39396@noindent
53a5351d 39397
a6f3e723
SL
39398The @samp{+}/@samp{-} acknowledgments can be disabled
39399once a connection is established.
39400@xref{Packet Acknowledgment}, for details.
39401
8e04817f
AC
39402The host (@value{GDBN}) sends @var{command}s, and the target (the
39403debugging stub incorporated in your program) sends a @var{response}. In
39404the case of step and continue @var{command}s, the response is only sent
8b23ecc4
SL
39405when the operation has completed, and the target has again stopped all
39406threads in all attached processes. This is the default all-stop mode
39407behavior, but the remote protocol also supports @value{GDBN}'s non-stop
39408execution mode; see @ref{Remote Non-Stop}, for details.
c906108c 39409
8e04817f
AC
39410@var{packet-data} consists of a sequence of characters with the
39411exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
39412exceptions).
c906108c 39413
ee2d5c50 39414@cindex remote protocol, field separator
0876f84a 39415Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 39416@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 39417@sc{hex} with leading zeros suppressed.
c906108c 39418
8e04817f
AC
39419Implementors should note that prior to @value{GDBN} 5.0, the character
39420@samp{:} could not appear as the third character in a packet (as it
39421would potentially conflict with the @var{sequence-id}).
c906108c 39422
0876f84a
DJ
39423@cindex remote protocol, binary data
39424@anchor{Binary Data}
39425Binary data in most packets is encoded either as two hexadecimal
39426digits per byte of binary data. This allowed the traditional remote
39427protocol to work over connections which were only seven-bit clean.
39428Some packets designed more recently assume an eight-bit clean
39429connection, and use a more efficient encoding to send and receive
39430binary data.
39431
39432The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
39433as an escape character. Any escaped byte is transmitted as the escape
39434character followed by the original character XORed with @code{0x20}.
39435For example, the byte @code{0x7d} would be transmitted as the two
39436bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
39437@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
39438@samp{@}}) must always be escaped. Responses sent by the stub
39439must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
39440is not interpreted as the start of a run-length encoded sequence
39441(described next).
39442
1d3811f6
DJ
39443Response @var{data} can be run-length encoded to save space.
39444Run-length encoding replaces runs of identical characters with one
39445instance of the repeated character, followed by a @samp{*} and a
39446repeat count. The repeat count is itself sent encoded, to avoid
39447binary characters in @var{data}: a value of @var{n} is sent as
39448@code{@var{n}+29}. For a repeat count greater or equal to 3, this
39449produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
39450code 32) for a repeat count of 3. (This is because run-length
39451encoding starts to win for counts 3 or more.) Thus, for example,
39452@samp{0* } is a run-length encoding of ``0000'': the space character
39453after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
394543}} more times.
39455
39456The printable characters @samp{#} and @samp{$} or with a numeric value
39457greater than 126 must not be used. Runs of six repeats (@samp{#}) or
39458seven repeats (@samp{$}) can be expanded using a repeat count of only
39459five (@samp{"}). For example, @samp{00000000} can be encoded as
39460@samp{0*"00}.
c906108c 39461
8e04817f
AC
39462The error response returned for some packets includes a two character
39463error number. That number is not well defined.
c906108c 39464
f8da2bff 39465@cindex empty response, for unsupported packets
8e04817f
AC
39466For any @var{command} not supported by the stub, an empty response
39467(@samp{$#00}) should be returned. That way it is possible to extend the
39468protocol. A newer @value{GDBN} can tell if a packet is supported based
39469on that response.
c906108c 39470
c9fe1b58
RT
39471At a minimum, a stub is required to support the @samp{?} command to
39472tell @value{GDBN} the reason for halting, @samp{g} and @samp{G}
393eab54
PA
39473commands for register access, and the @samp{m} and @samp{M} commands
39474for memory access. Stubs that only control single-threaded targets
c9fe1b58
RT
39475can implement run control with the @samp{c} (continue) command, and if
39476the target architecture supports hardware-assisted single-stepping,
39477the @samp{s} (step) command. Stubs that support multi-threading
39478targets should support the @samp{vCont} command. All other commands
39479are optional.
c906108c 39480
ee2d5c50
AC
39481@node Packets
39482@section Packets
39483
39484The following table provides a complete list of all currently defined
39485@var{command}s and their corresponding response @var{data}.
79a6e687 39486@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 39487I/O extension of the remote protocol.
ee2d5c50 39488
b8ff78ce
JB
39489Each packet's description has a template showing the packet's overall
39490syntax, followed by an explanation of the packet's meaning. We
39491include spaces in some of the templates for clarity; these are not
39492part of the packet's syntax. No @value{GDBN} packet uses spaces to
39493separate its components. For example, a template like @samp{foo
39494@var{bar} @var{baz}} describes a packet beginning with the three ASCII
39495bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 39496@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
39497@samp{foo} and the @var{bar}, or between the @var{bar} and the
39498@var{baz}.
39499
b90a069a
SL
39500@cindex @var{thread-id}, in remote protocol
39501@anchor{thread-id syntax}
39502Several packets and replies include a @var{thread-id} field to identify
39503a thread. Normally these are positive numbers with a target-specific
39504interpretation, formatted as big-endian hex strings. A @var{thread-id}
39505can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
39506pick any thread.
39507
39508In addition, the remote protocol supports a multiprocess feature in
39509which the @var{thread-id} syntax is extended to optionally include both
39510process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
39511The @var{pid} (process) and @var{tid} (thread) components each have the
39512format described above: a positive number with target-specific
39513interpretation formatted as a big-endian hex string, literal @samp{-1}
39514to indicate all processes or threads (respectively), or @samp{0} to
39515indicate an arbitrary process or thread. Specifying just a process, as
39516@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
39517error to specify all processes but a specific thread, such as
39518@samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
39519for those packets and replies explicitly documented to include a process
39520ID, rather than a @var{thread-id}.
39521
39522The multiprocess @var{thread-id} syntax extensions are only used if both
39523@value{GDBN} and the stub report support for the @samp{multiprocess}
39524feature using @samp{qSupported}. @xref{multiprocess extensions}, for
39525more information.
39526
8ffe2530
JB
39527Note that all packet forms beginning with an upper- or lower-case
39528letter, other than those described here, are reserved for future use.
39529
b8ff78ce 39530Here are the packet descriptions.
ee2d5c50 39531
b8ff78ce 39532@table @samp
ee2d5c50 39533
b8ff78ce
JB
39534@item !
39535@cindex @samp{!} packet
2d717e4f 39536@anchor{extended mode}
8e04817f
AC
39537Enable extended mode. In extended mode, the remote server is made
39538persistent. The @samp{R} packet is used to restart the program being
39539debugged.
ee2d5c50
AC
39540
39541Reply:
39542@table @samp
39543@item OK
8e04817f 39544The remote target both supports and has enabled extended mode.
ee2d5c50 39545@end table
c906108c 39546
b8ff78ce
JB
39547@item ?
39548@cindex @samp{?} packet
36cb1214 39549@anchor{? packet}
f37059ea
AB
39550This is sent when connection is first established to query the reason
39551the target halted. The reply is the same as for step and continue.
39552This packet has a special interpretation when the target is in
39553non-stop mode; see @ref{Remote Non-Stop}.
c906108c 39554
ee2d5c50
AC
39555Reply:
39556@xref{Stop Reply Packets}, for the reply specifications.
39557
b8ff78ce
JB
39558@item A @var{arglen},@var{argnum},@var{arg},@dots{}
39559@cindex @samp{A} packet
39560Initialized @code{argv[]} array passed into program. @var{arglen}
39561specifies the number of bytes in the hex encoded byte stream
39562@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
39563
39564Reply:
39565@table @samp
39566@item OK
b8ff78ce
JB
39567The arguments were set.
39568@item E @var{NN}
39569An error occurred.
ee2d5c50
AC
39570@end table
39571
b8ff78ce
JB
39572@item b @var{baud}
39573@cindex @samp{b} packet
39574(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
39575Change the serial line speed to @var{baud}.
39576
39577JTC: @emph{When does the transport layer state change? When it's
39578received, or after the ACK is transmitted. In either case, there are
39579problems if the command or the acknowledgment packet is dropped.}
39580
39581Stan: @emph{If people really wanted to add something like this, and get
39582it working for the first time, they ought to modify ser-unix.c to send
39583some kind of out-of-band message to a specially-setup stub and have the
39584switch happen "in between" packets, so that from remote protocol's point
39585of view, nothing actually happened.}
39586
b8ff78ce
JB
39587@item B @var{addr},@var{mode}
39588@cindex @samp{B} packet
8e04817f 39589Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
39590breakpoint at @var{addr}.
39591
b8ff78ce 39592Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 39593(@pxref{insert breakpoint or watchpoint packet}).
c906108c 39594
bacec72f 39595@cindex @samp{bc} packet
0d772ac9
MS
39596@anchor{bc}
39597@item bc
bacec72f
MS
39598Backward continue. Execute the target system in reverse. No parameter.
39599@xref{Reverse Execution}, for more information.
39600
39601Reply:
39602@xref{Stop Reply Packets}, for the reply specifications.
39603
bacec72f 39604@cindex @samp{bs} packet
0d772ac9
MS
39605@anchor{bs}
39606@item bs
bacec72f
MS
39607Backward single step. Execute one instruction in reverse. No parameter.
39608@xref{Reverse Execution}, for more information.
39609
39610Reply:
39611@xref{Stop Reply Packets}, for the reply specifications.
39612
4f553f88 39613@item c @r{[}@var{addr}@r{]}
b8ff78ce 39614@cindex @samp{c} packet
697aa1b7
EZ
39615Continue at @var{addr}, which is the address to resume. If @var{addr}
39616is omitted, resume at current address.
c906108c 39617
393eab54
PA
39618This packet is deprecated for multi-threading support. @xref{vCont
39619packet}.
39620
ee2d5c50
AC
39621Reply:
39622@xref{Stop Reply Packets}, for the reply specifications.
39623
4f553f88 39624@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 39625@cindex @samp{C} packet
8e04817f 39626Continue with signal @var{sig} (hex signal number). If
b8ff78ce 39627@samp{;@var{addr}} is omitted, resume at same address.
c906108c 39628
393eab54
PA
39629This packet is deprecated for multi-threading support. @xref{vCont
39630packet}.
39631
ee2d5c50
AC
39632Reply:
39633@xref{Stop Reply Packets}, for the reply specifications.
c906108c 39634
b8ff78ce
JB
39635@item d
39636@cindex @samp{d} packet
ee2d5c50
AC
39637Toggle debug flag.
39638
b8ff78ce
JB
39639Don't use this packet; instead, define a general set packet
39640(@pxref{General Query Packets}).
ee2d5c50 39641
b8ff78ce 39642@item D
b90a069a 39643@itemx D;@var{pid}
b8ff78ce 39644@cindex @samp{D} packet
b90a069a
SL
39645The first form of the packet is used to detach @value{GDBN} from the
39646remote system. It is sent to the remote target
07f31aa6 39647before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50 39648
b90a069a
SL
39649The second form, including a process ID, is used when multiprocess
39650protocol extensions are enabled (@pxref{multiprocess extensions}), to
39651detach only a specific process. The @var{pid} is specified as a
39652big-endian hex string.
39653
ee2d5c50
AC
39654Reply:
39655@table @samp
10fac096
NW
39656@item OK
39657for success
b8ff78ce 39658@item E @var{NN}
10fac096 39659for an error
ee2d5c50 39660@end table
c906108c 39661
b8ff78ce
JB
39662@item F @var{RC},@var{EE},@var{CF};@var{XX}
39663@cindex @samp{F} packet
39664A reply from @value{GDBN} to an @samp{F} packet sent by the target.
39665This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 39666Remote Protocol Extension}, for the specification.
ee2d5c50 39667
b8ff78ce 39668@item g
ee2d5c50 39669@anchor{read registers packet}
b8ff78ce 39670@cindex @samp{g} packet
ee2d5c50
AC
39671Read general registers.
39672
39673Reply:
39674@table @samp
39675@item @var{XX@dots{}}
8e04817f
AC
39676Each byte of register data is described by two hex digits. The bytes
39677with the register are transmitted in target byte order. The size of
b8ff78ce 39678each register and their position within the @samp{g} packet are
4a9bb1df 39679determined by the @value{GDBN} internal gdbarch functions
4435e1cc 39680@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
ad196637
PA
39681
39682When reading registers from a trace frame (@pxref{Analyze Collected
39683Data,,Using the Collected Data}), the stub may also return a string of
39684literal @samp{x}'s in place of the register data digits, to indicate
39685that the corresponding register has not been collected, thus its value
39686is unavailable. For example, for an architecture with 4 registers of
396874 bytes each, the following reply indicates to @value{GDBN} that
39688registers 0 and 2 have not been collected, while registers 1 and 3
39689have been collected, and both have zero value:
39690
39691@smallexample
39692-> @code{g}
39693<- @code{xxxxxxxx00000000xxxxxxxx00000000}
39694@end smallexample
39695
b8ff78ce 39696@item E @var{NN}
ee2d5c50
AC
39697for an error.
39698@end table
c906108c 39699
b8ff78ce
JB
39700@item G @var{XX@dots{}}
39701@cindex @samp{G} packet
39702Write general registers. @xref{read registers packet}, for a
39703description of the @var{XX@dots{}} data.
ee2d5c50
AC
39704
39705Reply:
39706@table @samp
39707@item OK
39708for success
b8ff78ce 39709@item E @var{NN}
ee2d5c50
AC
39710for an error
39711@end table
39712
393eab54 39713@item H @var{op} @var{thread-id}
b8ff78ce 39714@cindex @samp{H} packet
8e04817f 39715Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
697aa1b7
EZ
39716@samp{G}, et.al.). Depending on the operation to be performed, @var{op}
39717should be @samp{c} for step and continue operations (note that this
393eab54 39718is deprecated, supporting the @samp{vCont} command is a better
697aa1b7 39719option), and @samp{g} for other operations. The thread designator
393eab54
PA
39720@var{thread-id} has the format and interpretation described in
39721@ref{thread-id syntax}.
ee2d5c50
AC
39722
39723Reply:
39724@table @samp
39725@item OK
39726for success
b8ff78ce 39727@item E @var{NN}
ee2d5c50
AC
39728for an error
39729@end table
c906108c 39730
8e04817f
AC
39731@c FIXME: JTC:
39732@c 'H': How restrictive (or permissive) is the thread model. If a
39733@c thread is selected and stopped, are other threads allowed
39734@c to continue to execute? As I mentioned above, I think the
39735@c semantics of each command when a thread is selected must be
39736@c described. For example:
39737@c
39738@c 'g': If the stub supports threads and a specific thread is
39739@c selected, returns the register block from that thread;
39740@c otherwise returns current registers.
39741@c
39742@c 'G' If the stub supports threads and a specific thread is
39743@c selected, sets the registers of the register block of
39744@c that thread; otherwise sets current registers.
c906108c 39745
b8ff78ce 39746@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 39747@anchor{cycle step packet}
b8ff78ce
JB
39748@cindex @samp{i} packet
39749Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
39750present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
39751step starting at that address.
c906108c 39752
b8ff78ce
JB
39753@item I
39754@cindex @samp{I} packet
39755Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
39756step packet}.
ee2d5c50 39757
b8ff78ce
JB
39758@item k
39759@cindex @samp{k} packet
39760Kill request.
c906108c 39761
36cb1214
HZ
39762The exact effect of this packet is not specified.
39763
39764For a bare-metal target, it may power cycle or reset the target
39765system. For that reason, the @samp{k} packet has no reply.
39766
39767For a single-process target, it may kill that process if possible.
39768
39769A multiple-process target may choose to kill just one process, or all
39770that are under @value{GDBN}'s control. For more precise control, use
39771the vKill packet (@pxref{vKill packet}).
39772
39773If the target system immediately closes the connection in response to
39774@samp{k}, @value{GDBN} does not consider the lack of packet
39775acknowledgment to be an error, and assumes the kill was successful.
39776
39777If connected using @kbd{target extended-remote}, and the target does
39778not close the connection in response to a kill request, @value{GDBN}
39779probes the target state as if a new connection was opened
39780(@pxref{? packet}).
c906108c 39781
b8ff78ce
JB
39782@item m @var{addr},@var{length}
39783@cindex @samp{m} packet
a86c90e6
SM
39784Read @var{length} addressable memory units starting at address @var{addr}
39785(@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
39786any particular boundary.
fb031cdf
JB
39787
39788The stub need not use any particular size or alignment when gathering
39789data from memory for the response; even if @var{addr} is word-aligned
39790and @var{length} is a multiple of the word size, the stub is free to
39791use byte accesses, or not. For this reason, this packet may not be
39792suitable for accessing memory-mapped I/O devices.
c43c5473
JB
39793@cindex alignment of remote memory accesses
39794@cindex size of remote memory accesses
39795@cindex memory, alignment and size of remote accesses
c906108c 39796
ee2d5c50
AC
39797Reply:
39798@table @samp
39799@item @var{XX@dots{}}
a86c90e6
SM
39800Memory contents; each byte is transmitted as a two-digit hexadecimal number.
39801The reply may contain fewer addressable memory units than requested if the
b8ff78ce
JB
39802server was able to read only part of the region of memory.
39803@item E @var{NN}
ee2d5c50
AC
39804@var{NN} is errno
39805@end table
39806
b8ff78ce
JB
39807@item M @var{addr},@var{length}:@var{XX@dots{}}
39808@cindex @samp{M} packet
a86c90e6
SM
39809Write @var{length} addressable memory units starting at address @var{addr}
39810(@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
39811byte is transmitted as a two-digit hexadecimal number.
ee2d5c50
AC
39812
39813Reply:
39814@table @samp
39815@item OK
39816for success
b8ff78ce 39817@item E @var{NN}
8e04817f
AC
39818for an error (this includes the case where only part of the data was
39819written).
ee2d5c50 39820@end table
c906108c 39821
b8ff78ce
JB
39822@item p @var{n}
39823@cindex @samp{p} packet
39824Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
39825@xref{read registers packet}, for a description of how the returned
39826register value is encoded.
ee2d5c50
AC
39827
39828Reply:
39829@table @samp
2e868123
AC
39830@item @var{XX@dots{}}
39831the register's value
b8ff78ce 39832@item E @var{NN}
2e868123 39833for an error
d57350ea 39834@item @w{}
2e868123 39835Indicating an unrecognized @var{query}.
ee2d5c50
AC
39836@end table
39837
b8ff78ce 39838@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 39839@anchor{write register packet}
b8ff78ce
JB
39840@cindex @samp{P} packet
39841Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 39842number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 39843digits for each byte in the register (target byte order).
c906108c 39844
ee2d5c50
AC
39845Reply:
39846@table @samp
39847@item OK
39848for success
b8ff78ce 39849@item E @var{NN}
ee2d5c50
AC
39850for an error
39851@end table
39852
5f3bebba
JB
39853@item q @var{name} @var{params}@dots{}
39854@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 39855@cindex @samp{q} packet
b8ff78ce 39856@cindex @samp{Q} packet
5f3bebba
JB
39857General query (@samp{q}) and set (@samp{Q}). These packets are
39858described fully in @ref{General Query Packets}.
c906108c 39859
b8ff78ce
JB
39860@item r
39861@cindex @samp{r} packet
8e04817f 39862Reset the entire system.
c906108c 39863
b8ff78ce 39864Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 39865
b8ff78ce
JB
39866@item R @var{XX}
39867@cindex @samp{R} packet
697aa1b7 39868Restart the program being debugged. The @var{XX}, while needed, is ignored.
2d717e4f 39869This packet is only available in extended mode (@pxref{extended mode}).
ee2d5c50 39870
8e04817f 39871The @samp{R} packet has no reply.
ee2d5c50 39872
4f553f88 39873@item s @r{[}@var{addr}@r{]}
b8ff78ce 39874@cindex @samp{s} packet
697aa1b7 39875Single step, resuming at @var{addr}. If
b8ff78ce 39876@var{addr} is omitted, resume at same address.
c906108c 39877
393eab54
PA
39878This packet is deprecated for multi-threading support. @xref{vCont
39879packet}.
39880
ee2d5c50
AC
39881Reply:
39882@xref{Stop Reply Packets}, for the reply specifications.
39883
4f553f88 39884@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 39885@anchor{step with signal packet}
b8ff78ce
JB
39886@cindex @samp{S} packet
39887Step with signal. This is analogous to the @samp{C} packet, but
39888requests a single-step, rather than a normal resumption of execution.
c906108c 39889
393eab54
PA
39890This packet is deprecated for multi-threading support. @xref{vCont
39891packet}.
39892
ee2d5c50
AC
39893Reply:
39894@xref{Stop Reply Packets}, for the reply specifications.
39895
b8ff78ce
JB
39896@item t @var{addr}:@var{PP},@var{MM}
39897@cindex @samp{t} packet
8e04817f 39898Search backwards starting at address @var{addr} for a match with pattern
697aa1b7
EZ
39899@var{PP} and mask @var{MM}, both of which are are 4 byte long.
39900There must be at least 3 digits in @var{addr}.
c906108c 39901
b90a069a 39902@item T @var{thread-id}
b8ff78ce 39903@cindex @samp{T} packet
b90a069a 39904Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
c906108c 39905
ee2d5c50
AC
39906Reply:
39907@table @samp
39908@item OK
39909thread is still alive
b8ff78ce 39910@item E @var{NN}
ee2d5c50
AC
39911thread is dead
39912@end table
39913
b8ff78ce
JB
39914@item v
39915Packets starting with @samp{v} are identified by a multi-letter name,
39916up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 39917
2d717e4f
DJ
39918@item vAttach;@var{pid}
39919@cindex @samp{vAttach} packet
8b23ecc4
SL
39920Attach to a new process with the specified process ID @var{pid}.
39921The process ID is a
39922hexadecimal integer identifying the process. In all-stop mode, all
39923threads in the attached process are stopped; in non-stop mode, it may be
39924attached without being stopped if that is supported by the target.
39925
39926@c In non-stop mode, on a successful vAttach, the stub should set the
39927@c current thread to a thread of the newly-attached process. After
39928@c attaching, GDB queries for the attached process's thread ID with qC.
39929@c Also note that, from a user perspective, whether or not the
39930@c target is stopped on attach in non-stop mode depends on whether you
39931@c use the foreground or background version of the attach command, not
39932@c on what vAttach does; GDB does the right thing with respect to either
39933@c stopping or restarting threads.
2d717e4f
DJ
39934
39935This packet is only available in extended mode (@pxref{extended mode}).
39936
39937Reply:
39938@table @samp
39939@item E @var{nn}
39940for an error
39941@item @r{Any stop packet}
8b23ecc4
SL
39942for success in all-stop mode (@pxref{Stop Reply Packets})
39943@item OK
39944for success in non-stop mode (@pxref{Remote Non-Stop})
2d717e4f
DJ
39945@end table
39946
b90a069a 39947@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
b8ff78ce 39948@cindex @samp{vCont} packet
393eab54 39949@anchor{vCont packet}
b8ff78ce 39950Resume the inferior, specifying different actions for each thread.
ca6eff59
PA
39951
39952For each inferior thread, the leftmost action with a matching
39953@var{thread-id} is applied. Threads that don't match any action
39954remain in their current state. Thread IDs are specified using the
39955syntax described in @ref{thread-id syntax}. If multiprocess
39956extensions (@pxref{multiprocess extensions}) are supported, actions
39957can be specified to match all threads in a process by using the
39958@samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
39402e6c
PA
39959@var{thread-id} matches all threads. Specifying no actions is an
39960error.
b90a069a
SL
39961
39962Currently supported actions are:
86d30acc 39963
b8ff78ce 39964@table @samp
86d30acc
DJ
39965@item c
39966Continue.
b8ff78ce 39967@item C @var{sig}
8b23ecc4 39968Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
39969@item s
39970Step.
b8ff78ce 39971@item S @var{sig}
8b23ecc4
SL
39972Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
39973@item t
39974Stop.
c1e36e3e
PA
39975@item r @var{start},@var{end}
39976Step once, and then keep stepping as long as the thread stops at
39977addresses between @var{start} (inclusive) and @var{end} (exclusive).
39978The remote stub reports a stop reply when either the thread goes out
39979of the range or is stopped due to an unrelated reason, such as hitting
39980a breakpoint. @xref{range stepping}.
39981
39982If the range is empty (@var{start} == @var{end}), then the action
39983becomes equivalent to the @samp{s} action. In other words,
39984single-step once, and report the stop (even if the stepped instruction
39985jumps to @var{start}).
39986
39987(A stop reply may be sent at any point even if the PC is still within
39988the stepping range; for example, it is valid to implement this packet
39989in a degenerate way as a single instruction step operation.)
39990
86d30acc
DJ
39991@end table
39992
8b23ecc4
SL
39993The optional argument @var{addr} normally associated with the
39994@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
b8ff78ce 39995not supported in @samp{vCont}.
86d30acc 39996
08a0efd0
PA
39997The @samp{t} action is only relevant in non-stop mode
39998(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
8b23ecc4
SL
39999A stop reply should be generated for any affected thread not already stopped.
40000When a thread is stopped by means of a @samp{t} action,
40001the corresponding stop reply should indicate that the thread has stopped with
40002signal @samp{0}, regardless of whether the target uses some other signal
40003as an implementation detail.
40004
ca6eff59
PA
40005The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
40006@samp{r} actions for threads that are already running. Conversely,
40007the server must ignore @samp{t} actions for threads that are already
40008stopped.
40009
40010@emph{Note:} In non-stop mode, a thread is considered running until
6b92c0d3 40011@value{GDBN} acknowledges an asynchronous stop notification for it with
ca6eff59
PA
40012the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
40013
4220b2f8 40014The stub must support @samp{vCont} if it reports support for
ca6eff59 40015multiprocess extensions (@pxref{multiprocess extensions}).
4220b2f8 40016
86d30acc
DJ
40017Reply:
40018@xref{Stop Reply Packets}, for the reply specifications.
40019
b8ff78ce
JB
40020@item vCont?
40021@cindex @samp{vCont?} packet
d3e8051b 40022Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
40023
40024Reply:
40025@table @samp
b8ff78ce
JB
40026@item vCont@r{[};@var{action}@dots{}@r{]}
40027The @samp{vCont} packet is supported. Each @var{action} is a supported
40028command in the @samp{vCont} packet.
d57350ea 40029@item @w{}
b8ff78ce 40030The @samp{vCont} packet is not supported.
86d30acc 40031@end table
ee2d5c50 40032
de979965
PA
40033@anchor{vCtrlC packet}
40034@item vCtrlC
40035@cindex @samp{vCtrlC} packet
40036Interrupt remote target as if a control-C was pressed on the remote
40037terminal. This is the equivalent to reacting to the @code{^C}
40038(@samp{\003}, the control-C character) character in all-stop mode
40039while the target is running, except this works in non-stop mode.
40040@xref{interrupting remote targets}, for more info on the all-stop
40041variant.
40042
40043Reply:
40044@table @samp
40045@item E @var{nn}
40046for an error
40047@item OK
40048for success
40049@end table
40050
a6b151f1
DJ
40051@item vFile:@var{operation}:@var{parameter}@dots{}
40052@cindex @samp{vFile} packet
40053Perform a file operation on the target system. For details,
40054see @ref{Host I/O Packets}.
40055
68437a39
DJ
40056@item vFlashErase:@var{addr},@var{length}
40057@cindex @samp{vFlashErase} packet
40058Direct the stub to erase @var{length} bytes of flash starting at
40059@var{addr}. The region may enclose any number of flash blocks, but
40060its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
40061flash block size appearing in the memory map (@pxref{Memory Map
40062Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
40063together, and sends a @samp{vFlashDone} request after each group; the
40064stub is allowed to delay erase operation until the @samp{vFlashDone}
40065packet is received.
40066
40067Reply:
40068@table @samp
40069@item OK
40070for success
40071@item E @var{NN}
40072for an error
40073@end table
40074
40075@item vFlashWrite:@var{addr}:@var{XX@dots{}}
40076@cindex @samp{vFlashWrite} packet
40077Direct the stub to write data to flash address @var{addr}. The data
40078is passed in binary form using the same encoding as for the @samp{X}
40079packet (@pxref{Binary Data}). The memory ranges specified by
40080@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
40081not overlap, and must appear in order of increasing addresses
40082(although @samp{vFlashErase} packets for higher addresses may already
40083have been received; the ordering is guaranteed only between
40084@samp{vFlashWrite} packets). If a packet writes to an address that was
40085neither erased by a preceding @samp{vFlashErase} packet nor by some other
40086target-specific method, the results are unpredictable.
40087
40088
40089Reply:
40090@table @samp
40091@item OK
40092for success
40093@item E.memtype
40094for vFlashWrite addressing non-flash memory
40095@item E @var{NN}
40096for an error
40097@end table
40098
40099@item vFlashDone
40100@cindex @samp{vFlashDone} packet
40101Indicate to the stub that flash programming operation is finished.
40102The stub is permitted to delay or batch the effects of a group of
40103@samp{vFlashErase} and @samp{vFlashWrite} packets until a
40104@samp{vFlashDone} packet is received. The contents of the affected
40105regions of flash memory are unpredictable until the @samp{vFlashDone}
40106request is completed.
40107
b90a069a
SL
40108@item vKill;@var{pid}
40109@cindex @samp{vKill} packet
36cb1214 40110@anchor{vKill packet}
697aa1b7 40111Kill the process with the specified process ID @var{pid}, which is a
b90a069a
SL
40112hexadecimal integer identifying the process. This packet is used in
40113preference to @samp{k} when multiprocess protocol extensions are
40114supported; see @ref{multiprocess extensions}.
40115
40116Reply:
40117@table @samp
40118@item E @var{nn}
40119for an error
40120@item OK
40121for success
40122@end table
40123
176efed1
AB
40124@item vMustReplyEmpty
40125@cindex @samp{vMustReplyEmpty} packet
40126The correct reply to an unknown @samp{v} packet is to return the empty
40127string, however, some older versions of @command{gdbserver} would
40128incorrectly return @samp{OK} for unknown @samp{v} packets.
40129
40130The @samp{vMustReplyEmpty} is used as a feature test to check how
40131@command{gdbserver} handles unknown packets, it is important that this
40132packet be handled in the same way as other unknown @samp{v} packets.
40133If this packet is handled differently to other unknown @samp{v}
6b92c0d3 40134packets then it is possible that @value{GDBN} may run into problems in
176efed1
AB
40135other areas, specifically around use of @samp{vFile:setfs:}.
40136
2d717e4f
DJ
40137@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
40138@cindex @samp{vRun} packet
40139Run the program @var{filename}, passing it each @var{argument} on its
40140command line. The file and arguments are hex-encoded strings. If
40141@var{filename} is an empty string, the stub may use a default program
40142(e.g.@: the last program run). The program is created in the stopped
9b562ab8 40143state.
2d717e4f 40144
8b23ecc4
SL
40145@c FIXME: What about non-stop mode?
40146
2d717e4f
DJ
40147This packet is only available in extended mode (@pxref{extended mode}).
40148
40149Reply:
40150@table @samp
40151@item E @var{nn}
40152for an error
40153@item @r{Any stop packet}
40154for success (@pxref{Stop Reply Packets})
40155@end table
40156
8b23ecc4 40157@item vStopped
8b23ecc4 40158@cindex @samp{vStopped} packet
8dbe8ece 40159@xref{Notification Packets}.
8b23ecc4 40160
b8ff78ce 40161@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 40162@anchor{X packet}
b8ff78ce
JB
40163@cindex @samp{X} packet
40164Write data to memory, where the data is transmitted in binary.
a86c90e6
SM
40165Memory is specified by its address @var{addr} and number of addressable memory
40166units @var{length} (@pxref{addressable memory unit});
0876f84a 40167@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 40168
ee2d5c50
AC
40169Reply:
40170@table @samp
40171@item OK
40172for success
b8ff78ce 40173@item E @var{NN}
ee2d5c50
AC
40174for an error
40175@end table
40176
a1dcb23a
DJ
40177@item z @var{type},@var{addr},@var{kind}
40178@itemx Z @var{type},@var{addr},@var{kind}
2f870471 40179@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
40180@cindex @samp{z} packet
40181@cindex @samp{Z} packets
40182Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
a1dcb23a 40183watchpoint starting at address @var{address} of kind @var{kind}.
ee2d5c50 40184
2f870471
AC
40185Each breakpoint and watchpoint packet @var{type} is documented
40186separately.
40187
512217c7
AC
40188@emph{Implementation notes: A remote target shall return an empty string
40189for an unrecognized breakpoint or watchpoint packet @var{type}. A
40190remote target shall support either both or neither of a given
b8ff78ce 40191@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
40192avoid potential problems with duplicate packets, the operations should
40193be implemented in an idempotent way.}
40194
a1dcb23a 40195@item z0,@var{addr},@var{kind}
d3ce09f5 40196@itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
40197@cindex @samp{z0} packet
40198@cindex @samp{Z0} packet
4435e1cc 40199Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
a1dcb23a 40200@var{addr} of type @var{kind}.
2f870471 40201
4435e1cc 40202A software breakpoint is implemented by replacing the instruction at
2f870471 40203@var{addr} with a software breakpoint or trap instruction. The
4435e1cc
TT
40204@var{kind} is target-specific and typically indicates the size of the
40205breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
40206@sc{mips} can insert either a 2 or 4 byte breakpoint. Some
40207architectures have additional meanings for @var{kind}
40208(@pxref{Architecture-Specific Protocol Details}); if no
40209architecture-specific value is being used, it should be @samp{0}.
40210@var{kind} is hex-encoded. @var{cond_list} is an optional list of
40211conditional expressions in bytecode form that should be evaluated on
40212the target's side. These are the conditions that should be taken into
40213consideration when deciding if the breakpoint trigger should be
40214reported back to @value{GDBN}.
83364271 40215
f7e6eed5 40216See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
4435e1cc 40217for how to best report a software breakpoint event to @value{GDBN}.
f7e6eed5 40218
83364271
LM
40219The @var{cond_list} parameter is comprised of a series of expressions,
40220concatenated without separators. Each expression has the following form:
40221
40222@table @samp
40223
40224@item X @var{len},@var{expr}
40225@var{len} is the length of the bytecode expression and @var{expr} is the
40226actual conditional expression in bytecode form.
40227
40228@end table
40229
d3ce09f5
SS
40230The optional @var{cmd_list} parameter introduces commands that may be
40231run on the target, rather than being reported back to @value{GDBN}.
40232The parameter starts with a numeric flag @var{persist}; if the flag is
40233nonzero, then the breakpoint may remain active and the commands
40234continue to be run even when @value{GDBN} disconnects from the target.
40235Following this flag is a series of expressions concatenated with no
40236separators. Each expression has the following form:
40237
40238@table @samp
40239
40240@item X @var{len},@var{expr}
40241@var{len} is the length of the bytecode expression and @var{expr} is the
0968fbae 40242actual commands expression in bytecode form.
d3ce09f5
SS
40243
40244@end table
40245
2f870471 40246@emph{Implementation note: It is possible for a target to copy or move
4435e1cc 40247code that contains software breakpoints (e.g., when implementing
2f870471
AC
40248overlays). The behavior of this packet, in the presence of such a
40249target, is not defined.}
c906108c 40250
ee2d5c50
AC
40251Reply:
40252@table @samp
2f870471
AC
40253@item OK
40254success
d57350ea 40255@item @w{}
2f870471 40256not supported
b8ff78ce 40257@item E @var{NN}
ee2d5c50 40258for an error
2f870471
AC
40259@end table
40260
a1dcb23a 40261@item z1,@var{addr},@var{kind}
4435e1cc 40262@itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
40263@cindex @samp{z1} packet
40264@cindex @samp{Z1} packet
40265Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
a1dcb23a 40266address @var{addr}.
2f870471
AC
40267
40268A hardware breakpoint is implemented using a mechanism that is not
4435e1cc
TT
40269dependent on being able to modify the target's memory. The
40270@var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
40271same meaning as in @samp{Z0} packets.
2f870471
AC
40272
40273@emph{Implementation note: A hardware breakpoint is not affected by code
40274movement.}
40275
40276Reply:
40277@table @samp
ee2d5c50 40278@item OK
2f870471 40279success
d57350ea 40280@item @w{}
2f870471 40281not supported
b8ff78ce 40282@item E @var{NN}
2f870471
AC
40283for an error
40284@end table
40285
a1dcb23a
DJ
40286@item z2,@var{addr},@var{kind}
40287@itemx Z2,@var{addr},@var{kind}
b8ff78ce
JB
40288@cindex @samp{z2} packet
40289@cindex @samp{Z2} packet
a1dcb23a 40290Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
697aa1b7 40291The number of bytes to watch is specified by @var{kind}.
2f870471
AC
40292
40293Reply:
40294@table @samp
40295@item OK
40296success
d57350ea 40297@item @w{}
2f870471 40298not supported
b8ff78ce 40299@item E @var{NN}
2f870471
AC
40300for an error
40301@end table
40302
a1dcb23a
DJ
40303@item z3,@var{addr},@var{kind}
40304@itemx Z3,@var{addr},@var{kind}
b8ff78ce
JB
40305@cindex @samp{z3} packet
40306@cindex @samp{Z3} packet
a1dcb23a 40307Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
697aa1b7 40308The number of bytes to watch is specified by @var{kind}.
2f870471
AC
40309
40310Reply:
40311@table @samp
40312@item OK
40313success
d57350ea 40314@item @w{}
2f870471 40315not supported
b8ff78ce 40316@item E @var{NN}
2f870471
AC
40317for an error
40318@end table
40319
a1dcb23a
DJ
40320@item z4,@var{addr},@var{kind}
40321@itemx Z4,@var{addr},@var{kind}
b8ff78ce
JB
40322@cindex @samp{z4} packet
40323@cindex @samp{Z4} packet
a1dcb23a 40324Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
697aa1b7 40325The number of bytes to watch is specified by @var{kind}.
2f870471
AC
40326
40327Reply:
40328@table @samp
40329@item OK
40330success
d57350ea 40331@item @w{}
2f870471 40332not supported
b8ff78ce 40333@item E @var{NN}
2f870471 40334for an error
ee2d5c50
AC
40335@end table
40336
40337@end table
c906108c 40338
ee2d5c50
AC
40339@node Stop Reply Packets
40340@section Stop Reply Packets
40341@cindex stop reply packets
c906108c 40342
8b23ecc4
SL
40343The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
40344@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
40345receive any of the below as a reply. Except for @samp{?}
40346and @samp{vStopped}, that reply is only returned
b8ff78ce 40347when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
40348number} is defined by the header @file{include/gdb/signals.h} in the
40349@value{GDBN} source code.
c906108c 40350
4435e1cc
TT
40351In non-stop mode, the server will simply reply @samp{OK} to commands
40352such as @samp{vCont}; any stop will be the subject of a future
40353notification. @xref{Remote Non-Stop}.
40354
b8ff78ce
JB
40355As in the description of request packets, we include spaces in the
40356reply templates for clarity; these are not part of the reply packet's
40357syntax. No @value{GDBN} stop reply packet uses spaces to separate its
40358components.
c906108c 40359
b8ff78ce 40360@table @samp
ee2d5c50 40361
b8ff78ce 40362@item S @var{AA}
599b237a 40363The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
40364number). This is equivalent to a @samp{T} response with no
40365@var{n}:@var{r} pairs.
c906108c 40366
b8ff78ce
JB
40367@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
40368@cindex @samp{T} packet reply
599b237a 40369The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
40370number). This is equivalent to an @samp{S} response, except that the
40371@samp{@var{n}:@var{r}} pairs can carry values of important registers
40372and other information directly in the stop reply packet, reducing
40373round-trip latency. Single-step and breakpoint traps are reported
40374this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
40375
40376@itemize @bullet
b8ff78ce 40377@item
599b237a 40378If @var{n} is a hexadecimal number, it is a register number, and the
697aa1b7 40379corresponding @var{r} gives that register's value. The data @var{r} is a
b8ff78ce
JB
40380series of bytes in target byte order, with each byte given by a
40381two-digit hex number.
cfa9d6d9 40382
b8ff78ce 40383@item
b90a069a
SL
40384If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
40385the stopped thread, as specified in @ref{thread-id syntax}.
cfa9d6d9 40386
dc146f7c
VP
40387@item
40388If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
40389the core on which the stop event was detected.
40390
b8ff78ce 40391@item
cfa9d6d9
DJ
40392If @var{n} is a recognized @dfn{stop reason}, it describes a more
40393specific event that stopped the target. The currently defined stop
697aa1b7 40394reasons are listed below. The @var{aa} should be @samp{05}, the trap
cfa9d6d9
DJ
40395signal. At most one stop reason should be present.
40396
b8ff78ce
JB
40397@item
40398Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
40399and go on to the next; this allows us to extend the protocol in the
40400future.
cfa9d6d9
DJ
40401@end itemize
40402
40403The currently defined stop reasons are:
40404
40405@table @samp
40406@item watch
40407@itemx rwatch
40408@itemx awatch
40409The packet indicates a watchpoint hit, and @var{r} is the data address, in
40410hex.
40411
82075af2
JS
40412@item syscall_entry
40413@itemx syscall_return
40414The packet indicates a syscall entry or return, and @var{r} is the
40415syscall number, in hex.
40416
cfa9d6d9
DJ
40417@cindex shared library events, remote reply
40418@item library
40419The packet indicates that the loaded libraries have changed.
40420@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
697aa1b7 40421list of loaded libraries. The @var{r} part is ignored.
bacec72f
MS
40422
40423@cindex replay log events, remote reply
40424@item replaylog
40425The packet indicates that the target cannot continue replaying
40426logged execution events, because it has reached the end (or the
40427beginning when executing backward) of the log. The value of @var{r}
40428will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
40429for more information.
f7e6eed5
PA
40430
40431@item swbreak
40432@anchor{swbreak stop reason}
4435e1cc 40433The packet indicates a software breakpoint instruction was executed,
f7e6eed5
PA
40434irrespective of whether it was @value{GDBN} that planted the
40435breakpoint or the breakpoint is hardcoded in the program. The @var{r}
40436part must be left empty.
40437
40438On some architectures, such as x86, at the architecture level, when a
40439breakpoint instruction executes the program counter points at the
40440breakpoint address plus an offset. On such targets, the stub is
40441responsible for adjusting the PC to point back at the breakpoint
40442address.
40443
40444This packet should not be sent by default; older @value{GDBN} versions
40445did not support it. @value{GDBN} requests it, by supplying an
40446appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40447remote stub must also supply the appropriate @samp{qSupported} feature
40448indicating support.
40449
40450This packet is required for correct non-stop mode operation.
40451
40452@item hwbreak
40453The packet indicates the target stopped for a hardware breakpoint.
40454The @var{r} part must be left empty.
40455
40456The same remarks about @samp{qSupported} and non-stop mode above
40457apply.
0d71eef5
DB
40458
40459@cindex fork events, remote reply
40460@item fork
40461The packet indicates that @code{fork} was called, and @var{r}
40462is the thread ID of the new child process. Refer to
40463@ref{thread-id syntax} for the format of the @var{thread-id}
40464field. This packet is only applicable to targets that support
40465fork events.
40466
40467This packet should not be sent by default; older @value{GDBN} versions
40468did not support it. @value{GDBN} requests it, by supplying an
40469appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40470remote stub must also supply the appropriate @samp{qSupported} feature
40471indicating support.
40472
40473@cindex vfork events, remote reply
40474@item vfork
40475The packet indicates that @code{vfork} was called, and @var{r}
40476is the thread ID of the new child process. Refer to
40477@ref{thread-id syntax} for the format of the @var{thread-id}
40478field. This packet is only applicable to targets that support
40479vfork events.
40480
40481This packet should not be sent by default; older @value{GDBN} versions
40482did not support it. @value{GDBN} requests it, by supplying an
40483appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40484remote stub must also supply the appropriate @samp{qSupported} feature
40485indicating support.
40486
40487@cindex vforkdone events, remote reply
40488@item vforkdone
e68fa6f0
PA
40489The packet indicates that a child process created by a vfork
40490has either called @code{exec} or terminated, so that the
40491address spaces of the parent and child process are no longer
40492shared. The @var{r} part is ignored. This packet is only
40493applicable to targets that support vforkdone events.
0d71eef5
DB
40494
40495This packet should not be sent by default; older @value{GDBN} versions
40496did not support it. @value{GDBN} requests it, by supplying an
40497appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40498remote stub must also supply the appropriate @samp{qSupported} feature
40499indicating support.
40500
b459a59b
DB
40501@cindex exec events, remote reply
40502@item exec
40503The packet indicates that @code{execve} was called, and @var{r}
40504is the absolute pathname of the file that was executed, in hex.
40505This packet is only applicable to targets that support exec events.
40506
40507This packet should not be sent by default; older @value{GDBN} versions
40508did not support it. @value{GDBN} requests it, by supplying an
40509appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40510remote stub must also supply the appropriate @samp{qSupported} feature
40511indicating support.
40512
65706a29
PA
40513@cindex thread create event, remote reply
40514@anchor{thread create event}
40515@item create
40516The packet indicates that the thread was just created. The new thread
40517is stopped until @value{GDBN} sets it running with a resumption packet
40518(@pxref{vCont packet}). This packet should not be sent by default;
40519@value{GDBN} requests it with the @ref{QThreadEvents} packet. See
4435e1cc
TT
40520also the @samp{w} (@pxref{thread exit event}) remote reply below. The
40521@var{r} part is ignored.
65706a29 40522
cfa9d6d9 40523@end table
ee2d5c50 40524
b8ff78ce 40525@item W @var{AA}
b90a069a 40526@itemx W @var{AA} ; process:@var{pid}
8e04817f 40527The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
40528applicable to certain targets.
40529
4435e1cc
TT
40530The second form of the response, including the process ID of the
40531exited process, can be used only when @value{GDBN} has reported
40532support for multiprocess protocol extensions; see @ref{multiprocess
40533extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40534hex strings.
b90a069a 40535
b8ff78ce 40536@item X @var{AA}
b90a069a 40537@itemx X @var{AA} ; process:@var{pid}
8e04817f 40538The process terminated with signal @var{AA}.
c906108c 40539
b90a069a
SL
40540The second form of the response, including the process ID of the
40541terminated process, can be used only when @value{GDBN} has reported
40542support for multiprocess protocol extensions; see @ref{multiprocess
4435e1cc
TT
40543extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40544hex strings.
b90a069a 40545
65706a29
PA
40546@anchor{thread exit event}
40547@cindex thread exit event, remote reply
40548@item w @var{AA} ; @var{tid}
40549
40550The thread exited, and @var{AA} is the exit status. This response
40551should not be sent by default; @value{GDBN} requests it with the
40552@ref{QThreadEvents} packet. See also @ref{thread create event} above.
4435e1cc 40553@var{AA} is formatted as a big-endian hex string.
65706a29 40554
f2faf941
PA
40555@item N
40556There are no resumed threads left in the target. In other words, even
40557though the process is alive, the last resumed thread has exited. For
40558example, say the target process has two threads: thread 1 and thread
405592. The client leaves thread 1 stopped, and resumes thread 2, which
40560subsequently exits. At this point, even though the process is still
40561alive, and thus no @samp{W} stop reply is sent, no thread is actually
40562executing either. The @samp{N} stop reply thus informs the client
40563that it can stop waiting for stop replies. This packet should not be
40564sent by default; older @value{GDBN} versions did not support it.
40565@value{GDBN} requests it, by supplying an appropriate
40566@samp{qSupported} feature (@pxref{qSupported}). The remote stub must
40567also supply the appropriate @samp{qSupported} feature indicating
40568support.
40569
b8ff78ce
JB
40570@item O @var{XX}@dots{}
40571@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
40572written as the program's console output. This can happen at any time
40573while the program is running and the debugger should continue to wait
8b23ecc4 40574for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
0ce1b118 40575
b8ff78ce 40576@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
40577@var{call-id} is the identifier which says which host system call should
40578be called. This is just the name of the function. Translation into the
40579correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 40580@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
40581system calls.
40582
b8ff78ce
JB
40583@samp{@var{parameter}@dots{}} is a list of parameters as defined for
40584this very system call.
0ce1b118 40585
b8ff78ce
JB
40586The target replies with this packet when it expects @value{GDBN} to
40587call a host system call on behalf of the target. @value{GDBN} replies
40588with an appropriate @samp{F} packet and keeps up waiting for the next
40589reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
40590or @samp{s} action is expected to be continued. @xref{File-I/O Remote
40591Protocol Extension}, for more details.
0ce1b118 40592
ee2d5c50
AC
40593@end table
40594
40595@node General Query Packets
40596@section General Query Packets
9c16f35a 40597@cindex remote query requests
c906108c 40598
5f3bebba
JB
40599Packets starting with @samp{q} are @dfn{general query packets};
40600packets starting with @samp{Q} are @dfn{general set packets}. General
40601query and set packets are a semi-unified form for retrieving and
40602sending information to and from the stub.
40603
40604The initial letter of a query or set packet is followed by a name
40605indicating what sort of thing the packet applies to. For example,
40606@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
40607definitions with the stub. These packet names follow some
40608conventions:
40609
40610@itemize @bullet
40611@item
40612The name must not contain commas, colons or semicolons.
40613@item
40614Most @value{GDBN} query and set packets have a leading upper case
40615letter.
40616@item
40617The names of custom vendor packets should use a company prefix, in
40618lower case, followed by a period. For example, packets designed at
40619the Acme Corporation might begin with @samp{qacme.foo} (for querying
40620foos) or @samp{Qacme.bar} (for setting bars).
40621@end itemize
40622
aa56d27a
JB
40623The name of a query or set packet should be separated from any
40624parameters by a @samp{:}; the parameters themselves should be
40625separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
40626full packet name, and check for a separator or the end of the packet,
40627in case two packet names share a common prefix. New packets should not begin
40628with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
40629packets predate these conventions, and have arguments without any terminator
40630for the packet name; we suspect they are in widespread use in places that
40631are difficult to upgrade. The @samp{qC} packet has no arguments, but some
40632existing stubs (e.g.@: RedBoot) are known to not check for the end of the
40633packet.}.
c906108c 40634
b8ff78ce
JB
40635Like the descriptions of the other packets, each description here
40636has a template showing the packet's overall syntax, followed by an
40637explanation of the packet's meaning. We include spaces in some of the
40638templates for clarity; these are not part of the packet's syntax. No
40639@value{GDBN} packet uses spaces to separate its components.
40640
5f3bebba
JB
40641Here are the currently defined query and set packets:
40642
b8ff78ce 40643@table @samp
c906108c 40644
d1feda86 40645@item QAgent:1
af4238e5 40646@itemx QAgent:0
d1feda86
YQ
40647Turn on or off the agent as a helper to perform some debugging operations
40648delegated from @value{GDBN} (@pxref{Control Agent}).
40649
d914c394
SS
40650@item QAllow:@var{op}:@var{val}@dots{}
40651@cindex @samp{QAllow} packet
40652Specify which operations @value{GDBN} expects to request of the
40653target, as a semicolon-separated list of operation name and value
40654pairs. Possible values for @var{op} include @samp{WriteReg},
40655@samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
40656@samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
40657indicating that @value{GDBN} will not request the operation, or 1,
40658indicating that it may. (The target can then use this to set up its
40659own internals optimally, for instance if the debugger never expects to
40660insert breakpoints, it may not need to install its own trap handler.)
40661
b8ff78ce 40662@item qC
9c16f35a 40663@cindex current thread, remote request
b8ff78ce 40664@cindex @samp{qC} packet
b90a069a 40665Return the current thread ID.
ee2d5c50
AC
40666
40667Reply:
40668@table @samp
b90a069a
SL
40669@item QC @var{thread-id}
40670Where @var{thread-id} is a thread ID as documented in
40671@ref{thread-id syntax}.
b8ff78ce 40672@item @r{(anything else)}
b90a069a 40673Any other reply implies the old thread ID.
ee2d5c50
AC
40674@end table
40675
b8ff78ce 40676@item qCRC:@var{addr},@var{length}
ff2587ec 40677@cindex CRC of memory block, remote request
b8ff78ce 40678@cindex @samp{qCRC} packet
936d2992 40679@anchor{qCRC packet}
99e008fe
EZ
40680Compute the CRC checksum of a block of memory using CRC-32 defined in
40681IEEE 802.3. The CRC is computed byte at a time, taking the most
40682significant bit of each byte first. The initial pattern code
40683@code{0xffffffff} is used to ensure leading zeros affect the CRC.
40684
40685@emph{Note:} This is the same CRC used in validating separate debug
40686files (@pxref{Separate Debug Files, , Debugging Information in Separate
40687Files}). However the algorithm is slightly different. When validating
40688separate debug files, the CRC is computed taking the @emph{least}
40689significant bit of each byte first, and the final result is inverted to
40690detect trailing zeros.
40691
ff2587ec
WZ
40692Reply:
40693@table @samp
b8ff78ce 40694@item E @var{NN}
ff2587ec 40695An error (such as memory fault)
b8ff78ce
JB
40696@item C @var{crc32}
40697The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
40698@end table
40699
03583c20
UW
40700@item QDisableRandomization:@var{value}
40701@cindex disable address space randomization, remote request
40702@cindex @samp{QDisableRandomization} packet
40703Some target operating systems will randomize the virtual address space
40704of the inferior process as a security feature, but provide a feature
40705to disable such randomization, e.g.@: to allow for a more deterministic
40706debugging experience. On such systems, this packet with a @var{value}
40707of 1 directs the target to disable address space randomization for
40708processes subsequently started via @samp{vRun} packets, while a packet
40709with a @var{value} of 0 tells the target to enable address space
40710randomization.
40711
40712This packet is only available in extended mode (@pxref{extended mode}).
40713
40714Reply:
40715@table @samp
40716@item OK
40717The request succeeded.
40718
40719@item E @var{nn}
697aa1b7 40720An error occurred. The error number @var{nn} is given as hex digits.
03583c20 40721
d57350ea 40722@item @w{}
03583c20
UW
40723An empty reply indicates that @samp{QDisableRandomization} is not supported
40724by the stub.
40725@end table
40726
40727This packet is not probed by default; the remote stub must request it,
40728by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40729This should only be done on targets that actually support disabling
40730address space randomization.
40731
aefd8b33
SDJ
40732@item QStartupWithShell:@var{value}
40733@cindex startup with shell, remote request
40734@cindex @samp{QStartupWithShell} packet
40735On UNIX-like targets, it is possible to start the inferior using a
40736shell program. This is the default behavior on both @value{GDBN} and
40737@command{gdbserver} (@pxref{set startup-with-shell}). This packet is
40738used to inform @command{gdbserver} whether it should start the
40739inferior using a shell or not.
40740
40741If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
40742to start the inferior. If @var{value} is @samp{1},
40743@command{gdbserver} will use a shell to start the inferior. All other
40744values are considered an error.
40745
40746This packet is only available in extended mode (@pxref{extended
40747mode}).
40748
40749Reply:
40750@table @samp
40751@item OK
40752The request succeeded.
40753
40754@item E @var{nn}
40755An error occurred. The error number @var{nn} is given as hex digits.
40756@end table
40757
40758This packet is not probed by default; the remote stub must request it,
40759by supplying an appropriate @samp{qSupported} response
40760(@pxref{qSupported}). This should only be done on targets that
40761actually support starting the inferior using a shell.
40762
40763Use of this packet is controlled by the @code{set startup-with-shell}
40764command; @pxref{set startup-with-shell}.
40765
0a2dde4a
SDJ
40766@item QEnvironmentHexEncoded:@var{hex-value}
40767@anchor{QEnvironmentHexEncoded}
40768@cindex set environment variable, remote request
40769@cindex @samp{QEnvironmentHexEncoded} packet
40770On UNIX-like targets, it is possible to set environment variables that
40771will be passed to the inferior during the startup process. This
40772packet is used to inform @command{gdbserver} of an environment
40773variable that has been defined by the user on @value{GDBN} (@pxref{set
40774environment}).
40775
40776The packet is composed by @var{hex-value}, an hex encoded
40777representation of the @var{name=value} format representing an
40778environment variable. The name of the environment variable is
40779represented by @var{name}, and the value to be assigned to the
40780environment variable is represented by @var{value}. If the variable
40781has no value (i.e., the value is @code{null}), then @var{value} will
40782not be present.
40783
40784This packet is only available in extended mode (@pxref{extended
40785mode}).
40786
40787Reply:
40788@table @samp
40789@item OK
40790The request succeeded.
40791@end table
40792
40793This packet is not probed by default; the remote stub must request it,
40794by supplying an appropriate @samp{qSupported} response
40795(@pxref{qSupported}). This should only be done on targets that
40796actually support passing environment variables to the starting
40797inferior.
40798
40799This packet is related to the @code{set environment} command;
40800@pxref{set environment}.
40801
40802@item QEnvironmentUnset:@var{hex-value}
40803@anchor{QEnvironmentUnset}
40804@cindex unset environment variable, remote request
40805@cindex @samp{QEnvironmentUnset} packet
40806On UNIX-like targets, it is possible to unset environment variables
40807before starting the inferior in the remote target. This packet is
40808used to inform @command{gdbserver} of an environment variable that has
40809been unset by the user on @value{GDBN} (@pxref{unset environment}).
40810
40811The packet is composed by @var{hex-value}, an hex encoded
40812representation of the name of the environment variable to be unset.
40813
40814This packet is only available in extended mode (@pxref{extended
40815mode}).
40816
40817Reply:
40818@table @samp
40819@item OK
40820The request succeeded.
40821@end table
40822
40823This packet is not probed by default; the remote stub must request it,
40824by supplying an appropriate @samp{qSupported} response
40825(@pxref{qSupported}). This should only be done on targets that
40826actually support passing environment variables to the starting
40827inferior.
40828
40829This packet is related to the @code{unset environment} command;
40830@pxref{unset environment}.
40831
40832@item QEnvironmentReset
40833@anchor{QEnvironmentReset}
40834@cindex reset environment, remote request
40835@cindex @samp{QEnvironmentReset} packet
40836On UNIX-like targets, this packet is used to reset the state of
40837environment variables in the remote target before starting the
40838inferior. In this context, reset means unsetting all environment
40839variables that were previously set by the user (i.e., were not
40840initially present in the environment). It is sent to
40841@command{gdbserver} before the @samp{QEnvironmentHexEncoded}
40842(@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
40843(@pxref{QEnvironmentUnset}) packets.
40844
40845This packet is only available in extended mode (@pxref{extended
40846mode}).
40847
40848Reply:
40849@table @samp
40850@item OK
40851The request succeeded.
40852@end table
40853
40854This packet is not probed by default; the remote stub must request it,
40855by supplying an appropriate @samp{qSupported} response
40856(@pxref{qSupported}). This should only be done on targets that
40857actually support passing environment variables to the starting
40858inferior.
40859
bc3b087d
SDJ
40860@item QSetWorkingDir:@r{[}@var{directory}@r{]}
40861@anchor{QSetWorkingDir packet}
40862@cindex set working directory, remote request
40863@cindex @samp{QSetWorkingDir} packet
40864This packet is used to inform the remote server of the intended
40865current working directory for programs that are going to be executed.
40866
40867The packet is composed by @var{directory}, an hex encoded
40868representation of the directory that the remote inferior will use as
40869its current working directory. If @var{directory} is an empty string,
40870the remote server should reset the inferior's current working
40871directory to its original, empty value.
40872
40873This packet is only available in extended mode (@pxref{extended
40874mode}).
40875
40876Reply:
40877@table @samp
40878@item OK
40879The request succeeded.
40880@end table
40881
b8ff78ce
JB
40882@item qfThreadInfo
40883@itemx qsThreadInfo
9c16f35a 40884@cindex list active threads, remote request
b8ff78ce
JB
40885@cindex @samp{qfThreadInfo} packet
40886@cindex @samp{qsThreadInfo} packet
b90a069a 40887Obtain a list of all active thread IDs from the target (OS). Since there
8e04817f
AC
40888may be too many active threads to fit into one reply packet, this query
40889works iteratively: it may require more than one query/reply sequence to
40890obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
40891be the @samp{qfThreadInfo} query; subsequent queries in the
40892sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 40893
b8ff78ce 40894NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
40895
40896Reply:
40897@table @samp
b90a069a
SL
40898@item m @var{thread-id}
40899A single thread ID
40900@item m @var{thread-id},@var{thread-id}@dots{}
40901a comma-separated list of thread IDs
b8ff78ce
JB
40902@item l
40903(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
40904@end table
40905
40906In response to each query, the target will reply with a list of one or
b90a069a 40907more thread IDs, separated by commas.
e1aac25b 40908@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce 40909ids (using the @samp{qs} form of the query), until the target responds
501994c0 40910with @samp{l} (lower-case ell, for @dfn{last}).
b90a069a
SL
40911Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
40912fields.
c906108c 40913
8dfcab11
DT
40914@emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
40915initial connection with the remote target, and the very first thread ID
40916mentioned in the reply will be stopped by @value{GDBN} in a subsequent
40917message. Therefore, the stub should ensure that the first thread ID in
40918the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
40919
b8ff78ce 40920@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 40921@cindex get thread-local storage address, remote request
b8ff78ce 40922@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
40923Fetch the address associated with thread local storage specified
40924by @var{thread-id}, @var{offset}, and @var{lm}.
40925
b90a069a
SL
40926@var{thread-id} is the thread ID associated with the
40927thread for which to fetch the TLS address. @xref{thread-id syntax}.
ff2587ec
WZ
40928
40929@var{offset} is the (big endian, hex encoded) offset associated with the
40930thread local variable. (This offset is obtained from the debug
40931information associated with the variable.)
40932
db2e3e2e 40933@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
7a9dd1b2 40934load module associated with the thread local storage. For example,
ff2587ec
WZ
40935a @sc{gnu}/Linux system will pass the link map address of the shared
40936object associated with the thread local storage under consideration.
40937Other operating environments may choose to represent the load module
40938differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
40939
40940Reply:
b8ff78ce
JB
40941@table @samp
40942@item @var{XX}@dots{}
ff2587ec
WZ
40943Hex encoded (big endian) bytes representing the address of the thread
40944local storage requested.
40945
b8ff78ce 40946@item E @var{nn}
697aa1b7 40947An error occurred. The error number @var{nn} is given as hex digits.
ff2587ec 40948
d57350ea 40949@item @w{}
b8ff78ce 40950An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
40951@end table
40952
711e434b
PM
40953@item qGetTIBAddr:@var{thread-id}
40954@cindex get thread information block address
40955@cindex @samp{qGetTIBAddr} packet
40956Fetch address of the Windows OS specific Thread Information Block.
40957
40958@var{thread-id} is the thread ID associated with the thread.
40959
40960Reply:
40961@table @samp
40962@item @var{XX}@dots{}
40963Hex encoded (big endian) bytes representing the linear address of the
40964thread information block.
40965
40966@item E @var{nn}
40967An error occured. This means that either the thread was not found, or the
40968address could not be retrieved.
40969
d57350ea 40970@item @w{}
711e434b
PM
40971An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
40972@end table
40973
b8ff78ce 40974@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
40975Obtain thread information from RTOS. Where: @var{startflag} (one hex
40976digit) is one to indicate the first query and zero to indicate a
40977subsequent query; @var{threadcount} (two hex digits) is the maximum
40978number of threads the response packet can contain; and @var{nextthread}
40979(eight hex digits), for subsequent queries (@var{startflag} is zero), is
40980returned in the response as @var{argthread}.
ee2d5c50 40981
b8ff78ce 40982Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
40983
40984Reply:
40985@table @samp
b8ff78ce 40986@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
40987Where: @var{count} (two hex digits) is the number of threads being
40988returned; @var{done} (one hex digit) is zero to indicate more threads
40989and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 40990digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
697aa1b7
EZ
40991is a sequence of thread IDs, @var{threadid} (eight hex
40992digits), from the target. See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 40993@end table
c906108c 40994
b8ff78ce 40995@item qOffsets
9c16f35a 40996@cindex section offsets, remote request
b8ff78ce 40997@cindex @samp{qOffsets} packet
31d99776
DJ
40998Get section offsets that the target used when relocating the downloaded
40999image.
c906108c 41000
ee2d5c50
AC
41001Reply:
41002@table @samp
31d99776
DJ
41003@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
41004Relocate the @code{Text} section by @var{xxx} from its original address.
41005Relocate the @code{Data} section by @var{yyy} from its original address.
41006If the object file format provides segment information (e.g.@: @sc{elf}
41007@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
41008segments by the supplied offsets.
41009
41010@emph{Note: while a @code{Bss} offset may be included in the response,
41011@value{GDBN} ignores this and instead applies the @code{Data} offset
41012to the @code{Bss} section.}
41013
41014@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
41015Relocate the first segment of the object file, which conventionally
41016contains program code, to a starting address of @var{xxx}. If
41017@samp{DataSeg} is specified, relocate the second segment, which
41018conventionally contains modifiable data, to a starting address of
41019@var{yyy}. @value{GDBN} will report an error if the object file
41020does not contain segment information, or does not contain at least
41021as many segments as mentioned in the reply. Extra segments are
41022kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
41023@end table
41024
b90a069a 41025@item qP @var{mode} @var{thread-id}
9c16f35a 41026@cindex thread information, remote request
b8ff78ce 41027@cindex @samp{qP} packet
b90a069a
SL
41028Returns information on @var{thread-id}. Where: @var{mode} is a hex
41029encoded 32 bit mode; @var{thread-id} is a thread ID
41030(@pxref{thread-id syntax}).
ee2d5c50 41031
aa56d27a
JB
41032Don't use this packet; use the @samp{qThreadExtraInfo} query instead
41033(see below).
41034
b8ff78ce 41035Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 41036
8b23ecc4 41037@item QNonStop:1
687e43a4 41038@itemx QNonStop:0
8b23ecc4
SL
41039@cindex non-stop mode, remote request
41040@cindex @samp{QNonStop} packet
41041@anchor{QNonStop}
41042Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
41043@xref{Remote Non-Stop}, for more information.
41044
41045Reply:
41046@table @samp
41047@item OK
41048The request succeeded.
41049
41050@item E @var{nn}
697aa1b7 41051An error occurred. The error number @var{nn} is given as hex digits.
8b23ecc4 41052
d57350ea 41053@item @w{}
8b23ecc4
SL
41054An empty reply indicates that @samp{QNonStop} is not supported by
41055the stub.
41056@end table
41057
41058This packet is not probed by default; the remote stub must request it,
41059by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41060Use of this packet is controlled by the @code{set non-stop} command;
41061@pxref{Non-Stop Mode}.
41062
82075af2
JS
41063@item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
41064@itemx QCatchSyscalls:0
41065@cindex catch syscalls from inferior, remote request
41066@cindex @samp{QCatchSyscalls} packet
41067@anchor{QCatchSyscalls}
41068Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
41069catching syscalls from the inferior process.
41070
41071For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
41072in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
41073is listed, every system call should be reported.
41074
41075Note that if a syscall not in the list is reported, @value{GDBN} will
41076still filter the event according to its own list from all corresponding
41077@code{catch syscall} commands. However, it is more efficient to only
41078report the requested syscalls.
41079
41080Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
41081@samp{QCatchSyscalls:1} list is completely replaced by the new list.
41082
41083If the inferior process execs, the state of @samp{QCatchSyscalls} is
41084kept for the new process too. On targets where exec may affect syscall
41085numbers, for example with exec between 32 and 64-bit processes, the
41086client should send a new packet with the new syscall list.
41087
41088Reply:
41089@table @samp
41090@item OK
41091The request succeeded.
41092
41093@item E @var{nn}
41094An error occurred. @var{nn} are hex digits.
41095
41096@item @w{}
41097An empty reply indicates that @samp{QCatchSyscalls} is not supported by
41098the stub.
41099@end table
41100
41101Use of this packet is controlled by the @code{set remote catch-syscalls}
41102command (@pxref{Remote Configuration, set remote catch-syscalls}).
41103This packet is not probed by default; the remote stub must request it,
41104by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41105
89be2091
DJ
41106@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
41107@cindex pass signals to inferior, remote request
41108@cindex @samp{QPassSignals} packet
23181151 41109@anchor{QPassSignals}
89be2091
DJ
41110Each listed @var{signal} should be passed directly to the inferior process.
41111Signals are numbered identically to continue packets and stop replies
41112(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
41113strictly greater than the previous item. These signals do not need to stop
41114the inferior, or be reported to @value{GDBN}. All other signals should be
41115reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
41116combine; any earlier @samp{QPassSignals} list is completely replaced by the
41117new list. This packet improves performance when using @samp{handle
41118@var{signal} nostop noprint pass}.
41119
41120Reply:
41121@table @samp
41122@item OK
41123The request succeeded.
41124
41125@item E @var{nn}
697aa1b7 41126An error occurred. The error number @var{nn} is given as hex digits.
89be2091 41127
d57350ea 41128@item @w{}
89be2091
DJ
41129An empty reply indicates that @samp{QPassSignals} is not supported by
41130the stub.
41131@end table
41132
41133Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 41134command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
41135This packet is not probed by default; the remote stub must request it,
41136by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41137
9b224c5e
PA
41138@item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
41139@cindex signals the inferior may see, remote request
41140@cindex @samp{QProgramSignals} packet
41141@anchor{QProgramSignals}
41142Each listed @var{signal} may be delivered to the inferior process.
41143Others should be silently discarded.
41144
41145In some cases, the remote stub may need to decide whether to deliver a
41146signal to the program or not without @value{GDBN} involvement. One
41147example of that is while detaching --- the program's threads may have
41148stopped for signals that haven't yet had a chance of being reported to
41149@value{GDBN}, and so the remote stub can use the signal list specified
41150by this packet to know whether to deliver or ignore those pending
41151signals.
41152
41153This does not influence whether to deliver a signal as requested by a
41154resumption packet (@pxref{vCont packet}).
41155
41156Signals are numbered identically to continue packets and stop replies
41157(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
41158strictly greater than the previous item. Multiple
41159@samp{QProgramSignals} packets do not combine; any earlier
41160@samp{QProgramSignals} list is completely replaced by the new list.
41161
41162Reply:
41163@table @samp
41164@item OK
41165The request succeeded.
41166
41167@item E @var{nn}
697aa1b7 41168An error occurred. The error number @var{nn} is given as hex digits.
9b224c5e 41169
d57350ea 41170@item @w{}
9b224c5e
PA
41171An empty reply indicates that @samp{QProgramSignals} is not supported
41172by the stub.
41173@end table
41174
41175Use of this packet is controlled by the @code{set remote program-signals}
41176command (@pxref{Remote Configuration, set remote program-signals}).
41177This packet is not probed by default; the remote stub must request it,
41178by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41179
65706a29
PA
41180@anchor{QThreadEvents}
41181@item QThreadEvents:1
41182@itemx QThreadEvents:0
41183@cindex thread create/exit events, remote request
41184@cindex @samp{QThreadEvents} packet
41185
41186Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
41187reporting of thread create and exit events. @xref{thread create
41188event}, for the reply specifications. For example, this is used in
41189non-stop mode when @value{GDBN} stops a set of threads and
41190synchronously waits for the their corresponding stop replies. Without
41191exit events, if one of the threads exits, @value{GDBN} would hang
41192forever not knowing that it should no longer expect a stop for that
41193same thread. @value{GDBN} does not enable this feature unless the
41194stub reports that it supports it by including @samp{QThreadEvents+} in
41195its @samp{qSupported} reply.
41196
41197Reply:
41198@table @samp
41199@item OK
41200The request succeeded.
41201
41202@item E @var{nn}
41203An error occurred. The error number @var{nn} is given as hex digits.
41204
41205@item @w{}
41206An empty reply indicates that @samp{QThreadEvents} is not supported by
41207the stub.
41208@end table
41209
41210Use of this packet is controlled by the @code{set remote thread-events}
41211command (@pxref{Remote Configuration, set remote thread-events}).
41212
b8ff78ce 41213@item qRcmd,@var{command}
ff2587ec 41214@cindex execute remote command, remote request
b8ff78ce 41215@cindex @samp{qRcmd} packet
ff2587ec 41216@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
41217execution. Invalid commands should be reported using the output
41218string. Before the final result packet, the target may also respond
41219with a number of intermediate @samp{O@var{output}} console output
41220packets. @emph{Implementors should note that providing access to a
41221stubs's interpreter may have security implications}.
fa93a9d8 41222
ff2587ec
WZ
41223Reply:
41224@table @samp
41225@item OK
41226A command response with no output.
41227@item @var{OUTPUT}
41228A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 41229@item E @var{NN}
ff2587ec 41230Indicate a badly formed request.
d57350ea 41231@item @w{}
b8ff78ce 41232An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 41233@end table
fa93a9d8 41234
aa56d27a
JB
41235(Note that the @code{qRcmd} packet's name is separated from the
41236command by a @samp{,}, not a @samp{:}, contrary to the naming
41237conventions above. Please don't use this packet as a model for new
41238packets.)
41239
08388c79
DE
41240@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
41241@cindex searching memory, in remote debugging
5c4808ca 41242@ifnotinfo
08388c79 41243@cindex @samp{qSearch:memory} packet
5c4808ca
EZ
41244@end ifnotinfo
41245@cindex @samp{qSearch memory} packet
08388c79
DE
41246@anchor{qSearch memory}
41247Search @var{length} bytes at @var{address} for @var{search-pattern}.
697aa1b7
EZ
41248Both @var{address} and @var{length} are encoded in hex;
41249@var{search-pattern} is a sequence of bytes, also hex encoded.
08388c79
DE
41250
41251Reply:
41252@table @samp
41253@item 0
41254The pattern was not found.
41255@item 1,address
41256The pattern was found at @var{address}.
41257@item E @var{NN}
41258A badly formed request or an error was encountered while searching memory.
d57350ea 41259@item @w{}
08388c79
DE
41260An empty reply indicates that @samp{qSearch:memory} is not recognized.
41261@end table
41262
a6f3e723
SL
41263@item QStartNoAckMode
41264@cindex @samp{QStartNoAckMode} packet
41265@anchor{QStartNoAckMode}
41266Request that the remote stub disable the normal @samp{+}/@samp{-}
41267protocol acknowledgments (@pxref{Packet Acknowledgment}).
41268
41269Reply:
41270@table @samp
41271@item OK
41272The stub has switched to no-acknowledgment mode.
6b92c0d3 41273@value{GDBN} acknowledges this response,
a6f3e723
SL
41274but neither the stub nor @value{GDBN} shall send or expect further
41275@samp{+}/@samp{-} acknowledgments in the current connection.
d57350ea 41276@item @w{}
a6f3e723
SL
41277An empty reply indicates that the stub does not support no-acknowledgment mode.
41278@end table
41279
be2a5f71
DJ
41280@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
41281@cindex supported packets, remote query
41282@cindex features of the remote protocol
41283@cindex @samp{qSupported} packet
0876f84a 41284@anchor{qSupported}
be2a5f71
DJ
41285Tell the remote stub about features supported by @value{GDBN}, and
41286query the stub for features it supports. This packet allows
41287@value{GDBN} and the remote stub to take advantage of each others'
41288features. @samp{qSupported} also consolidates multiple feature probes
41289at startup, to improve @value{GDBN} performance---a single larger
41290packet performs better than multiple smaller probe packets on
41291high-latency links. Some features may enable behavior which must not
41292be on by default, e.g.@: because it would confuse older clients or
41293stubs. Other features may describe packets which could be
41294automatically probed for, but are not. These features must be
41295reported before @value{GDBN} will use them. This ``default
41296unsupported'' behavior is not appropriate for all packets, but it
41297helps to keep the initial connection time under control with new
41298versions of @value{GDBN} which support increasing numbers of packets.
41299
41300Reply:
41301@table @samp
41302@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
41303The stub supports or does not support each returned @var{stubfeature},
41304depending on the form of each @var{stubfeature} (see below for the
41305possible forms).
d57350ea 41306@item @w{}
be2a5f71
DJ
41307An empty reply indicates that @samp{qSupported} is not recognized,
41308or that no features needed to be reported to @value{GDBN}.
41309@end table
41310
41311The allowed forms for each feature (either a @var{gdbfeature} in the
41312@samp{qSupported} packet, or a @var{stubfeature} in the response)
41313are:
41314
41315@table @samp
41316@item @var{name}=@var{value}
41317The remote protocol feature @var{name} is supported, and associated
41318with the specified @var{value}. The format of @var{value} depends
41319on the feature, but it must not include a semicolon.
41320@item @var{name}+
41321The remote protocol feature @var{name} is supported, and does not
41322need an associated value.
41323@item @var{name}-
41324The remote protocol feature @var{name} is not supported.
41325@item @var{name}?
41326The remote protocol feature @var{name} may be supported, and
41327@value{GDBN} should auto-detect support in some other way when it is
41328needed. This form will not be used for @var{gdbfeature} notifications,
41329but may be used for @var{stubfeature} responses.
41330@end table
41331
41332Whenever the stub receives a @samp{qSupported} request, the
41333supplied set of @value{GDBN} features should override any previous
41334request. This allows @value{GDBN} to put the stub in a known
41335state, even if the stub had previously been communicating with
41336a different version of @value{GDBN}.
41337
b90a069a
SL
41338The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
41339are defined:
41340
41341@table @samp
41342@item multiprocess
41343This feature indicates whether @value{GDBN} supports multiprocess
41344extensions to the remote protocol. @value{GDBN} does not use such
41345extensions unless the stub also reports that it supports them by
41346including @samp{multiprocess+} in its @samp{qSupported} reply.
41347@xref{multiprocess extensions}, for details.
c8d5aac9
L
41348
41349@item xmlRegisters
41350This feature indicates that @value{GDBN} supports the XML target
41351description. If the stub sees @samp{xmlRegisters=} with target
41352specific strings separated by a comma, it will report register
41353description.
dde08ee1
PA
41354
41355@item qRelocInsn
41356This feature indicates whether @value{GDBN} supports the
41357@samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
41358instruction reply packet}).
f7e6eed5
PA
41359
41360@item swbreak
41361This feature indicates whether @value{GDBN} supports the swbreak stop
41362reason in stop replies. @xref{swbreak stop reason}, for details.
41363
41364@item hwbreak
41365This feature indicates whether @value{GDBN} supports the hwbreak stop
41366reason in stop replies. @xref{swbreak stop reason}, for details.
0d71eef5
DB
41367
41368@item fork-events
41369This feature indicates whether @value{GDBN} supports fork event
41370extensions to the remote protocol. @value{GDBN} does not use such
41371extensions unless the stub also reports that it supports them by
41372including @samp{fork-events+} in its @samp{qSupported} reply.
41373
41374@item vfork-events
41375This feature indicates whether @value{GDBN} supports vfork event
41376extensions to the remote protocol. @value{GDBN} does not use such
41377extensions unless the stub also reports that it supports them by
41378including @samp{vfork-events+} in its @samp{qSupported} reply.
b459a59b
DB
41379
41380@item exec-events
41381This feature indicates whether @value{GDBN} supports exec event
41382extensions to the remote protocol. @value{GDBN} does not use such
41383extensions unless the stub also reports that it supports them by
41384including @samp{exec-events+} in its @samp{qSupported} reply.
750ce8d1
YQ
41385
41386@item vContSupported
41387This feature indicates whether @value{GDBN} wants to know the
41388supported actions in the reply to @samp{vCont?} packet.
b90a069a
SL
41389@end table
41390
41391Stubs should ignore any unknown values for
be2a5f71
DJ
41392@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
41393packet supports receiving packets of unlimited length (earlier
b90a069a 41394versions of @value{GDBN} may reject overly long responses). Additional values
be2a5f71
DJ
41395for @var{gdbfeature} may be defined in the future to let the stub take
41396advantage of new features in @value{GDBN}, e.g.@: incompatible
b90a069a
SL
41397improvements in the remote protocol---the @samp{multiprocess} feature is
41398an example of such a feature. The stub's reply should be independent
be2a5f71
DJ
41399of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
41400describes all the features it supports, and then the stub replies with
41401all the features it supports.
41402
41403Similarly, @value{GDBN} will silently ignore unrecognized stub feature
41404responses, as long as each response uses one of the standard forms.
41405
41406Some features are flags. A stub which supports a flag feature
41407should respond with a @samp{+} form response. Other features
41408require values, and the stub should respond with an @samp{=}
41409form response.
41410
41411Each feature has a default value, which @value{GDBN} will use if
41412@samp{qSupported} is not available or if the feature is not mentioned
41413in the @samp{qSupported} response. The default values are fixed; a
41414stub is free to omit any feature responses that match the defaults.
41415
41416Not all features can be probed, but for those which can, the probing
41417mechanism is useful: in some cases, a stub's internal
41418architecture may not allow the protocol layer to know some information
41419about the underlying target in advance. This is especially common in
41420stubs which may be configured for multiple targets.
41421
41422These are the currently defined stub features and their properties:
41423
cfa9d6d9 41424@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
41425@c NOTE: The first row should be @headitem, but we do not yet require
41426@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 41427@item Feature Name
be2a5f71
DJ
41428@tab Value Required
41429@tab Default
41430@tab Probe Allowed
41431
41432@item @samp{PacketSize}
41433@tab Yes
41434@tab @samp{-}
41435@tab No
41436
0876f84a
DJ
41437@item @samp{qXfer:auxv:read}
41438@tab No
41439@tab @samp{-}
41440@tab Yes
41441
2ae8c8e7
MM
41442@item @samp{qXfer:btrace:read}
41443@tab No
41444@tab @samp{-}
41445@tab Yes
41446
f4abbc16
MM
41447@item @samp{qXfer:btrace-conf:read}
41448@tab No
41449@tab @samp{-}
41450@tab Yes
41451
c78fa86a
GB
41452@item @samp{qXfer:exec-file:read}
41453@tab No
41454@tab @samp{-}
41455@tab Yes
41456
23181151
DJ
41457@item @samp{qXfer:features:read}
41458@tab No
41459@tab @samp{-}
41460@tab Yes
41461
cfa9d6d9
DJ
41462@item @samp{qXfer:libraries:read}
41463@tab No
41464@tab @samp{-}
41465@tab Yes
41466
85dc5a12
GB
41467@item @samp{qXfer:libraries-svr4:read}
41468@tab No
41469@tab @samp{-}
41470@tab Yes
41471
41472@item @samp{augmented-libraries-svr4-read}
41473@tab No
41474@tab @samp{-}
41475@tab No
41476
68437a39
DJ
41477@item @samp{qXfer:memory-map:read}
41478@tab No
41479@tab @samp{-}
41480@tab Yes
41481
0fb4aa4b
PA
41482@item @samp{qXfer:sdata:read}
41483@tab No
41484@tab @samp{-}
41485@tab Yes
41486
4aa995e1
PA
41487@item @samp{qXfer:siginfo:read}
41488@tab No
41489@tab @samp{-}
41490@tab Yes
41491
41492@item @samp{qXfer:siginfo:write}
41493@tab No
41494@tab @samp{-}
41495@tab Yes
41496
dc146f7c
VP
41497@item @samp{qXfer:threads:read}
41498@tab No
41499@tab @samp{-}
41500@tab Yes
41501
b3b9301e
PA
41502@item @samp{qXfer:traceframe-info:read}
41503@tab No
41504@tab @samp{-}
41505@tab Yes
41506
169081d0
TG
41507@item @samp{qXfer:uib:read}
41508@tab No
41509@tab @samp{-}
41510@tab Yes
41511
78d85199
YQ
41512@item @samp{qXfer:fdpic:read}
41513@tab No
41514@tab @samp{-}
41515@tab Yes
dc146f7c 41516
2ae8c8e7
MM
41517@item @samp{Qbtrace:off}
41518@tab Yes
41519@tab @samp{-}
41520@tab Yes
41521
41522@item @samp{Qbtrace:bts}
41523@tab Yes
41524@tab @samp{-}
41525@tab Yes
41526
b20a6524
MM
41527@item @samp{Qbtrace:pt}
41528@tab Yes
41529@tab @samp{-}
41530@tab Yes
41531
d33501a5
MM
41532@item @samp{Qbtrace-conf:bts:size}
41533@tab Yes
41534@tab @samp{-}
41535@tab Yes
41536
b20a6524
MM
41537@item @samp{Qbtrace-conf:pt:size}
41538@tab Yes
41539@tab @samp{-}
41540@tab Yes
41541
8b23ecc4
SL
41542@item @samp{QNonStop}
41543@tab No
41544@tab @samp{-}
41545@tab Yes
41546
82075af2
JS
41547@item @samp{QCatchSyscalls}
41548@tab No
41549@tab @samp{-}
41550@tab Yes
41551
89be2091
DJ
41552@item @samp{QPassSignals}
41553@tab No
41554@tab @samp{-}
41555@tab Yes
41556
a6f3e723
SL
41557@item @samp{QStartNoAckMode}
41558@tab No
41559@tab @samp{-}
41560@tab Yes
41561
b90a069a
SL
41562@item @samp{multiprocess}
41563@tab No
41564@tab @samp{-}
41565@tab No
41566
83364271
LM
41567@item @samp{ConditionalBreakpoints}
41568@tab No
41569@tab @samp{-}
41570@tab No
41571
782b2b07
SS
41572@item @samp{ConditionalTracepoints}
41573@tab No
41574@tab @samp{-}
41575@tab No
41576
0d772ac9
MS
41577@item @samp{ReverseContinue}
41578@tab No
2f8132f3 41579@tab @samp{-}
0d772ac9
MS
41580@tab No
41581
41582@item @samp{ReverseStep}
41583@tab No
2f8132f3 41584@tab @samp{-}
0d772ac9
MS
41585@tab No
41586
409873ef
SS
41587@item @samp{TracepointSource}
41588@tab No
41589@tab @samp{-}
41590@tab No
41591
d1feda86
YQ
41592@item @samp{QAgent}
41593@tab No
41594@tab @samp{-}
41595@tab No
41596
d914c394
SS
41597@item @samp{QAllow}
41598@tab No
41599@tab @samp{-}
41600@tab No
41601
03583c20
UW
41602@item @samp{QDisableRandomization}
41603@tab No
41604@tab @samp{-}
41605@tab No
41606
d248b706
KY
41607@item @samp{EnableDisableTracepoints}
41608@tab No
41609@tab @samp{-}
41610@tab No
41611
f6f899bf
HAQ
41612@item @samp{QTBuffer:size}
41613@tab No
41614@tab @samp{-}
41615@tab No
41616
3065dfb6
SS
41617@item @samp{tracenz}
41618@tab No
41619@tab @samp{-}
41620@tab No
41621
d3ce09f5
SS
41622@item @samp{BreakpointCommands}
41623@tab No
41624@tab @samp{-}
41625@tab No
41626
f7e6eed5
PA
41627@item @samp{swbreak}
41628@tab No
41629@tab @samp{-}
41630@tab No
41631
41632@item @samp{hwbreak}
41633@tab No
41634@tab @samp{-}
41635@tab No
41636
0d71eef5
DB
41637@item @samp{fork-events}
41638@tab No
41639@tab @samp{-}
41640@tab No
41641
41642@item @samp{vfork-events}
41643@tab No
41644@tab @samp{-}
41645@tab No
41646
b459a59b
DB
41647@item @samp{exec-events}
41648@tab No
41649@tab @samp{-}
41650@tab No
41651
65706a29
PA
41652@item @samp{QThreadEvents}
41653@tab No
41654@tab @samp{-}
41655@tab No
41656
f2faf941
PA
41657@item @samp{no-resumed}
41658@tab No
41659@tab @samp{-}
41660@tab No
41661
be2a5f71
DJ
41662@end multitable
41663
41664These are the currently defined stub features, in more detail:
41665
41666@table @samp
41667@cindex packet size, remote protocol
41668@item PacketSize=@var{bytes}
41669The remote stub can accept packets up to at least @var{bytes} in
41670length. @value{GDBN} will send packets up to this size for bulk
41671transfers, and will never send larger packets. This is a limit on the
41672data characters in the packet, including the frame and checksum.
41673There is no trailing NUL byte in a remote protocol packet; if the stub
41674stores packets in a NUL-terminated format, it should allow an extra
41675byte in its buffer for the NUL. If this stub feature is not supported,
41676@value{GDBN} guesses based on the size of the @samp{g} packet response.
41677
0876f84a
DJ
41678@item qXfer:auxv:read
41679The remote stub understands the @samp{qXfer:auxv:read} packet
41680(@pxref{qXfer auxiliary vector read}).
41681
2ae8c8e7
MM
41682@item qXfer:btrace:read
41683The remote stub understands the @samp{qXfer:btrace:read}
41684packet (@pxref{qXfer btrace read}).
41685
f4abbc16
MM
41686@item qXfer:btrace-conf:read
41687The remote stub understands the @samp{qXfer:btrace-conf:read}
41688packet (@pxref{qXfer btrace-conf read}).
41689
c78fa86a
GB
41690@item qXfer:exec-file:read
41691The remote stub understands the @samp{qXfer:exec-file:read} packet
41692(@pxref{qXfer executable filename read}).
41693
23181151
DJ
41694@item qXfer:features:read
41695The remote stub understands the @samp{qXfer:features:read} packet
41696(@pxref{qXfer target description read}).
41697
cfa9d6d9
DJ
41698@item qXfer:libraries:read
41699The remote stub understands the @samp{qXfer:libraries:read} packet
41700(@pxref{qXfer library list read}).
41701
2268b414
JK
41702@item qXfer:libraries-svr4:read
41703The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
41704(@pxref{qXfer svr4 library list read}).
41705
85dc5a12
GB
41706@item augmented-libraries-svr4-read
41707The remote stub understands the augmented form of the
41708@samp{qXfer:libraries-svr4:read} packet
41709(@pxref{qXfer svr4 library list read}).
41710
23181151
DJ
41711@item qXfer:memory-map:read
41712The remote stub understands the @samp{qXfer:memory-map:read} packet
41713(@pxref{qXfer memory map read}).
41714
0fb4aa4b
PA
41715@item qXfer:sdata:read
41716The remote stub understands the @samp{qXfer:sdata:read} packet
41717(@pxref{qXfer sdata read}).
41718
4aa995e1
PA
41719@item qXfer:siginfo:read
41720The remote stub understands the @samp{qXfer:siginfo:read} packet
41721(@pxref{qXfer siginfo read}).
41722
41723@item qXfer:siginfo:write
41724The remote stub understands the @samp{qXfer:siginfo:write} packet
41725(@pxref{qXfer siginfo write}).
41726
dc146f7c
VP
41727@item qXfer:threads:read
41728The remote stub understands the @samp{qXfer:threads:read} packet
41729(@pxref{qXfer threads read}).
41730
b3b9301e
PA
41731@item qXfer:traceframe-info:read
41732The remote stub understands the @samp{qXfer:traceframe-info:read}
41733packet (@pxref{qXfer traceframe info read}).
41734
169081d0
TG
41735@item qXfer:uib:read
41736The remote stub understands the @samp{qXfer:uib:read}
41737packet (@pxref{qXfer unwind info block}).
41738
78d85199
YQ
41739@item qXfer:fdpic:read
41740The remote stub understands the @samp{qXfer:fdpic:read}
41741packet (@pxref{qXfer fdpic loadmap read}).
41742
8b23ecc4
SL
41743@item QNonStop
41744The remote stub understands the @samp{QNonStop} packet
41745(@pxref{QNonStop}).
41746
82075af2
JS
41747@item QCatchSyscalls
41748The remote stub understands the @samp{QCatchSyscalls} packet
41749(@pxref{QCatchSyscalls}).
41750
23181151
DJ
41751@item QPassSignals
41752The remote stub understands the @samp{QPassSignals} packet
41753(@pxref{QPassSignals}).
41754
a6f3e723
SL
41755@item QStartNoAckMode
41756The remote stub understands the @samp{QStartNoAckMode} packet and
41757prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
41758
b90a069a
SL
41759@item multiprocess
41760@anchor{multiprocess extensions}
41761@cindex multiprocess extensions, in remote protocol
41762The remote stub understands the multiprocess extensions to the remote
41763protocol syntax. The multiprocess extensions affect the syntax of
41764thread IDs in both packets and replies (@pxref{thread-id syntax}), and
41765add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
41766replies. Note that reporting this feature indicates support for the
41767syntactic extensions only, not that the stub necessarily supports
41768debugging of more than one process at a time. The stub must not use
41769multiprocess extensions in packet replies unless @value{GDBN} has also
41770indicated it supports them in its @samp{qSupported} request.
41771
07e059b5
VP
41772@item qXfer:osdata:read
41773The remote stub understands the @samp{qXfer:osdata:read} packet
41774((@pxref{qXfer osdata read}).
41775
83364271
LM
41776@item ConditionalBreakpoints
41777The target accepts and implements evaluation of conditional expressions
41778defined for breakpoints. The target will only report breakpoint triggers
41779when such conditions are true (@pxref{Conditions, ,Break Conditions}).
41780
782b2b07
SS
41781@item ConditionalTracepoints
41782The remote stub accepts and implements conditional expressions defined
41783for tracepoints (@pxref{Tracepoint Conditions}).
41784
0d772ac9
MS
41785@item ReverseContinue
41786The remote stub accepts and implements the reverse continue packet
41787(@pxref{bc}).
41788
41789@item ReverseStep
41790The remote stub accepts and implements the reverse step packet
41791(@pxref{bs}).
41792
409873ef
SS
41793@item TracepointSource
41794The remote stub understands the @samp{QTDPsrc} packet that supplies
41795the source form of tracepoint definitions.
41796
d1feda86
YQ
41797@item QAgent
41798The remote stub understands the @samp{QAgent} packet.
41799
d914c394
SS
41800@item QAllow
41801The remote stub understands the @samp{QAllow} packet.
41802
03583c20
UW
41803@item QDisableRandomization
41804The remote stub understands the @samp{QDisableRandomization} packet.
41805
0fb4aa4b
PA
41806@item StaticTracepoint
41807@cindex static tracepoints, in remote protocol
41808The remote stub supports static tracepoints.
41809
1e4d1764
YQ
41810@item InstallInTrace
41811@anchor{install tracepoint in tracing}
41812The remote stub supports installing tracepoint in tracing.
41813
d248b706
KY
41814@item EnableDisableTracepoints
41815The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
41816@samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
41817to be enabled and disabled while a trace experiment is running.
41818
f6f899bf 41819@item QTBuffer:size
28abe188 41820The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
f6f899bf
HAQ
41821packet that allows to change the size of the trace buffer.
41822
3065dfb6
SS
41823@item tracenz
41824@cindex string tracing, in remote protocol
41825The remote stub supports the @samp{tracenz} bytecode for collecting strings.
41826See @ref{Bytecode Descriptions} for details about the bytecode.
41827
d3ce09f5
SS
41828@item BreakpointCommands
41829@cindex breakpoint commands, in remote protocol
41830The remote stub supports running a breakpoint's command list itself,
41831rather than reporting the hit to @value{GDBN}.
41832
2ae8c8e7
MM
41833@item Qbtrace:off
41834The remote stub understands the @samp{Qbtrace:off} packet.
41835
41836@item Qbtrace:bts
41837The remote stub understands the @samp{Qbtrace:bts} packet.
41838
b20a6524
MM
41839@item Qbtrace:pt
41840The remote stub understands the @samp{Qbtrace:pt} packet.
41841
d33501a5
MM
41842@item Qbtrace-conf:bts:size
41843The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
41844
b20a6524
MM
41845@item Qbtrace-conf:pt:size
41846The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
41847
f7e6eed5
PA
41848@item swbreak
41849The remote stub reports the @samp{swbreak} stop reason for memory
41850breakpoints.
41851
41852@item hwbreak
41853The remote stub reports the @samp{hwbreak} stop reason for hardware
41854breakpoints.
41855
0d71eef5
DB
41856@item fork-events
41857The remote stub reports the @samp{fork} stop reason for fork events.
41858
41859@item vfork-events
41860The remote stub reports the @samp{vfork} stop reason for vfork events
41861and vforkdone events.
41862
b459a59b
DB
41863@item exec-events
41864The remote stub reports the @samp{exec} stop reason for exec events.
41865
750ce8d1
YQ
41866@item vContSupported
41867The remote stub reports the supported actions in the reply to
41868@samp{vCont?} packet.
41869
65706a29
PA
41870@item QThreadEvents
41871The remote stub understands the @samp{QThreadEvents} packet.
41872
f2faf941
PA
41873@item no-resumed
41874The remote stub reports the @samp{N} stop reply.
41875
be2a5f71
DJ
41876@end table
41877
b8ff78ce 41878@item qSymbol::
ff2587ec 41879@cindex symbol lookup, remote request
b8ff78ce 41880@cindex @samp{qSymbol} packet
ff2587ec
WZ
41881Notify the target that @value{GDBN} is prepared to serve symbol lookup
41882requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
41883
41884Reply:
ff2587ec 41885@table @samp
b8ff78ce 41886@item OK
ff2587ec 41887The target does not need to look up any (more) symbols.
b8ff78ce 41888@item qSymbol:@var{sym_name}
ff2587ec
WZ
41889The target requests the value of symbol @var{sym_name} (hex encoded).
41890@value{GDBN} may provide the value by using the
b8ff78ce
JB
41891@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
41892below.
ff2587ec 41893@end table
83761cbd 41894
b8ff78ce 41895@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
41896Set the value of @var{sym_name} to @var{sym_value}.
41897
41898@var{sym_name} (hex encoded) is the name of a symbol whose value the
41899target has previously requested.
41900
41901@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
41902@value{GDBN} cannot supply a value for @var{sym_name}, then this field
41903will be empty.
41904
41905Reply:
41906@table @samp
b8ff78ce 41907@item OK
ff2587ec 41908The target does not need to look up any (more) symbols.
b8ff78ce 41909@item qSymbol:@var{sym_name}
ff2587ec
WZ
41910The target requests the value of a new symbol @var{sym_name} (hex
41911encoded). @value{GDBN} will continue to supply the values of symbols
41912(if available), until the target ceases to request them.
fa93a9d8 41913@end table
0abb7bc7 41914
00bf0b85 41915@item qTBuffer
687e43a4
TT
41916@itemx QTBuffer
41917@itemx QTDisconnected
d5551862 41918@itemx QTDP
409873ef 41919@itemx QTDPsrc
d5551862 41920@itemx QTDV
00bf0b85
SS
41921@itemx qTfP
41922@itemx qTfV
9d29849a 41923@itemx QTFrame
405f8e94
SS
41924@itemx qTMinFTPILen
41925
9d29849a
JB
41926@xref{Tracepoint Packets}.
41927
b90a069a 41928@item qThreadExtraInfo,@var{thread-id}
ff2587ec 41929@cindex thread attributes info, remote request
b8ff78ce 41930@cindex @samp{qThreadExtraInfo} packet
697aa1b7
EZ
41931Obtain from the target OS a printable string description of thread
41932attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
41933for the forms of @var{thread-id}. This
b8ff78ce
JB
41934string may contain anything that the target OS thinks is interesting
41935for @value{GDBN} to tell the user about the thread. The string is
41936displayed in @value{GDBN}'s @code{info threads} display. Some
41937examples of possible thread extra info strings are @samp{Runnable}, or
41938@samp{Blocked on Mutex}.
ff2587ec
WZ
41939
41940Reply:
41941@table @samp
b8ff78ce
JB
41942@item @var{XX}@dots{}
41943Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
41944comprising the printable string containing the extra information about
41945the thread's attributes.
ff2587ec 41946@end table
814e32d7 41947
aa56d27a
JB
41948(Note that the @code{qThreadExtraInfo} packet's name is separated from
41949the command by a @samp{,}, not a @samp{:}, contrary to the naming
41950conventions above. Please don't use this packet as a model for new
41951packets.)
41952
f196051f 41953@item QTNotes
687e43a4
TT
41954@itemx qTP
41955@itemx QTSave
41956@itemx qTsP
41957@itemx qTsV
d5551862 41958@itemx QTStart
9d29849a 41959@itemx QTStop
d248b706
KY
41960@itemx QTEnable
41961@itemx QTDisable
9d29849a
JB
41962@itemx QTinit
41963@itemx QTro
41964@itemx qTStatus
d5551862 41965@itemx qTV
0fb4aa4b
PA
41966@itemx qTfSTM
41967@itemx qTsSTM
41968@itemx qTSTMat
9d29849a
JB
41969@xref{Tracepoint Packets}.
41970
0876f84a
DJ
41971@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
41972@cindex read special object, remote request
41973@cindex @samp{qXfer} packet
68437a39 41974@anchor{qXfer read}
0876f84a
DJ
41975Read uninterpreted bytes from the target's special data area
41976identified by the keyword @var{object}. Request @var{length} bytes
41977starting at @var{offset} bytes into the data. The content and
0e7f50da 41978encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
41979additional details about what data to access.
41980
c185ba27
EZ
41981Reply:
41982@table @samp
41983@item m @var{data}
41984Data @var{data} (@pxref{Binary Data}) has been read from the
41985target. There may be more data at a higher address (although
41986it is permitted to return @samp{m} even for the last valid
41987block of data, as long as at least one byte of data was read).
41988It is possible for @var{data} to have fewer bytes than the @var{length} in the
41989request.
41990
41991@item l @var{data}
41992Data @var{data} (@pxref{Binary Data}) has been read from the target.
41993There is no more data to be read. It is possible for @var{data} to
41994have fewer bytes than the @var{length} in the request.
41995
41996@item l
41997The @var{offset} in the request is at the end of the data.
41998There is no more data to be read.
41999
42000@item E00
42001The request was malformed, or @var{annex} was invalid.
42002
42003@item E @var{nn}
42004The offset was invalid, or there was an error encountered reading the data.
42005The @var{nn} part is a hex-encoded @code{errno} value.
42006
42007@item @w{}
42008An empty reply indicates the @var{object} string was not recognized by
42009the stub, or that the object does not support reading.
42010@end table
42011
42012Here are the specific requests of this form defined so far. All the
0876f84a 42013@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
c185ba27 42014formats, listed above.
0876f84a
DJ
42015
42016@table @samp
42017@item qXfer:auxv:read::@var{offset},@var{length}
42018@anchor{qXfer auxiliary vector read}
42019Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 42020auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
42021
42022This packet is not probed by default; the remote stub must request it,
89be2091 42023by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 42024
2ae8c8e7
MM
42025@item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
42026@anchor{qXfer btrace read}
42027
42028Return a description of the current branch trace.
42029@xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
42030packet may have one of the following values:
42031
42032@table @code
42033@item all
42034Returns all available branch trace.
42035
42036@item new
42037Returns all available branch trace if the branch trace changed since
42038the last read request.
969c39fb
MM
42039
42040@item delta
42041Returns the new branch trace since the last read request. Adds a new
42042block to the end of the trace that begins at zero and ends at the source
42043location of the first branch in the trace buffer. This extra block is
42044used to stitch traces together.
42045
42046If the trace buffer overflowed, returns an error indicating the overflow.
2ae8c8e7
MM
42047@end table
42048
42049This packet is not probed by default; the remote stub must request it
42050by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42051
f4abbc16
MM
42052@item qXfer:btrace-conf:read::@var{offset},@var{length}
42053@anchor{qXfer btrace-conf read}
42054
42055Return a description of the current branch trace configuration.
42056@xref{Branch Trace Configuration Format}.
42057
42058This packet is not probed by default; the remote stub must request it
42059by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
c78fa86a
GB
42060
42061@item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
42062@anchor{qXfer executable filename read}
42063Return the full absolute name of the file that was executed to create
42064a process running on the remote system. The annex specifies the
42065numeric process ID of the process to query, encoded as a hexadecimal
835205d0
GB
42066number. If the annex part is empty the remote stub should return the
42067filename corresponding to the currently executing process.
c78fa86a
GB
42068
42069This packet is not probed by default; the remote stub must request it,
42070by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
f4abbc16 42071
23181151
DJ
42072@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
42073@anchor{qXfer target description read}
42074Access the @dfn{target description}. @xref{Target Descriptions}. The
42075annex specifies which XML document to access. The main description is
42076always loaded from the @samp{target.xml} annex.
42077
42078This packet is not probed by default; the remote stub must request it,
42079by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42080
cfa9d6d9
DJ
42081@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
42082@anchor{qXfer library list read}
42083Access the target's list of loaded libraries. @xref{Library List Format}.
42084The annex part of the generic @samp{qXfer} packet must be empty
42085(@pxref{qXfer read}).
42086
42087Targets which maintain a list of libraries in the program's memory do
42088not need to implement this packet; it is designed for platforms where
42089the operating system manages the list of loaded libraries.
42090
42091This packet is not probed by default; the remote stub must request it,
42092by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42093
2268b414
JK
42094@item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
42095@anchor{qXfer svr4 library list read}
42096Access the target's list of loaded libraries when the target is an SVR4
42097platform. @xref{Library List Format for SVR4 Targets}. The annex part
85dc5a12
GB
42098of the generic @samp{qXfer} packet must be empty unless the remote
42099stub indicated it supports the augmented form of this packet
42100by supplying an appropriate @samp{qSupported} response
42101(@pxref{qXfer read}, @ref{qSupported}).
2268b414
JK
42102
42103This packet is optional for better performance on SVR4 targets.
42104@value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
42105
42106This packet is not probed by default; the remote stub must request it,
42107by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42108
85dc5a12
GB
42109If the remote stub indicates it supports the augmented form of this
42110packet then the annex part of the generic @samp{qXfer} packet may
42111contain a semicolon-separated list of @samp{@var{name}=@var{value}}
42112arguments. The currently supported arguments are:
42113
42114@table @code
42115@item start=@var{address}
42116A hexadecimal number specifying the address of the @samp{struct
42117link_map} to start reading the library list from. If unset or zero
42118then the first @samp{struct link_map} in the library list will be
42119chosen as the starting point.
42120
42121@item prev=@var{address}
42122A hexadecimal number specifying the address of the @samp{struct
42123link_map} immediately preceding the @samp{struct link_map}
42124specified by the @samp{start} argument. If unset or zero then
42125the remote stub will expect that no @samp{struct link_map}
42126exists prior to the starting point.
42127
42128@end table
42129
42130Arguments that are not understood by the remote stub will be silently
42131ignored.
42132
68437a39
DJ
42133@item qXfer:memory-map:read::@var{offset},@var{length}
42134@anchor{qXfer memory map read}
79a6e687 42135Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
42136annex part of the generic @samp{qXfer} packet must be empty
42137(@pxref{qXfer read}).
42138
0e7f50da
UW
42139This packet is not probed by default; the remote stub must request it,
42140by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42141
0fb4aa4b
PA
42142@item qXfer:sdata:read::@var{offset},@var{length}
42143@anchor{qXfer sdata read}
42144
42145Read contents of the extra collected static tracepoint marker
42146information. The annex part of the generic @samp{qXfer} packet must
42147be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
42148Action Lists}.
42149
42150This packet is not probed by default; the remote stub must request it,
42151by supplying an appropriate @samp{qSupported} response
42152(@pxref{qSupported}).
42153
4aa995e1
PA
42154@item qXfer:siginfo:read::@var{offset},@var{length}
42155@anchor{qXfer siginfo read}
42156Read contents of the extra signal information on the target
42157system. The annex part of the generic @samp{qXfer} packet must be
42158empty (@pxref{qXfer read}).
42159
42160This packet is not probed by default; the remote stub must request it,
42161by supplying an appropriate @samp{qSupported} response
42162(@pxref{qSupported}).
42163
dc146f7c
VP
42164@item qXfer:threads:read::@var{offset},@var{length}
42165@anchor{qXfer threads read}
42166Access the list of threads on target. @xref{Thread List Format}. The
42167annex part of the generic @samp{qXfer} packet must be empty
42168(@pxref{qXfer read}).
42169
42170This packet is not probed by default; the remote stub must request it,
42171by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42172
b3b9301e
PA
42173@item qXfer:traceframe-info:read::@var{offset},@var{length}
42174@anchor{qXfer traceframe info read}
42175
42176Return a description of the current traceframe's contents.
42177@xref{Traceframe Info Format}. The annex part of the generic
42178@samp{qXfer} packet must be empty (@pxref{qXfer read}).
42179
42180This packet is not probed by default; the remote stub must request it,
42181by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42182
169081d0
TG
42183@item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
42184@anchor{qXfer unwind info block}
42185
42186Return the unwind information block for @var{pc}. This packet is used
42187on OpenVMS/ia64 to ask the kernel unwind information.
42188
42189This packet is not probed by default.
42190
78d85199
YQ
42191@item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
42192@anchor{qXfer fdpic loadmap read}
42193Read contents of @code{loadmap}s on the target system. The
42194annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
42195executable @code{loadmap} or interpreter @code{loadmap} to read.
42196
42197This packet is not probed by default; the remote stub must request it,
42198by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42199
07e059b5
VP
42200@item qXfer:osdata:read::@var{offset},@var{length}
42201@anchor{qXfer osdata read}
697aa1b7 42202Access the target's @dfn{operating system information}.
07e059b5
VP
42203@xref{Operating System Information}.
42204
68437a39
DJ
42205@end table
42206
c185ba27
EZ
42207@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
42208@cindex write data into object, remote request
42209@anchor{qXfer write}
42210Write uninterpreted bytes into the target's special data area
42211identified by the keyword @var{object}, starting at @var{offset} bytes
42212into the data. The binary-encoded data (@pxref{Binary Data}) to be
42213written is given by @var{data}@dots{}. The content and encoding of @var{annex}
42214is specific to @var{object}; it can supply additional details about what data
42215to access.
42216
0876f84a
DJ
42217Reply:
42218@table @samp
c185ba27
EZ
42219@item @var{nn}
42220@var{nn} (hex encoded) is the number of bytes written.
42221This may be fewer bytes than supplied in the request.
0876f84a
DJ
42222
42223@item E00
42224The request was malformed, or @var{annex} was invalid.
42225
42226@item E @var{nn}
c185ba27 42227The offset was invalid, or there was an error encountered writing the data.
697aa1b7 42228The @var{nn} part is a hex-encoded @code{errno} value.
0876f84a 42229
d57350ea 42230@item @w{}
c185ba27
EZ
42231An empty reply indicates the @var{object} string was not
42232recognized by the stub, or that the object does not support writing.
0876f84a
DJ
42233@end table
42234
c185ba27 42235Here are the specific requests of this form defined so far. All the
0e7f50da 42236@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
c185ba27 42237formats, listed above.
0e7f50da
UW
42238
42239@table @samp
4aa995e1
PA
42240@item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
42241@anchor{qXfer siginfo write}
42242Write @var{data} to the extra signal information on the target system.
42243The annex part of the generic @samp{qXfer} packet must be
42244empty (@pxref{qXfer write}).
42245
42246This packet is not probed by default; the remote stub must request it,
42247by supplying an appropriate @samp{qSupported} response
42248(@pxref{qSupported}).
0e7f50da 42249@end table
0876f84a 42250
0876f84a
DJ
42251@item qXfer:@var{object}:@var{operation}:@dots{}
42252Requests of this form may be added in the future. When a stub does
42253not recognize the @var{object} keyword, or its support for
42254@var{object} does not recognize the @var{operation} keyword, the stub
42255must respond with an empty packet.
42256
0b16c5cf
PA
42257@item qAttached:@var{pid}
42258@cindex query attached, remote request
42259@cindex @samp{qAttached} packet
42260Return an indication of whether the remote server attached to an
42261existing process or created a new process. When the multiprocess
42262protocol extensions are supported (@pxref{multiprocess extensions}),
42263@var{pid} is an integer in hexadecimal format identifying the target
42264process. Otherwise, @value{GDBN} will omit the @var{pid} field and
42265the query packet will be simplified as @samp{qAttached}.
42266
42267This query is used, for example, to know whether the remote process
42268should be detached or killed when a @value{GDBN} session is ended with
42269the @code{quit} command.
42270
42271Reply:
42272@table @samp
42273@item 1
42274The remote server attached to an existing process.
42275@item 0
42276The remote server created a new process.
42277@item E @var{NN}
42278A badly formed request or an error was encountered.
42279@end table
42280
2ae8c8e7 42281@item Qbtrace:bts
b20a6524
MM
42282Enable branch tracing for the current thread using Branch Trace Store.
42283
42284Reply:
42285@table @samp
42286@item OK
42287Branch tracing has been enabled.
42288@item E.errtext
42289A badly formed request or an error was encountered.
42290@end table
42291
42292@item Qbtrace:pt
bc504a31 42293Enable branch tracing for the current thread using Intel Processor Trace.
2ae8c8e7
MM
42294
42295Reply:
42296@table @samp
42297@item OK
42298Branch tracing has been enabled.
42299@item E.errtext
42300A badly formed request or an error was encountered.
42301@end table
42302
42303@item Qbtrace:off
42304Disable branch tracing for the current thread.
42305
42306Reply:
42307@table @samp
42308@item OK
42309Branch tracing has been disabled.
42310@item E.errtext
42311A badly formed request or an error was encountered.
42312@end table
42313
d33501a5
MM
42314@item Qbtrace-conf:bts:size=@var{value}
42315Set the requested ring buffer size for new threads that use the
42316btrace recording method in bts format.
42317
42318Reply:
42319@table @samp
42320@item OK
42321The ring buffer size has been set.
42322@item E.errtext
42323A badly formed request or an error was encountered.
42324@end table
42325
b20a6524
MM
42326@item Qbtrace-conf:pt:size=@var{value}
42327Set the requested ring buffer size for new threads that use the
42328btrace recording method in pt format.
42329
42330Reply:
42331@table @samp
42332@item OK
42333The ring buffer size has been set.
42334@item E.errtext
42335A badly formed request or an error was encountered.
42336@end table
42337
ee2d5c50
AC
42338@end table
42339
a1dcb23a
DJ
42340@node Architecture-Specific Protocol Details
42341@section Architecture-Specific Protocol Details
42342
42343This section describes how the remote protocol is applied to specific
42344target architectures. Also see @ref{Standard Target Features}, for
42345details of XML target descriptions for each architecture.
42346
02b67415
MR
42347@menu
42348* ARM-Specific Protocol Details::
42349* MIPS-Specific Protocol Details::
42350@end menu
42351
42352@node ARM-Specific Protocol Details
42353@subsection @acronym{ARM}-specific Protocol Details
42354
42355@menu
42356* ARM Breakpoint Kinds::
42357@end menu
a1dcb23a 42358
02b67415
MR
42359@node ARM Breakpoint Kinds
42360@subsubsection @acronym{ARM} Breakpoint Kinds
42361@cindex breakpoint kinds, @acronym{ARM}
a1dcb23a
DJ
42362
42363These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42364
42365@table @r
42366
42367@item 2
4236816-bit Thumb mode breakpoint.
42369
42370@item 3
4237132-bit Thumb mode (Thumb-2) breakpoint.
42372
42373@item 4
02b67415 4237432-bit @acronym{ARM} mode breakpoint.
a1dcb23a
DJ
42375
42376@end table
42377
02b67415
MR
42378@node MIPS-Specific Protocol Details
42379@subsection @acronym{MIPS}-specific Protocol Details
42380
42381@menu
42382* MIPS Register packet Format::
4cc0665f 42383* MIPS Breakpoint Kinds::
02b67415 42384@end menu
a1dcb23a 42385
02b67415
MR
42386@node MIPS Register packet Format
42387@subsubsection @acronym{MIPS} Register Packet Format
eb17f351 42388@cindex register packet format, @acronym{MIPS}
eb12ee30 42389
b8ff78ce 42390The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
42391In the below, some thirty-two bit registers are transferred as
42392sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
42393to fill the space allocated. Register bytes are transferred in target
42394byte order. The two nibbles within a register byte are transferred
02b67415 42395most-significant -- least-significant.
eb12ee30 42396
ee2d5c50 42397@table @r
eb12ee30 42398
8e04817f 42399@item MIPS32
599b237a 42400All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
4240132 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
42402registers; fsr; fir; fp.
eb12ee30 42403
8e04817f 42404@item MIPS64
599b237a 42405All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
42406thirty-two bit registers such as @code{sr}). The ordering is the same
42407as @code{MIPS32}.
eb12ee30 42408
ee2d5c50
AC
42409@end table
42410
4cc0665f
MR
42411@node MIPS Breakpoint Kinds
42412@subsubsection @acronym{MIPS} Breakpoint Kinds
42413@cindex breakpoint kinds, @acronym{MIPS}
42414
42415These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42416
42417@table @r
42418
42419@item 2
4242016-bit @acronym{MIPS16} mode breakpoint.
42421
42422@item 3
4242316-bit @acronym{microMIPS} mode breakpoint.
42424
42425@item 4
4242632-bit standard @acronym{MIPS} mode breakpoint.
42427
42428@item 5
4242932-bit @acronym{microMIPS} mode breakpoint.
42430
42431@end table
42432
9d29849a
JB
42433@node Tracepoint Packets
42434@section Tracepoint Packets
42435@cindex tracepoint packets
42436@cindex packets, tracepoint
42437
42438Here we describe the packets @value{GDBN} uses to implement
42439tracepoints (@pxref{Tracepoints}).
42440
42441@table @samp
42442
7a697b8d 42443@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
c614397c 42444@cindex @samp{QTDP} packet
9d29849a
JB
42445Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
42446is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
697aa1b7
EZ
42447the tracepoint is disabled. The @var{step} gives the tracepoint's step
42448count, and @var{pass} gives its pass count. If an @samp{F} is present,
7a697b8d
SS
42449then the tracepoint is to be a fast tracepoint, and the @var{flen} is
42450the number of bytes that the target should copy elsewhere to make room
42451for the tracepoint. If an @samp{X} is present, it introduces a
42452tracepoint condition, which consists of a hexadecimal length, followed
42453by a comma and hex-encoded bytes, in a manner similar to action
42454encodings as described below. If the trailing @samp{-} is present,
42455further @samp{QTDP} packets will follow to specify this tracepoint's
42456actions.
9d29849a
JB
42457
42458Replies:
42459@table @samp
42460@item OK
42461The packet was understood and carried out.
dde08ee1
PA
42462@item qRelocInsn
42463@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 42464@item @w{}
9d29849a
JB
42465The packet was not recognized.
42466@end table
42467
42468@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
697aa1b7 42469Define actions to be taken when a tracepoint is hit. The @var{n} and
9d29849a
JB
42470@var{addr} must be the same as in the initial @samp{QTDP} packet for
42471this tracepoint. This packet may only be sent immediately after
42472another @samp{QTDP} packet that ended with a @samp{-}. If the
42473trailing @samp{-} is present, further @samp{QTDP} packets will follow,
42474specifying more actions for this tracepoint.
42475
42476In the series of action packets for a given tracepoint, at most one
42477can have an @samp{S} before its first @var{action}. If such a packet
42478is sent, it and the following packets define ``while-stepping''
42479actions. Any prior packets define ordinary actions --- that is, those
42480taken when the tracepoint is first hit. If no action packet has an
42481@samp{S}, then all the packets in the series specify ordinary
42482tracepoint actions.
42483
42484The @samp{@var{action}@dots{}} portion of the packet is a series of
42485actions, concatenated without separators. Each action has one of the
42486following forms:
42487
42488@table @samp
42489
42490@item R @var{mask}
697aa1b7 42491Collect the registers whose bits are set in @var{mask},
599b237a 42492a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
42493@var{i} should be collected. (The least significant bit is numbered
42494zero.) Note that @var{mask} may be any number of digits long; it may
42495not fit in a 32-bit word.
42496
42497@item M @var{basereg},@var{offset},@var{len}
42498Collect @var{len} bytes of memory starting at the address in register
42499number @var{basereg}, plus @var{offset}. If @var{basereg} is
42500@samp{-1}, then the range has a fixed address: @var{offset} is the
42501address of the lowest byte to collect. The @var{basereg},
599b237a 42502@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
42503values (the @samp{-1} value for @var{basereg} is a special case).
42504
42505@item X @var{len},@var{expr}
42506Evaluate @var{expr}, whose length is @var{len}, and collect memory as
697aa1b7 42507it directs. The agent expression @var{expr} is as described in
9d29849a
JB
42508@ref{Agent Expressions}. Each byte of the expression is encoded as a
42509two-digit hex number in the packet; @var{len} is the number of bytes
42510in the expression (and thus one-half the number of hex digits in the
42511packet).
42512
42513@end table
42514
42515Any number of actions may be packed together in a single @samp{QTDP}
42516packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
42517length (400 bytes, for many stubs). There may be only one @samp{R}
42518action per tracepoint, and it must precede any @samp{M} or @samp{X}
42519actions. Any registers referred to by @samp{M} and @samp{X} actions
42520must be collected by a preceding @samp{R} action. (The
42521``while-stepping'' actions are treated as if they were attached to a
42522separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
42523
42524Replies:
42525@table @samp
42526@item OK
42527The packet was understood and carried out.
dde08ee1
PA
42528@item qRelocInsn
42529@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 42530@item @w{}
9d29849a
JB
42531The packet was not recognized.
42532@end table
42533
409873ef
SS
42534@item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
42535@cindex @samp{QTDPsrc} packet
42536Specify a source string of tracepoint @var{n} at address @var{addr}.
42537This is useful to get accurate reproduction of the tracepoints
697aa1b7 42538originally downloaded at the beginning of the trace run. The @var{type}
409873ef
SS
42539is the name of the tracepoint part, such as @samp{cond} for the
42540tracepoint's conditional expression (see below for a list of types), while
42541@var{bytes} is the string, encoded in hexadecimal.
42542
42543@var{start} is the offset of the @var{bytes} within the overall source
42544string, while @var{slen} is the total length of the source string.
42545This is intended for handling source strings that are longer than will
42546fit in a single packet.
42547@c Add detailed example when this info is moved into a dedicated
42548@c tracepoint descriptions section.
42549
42550The available string types are @samp{at} for the location,
42551@samp{cond} for the conditional, and @samp{cmd} for an action command.
42552@value{GDBN} sends a separate packet for each command in the action
42553list, in the same order in which the commands are stored in the list.
42554
42555The target does not need to do anything with source strings except
42556report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
42557query packets.
42558
42559Although this packet is optional, and @value{GDBN} will only send it
42560if the target replies with @samp{TracepointSource} @xref{General
42561Query Packets}, it makes both disconnected tracing and trace files
42562much easier to use. Otherwise the user must be careful that the
42563tracepoints in effect while looking at trace frames are identical to
42564the ones in effect during the trace run; even a small discrepancy
42565could cause @samp{tdump} not to work, or a particular trace frame not
42566be found.
42567
fa3f8d5a 42568@item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
f61e138d
SS
42569@cindex define trace state variable, remote request
42570@cindex @samp{QTDV} packet
42571Create a new trace state variable, number @var{n}, with an initial
42572value of @var{value}, which is a 64-bit signed integer. Both @var{n}
42573and @var{value} are encoded as hexadecimal values. @value{GDBN} has
42574the option of not using this packet for initial values of zero; the
42575target should simply create the trace state variables as they are
fa3f8d5a
DT
42576mentioned in expressions. The value @var{builtin} should be 1 (one)
42577if the trace state variable is builtin and 0 (zero) if it is not builtin.
42578@value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
42579@samp{qTsV} packet had it set. The contents of @var{name} is the
42580hex-encoded name (without the leading @samp{$}) of the trace state
42581variable.
f61e138d 42582
9d29849a 42583@item QTFrame:@var{n}
c614397c 42584@cindex @samp{QTFrame} packet
9d29849a
JB
42585Select the @var{n}'th tracepoint frame from the buffer, and use the
42586register and memory contents recorded there to answer subsequent
42587request packets from @value{GDBN}.
42588
42589A successful reply from the stub indicates that the stub has found the
42590requested frame. The response is a series of parts, concatenated
42591without separators, describing the frame we selected. Each part has
42592one of the following forms:
42593
42594@table @samp
42595@item F @var{f}
42596The selected frame is number @var{n} in the trace frame buffer;
599b237a 42597@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
42598was no frame matching the criteria in the request packet.
42599
42600@item T @var{t}
42601The selected trace frame records a hit of tracepoint number @var{t};
599b237a 42602@var{t} is a hexadecimal number.
9d29849a
JB
42603
42604@end table
42605
42606@item QTFrame:pc:@var{addr}
42607Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42608currently selected frame whose PC is @var{addr};
599b237a 42609@var{addr} is a hexadecimal number.
9d29849a
JB
42610
42611@item QTFrame:tdp:@var{t}
42612Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42613currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 42614is a hexadecimal number.
9d29849a
JB
42615
42616@item QTFrame:range:@var{start}:@var{end}
42617Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42618currently selected frame whose PC is between @var{start} (inclusive)
081dfbf7 42619and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
42620numbers.
42621
42622@item QTFrame:outside:@var{start}:@var{end}
42623Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
081dfbf7 42624frame @emph{outside} the given range of addresses (exclusive).
9d29849a 42625
405f8e94 42626@item qTMinFTPILen
c614397c 42627@cindex @samp{qTMinFTPILen} packet
405f8e94
SS
42628This packet requests the minimum length of instruction at which a fast
42629tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
42630the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
42631it depends on the target system being able to create trampolines in
42632the first 64K of memory, which might or might not be possible for that
42633system. So the reply to this packet will be 4 if it is able to
42634arrange for that.
42635
42636Replies:
42637
42638@table @samp
42639@item 0
42640The minimum instruction length is currently unknown.
42641@item @var{length}
697aa1b7
EZ
42642The minimum instruction length is @var{length}, where @var{length}
42643is a hexadecimal number greater or equal to 1. A reply
42644of 1 means that a fast tracepoint may be placed on any instruction
42645regardless of size.
405f8e94
SS
42646@item E
42647An error has occurred.
d57350ea 42648@item @w{}
405f8e94
SS
42649An empty reply indicates that the request is not supported by the stub.
42650@end table
42651
9d29849a 42652@item QTStart
c614397c 42653@cindex @samp{QTStart} packet
dde08ee1
PA
42654Begin the tracepoint experiment. Begin collecting data from
42655tracepoint hits in the trace frame buffer. This packet supports the
42656@samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
42657instruction reply packet}).
9d29849a
JB
42658
42659@item QTStop
c614397c 42660@cindex @samp{QTStop} packet
9d29849a
JB
42661End the tracepoint experiment. Stop collecting trace frames.
42662
d248b706
KY
42663@item QTEnable:@var{n}:@var{addr}
42664@anchor{QTEnable}
c614397c 42665@cindex @samp{QTEnable} packet
d248b706
KY
42666Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
42667experiment. If the tracepoint was previously disabled, then collection
42668of data from it will resume.
42669
42670@item QTDisable:@var{n}:@var{addr}
42671@anchor{QTDisable}
c614397c 42672@cindex @samp{QTDisable} packet
d248b706
KY
42673Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
42674experiment. No more data will be collected from the tracepoint unless
42675@samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
42676
9d29849a 42677@item QTinit
c614397c 42678@cindex @samp{QTinit} packet
9d29849a
JB
42679Clear the table of tracepoints, and empty the trace frame buffer.
42680
42681@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
c614397c 42682@cindex @samp{QTro} packet
9d29849a
JB
42683Establish the given ranges of memory as ``transparent''. The stub
42684will answer requests for these ranges from memory's current contents,
42685if they were not collected as part of the tracepoint hit.
42686
42687@value{GDBN} uses this to mark read-only regions of memory, like those
42688containing program code. Since these areas never change, they should
42689still have the same contents they did when the tracepoint was hit, so
42690there's no reason for the stub to refuse to provide their contents.
42691
d5551862 42692@item QTDisconnected:@var{value}
c614397c 42693@cindex @samp{QTDisconnected} packet
d5551862
SS
42694Set the choice to what to do with the tracing run when @value{GDBN}
42695disconnects from the target. A @var{value} of 1 directs the target to
42696continue the tracing run, while 0 tells the target to stop tracing if
42697@value{GDBN} is no longer in the picture.
42698
9d29849a 42699@item qTStatus
c614397c 42700@cindex @samp{qTStatus} packet
9d29849a
JB
42701Ask the stub if there is a trace experiment running right now.
42702
4daf5ac0
SS
42703The reply has the form:
42704
42705@table @samp
42706
42707@item T@var{running}@r{[};@var{field}@r{]}@dots{}
42708@var{running} is a single digit @code{1} if the trace is presently
42709running, or @code{0} if not. It is followed by semicolon-separated
42710optional fields that an agent may use to report additional status.
42711
42712@end table
42713
42714If the trace is not running, the agent may report any of several
42715explanations as one of the optional fields:
42716
42717@table @samp
42718
42719@item tnotrun:0
42720No trace has been run yet.
42721
f196051f
SS
42722@item tstop[:@var{text}]:0
42723The trace was stopped by a user-originated stop command. The optional
42724@var{text} field is a user-supplied string supplied as part of the
42725stop command (for instance, an explanation of why the trace was
42726stopped manually). It is hex-encoded.
4daf5ac0
SS
42727
42728@item tfull:0
42729The trace stopped because the trace buffer filled up.
42730
42731@item tdisconnected:0
42732The trace stopped because @value{GDBN} disconnected from the target.
42733
42734@item tpasscount:@var{tpnum}
42735The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
42736
6c28cbf2
SS
42737@item terror:@var{text}:@var{tpnum}
42738The trace stopped because tracepoint @var{tpnum} had an error. The
42739string @var{text} is available to describe the nature of the error
697aa1b7
EZ
42740(for instance, a divide by zero in the condition expression); it
42741is hex encoded.
6c28cbf2 42742
4daf5ac0
SS
42743@item tunknown:0
42744The trace stopped for some other reason.
42745
42746@end table
42747
33da3f1c
SS
42748Additional optional fields supply statistical and other information.
42749Although not required, they are extremely useful for users monitoring
42750the progress of a trace run. If a trace has stopped, and these
42751numbers are reported, they must reflect the state of the just-stopped
42752trace.
4daf5ac0 42753
9d29849a 42754@table @samp
4daf5ac0
SS
42755
42756@item tframes:@var{n}
42757The number of trace frames in the buffer.
42758
42759@item tcreated:@var{n}
42760The total number of trace frames created during the run. This may
42761be larger than the trace frame count, if the buffer is circular.
42762
42763@item tsize:@var{n}
42764The total size of the trace buffer, in bytes.
42765
42766@item tfree:@var{n}
42767The number of bytes still unused in the buffer.
42768
33da3f1c
SS
42769@item circular:@var{n}
42770The value of the circular trace buffer flag. @code{1} means that the
42771trace buffer is circular and old trace frames will be discarded if
42772necessary to make room, @code{0} means that the trace buffer is linear
42773and may fill up.
42774
42775@item disconn:@var{n}
42776The value of the disconnected tracing flag. @code{1} means that
42777tracing will continue after @value{GDBN} disconnects, @code{0} means
42778that the trace run will stop.
42779
9d29849a
JB
42780@end table
42781
f196051f
SS
42782@item qTP:@var{tp}:@var{addr}
42783@cindex tracepoint status, remote request
42784@cindex @samp{qTP} packet
42785Ask the stub for the current state of tracepoint number @var{tp} at
42786address @var{addr}.
42787
42788Replies:
42789@table @samp
42790@item V@var{hits}:@var{usage}
42791The tracepoint has been hit @var{hits} times so far during the trace
42792run, and accounts for @var{usage} in the trace buffer. Note that
42793@code{while-stepping} steps are not counted as separate hits, but the
42794steps' space consumption is added into the usage number.
42795
42796@end table
42797
f61e138d
SS
42798@item qTV:@var{var}
42799@cindex trace state variable value, remote request
42800@cindex @samp{qTV} packet
42801Ask the stub for the value of the trace state variable number @var{var}.
42802
42803Replies:
42804@table @samp
42805@item V@var{value}
42806The value of the variable is @var{value}. This will be the current
42807value of the variable if the user is examining a running target, or a
42808saved value if the variable was collected in the trace frame that the
42809user is looking at. Note that multiple requests may result in
42810different reply values, such as when requesting values while the
42811program is running.
42812
42813@item U
42814The value of the variable is unknown. This would occur, for example,
42815if the user is examining a trace frame in which the requested variable
42816was not collected.
9d29849a
JB
42817@end table
42818
d5551862 42819@item qTfP
c614397c 42820@cindex @samp{qTfP} packet
d5551862 42821@itemx qTsP
c614397c 42822@cindex @samp{qTsP} packet
d5551862
SS
42823These packets request data about tracepoints that are being used by
42824the target. @value{GDBN} sends @code{qTfP} to get the first piece
42825of data, and multiple @code{qTsP} to get additional pieces. Replies
42826to these packets generally take the form of the @code{QTDP} packets
42827that define tracepoints. (FIXME add detailed syntax)
42828
00bf0b85 42829@item qTfV
c614397c 42830@cindex @samp{qTfV} packet
00bf0b85 42831@itemx qTsV
c614397c 42832@cindex @samp{qTsV} packet
00bf0b85
SS
42833These packets request data about trace state variables that are on the
42834target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
42835and multiple @code{qTsV} to get additional variables. Replies to
42836these packets follow the syntax of the @code{QTDV} packets that define
42837trace state variables.
42838
0fb4aa4b
PA
42839@item qTfSTM
42840@itemx qTsSTM
16bdd41f
YQ
42841@anchor{qTfSTM}
42842@anchor{qTsSTM}
c614397c
YQ
42843@cindex @samp{qTfSTM} packet
42844@cindex @samp{qTsSTM} packet
0fb4aa4b
PA
42845These packets request data about static tracepoint markers that exist
42846in the target program. @value{GDBN} sends @code{qTfSTM} to get the
42847first piece of data, and multiple @code{qTsSTM} to get additional
42848pieces. Replies to these packets take the following form:
42849
42850Reply:
42851@table @samp
42852@item m @var{address}:@var{id}:@var{extra}
42853A single marker
42854@item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
42855a comma-separated list of markers
42856@item l
42857(lower case letter @samp{L}) denotes end of list.
42858@item E @var{nn}
697aa1b7 42859An error occurred. The error number @var{nn} is given as hex digits.
d57350ea 42860@item @w{}
0fb4aa4b
PA
42861An empty reply indicates that the request is not supported by the
42862stub.
42863@end table
42864
697aa1b7 42865The @var{address} is encoded in hex;
0fb4aa4b
PA
42866@var{id} and @var{extra} are strings encoded in hex.
42867
42868In response to each query, the target will reply with a list of one or
42869more markers, separated by commas. @value{GDBN} will respond to each
42870reply with a request for more markers (using the @samp{qs} form of the
42871query), until the target responds with @samp{l} (lower-case ell, for
42872@dfn{last}).
42873
42874@item qTSTMat:@var{address}
16bdd41f 42875@anchor{qTSTMat}
c614397c 42876@cindex @samp{qTSTMat} packet
0fb4aa4b
PA
42877This packets requests data about static tracepoint markers in the
42878target program at @var{address}. Replies to this packet follow the
42879syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
42880tracepoint markers.
42881
00bf0b85 42882@item QTSave:@var{filename}
c614397c 42883@cindex @samp{QTSave} packet
00bf0b85 42884This packet directs the target to save trace data to the file name
697aa1b7 42885@var{filename} in the target's filesystem. The @var{filename} is encoded
00bf0b85
SS
42886as a hex string; the interpretation of the file name (relative vs
42887absolute, wild cards, etc) is up to the target.
42888
42889@item qTBuffer:@var{offset},@var{len}
c614397c 42890@cindex @samp{qTBuffer} packet
00bf0b85
SS
42891Return up to @var{len} bytes of the current contents of trace buffer,
42892starting at @var{offset}. The trace buffer is treated as if it were
42893a contiguous collection of traceframes, as per the trace file format.
42894The reply consists as many hex-encoded bytes as the target can deliver
42895in a packet; it is not an error to return fewer than were asked for.
42896A reply consisting of just @code{l} indicates that no bytes are
42897available.
42898
4daf5ac0
SS
42899@item QTBuffer:circular:@var{value}
42900This packet directs the target to use a circular trace buffer if
42901@var{value} is 1, or a linear buffer if the value is 0.
42902
f6f899bf 42903@item QTBuffer:size:@var{size}
28abe188
EZ
42904@anchor{QTBuffer-size}
42905@cindex @samp{QTBuffer size} packet
f6f899bf
HAQ
42906This packet directs the target to make the trace buffer be of size
42907@var{size} if possible. A value of @code{-1} tells the target to
42908use whatever size it prefers.
42909
f196051f 42910@item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
c614397c 42911@cindex @samp{QTNotes} packet
f196051f
SS
42912This packet adds optional textual notes to the trace run. Allowable
42913types include @code{user}, @code{notes}, and @code{tstop}, the
42914@var{text} fields are arbitrary strings, hex-encoded.
42915
f61e138d 42916@end table
9d29849a 42917
dde08ee1
PA
42918@subsection Relocate instruction reply packet
42919When installing fast tracepoints in memory, the target may need to
42920relocate the instruction currently at the tracepoint address to a
42921different address in memory. For most instructions, a simple copy is
42922enough, but, for example, call instructions that implicitly push the
42923return address on the stack, and relative branches or other
42924PC-relative instructions require offset adjustment, so that the effect
42925of executing the instruction at a different address is the same as if
42926it had executed in the original location.
42927
42928In response to several of the tracepoint packets, the target may also
42929respond with a number of intermediate @samp{qRelocInsn} request
42930packets before the final result packet, to have @value{GDBN} handle
42931this relocation operation. If a packet supports this mechanism, its
42932documentation will explicitly say so. See for example the above
42933descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
42934format of the request is:
42935
42936@table @samp
42937@item qRelocInsn:@var{from};@var{to}
42938
42939This requests @value{GDBN} to copy instruction at address @var{from}
42940to address @var{to}, possibly adjusted so that executing the
42941instruction at @var{to} has the same effect as executing it at
42942@var{from}. @value{GDBN} writes the adjusted instruction to target
42943memory starting at @var{to}.
42944@end table
42945
42946Replies:
42947@table @samp
42948@item qRelocInsn:@var{adjusted_size}
697aa1b7 42949Informs the stub the relocation is complete. The @var{adjusted_size} is
dde08ee1
PA
42950the length in bytes of resulting relocated instruction sequence.
42951@item E @var{NN}
42952A badly formed request was detected, or an error was encountered while
42953relocating the instruction.
42954@end table
42955
a6b151f1
DJ
42956@node Host I/O Packets
42957@section Host I/O Packets
42958@cindex Host I/O, remote protocol
42959@cindex file transfer, remote protocol
42960
42961The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
42962operations on the far side of a remote link. For example, Host I/O is
42963used to upload and download files to a remote target with its own
42964filesystem. Host I/O uses the same constant values and data structure
42965layout as the target-initiated File-I/O protocol. However, the
42966Host I/O packets are structured differently. The target-initiated
42967protocol relies on target memory to store parameters and buffers.
42968Host I/O requests are initiated by @value{GDBN}, and the
42969target's memory is not involved. @xref{File-I/O Remote Protocol
42970Extension}, for more details on the target-initiated protocol.
42971
42972The Host I/O request packets all encode a single operation along with
42973its arguments. They have this format:
42974
42975@table @samp
42976
42977@item vFile:@var{operation}: @var{parameter}@dots{}
42978@var{operation} is the name of the particular request; the target
42979should compare the entire packet name up to the second colon when checking
42980for a supported operation. The format of @var{parameter} depends on
42981the operation. Numbers are always passed in hexadecimal. Negative
42982numbers have an explicit minus sign (i.e.@: two's complement is not
42983used). Strings (e.g.@: filenames) are encoded as a series of
42984hexadecimal bytes. The last argument to a system call may be a
42985buffer of escaped binary data (@pxref{Binary Data}).
42986
42987@end table
42988
42989The valid responses to Host I/O packets are:
42990
42991@table @samp
42992
42993@item F @var{result} [, @var{errno}] [; @var{attachment}]
42994@var{result} is the integer value returned by this operation, usually
42995non-negative for success and -1 for errors. If an error has occured,
697aa1b7 42996@var{errno} will be included in the result specifying a
a6b151f1
DJ
42997value defined by the File-I/O protocol (@pxref{Errno Values}). For
42998operations which return data, @var{attachment} supplies the data as a
42999binary buffer. Binary buffers in response packets are escaped in the
43000normal way (@pxref{Binary Data}). See the individual packet
43001documentation for the interpretation of @var{result} and
43002@var{attachment}.
43003
d57350ea 43004@item @w{}
a6b151f1
DJ
43005An empty response indicates that this operation is not recognized.
43006
43007@end table
43008
43009These are the supported Host I/O operations:
43010
43011@table @samp
697aa1b7
EZ
43012@item vFile:open: @var{filename}, @var{flags}, @var{mode}
43013Open a file at @var{filename} and return a file descriptor for it, or
43014return -1 if an error occurs. The @var{filename} is a string,
a6b151f1
DJ
43015@var{flags} is an integer indicating a mask of open flags
43016(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
43017of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 43018@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
43019
43020@item vFile:close: @var{fd}
43021Close the open file corresponding to @var{fd} and return 0, or
43022-1 if an error occurs.
43023
43024@item vFile:pread: @var{fd}, @var{count}, @var{offset}
43025Read data from the open file corresponding to @var{fd}. Up to
43026@var{count} bytes will be read from the file, starting at @var{offset}
43027relative to the start of the file. The target may read fewer bytes;
43028common reasons include packet size limits and an end-of-file
43029condition. The number of bytes read is returned. Zero should only be
43030returned for a successful read at the end of the file, or if
43031@var{count} was zero.
43032
43033The data read should be returned as a binary attachment on success.
43034If zero bytes were read, the response should include an empty binary
43035attachment (i.e.@: a trailing semicolon). The return value is the
43036number of target bytes read; the binary attachment may be longer if
43037some characters were escaped.
43038
43039@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
43040Write @var{data} (a binary buffer) to the open file corresponding
43041to @var{fd}. Start the write at @var{offset} from the start of the
43042file. Unlike many @code{write} system calls, there is no
43043separate @var{count} argument; the length of @var{data} in the
fb092e09 43044packet is used. @samp{vFile:pwrite} returns the number of bytes written,
a6b151f1
DJ
43045which may be shorter than the length of @var{data}, or -1 if an
43046error occurred.
43047
0a93529c
GB
43048@item vFile:fstat: @var{fd}
43049Get information about the open file corresponding to @var{fd}.
43050On success the information is returned as a binary attachment
43051and the return value is the size of this attachment in bytes.
43052If an error occurs the return value is -1. The format of the
43053returned binary attachment is as described in @ref{struct stat}.
43054
697aa1b7
EZ
43055@item vFile:unlink: @var{filename}
43056Delete the file at @var{filename} on the target. Return 0,
43057or -1 if an error occurs. The @var{filename} is a string.
a6b151f1 43058
b9e7b9c3
UW
43059@item vFile:readlink: @var{filename}
43060Read value of symbolic link @var{filename} on the target. Return
43061the number of bytes read, or -1 if an error occurs.
43062
43063The data read should be returned as a binary attachment on success.
43064If zero bytes were read, the response should include an empty binary
43065attachment (i.e.@: a trailing semicolon). The return value is the
43066number of target bytes read; the binary attachment may be longer if
43067some characters were escaped.
43068
15a201c8
GB
43069@item vFile:setfs: @var{pid}
43070Select the filesystem on which @code{vFile} operations with
43071@var{filename} arguments will operate. This is required for
43072@value{GDBN} to be able to access files on remote targets where
43073the remote stub does not share a common filesystem with the
43074inferior(s).
43075
43076If @var{pid} is nonzero, select the filesystem as seen by process
43077@var{pid}. If @var{pid} is zero, select the filesystem as seen by
43078the remote stub. Return 0 on success, or -1 if an error occurs.
43079If @code{vFile:setfs:} indicates success, the selected filesystem
43080remains selected until the next successful @code{vFile:setfs:}
43081operation.
43082
a6b151f1
DJ
43083@end table
43084
9a6253be
KB
43085@node Interrupts
43086@section Interrupts
43087@cindex interrupts (remote protocol)
de979965 43088@anchor{interrupting remote targets}
9a6253be 43089
de979965
PA
43090In all-stop mode, when a program on the remote target is running,
43091@value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
43092@code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
43093is specified via @value{GDBN}'s @samp{interrupt-sequence}.
9a6253be
KB
43094
43095The precise meaning of @code{BREAK} is defined by the transport
8775bb90
MS
43096mechanism and may, in fact, be undefined. @value{GDBN} does not
43097currently define a @code{BREAK} mechanism for any of the network
43098interfaces except for TCP, in which case @value{GDBN} sends the
43099@code{telnet} BREAK sequence.
9a6253be
KB
43100
43101@samp{Ctrl-C}, on the other hand, is defined and implemented for all
43102transport mechanisms. It is represented by sending the single byte
43103@code{0x03} without any of the usual packet overhead described in
43104the Overview section (@pxref{Overview}). When a @code{0x03} byte is
43105transmitted as part of a packet, it is considered to be packet data
43106and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 43107(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
43108@code{0x03} as part of its packet.
43109
9a7071a8
JB
43110@code{BREAK} followed by @code{g} is also known as Magic SysRq g.
43111When Linux kernel receives this sequence from serial port,
43112it stops execution and connects to gdb.
43113
de979965
PA
43114In non-stop mode, because packet resumptions are asynchronous
43115(@pxref{vCont packet}), @value{GDBN} is always free to send a remote
43116command to the remote stub, even when the target is running. For that
43117reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
43118packet}) with the usual packet framing instead of the single byte
43119@code{0x03}.
43120
9a6253be
KB
43121Stubs are not required to recognize these interrupt mechanisms and the
43122precise meaning associated with receipt of the interrupt is
8b23ecc4
SL
43123implementation defined. If the target supports debugging of multiple
43124threads and/or processes, it should attempt to interrupt all
43125currently-executing threads and processes.
43126If the stub is successful at interrupting the
43127running program, it should send one of the stop
43128reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
43129of successfully stopping the program in all-stop mode, and a stop reply
43130for each stopped thread in non-stop mode.
43131Interrupts received while the
cde67b27
YQ
43132program is stopped are queued and the program will be interrupted when
43133it is resumed next time.
8b23ecc4
SL
43134
43135@node Notification Packets
43136@section Notification Packets
43137@cindex notification packets
43138@cindex packets, notification
43139
43140The @value{GDBN} remote serial protocol includes @dfn{notifications},
43141packets that require no acknowledgment. Both the GDB and the stub
43142may send notifications (although the only notifications defined at
43143present are sent by the stub). Notifications carry information
43144without incurring the round-trip latency of an acknowledgment, and so
43145are useful for low-impact communications where occasional packet loss
43146is not a problem.
43147
43148A notification packet has the form @samp{% @var{data} #
43149@var{checksum}}, where @var{data} is the content of the notification,
43150and @var{checksum} is a checksum of @var{data}, computed and formatted
43151as for ordinary @value{GDBN} packets. A notification's @var{data}
43152never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
43153receiving a notification, the recipient sends no @samp{+} or @samp{-}
43154to acknowledge the notification's receipt or to report its corruption.
43155
43156Every notification's @var{data} begins with a name, which contains no
43157colon characters, followed by a colon character.
43158
43159Recipients should silently ignore corrupted notifications and
43160notifications they do not understand. Recipients should restart
43161timeout periods on receipt of a well-formed notification, whether or
43162not they understand it.
43163
43164Senders should only send the notifications described here when this
43165protocol description specifies that they are permitted. In the
43166future, we may extend the protocol to permit existing notifications in
43167new contexts; this rule helps older senders avoid confusing newer
43168recipients.
43169
43170(Older versions of @value{GDBN} ignore bytes received until they see
43171the @samp{$} byte that begins an ordinary packet, so new stubs may
43172transmit notifications without fear of confusing older clients. There
43173are no notifications defined for @value{GDBN} to send at the moment, but we
43174assume that most older stubs would ignore them, as well.)
43175
8dbe8ece 43176Each notification is comprised of three parts:
8b23ecc4 43177@table @samp
8dbe8ece
YQ
43178@item @var{name}:@var{event}
43179The notification packet is sent by the side that initiates the
43180exchange (currently, only the stub does that), with @var{event}
697aa1b7
EZ
43181carrying the specific information about the notification, and
43182@var{name} specifying the name of the notification.
8dbe8ece
YQ
43183@item @var{ack}
43184The acknowledge sent by the other side, usually @value{GDBN}, to
43185acknowledge the exchange and request the event.
43186@end table
43187
43188The purpose of an asynchronous notification mechanism is to report to
43189@value{GDBN} that something interesting happened in the remote stub.
43190
43191The remote stub may send notification @var{name}:@var{event}
43192at any time, but @value{GDBN} acknowledges the notification when
43193appropriate. The notification event is pending before @value{GDBN}
43194acknowledges. Only one notification at a time may be pending; if
43195additional events occur before @value{GDBN} has acknowledged the
43196previous notification, they must be queued by the stub for later
43197synchronous transmission in response to @var{ack} packets from
43198@value{GDBN}. Because the notification mechanism is unreliable,
43199the stub is permitted to resend a notification if it believes
43200@value{GDBN} may not have received it.
43201
43202Specifically, notifications may appear when @value{GDBN} is not
43203otherwise reading input from the stub, or when @value{GDBN} is
43204expecting to read a normal synchronous response or a
43205@samp{+}/@samp{-} acknowledgment to a packet it has sent.
43206Notification packets are distinct from any other communication from
43207the stub so there is no ambiguity.
43208
43209After receiving a notification, @value{GDBN} shall acknowledge it by
43210sending a @var{ack} packet as a regular, synchronous request to the
43211stub. Such acknowledgment is not required to happen immediately, as
43212@value{GDBN} is permitted to send other, unrelated packets to the
43213stub first, which the stub should process normally.
43214
43215Upon receiving a @var{ack} packet, if the stub has other queued
43216events to report to @value{GDBN}, it shall respond by sending a
43217normal @var{event}. @value{GDBN} shall then send another @var{ack}
43218packet to solicit further responses; again, it is permitted to send
43219other, unrelated packets as well which the stub should process
43220normally.
43221
43222If the stub receives a @var{ack} packet and there are no additional
43223@var{event} to report, the stub shall return an @samp{OK} response.
43224At this point, @value{GDBN} has finished processing a notification
43225and the stub has completed sending any queued events. @value{GDBN}
43226won't accept any new notifications until the final @samp{OK} is
43227received . If further notification events occur, the stub shall send
43228a new notification, @value{GDBN} shall accept the notification, and
43229the process shall be repeated.
43230
43231The process of asynchronous notification can be illustrated by the
43232following example:
43233@smallexample
4435e1cc 43234<- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
8dbe8ece
YQ
43235@code{...}
43236-> @code{vStopped}
43237<- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
43238-> @code{vStopped}
43239<- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
43240-> @code{vStopped}
43241<- @code{OK}
43242@end smallexample
43243
43244The following notifications are defined:
43245@multitable @columnfractions 0.12 0.12 0.38 0.38
43246
43247@item Notification
43248@tab Ack
43249@tab Event
43250@tab Description
43251
43252@item Stop
43253@tab vStopped
43254@tab @var{reply}. The @var{reply} has the form of a stop reply, as
8b23ecc4
SL
43255described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
43256for information on how these notifications are acknowledged by
43257@value{GDBN}.
8dbe8ece
YQ
43258@tab Report an asynchronous stop event in non-stop mode.
43259
43260@end multitable
8b23ecc4
SL
43261
43262@node Remote Non-Stop
43263@section Remote Protocol Support for Non-Stop Mode
43264
43265@value{GDBN}'s remote protocol supports non-stop debugging of
43266multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
43267supports non-stop mode, it should report that to @value{GDBN} by including
43268@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
43269
43270@value{GDBN} typically sends a @samp{QNonStop} packet only when
43271establishing a new connection with the stub. Entering non-stop mode
43272does not alter the state of any currently-running threads, but targets
43273must stop all threads in any already-attached processes when entering
43274all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
43275probe the target state after a mode change.
43276
43277In non-stop mode, when an attached process encounters an event that
43278would otherwise be reported with a stop reply, it uses the
43279asynchronous notification mechanism (@pxref{Notification Packets}) to
43280inform @value{GDBN}. In contrast to all-stop mode, where all threads
43281in all processes are stopped when a stop reply is sent, in non-stop
43282mode only the thread reporting the stop event is stopped. That is,
43283when reporting a @samp{S} or @samp{T} response to indicate completion
43284of a step operation, hitting a breakpoint, or a fault, only the
43285affected thread is stopped; any other still-running threads continue
43286to run. When reporting a @samp{W} or @samp{X} response, all running
43287threads belonging to other attached processes continue to run.
43288
8b23ecc4
SL
43289In non-stop mode, the target shall respond to the @samp{?} packet as
43290follows. First, any incomplete stop reply notification/@samp{vStopped}
43291sequence in progress is abandoned. The target must begin a new
43292sequence reporting stop events for all stopped threads, whether or not
43293it has previously reported those events to @value{GDBN}. The first
43294stop reply is sent as a synchronous reply to the @samp{?} packet, and
43295subsequent stop replies are sent as responses to @samp{vStopped} packets
43296using the mechanism described above. The target must not send
43297asynchronous stop reply notifications until the sequence is complete.
43298If all threads are running when the target receives the @samp{?} packet,
43299or if the target is not attached to any process, it shall respond
43300@samp{OK}.
9a6253be 43301
f7e6eed5
PA
43302If the stub supports non-stop mode, it should also support the
43303@samp{swbreak} stop reason if software breakpoints are supported, and
43304the @samp{hwbreak} stop reason if hardware breakpoints are supported
43305(@pxref{swbreak stop reason}). This is because given the asynchronous
43306nature of non-stop mode, between the time a thread hits a breakpoint
43307and the time the event is finally processed by @value{GDBN}, the
43308breakpoint may have already been removed from the target. Due to
43309this, @value{GDBN} needs to be able to tell whether a trap stop was
43310caused by a delayed breakpoint event, which should be ignored, as
43311opposed to a random trap signal, which should be reported to the user.
43312Note the @samp{swbreak} feature implies that the target is responsible
43313for adjusting the PC when a software breakpoint triggers, if
43314necessary, such as on the x86 architecture.
43315
a6f3e723
SL
43316@node Packet Acknowledgment
43317@section Packet Acknowledgment
43318
43319@cindex acknowledgment, for @value{GDBN} remote
43320@cindex packet acknowledgment, for @value{GDBN} remote
43321By default, when either the host or the target machine receives a packet,
43322the first response expected is an acknowledgment: either @samp{+} (to indicate
43323the package was received correctly) or @samp{-} (to request retransmission).
43324This mechanism allows the @value{GDBN} remote protocol to operate over
43325unreliable transport mechanisms, such as a serial line.
43326
43327In cases where the transport mechanism is itself reliable (such as a pipe or
43328TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
43329It may be desirable to disable them in that case to reduce communication
43330overhead, or for other reasons. This can be accomplished by means of the
43331@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
43332
43333When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
43334expect @samp{+}/@samp{-} protocol acknowledgments. The packet
43335and response format still includes the normal checksum, as described in
43336@ref{Overview}, but the checksum may be ignored by the receiver.
43337
43338If the stub supports @samp{QStartNoAckMode} and prefers to operate in
43339no-acknowledgment mode, it should report that to @value{GDBN}
43340by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
43341@pxref{qSupported}.
43342If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
43343disabled via the @code{set remote noack-packet off} command
43344(@pxref{Remote Configuration}),
43345@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
43346Only then may the stub actually turn off packet acknowledgments.
43347@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
43348response, which can be safely ignored by the stub.
43349
43350Note that @code{set remote noack-packet} command only affects negotiation
43351between @value{GDBN} and the stub when subsequent connections are made;
43352it does not affect the protocol acknowledgment state for any current
43353connection.
43354Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
43355new connection is established,
43356there is also no protocol request to re-enable the acknowledgments
43357for the current connection, once disabled.
43358
ee2d5c50
AC
43359@node Examples
43360@section Examples
eb12ee30 43361
8e04817f
AC
43362Example sequence of a target being re-started. Notice how the restart
43363does not get any direct output:
eb12ee30 43364
474c8240 43365@smallexample
d2c6833e
AC
43366-> @code{R00}
43367<- @code{+}
8e04817f 43368@emph{target restarts}
d2c6833e 43369-> @code{?}
8e04817f 43370<- @code{+}
d2c6833e
AC
43371<- @code{T001:1234123412341234}
43372-> @code{+}
474c8240 43373@end smallexample
eb12ee30 43374
8e04817f 43375Example sequence of a target being stepped by a single instruction:
eb12ee30 43376
474c8240 43377@smallexample
d2c6833e 43378-> @code{G1445@dots{}}
8e04817f 43379<- @code{+}
d2c6833e
AC
43380-> @code{s}
43381<- @code{+}
43382@emph{time passes}
43383<- @code{T001:1234123412341234}
8e04817f 43384-> @code{+}
d2c6833e 43385-> @code{g}
8e04817f 43386<- @code{+}
d2c6833e
AC
43387<- @code{1455@dots{}}
43388-> @code{+}
474c8240 43389@end smallexample
eb12ee30 43390
79a6e687
BW
43391@node File-I/O Remote Protocol Extension
43392@section File-I/O Remote Protocol Extension
0ce1b118
CV
43393@cindex File-I/O remote protocol extension
43394
43395@menu
43396* File-I/O Overview::
79a6e687
BW
43397* Protocol Basics::
43398* The F Request Packet::
43399* The F Reply Packet::
43400* The Ctrl-C Message::
0ce1b118 43401* Console I/O::
79a6e687 43402* List of Supported Calls::
db2e3e2e 43403* Protocol-specific Representation of Datatypes::
0ce1b118
CV
43404* Constants::
43405* File-I/O Examples::
43406@end menu
43407
43408@node File-I/O Overview
43409@subsection File-I/O Overview
43410@cindex file-i/o overview
43411
9c16f35a 43412The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 43413target to use the host's file system and console I/O to perform various
0ce1b118 43414system calls. System calls on the target system are translated into a
fc320d37
SL
43415remote protocol packet to the host system, which then performs the needed
43416actions and returns a response packet to the target system.
0ce1b118
CV
43417This simulates file system operations even on targets that lack file systems.
43418
fc320d37
SL
43419The protocol is defined to be independent of both the host and target systems.
43420It uses its own internal representation of datatypes and values. Both
0ce1b118 43421@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
43422translating the system-dependent value representations into the internal
43423protocol representations when data is transmitted.
0ce1b118 43424
fc320d37
SL
43425The communication is synchronous. A system call is possible only when
43426@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
43427or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 43428the target is stopped to allow deterministic access to the target's
fc320d37
SL
43429memory. Therefore File-I/O is not interruptible by target signals. On
43430the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 43431(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
43432
43433The target's request to perform a host system call does not finish
43434the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
43435after finishing the system call, the target returns to continuing the
43436previous activity (continue, step). No additional continue or step
43437request from @value{GDBN} is required.
43438
43439@smallexample
f7dc1244 43440(@value{GDBP}) continue
0ce1b118
CV
43441 <- target requests 'system call X'
43442 target is stopped, @value{GDBN} executes system call
3f94c067
BW
43443 -> @value{GDBN} returns result
43444 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
43445 <- target hits breakpoint and sends a Txx packet
43446@end smallexample
43447
fc320d37
SL
43448The protocol only supports I/O on the console and to regular files on
43449the host file system. Character or block special devices, pipes,
43450named pipes, sockets or any other communication method on the host
0ce1b118
CV
43451system are not supported by this protocol.
43452
8b23ecc4
SL
43453File I/O is not supported in non-stop mode.
43454
79a6e687
BW
43455@node Protocol Basics
43456@subsection Protocol Basics
0ce1b118
CV
43457@cindex protocol basics, file-i/o
43458
fc320d37
SL
43459The File-I/O protocol uses the @code{F} packet as the request as well
43460as reply packet. Since a File-I/O system call can only occur when
43461@value{GDBN} is waiting for a response from the continuing or stepping target,
43462the File-I/O request is a reply that @value{GDBN} has to expect as a result
43463of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
43464This @code{F} packet contains all information needed to allow @value{GDBN}
43465to call the appropriate host system call:
43466
43467@itemize @bullet
b383017d 43468@item
0ce1b118
CV
43469A unique identifier for the requested system call.
43470
43471@item
43472All parameters to the system call. Pointers are given as addresses
43473in the target memory address space. Pointers to strings are given as
b383017d 43474pointer/length pair. Numerical values are given as they are.
db2e3e2e 43475Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
43476
43477@end itemize
43478
fc320d37 43479At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
43480
43481@itemize @bullet
b383017d 43482@item
fc320d37
SL
43483If the parameters include pointer values to data needed as input to a
43484system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
43485standard @code{m} packet request. This additional communication has to be
43486expected by the target implementation and is handled as any other @code{m}
43487packet.
43488
43489@item
43490@value{GDBN} translates all value from protocol representation to host
43491representation as needed. Datatypes are coerced into the host types.
43492
43493@item
fc320d37 43494@value{GDBN} calls the system call.
0ce1b118
CV
43495
43496@item
43497It then coerces datatypes back to protocol representation.
43498
43499@item
fc320d37
SL
43500If the system call is expected to return data in buffer space specified
43501by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
43502target using a @code{M} or @code{X} packet. This packet has to be expected
43503by the target implementation and is handled as any other @code{M} or @code{X}
43504packet.
43505
43506@end itemize
43507
43508Eventually @value{GDBN} replies with another @code{F} packet which contains all
43509necessary information for the target to continue. This at least contains
43510
43511@itemize @bullet
43512@item
43513Return value.
43514
43515@item
43516@code{errno}, if has been changed by the system call.
43517
43518@item
43519``Ctrl-C'' flag.
43520
43521@end itemize
43522
43523After having done the needed type and value coercion, the target continues
43524the latest continue or step action.
43525
79a6e687
BW
43526@node The F Request Packet
43527@subsection The @code{F} Request Packet
0ce1b118
CV
43528@cindex file-i/o request packet
43529@cindex @code{F} request packet
43530
43531The @code{F} request packet has the following format:
43532
43533@table @samp
fc320d37 43534@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
43535
43536@var{call-id} is the identifier to indicate the host system call to be called.
43537This is just the name of the function.
43538
fc320d37
SL
43539@var{parameter@dots{}} are the parameters to the system call.
43540Parameters are hexadecimal integer values, either the actual values in case
43541of scalar datatypes, pointers to target buffer space in case of compound
43542datatypes and unspecified memory areas, or pointer/length pairs in case
43543of string parameters. These are appended to the @var{call-id} as a
43544comma-delimited list. All values are transmitted in ASCII
43545string representation, pointer/length pairs separated by a slash.
0ce1b118 43546
b383017d 43547@end table
0ce1b118 43548
fc320d37 43549
0ce1b118 43550
79a6e687
BW
43551@node The F Reply Packet
43552@subsection The @code{F} Reply Packet
0ce1b118
CV
43553@cindex file-i/o reply packet
43554@cindex @code{F} reply packet
43555
43556The @code{F} reply packet has the following format:
43557
43558@table @samp
43559
d3bdde98 43560@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
43561
43562@var{retcode} is the return code of the system call as hexadecimal value.
43563
db2e3e2e
BW
43564@var{errno} is the @code{errno} set by the call, in protocol-specific
43565representation.
0ce1b118
CV
43566This parameter can be omitted if the call was successful.
43567
fc320d37
SL
43568@var{Ctrl-C flag} is only sent if the user requested a break. In this
43569case, @var{errno} must be sent as well, even if the call was successful.
43570The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
43571
43572@smallexample
43573F0,0,C
43574@end smallexample
43575
43576@noindent
fc320d37 43577or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
43578
43579@smallexample
43580F-1,4,C
43581@end smallexample
43582
43583@noindent
db2e3e2e 43584assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
43585
43586@end table
43587
0ce1b118 43588
79a6e687
BW
43589@node The Ctrl-C Message
43590@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
43591@cindex ctrl-c message, in file-i/o protocol
43592
c8aa23ab 43593If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 43594reply packet (@pxref{The F Reply Packet}),
fc320d37 43595the target should behave as if it had
0ce1b118 43596gotten a break message. The meaning for the target is ``system call
fc320d37 43597interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 43598(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 43599packet.
fc320d37
SL
43600
43601It's important for the target to know in which
43602state the system call was interrupted. There are two possible cases:
0ce1b118
CV
43603
43604@itemize @bullet
43605@item
43606The system call hasn't been performed on the host yet.
43607
43608@item
43609The system call on the host has been finished.
43610
43611@end itemize
43612
43613These two states can be distinguished by the target by the value of the
43614returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
43615call hasn't been performed. This is equivalent to the @code{EINTR} handling
43616on POSIX systems. In any other case, the target may presume that the
fc320d37 43617system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
43618as if the break message arrived right after the system call.
43619
fc320d37 43620@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
43621yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
43622@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
43623before the user requests a break, the full action must be finished by
43624@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
43625The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
43626or the full action has been completed.
43627
43628@node Console I/O
43629@subsection Console I/O
43630@cindex console i/o as part of file-i/o
43631
d3e8051b 43632By default and if not explicitly closed by the target system, the file
0ce1b118
CV
43633descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
43634on the @value{GDBN} console is handled as any other file output operation
43635(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
43636by @value{GDBN} so that after the target read request from file descriptor
436370 all following typing is buffered until either one of the following
43638conditions is met:
43639
43640@itemize @bullet
43641@item
c8aa23ab 43642The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
43643@code{read}
43644system call is treated as finished.
43645
43646@item
7f9087cb 43647The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 43648newline.
0ce1b118
CV
43649
43650@item
c8aa23ab
EZ
43651The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
43652character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
43653
43654@end itemize
43655
fc320d37
SL
43656If the user has typed more characters than fit in the buffer given to
43657the @code{read} call, the trailing characters are buffered in @value{GDBN} until
43658either another @code{read(0, @dots{})} is requested by the target, or debugging
43659is stopped at the user's request.
0ce1b118 43660
0ce1b118 43661
79a6e687
BW
43662@node List of Supported Calls
43663@subsection List of Supported Calls
0ce1b118
CV
43664@cindex list of supported file-i/o calls
43665
43666@menu
43667* open::
43668* close::
43669* read::
43670* write::
43671* lseek::
43672* rename::
43673* unlink::
43674* stat/fstat::
43675* gettimeofday::
43676* isatty::
43677* system::
43678@end menu
43679
43680@node open
43681@unnumberedsubsubsec open
43682@cindex open, file-i/o system call
43683
fc320d37
SL
43684@table @asis
43685@item Synopsis:
0ce1b118 43686@smallexample
0ce1b118
CV
43687int open(const char *pathname, int flags);
43688int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
43689@end smallexample
43690
fc320d37
SL
43691@item Request:
43692@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
43693
0ce1b118 43694@noindent
fc320d37 43695@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
43696
43697@table @code
b383017d 43698@item O_CREAT
0ce1b118
CV
43699If the file does not exist it will be created. The host
43700rules apply as far as file ownership and time stamps
43701are concerned.
43702
b383017d 43703@item O_EXCL
fc320d37 43704When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
43705an error and open() fails.
43706
b383017d 43707@item O_TRUNC
0ce1b118 43708If the file already exists and the open mode allows
fc320d37
SL
43709writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
43710truncated to zero length.
0ce1b118 43711
b383017d 43712@item O_APPEND
0ce1b118
CV
43713The file is opened in append mode.
43714
b383017d 43715@item O_RDONLY
0ce1b118
CV
43716The file is opened for reading only.
43717
b383017d 43718@item O_WRONLY
0ce1b118
CV
43719The file is opened for writing only.
43720
b383017d 43721@item O_RDWR
0ce1b118 43722The file is opened for reading and writing.
fc320d37 43723@end table
0ce1b118
CV
43724
43725@noindent
fc320d37 43726Other bits are silently ignored.
0ce1b118 43727
0ce1b118
CV
43728
43729@noindent
fc320d37 43730@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
43731
43732@table @code
b383017d 43733@item S_IRUSR
0ce1b118
CV
43734User has read permission.
43735
b383017d 43736@item S_IWUSR
0ce1b118
CV
43737User has write permission.
43738
b383017d 43739@item S_IRGRP
0ce1b118
CV
43740Group has read permission.
43741
b383017d 43742@item S_IWGRP
0ce1b118
CV
43743Group has write permission.
43744
b383017d 43745@item S_IROTH
0ce1b118
CV
43746Others have read permission.
43747
b383017d 43748@item S_IWOTH
0ce1b118 43749Others have write permission.
fc320d37 43750@end table
0ce1b118
CV
43751
43752@noindent
fc320d37 43753Other bits are silently ignored.
0ce1b118 43754
0ce1b118 43755
fc320d37
SL
43756@item Return value:
43757@code{open} returns the new file descriptor or -1 if an error
43758occurred.
0ce1b118 43759
fc320d37 43760@item Errors:
0ce1b118
CV
43761
43762@table @code
b383017d 43763@item EEXIST
fc320d37 43764@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 43765
b383017d 43766@item EISDIR
fc320d37 43767@var{pathname} refers to a directory.
0ce1b118 43768
b383017d 43769@item EACCES
0ce1b118
CV
43770The requested access is not allowed.
43771
43772@item ENAMETOOLONG
fc320d37 43773@var{pathname} was too long.
0ce1b118 43774
b383017d 43775@item ENOENT
fc320d37 43776A directory component in @var{pathname} does not exist.
0ce1b118 43777
b383017d 43778@item ENODEV
fc320d37 43779@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 43780
b383017d 43781@item EROFS
fc320d37 43782@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
43783write access was requested.
43784
b383017d 43785@item EFAULT
fc320d37 43786@var{pathname} is an invalid pointer value.
0ce1b118 43787
b383017d 43788@item ENOSPC
0ce1b118
CV
43789No space on device to create the file.
43790
b383017d 43791@item EMFILE
0ce1b118
CV
43792The process already has the maximum number of files open.
43793
b383017d 43794@item ENFILE
0ce1b118
CV
43795The limit on the total number of files open on the system
43796has been reached.
43797
b383017d 43798@item EINTR
0ce1b118
CV
43799The call was interrupted by the user.
43800@end table
43801
fc320d37
SL
43802@end table
43803
0ce1b118
CV
43804@node close
43805@unnumberedsubsubsec close
43806@cindex close, file-i/o system call
43807
fc320d37
SL
43808@table @asis
43809@item Synopsis:
0ce1b118 43810@smallexample
0ce1b118 43811int close(int fd);
fc320d37 43812@end smallexample
0ce1b118 43813
fc320d37
SL
43814@item Request:
43815@samp{Fclose,@var{fd}}
0ce1b118 43816
fc320d37
SL
43817@item Return value:
43818@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 43819
fc320d37 43820@item Errors:
0ce1b118
CV
43821
43822@table @code
b383017d 43823@item EBADF
fc320d37 43824@var{fd} isn't a valid open file descriptor.
0ce1b118 43825
b383017d 43826@item EINTR
0ce1b118
CV
43827The call was interrupted by the user.
43828@end table
43829
fc320d37
SL
43830@end table
43831
0ce1b118
CV
43832@node read
43833@unnumberedsubsubsec read
43834@cindex read, file-i/o system call
43835
fc320d37
SL
43836@table @asis
43837@item Synopsis:
0ce1b118 43838@smallexample
0ce1b118 43839int read(int fd, void *buf, unsigned int count);
fc320d37 43840@end smallexample
0ce1b118 43841
fc320d37
SL
43842@item Request:
43843@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 43844
fc320d37 43845@item Return value:
0ce1b118
CV
43846On success, the number of bytes read is returned.
43847Zero indicates end of file. If count is zero, read
b383017d 43848returns zero as well. On error, -1 is returned.
0ce1b118 43849
fc320d37 43850@item Errors:
0ce1b118
CV
43851
43852@table @code
b383017d 43853@item EBADF
fc320d37 43854@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
43855reading.
43856
b383017d 43857@item EFAULT
fc320d37 43858@var{bufptr} is an invalid pointer value.
0ce1b118 43859
b383017d 43860@item EINTR
0ce1b118
CV
43861The call was interrupted by the user.
43862@end table
43863
fc320d37
SL
43864@end table
43865
0ce1b118
CV
43866@node write
43867@unnumberedsubsubsec write
43868@cindex write, file-i/o system call
43869
fc320d37
SL
43870@table @asis
43871@item Synopsis:
0ce1b118 43872@smallexample
0ce1b118 43873int write(int fd, const void *buf, unsigned int count);
fc320d37 43874@end smallexample
0ce1b118 43875
fc320d37
SL
43876@item Request:
43877@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 43878
fc320d37 43879@item Return value:
0ce1b118
CV
43880On success, the number of bytes written are returned.
43881Zero indicates nothing was written. On error, -1
43882is returned.
43883
fc320d37 43884@item Errors:
0ce1b118
CV
43885
43886@table @code
b383017d 43887@item EBADF
fc320d37 43888@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
43889writing.
43890
b383017d 43891@item EFAULT
fc320d37 43892@var{bufptr} is an invalid pointer value.
0ce1b118 43893
b383017d 43894@item EFBIG
0ce1b118 43895An attempt was made to write a file that exceeds the
db2e3e2e 43896host-specific maximum file size allowed.
0ce1b118 43897
b383017d 43898@item ENOSPC
0ce1b118
CV
43899No space on device to write the data.
43900
b383017d 43901@item EINTR
0ce1b118
CV
43902The call was interrupted by the user.
43903@end table
43904
fc320d37
SL
43905@end table
43906
0ce1b118
CV
43907@node lseek
43908@unnumberedsubsubsec lseek
43909@cindex lseek, file-i/o system call
43910
fc320d37
SL
43911@table @asis
43912@item Synopsis:
0ce1b118 43913@smallexample
0ce1b118 43914long lseek (int fd, long offset, int flag);
0ce1b118
CV
43915@end smallexample
43916
fc320d37
SL
43917@item Request:
43918@samp{Flseek,@var{fd},@var{offset},@var{flag}}
43919
43920@var{flag} is one of:
0ce1b118
CV
43921
43922@table @code
b383017d 43923@item SEEK_SET
fc320d37 43924The offset is set to @var{offset} bytes.
0ce1b118 43925
b383017d 43926@item SEEK_CUR
fc320d37 43927The offset is set to its current location plus @var{offset}
0ce1b118
CV
43928bytes.
43929
b383017d 43930@item SEEK_END
fc320d37 43931The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
43932bytes.
43933@end table
43934
fc320d37 43935@item Return value:
0ce1b118
CV
43936On success, the resulting unsigned offset in bytes from
43937the beginning of the file is returned. Otherwise, a
43938value of -1 is returned.
43939
fc320d37 43940@item Errors:
0ce1b118
CV
43941
43942@table @code
b383017d 43943@item EBADF
fc320d37 43944@var{fd} is not a valid open file descriptor.
0ce1b118 43945
b383017d 43946@item ESPIPE
fc320d37 43947@var{fd} is associated with the @value{GDBN} console.
0ce1b118 43948
b383017d 43949@item EINVAL
fc320d37 43950@var{flag} is not a proper value.
0ce1b118 43951
b383017d 43952@item EINTR
0ce1b118
CV
43953The call was interrupted by the user.
43954@end table
43955
fc320d37
SL
43956@end table
43957
0ce1b118
CV
43958@node rename
43959@unnumberedsubsubsec rename
43960@cindex rename, file-i/o system call
43961
fc320d37
SL
43962@table @asis
43963@item Synopsis:
0ce1b118 43964@smallexample
0ce1b118 43965int rename(const char *oldpath, const char *newpath);
fc320d37 43966@end smallexample
0ce1b118 43967
fc320d37
SL
43968@item Request:
43969@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 43970
fc320d37 43971@item Return value:
0ce1b118
CV
43972On success, zero is returned. On error, -1 is returned.
43973
fc320d37 43974@item Errors:
0ce1b118
CV
43975
43976@table @code
b383017d 43977@item EISDIR
fc320d37 43978@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
43979directory.
43980
b383017d 43981@item EEXIST
fc320d37 43982@var{newpath} is a non-empty directory.
0ce1b118 43983
b383017d 43984@item EBUSY
fc320d37 43985@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
43986process.
43987
b383017d 43988@item EINVAL
0ce1b118
CV
43989An attempt was made to make a directory a subdirectory
43990of itself.
43991
b383017d 43992@item ENOTDIR
fc320d37
SL
43993A component used as a directory in @var{oldpath} or new
43994path is not a directory. Or @var{oldpath} is a directory
43995and @var{newpath} exists but is not a directory.
0ce1b118 43996
b383017d 43997@item EFAULT
fc320d37 43998@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 43999
b383017d 44000@item EACCES
0ce1b118
CV
44001No access to the file or the path of the file.
44002
44003@item ENAMETOOLONG
b383017d 44004
fc320d37 44005@var{oldpath} or @var{newpath} was too long.
0ce1b118 44006
b383017d 44007@item ENOENT
fc320d37 44008A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 44009
b383017d 44010@item EROFS
0ce1b118
CV
44011The file is on a read-only filesystem.
44012
b383017d 44013@item ENOSPC
0ce1b118
CV
44014The device containing the file has no room for the new
44015directory entry.
44016
b383017d 44017@item EINTR
0ce1b118
CV
44018The call was interrupted by the user.
44019@end table
44020
fc320d37
SL
44021@end table
44022
0ce1b118
CV
44023@node unlink
44024@unnumberedsubsubsec unlink
44025@cindex unlink, file-i/o system call
44026
fc320d37
SL
44027@table @asis
44028@item Synopsis:
0ce1b118 44029@smallexample
0ce1b118 44030int unlink(const char *pathname);
fc320d37 44031@end smallexample
0ce1b118 44032
fc320d37
SL
44033@item Request:
44034@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 44035
fc320d37 44036@item Return value:
0ce1b118
CV
44037On success, zero is returned. On error, -1 is returned.
44038
fc320d37 44039@item Errors:
0ce1b118
CV
44040
44041@table @code
b383017d 44042@item EACCES
0ce1b118
CV
44043No access to the file or the path of the file.
44044
b383017d 44045@item EPERM
0ce1b118
CV
44046The system does not allow unlinking of directories.
44047
b383017d 44048@item EBUSY
fc320d37 44049The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
44050being used by another process.
44051
b383017d 44052@item EFAULT
fc320d37 44053@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
44054
44055@item ENAMETOOLONG
fc320d37 44056@var{pathname} was too long.
0ce1b118 44057
b383017d 44058@item ENOENT
fc320d37 44059A directory component in @var{pathname} does not exist.
0ce1b118 44060
b383017d 44061@item ENOTDIR
0ce1b118
CV
44062A component of the path is not a directory.
44063
b383017d 44064@item EROFS
0ce1b118
CV
44065The file is on a read-only filesystem.
44066
b383017d 44067@item EINTR
0ce1b118
CV
44068The call was interrupted by the user.
44069@end table
44070
fc320d37
SL
44071@end table
44072
0ce1b118
CV
44073@node stat/fstat
44074@unnumberedsubsubsec stat/fstat
44075@cindex fstat, file-i/o system call
44076@cindex stat, file-i/o system call
44077
fc320d37
SL
44078@table @asis
44079@item Synopsis:
0ce1b118 44080@smallexample
0ce1b118
CV
44081int stat(const char *pathname, struct stat *buf);
44082int fstat(int fd, struct stat *buf);
fc320d37 44083@end smallexample
0ce1b118 44084
fc320d37
SL
44085@item Request:
44086@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
44087@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 44088
fc320d37 44089@item Return value:
0ce1b118
CV
44090On success, zero is returned. On error, -1 is returned.
44091
fc320d37 44092@item Errors:
0ce1b118
CV
44093
44094@table @code
b383017d 44095@item EBADF
fc320d37 44096@var{fd} is not a valid open file.
0ce1b118 44097
b383017d 44098@item ENOENT
fc320d37 44099A directory component in @var{pathname} does not exist or the
0ce1b118
CV
44100path is an empty string.
44101
b383017d 44102@item ENOTDIR
0ce1b118
CV
44103A component of the path is not a directory.
44104
b383017d 44105@item EFAULT
fc320d37 44106@var{pathnameptr} is an invalid pointer value.
0ce1b118 44107
b383017d 44108@item EACCES
0ce1b118
CV
44109No access to the file or the path of the file.
44110
44111@item ENAMETOOLONG
fc320d37 44112@var{pathname} was too long.
0ce1b118 44113
b383017d 44114@item EINTR
0ce1b118
CV
44115The call was interrupted by the user.
44116@end table
44117
fc320d37
SL
44118@end table
44119
0ce1b118
CV
44120@node gettimeofday
44121@unnumberedsubsubsec gettimeofday
44122@cindex gettimeofday, file-i/o system call
44123
fc320d37
SL
44124@table @asis
44125@item Synopsis:
0ce1b118 44126@smallexample
0ce1b118 44127int gettimeofday(struct timeval *tv, void *tz);
fc320d37 44128@end smallexample
0ce1b118 44129
fc320d37
SL
44130@item Request:
44131@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 44132
fc320d37 44133@item Return value:
0ce1b118
CV
44134On success, 0 is returned, -1 otherwise.
44135
fc320d37 44136@item Errors:
0ce1b118
CV
44137
44138@table @code
b383017d 44139@item EINVAL
fc320d37 44140@var{tz} is a non-NULL pointer.
0ce1b118 44141
b383017d 44142@item EFAULT
fc320d37
SL
44143@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
44144@end table
44145
0ce1b118
CV
44146@end table
44147
44148@node isatty
44149@unnumberedsubsubsec isatty
44150@cindex isatty, file-i/o system call
44151
fc320d37
SL
44152@table @asis
44153@item Synopsis:
0ce1b118 44154@smallexample
0ce1b118 44155int isatty(int fd);
fc320d37 44156@end smallexample
0ce1b118 44157
fc320d37
SL
44158@item Request:
44159@samp{Fisatty,@var{fd}}
0ce1b118 44160
fc320d37
SL
44161@item Return value:
44162Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 44163
fc320d37 44164@item Errors:
0ce1b118
CV
44165
44166@table @code
b383017d 44167@item EINTR
0ce1b118
CV
44168The call was interrupted by the user.
44169@end table
44170
fc320d37
SL
44171@end table
44172
44173Note that the @code{isatty} call is treated as a special case: it returns
441741 to the target if the file descriptor is attached
44175to the @value{GDBN} console, 0 otherwise. Implementing through system calls
44176would require implementing @code{ioctl} and would be more complex than
44177needed.
44178
44179
0ce1b118
CV
44180@node system
44181@unnumberedsubsubsec system
44182@cindex system, file-i/o system call
44183
fc320d37
SL
44184@table @asis
44185@item Synopsis:
0ce1b118 44186@smallexample
0ce1b118 44187int system(const char *command);
fc320d37 44188@end smallexample
0ce1b118 44189
fc320d37
SL
44190@item Request:
44191@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 44192
fc320d37 44193@item Return value:
5600ea19
NS
44194If @var{len} is zero, the return value indicates whether a shell is
44195available. A zero return value indicates a shell is not available.
44196For non-zero @var{len}, the value returned is -1 on error and the
44197return status of the command otherwise. Only the exit status of the
44198command is returned, which is extracted from the host's @code{system}
44199return value by calling @code{WEXITSTATUS(retval)}. In case
44200@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 44201
fc320d37 44202@item Errors:
0ce1b118
CV
44203
44204@table @code
b383017d 44205@item EINTR
0ce1b118
CV
44206The call was interrupted by the user.
44207@end table
44208
fc320d37
SL
44209@end table
44210
44211@value{GDBN} takes over the full task of calling the necessary host calls
44212to perform the @code{system} call. The return value of @code{system} on
44213the host is simplified before it's returned
44214to the target. Any termination signal information from the child process
44215is discarded, and the return value consists
44216entirely of the exit status of the called command.
44217
44218Due to security concerns, the @code{system} call is by default refused
44219by @value{GDBN}. The user has to allow this call explicitly with the
44220@code{set remote system-call-allowed 1} command.
44221
44222@table @code
44223@item set remote system-call-allowed
44224@kindex set remote system-call-allowed
44225Control whether to allow the @code{system} calls in the File I/O
44226protocol for the remote target. The default is zero (disabled).
44227
44228@item show remote system-call-allowed
44229@kindex show remote system-call-allowed
44230Show whether the @code{system} calls are allowed in the File I/O
44231protocol.
44232@end table
44233
db2e3e2e
BW
44234@node Protocol-specific Representation of Datatypes
44235@subsection Protocol-specific Representation of Datatypes
44236@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
44237
44238@menu
79a6e687
BW
44239* Integral Datatypes::
44240* Pointer Values::
44241* Memory Transfer::
0ce1b118
CV
44242* struct stat::
44243* struct timeval::
44244@end menu
44245
79a6e687
BW
44246@node Integral Datatypes
44247@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
44248@cindex integral datatypes, in file-i/o protocol
44249
fc320d37
SL
44250The integral datatypes used in the system calls are @code{int},
44251@code{unsigned int}, @code{long}, @code{unsigned long},
44252@code{mode_t}, and @code{time_t}.
0ce1b118 44253
fc320d37 44254@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
44255implemented as 32 bit values in this protocol.
44256
fc320d37 44257@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 44258
0ce1b118
CV
44259@xref{Limits}, for corresponding MIN and MAX values (similar to those
44260in @file{limits.h}) to allow range checking on host and target.
44261
44262@code{time_t} datatypes are defined as seconds since the Epoch.
44263
44264All integral datatypes transferred as part of a memory read or write of a
44265structured datatype e.g.@: a @code{struct stat} have to be given in big endian
44266byte order.
44267
79a6e687
BW
44268@node Pointer Values
44269@unnumberedsubsubsec Pointer Values
0ce1b118
CV
44270@cindex pointer values, in file-i/o protocol
44271
44272Pointers to target data are transmitted as they are. An exception
44273is made for pointers to buffers for which the length isn't
44274transmitted as part of the function call, namely strings. Strings
44275are transmitted as a pointer/length pair, both as hex values, e.g.@:
44276
44277@smallexample
44278@code{1aaf/12}
44279@end smallexample
44280
44281@noindent
44282which is a pointer to data of length 18 bytes at position 0x1aaf.
44283The length is defined as the full string length in bytes, including
fc320d37
SL
44284the trailing null byte. For example, the string @code{"hello world"}
44285at address 0x123456 is transmitted as
0ce1b118
CV
44286
44287@smallexample
fc320d37 44288@code{123456/d}
0ce1b118
CV
44289@end smallexample
44290
79a6e687
BW
44291@node Memory Transfer
44292@unnumberedsubsubsec Memory Transfer
fc320d37
SL
44293@cindex memory transfer, in file-i/o protocol
44294
44295Structured data which is transferred using a memory read or write (for
db2e3e2e 44296example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
44297with all scalar multibyte datatypes being big endian. Translation to
44298this representation needs to be done both by the target before the @code{F}
44299packet is sent, and by @value{GDBN} before
44300it transfers memory to the target. Transferred pointers to structured
44301data should point to the already-coerced data at any time.
0ce1b118 44302
0ce1b118
CV
44303
44304@node struct stat
44305@unnumberedsubsubsec struct stat
44306@cindex struct stat, in file-i/o protocol
44307
fc320d37
SL
44308The buffer of type @code{struct stat} used by the target and @value{GDBN}
44309is defined as follows:
0ce1b118
CV
44310
44311@smallexample
44312struct stat @{
44313 unsigned int st_dev; /* device */
44314 unsigned int st_ino; /* inode */
44315 mode_t st_mode; /* protection */
44316 unsigned int st_nlink; /* number of hard links */
44317 unsigned int st_uid; /* user ID of owner */
44318 unsigned int st_gid; /* group ID of owner */
44319 unsigned int st_rdev; /* device type (if inode device) */
44320 unsigned long st_size; /* total size, in bytes */
44321 unsigned long st_blksize; /* blocksize for filesystem I/O */
44322 unsigned long st_blocks; /* number of blocks allocated */
44323 time_t st_atime; /* time of last access */
44324 time_t st_mtime; /* time of last modification */
44325 time_t st_ctime; /* time of last change */
44326@};
44327@end smallexample
44328
fc320d37 44329The integral datatypes conform to the definitions given in the
79a6e687 44330appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
44331structure is of size 64 bytes.
44332
44333The values of several fields have a restricted meaning and/or
44334range of values.
44335
fc320d37 44336@table @code
0ce1b118 44337
fc320d37
SL
44338@item st_dev
44339A value of 0 represents a file, 1 the console.
0ce1b118 44340
fc320d37
SL
44341@item st_ino
44342No valid meaning for the target. Transmitted unchanged.
0ce1b118 44343
fc320d37
SL
44344@item st_mode
44345Valid mode bits are described in @ref{Constants}. Any other
44346bits have currently no meaning for the target.
0ce1b118 44347
fc320d37
SL
44348@item st_uid
44349@itemx st_gid
44350@itemx st_rdev
44351No valid meaning for the target. Transmitted unchanged.
0ce1b118 44352
fc320d37
SL
44353@item st_atime
44354@itemx st_mtime
44355@itemx st_ctime
44356These values have a host and file system dependent
44357accuracy. Especially on Windows hosts, the file system may not
44358support exact timing values.
44359@end table
0ce1b118 44360
fc320d37
SL
44361The target gets a @code{struct stat} of the above representation and is
44362responsible for coercing it to the target representation before
0ce1b118
CV
44363continuing.
44364
fc320d37
SL
44365Note that due to size differences between the host, target, and protocol
44366representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
44367get truncated on the target.
44368
44369@node struct timeval
44370@unnumberedsubsubsec struct timeval
44371@cindex struct timeval, in file-i/o protocol
44372
fc320d37 44373The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
44374is defined as follows:
44375
44376@smallexample
b383017d 44377struct timeval @{
0ce1b118
CV
44378 time_t tv_sec; /* second */
44379 long tv_usec; /* microsecond */
44380@};
44381@end smallexample
44382
fc320d37 44383The integral datatypes conform to the definitions given in the
79a6e687 44384appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
44385structure is of size 8 bytes.
44386
44387@node Constants
44388@subsection Constants
44389@cindex constants, in file-i/o protocol
44390
44391The following values are used for the constants inside of the
fc320d37 44392protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
44393values before and after the call as needed.
44394
44395@menu
79a6e687
BW
44396* Open Flags::
44397* mode_t Values::
44398* Errno Values::
44399* Lseek Flags::
0ce1b118
CV
44400* Limits::
44401@end menu
44402
79a6e687
BW
44403@node Open Flags
44404@unnumberedsubsubsec Open Flags
0ce1b118
CV
44405@cindex open flags, in file-i/o protocol
44406
44407All values are given in hexadecimal representation.
44408
44409@smallexample
44410 O_RDONLY 0x0
44411 O_WRONLY 0x1
44412 O_RDWR 0x2
44413 O_APPEND 0x8
44414 O_CREAT 0x200
44415 O_TRUNC 0x400
44416 O_EXCL 0x800
44417@end smallexample
44418
79a6e687
BW
44419@node mode_t Values
44420@unnumberedsubsubsec mode_t Values
0ce1b118
CV
44421@cindex mode_t values, in file-i/o protocol
44422
44423All values are given in octal representation.
44424
44425@smallexample
44426 S_IFREG 0100000
44427 S_IFDIR 040000
44428 S_IRUSR 0400
44429 S_IWUSR 0200
44430 S_IXUSR 0100
44431 S_IRGRP 040
44432 S_IWGRP 020
44433 S_IXGRP 010
44434 S_IROTH 04
44435 S_IWOTH 02
44436 S_IXOTH 01
44437@end smallexample
44438
79a6e687
BW
44439@node Errno Values
44440@unnumberedsubsubsec Errno Values
0ce1b118
CV
44441@cindex errno values, in file-i/o protocol
44442
44443All values are given in decimal representation.
44444
44445@smallexample
44446 EPERM 1
44447 ENOENT 2
44448 EINTR 4
44449 EBADF 9
44450 EACCES 13
44451 EFAULT 14
44452 EBUSY 16
44453 EEXIST 17
44454 ENODEV 19
44455 ENOTDIR 20
44456 EISDIR 21
44457 EINVAL 22
44458 ENFILE 23
44459 EMFILE 24
44460 EFBIG 27
44461 ENOSPC 28
44462 ESPIPE 29
44463 EROFS 30
44464 ENAMETOOLONG 91
44465 EUNKNOWN 9999
44466@end smallexample
44467
fc320d37 44468 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
44469 any error value not in the list of supported error numbers.
44470
79a6e687
BW
44471@node Lseek Flags
44472@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
44473@cindex lseek flags, in file-i/o protocol
44474
44475@smallexample
44476 SEEK_SET 0
44477 SEEK_CUR 1
44478 SEEK_END 2
44479@end smallexample
44480
44481@node Limits
44482@unnumberedsubsubsec Limits
44483@cindex limits, in file-i/o protocol
44484
44485All values are given in decimal representation.
44486
44487@smallexample
44488 INT_MIN -2147483648
44489 INT_MAX 2147483647
44490 UINT_MAX 4294967295
44491 LONG_MIN -9223372036854775808
44492 LONG_MAX 9223372036854775807
44493 ULONG_MAX 18446744073709551615
44494@end smallexample
44495
44496@node File-I/O Examples
44497@subsection File-I/O Examples
44498@cindex file-i/o examples
44499
44500Example sequence of a write call, file descriptor 3, buffer is at target
44501address 0x1234, 6 bytes should be written:
44502
44503@smallexample
44504<- @code{Fwrite,3,1234,6}
44505@emph{request memory read from target}
44506-> @code{m1234,6}
44507<- XXXXXX
44508@emph{return "6 bytes written"}
44509-> @code{F6}
44510@end smallexample
44511
44512Example sequence of a read call, file descriptor 3, buffer is at target
44513address 0x1234, 6 bytes should be read:
44514
44515@smallexample
44516<- @code{Fread,3,1234,6}
44517@emph{request memory write to target}
44518-> @code{X1234,6:XXXXXX}
44519@emph{return "6 bytes read"}
44520-> @code{F6}
44521@end smallexample
44522
44523Example sequence of a read call, call fails on the host due to invalid
fc320d37 44524file descriptor (@code{EBADF}):
0ce1b118
CV
44525
44526@smallexample
44527<- @code{Fread,3,1234,6}
44528-> @code{F-1,9}
44529@end smallexample
44530
c8aa23ab 44531Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
44532host is called:
44533
44534@smallexample
44535<- @code{Fread,3,1234,6}
44536-> @code{F-1,4,C}
44537<- @code{T02}
44538@end smallexample
44539
c8aa23ab 44540Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
44541host is called:
44542
44543@smallexample
44544<- @code{Fread,3,1234,6}
44545-> @code{X1234,6:XXXXXX}
44546<- @code{T02}
44547@end smallexample
44548
cfa9d6d9
DJ
44549@node Library List Format
44550@section Library List Format
44551@cindex library list format, remote protocol
44552
44553On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
44554same process as your application to manage libraries. In this case,
44555@value{GDBN} can use the loader's symbol table and normal memory
44556operations to maintain a list of shared libraries. On other
44557platforms, the operating system manages loaded libraries.
44558@value{GDBN} can not retrieve the list of currently loaded libraries
44559through memory operations, so it uses the @samp{qXfer:libraries:read}
44560packet (@pxref{qXfer library list read}) instead. The remote stub
44561queries the target's operating system and reports which libraries
44562are loaded.
44563
44564The @samp{qXfer:libraries:read} packet returns an XML document which
44565lists loaded libraries and their offsets. Each library has an
1fddbabb
PA
44566associated name and one or more segment or section base addresses,
44567which report where the library was loaded in memory.
44568
44569For the common case of libraries that are fully linked binaries, the
44570library should have a list of segments. If the target supports
44571dynamic linking of a relocatable object file, its library XML element
44572should instead include a list of allocated sections. The segment or
44573section bases are start addresses, not relocation offsets; they do not
44574depend on the library's link-time base addresses.
cfa9d6d9 44575
9cceb671
DJ
44576@value{GDBN} must be linked with the Expat library to support XML
44577library lists. @xref{Expat}.
44578
cfa9d6d9
DJ
44579A simple memory map, with one loaded library relocated by a single
44580offset, looks like this:
44581
44582@smallexample
44583<library-list>
44584 <library name="/lib/libc.so.6">
44585 <segment address="0x10000000"/>
44586 </library>
44587</library-list>
44588@end smallexample
44589
1fddbabb
PA
44590Another simple memory map, with one loaded library with three
44591allocated sections (.text, .data, .bss), looks like this:
44592
44593@smallexample
44594<library-list>
44595 <library name="sharedlib.o">
44596 <section address="0x10000000"/>
44597 <section address="0x20000000"/>
44598 <section address="0x30000000"/>
44599 </library>
44600</library-list>
44601@end smallexample
44602
cfa9d6d9
DJ
44603The format of a library list is described by this DTD:
44604
44605@smallexample
44606<!-- library-list: Root element with versioning -->
44607<!ELEMENT library-list (library)*>
44608<!ATTLIST library-list version CDATA #FIXED "1.0">
1fddbabb 44609<!ELEMENT library (segment*, section*)>
cfa9d6d9
DJ
44610<!ATTLIST library name CDATA #REQUIRED>
44611<!ELEMENT segment EMPTY>
44612<!ATTLIST segment address CDATA #REQUIRED>
1fddbabb
PA
44613<!ELEMENT section EMPTY>
44614<!ATTLIST section address CDATA #REQUIRED>
cfa9d6d9
DJ
44615@end smallexample
44616
1fddbabb
PA
44617In addition, segments and section descriptors cannot be mixed within a
44618single library element, and you must supply at least one segment or
44619section for each library.
44620
2268b414
JK
44621@node Library List Format for SVR4 Targets
44622@section Library List Format for SVR4 Targets
44623@cindex library list format, remote protocol
44624
44625On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
44626(e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
44627shared libraries. Still a special library list provided by this packet is
44628more efficient for the @value{GDBN} remote protocol.
44629
44630The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
44631loaded libraries and their SVR4 linker parameters. For each library on SVR4
44632target, the following parameters are reported:
44633
44634@itemize @minus
44635@item
44636@code{name}, the absolute file name from the @code{l_name} field of
44637@code{struct link_map}.
44638@item
44639@code{lm} with address of @code{struct link_map} used for TLS
44640(Thread Local Storage) access.
44641@item
44642@code{l_addr}, the displacement as read from the field @code{l_addr} of
44643@code{struct link_map}. For prelinked libraries this is not an absolute
44644memory address. It is a displacement of absolute memory address against
44645address the file was prelinked to during the library load.
44646@item
44647@code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
44648@end itemize
44649
44650Additionally the single @code{main-lm} attribute specifies address of
44651@code{struct link_map} used for the main executable. This parameter is used
44652for TLS access and its presence is optional.
44653
44654@value{GDBN} must be linked with the Expat library to support XML
44655SVR4 library lists. @xref{Expat}.
44656
44657A simple memory map, with two loaded libraries (which do not use prelink),
44658looks like this:
44659
44660@smallexample
44661<library-list-svr4 version="1.0" main-lm="0xe4f8f8">
44662 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
44663 l_ld="0xe4eefc"/>
44664 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
db1ff28b 44665 l_ld="0x152350"/>
2268b414
JK
44666</library-list-svr>
44667@end smallexample
44668
44669The format of an SVR4 library list is described by this DTD:
44670
44671@smallexample
44672<!-- library-list-svr4: Root element with versioning -->
44673<!ELEMENT library-list-svr4 (library)*>
db1ff28b
JK
44674<!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
44675<!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
2268b414 44676<!ELEMENT library EMPTY>
db1ff28b
JK
44677<!ATTLIST library name CDATA #REQUIRED>
44678<!ATTLIST library lm CDATA #REQUIRED>
44679<!ATTLIST library l_addr CDATA #REQUIRED>
44680<!ATTLIST library l_ld CDATA #REQUIRED>
2268b414
JK
44681@end smallexample
44682
79a6e687
BW
44683@node Memory Map Format
44684@section Memory Map Format
68437a39
DJ
44685@cindex memory map format
44686
44687To be able to write into flash memory, @value{GDBN} needs to obtain a
44688memory map from the target. This section describes the format of the
44689memory map.
44690
44691The memory map is obtained using the @samp{qXfer:memory-map:read}
44692(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
44693lists memory regions.
44694
44695@value{GDBN} must be linked with the Expat library to support XML
44696memory maps. @xref{Expat}.
44697
44698The top-level structure of the document is shown below:
68437a39
DJ
44699
44700@smallexample
44701<?xml version="1.0"?>
44702<!DOCTYPE memory-map
44703 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44704 "http://sourceware.org/gdb/gdb-memory-map.dtd">
44705<memory-map>
44706 region...
44707</memory-map>
44708@end smallexample
44709
44710Each region can be either:
44711
44712@itemize
44713
44714@item
44715A region of RAM starting at @var{addr} and extending for @var{length}
44716bytes from there:
44717
44718@smallexample
44719<memory type="ram" start="@var{addr}" length="@var{length}"/>
44720@end smallexample
44721
44722
44723@item
44724A region of read-only memory:
44725
44726@smallexample
44727<memory type="rom" start="@var{addr}" length="@var{length}"/>
44728@end smallexample
44729
44730
44731@item
44732A region of flash memory, with erasure blocks @var{blocksize}
44733bytes in length:
44734
44735@smallexample
44736<memory type="flash" start="@var{addr}" length="@var{length}">
44737 <property name="blocksize">@var{blocksize}</property>
44738</memory>
44739@end smallexample
44740
44741@end itemize
44742
44743Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
44744by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
44745packets to write to addresses in such ranges.
44746
44747The formal DTD for memory map format is given below:
44748
44749@smallexample
44750<!-- ................................................... -->
44751<!-- Memory Map XML DTD ................................ -->
44752<!-- File: memory-map.dtd .............................. -->
44753<!-- .................................... .............. -->
44754<!-- memory-map.dtd -->
44755<!-- memory-map: Root element with versioning -->
5f1ca24a 44756<!ELEMENT memory-map (memory)*>
68437a39 44757<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
5f1ca24a 44758<!ELEMENT memory (property)*>
68437a39
DJ
44759<!-- memory: Specifies a memory region,
44760 and its type, or device. -->
5f1ca24a 44761<!ATTLIST memory type (ram|rom|flash) #REQUIRED
68437a39 44762 start CDATA #REQUIRED
5f1ca24a 44763 length CDATA #REQUIRED>
68437a39
DJ
44764<!-- property: Generic attribute tag -->
44765<!ELEMENT property (#PCDATA | property)*>
5f1ca24a 44766<!ATTLIST property name (blocksize) #REQUIRED>
68437a39
DJ
44767@end smallexample
44768
dc146f7c
VP
44769@node Thread List Format
44770@section Thread List Format
44771@cindex thread list format
44772
44773To efficiently update the list of threads and their attributes,
44774@value{GDBN} issues the @samp{qXfer:threads:read} packet
44775(@pxref{qXfer threads read}) and obtains the XML document with
44776the following structure:
44777
44778@smallexample
44779<?xml version="1.0"?>
44780<threads>
79efa585 44781 <thread id="id" core="0" name="name">
dc146f7c
VP
44782 ... description ...
44783 </thread>
44784</threads>
44785@end smallexample
44786
44787Each @samp{thread} element must have the @samp{id} attribute that
44788identifies the thread (@pxref{thread-id syntax}). The
44789@samp{core} attribute, if present, specifies which processor core
79efa585
SM
44790the thread was last executing on. The @samp{name} attribute, if
44791present, specifies the human-readable name of the thread. The content
44792of the of @samp{thread} element is interpreted as human-readable
f2ff95c5
KB
44793auxiliary information. The @samp{handle} attribute, if present,
44794is a hex encoded representation of the thread handle.
44795
dc146f7c 44796
b3b9301e
PA
44797@node Traceframe Info Format
44798@section Traceframe Info Format
44799@cindex traceframe info format
44800
44801To be able to know which objects in the inferior can be examined when
44802inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
44803memory ranges, registers and trace state variables that have been
44804collected in a traceframe.
44805
44806This list is obtained using the @samp{qXfer:traceframe-info:read}
44807(@pxref{qXfer traceframe info read}) packet and is an XML document.
44808
44809@value{GDBN} must be linked with the Expat library to support XML
44810traceframe info discovery. @xref{Expat}.
44811
44812The top-level structure of the document is shown below:
44813
44814@smallexample
44815<?xml version="1.0"?>
44816<!DOCTYPE traceframe-info
44817 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44818 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
44819<traceframe-info>
44820 block...
44821</traceframe-info>
44822@end smallexample
44823
44824Each traceframe block can be either:
44825
44826@itemize
44827
44828@item
44829A region of collected memory starting at @var{addr} and extending for
44830@var{length} bytes from there:
44831
44832@smallexample
44833<memory start="@var{addr}" length="@var{length}"/>
44834@end smallexample
44835
28a93511
YQ
44836@item
44837A block indicating trace state variable numbered @var{number} has been
44838collected:
44839
44840@smallexample
44841<tvar id="@var{number}"/>
44842@end smallexample
44843
b3b9301e
PA
44844@end itemize
44845
44846The formal DTD for the traceframe info format is given below:
44847
44848@smallexample
28a93511 44849<!ELEMENT traceframe-info (memory | tvar)* >
b3b9301e
PA
44850<!ATTLIST traceframe-info version CDATA #FIXED "1.0">
44851
44852<!ELEMENT memory EMPTY>
44853<!ATTLIST memory start CDATA #REQUIRED
44854 length CDATA #REQUIRED>
28a93511
YQ
44855<!ELEMENT tvar>
44856<!ATTLIST tvar id CDATA #REQUIRED>
b3b9301e
PA
44857@end smallexample
44858
2ae8c8e7
MM
44859@node Branch Trace Format
44860@section Branch Trace Format
44861@cindex branch trace format
44862
44863In order to display the branch trace of an inferior thread,
44864@value{GDBN} needs to obtain the list of branches. This list is
44865represented as list of sequential code blocks that are connected via
44866branches. The code in each block has been executed sequentially.
44867
44868This list is obtained using the @samp{qXfer:btrace:read}
44869(@pxref{qXfer btrace read}) packet and is an XML document.
44870
44871@value{GDBN} must be linked with the Expat library to support XML
44872traceframe info discovery. @xref{Expat}.
44873
44874The top-level structure of the document is shown below:
44875
44876@smallexample
44877<?xml version="1.0"?>
44878<!DOCTYPE btrace
44879 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
44880 "http://sourceware.org/gdb/gdb-btrace.dtd">
44881<btrace>
44882 block...
44883</btrace>
44884@end smallexample
44885
44886@itemize
44887
44888@item
44889A block of sequentially executed instructions starting at @var{begin}
44890and ending at @var{end}:
44891
44892@smallexample
44893<block begin="@var{begin}" end="@var{end}"/>
44894@end smallexample
44895
44896@end itemize
44897
44898The formal DTD for the branch trace format is given below:
44899
44900@smallexample
b20a6524 44901<!ELEMENT btrace (block* | pt) >
2ae8c8e7
MM
44902<!ATTLIST btrace version CDATA #FIXED "1.0">
44903
44904<!ELEMENT block EMPTY>
44905<!ATTLIST block begin CDATA #REQUIRED
44906 end CDATA #REQUIRED>
b20a6524
MM
44907
44908<!ELEMENT pt (pt-config?, raw?)>
44909
44910<!ELEMENT pt-config (cpu?)>
44911
44912<!ELEMENT cpu EMPTY>
44913<!ATTLIST cpu vendor CDATA #REQUIRED
44914 family CDATA #REQUIRED
44915 model CDATA #REQUIRED
44916 stepping CDATA #REQUIRED>
44917
44918<!ELEMENT raw (#PCDATA)>
2ae8c8e7
MM
44919@end smallexample
44920
f4abbc16
MM
44921@node Branch Trace Configuration Format
44922@section Branch Trace Configuration Format
44923@cindex branch trace configuration format
44924
44925For each inferior thread, @value{GDBN} can obtain the branch trace
44926configuration using the @samp{qXfer:btrace-conf:read}
44927(@pxref{qXfer btrace-conf read}) packet.
44928
44929The configuration describes the branch trace format and configuration
d33501a5
MM
44930settings for that format. The following information is described:
44931
44932@table @code
44933@item bts
44934This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
44935@table @code
44936@item size
44937The size of the @acronym{BTS} ring buffer in bytes.
44938@end table
b20a6524 44939@item pt
bc504a31 44940This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
b20a6524
MM
44941PT}) format.
44942@table @code
44943@item size
bc504a31 44944The size of the @acronym{Intel PT} ring buffer in bytes.
b20a6524 44945@end table
d33501a5 44946@end table
f4abbc16
MM
44947
44948@value{GDBN} must be linked with the Expat library to support XML
44949branch trace configuration discovery. @xref{Expat}.
44950
44951The formal DTD for the branch trace configuration format is given below:
44952
44953@smallexample
b20a6524 44954<!ELEMENT btrace-conf (bts?, pt?)>
f4abbc16
MM
44955<!ATTLIST btrace-conf version CDATA #FIXED "1.0">
44956
44957<!ELEMENT bts EMPTY>
d33501a5 44958<!ATTLIST bts size CDATA #IMPLIED>
b20a6524
MM
44959
44960<!ELEMENT pt EMPTY>
44961<!ATTLIST pt size CDATA #IMPLIED>
f4abbc16
MM
44962@end smallexample
44963
f418dd93
DJ
44964@include agentexpr.texi
44965
23181151
DJ
44966@node Target Descriptions
44967@appendix Target Descriptions
44968@cindex target descriptions
44969
23181151
DJ
44970One of the challenges of using @value{GDBN} to debug embedded systems
44971is that there are so many minor variants of each processor
44972architecture in use. It is common practice for vendors to start with
eb17f351 44973a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
23181151
DJ
44974and then make changes to adapt it to a particular market niche. Some
44975architectures have hundreds of variants, available from dozens of
44976vendors. This leads to a number of problems:
44977
44978@itemize @bullet
44979@item
44980With so many different customized processors, it is difficult for
44981the @value{GDBN} maintainers to keep up with the changes.
44982@item
44983Since individual variants may have short lifetimes or limited
44984audiences, it may not be worthwhile to carry information about every
44985variant in the @value{GDBN} source tree.
44986@item
44987When @value{GDBN} does support the architecture of the embedded system
44988at hand, the task of finding the correct architecture name to give the
44989@command{set architecture} command can be error-prone.
44990@end itemize
44991
44992To address these problems, the @value{GDBN} remote protocol allows a
44993target system to not only identify itself to @value{GDBN}, but to
44994actually describe its own features. This lets @value{GDBN} support
44995processor variants it has never seen before --- to the extent that the
44996descriptions are accurate, and that @value{GDBN} understands them.
44997
9cceb671
DJ
44998@value{GDBN} must be linked with the Expat library to support XML
44999target descriptions. @xref{Expat}.
123dc839 45000
23181151
DJ
45001@menu
45002* Retrieving Descriptions:: How descriptions are fetched from a target.
45003* Target Description Format:: The contents of a target description.
123dc839
DJ
45004* Predefined Target Types:: Standard types available for target
45005 descriptions.
81516450 45006* Enum Target Types:: How to define enum target types.
123dc839 45007* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
45008@end menu
45009
45010@node Retrieving Descriptions
45011@section Retrieving Descriptions
45012
45013Target descriptions can be read from the target automatically, or
45014specified by the user manually. The default behavior is to read the
45015description from the target. @value{GDBN} retrieves it via the remote
45016protocol using @samp{qXfer} requests (@pxref{General Query Packets,
45017qXfer}). The @var{annex} in the @samp{qXfer} packet will be
45018@samp{target.xml}. The contents of the @samp{target.xml} annex are an
45019XML document, of the form described in @ref{Target Description
45020Format}.
45021
45022Alternatively, you can specify a file to read for the target description.
45023If a file is set, the target will not be queried. The commands to
45024specify a file are:
45025
45026@table @code
45027@cindex set tdesc filename
45028@item set tdesc filename @var{path}
45029Read the target description from @var{path}.
45030
45031@cindex unset tdesc filename
45032@item unset tdesc filename
45033Do not read the XML target description from a file. @value{GDBN}
45034will use the description supplied by the current target.
45035
45036@cindex show tdesc filename
45037@item show tdesc filename
45038Show the filename to read for a target description, if any.
45039@end table
45040
45041
45042@node Target Description Format
45043@section Target Description Format
45044@cindex target descriptions, XML format
45045
45046A target description annex is an @uref{http://www.w3.org/XML/, XML}
45047document which complies with the Document Type Definition provided in
45048the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
45049means you can use generally available tools like @command{xmllint} to
45050check that your feature descriptions are well-formed and valid.
45051However, to help people unfamiliar with XML write descriptions for
45052their targets, we also describe the grammar here.
45053
123dc839
DJ
45054Target descriptions can identify the architecture of the remote target
45055and (for some architectures) provide information about custom register
08d16641
PA
45056sets. They can also identify the OS ABI of the remote target.
45057@value{GDBN} can use this information to autoconfigure for your
123dc839 45058target, or to warn you if you connect to an unsupported target.
23181151
DJ
45059
45060Here is a simple target description:
45061
123dc839 45062@smallexample
1780a0ed 45063<target version="1.0">
23181151
DJ
45064 <architecture>i386:x86-64</architecture>
45065</target>
123dc839 45066@end smallexample
23181151
DJ
45067
45068@noindent
45069This minimal description only says that the target uses
45070the x86-64 architecture.
45071
123dc839
DJ
45072A target description has the following overall form, with [ ] marking
45073optional elements and @dots{} marking repeatable elements. The elements
45074are explained further below.
23181151 45075
123dc839 45076@smallexample
23181151
DJ
45077<?xml version="1.0"?>
45078<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 45079<target version="1.0">
123dc839 45080 @r{[}@var{architecture}@r{]}
08d16641 45081 @r{[}@var{osabi}@r{]}
e35359c5 45082 @r{[}@var{compatible}@r{]}
123dc839 45083 @r{[}@var{feature}@dots{}@r{]}
23181151 45084</target>
123dc839 45085@end smallexample
23181151
DJ
45086
45087@noindent
45088The description is generally insensitive to whitespace and line
45089breaks, under the usual common-sense rules. The XML version
45090declaration and document type declaration can generally be omitted
45091(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
45092useful for XML validation tools. The @samp{version} attribute for
45093@samp{<target>} may also be omitted, but we recommend
45094including it; if future versions of @value{GDBN} use an incompatible
45095revision of @file{gdb-target.dtd}, they will detect and report
45096the version mismatch.
23181151 45097
108546a0
DJ
45098@subsection Inclusion
45099@cindex target descriptions, inclusion
45100@cindex XInclude
45101@ifnotinfo
45102@cindex <xi:include>
45103@end ifnotinfo
45104
45105It can sometimes be valuable to split a target description up into
45106several different annexes, either for organizational purposes, or to
45107share files between different possible target descriptions. You can
45108divide a description into multiple files by replacing any element of
45109the target description with an inclusion directive of the form:
45110
123dc839 45111@smallexample
108546a0 45112<xi:include href="@var{document}"/>
123dc839 45113@end smallexample
108546a0
DJ
45114
45115@noindent
45116When @value{GDBN} encounters an element of this form, it will retrieve
45117the named XML @var{document}, and replace the inclusion directive with
45118the contents of that document. If the current description was read
45119using @samp{qXfer}, then so will be the included document;
45120@var{document} will be interpreted as the name of an annex. If the
45121current description was read from a file, @value{GDBN} will look for
45122@var{document} as a file in the same directory where it found the
45123original description.
45124
123dc839
DJ
45125@subsection Architecture
45126@cindex <architecture>
45127
45128An @samp{<architecture>} element has this form:
45129
45130@smallexample
45131 <architecture>@var{arch}</architecture>
45132@end smallexample
45133
e35359c5
UW
45134@var{arch} is one of the architectures from the set accepted by
45135@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
123dc839 45136
08d16641
PA
45137@subsection OS ABI
45138@cindex @code{<osabi>}
45139
45140This optional field was introduced in @value{GDBN} version 7.0.
45141Previous versions of @value{GDBN} ignore it.
45142
45143An @samp{<osabi>} element has this form:
45144
45145@smallexample
45146 <osabi>@var{abi-name}</osabi>
45147@end smallexample
45148
45149@var{abi-name} is an OS ABI name from the same selection accepted by
45150@w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
45151
e35359c5
UW
45152@subsection Compatible Architecture
45153@cindex @code{<compatible>}
45154
45155This optional field was introduced in @value{GDBN} version 7.0.
45156Previous versions of @value{GDBN} ignore it.
45157
45158A @samp{<compatible>} element has this form:
45159
45160@smallexample
45161 <compatible>@var{arch}</compatible>
45162@end smallexample
45163
45164@var{arch} is one of the architectures from the set accepted by
45165@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
45166
45167A @samp{<compatible>} element is used to specify that the target
45168is able to run binaries in some other than the main target architecture
45169given by the @samp{<architecture>} element. For example, on the
45170Cell Broadband Engine, the main architecture is @code{powerpc:common}
45171or @code{powerpc:common64}, but the system is able to run binaries
45172in the @code{spu} architecture as well. The way to describe this
45173capability with @samp{<compatible>} is as follows:
45174
45175@smallexample
45176 <architecture>powerpc:common</architecture>
45177 <compatible>spu</compatible>
45178@end smallexample
45179
123dc839
DJ
45180@subsection Features
45181@cindex <feature>
45182
45183Each @samp{<feature>} describes some logical portion of the target
45184system. Features are currently used to describe available CPU
45185registers and the types of their contents. A @samp{<feature>} element
45186has this form:
45187
45188@smallexample
45189<feature name="@var{name}">
45190 @r{[}@var{type}@dots{}@r{]}
45191 @var{reg}@dots{}
45192</feature>
45193@end smallexample
45194
45195@noindent
45196Each feature's name should be unique within the description. The name
45197of a feature does not matter unless @value{GDBN} has some special
45198knowledge of the contents of that feature; if it does, the feature
45199should have its standard name. @xref{Standard Target Features}.
45200
45201@subsection Types
45202
45203Any register's value is a collection of bits which @value{GDBN} must
45204interpret. The default interpretation is a two's complement integer,
45205but other types can be requested by name in the register description.
45206Some predefined types are provided by @value{GDBN} (@pxref{Predefined
81516450
DE
45207Target Types}), and the description can define additional composite
45208and enum types.
123dc839
DJ
45209
45210Each type element must have an @samp{id} attribute, which gives
45211a unique (within the containing @samp{<feature>}) name to the type.
45212Types must be defined before they are used.
45213
45214@cindex <vector>
45215Some targets offer vector registers, which can be treated as arrays
45216of scalar elements. These types are written as @samp{<vector>} elements,
45217specifying the array element type, @var{type}, and the number of elements,
45218@var{count}:
45219
45220@smallexample
45221<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
45222@end smallexample
45223
45224@cindex <union>
45225If a register's value is usefully viewed in multiple ways, define it
45226with a union type containing the useful representations. The
45227@samp{<union>} element contains one or more @samp{<field>} elements,
45228each of which has a @var{name} and a @var{type}:
45229
45230@smallexample
45231<union id="@var{id}">
45232 <field name="@var{name}" type="@var{type}"/>
45233 @dots{}
45234</union>
45235@end smallexample
45236
f5dff777 45237@cindex <struct>
81516450 45238@cindex <flags>
f5dff777 45239If a register's value is composed from several separate values, define
81516450
DE
45240it with either a structure type or a flags type.
45241A flags type may only contain bitfields.
45242A structure type may either contain only bitfields or contain no bitfields.
45243If the value contains only bitfields, its total size in bytes must be
45244specified.
45245
45246Non-bitfield values have a @var{name} and @var{type}.
f5dff777
DJ
45247
45248@smallexample
81516450
DE
45249<struct id="@var{id}">
45250 <field name="@var{name}" type="@var{type}"/>
f5dff777
DJ
45251 @dots{}
45252</struct>
45253@end smallexample
45254
81516450
DE
45255Both @var{name} and @var{type} values are required.
45256No implicit padding is added.
45257
45258Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
f5dff777
DJ
45259
45260@smallexample
81516450
DE
45261<struct id="@var{id}" size="@var{size}">
45262 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
f5dff777
DJ
45263 @dots{}
45264</struct>
45265@end smallexample
45266
f5dff777
DJ
45267@smallexample
45268<flags id="@var{id}" size="@var{size}">
81516450 45269 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
f5dff777
DJ
45270 @dots{}
45271</flags>
45272@end smallexample
45273
81516450
DE
45274The @var{name} value is required.
45275Bitfield values may be named with the empty string, @samp{""},
45276in which case the field is ``filler'' and its value is not printed.
45277Not all bits need to be specified, so ``filler'' fields are optional.
45278
ee8da4b8
DE
45279The @var{start} and @var{end} values are required, and @var{type}
45280is optional.
81516450
DE
45281The field's @var{start} must be less than or equal to its @var{end},
45282and zero represents the least significant bit.
81516450 45283
ee8da4b8
DE
45284The default value of @var{type} is @code{bool} for single bit fields,
45285and an unsigned integer otherwise.
81516450
DE
45286
45287Which to choose? Structures or flags?
45288
45289Registers defined with @samp{flags} have these advantages over
45290defining them with @samp{struct}:
45291
45292@itemize @bullet
45293@item
45294Arithmetic may be performed on them as if they were integers.
45295@item
45296They are printed in a more readable fashion.
45297@end itemize
45298
45299Registers defined with @samp{struct} have one advantage over
45300defining them with @samp{flags}:
45301
45302@itemize @bullet
45303@item
45304One can fetch individual fields like in @samp{C}.
45305
45306@smallexample
45307(gdb) print $my_struct_reg.field3
45308$1 = 42
45309@end smallexample
45310
45311@end itemize
45312
123dc839
DJ
45313@subsection Registers
45314@cindex <reg>
45315
45316Each register is represented as an element with this form:
45317
45318@smallexample
45319<reg name="@var{name}"
45320 bitsize="@var{size}"
45321 @r{[}regnum="@var{num}"@r{]}
45322 @r{[}save-restore="@var{save-restore}"@r{]}
45323 @r{[}type="@var{type}"@r{]}
45324 @r{[}group="@var{group}"@r{]}/>
45325@end smallexample
45326
45327@noindent
45328The components are as follows:
45329
45330@table @var
45331
45332@item name
45333The register's name; it must be unique within the target description.
45334
45335@item bitsize
45336The register's size, in bits.
45337
45338@item regnum
45339The register's number. If omitted, a register's number is one greater
45340than that of the previous register (either in the current feature or in
177b42fe 45341a preceding feature); the first register in the target description
123dc839
DJ
45342defaults to zero. This register number is used to read or write
45343the register; e.g.@: it is used in the remote @code{p} and @code{P}
45344packets, and registers appear in the @code{g} and @code{G} packets
45345in order of increasing register number.
45346
45347@item save-restore
45348Whether the register should be preserved across inferior function
45349calls; this must be either @code{yes} or @code{no}. The default is
45350@code{yes}, which is appropriate for most registers except for
45351some system control registers; this is not related to the target's
45352ABI.
45353
45354@item type
697aa1b7 45355The type of the register. It may be a predefined type, a type
123dc839
DJ
45356defined in the current feature, or one of the special types @code{int}
45357and @code{float}. @code{int} is an integer type of the correct size
45358for @var{bitsize}, and @code{float} is a floating point type (in the
45359architecture's normal floating point format) of the correct size for
45360@var{bitsize}. The default is @code{int}.
45361
45362@item group
cef0f868
SH
45363The register group to which this register belongs. It can be one of the
45364standard register groups @code{general}, @code{float}, @code{vector} or an
45365arbitrary string. Group names should be limited to alphanumeric characters.
45366If a group name is made up of multiple words the words may be separated by
45367hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
45368@var{group} is specified, @value{GDBN} will not display the register in
45369@code{info registers}.
123dc839
DJ
45370
45371@end table
45372
45373@node Predefined Target Types
45374@section Predefined Target Types
45375@cindex target descriptions, predefined types
45376
45377Type definitions in the self-description can build up composite types
45378from basic building blocks, but can not define fundamental types. Instead,
45379standard identifiers are provided by @value{GDBN} for the fundamental
45380types. The currently supported types are:
45381
45382@table @code
45383
81516450
DE
45384@item bool
45385Boolean type, occupying a single bit.
45386
123dc839
DJ
45387@item int8
45388@itemx int16
d1908f2d 45389@itemx int24
123dc839
DJ
45390@itemx int32
45391@itemx int64
7cc46491 45392@itemx int128
123dc839
DJ
45393Signed integer types holding the specified number of bits.
45394
45395@item uint8
45396@itemx uint16
d1908f2d 45397@itemx uint24
123dc839
DJ
45398@itemx uint32
45399@itemx uint64
7cc46491 45400@itemx uint128
123dc839
DJ
45401Unsigned integer types holding the specified number of bits.
45402
45403@item code_ptr
45404@itemx data_ptr
45405Pointers to unspecified code and data. The program counter and
45406any dedicated return address register may be marked as code
45407pointers; printing a code pointer converts it into a symbolic
45408address. The stack pointer and any dedicated address registers
45409may be marked as data pointers.
45410
6e3bbd1a
PB
45411@item ieee_single
45412Single precision IEEE floating point.
45413
45414@item ieee_double
45415Double precision IEEE floating point.
45416
123dc839
DJ
45417@item arm_fpa_ext
45418The 12-byte extended precision format used by ARM FPA registers.
45419
075b51b7
L
45420@item i387_ext
45421The 10-byte extended precision format used by x87 registers.
45422
45423@item i386_eflags
4542432bit @sc{eflags} register used by x86.
45425
45426@item i386_mxcsr
4542732bit @sc{mxcsr} register used by x86.
45428
123dc839
DJ
45429@end table
45430
81516450
DE
45431@node Enum Target Types
45432@section Enum Target Types
45433@cindex target descriptions, enum types
45434
45435Enum target types are useful in @samp{struct} and @samp{flags}
45436register descriptions. @xref{Target Description Format}.
45437
45438Enum types have a name, size and a list of name/value pairs.
45439
45440@smallexample
45441<enum id="@var{id}" size="@var{size}">
45442 <evalue name="@var{name}" value="@var{value}"/>
45443 @dots{}
45444</enum>
45445@end smallexample
45446
45447Enums must be defined before they are used.
45448
45449@smallexample
45450<enum id="levels_type" size="4">
45451 <evalue name="low" value="0"/>
45452 <evalue name="high" value="1"/>
45453</enum>
45454<flags id="flags_type" size="4">
45455 <field name="X" start="0"/>
45456 <field name="LEVEL" start="1" end="1" type="levels_type"/>
45457</flags>
45458<reg name="flags" bitsize="32" type="flags_type"/>
45459@end smallexample
45460
45461Given that description, a value of 3 for the @samp{flags} register
45462would be printed as:
45463
45464@smallexample
45465(gdb) info register flags
45466flags 0x3 [ X LEVEL=high ]
45467@end smallexample
45468
123dc839
DJ
45469@node Standard Target Features
45470@section Standard Target Features
45471@cindex target descriptions, standard features
45472
45473A target description must contain either no registers or all the
45474target's registers. If the description contains no registers, then
45475@value{GDBN} will assume a default register layout, selected based on
45476the architecture. If the description contains any registers, the
45477default layout will not be used; the standard registers must be
45478described in the target description, in such a way that @value{GDBN}
45479can recognize them.
45480
45481This is accomplished by giving specific names to feature elements
45482which contain standard registers. @value{GDBN} will look for features
45483with those names and verify that they contain the expected registers;
45484if any known feature is missing required registers, or if any required
45485feature is missing, @value{GDBN} will reject the target
45486description. You can add additional registers to any of the
45487standard features --- @value{GDBN} will display them just as if
45488they were added to an unrecognized feature.
45489
45490This section lists the known features and their expected contents.
45491Sample XML documents for these features are included in the
45492@value{GDBN} source tree, in the directory @file{gdb/features}.
45493
45494Names recognized by @value{GDBN} should include the name of the
45495company or organization which selected the name, and the overall
45496architecture to which the feature applies; so e.g.@: the feature
45497containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
45498
ff6f572f
DJ
45499The names of registers are not case sensitive for the purpose
45500of recognizing standard features, but @value{GDBN} will only display
45501registers using the capitalization used in the description.
45502
e9c17194 45503@menu
430ed3f0 45504* AArch64 Features::
ad0a504f 45505* ARC Features::
e9c17194 45506* ARM Features::
3bb8d5c3 45507* i386 Features::
164224e9 45508* MicroBlaze Features::
1e26b4f8 45509* MIPS Features::
e9c17194 45510* M68K Features::
a28d8e50 45511* NDS32 Features::
a1217d97 45512* Nios II Features::
a994fec4 45513* OpenRISC 1000 Features::
1e26b4f8 45514* PowerPC Features::
b5ffee31 45515* RISC-V Features::
e3ec872f 45516* RX Features::
4ac33720 45517* S/390 and System z Features::
3f7b46f2 45518* Sparc Features::
224bbe49 45519* TIC6x Features::
e9c17194
VP
45520@end menu
45521
45522
430ed3f0
MS
45523@node AArch64 Features
45524@subsection AArch64 Features
45525@cindex target descriptions, AArch64 features
45526
45527The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
45528targets. It should contain registers @samp{x0} through @samp{x30},
45529@samp{sp}, @samp{pc}, and @samp{cpsr}.
45530
45531The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
45532it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
45533and @samp{fpcr}.
45534
95228a0d
AH
45535The @samp{org.gnu.gdb.aarch64.sve} feature is optional. If present,
45536it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
45537through @samp{p15}, @samp{ffr} and @samp{vg}.
45538
6dc0ebde
AH
45539The @samp{org.gnu.gdb.aarch64.pauth} feature is optional. If present,
45540it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
45541
ad0a504f
AK
45542@node ARC Features
45543@subsection ARC Features
45544@cindex target descriptions, ARC Features
45545
995d3a19
SV
45546ARC processors are so configurable that even core registers and their numbers
45547are not predetermined completely. Moreover, @emph{flags} and @emph{PC}
45548registers, which are important to @value{GDBN}, are not ``core'' registers in
45549ARC. Therefore, there are two features that their presence is mandatory:
45550@samp{org.gnu.gdb.arc.core} and @samp{org.gnu.gdb.arc.aux}.
45551
45552The @samp{org.gnu.gdb.arc.core} feature is required for all targets. It must
45553contain registers:
45554
45555@itemize @minus
45556@item
45557@samp{r0} through @samp{r25} for normal register file targets.
45558@item
45559@samp{r0} through @samp{r3}, and @samp{r10} through @samp{r15} for reduced
45560register file targets.
45561@item
45562@samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}@footnote{Not necessary for ARCv1.},
45563@samp{blink}, @samp{lp_count}, @samp{pcl}.
45564@end itemize
45565
45566In case of an ARCompact target (ARCv1 ISA), the @samp{org.gnu.gdb.arc.core}
45567feature may contain registers @samp{ilink1} and @samp{ilink2}. While in case
45568of ARC EM and ARC HS targets (ARCv2 ISA), register @samp{ilink} may be present.
45569The difference between ARCv1 and ARCv2 is the naming of registers @emph{29th}
45570and @emph{30th}. They are called @samp{ilink1} and @samp{ilink2} for ARCv1 and
45571are optional. For ARCv2, they are called @samp{ilink} and @samp{r30} and only
45572@samp{ilink} is optional. The optionality of @samp{ilink*} registers is
45573because of their inaccessibility during user space debugging sessions.
45574
45575Extension core registers @samp{r32} through @samp{r59} are optional and their
45576existence depends on the configuration. When debugging GNU/Linux applications,
45577i.e.@: user space debugging, these core registers are not available.
45578
fdd8731b
SV
45579The @samp{org.gnu.gdb.arc.aux} feature is required for all ARC targets. Here
45580is the list of registers pertinent to this feature:
45581
45582@itemize @minus
45583@item
45584mandatory: @samp{pc} and @samp{status32}.
45585@item
45586optional: @samp{lp_start}, @samp{lp_end}, and @samp{bta}.
45587@end itemize
ad0a504f 45588
e9c17194 45589@node ARM Features
123dc839
DJ
45590@subsection ARM Features
45591@cindex target descriptions, ARM features
45592
9779414d
DJ
45593The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
45594ARM targets.
123dc839
DJ
45595It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
45596@samp{lr}, @samp{pc}, and @samp{cpsr}.
45597
9779414d
DJ
45598For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
45599feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
45600registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
45601and @samp{xpsr}.
45602
123dc839
DJ
45603The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
45604should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
45605
ff6f572f
DJ
45606The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
45607it should contain at least registers @samp{wR0} through @samp{wR15} and
45608@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
45609@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 45610
58d6951d
DJ
45611The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
45612should contain at least registers @samp{d0} through @samp{d15}. If
45613they are present, @samp{d16} through @samp{d31} should also be included.
45614@value{GDBN} will synthesize the single-precision registers from
45615halves of the double-precision registers.
45616
45617The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
45618need to contain registers; it instructs @value{GDBN} to display the
45619VFP double-precision registers as vectors and to synthesize the
45620quad-precision registers from pairs of double-precision registers.
45621If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
45622be present and include 32 double-precision registers.
45623
3bb8d5c3
L
45624@node i386 Features
45625@subsection i386 Features
45626@cindex target descriptions, i386 features
45627
45628The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
45629targets. It should describe the following registers:
45630
45631@itemize @minus
45632@item
45633@samp{eax} through @samp{edi} plus @samp{eip} for i386
45634@item
45635@samp{rax} through @samp{r15} plus @samp{rip} for amd64
45636@item
45637@samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
45638@samp{fs}, @samp{gs}
45639@item
45640@samp{st0} through @samp{st7}
45641@item
45642@samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
45643@samp{foseg}, @samp{fooff} and @samp{fop}
45644@end itemize
45645
45646The register sets may be different, depending on the target.
45647
3a13a53b 45648The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
3bb8d5c3
L
45649describe registers:
45650
45651@itemize @minus
45652@item
45653@samp{xmm0} through @samp{xmm7} for i386
45654@item
45655@samp{xmm0} through @samp{xmm15} for amd64
45656@item
45657@samp{mxcsr}
45658@end itemize
45659
3a13a53b
L
45660The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
45661@samp{org.gnu.gdb.i386.sse} feature. It should
f68eb612
L
45662describe the upper 128 bits of @sc{ymm} registers:
45663
45664@itemize @minus
45665@item
45666@samp{ymm0h} through @samp{ymm7h} for i386
45667@item
45668@samp{ymm0h} through @samp{ymm15h} for amd64
f68eb612
L
45669@end itemize
45670
bc504a31 45671The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
ca8941bb
WT
45672Memory Protection Extension (MPX). It should describe the following registers:
45673
45674@itemize @minus
45675@item
45676@samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
45677@item
45678@samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
45679@end itemize
45680
3bb8d5c3
L
45681The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
45682describe a single register, @samp{orig_eax}.
45683
2735833d
WT
45684The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
45685describe two system registers: @samp{fs_base} and @samp{gs_base}.
45686
01f9f808
MS
45687The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
45688@samp{org.gnu.gdb.i386.avx} feature. It should
45689describe additional @sc{xmm} registers:
45690
45691@itemize @minus
45692@item
45693@samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
45694@end itemize
45695
45696It should describe the upper 128 bits of additional @sc{ymm} registers:
45697
45698@itemize @minus
45699@item
45700@samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
45701@end itemize
45702
45703It should
45704describe the upper 256 bits of @sc{zmm} registers:
45705
45706@itemize @minus
45707@item
45708@samp{zmm0h} through @samp{zmm7h} for i386.
45709@item
45710@samp{zmm0h} through @samp{zmm15h} for amd64.
45711@end itemize
45712
45713It should
45714describe the additional @sc{zmm} registers:
45715
45716@itemize @minus
45717@item
45718@samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
45719@end itemize
45720
51547df6
MS
45721The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
45722describe a single register, @samp{pkru}. It is a 32-bit register
45723valid for i386 and amd64.
45724
164224e9
ME
45725@node MicroBlaze Features
45726@subsection MicroBlaze Features
45727@cindex target descriptions, MicroBlaze features
45728
45729The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
45730targets. It should contain registers @samp{r0} through @samp{r31},
45731@samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
45732@samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
45733@samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
45734
45735The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
45736If present, it should contain registers @samp{rshr} and @samp{rslr}
45737
1e26b4f8 45738@node MIPS Features
eb17f351
EZ
45739@subsection @acronym{MIPS} Features
45740@cindex target descriptions, @acronym{MIPS} features
f8b73d13 45741
eb17f351 45742The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
f8b73d13
DJ
45743It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
45744@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
45745on the target.
45746
45747The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
45748contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
45749registers. They may be 32-bit or 64-bit depending on the target.
45750
45751The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
45752it may be optional in a future version of @value{GDBN}. It should
45753contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
45754@samp{fir}. They may be 32-bit or 64-bit depending on the target.
45755
1faeff08
MR
45756The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
45757contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
45758@samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
45759be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
45760
822b6570
DJ
45761The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
45762contain a single register, @samp{restart}, which is used by the
45763Linux kernel to control restartable syscalls.
45764
e9c17194
VP
45765@node M68K Features
45766@subsection M68K Features
45767@cindex target descriptions, M68K features
45768
45769@table @code
45770@item @samp{org.gnu.gdb.m68k.core}
45771@itemx @samp{org.gnu.gdb.coldfire.core}
45772@itemx @samp{org.gnu.gdb.fido.core}
45773One of those features must be always present.
249e1128 45774The feature that is present determines which flavor of m68k is
e9c17194
VP
45775used. The feature that is present should contain registers
45776@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
45777@samp{sp}, @samp{ps} and @samp{pc}.
45778
45779@item @samp{org.gnu.gdb.coldfire.fp}
45780This feature is optional. If present, it should contain registers
45781@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
45782@samp{fpiaddr}.
b7d2fe14
TT
45783
45784Note that, despite the fact that this feature's name says
45785@samp{coldfire}, it is used to describe any floating point registers.
45786The size of the registers must match the main m68k flavor; so, for
45787example, if the primary feature is reported as @samp{coldfire}, then
4578864-bit floating point registers are required.
e9c17194
VP
45789@end table
45790
a28d8e50
YTL
45791@node NDS32 Features
45792@subsection NDS32 Features
45793@cindex target descriptions, NDS32 features
45794
45795The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
45796targets. It should contain at least registers @samp{r0} through
45797@samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
45798and @samp{pc}.
45799
45800The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
45801it should contain 64-bit double-precision floating-point registers
45802@samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
45803@samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
45804
45805@emph{Note:} The first sixteen 64-bit double-precision floating-point
45806registers are overlapped with the thirty-two 32-bit single-precision
45807floating-point registers. The 32-bit single-precision registers, if
45808not being listed explicitly, will be synthesized from halves of the
45809overlapping 64-bit double-precision registers. Listing 32-bit
45810single-precision registers explicitly is deprecated, and the
45811support to it could be totally removed some day.
45812
a1217d97
SL
45813@node Nios II Features
45814@subsection Nios II Features
45815@cindex target descriptions, Nios II features
45816
45817The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
45818targets. It should contain the 32 core registers (@samp{zero},
45819@samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
45820@samp{pc}, and the 16 control registers (@samp{status} through
45821@samp{mpuacc}).
45822
a994fec4
FJ
45823@node OpenRISC 1000 Features
45824@subsection Openrisc 1000 Features
45825@cindex target descriptions, OpenRISC 1000 features
45826
45827The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
45828targets. It should contain the 32 general purpose registers (@samp{r0}
45829through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
45830
1e26b4f8 45831@node PowerPC Features
7cc46491
DJ
45832@subsection PowerPC Features
45833@cindex target descriptions, PowerPC features
45834
45835The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
45836targets. It should contain registers @samp{r0} through @samp{r31},
45837@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
45838@samp{xer}. They may be 32-bit or 64-bit depending on the target.
45839
45840The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
45841contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
45842
45843The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
6f072a10
PFC
45844contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
45845@samp{vrsave}. @value{GDBN} will define pseudo-registers @samp{v0}
45846through @samp{v31} as aliases for the corresponding @samp{vrX}
45847registers.
7cc46491 45848
677c5bb1 45849The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
4b905ae1
PFC
45850contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN} will
45851combine these registers with the floating point registers (@samp{f0}
45852through @samp{f31}) and the altivec registers (@samp{vr0} through
45853@samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
45854@samp{vs63}, the set of vector-scalar registers for POWER7.
45855Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
45856@samp{org.gnu.gdb.power.altivec}.
677c5bb1 45857
7cc46491
DJ
45858The @samp{org.gnu.gdb.power.spe} feature is optional. It should
45859contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
45860@samp{spefscr}. SPE targets should provide 32-bit registers in
45861@samp{org.gnu.gdb.power.core} and provide the upper halves in
45862@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
45863these to present registers @samp{ev0} through @samp{ev31} to the
45864user.
45865
7ca18ed6
EBM
45866The @samp{org.gnu.gdb.power.ppr} feature is optional. It should
45867contain the 64-bit register @samp{ppr}.
45868
45869The @samp{org.gnu.gdb.power.dscr} feature is optional. It should
45870contain the 64-bit register @samp{dscr}.
45871
f2cf6173
EBM
45872The @samp{org.gnu.gdb.power.tar} feature is optional. It should
45873contain the 64-bit register @samp{tar}.
45874
232bfb86
EBM
45875The @samp{org.gnu.gdb.power.ebb} feature is optional. It should
45876contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
4587764-bit wide.
45878
45879The @samp{org.gnu.gdb.power.linux.pmu} feature is optional. It should
45880contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
45881and @samp{sier}, all 64-bit wide. This is the subset of the isa 2.07
45882server PMU registers provided by @sc{gnu}/Linux.
45883
8d619c01
EBM
45884The @samp{org.gnu.gdb.power.htm.spr} feature is optional. It should
45885contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
4588664-bit wide.
45887
45888The @samp{org.gnu.gdb.power.htm.core} feature is optional. It should
45889contain the checkpointed general-purpose registers @samp{cr0} through
45890@samp{cr31}, as well as the checkpointed registers @samp{clr} and
45891@samp{cctr}. These registers may all be either 32-bit or 64-bit
45892depending on the target. It should also contain the checkpointed
45893registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
45894wide.
45895
45896The @samp{org.gnu.gdb.power.htm.fpu} feature is optional. It should
45897contain the checkpointed 64-bit floating-point registers @samp{cf0}
45898through @samp{cf31}, as well as the checkpointed 64-bit register
45899@samp{cfpscr}.
45900
45901The @samp{org.gnu.gdb.power.htm.altivec} feature is optional. It
45902should contain the checkpointed altivec registers @samp{cvr0} through
45903@samp{cvr31}, all 128-bit wide. It should also contain the
45904checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
45905wide.
45906
45907The @samp{org.gnu.gdb.power.htm.vsx} feature is optional. It should
45908contain registers @samp{cvs0h} through @samp{cvs31h}. @value{GDBN}
45909will combine these registers with the checkpointed floating point
45910registers (@samp{cf0} through @samp{cf31}) and the checkpointed
45911altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
45912128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
45913@samp{cvs63}. Therefore, this feature requires both
45914@samp{org.gnu.gdb.power.htm.altivec} and
45915@samp{org.gnu.gdb.power.htm.fpu}.
45916
45917The @samp{org.gnu.gdb.power.htm.ppr} feature is optional. It should
45918contain the 64-bit checkpointed register @samp{cppr}.
45919
45920The @samp{org.gnu.gdb.power.htm.dscr} feature is optional. It should
45921contain the 64-bit checkpointed register @samp{cdscr}.
45922
45923The @samp{org.gnu.gdb.power.htm.tar} feature is optional. It should
45924contain the 64-bit checkpointed register @samp{ctar}.
45925
b5ffee31
AB
45926
45927@node RISC-V Features
45928@subsection RISC-V Features
45929@cindex target descriptions, RISC-V Features
45930
45931The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
45932targets. It should contain the registers @samp{x0} through
45933@samp{x31}, and @samp{pc}. Either the architectural names (@samp{x0},
45934@samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
45935etc).
45936
45937The @samp{org.gnu.gdb.riscv.fpu} feature is optional. If present, it
45938should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
45939@samp{frm}, and @samp{fcsr}. As with the cpu feature, either the
45940architectural register names, or the ABI names can be used.
45941
45942The @samp{org.gnu.gdb.riscv.virtual} feature is optional. If present,
45943it should contain registers that are not backed by real registers on
45944the target, but are instead virtual, where the register value is
45945derived from other target state. In many ways these are like
45946@value{GDBN}s pseudo-registers, except implemented by the target.
45947Currently the only register expected in this set is the one byte
45948@samp{priv} register that contains the target's privilege level in the
45949least significant two bits.
45950
45951The @samp{org.gnu.gdb.riscv.csr} feature is optional. If present, it
45952should contain all of the target's standard CSRs. Standard CSRs are
45953those defined in the RISC-V specification documents. There is some
45954overlap between this feature and the fpu feature; the @samp{fflags},
45955@samp{frm}, and @samp{fcsr} registers could be in either feature. The
45956expectation is that these registers will be in the fpu feature if the
45957target has floating point hardware, but can be moved into the csr
45958feature if the target has the floating point control registers, but no
45959other floating point hardware.
45960
e3ec872f
YS
45961@node RX Features
45962@subsection RX Features
45963@cindex target descriptions, RX Features
45964
45965The @samp{org.gnu.gdb.rx.core} feature is required for RX
45966targets. It should contain the registers @samp{r0} through
45967@samp{r15}, @samp{usp}, @samp{isp}, @samp{psw}, @samp{pc}, @samp{intb},
45968@samp{bpsw}, @samp{bpc}, @samp{fintv}, @samp{fpsw}, and @samp{acc}.
45969
4ac33720
UW
45970@node S/390 and System z Features
45971@subsection S/390 and System z Features
45972@cindex target descriptions, S/390 features
45973@cindex target descriptions, System z features
45974
45975The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
45976System z targets. It should contain the PSW and the 16 general
45977registers. In particular, System z targets should provide the 64-bit
45978registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
45979S/390 targets should provide the 32-bit versions of these registers.
45980A System z target that runs in 31-bit addressing mode should provide
4598132-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
45982register's upper halves @samp{r0h} through @samp{r15h}, and their
45983lower halves @samp{r0l} through @samp{r15l}.
45984
45985The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
45986contain the 64-bit registers @samp{f0} through @samp{f15}, and
45987@samp{fpc}.
45988
45989The @samp{org.gnu.gdb.s390.acr} feature is required. It should
45990contain the 32-bit registers @samp{acr0} through @samp{acr15}.
45991
45992The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
45993contain the register @samp{orig_r2}, which is 64-bit wide on System z
45994targets and 32-bit otherwise. In addition, the feature may contain
45995the @samp{last_break} register, whose width depends on the addressing
45996mode, as well as the @samp{system_call} register, which is always
4599732-bit wide.
45998
45999The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
46000contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
46001@samp{atia}, and @samp{tr0} through @samp{tr15}.
46002
446899e4
AA
46003The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
4600464-bit wide registers @samp{v0l} through @samp{v15l}, which will be
46005combined by @value{GDBN} with the floating point registers @samp{f0}
46006through @samp{f15} to present the 128-bit wide vector registers
46007@samp{v0} through @samp{v15}. In addition, this feature should
46008contain the 128-bit wide vector registers @samp{v16} through
46009@samp{v31}.
46010
289e23aa
AA
46011The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
46012the 64-bit wide guarded-storage-control registers @samp{gsd},
46013@samp{gssm}, and @samp{gsepla}.
46014
46015The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
46016the 64-bit wide guarded-storage broadcast control registers
46017@samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
46018
3f7b46f2
IR
46019@node Sparc Features
46020@subsection Sparc Features
46021@cindex target descriptions, sparc32 features
46022@cindex target descriptions, sparc64 features
46023The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
46024targets. It should describe the following registers:
46025
46026@itemize @minus
46027@item
46028@samp{g0} through @samp{g7}
46029@item
46030@samp{o0} through @samp{o7}
46031@item
46032@samp{l0} through @samp{l7}
46033@item
46034@samp{i0} through @samp{i7}
46035@end itemize
46036
46037They may be 32-bit or 64-bit depending on the target.
46038
46039Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
46040targets. It should describe the following registers:
46041
46042@itemize @minus
46043@item
46044@samp{f0} through @samp{f31}
46045@item
46046@samp{f32} through @samp{f62} for sparc64
46047@end itemize
46048
46049The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
46050targets. It should describe the following registers:
46051
46052@itemize @minus
46053@item
46054@samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
46055@samp{fsr}, and @samp{csr} for sparc32
46056@item
46057@samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
46058for sparc64
46059@end itemize
46060
224bbe49
YQ
46061@node TIC6x Features
46062@subsection TMS320C6x Features
46063@cindex target descriptions, TIC6x features
46064@cindex target descriptions, TMS320C6x features
46065The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
46066targets. It should contain registers @samp{A0} through @samp{A15},
46067registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
46068
46069The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
46070contain registers @samp{A16} through @samp{A31} and @samp{B16}
46071through @samp{B31}.
46072
46073The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
46074contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
46075
07e059b5
VP
46076@node Operating System Information
46077@appendix Operating System Information
46078@cindex operating system information
46079
07e059b5
VP
46080Users of @value{GDBN} often wish to obtain information about the state of
46081the operating system running on the target---for example the list of
46082processes, or the list of open files. This section describes the
46083mechanism that makes it possible. This mechanism is similar to the
46084target features mechanism (@pxref{Target Descriptions}), but focuses
46085on a different aspect of target.
46086
6b92c0d3 46087Operating system information is retrieved from the target via the
07e059b5
VP
46088remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
46089read}). The object name in the request should be @samp{osdata}, and
46090the @var{annex} identifies the data to be fetched.
46091
04de9f3e
AB
46092@menu
46093* Process list::
46094@end menu
46095
07e059b5
VP
46096@node Process list
46097@appendixsection Process list
46098@cindex operating system information, process list
46099
46100When requesting the process list, the @var{annex} field in the
46101@samp{qXfer} request should be @samp{processes}. The returned data is
46102an XML document. The formal syntax of this document is defined in
46103@file{gdb/features/osdata.dtd}.
46104
46105An example document is:
46106
46107@smallexample
46108<?xml version="1.0"?>
46109<!DOCTYPE target SYSTEM "osdata.dtd">
46110<osdata type="processes">
46111 <item>
46112 <column name="pid">1</column>
46113 <column name="user">root</column>
46114 <column name="command">/sbin/init</column>
dc146f7c 46115 <column name="cores">1,2,3</column>
07e059b5
VP
46116 </item>
46117</osdata>
46118@end smallexample
46119
46120Each item should include a column whose name is @samp{pid}. The value
46121of that column should identify the process on the target. The
46122@samp{user} and @samp{command} columns are optional, and will be
dc146f7c
VP
46123displayed by @value{GDBN}. The @samp{cores} column, if present,
46124should contain a comma-separated list of cores that this process
46125is running on. Target may provide additional columns,
07e059b5
VP
46126which @value{GDBN} currently ignores.
46127
05c8c3f5
TT
46128@node Trace File Format
46129@appendix Trace File Format
46130@cindex trace file format
46131
46132The trace file comes in three parts: a header, a textual description
46133section, and a trace frame section with binary data.
46134
46135The header has the form @code{\x7fTRACE0\n}. The first byte is
46136@code{0x7f} so as to indicate that the file contains binary data,
46137while the @code{0} is a version number that may have different values
46138in the future.
46139
46140The description section consists of multiple lines of @sc{ascii} text
46141separated by newline characters (@code{0xa}). The lines may include a
46142variety of optional descriptive or context-setting information, such
46143as tracepoint definitions or register set size. @value{GDBN} will
46144ignore any line that it does not recognize. An empty line marks the end
46145of this section.
46146
0748bf3e
MK
46147@table @code
46148@item R @var{size}
46149Specifies the size of a register block in bytes. This is equal to the
46150size of a @code{g} packet payload in the remote protocol. @var{size}
46151is an ascii decimal number. There should be only one such line in
46152a single trace file.
46153
46154@item status @var{status}
46155Trace status. @var{status} has the same format as a @code{qTStatus}
46156remote packet reply. There should be only one such line in a single trace
46157file.
46158
46159@item tp @var{payload}
46160Tracepoint definition. The @var{payload} has the same format as
46161@code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
46162may take multiple lines of definition, corresponding to the multiple
46163reply packets.
46164
46165@item tsv @var{payload}
46166Trace state variable definition. The @var{payload} has the same format as
46167@code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
46168may take multiple lines of definition, corresponding to the multiple
46169reply packets.
46170
46171@item tdesc @var{payload}
46172Target description in XML format. The @var{payload} is a single line of
46173the XML file. All such lines should be concatenated together to get
46174the original XML file. This file is in the same format as @code{qXfer}
46175@code{features} payload, and corresponds to the main @code{target.xml}
46176file. Includes are not allowed.
46177
46178@end table
05c8c3f5
TT
46179
46180The trace frame section consists of a number of consecutive frames.
46181Each frame begins with a two-byte tracepoint number, followed by a
46182four-byte size giving the amount of data in the frame. The data in
46183the frame consists of a number of blocks, each introduced by a
46184character indicating its type (at least register, memory, and trace
46185state variable). The data in this section is raw binary, not a
46186hexadecimal or other encoding; its endianness matches the target's
46187endianness.
46188
46189@c FIXME bi-arch may require endianness/arch info in description section
46190
46191@table @code
46192@item R @var{bytes}
46193Register block. The number and ordering of bytes matches that of a
46194@code{g} packet in the remote protocol. Note that these are the
e909d859 46195actual bytes, in target order, not a hexadecimal encoding.
05c8c3f5
TT
46196
46197@item M @var{address} @var{length} @var{bytes}...
46198Memory block. This is a contiguous block of memory, at the 8-byte
46199address @var{address}, with a 2-byte length @var{length}, followed by
46200@var{length} bytes.
46201
46202@item V @var{number} @var{value}
46203Trace state variable block. This records the 8-byte signed value
46204@var{value} of trace state variable numbered @var{number}.
46205
46206@end table
46207
46208Future enhancements of the trace file format may include additional types
46209of blocks.
46210
90476074
TT
46211@node Index Section Format
46212@appendix @code{.gdb_index} section format
46213@cindex .gdb_index section format
46214@cindex index section format
46215
46216This section documents the index section that is created by @code{save
46217gdb-index} (@pxref{Index Files}). The index section is
46218DWARF-specific; some knowledge of DWARF is assumed in this
46219description.
46220
46221The mapped index file format is designed to be directly
46222@code{mmap}able on any architecture. In most cases, a datum is
46223represented using a little-endian 32-bit integer value, called an
46224@code{offset_type}. Big endian machines must byte-swap the values
46225before using them. Exceptions to this rule are noted. The data is
46226laid out such that alignment is always respected.
46227
46228A mapped index consists of several areas, laid out in order.
46229
46230@enumerate
46231@item
46232The file header. This is a sequence of values, of @code{offset_type}
46233unless otherwise noted:
46234
46235@enumerate
46236@item
796a7ff8 46237The version number, currently 8. Versions 1, 2 and 3 are obsolete.
481860b3 46238Version 4 uses a different hashing function from versions 5 and 6.
b6ba681c
TT
46239Version 6 includes symbols for inlined functions, whereas versions 4
46240and 5 do not. Version 7 adds attributes to the CU indices in the
796a7ff8
DE
46241symbol table. Version 8 specifies that symbols from DWARF type units
46242(@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
46243compilation unit (@samp{DW_TAG_comp_unit}) using the type.
46244
46245@value{GDBN} will only read version 4, 5, or 6 indices
e615022a 46246by specifying @code{set use-deprecated-index-sections on}.
796a7ff8
DE
46247GDB has a workaround for potentially broken version 7 indices so it is
46248currently not flagged as deprecated.
90476074
TT
46249
46250@item
46251The offset, from the start of the file, of the CU list.
46252
46253@item
46254The offset, from the start of the file, of the types CU list. Note
46255that this area can be empty, in which case this offset will be equal
46256to the next offset.
46257
46258@item
46259The offset, from the start of the file, of the address area.
46260
46261@item
46262The offset, from the start of the file, of the symbol table.
46263
46264@item
46265The offset, from the start of the file, of the constant pool.
46266@end enumerate
46267
46268@item
46269The CU list. This is a sequence of pairs of 64-bit little-endian
46270values, sorted by the CU offset. The first element in each pair is
46271the offset of a CU in the @code{.debug_info} section. The second
46272element in each pair is the length of that CU. References to a CU
46273elsewhere in the map are done using a CU index, which is just the
462740-based index into this table. Note that if there are type CUs, then
46275conceptually CUs and type CUs form a single list for the purposes of
46276CU indices.
46277
46278@item
46279The types CU list. This is a sequence of triplets of 64-bit
46280little-endian values. In a triplet, the first value is the CU offset,
46281the second value is the type offset in the CU, and the third value is
46282the type signature. The types CU list is not sorted.
46283
46284@item
46285The address area. The address area consists of a sequence of address
46286entries. Each address entry has three elements:
46287
46288@enumerate
46289@item
46290The low address. This is a 64-bit little-endian value.
46291
46292@item
46293The high address. This is a 64-bit little-endian value. Like
46294@code{DW_AT_high_pc}, the value is one byte beyond the end.
46295
46296@item
46297The CU index. This is an @code{offset_type} value.
46298@end enumerate
46299
46300@item
46301The symbol table. This is an open-addressed hash table. The size of
46302the hash table is always a power of 2.
46303
46304Each slot in the hash table consists of a pair of @code{offset_type}
46305values. The first value is the offset of the symbol's name in the
46306constant pool. The second value is the offset of the CU vector in the
46307constant pool.
46308
46309If both values are 0, then this slot in the hash table is empty. This
46310is ok because while 0 is a valid constant pool index, it cannot be a
46311valid index for both a string and a CU vector.
46312
46313The hash value for a table entry is computed by applying an
46314iterative hash function to the symbol's name. Starting with an
46315initial value of @code{r = 0}, each (unsigned) character @samp{c} in
559a7a62
JK
46316the string is incorporated into the hash using the formula depending on the
46317index version:
46318
46319@table @asis
46320@item Version 4
46321The formula is @code{r = r * 67 + c - 113}.
46322
156942c7 46323@item Versions 5 to 7
559a7a62
JK
46324The formula is @code{r = r * 67 + tolower (c) - 113}.
46325@end table
46326
46327The terminating @samp{\0} is not incorporated into the hash.
90476074
TT
46328
46329The step size used in the hash table is computed via
46330@code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
46331value, and @samp{size} is the size of the hash table. The step size
46332is used to find the next candidate slot when handling a hash
46333collision.
46334
46335The names of C@t{++} symbols in the hash table are canonicalized. We
46336don't currently have a simple description of the canonicalization
46337algorithm; if you intend to create new index sections, you must read
46338the code.
46339
46340@item
46341The constant pool. This is simply a bunch of bytes. It is organized
46342so that alignment is correct: CU vectors are stored first, followed by
46343strings.
46344
46345A CU vector in the constant pool is a sequence of @code{offset_type}
46346values. The first value is the number of CU indices in the vector.
156942c7
DE
46347Each subsequent value is the index and symbol attributes of a CU in
46348the CU list. This element in the hash table is used to indicate which
46349CUs define the symbol and how the symbol is used.
46350See below for the format of each CU index+attributes entry.
90476074
TT
46351
46352A string in the constant pool is zero-terminated.
46353@end enumerate
46354
156942c7
DE
46355Attributes were added to CU index values in @code{.gdb_index} version 7.
46356If a symbol has multiple uses within a CU then there is one
46357CU index+attributes value for each use.
46358
46359The format of each CU index+attributes entry is as follows
46360(bit 0 = LSB):
46361
46362@table @asis
46363
46364@item Bits 0-23
46365This is the index of the CU in the CU list.
46366@item Bits 24-27
46367These bits are reserved for future purposes and must be zero.
46368@item Bits 28-30
46369The kind of the symbol in the CU.
46370
46371@table @asis
46372@item 0
46373This value is reserved and should not be used.
46374By reserving zero the full @code{offset_type} value is backwards compatible
46375with previous versions of the index.
46376@item 1
46377The symbol is a type.
46378@item 2
46379The symbol is a variable or an enum value.
46380@item 3
46381The symbol is a function.
46382@item 4
46383Any other kind of symbol.
46384@item 5,6,7
46385These values are reserved.
46386@end table
46387
46388@item Bit 31
46389This bit is zero if the value is global and one if it is static.
46390
46391The determination of whether a symbol is global or static is complicated.
46392The authorative reference is the file @file{dwarf2read.c} in
46393@value{GDBN} sources.
46394
46395@end table
46396
46397This pseudo-code describes the computation of a symbol's kind and
46398global/static attributes in the index.
46399
46400@smallexample
46401is_external = get_attribute (die, DW_AT_external);
46402language = get_attribute (cu_die, DW_AT_language);
46403switch (die->tag)
46404 @{
46405 case DW_TAG_typedef:
46406 case DW_TAG_base_type:
46407 case DW_TAG_subrange_type:
46408 kind = TYPE;
46409 is_static = 1;
46410 break;
46411 case DW_TAG_enumerator:
46412 kind = VARIABLE;
9c37b5ae 46413 is_static = language != CPLUS;
156942c7
DE
46414 break;
46415 case DW_TAG_subprogram:
46416 kind = FUNCTION;
46417 is_static = ! (is_external || language == ADA);
46418 break;
46419 case DW_TAG_constant:
46420 kind = VARIABLE;
46421 is_static = ! is_external;
46422 break;
46423 case DW_TAG_variable:
46424 kind = VARIABLE;
46425 is_static = ! is_external;
46426 break;
46427 case DW_TAG_namespace:
46428 kind = TYPE;
46429 is_static = 0;
46430 break;
46431 case DW_TAG_class_type:
46432 case DW_TAG_interface_type:
46433 case DW_TAG_structure_type:
46434 case DW_TAG_union_type:
46435 case DW_TAG_enumeration_type:
46436 kind = TYPE;
9c37b5ae 46437 is_static = language != CPLUS;
156942c7
DE
46438 break;
46439 default:
46440 assert (0);
46441 @}
46442@end smallexample
46443
43662968
JK
46444@node Man Pages
46445@appendix Manual pages
46446@cindex Man pages
46447
46448@menu
46449* gdb man:: The GNU Debugger man page
46450* gdbserver man:: Remote Server for the GNU Debugger man page
b292c783 46451* gcore man:: Generate a core file of a running program
43662968 46452* gdbinit man:: gdbinit scripts
ba643918 46453* gdb-add-index man:: Add index files to speed up GDB
43662968
JK
46454@end menu
46455
46456@node gdb man
46457@heading gdb man
46458
46459@c man title gdb The GNU Debugger
46460
46461@c man begin SYNOPSIS gdb
46462gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
46463[@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
46464[@option{-b}@w{ }@var{bps}]
46465 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
46466[@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
906ccdf0
JK
46467[@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
46468 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
46469[@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
43662968
JK
46470@c man end
46471
46472@c man begin DESCRIPTION gdb
46473The purpose of a debugger such as @value{GDBN} is to allow you to see what is
46474going on ``inside'' another program while it executes -- or what another
46475program was doing at the moment it crashed.
46476
46477@value{GDBN} can do four main kinds of things (plus other things in support of
46478these) to help you catch bugs in the act:
46479
46480@itemize @bullet
46481@item
46482Start your program, specifying anything that might affect its behavior.
46483
46484@item
46485Make your program stop on specified conditions.
46486
46487@item
46488Examine what has happened, when your program has stopped.
46489
46490@item
46491Change things in your program, so you can experiment with correcting the
46492effects of one bug and go on to learn about another.
46493@end itemize
46494
906ccdf0
JK
46495You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
46496Modula-2.
43662968
JK
46497
46498@value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
46499commands from the terminal until you tell it to exit with the @value{GDBN}
46500command @code{quit}. You can get online help from @value{GDBN} itself
46501by using the command @code{help}.
46502
46503You can run @code{gdb} with no arguments or options; but the most
46504usual way to start @value{GDBN} is with one argument or two, specifying an
46505executable program as the argument:
46506
46507@smallexample
46508gdb program
46509@end smallexample
46510
46511You can also start with both an executable program and a core file specified:
46512
46513@smallexample
46514gdb program core
46515@end smallexample
46516
4ed4690f
SM
46517You can, instead, specify a process ID as a second argument or use option
46518@code{-p}, if you want to debug a running process:
43662968
JK
46519
46520@smallexample
46521gdb program 1234
906ccdf0 46522gdb -p 1234
43662968
JK
46523@end smallexample
46524
46525@noindent
4ed4690f
SM
46526would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
46527can omit the @var{program} filename.
43662968
JK
46528
46529Here are some of the most frequently needed @value{GDBN} commands:
46530
46531@c pod2man highlights the right hand side of the @item lines.
46532@table @env
224f10c1 46533@item break [@var{file}:]@var{function}
43662968
JK
46534Set a breakpoint at @var{function} (in @var{file}).
46535
46536@item run [@var{arglist}]
46537Start your program (with @var{arglist}, if specified).
46538
46539@item bt
46540Backtrace: display the program stack.
46541
46542@item print @var{expr}
46543Display the value of an expression.
46544
46545@item c
46546Continue running your program (after stopping, e.g. at a breakpoint).
46547
46548@item next
46549Execute next program line (after stopping); step @emph{over} any
46550function calls in the line.
46551
46552@item edit [@var{file}:]@var{function}
46553look at the program line where it is presently stopped.
46554
46555@item list [@var{file}:]@var{function}
46556type the text of the program in the vicinity of where it is presently stopped.
46557
46558@item step
46559Execute next program line (after stopping); step @emph{into} any
46560function calls in the line.
46561
46562@item help [@var{name}]
46563Show information about @value{GDBN} command @var{name}, or general information
46564about using @value{GDBN}.
46565
46566@item quit
46567Exit from @value{GDBN}.
46568@end table
46569
46570@ifset man
46571For full details on @value{GDBN},
46572see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46573by Richard M. Stallman and Roland H. Pesch. The same text is available online
46574as the @code{gdb} entry in the @code{info} program.
46575@end ifset
46576@c man end
46577
46578@c man begin OPTIONS gdb
46579Any arguments other than options specify an executable
46580file and core file (or process ID); that is, the first argument
46581encountered with no
46582associated option flag is equivalent to a @option{-se} option, and the second,
46583if any, is equivalent to a @option{-c} option if it's the name of a file.
46584Many options have
46585both long and short forms; both are shown here. The long forms are also
46586recognized if you truncate them, so long as enough of the option is
46587present to be unambiguous. (If you prefer, you can flag option
46588arguments with @option{+} rather than @option{-}, though we illustrate the
46589more usual convention.)
46590
46591All the options and command line arguments you give are processed
46592in sequential order. The order makes a difference when the @option{-x}
46593option is used.
46594
46595@table @env
46596@item -help
46597@itemx -h
46598List all options, with brief explanations.
46599
46600@item -symbols=@var{file}
46601@itemx -s @var{file}
46602Read symbol table from file @var{file}.
46603
46604@item -write
46605Enable writing into executable and core files.
46606
46607@item -exec=@var{file}
46608@itemx -e @var{file}
46609Use file @var{file} as the executable file to execute when
46610appropriate, and for examining pure data in conjunction with a core
46611dump.
46612
46613@item -se=@var{file}
46614Read symbol table from file @var{file} and use it as the executable
46615file.
46616
46617@item -core=@var{file}
46618@itemx -c @var{file}
46619Use file @var{file} as a core dump to examine.
46620
46621@item -command=@var{file}
46622@itemx -x @var{file}
46623Execute @value{GDBN} commands from file @var{file}.
46624
46625@item -ex @var{command}
46626Execute given @value{GDBN} @var{command}.
46627
46628@item -directory=@var{directory}
46629@itemx -d @var{directory}
46630Add @var{directory} to the path to search for source files.
46631
46632@item -nh
64aaad63
AB
46633Do not execute commands from @file{~/.config/gdb/gdbinit} or
46634@file{~/.gdbinit}.
43662968
JK
46635
46636@item -nx
46637@itemx -n
46638Do not execute commands from any @file{.gdbinit} initialization files.
46639
46640@item -quiet
46641@itemx -q
46642``Quiet''. Do not print the introductory and copyright messages. These
46643messages are also suppressed in batch mode.
46644
46645@item -batch
46646Run in batch mode. Exit with status @code{0} after processing all the command
46647files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
46648Exit with nonzero status if an error occurs in executing the @value{GDBN}
46649commands in the command files.
46650
46651Batch mode may be useful for running @value{GDBN} as a filter, for example to
46652download and run a program on another computer; in order to make this
46653more useful, the message
46654
46655@smallexample
46656Program exited normally.
46657@end smallexample
46658
46659@noindent
46660(which is ordinarily issued whenever a program running under @value{GDBN} control
46661terminates) is not issued when running in batch mode.
46662
46663@item -cd=@var{directory}
46664Run @value{GDBN} using @var{directory} as its working directory,
46665instead of the current directory.
46666
46667@item -fullname
46668@itemx -f
46669Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
46670@value{GDBN} to output the full file name and line number in a standard,
46671recognizable fashion each time a stack frame is displayed (which
46672includes each time the program stops). This recognizable format looks
46673like two @samp{\032} characters, followed by the file name, line number
46674and character position separated by colons, and a newline. The
46675Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
46676characters as a signal to display the source code for the frame.
46677
46678@item -b @var{bps}
46679Set the line speed (baud rate or bits per second) of any serial
46680interface used by @value{GDBN} for remote debugging.
46681
46682@item -tty=@var{device}
46683Run using @var{device} for your program's standard input and output.
46684@end table
46685@c man end
46686
46687@c man begin SEEALSO gdb
46688@ifset man
46689The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46690If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46691documentation are properly installed at your site, the command
46692
46693@smallexample
46694info gdb
46695@end smallexample
46696
46697@noindent
46698should give you access to the complete manual.
46699
46700@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46701Richard M. Stallman and Roland H. Pesch, July 1991.
46702@end ifset
46703@c man end
46704
46705@node gdbserver man
46706@heading gdbserver man
46707
46708@c man title gdbserver Remote Server for the GNU Debugger
46709@format
46710@c man begin SYNOPSIS gdbserver
5b8b6385 46711gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
43662968 46712
5b8b6385
JK
46713gdbserver --attach @var{comm} @var{pid}
46714
46715gdbserver --multi @var{comm}
43662968
JK
46716@c man end
46717@end format
46718
46719@c man begin DESCRIPTION gdbserver
46720@command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
46721than the one which is running the program being debugged.
46722
46723@ifclear man
46724@subheading Usage (server (target) side)
46725@end ifclear
46726@ifset man
46727Usage (server (target) side):
46728@end ifset
46729
46730First, you need to have a copy of the program you want to debug put onto
46731the target system. The program can be stripped to save space if needed, as
46732@command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
46733the @value{GDBN} running on the host system.
46734
46735To use the server, you log on to the target system, and run the @command{gdbserver}
46736program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
46737your program, and (c) its arguments. The general syntax is:
46738
46739@smallexample
46740target> gdbserver @var{comm} @var{program} [@var{args} ...]
46741@end smallexample
46742
46743For example, using a serial port, you might say:
46744
46745@smallexample
46746@ifset man
46747@c @file would wrap it as F</dev/com1>.
46748target> gdbserver /dev/com1 emacs foo.txt
46749@end ifset
46750@ifclear man
46751target> gdbserver @file{/dev/com1} emacs foo.txt
46752@end ifclear
46753@end smallexample
46754
46755This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
46756to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
46757waits patiently for the host @value{GDBN} to communicate with it.
46758
46759To use a TCP connection, you could say:
46760
46761@smallexample
46762target> gdbserver host:2345 emacs foo.txt
46763@end smallexample
46764
46765This says pretty much the same thing as the last example, except that we are
46766going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
46767that we are expecting to see a TCP connection from @code{host} to local TCP port
467682345. (Currently, the @code{host} part is ignored.) You can choose any number you
46769want for the port number as long as it does not conflict with any existing TCP
46770ports on the target system. This same port number must be used in the host
46771@value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
46772you chose a port number that conflicts with another service, @command{gdbserver} will
46773print an error message and exit.
46774
5b8b6385 46775@command{gdbserver} can also attach to running programs.
43662968
JK
46776This is accomplished via the @option{--attach} argument. The syntax is:
46777
46778@smallexample
5b8b6385 46779target> gdbserver --attach @var{comm} @var{pid}
43662968
JK
46780@end smallexample
46781
46782@var{pid} is the process ID of a currently running process. It isn't
46783necessary to point @command{gdbserver} at a binary for the running process.
46784
5b8b6385
JK
46785To start @code{gdbserver} without supplying an initial command to run
46786or process ID to attach, use the @option{--multi} command line option.
46787In such case you should connect using @kbd{target extended-remote} to start
46788the program you want to debug.
46789
46790@smallexample
46791target> gdbserver --multi @var{comm}
46792@end smallexample
46793
43662968
JK
46794@ifclear man
46795@subheading Usage (host side)
46796@end ifclear
46797@ifset man
46798Usage (host side):
46799@end ifset
46800
46801You need an unstripped copy of the target program on your host system, since
1a088a2e 46802@value{GDBN} needs to examine its symbol tables and such. Start up @value{GDBN} as you normally
43662968
JK
46803would, with the target program as the first argument. (You may need to use the
46804@option{--baud} option if the serial line is running at anything except 9600 baud.)
46805That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
5b8b6385
JK
46806new command you need to know about is @code{target remote}
46807(or @code{target extended-remote}). Its argument is either
43662968
JK
46808a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
46809descriptor. For example:
46810
46811@smallexample
46812@ifset man
46813@c @file would wrap it as F</dev/ttyb>.
46814(gdb) target remote /dev/ttyb
46815@end ifset
46816@ifclear man
46817(gdb) target remote @file{/dev/ttyb}
46818@end ifclear
46819@end smallexample
46820
46821@noindent
46822communicates with the server via serial line @file{/dev/ttyb}, and:
46823
46824@smallexample
46825(gdb) target remote the-target:2345
46826@end smallexample
46827
46828@noindent
46829communicates via a TCP connection to port 2345 on host `the-target', where
46830you previously started up @command{gdbserver} with the same port number. Note that for
46831TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
46832command, otherwise you may get an error that looks something like
46833`Connection refused'.
5b8b6385
JK
46834
46835@command{gdbserver} can also debug multiple inferiors at once,
46836described in
46837@ifset man
65c574f6
PA
46838the @value{GDBN} manual in node @code{Inferiors Connections and Programs}
46839-- shell command @code{info -f gdb -n 'Inferiors Connections and Programs'}.
5b8b6385
JK
46840@end ifset
46841@ifclear man
65c574f6 46842@ref{Inferiors Connections and Programs}.
5b8b6385
JK
46843@end ifclear
46844In such case use the @code{extended-remote} @value{GDBN} command variant:
46845
46846@smallexample
46847(gdb) target extended-remote the-target:2345
46848@end smallexample
46849
46850The @command{gdbserver} option @option{--multi} may or may not be used in such
46851case.
43662968
JK
46852@c man end
46853
46854@c man begin OPTIONS gdbserver
5b8b6385
JK
46855There are three different modes for invoking @command{gdbserver}:
46856
46857@itemize @bullet
46858
46859@item
46860Debug a specific program specified by its program name:
46861
46862@smallexample
46863gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
46864@end smallexample
46865
46866The @var{comm} parameter specifies how should the server communicate
46867with @value{GDBN}; it is either a device name (to use a serial line),
46868a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
46869stdin/stdout of @code{gdbserver}. Specify the name of the program to
46870debug in @var{prog}. Any remaining arguments will be passed to the
46871program verbatim. When the program exits, @value{GDBN} will close the
46872connection, and @code{gdbserver} will exit.
46873
46874@item
46875Debug a specific program by specifying the process ID of a running
46876program:
46877
46878@smallexample
46879gdbserver --attach @var{comm} @var{pid}
46880@end smallexample
46881
46882The @var{comm} parameter is as described above. Supply the process ID
46883of a running program in @var{pid}; @value{GDBN} will do everything
46884else. Like with the previous mode, when the process @var{pid} exits,
46885@value{GDBN} will close the connection, and @code{gdbserver} will exit.
46886
46887@item
46888Multi-process mode -- debug more than one program/process:
46889
46890@smallexample
46891gdbserver --multi @var{comm}
46892@end smallexample
46893
46894In this mode, @value{GDBN} can instruct @command{gdbserver} which
46895command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
46896close the connection when a process being debugged exits, so you can
46897debug several processes in the same session.
46898@end itemize
46899
46900In each of the modes you may specify these options:
46901
46902@table @env
46903
46904@item --help
46905List all options, with brief explanations.
46906
46907@item --version
46908This option causes @command{gdbserver} to print its version number and exit.
46909
46910@item --attach
46911@command{gdbserver} will attach to a running program. The syntax is:
46912
46913@smallexample
46914target> gdbserver --attach @var{comm} @var{pid}
46915@end smallexample
46916
46917@var{pid} is the process ID of a currently running process. It isn't
46918necessary to point @command{gdbserver} at a binary for the running process.
46919
46920@item --multi
46921To start @code{gdbserver} without supplying an initial command to run
46922or process ID to attach, use this command line option.
46923Then you can connect using @kbd{target extended-remote} and start
46924the program you want to debug. The syntax is:
46925
46926@smallexample
46927target> gdbserver --multi @var{comm}
46928@end smallexample
46929
46930@item --debug
46931Instruct @code{gdbserver} to display extra status information about the debugging
46932process.
46933This option is intended for @code{gdbserver} development and for bug reports to
46934the developers.
46935
46936@item --remote-debug
46937Instruct @code{gdbserver} to display remote protocol debug output.
46938This option is intended for @code{gdbserver} development and for bug reports to
46939the developers.
46940
aeb2e706
AH
46941@item --debug-file=@var{filename}
46942Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
46943This option is intended for @code{gdbserver} development and for bug reports to
46944the developers.
46945
87ce2a04
DE
46946@item --debug-format=option1@r{[},option2,...@r{]}
46947Instruct @code{gdbserver} to include extra information in each line
46948of debugging output.
46949@xref{Other Command-Line Arguments for gdbserver}.
46950
5b8b6385
JK
46951@item --wrapper
46952Specify a wrapper to launch programs
46953for debugging. The option should be followed by the name of the
46954wrapper, then any command-line arguments to pass to the wrapper, then
46955@kbd{--} indicating the end of the wrapper arguments.
46956
46957@item --once
46958By default, @command{gdbserver} keeps the listening TCP port open, so that
46959additional connections are possible. However, if you start @code{gdbserver}
46960with the @option{--once} option, it will stop listening for any further
46961connection attempts after connecting to the first @value{GDBN} session.
46962
46963@c --disable-packet is not documented for users.
46964
46965@c --disable-randomization and --no-disable-randomization are superseded by
46966@c QDisableRandomization.
46967
46968@end table
43662968
JK
46969@c man end
46970
46971@c man begin SEEALSO gdbserver
46972@ifset man
46973The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46974If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46975documentation are properly installed at your site, the command
46976
46977@smallexample
46978info gdb
46979@end smallexample
46980
46981should give you access to the complete manual.
46982
46983@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46984Richard M. Stallman and Roland H. Pesch, July 1991.
46985@end ifset
46986@c man end
46987
b292c783
JK
46988@node gcore man
46989@heading gcore
46990
46991@c man title gcore Generate a core file of a running program
46992
46993@format
46994@c man begin SYNOPSIS gcore
129eb0f1 46995gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
b292c783
JK
46996@c man end
46997@end format
46998
46999@c man begin DESCRIPTION gcore
129eb0f1
SDJ
47000Generate core dumps of one or more running programs with process IDs
47001@var{pid1}, @var{pid2}, etc. A core file produced by @command{gcore}
47002is equivalent to one produced by the kernel when the process crashes
47003(and when @kbd{ulimit -c} was used to set up an appropriate core dump
47004limit). However, unlike after a crash, after @command{gcore} finishes
47005its job the program remains running without any change.
b292c783
JK
47006@c man end
47007
47008@c man begin OPTIONS gcore
47009@table @env
c179febe
SL
47010@item -a
47011Dump all memory mappings. The actual effect of this option depends on
47012the Operating System. On @sc{gnu}/Linux, it will disable
47013@code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
47014enable @code{dump-excluded-mappings} (@pxref{set
47015dump-excluded-mappings}).
47016
129eb0f1
SDJ
47017@item -o @var{prefix}
47018The optional argument @var{prefix} specifies the prefix to be used
47019when composing the file names of the core dumps. The file name is
47020composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
47021process ID of the running program being analyzed by @command{gcore}.
47022If not specified, @var{prefix} defaults to @var{gcore}.
b292c783
JK
47023@end table
47024@c man end
47025
47026@c man begin SEEALSO gcore
47027@ifset man
47028The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47029If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47030documentation are properly installed at your site, the command
47031
47032@smallexample
47033info gdb
47034@end smallexample
47035
47036@noindent
47037should give you access to the complete manual.
47038
47039@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47040Richard M. Stallman and Roland H. Pesch, July 1991.
47041@end ifset
47042@c man end
47043
43662968
JK
47044@node gdbinit man
47045@heading gdbinit
47046
47047@c man title gdbinit GDB initialization scripts
47048
47049@format
47050@c man begin SYNOPSIS gdbinit
47051@ifset SYSTEM_GDBINIT
47052@value{SYSTEM_GDBINIT}
47053@end ifset
47054
ed2a2229
CB
47055@ifset SYSTEM_GDBINIT_DIR
47056@value{SYSTEM_GDBINIT_DIR}/*
47057@end ifset
47058
64aaad63
AB
47059~/.config/gdb/gdbinit
47060
43662968
JK
47061~/.gdbinit
47062
47063./.gdbinit
47064@c man end
47065@end format
47066
47067@c man begin DESCRIPTION gdbinit
47068These files contain @value{GDBN} commands to automatically execute during
47069@value{GDBN} startup. The lines of contents are canned sequences of commands,
47070described in
47071@ifset man
47072the @value{GDBN} manual in node @code{Sequences}
47073-- shell command @code{info -f gdb -n Sequences}.
47074@end ifset
47075@ifclear man
47076@ref{Sequences}.
47077@end ifclear
47078
47079Please read more in
47080@ifset man
47081the @value{GDBN} manual in node @code{Startup}
47082-- shell command @code{info -f gdb -n Startup}.
47083@end ifset
47084@ifclear man
47085@ref{Startup}.
47086@end ifclear
47087
47088@table @env
47089@ifset SYSTEM_GDBINIT
47090@item @value{SYSTEM_GDBINIT}
47091@end ifset
47092@ifclear SYSTEM_GDBINIT
47093@item (not enabled with @code{--with-system-gdbinit} during compilation)
47094@end ifclear
47095System-wide initialization file. It is executed unless user specified
47096@value{GDBN} option @code{-nx} or @code{-n}.
47097See more in
47098@ifset man
47099the @value{GDBN} manual in node @code{System-wide configuration}
47100-- shell command @code{info -f gdb -n 'System-wide configuration'}.
47101@end ifset
ed2a2229
CB
47102@ifset SYSTEM_GDBINIT_DIR
47103@item @value{SYSTEM_GDBINIT_DIR}
47104@end ifset
47105@ifclear SYSTEM_GDBINIT_DIR
47106@item (not enabled with @code{--with-system-gdbinit-dir} during compilation)
47107@end ifclear
47108System-wide initialization directory. All files in this directory are
47109executed on startup unless user specified @value{GDBN} option @code{-nx} or
47110@code{-n}, as long as they have a recognized file extension.
47111See more in
47112@ifset man
47113the @value{GDBN} manual in node @code{System-wide configuration}
47114-- shell command @code{info -f gdb -n 'System-wide configuration'}.
47115@end ifset
43662968
JK
47116@ifclear man
47117@ref{System-wide configuration}.
47118@end ifclear
47119
64aaad63 47120@item @file{~/.config/gdb/gdbinit} or @file{~/.gdbinit}
43662968
JK
47121User initialization file. It is executed unless user specified
47122@value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
47123
64aaad63 47124@item @file{.gdbinit}
43662968
JK
47125Initialization file for current directory. It may need to be enabled with
47126@value{GDBN} security command @code{set auto-load local-gdbinit}.
47127See more in
47128@ifset man
47129the @value{GDBN} manual in node @code{Init File in the Current Directory}
47130-- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
47131@end ifset
47132@ifclear man
47133@ref{Init File in the Current Directory}.
47134@end ifclear
47135@end table
47136@c man end
47137
47138@c man begin SEEALSO gdbinit
47139@ifset man
47140gdb(1), @code{info -f gdb -n Startup}
47141
47142The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47143If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47144documentation are properly installed at your site, the command
ba643918
SDJ
47145
47146@smallexample
47147info gdb
47148@end smallexample
47149
47150should give you access to the complete manual.
47151
47152@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47153Richard M. Stallman and Roland H. Pesch, July 1991.
47154@end ifset
47155@c man end
47156
47157@node gdb-add-index man
ba643918 47158@heading gdb-add-index
d726cb5d 47159@pindex gdb-add-index
dbfa4523 47160@anchor{gdb-add-index}
ba643918
SDJ
47161
47162@c man title gdb-add-index Add index files to speed up GDB
47163
47164@c man begin SYNOPSIS gdb-add-index
47165gdb-add-index @var{filename}
47166@c man end
47167
47168@c man begin DESCRIPTION gdb-add-index
47169When @value{GDBN} finds a symbol file, it scans the symbols in the
47170file in order to construct an internal symbol table. This lets most
47171@value{GDBN} operations work quickly--at the cost of a delay early on.
47172For large programs, this delay can be quite lengthy, so @value{GDBN}
47173provides a way to build an index, which speeds up startup.
47174
47175To determine whether a file contains such an index, use the command
47176@kbd{readelf -S filename}: the index is stored in a section named
47177@code{.gdb_index}. The index file can only be produced on systems
47178which use ELF binaries and DWARF debug information (i.e., sections
47179named @code{.debug_*}).
47180
47181@command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
47182in the @env{PATH} environment variable. If you want to use different
47183versions of these programs, you can specify them through the
47184@env{GDB} and @env{OBJDUMP} environment variables.
47185
47186See more in
47187@ifset man
47188the @value{GDBN} manual in node @code{Index Files}
47189-- shell command @kbd{info -f gdb -n "Index Files"}.
47190@end ifset
47191@ifclear man
47192@ref{Index Files}.
47193@end ifclear
47194@c man end
47195
47196@c man begin SEEALSO gdb-add-index
47197@ifset man
47198The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47199If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47200documentation are properly installed at your site, the command
43662968
JK
47201
47202@smallexample
47203info gdb
47204@end smallexample
47205
47206should give you access to the complete manual.
47207
47208@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47209Richard M. Stallman and Roland H. Pesch, July 1991.
47210@end ifset
47211@c man end
47212
aab4e0ec 47213@include gpl.texi
eb12ee30 47214
e4c0cfae
SS
47215@node GNU Free Documentation License
47216@appendix GNU Free Documentation License
6826cf00
EZ
47217@include fdl.texi
47218
00595b5e
EZ
47219@node Concept Index
47220@unnumbered Concept Index
c906108c
SS
47221
47222@printindex cp
47223
00595b5e
EZ
47224@node Command and Variable Index
47225@unnumbered Command, Variable, and Function Index
47226
47227@printindex fn
47228
c906108c 47229@tex
984359d2 47230% I think something like @@colophon should be in texinfo. In the
c906108c
SS
47231% meantime:
47232\long\def\colophon{\hbox to0pt{}\vfill
47233\centerline{The body of this manual is set in}
47234\centerline{\fontname\tenrm,}
47235\centerline{with headings in {\bf\fontname\tenbf}}
47236\centerline{and examples in {\tt\fontname\tentt}.}
47237\centerline{{\it\fontname\tenit\/},}
47238\centerline{{\bf\fontname\tenbf}, and}
47239\centerline{{\sl\fontname\tensl\/}}
47240\centerline{are used for emphasis.}\vfill}
47241\page\colophon
984359d2 47242% Blame: doc@@cygnus.com, 1991.
c906108c
SS
47243@end tex
47244
c906108c 47245@bye
This page took 8.340505 seconds and 4 git commands to generate.