Add a new debug knob for the FreeBSD native target.
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
e2882c85 2@c Copyright (C) 1988-2018 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
e2882c85 53Copyright @copyright{} 1988-2018 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
6d2ebf8b
SS
111@node Top, Summary, (dir), (dir)
112
c906108c
SS
113@top Debugging with @value{GDBN}
114
115This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
c16158bc
JM
117This is the @value{EDITION} Edition, for @value{GDBN}
118@ifset VERSION_PACKAGE
119@value{VERSION_PACKAGE}
120@end ifset
121Version @value{GDBVN}.
c906108c 122
e2882c85 123Copyright (C) 1988-2018 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
a994fec4
FJ
549The original port to the OpenRISC 1000 is believed to be due to
550Alessandro Forin and Per Bothner. More recent ports have been the work
551of Jeremy Bennett, Franck Jullien, Stefan Wallentowitz and
552Stafford Horne.
553
6d2ebf8b 554@node Sample Session
c906108c
SS
555@chapter A Sample @value{GDBN} Session
556
557You can use this manual at your leisure to read all about @value{GDBN}.
558However, a handful of commands are enough to get started using the
559debugger. This chapter illustrates those commands.
560
561@iftex
562In this sample session, we emphasize user input like this: @b{input},
563to make it easier to pick out from the surrounding output.
564@end iftex
565
566@c FIXME: this example may not be appropriate for some configs, where
567@c FIXME...primary interest is in remote use.
568
569One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
570processor) exhibits the following bug: sometimes, when we change its
571quote strings from the default, the commands used to capture one macro
572definition within another stop working. In the following short @code{m4}
573session, we define a macro @code{foo} which expands to @code{0000}; we
574then use the @code{m4} built-in @code{defn} to define @code{bar} as the
575same thing. However, when we change the open quote string to
576@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
577procedure fails to define a new synonym @code{baz}:
578
579@smallexample
580$ @b{cd gnu/m4}
581$ @b{./m4}
582@b{define(foo,0000)}
583
584@b{foo}
5850000
586@b{define(bar,defn(`foo'))}
587
588@b{bar}
5890000
590@b{changequote(<QUOTE>,<UNQUOTE>)}
591
592@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
593@b{baz}
c8aa23ab 594@b{Ctrl-d}
c906108c
SS
595m4: End of input: 0: fatal error: EOF in string
596@end smallexample
597
598@noindent
599Let us use @value{GDBN} to try to see what is going on.
600
c906108c
SS
601@smallexample
602$ @b{@value{GDBP} m4}
603@c FIXME: this falsifies the exact text played out, to permit smallbook
604@c FIXME... format to come out better.
605@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 606 of it under certain conditions; type "show copying" to see
c906108c 607 the conditions.
5d161b24 608There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
609 for details.
610
611@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
612(@value{GDBP})
613@end smallexample
c906108c
SS
614
615@noindent
616@value{GDBN} reads only enough symbol data to know where to find the
617rest when needed; as a result, the first prompt comes up very quickly.
618We now tell @value{GDBN} to use a narrower display width than usual, so
619that examples fit in this manual.
620
621@smallexample
622(@value{GDBP}) @b{set width 70}
623@end smallexample
624
625@noindent
626We need to see how the @code{m4} built-in @code{changequote} works.
627Having looked at the source, we know the relevant subroutine is
628@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
629@code{break} command.
630
631@smallexample
632(@value{GDBP}) @b{break m4_changequote}
633Breakpoint 1 at 0x62f4: file builtin.c, line 879.
634@end smallexample
635
636@noindent
637Using the @code{run} command, we start @code{m4} running under @value{GDBN}
638control; as long as control does not reach the @code{m4_changequote}
639subroutine, the program runs as usual:
640
641@smallexample
642(@value{GDBP}) @b{run}
643Starting program: /work/Editorial/gdb/gnu/m4/m4
644@b{define(foo,0000)}
645
646@b{foo}
6470000
648@end smallexample
649
650@noindent
651To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
652suspends execution of @code{m4}, displaying information about the
653context where it stops.
654
655@smallexample
656@b{changequote(<QUOTE>,<UNQUOTE>)}
657
5d161b24 658Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
659 at builtin.c:879
660879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
661@end smallexample
662
663@noindent
664Now we use the command @code{n} (@code{next}) to advance execution to
665the next line of the current function.
666
667@smallexample
668(@value{GDBP}) @b{n}
669882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
670 : nil,
671@end smallexample
672
673@noindent
674@code{set_quotes} looks like a promising subroutine. We can go into it
675by using the command @code{s} (@code{step}) instead of @code{next}.
676@code{step} goes to the next line to be executed in @emph{any}
677subroutine, so it steps into @code{set_quotes}.
678
679@smallexample
680(@value{GDBP}) @b{s}
681set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
682 at input.c:530
683530 if (lquote != def_lquote)
684@end smallexample
685
686@noindent
687The display that shows the subroutine where @code{m4} is now
688suspended (and its arguments) is called a stack frame display. It
689shows a summary of the stack. We can use the @code{backtrace}
690command (which can also be spelled @code{bt}), to see where we are
691in the stack as a whole: the @code{backtrace} command displays a
692stack frame for each active subroutine.
693
694@smallexample
695(@value{GDBP}) @b{bt}
696#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
697 at input.c:530
5d161b24 698#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
699 at builtin.c:882
700#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
701#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
702 at macro.c:71
703#4 0x79dc in expand_input () at macro.c:40
704#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
705@end smallexample
706
707@noindent
708We step through a few more lines to see what happens. The first two
709times, we can use @samp{s}; the next two times we use @code{n} to avoid
710falling into the @code{xstrdup} subroutine.
711
712@smallexample
713(@value{GDBP}) @b{s}
7140x3b5c 532 if (rquote != def_rquote)
715(@value{GDBP}) @b{s}
7160x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
717def_lquote : xstrdup(lq);
718(@value{GDBP}) @b{n}
719536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
720 : xstrdup(rq);
721(@value{GDBP}) @b{n}
722538 len_lquote = strlen(rquote);
723@end smallexample
724
725@noindent
726The last line displayed looks a little odd; we can examine the variables
727@code{lquote} and @code{rquote} to see if they are in fact the new left
728and right quotes we specified. We use the command @code{p}
729(@code{print}) to see their values.
730
731@smallexample
732(@value{GDBP}) @b{p lquote}
733$1 = 0x35d40 "<QUOTE>"
734(@value{GDBP}) @b{p rquote}
735$2 = 0x35d50 "<UNQUOTE>"
736@end smallexample
737
738@noindent
739@code{lquote} and @code{rquote} are indeed the new left and right quotes.
740To look at some context, we can display ten lines of source
741surrounding the current line with the @code{l} (@code{list}) command.
742
743@smallexample
744(@value{GDBP}) @b{l}
745533 xfree(rquote);
746534
747535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
748 : xstrdup (lq);
749536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
750 : xstrdup (rq);
751537
752538 len_lquote = strlen(rquote);
753539 len_rquote = strlen(lquote);
754540 @}
755541
756542 void
757@end smallexample
758
759@noindent
760Let us step past the two lines that set @code{len_lquote} and
761@code{len_rquote}, and then examine the values of those variables.
762
763@smallexample
764(@value{GDBP}) @b{n}
765539 len_rquote = strlen(lquote);
766(@value{GDBP}) @b{n}
767540 @}
768(@value{GDBP}) @b{p len_lquote}
769$3 = 9
770(@value{GDBP}) @b{p len_rquote}
771$4 = 7
772@end smallexample
773
774@noindent
775That certainly looks wrong, assuming @code{len_lquote} and
776@code{len_rquote} are meant to be the lengths of @code{lquote} and
777@code{rquote} respectively. We can set them to better values using
778the @code{p} command, since it can print the value of
779any expression---and that expression can include subroutine calls and
780assignments.
781
782@smallexample
783(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
784$5 = 7
785(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
786$6 = 9
787@end smallexample
788
789@noindent
790Is that enough to fix the problem of using the new quotes with the
791@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
792executing with the @code{c} (@code{continue}) command, and then try the
793example that caused trouble initially:
794
795@smallexample
796(@value{GDBP}) @b{c}
797Continuing.
798
799@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
800
801baz
8020000
803@end smallexample
804
805@noindent
806Success! The new quotes now work just as well as the default ones. The
807problem seems to have been just the two typos defining the wrong
808lengths. We allow @code{m4} exit by giving it an EOF as input:
809
810@smallexample
c8aa23ab 811@b{Ctrl-d}
c906108c
SS
812Program exited normally.
813@end smallexample
814
815@noindent
816The message @samp{Program exited normally.} is from @value{GDBN}; it
817indicates @code{m4} has finished executing. We can end our @value{GDBN}
818session with the @value{GDBN} @code{quit} command.
819
820@smallexample
821(@value{GDBP}) @b{quit}
822@end smallexample
c906108c 823
6d2ebf8b 824@node Invocation
c906108c
SS
825@chapter Getting In and Out of @value{GDBN}
826
827This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 828The essentials are:
c906108c 829@itemize @bullet
5d161b24 830@item
53a5351d 831type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 832@item
c8aa23ab 833type @kbd{quit} or @kbd{Ctrl-d} to exit.
c906108c
SS
834@end itemize
835
836@menu
837* Invoking GDB:: How to start @value{GDBN}
838* Quitting GDB:: How to quit @value{GDBN}
839* Shell Commands:: How to use shell commands inside @value{GDBN}
79a6e687 840* Logging Output:: How to log @value{GDBN}'s output to a file
c906108c
SS
841@end menu
842
6d2ebf8b 843@node Invoking GDB
c906108c
SS
844@section Invoking @value{GDBN}
845
c906108c
SS
846Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
847@value{GDBN} reads commands from the terminal until you tell it to exit.
848
849You can also run @code{@value{GDBP}} with a variety of arguments and options,
850to specify more of your debugging environment at the outset.
851
c906108c
SS
852The command-line options described here are designed
853to cover a variety of situations; in some environments, some of these
5d161b24 854options may effectively be unavailable.
c906108c
SS
855
856The most usual way to start @value{GDBN} is with one argument,
857specifying an executable program:
858
474c8240 859@smallexample
c906108c 860@value{GDBP} @var{program}
474c8240 861@end smallexample
c906108c 862
c906108c
SS
863@noindent
864You can also start with both an executable program and a core file
865specified:
866
474c8240 867@smallexample
c906108c 868@value{GDBP} @var{program} @var{core}
474c8240 869@end smallexample
c906108c
SS
870
871You can, instead, specify a process ID as a second argument, if you want
872to debug a running process:
873
474c8240 874@smallexample
c906108c 875@value{GDBP} @var{program} 1234
474c8240 876@end smallexample
c906108c
SS
877
878@noindent
879would attach @value{GDBN} to process @code{1234} (unless you also have a file
880named @file{1234}; @value{GDBN} does check for a core file first).
881
c906108c 882Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
883complete operating system; when you use @value{GDBN} as a remote
884debugger attached to a bare board, there may not be any notion of
885``process'', and there is often no way to get a core dump. @value{GDBN}
886will warn you if it is unable to attach or to read core dumps.
c906108c 887
aa26fa3a
TT
888You can optionally have @code{@value{GDBP}} pass any arguments after the
889executable file to the inferior using @code{--args}. This option stops
890option processing.
474c8240 891@smallexample
3f94c067 892@value{GDBP} --args gcc -O2 -c foo.c
474c8240 893@end smallexample
aa26fa3a
TT
894This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
895@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
896
96a2c332 897You can run @code{@value{GDBP}} without printing the front material, which describes
adcc0a31 898@value{GDBN}'s non-warranty, by specifying @code{--silent}
899(or @code{-q}/@code{--quiet}):
c906108c
SS
900
901@smallexample
adcc0a31 902@value{GDBP} --silent
c906108c
SS
903@end smallexample
904
905@noindent
906You can further control how @value{GDBN} starts up by using command-line
907options. @value{GDBN} itself can remind you of the options available.
908
909@noindent
910Type
911
474c8240 912@smallexample
c906108c 913@value{GDBP} -help
474c8240 914@end smallexample
c906108c
SS
915
916@noindent
917to display all available options and briefly describe their use
918(@samp{@value{GDBP} -h} is a shorter equivalent).
919
920All options and command line arguments you give are processed
921in sequential order. The order makes a difference when the
922@samp{-x} option is used.
923
924
925@menu
c906108c
SS
926* File Options:: Choosing files
927* Mode Options:: Choosing modes
6fc08d32 928* Startup:: What @value{GDBN} does during startup
c906108c
SS
929@end menu
930
6d2ebf8b 931@node File Options
79a6e687 932@subsection Choosing Files
c906108c 933
2df3850c 934When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
935specifying an executable file and core file (or process ID). This is
936the same as if the arguments were specified by the @samp{-se} and
d52fb0e9 937@samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
19837790
MS
938first argument that does not have an associated option flag as
939equivalent to the @samp{-se} option followed by that argument; and the
940second argument that does not have an associated option flag, if any, as
941equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
942If the second argument begins with a decimal digit, @value{GDBN} will
943first attempt to attach to it as a process, and if that fails, attempt
944to open it as a corefile. If you have a corefile whose name begins with
b383017d 945a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 946prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
947
948If @value{GDBN} has not been configured to included core file support,
949such as for most embedded targets, then it will complain about a second
950argument and ignore it.
c906108c
SS
951
952Many options have both long and short forms; both are shown in the
953following list. @value{GDBN} also recognizes the long forms if you truncate
954them, so long as enough of the option is present to be unambiguous.
955(If you prefer, you can flag option arguments with @samp{--} rather
956than @samp{-}, though we illustrate the more usual convention.)
957
d700128c
EZ
958@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
959@c way, both those who look for -foo and --foo in the index, will find
960@c it.
961
c906108c
SS
962@table @code
963@item -symbols @var{file}
964@itemx -s @var{file}
d700128c
EZ
965@cindex @code{--symbols}
966@cindex @code{-s}
c906108c
SS
967Read symbol table from file @var{file}.
968
969@item -exec @var{file}
970@itemx -e @var{file}
d700128c
EZ
971@cindex @code{--exec}
972@cindex @code{-e}
7a292a7a
SS
973Use file @var{file} as the executable file to execute when appropriate,
974and for examining pure data in conjunction with a core dump.
c906108c
SS
975
976@item -se @var{file}
d700128c 977@cindex @code{--se}
c906108c
SS
978Read symbol table from file @var{file} and use it as the executable
979file.
980
c906108c
SS
981@item -core @var{file}
982@itemx -c @var{file}
d700128c
EZ
983@cindex @code{--core}
984@cindex @code{-c}
b383017d 985Use file @var{file} as a core dump to examine.
c906108c 986
19837790
MS
987@item -pid @var{number}
988@itemx -p @var{number}
989@cindex @code{--pid}
990@cindex @code{-p}
991Connect to process ID @var{number}, as with the @code{attach} command.
c906108c
SS
992
993@item -command @var{file}
994@itemx -x @var{file}
d700128c
EZ
995@cindex @code{--command}
996@cindex @code{-x}
95433b34
JB
997Execute commands from file @var{file}. The contents of this file is
998evaluated exactly as the @code{source} command would.
8150ff9c 999@xref{Command Files,, Command files}.
c906108c 1000
8a5a3c82
AS
1001@item -eval-command @var{command}
1002@itemx -ex @var{command}
1003@cindex @code{--eval-command}
1004@cindex @code{-ex}
1005Execute a single @value{GDBN} command.
1006
1007This option may be used multiple times to call multiple commands. It may
1008also be interleaved with @samp{-command} as required.
1009
1010@smallexample
1011@value{GDBP} -ex 'target sim' -ex 'load' \
1012 -x setbreakpoints -ex 'run' a.out
1013@end smallexample
1014
8320cc4f
JK
1015@item -init-command @var{file}
1016@itemx -ix @var{file}
1017@cindex @code{--init-command}
1018@cindex @code{-ix}
2d7b58e8
JK
1019Execute commands from file @var{file} before loading the inferior (but
1020after loading gdbinit files).
8320cc4f
JK
1021@xref{Startup}.
1022
1023@item -init-eval-command @var{command}
1024@itemx -iex @var{command}
1025@cindex @code{--init-eval-command}
1026@cindex @code{-iex}
2d7b58e8
JK
1027Execute a single @value{GDBN} command before loading the inferior (but
1028after loading gdbinit files).
8320cc4f
JK
1029@xref{Startup}.
1030
c906108c
SS
1031@item -directory @var{directory}
1032@itemx -d @var{directory}
d700128c
EZ
1033@cindex @code{--directory}
1034@cindex @code{-d}
4b505b12 1035Add @var{directory} to the path to search for source and script files.
c906108c 1036
c906108c
SS
1037@item -r
1038@itemx -readnow
d700128c
EZ
1039@cindex @code{--readnow}
1040@cindex @code{-r}
c906108c
SS
1041Read each symbol file's entire symbol table immediately, rather than
1042the default, which is to read it incrementally as it is needed.
1043This makes startup slower, but makes future operations faster.
53a5351d 1044
97cbe998
SDJ
1045@item --readnever
1046@anchor{--readnever}
1047@cindex @code{--readnever}, command-line option
1048Do not read each symbol file's symbolic debug information. This makes
1049startup faster but at the expense of not being able to perform
1050symbolic debugging. DWARF unwind information is also not read,
1051meaning backtraces may become incomplete or inaccurate. One use of
1052this is when a user simply wants to do the following sequence: attach,
1053dump core, detach. Loading the debugging information in this case is
1054an unnecessary cause of delay.
c906108c
SS
1055@end table
1056
6d2ebf8b 1057@node Mode Options
79a6e687 1058@subsection Choosing Modes
c906108c
SS
1059
1060You can run @value{GDBN} in various alternative modes---for example, in
1061batch mode or quiet mode.
1062
1063@table @code
bf88dd68 1064@anchor{-nx}
c906108c
SS
1065@item -nx
1066@itemx -n
d700128c
EZ
1067@cindex @code{--nx}
1068@cindex @code{-n}
07540c15
DE
1069Do not execute commands found in any initialization file.
1070There are three init files, loaded in the following order:
1071
1072@table @code
1073@item @file{system.gdbinit}
1074This is the system-wide init file.
1075Its location is specified with the @code{--with-system-gdbinit}
1076configure option (@pxref{System-wide configuration}).
1077It is loaded first when @value{GDBN} starts, before command line options
1078have been processed.
1079@item @file{~/.gdbinit}
1080This is the init file in your home directory.
1081It is loaded next, after @file{system.gdbinit}, and before
1082command options have been processed.
1083@item @file{./.gdbinit}
1084This is the init file in the current directory.
1085It is loaded last, after command line options other than @code{-x} and
1086@code{-ex} have been processed. Command line options @code{-x} and
1087@code{-ex} are processed last, after @file{./.gdbinit} has been loaded.
1088@end table
1089
1090For further documentation on startup processing, @xref{Startup}.
1091For documentation on how to write command files,
1092@xref{Command Files,,Command Files}.
1093
1094@anchor{-nh}
1095@item -nh
1096@cindex @code{--nh}
1097Do not execute commands found in @file{~/.gdbinit}, the init file
1098in your home directory.
1099@xref{Startup}.
c906108c
SS
1100
1101@item -quiet
d700128c 1102@itemx -silent
c906108c 1103@itemx -q
d700128c
EZ
1104@cindex @code{--quiet}
1105@cindex @code{--silent}
1106@cindex @code{-q}
c906108c
SS
1107``Quiet''. Do not print the introductory and copyright messages. These
1108messages are also suppressed in batch mode.
1109
1110@item -batch
d700128c 1111@cindex @code{--batch}
c906108c
SS
1112Run in batch mode. Exit with status @code{0} after processing all the
1113command files specified with @samp{-x} (and all commands from
1114initialization files, if not inhibited with @samp{-n}). Exit with
1115nonzero status if an error occurs in executing the @value{GDBN} commands
5da1313b
JK
1116in the command files. Batch mode also disables pagination, sets unlimited
1117terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1118off} were in effect (@pxref{Messages/Warnings}).
c906108c 1119
2df3850c
JM
1120Batch mode may be useful for running @value{GDBN} as a filter, for
1121example to download and run a program on another computer; in order to
1122make this more useful, the message
c906108c 1123
474c8240 1124@smallexample
c906108c 1125Program exited normally.
474c8240 1126@end smallexample
c906108c
SS
1127
1128@noindent
2df3850c
JM
1129(which is ordinarily issued whenever a program running under
1130@value{GDBN} control terminates) is not issued when running in batch
1131mode.
1132
1a088d06
AS
1133@item -batch-silent
1134@cindex @code{--batch-silent}
1135Run in batch mode exactly like @samp{-batch}, but totally silently. All
1136@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1137unaffected). This is much quieter than @samp{-silent} and would be useless
1138for an interactive session.
1139
1140This is particularly useful when using targets that give @samp{Loading section}
1141messages, for example.
1142
1143Note that targets that give their output via @value{GDBN}, as opposed to
1144writing directly to @code{stdout}, will also be made silent.
1145
4b0ad762
AS
1146@item -return-child-result
1147@cindex @code{--return-child-result}
1148The return code from @value{GDBN} will be the return code from the child
1149process (the process being debugged), with the following exceptions:
1150
1151@itemize @bullet
1152@item
1153@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1154internal error. In this case the exit code is the same as it would have been
1155without @samp{-return-child-result}.
1156@item
1157The user quits with an explicit value. E.g., @samp{quit 1}.
1158@item
1159The child process never runs, or is not allowed to terminate, in which case
1160the exit code will be -1.
1161@end itemize
1162
1163This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1164when @value{GDBN} is being used as a remote program loader or simulator
1165interface.
1166
2df3850c
JM
1167@item -nowindows
1168@itemx -nw
d700128c
EZ
1169@cindex @code{--nowindows}
1170@cindex @code{-nw}
2df3850c 1171``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1172(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1173interface. If no GUI is available, this option has no effect.
1174
1175@item -windows
1176@itemx -w
d700128c
EZ
1177@cindex @code{--windows}
1178@cindex @code{-w}
2df3850c
JM
1179If @value{GDBN} includes a GUI, then this option requires it to be
1180used if possible.
c906108c
SS
1181
1182@item -cd @var{directory}
d700128c 1183@cindex @code{--cd}
c906108c
SS
1184Run @value{GDBN} using @var{directory} as its working directory,
1185instead of the current directory.
1186
aae1c79a 1187@item -data-directory @var{directory}
8d551b02 1188@itemx -D @var{directory}
aae1c79a 1189@cindex @code{--data-directory}
8d551b02 1190@cindex @code{-D}
aae1c79a
DE
1191Run @value{GDBN} using @var{directory} as its data directory.
1192The data directory is where @value{GDBN} searches for its
1193auxiliary files. @xref{Data Files}.
1194
c906108c
SS
1195@item -fullname
1196@itemx -f
d700128c
EZ
1197@cindex @code{--fullname}
1198@cindex @code{-f}
7a292a7a
SS
1199@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1200subprocess. It tells @value{GDBN} to output the full file name and line
1201number in a standard, recognizable fashion each time a stack frame is
1202displayed (which includes each time your program stops). This
1203recognizable format looks like two @samp{\032} characters, followed by
1204the file name, line number and character position separated by colons,
1205and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1206@samp{\032} characters as a signal to display the source code for the
1207frame.
c906108c 1208
d700128c
EZ
1209@item -annotate @var{level}
1210@cindex @code{--annotate}
1211This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1212effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1213(@pxref{Annotations}). The annotation @var{level} controls how much
1214information @value{GDBN} prints together with its prompt, values of
1215expressions, source lines, and other types of output. Level 0 is the
1216normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1217@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1218that control @value{GDBN}, and level 2 has been deprecated.
1219
265eeb58 1220The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1221(@pxref{GDB/MI}).
d700128c 1222
aa26fa3a
TT
1223@item --args
1224@cindex @code{--args}
1225Change interpretation of command line so that arguments following the
1226executable file are passed as command line arguments to the inferior.
1227This option stops option processing.
1228
2df3850c
JM
1229@item -baud @var{bps}
1230@itemx -b @var{bps}
d700128c
EZ
1231@cindex @code{--baud}
1232@cindex @code{-b}
c906108c
SS
1233Set the line speed (baud rate or bits per second) of any serial
1234interface used by @value{GDBN} for remote debugging.
c906108c 1235
f47b1503
AS
1236@item -l @var{timeout}
1237@cindex @code{-l}
1238Set the timeout (in seconds) of any communication used by @value{GDBN}
1239for remote debugging.
1240
c906108c 1241@item -tty @var{device}
d700128c
EZ
1242@itemx -t @var{device}
1243@cindex @code{--tty}
1244@cindex @code{-t}
c906108c
SS
1245Run using @var{device} for your program's standard input and output.
1246@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1247
53a5351d 1248@c resolve the situation of these eventually
c4555f82
SC
1249@item -tui
1250@cindex @code{--tui}
d0d5df6f
AC
1251Activate the @dfn{Text User Interface} when starting. The Text User
1252Interface manages several text windows on the terminal, showing
1253source, assembly, registers and @value{GDBN} command outputs
217bff3e
JK
1254(@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1255option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1256Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d 1257
d700128c
EZ
1258@item -interpreter @var{interp}
1259@cindex @code{--interpreter}
1260Use the interpreter @var{interp} for interface with the controlling
1261program or device. This option is meant to be set by programs which
94bbb2c0 1262communicate with @value{GDBN} using it as a back end.
21c294e6 1263@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1264
da0f9dcd 1265@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1266@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1267The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1268previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1269selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1270@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1271
1272@item -write
1273@cindex @code{--write}
1274Open the executable and core files for both reading and writing. This
1275is equivalent to the @samp{set write on} command inside @value{GDBN}
1276(@pxref{Patching}).
1277
1278@item -statistics
1279@cindex @code{--statistics}
1280This option causes @value{GDBN} to print statistics about time and
1281memory usage after it completes each command and returns to the prompt.
1282
1283@item -version
1284@cindex @code{--version}
1285This option causes @value{GDBN} to print its version number and
1286no-warranty blurb, and exit.
1287
6eaaf48b
EZ
1288@item -configuration
1289@cindex @code{--configuration}
1290This option causes @value{GDBN} to print details about its build-time
1291configuration parameters, and then exit. These details can be
1292important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1293
c906108c
SS
1294@end table
1295
6fc08d32 1296@node Startup
79a6e687 1297@subsection What @value{GDBN} Does During Startup
6fc08d32
EZ
1298@cindex @value{GDBN} startup
1299
1300Here's the description of what @value{GDBN} does during session startup:
1301
1302@enumerate
1303@item
1304Sets up the command interpreter as specified by the command line
1305(@pxref{Mode Options, interpreter}).
1306
1307@item
1308@cindex init file
098b41a6
JG
1309Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1310used when building @value{GDBN}; @pxref{System-wide configuration,
1311 ,System-wide configuration and settings}) and executes all the commands in
1312that file.
1313
bf88dd68 1314@anchor{Home Directory Init File}
098b41a6
JG
1315@item
1316Reads the init file (if any) in your home directory@footnote{On
6fc08d32
EZ
1317DOS/Windows systems, the home directory is the one pointed to by the
1318@code{HOME} environment variable.} and executes all the commands in
1319that file.
1320
2d7b58e8
JK
1321@anchor{Option -init-eval-command}
1322@item
1323Executes commands and command files specified by the @samp{-iex} and
1324@samp{-ix} options in their specified order. Usually you should use the
1325@samp{-ex} and @samp{-x} options instead, but this way you can apply
1326settings before @value{GDBN} init files get executed and before inferior
1327gets loaded.
1328
6fc08d32
EZ
1329@item
1330Processes command line options and operands.
1331
bf88dd68 1332@anchor{Init File in the Current Directory during Startup}
6fc08d32
EZ
1333@item
1334Reads and executes the commands from init file (if any) in the current
bf88dd68
JK
1335working directory as long as @samp{set auto-load local-gdbinit} is set to
1336@samp{on} (@pxref{Init File in the Current Directory}).
1337This is only done if the current directory is
119b882a
EZ
1338different from your home directory. Thus, you can have more than one
1339init file, one generic in your home directory, and another, specific
1340to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1341@value{GDBN}.
1342
a86caf66
DE
1343@item
1344If the command line specified a program to debug, or a process to
1345attach to, or a core file, @value{GDBN} loads any auto-loaded
1346scripts provided for the program or for its loaded shared libraries.
1347@xref{Auto-loading}.
1348
1349If you wish to disable the auto-loading during startup,
1350you must do something like the following:
1351
1352@smallexample
bf88dd68 1353$ gdb -iex "set auto-load python-scripts off" myprogram
a86caf66
DE
1354@end smallexample
1355
8320cc4f
JK
1356Option @samp{-ex} does not work because the auto-loading is then turned
1357off too late.
a86caf66 1358
6fc08d32 1359@item
6fe37d23
JK
1360Executes commands and command files specified by the @samp{-ex} and
1361@samp{-x} options in their specified order. @xref{Command Files}, for
1362more details about @value{GDBN} command files.
6fc08d32
EZ
1363
1364@item
1365Reads the command history recorded in the @dfn{history file}.
d620b259 1366@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1367files where @value{GDBN} records it.
1368@end enumerate
1369
1370Init files use the same syntax as @dfn{command files} (@pxref{Command
1371Files}) and are processed by @value{GDBN} in the same way. The init
1372file in your home directory can set options (such as @samp{set
1373complaints}) that affect subsequent processing of command line options
1374and operands. Init files are not executed if you use the @samp{-nx}
79a6e687 1375option (@pxref{Mode Options, ,Choosing Modes}).
6fc08d32 1376
098b41a6
JG
1377To display the list of init files loaded by gdb at startup, you
1378can use @kbd{gdb --help}.
1379
6fc08d32
EZ
1380@cindex init file name
1381@cindex @file{.gdbinit}
119b882a 1382@cindex @file{gdb.ini}
8807d78b 1383The @value{GDBN} init files are normally called @file{.gdbinit}.
119b882a
EZ
1384The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1385the limitations of file names imposed by DOS filesystems. The Windows
4d3f93a2
JB
1386port of @value{GDBN} uses the standard name, but if it finds a
1387@file{gdb.ini} file in your home directory, it warns you about that
1388and suggests to rename the file to the standard name.
119b882a 1389
6fc08d32 1390
6d2ebf8b 1391@node Quitting GDB
c906108c
SS
1392@section Quitting @value{GDBN}
1393@cindex exiting @value{GDBN}
1394@cindex leaving @value{GDBN}
1395
1396@table @code
1397@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1398@kindex q @r{(@code{quit})}
96a2c332
SS
1399@item quit @r{[}@var{expression}@r{]}
1400@itemx q
1401To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1402@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1403do not supply @var{expression}, @value{GDBN} will terminate normally;
1404otherwise it will terminate using the result of @var{expression} as the
1405error code.
c906108c
SS
1406@end table
1407
1408@cindex interrupt
c8aa23ab 1409An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1410terminates the action of any @value{GDBN} command that is in progress and
1411returns to @value{GDBN} command level. It is safe to type the interrupt
1412character at any time because @value{GDBN} does not allow it to take effect
1413until a time when it is safe.
1414
c906108c
SS
1415If you have been using @value{GDBN} to control an attached process or
1416device, you can release it with the @code{detach} command
79a6e687 1417(@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 1418
6d2ebf8b 1419@node Shell Commands
79a6e687 1420@section Shell Commands
c906108c
SS
1421
1422If you need to execute occasional shell commands during your
1423debugging session, there is no need to leave or suspend @value{GDBN}; you can
1424just use the @code{shell} command.
1425
1426@table @code
1427@kindex shell
ed59ded5 1428@kindex !
c906108c 1429@cindex shell escape
ed59ded5
DE
1430@item shell @var{command-string}
1431@itemx !@var{command-string}
1432Invoke a standard shell to execute @var{command-string}.
1433Note that no space is needed between @code{!} and @var{command-string}.
c906108c 1434If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1435shell to run. Otherwise @value{GDBN} uses the default shell
1436(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1437@end table
1438
1439The utility @code{make} is often needed in development environments.
1440You do not have to use the @code{shell} command for this purpose in
1441@value{GDBN}:
1442
1443@table @code
1444@kindex make
1445@cindex calling make
1446@item make @var{make-args}
1447Execute the @code{make} program with the specified
1448arguments. This is equivalent to @samp{shell make @var{make-args}}.
1449@end table
1450
79a6e687
BW
1451@node Logging Output
1452@section Logging Output
0fac0b41 1453@cindex logging @value{GDBN} output
9c16f35a 1454@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1455
1456You may want to save the output of @value{GDBN} commands to a file.
1457There are several commands to control @value{GDBN}'s logging.
1458
1459@table @code
1460@kindex set logging
1461@item set logging on
1462Enable logging.
1463@item set logging off
1464Disable logging.
9c16f35a 1465@cindex logging file name
0fac0b41
DJ
1466@item set logging file @var{file}
1467Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1468@item set logging overwrite [on|off]
1469By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1470you want @code{set logging on} to overwrite the logfile instead.
1471@item set logging redirect [on|off]
1472By default, @value{GDBN} output will go to both the terminal and the logfile.
1473Set @code{redirect} if you want output to go only to the log file.
1474@kindex show logging
1475@item show logging
1476Show the current values of the logging settings.
1477@end table
1478
6d2ebf8b 1479@node Commands
c906108c
SS
1480@chapter @value{GDBN} Commands
1481
1482You can abbreviate a @value{GDBN} command to the first few letters of the command
1483name, if that abbreviation is unambiguous; and you can repeat certain
1484@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1485key to get @value{GDBN} to fill out the rest of a word in a command (or to
1486show you the alternatives available, if there is more than one possibility).
1487
1488@menu
1489* Command Syntax:: How to give commands to @value{GDBN}
1490* Completion:: Command completion
1491* Help:: How to ask @value{GDBN} for help
1492@end menu
1493
6d2ebf8b 1494@node Command Syntax
79a6e687 1495@section Command Syntax
c906108c
SS
1496
1497A @value{GDBN} command is a single line of input. There is no limit on
1498how long it can be. It starts with a command name, which is followed by
1499arguments whose meaning depends on the command name. For example, the
1500command @code{step} accepts an argument which is the number of times to
1501step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1502with no arguments. Some commands do not allow any arguments.
c906108c
SS
1503
1504@cindex abbreviation
1505@value{GDBN} command names may always be truncated if that abbreviation is
1506unambiguous. Other possible command abbreviations are listed in the
1507documentation for individual commands. In some cases, even ambiguous
1508abbreviations are allowed; for example, @code{s} is specially defined as
1509equivalent to @code{step} even though there are other commands whose
1510names start with @code{s}. You can test abbreviations by using them as
1511arguments to the @code{help} command.
1512
1513@cindex repeating commands
41afff9a 1514@kindex RET @r{(repeat last command)}
c906108c 1515A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1516repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1517will not repeat this way; these are commands whose unintentional
1518repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1519repeat. User-defined commands can disable this feature; see
1520@ref{Define, dont-repeat}.
c906108c
SS
1521
1522The @code{list} and @code{x} commands, when you repeat them with
1523@key{RET}, construct new arguments rather than repeating
1524exactly as typed. This permits easy scanning of source or memory.
1525
1526@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1527output, in a way similar to the common utility @code{more}
79a6e687 1528(@pxref{Screen Size,,Screen Size}). Since it is easy to press one
c906108c
SS
1529@key{RET} too many in this situation, @value{GDBN} disables command
1530repetition after any command that generates this sort of display.
1531
41afff9a 1532@kindex # @r{(a comment)}
c906108c
SS
1533@cindex comment
1534Any text from a @kbd{#} to the end of the line is a comment; it does
1535nothing. This is useful mainly in command files (@pxref{Command
79a6e687 1536Files,,Command Files}).
c906108c 1537
88118b3a 1538@cindex repeating command sequences
c8aa23ab
EZ
1539@kindex Ctrl-o @r{(operate-and-get-next)}
1540The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1541commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1542then fetches the next line relative to the current line from the history
1543for editing.
1544
6d2ebf8b 1545@node Completion
79a6e687 1546@section Command Completion
c906108c
SS
1547
1548@cindex completion
1549@cindex word completion
1550@value{GDBN} can fill in the rest of a word in a command for you, if there is
1551only one possibility; it can also show you what the valid possibilities
1552are for the next word in a command, at any time. This works for @value{GDBN}
1553commands, @value{GDBN} subcommands, and the names of symbols in your program.
1554
1555Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1556of a word. If there is only one possibility, @value{GDBN} fills in the
1557word, and waits for you to finish the command (or press @key{RET} to
1558enter it). For example, if you type
1559
1560@c FIXME "@key" does not distinguish its argument sufficiently to permit
1561@c complete accuracy in these examples; space introduced for clarity.
1562@c If texinfo enhancements make it unnecessary, it would be nice to
1563@c replace " @key" by "@key" in the following...
474c8240 1564@smallexample
c906108c 1565(@value{GDBP}) info bre @key{TAB}
474c8240 1566@end smallexample
c906108c
SS
1567
1568@noindent
1569@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1570the only @code{info} subcommand beginning with @samp{bre}:
1571
474c8240 1572@smallexample
c906108c 1573(@value{GDBP}) info breakpoints
474c8240 1574@end smallexample
c906108c
SS
1575
1576@noindent
1577You can either press @key{RET} at this point, to run the @code{info
1578breakpoints} command, or backspace and enter something else, if
1579@samp{breakpoints} does not look like the command you expected. (If you
1580were sure you wanted @code{info breakpoints} in the first place, you
1581might as well just type @key{RET} immediately after @samp{info bre},
1582to exploit command abbreviations rather than command completion).
1583
1584If there is more than one possibility for the next word when you press
1585@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1586characters and try again, or just press @key{TAB} a second time;
1587@value{GDBN} displays all the possible completions for that word. For
1588example, you might want to set a breakpoint on a subroutine whose name
1589begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1590just sounds the bell. Typing @key{TAB} again displays all the
1591function names in your program that begin with those characters, for
1592example:
1593
474c8240 1594@smallexample
c906108c
SS
1595(@value{GDBP}) b make_ @key{TAB}
1596@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1597make_a_section_from_file make_environ
1598make_abs_section make_function_type
1599make_blockvector make_pointer_type
1600make_cleanup make_reference_type
c906108c
SS
1601make_command make_symbol_completion_list
1602(@value{GDBP}) b make_
474c8240 1603@end smallexample
c906108c
SS
1604
1605@noindent
1606After displaying the available possibilities, @value{GDBN} copies your
1607partial input (@samp{b make_} in the example) so you can finish the
1608command.
1609
1610If you just want to see the list of alternatives in the first place, you
b37052ae 1611can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1612means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1613key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1614one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c 1615
ef0b411a
GB
1616If the number of possible completions is large, @value{GDBN} will
1617print as much of the list as it has collected, as well as a message
1618indicating that the list may be truncated.
1619
1620@smallexample
1621(@value{GDBP}) b m@key{TAB}@key{TAB}
1622main
1623<... the rest of the possible completions ...>
1624*** List may be truncated, max-completions reached. ***
1625(@value{GDBP}) b m
1626@end smallexample
1627
1628@noindent
1629This behavior can be controlled with the following commands:
1630
1631@table @code
1632@kindex set max-completions
1633@item set max-completions @var{limit}
1634@itemx set max-completions unlimited
1635Set the maximum number of completion candidates. @value{GDBN} will
1636stop looking for more completions once it collects this many candidates.
1637This is useful when completing on things like function names as collecting
1638all the possible candidates can be time consuming.
1639The default value is 200. A value of zero disables tab-completion.
1640Note that setting either no limit or a very large limit can make
1641completion slow.
1642@kindex show max-completions
1643@item show max-completions
1644Show the maximum number of candidates that @value{GDBN} will collect and show
1645during completion.
1646@end table
1647
c906108c
SS
1648@cindex quotes in commands
1649@cindex completion of quoted strings
1650Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1651parentheses or other characters that @value{GDBN} normally excludes from
1652its notion of a word. To permit word completion to work in this
1653situation, you may enclose words in @code{'} (single quote marks) in
1654@value{GDBN} commands.
c906108c 1655
d044bac8
PA
1656A likely situation where you might need this is in typing an
1657expression that involves a C@t{++} symbol name with template
1658parameters. This is because when completing expressions, GDB treats
1659the @samp{<} character as word delimiter, assuming that it's the
1660less-than comparison operator (@pxref{C Operators, , C and C@t{++}
1661Operators}).
1662
1663For example, when you want to call a C@t{++} template function
1664interactively using the @code{print} or @code{call} commands, you may
1665need to distinguish whether you mean the version of @code{name} that
1666was specialized for @code{int}, @code{name<int>()}, or the version
1667that was specialized for @code{float}, @code{name<float>()}. To use
1668the word-completion facilities in this situation, type a single quote
b37052ae
EZ
1669@code{'} at the beginning of the function name. This alerts
1670@value{GDBN} that it may need to consider more information than usual
1671when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1672
474c8240 1673@smallexample
d044bac8
PA
1674(@value{GDBP}) p 'func< @kbd{M-?}
1675func<int>() func<float>()
1676(@value{GDBP}) p 'func<
474c8240 1677@end smallexample
c906108c 1678
d044bac8
PA
1679When setting breakpoints however (@pxref{Specify Location}), you don't
1680usually need to type a quote before the function name, because
1681@value{GDBN} understands that you want to set a breakpoint on a
1682function:
c906108c 1683
474c8240 1684@smallexample
d044bac8
PA
1685(@value{GDBP}) b func< @kbd{M-?}
1686func<int>() func<float>()
1687(@value{GDBP}) b func<
474c8240 1688@end smallexample
c906108c 1689
d044bac8
PA
1690This is true even in the case of typing the name of C@t{++} overloaded
1691functions (multiple definitions of the same function, distinguished by
1692argument type). For example, when you want to set a breakpoint you
1693don't need to distinguish whether you mean the version of @code{name}
1694that takes an @code{int} parameter, @code{name(int)}, or the version
1695that takes a @code{float} parameter, @code{name(float)}.
1696
1697@smallexample
1698(@value{GDBP}) b bubble( @kbd{M-?}
1699bubble(int) bubble(double)
1700(@value{GDBP}) b bubble(dou @kbd{M-?}
1701bubble(double)
1702@end smallexample
1703
1704See @ref{quoting names} for a description of other scenarios that
1705require quoting.
c906108c 1706
79a6e687
BW
1707For more information about overloaded functions, see @ref{C Plus Plus
1708Expressions, ,C@t{++} Expressions}. You can use the command @code{set
c906108c 1709overload-resolution off} to disable overload resolution;
79a6e687 1710see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
c906108c 1711
65d12d83
TT
1712@cindex completion of structure field names
1713@cindex structure field name completion
1714@cindex completion of union field names
1715@cindex union field name completion
1716When completing in an expression which looks up a field in a
1717structure, @value{GDBN} also tries@footnote{The completer can be
1718confused by certain kinds of invalid expressions. Also, it only
1719examines the static type of the expression, not the dynamic type.} to
1720limit completions to the field names available in the type of the
1721left-hand-side:
1722
1723@smallexample
1724(@value{GDBP}) p gdb_stdout.@kbd{M-?}
01124a23
DE
1725magic to_fputs to_rewind
1726to_data to_isatty to_write
1727to_delete to_put to_write_async_safe
1728to_flush to_read
65d12d83
TT
1729@end smallexample
1730
1731@noindent
1732This is because the @code{gdb_stdout} is a variable of the type
1733@code{struct ui_file} that is defined in @value{GDBN} sources as
1734follows:
1735
1736@smallexample
1737struct ui_file
1738@{
1739 int *magic;
1740 ui_file_flush_ftype *to_flush;
1741 ui_file_write_ftype *to_write;
01124a23 1742 ui_file_write_async_safe_ftype *to_write_async_safe;
65d12d83
TT
1743 ui_file_fputs_ftype *to_fputs;
1744 ui_file_read_ftype *to_read;
1745 ui_file_delete_ftype *to_delete;
1746 ui_file_isatty_ftype *to_isatty;
1747 ui_file_rewind_ftype *to_rewind;
1748 ui_file_put_ftype *to_put;
1749 void *to_data;
1750@}
1751@end smallexample
1752
c906108c 1753
6d2ebf8b 1754@node Help
79a6e687 1755@section Getting Help
c906108c
SS
1756@cindex online documentation
1757@kindex help
1758
5d161b24 1759You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1760using the command @code{help}.
1761
1762@table @code
41afff9a 1763@kindex h @r{(@code{help})}
c906108c
SS
1764@item help
1765@itemx h
1766You can use @code{help} (abbreviated @code{h}) with no arguments to
1767display a short list of named classes of commands:
1768
1769@smallexample
1770(@value{GDBP}) help
1771List of classes of commands:
1772
2df3850c 1773aliases -- Aliases of other commands
c906108c 1774breakpoints -- Making program stop at certain points
2df3850c 1775data -- Examining data
c906108c 1776files -- Specifying and examining files
2df3850c
JM
1777internals -- Maintenance commands
1778obscure -- Obscure features
1779running -- Running the program
1780stack -- Examining the stack
c906108c
SS
1781status -- Status inquiries
1782support -- Support facilities
12c27660 1783tracepoints -- Tracing of program execution without
96a2c332 1784 stopping the program
c906108c 1785user-defined -- User-defined commands
c906108c 1786
5d161b24 1787Type "help" followed by a class name for a list of
c906108c 1788commands in that class.
5d161b24 1789Type "help" followed by command name for full
c906108c
SS
1790documentation.
1791Command name abbreviations are allowed if unambiguous.
1792(@value{GDBP})
1793@end smallexample
96a2c332 1794@c the above line break eliminates huge line overfull...
c906108c
SS
1795
1796@item help @var{class}
1797Using one of the general help classes as an argument, you can get a
1798list of the individual commands in that class. For example, here is the
1799help display for the class @code{status}:
1800
1801@smallexample
1802(@value{GDBP}) help status
1803Status inquiries.
1804
1805List of commands:
1806
1807@c Line break in "show" line falsifies real output, but needed
1808@c to fit in smallbook page size.
2df3850c 1809info -- Generic command for showing things
12c27660 1810 about the program being debugged
2df3850c 1811show -- Generic command for showing things
12c27660 1812 about the debugger
c906108c 1813
5d161b24 1814Type "help" followed by command name for full
c906108c
SS
1815documentation.
1816Command name abbreviations are allowed if unambiguous.
1817(@value{GDBP})
1818@end smallexample
1819
1820@item help @var{command}
1821With a command name as @code{help} argument, @value{GDBN} displays a
1822short paragraph on how to use that command.
1823
6837a0a2
DB
1824@kindex apropos
1825@item apropos @var{args}
09d4efe1 1826The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2 1827commands, and their documentation, for the regular expression specified in
99e008fe 1828@var{args}. It prints out all matches found. For example:
6837a0a2
DB
1829
1830@smallexample
16899756 1831apropos alias
6837a0a2
DB
1832@end smallexample
1833
b37052ae
EZ
1834@noindent
1835results in:
6837a0a2
DB
1836
1837@smallexample
6d2ebf8b 1838@c @group
16899756
DE
1839alias -- Define a new command that is an alias of an existing command
1840aliases -- Aliases of other commands
1841d -- Delete some breakpoints or auto-display expressions
1842del -- Delete some breakpoints or auto-display expressions
1843delete -- Delete some breakpoints or auto-display expressions
6d2ebf8b 1844@c @end group
6837a0a2
DB
1845@end smallexample
1846
c906108c
SS
1847@kindex complete
1848@item complete @var{args}
1849The @code{complete @var{args}} command lists all the possible completions
1850for the beginning of a command. Use @var{args} to specify the beginning of the
1851command you want completed. For example:
1852
1853@smallexample
1854complete i
1855@end smallexample
1856
1857@noindent results in:
1858
1859@smallexample
1860@group
2df3850c
JM
1861if
1862ignore
c906108c
SS
1863info
1864inspect
c906108c
SS
1865@end group
1866@end smallexample
1867
1868@noindent This is intended for use by @sc{gnu} Emacs.
1869@end table
1870
1871In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1872and @code{show} to inquire about the state of your program, or the state
1873of @value{GDBN} itself. Each command supports many topics of inquiry; this
1874manual introduces each of them in the appropriate context. The listings
00595b5e
EZ
1875under @code{info} and under @code{show} in the Command, Variable, and
1876Function Index point to all the sub-commands. @xref{Command and Variable
1877Index}.
c906108c
SS
1878
1879@c @group
1880@table @code
1881@kindex info
41afff9a 1882@kindex i @r{(@code{info})}
c906108c
SS
1883@item info
1884This command (abbreviated @code{i}) is for describing the state of your
cda4ce5a 1885program. For example, you can show the arguments passed to a function
c906108c
SS
1886with @code{info args}, list the registers currently in use with @code{info
1887registers}, or list the breakpoints you have set with @code{info breakpoints}.
1888You can get a complete list of the @code{info} sub-commands with
1889@w{@code{help info}}.
1890
1891@kindex set
1892@item set
5d161b24 1893You can assign the result of an expression to an environment variable with
c906108c
SS
1894@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1895@code{set prompt $}.
1896
1897@kindex show
1898@item show
5d161b24 1899In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1900@value{GDBN} itself.
1901You can change most of the things you can @code{show}, by using the
1902related command @code{set}; for example, you can control what number
1903system is used for displays with @code{set radix}, or simply inquire
1904which is currently in use with @code{show radix}.
1905
1906@kindex info set
1907To display all the settable parameters and their current
1908values, you can use @code{show} with no arguments; you may also use
1909@code{info set}. Both commands produce the same display.
1910@c FIXME: "info set" violates the rule that "info" is for state of
1911@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1912@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1913@end table
1914@c @end group
1915
6eaaf48b 1916Here are several miscellaneous @code{show} subcommands, all of which are
c906108c
SS
1917exceptional in lacking corresponding @code{set} commands:
1918
1919@table @code
1920@kindex show version
9c16f35a 1921@cindex @value{GDBN} version number
c906108c
SS
1922@item show version
1923Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1924information in @value{GDBN} bug-reports. If multiple versions of
1925@value{GDBN} are in use at your site, you may need to determine which
1926version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1927commands are introduced, and old ones may wither away. Also, many
1928system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1929variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1930The version number is the same as the one announced when you start
1931@value{GDBN}.
c906108c
SS
1932
1933@kindex show copying
09d4efe1 1934@kindex info copying
9c16f35a 1935@cindex display @value{GDBN} copyright
c906108c 1936@item show copying
09d4efe1 1937@itemx info copying
c906108c
SS
1938Display information about permission for copying @value{GDBN}.
1939
1940@kindex show warranty
09d4efe1 1941@kindex info warranty
c906108c 1942@item show warranty
09d4efe1 1943@itemx info warranty
2df3850c 1944Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1945if your version of @value{GDBN} comes with one.
2df3850c 1946
6eaaf48b
EZ
1947@kindex show configuration
1948@item show configuration
1949Display detailed information about the way @value{GDBN} was configured
1950when it was built. This displays the optional arguments passed to the
1951@file{configure} script and also configuration parameters detected
1952automatically by @command{configure}. When reporting a @value{GDBN}
1953bug (@pxref{GDB Bugs}), it is important to include this information in
1954your report.
1955
c906108c
SS
1956@end table
1957
6d2ebf8b 1958@node Running
c906108c
SS
1959@chapter Running Programs Under @value{GDBN}
1960
1961When you run a program under @value{GDBN}, you must first generate
1962debugging information when you compile it.
7a292a7a
SS
1963
1964You may start @value{GDBN} with its arguments, if any, in an environment
1965of your choice. If you are doing native debugging, you may redirect
1966your program's input and output, debug an already running process, or
1967kill a child process.
c906108c
SS
1968
1969@menu
1970* Compilation:: Compiling for debugging
1971* Starting:: Starting your program
c906108c
SS
1972* Arguments:: Your program's arguments
1973* Environment:: Your program's environment
c906108c
SS
1974
1975* Working Directory:: Your program's working directory
1976* Input/Output:: Your program's input and output
1977* Attach:: Debugging an already-running process
1978* Kill Process:: Killing the child process
c906108c 1979
6c95b8df 1980* Inferiors and Programs:: Debugging multiple inferiors and programs
c906108c 1981* Threads:: Debugging programs with multiple threads
6c95b8df 1982* Forks:: Debugging forks
5c95884b 1983* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
1984@end menu
1985
6d2ebf8b 1986@node Compilation
79a6e687 1987@section Compiling for Debugging
c906108c
SS
1988
1989In order to debug a program effectively, you need to generate
1990debugging information when you compile it. This debugging information
1991is stored in the object file; it describes the data type of each
1992variable or function and the correspondence between source line numbers
1993and addresses in the executable code.
1994
1995To request debugging information, specify the @samp{-g} option when you run
1996the compiler.
1997
514c4d71 1998Programs that are to be shipped to your customers are compiled with
edb3359d 1999optimizations, using the @samp{-O} compiler option. However, some
514c4d71
EZ
2000compilers are unable to handle the @samp{-g} and @samp{-O} options
2001together. Using those compilers, you cannot generate optimized
c906108c
SS
2002executables containing debugging information.
2003
514c4d71 2004@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
2005without @samp{-O}, making it possible to debug optimized code. We
2006recommend that you @emph{always} use @samp{-g} whenever you compile a
2007program. You may think your program is correct, but there is no sense
edb3359d 2008in pushing your luck. For more information, see @ref{Optimized Code}.
c906108c
SS
2009
2010Older versions of the @sc{gnu} C compiler permitted a variant option
2011@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2012format; if your @sc{gnu} C compiler has this option, do not use it.
2013
514c4d71
EZ
2014@value{GDBN} knows about preprocessor macros and can show you their
2015expansion (@pxref{Macros}). Most compilers do not include information
2016about preprocessor macros in the debugging information if you specify
e0f8f636
TT
2017the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2018the @sc{gnu} C compiler, provides macro information if you are using
2019the DWARF debugging format, and specify the option @option{-g3}.
2020
2021@xref{Debugging Options,,Options for Debugging Your Program or GCC,
2022gcc.info, Using the @sc{gnu} Compiler Collection (GCC)}, for more
2023information on @value{NGCC} options affecting debug information.
2024
2025You will have the best debugging experience if you use the latest
2026version of the DWARF debugging format that your compiler supports.
2027DWARF is currently the most expressive and best supported debugging
2028format in @value{GDBN}.
514c4d71 2029
c906108c 2030@need 2000
6d2ebf8b 2031@node Starting
79a6e687 2032@section Starting your Program
c906108c
SS
2033@cindex starting
2034@cindex running
2035
2036@table @code
2037@kindex run
41afff9a 2038@kindex r @r{(@code{run})}
c906108c
SS
2039@item run
2040@itemx r
7a292a7a 2041Use the @code{run} command to start your program under @value{GDBN}.
deb8ff2b
PA
2042You must first specify the program name with an argument to
2043@value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2044@value{GDBN}}), or by using the @code{file} or @code{exec-file}
2045command (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
2046
2047@end table
2048
c906108c
SS
2049If you are running your program in an execution environment that
2050supports processes, @code{run} creates an inferior process and makes
8edfe269
DJ
2051that process run your program. In some environments without processes,
2052@code{run} jumps to the start of your program. Other targets,
2053like @samp{remote}, are always running. If you get an error
2054message like this one:
2055
2056@smallexample
2057The "remote" target does not support "run".
2058Try "help target" or "continue".
2059@end smallexample
2060
2061@noindent
2062then use @code{continue} to run your program. You may need @code{load}
2063first (@pxref{load}).
c906108c
SS
2064
2065The execution of a program is affected by certain information it
2066receives from its superior. @value{GDBN} provides ways to specify this
2067information, which you must do @emph{before} starting your program. (You
2068can change it after starting your program, but such changes only affect
2069your program the next time you start it.) This information may be
2070divided into four categories:
2071
2072@table @asis
2073@item The @emph{arguments.}
2074Specify the arguments to give your program as the arguments of the
2075@code{run} command. If a shell is available on your target, the shell
2076is used to pass the arguments, so that you may use normal conventions
2077(such as wildcard expansion or variable substitution) in describing
2078the arguments.
2079In Unix systems, you can control which shell is used with the
98882a26
PA
2080@code{SHELL} environment variable. If you do not define @code{SHELL},
2081@value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2082use of any shell with the @code{set startup-with-shell} command (see
2083below for details).
c906108c
SS
2084
2085@item The @emph{environment.}
2086Your program normally inherits its environment from @value{GDBN}, but you can
2087use the @value{GDBN} commands @code{set environment} and @code{unset
2088environment} to change parts of the environment that affect
79a6e687 2089your program. @xref{Environment, ,Your Program's Environment}.
c906108c
SS
2090
2091@item The @emph{working directory.}
d092c5a2
SDJ
2092You can set your program's working directory with the command
2093@kbd{set cwd}. If you do not set any working directory with this
bc3b087d
SDJ
2094command, your program will inherit @value{GDBN}'s working directory if
2095native debugging, or the remote server's working directory if remote
2096debugging. @xref{Working Directory, ,Your Program's Working
2097Directory}.
c906108c
SS
2098
2099@item The @emph{standard input and output.}
2100Your program normally uses the same device for standard input and
2101standard output as @value{GDBN} is using. You can redirect input and output
2102in the @code{run} command line, or you can use the @code{tty} command to
2103set a different device for your program.
79a6e687 2104@xref{Input/Output, ,Your Program's Input and Output}.
c906108c
SS
2105
2106@cindex pipes
2107@emph{Warning:} While input and output redirection work, you cannot use
2108pipes to pass the output of the program you are debugging to another
2109program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2110wrong program.
2111@end table
c906108c
SS
2112
2113When you issue the @code{run} command, your program begins to execute
79a6e687 2114immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
c906108c
SS
2115of how to arrange for your program to stop. Once your program has
2116stopped, you may call functions in your program, using the @code{print}
2117or @code{call} commands. @xref{Data, ,Examining Data}.
2118
2119If the modification time of your symbol file has changed since the last
2120time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2121table, and reads it again. When it does this, @value{GDBN} tries to retain
2122your current breakpoints.
2123
4e8b0763
JB
2124@table @code
2125@kindex start
2126@item start
2127@cindex run to main procedure
2128The name of the main procedure can vary from language to language.
2129With C or C@t{++}, the main procedure name is always @code{main}, but
2130other languages such as Ada do not require a specific name for their
2131main procedure. The debugger provides a convenient way to start the
2132execution of the program and to stop at the beginning of the main
2133procedure, depending on the language used.
2134
2135The @samp{start} command does the equivalent of setting a temporary
2136breakpoint at the beginning of the main procedure and then invoking
2137the @samp{run} command.
2138
f018e82f
EZ
2139@cindex elaboration phase
2140Some programs contain an @dfn{elaboration} phase where some startup code is
2141executed before the main procedure is called. This depends on the
2142languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
2143constructors for static and global objects are executed before
2144@code{main} is called. It is therefore possible that the debugger stops
2145before reaching the main procedure. However, the temporary breakpoint
2146will remain to halt execution.
2147
2148Specify the arguments to give to your program as arguments to the
2149@samp{start} command. These arguments will be given verbatim to the
2150underlying @samp{run} command. Note that the same arguments will be
2151reused if no argument is provided during subsequent calls to
2152@samp{start} or @samp{run}.
2153
2154It is sometimes necessary to debug the program during elaboration. In
4e5a4f58
JB
2155these cases, using the @code{start} command would stop the execution
2156of your program too late, as the program would have already completed
2157the elaboration phase. Under these circumstances, either insert
2158breakpoints in your elaboration code before running your program or
2159use the @code{starti} command.
2160
2161@kindex starti
2162@item starti
2163@cindex run to first instruction
2164The @samp{starti} command does the equivalent of setting a temporary
2165breakpoint at the first instruction of a program's execution and then
2166invoking the @samp{run} command. For programs containing an
2167elaboration phase, the @code{starti} command will stop execution at
2168the start of the elaboration phase.
ccd213ac 2169
41ef2965 2170@anchor{set exec-wrapper}
ccd213ac
DJ
2171@kindex set exec-wrapper
2172@item set exec-wrapper @var{wrapper}
2173@itemx show exec-wrapper
2174@itemx unset exec-wrapper
2175When @samp{exec-wrapper} is set, the specified wrapper is used to
2176launch programs for debugging. @value{GDBN} starts your program
2177with a shell command of the form @kbd{exec @var{wrapper}
2178@var{program}}. Quoting is added to @var{program} and its
2179arguments, but not to @var{wrapper}, so you should add quotes if
2180appropriate for your shell. The wrapper runs until it executes
2181your program, and then @value{GDBN} takes control.
2182
2183You can use any program that eventually calls @code{execve} with
2184its arguments as a wrapper. Several standard Unix utilities do
2185this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2186with @code{exec "$@@"} will also work.
2187
2188For example, you can use @code{env} to pass an environment variable to
2189the debugged program, without setting the variable in your shell's
2190environment:
2191
2192@smallexample
2193(@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2194(@value{GDBP}) run
2195@end smallexample
2196
2197This command is available when debugging locally on most targets, excluding
2198@sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2199
98882a26 2200@kindex set startup-with-shell
aefd8b33 2201@anchor{set startup-with-shell}
98882a26
PA
2202@item set startup-with-shell
2203@itemx set startup-with-shell on
2204@itemx set startup-with-shell off
ca145713 2205@itemx show startup-with-shell
98882a26
PA
2206On Unix systems, by default, if a shell is available on your target,
2207@value{GDBN}) uses it to start your program. Arguments of the
2208@code{run} command are passed to the shell, which does variable
2209substitution, expands wildcard characters and performs redirection of
2210I/O. In some circumstances, it may be useful to disable such use of a
2211shell, for example, when debugging the shell itself or diagnosing
2212startup failures such as:
2213
2214@smallexample
2215(@value{GDBP}) run
2216Starting program: ./a.out
2217During startup program terminated with signal SIGSEGV, Segmentation fault.
2218@end smallexample
2219
2220@noindent
2221which indicates the shell or the wrapper specified with
2222@samp{exec-wrapper} crashed, not your program. Most often, this is
afa332ce
PA
2223caused by something odd in your shell's non-interactive mode
2224initialization file---such as @file{.cshrc} for C-shell,
2225$@file{.zshenv} for the Z shell, or the file specified in the
2226@samp{BASH_ENV} environment variable for BASH.
98882a26 2227
6a3cb8e8
PA
2228@anchor{set auto-connect-native-target}
2229@kindex set auto-connect-native-target
2230@item set auto-connect-native-target
2231@itemx set auto-connect-native-target on
2232@itemx set auto-connect-native-target off
2233@itemx show auto-connect-native-target
2234
2235By default, if not connected to any target yet (e.g., with
2236@code{target remote}), the @code{run} command starts your program as a
2237native process under @value{GDBN}, on your local machine. If you're
2238sure you don't want to debug programs on your local machine, you can
2239tell @value{GDBN} to not connect to the native target automatically
2240with the @code{set auto-connect-native-target off} command.
2241
2242If @code{on}, which is the default, and if @value{GDBN} is not
2243connected to a target already, the @code{run} command automaticaly
2244connects to the native target, if one is available.
2245
2246If @code{off}, and if @value{GDBN} is not connected to a target
2247already, the @code{run} command fails with an error:
2248
2249@smallexample
2250(@value{GDBP}) run
2251Don't know how to run. Try "help target".
2252@end smallexample
2253
2254If @value{GDBN} is already connected to a target, @value{GDBN} always
2255uses it with the @code{run} command.
2256
2257In any case, you can explicitly connect to the native target with the
2258@code{target native} command. For example,
2259
2260@smallexample
2261(@value{GDBP}) set auto-connect-native-target off
2262(@value{GDBP}) run
2263Don't know how to run. Try "help target".
2264(@value{GDBP}) target native
2265(@value{GDBP}) run
2266Starting program: ./a.out
2267[Inferior 1 (process 10421) exited normally]
2268@end smallexample
2269
2270In case you connected explicitly to the @code{native} target,
2271@value{GDBN} remains connected even if all inferiors exit, ready for
2272the next @code{run} command. Use the @code{disconnect} command to
2273disconnect.
2274
2275Examples of other commands that likewise respect the
2276@code{auto-connect-native-target} setting: @code{attach}, @code{info
2277proc}, @code{info os}.
2278
10568435
JK
2279@kindex set disable-randomization
2280@item set disable-randomization
2281@itemx set disable-randomization on
2282This option (enabled by default in @value{GDBN}) will turn off the native
2283randomization of the virtual address space of the started program. This option
2284is useful for multiple debugging sessions to make the execution better
2285reproducible and memory addresses reusable across debugging sessions.
2286
03583c20
UW
2287This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2288On @sc{gnu}/Linux you can get the same behavior using
10568435
JK
2289
2290@smallexample
2291(@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2292@end smallexample
2293
2294@item set disable-randomization off
2295Leave the behavior of the started executable unchanged. Some bugs rear their
2296ugly heads only when the program is loaded at certain addresses. If your bug
2297disappears when you run the program under @value{GDBN}, that might be because
2298@value{GDBN} by default disables the address randomization on platforms, such
2299as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2300disable-randomization off} to try to reproduce such elusive bugs.
2301
03583c20
UW
2302On targets where it is available, virtual address space randomization
2303protects the programs against certain kinds of security attacks. In these
10568435
JK
2304cases the attacker needs to know the exact location of a concrete executable
2305code. Randomizing its location makes it impossible to inject jumps misusing
2306a code at its expected addresses.
2307
2308Prelinking shared libraries provides a startup performance advantage but it
2309makes addresses in these libraries predictable for privileged processes by
2310having just unprivileged access at the target system. Reading the shared
2311library binary gives enough information for assembling the malicious code
2312misusing it. Still even a prelinked shared library can get loaded at a new
2313random address just requiring the regular relocation process during the
2314startup. Shared libraries not already prelinked are always loaded at
2315a randomly chosen address.
2316
2317Position independent executables (PIE) contain position independent code
2318similar to the shared libraries and therefore such executables get loaded at
2319a randomly chosen address upon startup. PIE executables always load even
2320already prelinked shared libraries at a random address. You can build such
2321executable using @command{gcc -fPIE -pie}.
2322
2323Heap (malloc storage), stack and custom mmap areas are always placed randomly
2324(as long as the randomization is enabled).
2325
2326@item show disable-randomization
2327Show the current setting of the explicit disable of the native randomization of
2328the virtual address space of the started program.
2329
4e8b0763
JB
2330@end table
2331
6d2ebf8b 2332@node Arguments
79a6e687 2333@section Your Program's Arguments
c906108c
SS
2334
2335@cindex arguments (to your program)
2336The arguments to your program can be specified by the arguments of the
5d161b24 2337@code{run} command.
c906108c
SS
2338They are passed to a shell, which expands wildcard characters and
2339performs redirection of I/O, and thence to your program. Your
2340@code{SHELL} environment variable (if it exists) specifies what shell
2341@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
2342the default shell (@file{/bin/sh} on Unix).
2343
2344On non-Unix systems, the program is usually invoked directly by
2345@value{GDBN}, which emulates I/O redirection via the appropriate system
2346calls, and the wildcard characters are expanded by the startup code of
2347the program, not by the shell.
c906108c
SS
2348
2349@code{run} with no arguments uses the same arguments used by the previous
2350@code{run}, or those set by the @code{set args} command.
2351
c906108c 2352@table @code
41afff9a 2353@kindex set args
c906108c
SS
2354@item set args
2355Specify the arguments to be used the next time your program is run. If
2356@code{set args} has no arguments, @code{run} executes your program
2357with no arguments. Once you have run your program with arguments,
2358using @code{set args} before the next @code{run} is the only way to run
2359it again without arguments.
2360
2361@kindex show args
2362@item show args
2363Show the arguments to give your program when it is started.
2364@end table
2365
6d2ebf8b 2366@node Environment
79a6e687 2367@section Your Program's Environment
c906108c
SS
2368
2369@cindex environment (of your program)
2370The @dfn{environment} consists of a set of environment variables and
2371their values. Environment variables conventionally record such things as
2372your user name, your home directory, your terminal type, and your search
2373path for programs to run. Usually you set up environment variables with
2374the shell and they are inherited by all the other programs you run. When
2375debugging, it can be useful to try running your program with a modified
2376environment without having to start @value{GDBN} over again.
2377
2378@table @code
2379@kindex path
2380@item path @var{directory}
2381Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
2382(the search path for executables) that will be passed to your program.
2383The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
2384You may specify several directory names, separated by whitespace or by a
2385system-dependent separator character (@samp{:} on Unix, @samp{;} on
2386MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2387is moved to the front, so it is searched sooner.
c906108c
SS
2388
2389You can use the string @samp{$cwd} to refer to whatever is the current
2390working directory at the time @value{GDBN} searches the path. If you
2391use @samp{.} instead, it refers to the directory where you executed the
2392@code{path} command. @value{GDBN} replaces @samp{.} in the
2393@var{directory} argument (with the current path) before adding
2394@var{directory} to the search path.
2395@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2396@c document that, since repeating it would be a no-op.
2397
2398@kindex show paths
2399@item show paths
2400Display the list of search paths for executables (the @code{PATH}
2401environment variable).
2402
2403@kindex show environment
2404@item show environment @r{[}@var{varname}@r{]}
2405Print the value of environment variable @var{varname} to be given to
2406your program when it starts. If you do not supply @var{varname},
2407print the names and values of all environment variables to be given to
2408your program. You can abbreviate @code{environment} as @code{env}.
2409
2410@kindex set environment
0a2dde4a 2411@anchor{set environment}
53a5351d 2412@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c 2413Set environment variable @var{varname} to @var{value}. The value
41ef2965 2414changes for your program (and the shell @value{GDBN} uses to launch
697aa1b7 2415it), not for @value{GDBN} itself. The @var{value} may be any string; the
41ef2965
PA
2416values of environment variables are just strings, and any
2417interpretation is supplied by your program itself. The @var{value}
c906108c
SS
2418parameter is optional; if it is eliminated, the variable is set to a
2419null value.
2420@c "any string" here does not include leading, trailing
2421@c blanks. Gnu asks: does anyone care?
2422
2423For example, this command:
2424
474c8240 2425@smallexample
c906108c 2426set env USER = foo
474c8240 2427@end smallexample
c906108c
SS
2428
2429@noindent
d4f3574e 2430tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2431@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2432are not actually required.)
2433
41ef2965
PA
2434Note that on Unix systems, @value{GDBN} runs your program via a shell,
2435which also inherits the environment set with @code{set environment}.
2436If necessary, you can avoid that by using the @samp{env} program as a
2437wrapper instead of using @code{set environment}. @xref{set
2438exec-wrapper}, for an example doing just that.
2439
0a2dde4a
SDJ
2440Environment variables that are set by the user are also transmitted to
2441@command{gdbserver} to be used when starting the remote inferior.
2442@pxref{QEnvironmentHexEncoded}.
2443
c906108c 2444@kindex unset environment
0a2dde4a 2445@anchor{unset environment}
c906108c
SS
2446@item unset environment @var{varname}
2447Remove variable @var{varname} from the environment to be passed to your
2448program. This is different from @samp{set env @var{varname} =};
2449@code{unset environment} removes the variable from the environment,
2450rather than assigning it an empty value.
0a2dde4a
SDJ
2451
2452Environment variables that are unset by the user are also unset on
2453@command{gdbserver} when starting the remote inferior.
2454@pxref{QEnvironmentUnset}.
c906108c
SS
2455@end table
2456
d4f3574e 2457@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
afa332ce
PA
2458the shell indicated by your @code{SHELL} environment variable if it
2459exists (or @code{/bin/sh} if not). If your @code{SHELL} variable
2460names a shell that runs an initialization file when started
2461non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2462for the Z shell, or the file specified in the @samp{BASH_ENV}
2463environment variable for BASH---any variables you set in that file
2464affect your program. You may wish to move setting of environment
2465variables to files that are only run when you sign on, such as
2466@file{.login} or @file{.profile}.
c906108c 2467
6d2ebf8b 2468@node Working Directory
79a6e687 2469@section Your Program's Working Directory
c906108c
SS
2470
2471@cindex working directory (of your program)
d092c5a2
SDJ
2472Each time you start your program with @code{run}, the inferior will be
2473initialized with the current working directory specified by the
2474@kbd{set cwd} command. If no directory has been specified by this
2475command, then the inferior will inherit @value{GDBN}'s current working
bc3b087d
SDJ
2476directory as its working directory if native debugging, or it will
2477inherit the remote server's current working directory if remote
2478debugging.
c906108c
SS
2479
2480@table @code
d092c5a2
SDJ
2481@kindex set cwd
2482@cindex change inferior's working directory
2483@anchor{set cwd command}
2484@item set cwd @r{[}@var{directory}@r{]}
2485Set the inferior's working directory to @var{directory}, which will be
2486@code{glob}-expanded in order to resolve tildes (@file{~}). If no
2487argument has been specified, the command clears the setting and resets
2488it to an empty state. This setting has no effect on @value{GDBN}'s
2489working directory, and it only takes effect the next time you start
2490the inferior. The @file{~} in @var{directory} is a short for the
2491@dfn{home directory}, usually pointed to by the @env{HOME} environment
2492variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2493uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2494fallback.
2495
2496You can also change @value{GDBN}'s current working directory by using
2497the @code{cd} command.
dbfa4523 2498@xref{cd command}.
d092c5a2
SDJ
2499
2500@kindex show cwd
2501@cindex show inferior's working directory
2502@item show cwd
2503Show the inferior's working directory. If no directory has been
2504specified by @kbd{set cwd}, then the default inferior's working
2505directory is the same as @value{GDBN}'s working directory.
2506
c906108c 2507@kindex cd
d092c5a2
SDJ
2508@cindex change @value{GDBN}'s working directory
2509@anchor{cd command}
f3c8a52a
JK
2510@item cd @r{[}@var{directory}@r{]}
2511Set the @value{GDBN} working directory to @var{directory}. If not
2512given, @var{directory} uses @file{'~'}.
c906108c 2513
d092c5a2
SDJ
2514The @value{GDBN} working directory serves as a default for the
2515commands that specify files for @value{GDBN} to operate on.
2516@xref{Files, ,Commands to Specify Files}.
dbfa4523 2517@xref{set cwd command}.
d092c5a2 2518
c906108c
SS
2519@kindex pwd
2520@item pwd
2521Print the @value{GDBN} working directory.
2522@end table
2523
60bf7e09
EZ
2524It is generally impossible to find the current working directory of
2525the process being debugged (since a program can change its directory
2d97a5d9 2526during its run). If you work on a system where @value{GDBN} supports
754452f0 2527the @code{info proc} command (@pxref{Process Information}), you can
2d97a5d9 2528use the @code{info proc} command to find out the
60bf7e09
EZ
2529current working directory of the debuggee.
2530
6d2ebf8b 2531@node Input/Output
79a6e687 2532@section Your Program's Input and Output
c906108c
SS
2533
2534@cindex redirection
2535@cindex i/o
2536@cindex terminal
2537By default, the program you run under @value{GDBN} does input and output to
5d161b24 2538the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2539to its own terminal modes to interact with you, but it records the terminal
2540modes your program was using and switches back to them when you continue
2541running your program.
2542
2543@table @code
2544@kindex info terminal
2545@item info terminal
2546Displays information recorded by @value{GDBN} about the terminal modes your
2547program is using.
2548@end table
2549
2550You can redirect your program's input and/or output using shell
2551redirection with the @code{run} command. For example,
2552
474c8240 2553@smallexample
c906108c 2554run > outfile
474c8240 2555@end smallexample
c906108c
SS
2556
2557@noindent
2558starts your program, diverting its output to the file @file{outfile}.
2559
2560@kindex tty
2561@cindex controlling terminal
2562Another way to specify where your program should do input and output is
2563with the @code{tty} command. This command accepts a file name as
2564argument, and causes this file to be the default for future @code{run}
2565commands. It also resets the controlling terminal for the child
2566process, for future @code{run} commands. For example,
2567
474c8240 2568@smallexample
c906108c 2569tty /dev/ttyb
474c8240 2570@end smallexample
c906108c
SS
2571
2572@noindent
2573directs that processes started with subsequent @code{run} commands
2574default to do input and output on the terminal @file{/dev/ttyb} and have
2575that as their controlling terminal.
2576
2577An explicit redirection in @code{run} overrides the @code{tty} command's
2578effect on the input/output device, but not its effect on the controlling
2579terminal.
2580
2581When you use the @code{tty} command or redirect input in the @code{run}
2582command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2583for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2584for @code{set inferior-tty}.
2585
2586@cindex inferior tty
2587@cindex set inferior controlling terminal
2588You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2589display the name of the terminal that will be used for future runs of your
2590program.
2591
2592@table @code
0a1ddfa6 2593@item set inferior-tty [ @var{tty} ]
3cb3b8df 2594@kindex set inferior-tty
0a1ddfa6
SM
2595Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
2596restores the default behavior, which is to use the same terminal as
2597@value{GDBN}.
3cb3b8df
BR
2598
2599@item show inferior-tty
2600@kindex show inferior-tty
2601Show the current tty for the program being debugged.
2602@end table
c906108c 2603
6d2ebf8b 2604@node Attach
79a6e687 2605@section Debugging an Already-running Process
c906108c
SS
2606@kindex attach
2607@cindex attach
2608
2609@table @code
2610@item attach @var{process-id}
2611This command attaches to a running process---one that was started
2612outside @value{GDBN}. (@code{info files} shows your active
2613targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2614find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2615or with the @samp{jobs -l} shell command.
2616
2617@code{attach} does not repeat if you press @key{RET} a second time after
2618executing the command.
2619@end table
2620
2621To use @code{attach}, your program must be running in an environment
2622which supports processes; for example, @code{attach} does not work for
2623programs on bare-board targets that lack an operating system. You must
2624also have permission to send the process a signal.
2625
2626When you use @code{attach}, the debugger finds the program running in
2627the process first by looking in the current working directory, then (if
2628the program is not found) by using the source file search path
79a6e687 2629(@pxref{Source Path, ,Specifying Source Directories}). You can also use
c906108c
SS
2630the @code{file} command to load the program. @xref{Files, ,Commands to
2631Specify Files}.
2632
2633The first thing @value{GDBN} does after arranging to debug the specified
2634process is to stop it. You can examine and modify an attached process
53a5351d
JM
2635with all the @value{GDBN} commands that are ordinarily available when
2636you start processes with @code{run}. You can insert breakpoints; you
2637can step and continue; you can modify storage. If you would rather the
2638process continue running, you may use the @code{continue} command after
c906108c
SS
2639attaching @value{GDBN} to the process.
2640
2641@table @code
2642@kindex detach
2643@item detach
2644When you have finished debugging the attached process, you can use the
2645@code{detach} command to release it from @value{GDBN} control. Detaching
2646the process continues its execution. After the @code{detach} command,
2647that process and @value{GDBN} become completely independent once more, and you
2648are ready to @code{attach} another process or start one with @code{run}.
2649@code{detach} does not repeat if you press @key{RET} again after
2650executing the command.
2651@end table
2652
159fcc13
JK
2653If you exit @value{GDBN} while you have an attached process, you detach
2654that process. If you use the @code{run} command, you kill that process.
2655By default, @value{GDBN} asks for confirmation if you try to do either of these
2656things; you can control whether or not you need to confirm by using the
2657@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
79a6e687 2658Messages}).
c906108c 2659
6d2ebf8b 2660@node Kill Process
79a6e687 2661@section Killing the Child Process
c906108c
SS
2662
2663@table @code
2664@kindex kill
2665@item kill
2666Kill the child process in which your program is running under @value{GDBN}.
2667@end table
2668
2669This command is useful if you wish to debug a core dump instead of a
2670running process. @value{GDBN} ignores any core dump file while your program
2671is running.
2672
2673On some operating systems, a program cannot be executed outside @value{GDBN}
2674while you have breakpoints set on it inside @value{GDBN}. You can use the
2675@code{kill} command in this situation to permit running your program
2676outside the debugger.
2677
2678The @code{kill} command is also useful if you wish to recompile and
2679relink your program, since on many systems it is impossible to modify an
2680executable file while it is running in a process. In this case, when you
2681next type @code{run}, @value{GDBN} notices that the file has changed, and
2682reads the symbol table again (while trying to preserve your current
2683breakpoint settings).
2684
6c95b8df
PA
2685@node Inferiors and Programs
2686@section Debugging Multiple Inferiors and Programs
b77209e0 2687
6c95b8df
PA
2688@value{GDBN} lets you run and debug multiple programs in a single
2689session. In addition, @value{GDBN} on some systems may let you run
2690several programs simultaneously (otherwise you have to exit from one
2691before starting another). In the most general case, you can have
2692multiple threads of execution in each of multiple processes, launched
2693from multiple executables.
b77209e0
PA
2694
2695@cindex inferior
2696@value{GDBN} represents the state of each program execution with an
2697object called an @dfn{inferior}. An inferior typically corresponds to
2698a process, but is more general and applies also to targets that do not
2699have processes. Inferiors may be created before a process runs, and
6c95b8df
PA
2700may be retained after a process exits. Inferiors have unique
2701identifiers that are different from process ids. Usually each
2702inferior will also have its own distinct address space, although some
2703embedded targets may have several inferiors running in different parts
2704of a single address space. Each inferior may in turn have multiple
2705threads running in it.
b77209e0 2706
6c95b8df
PA
2707To find out what inferiors exist at any moment, use @w{@code{info
2708inferiors}}:
b77209e0
PA
2709
2710@table @code
2711@kindex info inferiors
2712@item info inferiors
2713Print a list of all inferiors currently being managed by @value{GDBN}.
3a1ff0b6
PA
2714
2715@value{GDBN} displays for each inferior (in this order):
2716
2717@enumerate
2718@item
2719the inferior number assigned by @value{GDBN}
2720
2721@item
2722the target system's inferior identifier
6c95b8df
PA
2723
2724@item
2725the name of the executable the inferior is running.
2726
3a1ff0b6
PA
2727@end enumerate
2728
2729@noindent
2730An asterisk @samp{*} preceding the @value{GDBN} inferior number
2731indicates the current inferior.
2732
2733For example,
2277426b 2734@end table
3a1ff0b6
PA
2735@c end table here to get a little more width for example
2736
2737@smallexample
2738(@value{GDBP}) info inferiors
6c95b8df
PA
2739 Num Description Executable
2740 2 process 2307 hello
2741* 1 process 3401 goodbye
3a1ff0b6 2742@end smallexample
2277426b
PA
2743
2744To switch focus between inferiors, use the @code{inferior} command:
2745
2746@table @code
3a1ff0b6
PA
2747@kindex inferior @var{infno}
2748@item inferior @var{infno}
2749Make inferior number @var{infno} the current inferior. The argument
2750@var{infno} is the inferior number assigned by @value{GDBN}, as shown
2751in the first field of the @samp{info inferiors} display.
2277426b
PA
2752@end table
2753
e3940304
PA
2754@vindex $_inferior@r{, convenience variable}
2755The debugger convenience variable @samp{$_inferior} contains the
2756number of the current inferior. You may find this useful in writing
2757breakpoint conditional expressions, command scripts, and so forth.
2758@xref{Convenience Vars,, Convenience Variables}, for general
2759information on convenience variables.
6c95b8df
PA
2760
2761You can get multiple executables into a debugging session via the
2762@code{add-inferior} and @w{@code{clone-inferior}} commands. On some
2763systems @value{GDBN} can add inferiors to the debug session
2764automatically by following calls to @code{fork} and @code{exec}. To
2765remove inferiors from the debugging session use the
af624141 2766@w{@code{remove-inferiors}} command.
6c95b8df
PA
2767
2768@table @code
2769@kindex add-inferior
2770@item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ]
2771Adds @var{n} inferiors to be run using @var{executable} as the
697aa1b7 2772executable; @var{n} defaults to 1. If no executable is specified,
6c95b8df
PA
2773the inferiors begins empty, with no program. You can still assign or
2774change the program assigned to the inferior at any time by using the
2775@code{file} command with the executable name as its argument.
2776
2777@kindex clone-inferior
2778@item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
2779Adds @var{n} inferiors ready to execute the same program as inferior
697aa1b7 2780@var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
6c95b8df
PA
2781number of the current inferior. This is a convenient command when you
2782want to run another instance of the inferior you are debugging.
2783
2784@smallexample
2785(@value{GDBP}) info inferiors
2786 Num Description Executable
2787* 1 process 29964 helloworld
2788(@value{GDBP}) clone-inferior
2789Added inferior 2.
27901 inferiors added.
2791(@value{GDBP}) info inferiors
2792 Num Description Executable
2793 2 <null> helloworld
2794* 1 process 29964 helloworld
2795@end smallexample
2796
2797You can now simply switch focus to inferior 2 and run it.
2798
af624141
MS
2799@kindex remove-inferiors
2800@item remove-inferiors @var{infno}@dots{}
2801Removes the inferior or inferiors @var{infno}@dots{}. It is not
2802possible to remove an inferior that is running with this command. For
2803those, use the @code{kill} or @code{detach} command first.
6c95b8df
PA
2804
2805@end table
2806
2807To quit debugging one of the running inferiors that is not the current
2808inferior, you can either detach from it by using the @w{@code{detach
2809inferior}} command (allowing it to run independently), or kill it
af624141 2810using the @w{@code{kill inferiors}} command:
2277426b
PA
2811
2812@table @code
af624141
MS
2813@kindex detach inferiors @var{infno}@dots{}
2814@item detach inferior @var{infno}@dots{}
2815Detach from the inferior or inferiors identified by @value{GDBN}
5e30da2c 2816inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
af624141
MS
2817still stays on the list of inferiors shown by @code{info inferiors},
2818but its Description will show @samp{<null>}.
2819
2820@kindex kill inferiors @var{infno}@dots{}
2821@item kill inferiors @var{infno}@dots{}
2822Kill the inferior or inferiors identified by @value{GDBN} inferior
2823number(s) @var{infno}@dots{}. Note that the inferior's entry still
2824stays on the list of inferiors shown by @code{info inferiors}, but its
2825Description will show @samp{<null>}.
2277426b
PA
2826@end table
2827
6c95b8df 2828After the successful completion of a command such as @code{detach},
af624141 2829@code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
6c95b8df
PA
2830a normal process exit, the inferior is still valid and listed with
2831@code{info inferiors}, ready to be restarted.
2832
2833
2277426b
PA
2834To be notified when inferiors are started or exit under @value{GDBN}'s
2835control use @w{@code{set print inferior-events}}:
b77209e0 2836
2277426b 2837@table @code
b77209e0
PA
2838@kindex set print inferior-events
2839@cindex print messages on inferior start and exit
2840@item set print inferior-events
2841@itemx set print inferior-events on
2842@itemx set print inferior-events off
2843The @code{set print inferior-events} command allows you to enable or
2844disable printing of messages when @value{GDBN} notices that new
2845inferiors have started or that inferiors have exited or have been
2846detached. By default, these messages will not be printed.
2847
2848@kindex show print inferior-events
2849@item show print inferior-events
2850Show whether messages will be printed when @value{GDBN} detects that
2851inferiors have started, exited or have been detached.
2852@end table
2853
6c95b8df
PA
2854Many commands will work the same with multiple programs as with a
2855single program: e.g., @code{print myglobal} will simply display the
2856value of @code{myglobal} in the current inferior.
2857
2858
2859Occasionaly, when debugging @value{GDBN} itself, it may be useful to
2860get more info about the relationship of inferiors, programs, address
2861spaces in a debug session. You can do that with the @w{@code{maint
2862info program-spaces}} command.
2863
2864@table @code
2865@kindex maint info program-spaces
2866@item maint info program-spaces
2867Print a list of all program spaces currently being managed by
2868@value{GDBN}.
2869
2870@value{GDBN} displays for each program space (in this order):
2871
2872@enumerate
2873@item
2874the program space number assigned by @value{GDBN}
2875
2876@item
2877the name of the executable loaded into the program space, with e.g.,
2878the @code{file} command.
2879
2880@end enumerate
2881
2882@noindent
2883An asterisk @samp{*} preceding the @value{GDBN} program space number
2884indicates the current program space.
2885
2886In addition, below each program space line, @value{GDBN} prints extra
2887information that isn't suitable to display in tabular form. For
2888example, the list of inferiors bound to the program space.
2889
2890@smallexample
2891(@value{GDBP}) maint info program-spaces
2892 Id Executable
b05b1202 2893* 1 hello
6c95b8df
PA
2894 2 goodbye
2895 Bound inferiors: ID 1 (process 21561)
6c95b8df
PA
2896@end smallexample
2897
2898Here we can see that no inferior is running the program @code{hello},
2899while @code{process 21561} is running the program @code{goodbye}. On
2900some targets, it is possible that multiple inferiors are bound to the
2901same program space. The most common example is that of debugging both
2902the parent and child processes of a @code{vfork} call. For example,
2903
2904@smallexample
2905(@value{GDBP}) maint info program-spaces
2906 Id Executable
2907* 1 vfork-test
2908 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
2909@end smallexample
2910
2911Here, both inferior 2 and inferior 1 are running in the same program
2912space as a result of inferior 1 having executed a @code{vfork} call.
2913@end table
2914
6d2ebf8b 2915@node Threads
79a6e687 2916@section Debugging Programs with Multiple Threads
c906108c
SS
2917
2918@cindex threads of execution
2919@cindex multiple threads
2920@cindex switching threads
b1236ac3 2921In some operating systems, such as GNU/Linux and Solaris, a single program
c906108c
SS
2922may have more than one @dfn{thread} of execution. The precise semantics
2923of threads differ from one operating system to another, but in general
2924the threads of a single program are akin to multiple processes---except
2925that they share one address space (that is, they can all examine and
2926modify the same variables). On the other hand, each thread has its own
2927registers and execution stack, and perhaps private memory.
2928
2929@value{GDBN} provides these facilities for debugging multi-thread
2930programs:
2931
2932@itemize @bullet
2933@item automatic notification of new threads
5d5658a1 2934@item @samp{thread @var{thread-id}}, a command to switch among threads
c906108c 2935@item @samp{info threads}, a command to inquire about existing threads
5d5658a1 2936@item @samp{thread apply [@var{thread-id-list}] [@var{all}] @var{args}},
c906108c
SS
2937a command to apply a command to a list of threads
2938@item thread-specific breakpoints
93815fbf
VP
2939@item @samp{set print thread-events}, which controls printing of
2940messages on thread start and exit.
17a37d48
PP
2941@item @samp{set libthread-db-search-path @var{path}}, which lets
2942the user specify which @code{libthread_db} to use if the default choice
2943isn't compatible with the program.
c906108c
SS
2944@end itemize
2945
c906108c
SS
2946@cindex focus of debugging
2947@cindex current thread
2948The @value{GDBN} thread debugging facility allows you to observe all
2949threads while your program runs---but whenever @value{GDBN} takes
2950control, one thread in particular is always the focus of debugging.
2951This thread is called the @dfn{current thread}. Debugging commands show
2952program information from the perspective of the current thread.
2953
41afff9a 2954@cindex @code{New} @var{systag} message
c906108c
SS
2955@cindex thread identifier (system)
2956@c FIXME-implementors!! It would be more helpful if the [New...] message
2957@c included GDB's numeric thread handle, so you could just go to that
2958@c thread without first checking `info threads'.
2959Whenever @value{GDBN} detects a new thread in your program, it displays
2960the target system's identification for the thread with a message in the
697aa1b7 2961form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
c906108c 2962whose form varies depending on the particular system. For example, on
8807d78b 2963@sc{gnu}/Linux, you might see
c906108c 2964
474c8240 2965@smallexample
08e796bc 2966[New Thread 0x41e02940 (LWP 25582)]
474c8240 2967@end smallexample
c906108c
SS
2968
2969@noindent
b1236ac3 2970when @value{GDBN} notices a new thread. In contrast, on other systems,
c906108c
SS
2971the @var{systag} is simply something like @samp{process 368}, with no
2972further qualifier.
2973
2974@c FIXME!! (1) Does the [New...] message appear even for the very first
2975@c thread of a program, or does it only appear for the
6ca652b0 2976@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2977@c program?
2978@c (2) *Is* there necessarily a first thread always? Or do some
2979@c multithread systems permit starting a program with multiple
5d161b24 2980@c threads ab initio?
c906108c 2981
5d5658a1
PA
2982@anchor{thread numbers}
2983@cindex thread number, per inferior
c906108c 2984@cindex thread identifier (GDB)
5d5658a1
PA
2985For debugging purposes, @value{GDBN} associates its own thread number
2986---always a single integer---with each thread of an inferior. This
2987number is unique between all threads of an inferior, but not unique
2988between threads of different inferiors.
2989
2990@cindex qualified thread ID
2991You can refer to a given thread in an inferior using the qualified
2992@var{inferior-num}.@var{thread-num} syntax, also known as
2993@dfn{qualified thread ID}, with @var{inferior-num} being the inferior
2994number and @var{thread-num} being the thread number of the given
2995inferior. For example, thread @code{2.3} refers to thread number 3 of
2996inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
2997then @value{GDBN} infers you're referring to a thread of the current
2998inferior.
2999
3000Until you create a second inferior, @value{GDBN} does not show the
3001@var{inferior-num} part of thread IDs, even though you can always use
3002the full @var{inferior-num}.@var{thread-num} form to refer to threads
3003of inferior 1, the initial inferior.
3004
3005@anchor{thread ID lists}
3006@cindex thread ID lists
3007Some commands accept a space-separated @dfn{thread ID list} as
71ef29a8
PA
3008argument. A list element can be:
3009
3010@enumerate
3011@item
3012A thread ID as shown in the first field of the @samp{info threads}
3013display, with or without an inferior qualifier. E.g., @samp{2.1} or
3014@samp{1}.
3015
3016@item
3017A range of thread numbers, again with or without an inferior
3018qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3019@var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3020
3021@item
3022All threads of an inferior, specified with a star wildcard, with or
3023without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3024@samp{1.*}) or @code{*}. The former refers to all threads of the
3025given inferior, and the latter form without an inferior qualifier
3026refers to all threads of the current inferior.
3027
3028@end enumerate
3029
3030For example, if the current inferior is 1, and inferior 7 has one
3031thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3032includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
30337 to 9 of inferior 6 and all threads of inferior 7. That is, in
3034expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
30357.1}.
3036
5d5658a1
PA
3037
3038@anchor{global thread numbers}
3039@cindex global thread number
3040@cindex global thread identifier (GDB)
3041In addition to a @emph{per-inferior} number, each thread is also
3042assigned a unique @emph{global} number, also known as @dfn{global
3043thread ID}, a single integer. Unlike the thread number component of
3044the thread ID, no two threads have the same global ID, even when
3045you're debugging multiple inferiors.
c906108c 3046
f4f4330e
PA
3047From @value{GDBN}'s perspective, a process always has at least one
3048thread. In other words, @value{GDBN} assigns a thread number to the
3049program's ``main thread'' even if the program is not multi-threaded.
3050
5d5658a1 3051@vindex $_thread@r{, convenience variable}
663f6d42
PA
3052@vindex $_gthread@r{, convenience variable}
3053The debugger convenience variables @samp{$_thread} and
3054@samp{$_gthread} contain, respectively, the per-inferior thread number
3055and the global thread number of the current thread. You may find this
5d5658a1
PA
3056useful in writing breakpoint conditional expressions, command scripts,
3057and so forth. @xref{Convenience Vars,, Convenience Variables}, for
3058general information on convenience variables.
3059
f303dbd6
PA
3060If @value{GDBN} detects the program is multi-threaded, it augments the
3061usual message about stopping at a breakpoint with the ID and name of
3062the thread that hit the breakpoint.
3063
3064@smallexample
3065Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3066@end smallexample
3067
3068Likewise when the program receives a signal:
3069
3070@smallexample
3071Thread 1 "main" received signal SIGINT, Interrupt.
3072@end smallexample
3073
c906108c
SS
3074@table @code
3075@kindex info threads
5d5658a1
PA
3076@item info threads @r{[}@var{thread-id-list}@r{]}
3077
3078Display information about one or more threads. With no arguments
3079displays information about all threads. You can specify the list of
3080threads that you want to display using the thread ID list syntax
3081(@pxref{thread ID lists}).
3082
60f98dde 3083@value{GDBN} displays for each thread (in this order):
c906108c
SS
3084
3085@enumerate
09d4efe1 3086@item
5d5658a1 3087the per-inferior thread number assigned by @value{GDBN}
c906108c 3088
c84f6bbf
PA
3089@item
3090the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3091option was specified
3092
09d4efe1
EZ
3093@item
3094the target system's thread identifier (@var{systag})
c906108c 3095
4694da01
TT
3096@item
3097the thread's name, if one is known. A thread can either be named by
3098the user (see @code{thread name}, below), or, in some cases, by the
3099program itself.
3100
09d4efe1
EZ
3101@item
3102the current stack frame summary for that thread
c906108c
SS
3103@end enumerate
3104
3105@noindent
3106An asterisk @samp{*} to the left of the @value{GDBN} thread number
3107indicates the current thread.
3108
5d161b24 3109For example,
c906108c
SS
3110@end table
3111@c end table here to get a little more width for example
3112
3113@smallexample
3114(@value{GDBP}) info threads
13fd8b81 3115 Id Target Id Frame
c0ecb95f 3116* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
b05b1202
PA
3117 2 process 35 thread 23 0x34e5 in sigpause ()
3118 3 process 35 thread 27 0x34e5 in sigpause ()
c906108c
SS
3119 at threadtest.c:68
3120@end smallexample
53a5351d 3121
5d5658a1
PA
3122If you're debugging multiple inferiors, @value{GDBN} displays thread
3123IDs using the qualified @var{inferior-num}.@var{thread-num} format.
c84f6bbf
PA
3124Otherwise, only @var{thread-num} is shown.
3125
3126If you specify the @samp{-gid} option, @value{GDBN} displays a column
3127indicating each thread's global thread ID:
5d5658a1
PA
3128
3129@smallexample
3130(@value{GDBP}) info threads
c84f6bbf
PA
3131 Id GId Target Id Frame
3132 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3133 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3134 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3135* 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
5d5658a1
PA
3136@end smallexample
3137
c45da7e6
EZ
3138On Solaris, you can display more information about user threads with a
3139Solaris-specific command:
3140
3141@table @code
3142@item maint info sol-threads
3143@kindex maint info sol-threads
3144@cindex thread info (Solaris)
3145Display info on Solaris user threads.
3146@end table
3147
c906108c 3148@table @code
5d5658a1
PA
3149@kindex thread @var{thread-id}
3150@item thread @var{thread-id}
3151Make thread ID @var{thread-id} the current thread. The command
3152argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3153the first field of the @samp{info threads} display, with or without an
3154inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3155
3156@value{GDBN} responds by displaying the system identifier of the
3157thread you selected, and its current stack frame summary:
c906108c
SS
3158
3159@smallexample
c906108c 3160(@value{GDBP}) thread 2
13fd8b81
TT
3161[Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3162#0 some_function (ignore=0x0) at example.c:8
31638 printf ("hello\n");
c906108c
SS
3164@end smallexample
3165
3166@noindent
3167As with the @samp{[New @dots{}]} message, the form of the text after
3168@samp{Switching to} depends on your system's conventions for identifying
5d161b24 3169threads.
c906108c 3170
9c16f35a 3171@kindex thread apply
638ac427 3172@cindex apply command to several threads
5d5658a1 3173@item thread apply [@var{thread-id-list} | all [-ascending]] @var{command}
839c27b7 3174The @code{thread apply} command allows you to apply the named
5d5658a1
PA
3175@var{command} to one or more threads. Specify the threads that you
3176want affected using the thread ID list syntax (@pxref{thread ID
3177lists}), or specify @code{all} to apply to all threads. To apply a
3178command to all threads in descending order, type @kbd{thread apply all
253828f1
JK
3179@var{command}}. To apply a command to all threads in ascending order,
3180type @kbd{thread apply all -ascending @var{command}}.
3181
93815fbf 3182
4694da01
TT
3183@kindex thread name
3184@cindex name a thread
3185@item thread name [@var{name}]
3186This command assigns a name to the current thread. If no argument is
3187given, any existing user-specified name is removed. The thread name
3188appears in the @samp{info threads} display.
3189
3190On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3191determine the name of the thread as given by the OS. On these
3192systems, a name specified with @samp{thread name} will override the
3193system-give name, and removing the user-specified name will cause
3194@value{GDBN} to once again display the system-specified name.
3195
60f98dde
MS
3196@kindex thread find
3197@cindex search for a thread
3198@item thread find [@var{regexp}]
3199Search for and display thread ids whose name or @var{systag}
3200matches the supplied regular expression.
3201
3202As well as being the complement to the @samp{thread name} command,
3203this command also allows you to identify a thread by its target
3204@var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3205is the LWP id.
3206
3207@smallexample
3208(@value{GDBN}) thread find 26688
3209Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3210(@value{GDBN}) info thread 4
3211 Id Target Id Frame
3212 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3213@end smallexample
3214
93815fbf
VP
3215@kindex set print thread-events
3216@cindex print messages on thread start and exit
3217@item set print thread-events
3218@itemx set print thread-events on
3219@itemx set print thread-events off
3220The @code{set print thread-events} command allows you to enable or
3221disable printing of messages when @value{GDBN} notices that new threads have
3222started or that threads have exited. By default, these messages will
3223be printed if detection of these events is supported by the target.
3224Note that these messages cannot be disabled on all targets.
3225
3226@kindex show print thread-events
3227@item show print thread-events
3228Show whether messages will be printed when @value{GDBN} detects that threads
3229have started and exited.
c906108c
SS
3230@end table
3231
79a6e687 3232@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
c906108c
SS
3233more information about how @value{GDBN} behaves when you stop and start
3234programs with multiple threads.
3235
79a6e687 3236@xref{Set Watchpoints,,Setting Watchpoints}, for information about
c906108c 3237watchpoints in programs with multiple threads.
c906108c 3238
bf88dd68 3239@anchor{set libthread-db-search-path}
17a37d48
PP
3240@table @code
3241@kindex set libthread-db-search-path
3242@cindex search path for @code{libthread_db}
3243@item set libthread-db-search-path @r{[}@var{path}@r{]}
3244If this variable is set, @var{path} is a colon-separated list of
3245directories @value{GDBN} will use to search for @code{libthread_db}.
3246If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
98a5dd13 3247its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
7e0396aa
DE
3248Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3249macro.
17a37d48
PP
3250
3251On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3252@code{libthread_db} library to obtain information about threads in the
3253inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
bf88dd68
JK
3254to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3255specific thread debugging library loading is enabled
3256by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3257
3258A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3259refers to the default system directories that are
bf88dd68
JK
3260normally searched for loading shared libraries. The @samp{$sdir} entry
3261is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3262(@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3263
3264A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3265refers to the directory from which @code{libpthread}
3266was loaded in the inferior process.
17a37d48
PP
3267
3268For any @code{libthread_db} library @value{GDBN} finds in above directories,
3269@value{GDBN} attempts to initialize it with the current inferior process.
3270If this initialization fails (which could happen because of a version
3271mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3272will unload @code{libthread_db}, and continue with the next directory.
3273If none of @code{libthread_db} libraries initialize successfully,
3274@value{GDBN} will issue a warning and thread debugging will be disabled.
3275
3276Setting @code{libthread-db-search-path} is currently implemented
3277only on some platforms.
3278
3279@kindex show libthread-db-search-path
3280@item show libthread-db-search-path
3281Display current libthread_db search path.
02d868e8
PP
3282
3283@kindex set debug libthread-db
3284@kindex show debug libthread-db
3285@cindex debugging @code{libthread_db}
3286@item set debug libthread-db
3287@itemx show debug libthread-db
3288Turns on or off display of @code{libthread_db}-related events.
3289Use @code{1} to enable, @code{0} to disable.
17a37d48
PP
3290@end table
3291
6c95b8df
PA
3292@node Forks
3293@section Debugging Forks
c906108c
SS
3294
3295@cindex fork, debugging programs which call
3296@cindex multiple processes
3297@cindex processes, multiple
53a5351d
JM
3298On most systems, @value{GDBN} has no special support for debugging
3299programs which create additional processes using the @code{fork}
3300function. When a program forks, @value{GDBN} will continue to debug the
3301parent process and the child process will run unimpeded. If you have
3302set a breakpoint in any code which the child then executes, the child
3303will get a @code{SIGTRAP} signal which (unless it catches the signal)
3304will cause it to terminate.
c906108c
SS
3305
3306However, if you want to debug the child process there is a workaround
3307which isn't too painful. Put a call to @code{sleep} in the code which
3308the child process executes after the fork. It may be useful to sleep
3309only if a certain environment variable is set, or a certain file exists,
3310so that the delay need not occur when you don't want to run @value{GDBN}
3311on the child. While the child is sleeping, use the @code{ps} program to
3312get its process ID. Then tell @value{GDBN} (a new invocation of
3313@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 3314the child process (@pxref{Attach}). From that point on you can debug
c906108c 3315the child process just like any other process which you attached to.
c906108c 3316
b1236ac3
PA
3317On some systems, @value{GDBN} provides support for debugging programs
3318that create additional processes using the @code{fork} or @code{vfork}
3319functions. On @sc{gnu}/Linux platforms, this feature is supported
19d9d4ef 3320with kernel version 2.5.46 and later.
c906108c 3321
19d9d4ef
DB
3322The fork debugging commands are supported in native mode and when
3323connected to @code{gdbserver} in either @code{target remote} mode or
3324@code{target extended-remote} mode.
0d71eef5 3325
c906108c
SS
3326By default, when a program forks, @value{GDBN} will continue to debug
3327the parent process and the child process will run unimpeded.
3328
3329If you want to follow the child process instead of the parent process,
3330use the command @w{@code{set follow-fork-mode}}.
3331
3332@table @code
3333@kindex set follow-fork-mode
3334@item set follow-fork-mode @var{mode}
3335Set the debugger response to a program call of @code{fork} or
3336@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 3337process. The @var{mode} argument can be:
c906108c
SS
3338
3339@table @code
3340@item parent
3341The original process is debugged after a fork. The child process runs
2df3850c 3342unimpeded. This is the default.
c906108c
SS
3343
3344@item child
3345The new process is debugged after a fork. The parent process runs
3346unimpeded.
3347
c906108c
SS
3348@end table
3349
9c16f35a 3350@kindex show follow-fork-mode
c906108c 3351@item show follow-fork-mode
2df3850c 3352Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
3353@end table
3354
5c95884b
MS
3355@cindex debugging multiple processes
3356On Linux, if you want to debug both the parent and child processes, use the
3357command @w{@code{set detach-on-fork}}.
3358
3359@table @code
3360@kindex set detach-on-fork
3361@item set detach-on-fork @var{mode}
3362Tells gdb whether to detach one of the processes after a fork, or
3363retain debugger control over them both.
3364
3365@table @code
3366@item on
3367The child process (or parent process, depending on the value of
3368@code{follow-fork-mode}) will be detached and allowed to run
3369independently. This is the default.
3370
3371@item off
3372Both processes will be held under the control of @value{GDBN}.
3373One process (child or parent, depending on the value of
3374@code{follow-fork-mode}) is debugged as usual, while the other
3375is held suspended.
3376
3377@end table
3378
11310833
NR
3379@kindex show detach-on-fork
3380@item show detach-on-fork
3381Show whether detach-on-fork mode is on/off.
5c95884b
MS
3382@end table
3383
2277426b
PA
3384If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3385will retain control of all forked processes (including nested forks).
3386You can list the forked processes under the control of @value{GDBN} by
3387using the @w{@code{info inferiors}} command, and switch from one fork
6c95b8df
PA
3388to another by using the @code{inferior} command (@pxref{Inferiors and
3389Programs, ,Debugging Multiple Inferiors and Programs}).
5c95884b
MS
3390
3391To quit debugging one of the forked processes, you can either detach
af624141
MS
3392from it by using the @w{@code{detach inferiors}} command (allowing it
3393to run independently), or kill it using the @w{@code{kill inferiors}}
6c95b8df
PA
3394command. @xref{Inferiors and Programs, ,Debugging Multiple Inferiors
3395and Programs}.
5c95884b 3396
c906108c
SS
3397If you ask to debug a child process and a @code{vfork} is followed by an
3398@code{exec}, @value{GDBN} executes the new target up to the first
3399breakpoint in the new target. If you have a breakpoint set on
3400@code{main} in your original program, the breakpoint will also be set on
3401the child process's @code{main}.
3402
2277426b
PA
3403On some systems, when a child process is spawned by @code{vfork}, you
3404cannot debug the child or parent until an @code{exec} call completes.
c906108c
SS
3405
3406If you issue a @code{run} command to @value{GDBN} after an @code{exec}
6c95b8df
PA
3407call executes, the new target restarts. To restart the parent
3408process, use the @code{file} command with the parent executable name
3409as its argument. By default, after an @code{exec} call executes,
3410@value{GDBN} discards the symbols of the previous executable image.
3411You can change this behaviour with the @w{@code{set follow-exec-mode}}
3412command.
3413
3414@table @code
3415@kindex set follow-exec-mode
3416@item set follow-exec-mode @var{mode}
3417
3418Set debugger response to a program call of @code{exec}. An
3419@code{exec} call replaces the program image of a process.
3420
3421@code{follow-exec-mode} can be:
3422
3423@table @code
3424@item new
3425@value{GDBN} creates a new inferior and rebinds the process to this
3426new inferior. The program the process was running before the
3427@code{exec} call can be restarted afterwards by restarting the
3428original inferior.
3429
3430For example:
3431
3432@smallexample
3433(@value{GDBP}) info inferiors
3434(gdb) info inferior
3435 Id Description Executable
3436* 1 <null> prog1
3437(@value{GDBP}) run
3438process 12020 is executing new program: prog2
3439Program exited normally.
3440(@value{GDBP}) info inferiors
3441 Id Description Executable
c0ecb95f 3442 1 <null> prog1
b05b1202 3443* 2 <null> prog2
6c95b8df
PA
3444@end smallexample
3445
3446@item same
3447@value{GDBN} keeps the process bound to the same inferior. The new
3448executable image replaces the previous executable loaded in the
3449inferior. Restarting the inferior after the @code{exec} call, with
3450e.g., the @code{run} command, restarts the executable the process was
3451running after the @code{exec} call. This is the default mode.
3452
3453For example:
3454
3455@smallexample
3456(@value{GDBP}) info inferiors
3457 Id Description Executable
3458* 1 <null> prog1
3459(@value{GDBP}) run
3460process 12020 is executing new program: prog2
3461Program exited normally.
3462(@value{GDBP}) info inferiors
3463 Id Description Executable
3464* 1 <null> prog2
3465@end smallexample
3466
3467@end table
3468@end table
c906108c 3469
19d9d4ef
DB
3470@code{follow-exec-mode} is supported in native mode and
3471@code{target extended-remote} mode.
3472
c906108c
SS
3473You can use the @code{catch} command to make @value{GDBN} stop whenever
3474a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
79a6e687 3475Catchpoints, ,Setting Catchpoints}.
c906108c 3476
5c95884b 3477@node Checkpoint/Restart
79a6e687 3478@section Setting a @emph{Bookmark} to Return to Later
5c95884b
MS
3479
3480@cindex checkpoint
3481@cindex restart
3482@cindex bookmark
3483@cindex snapshot of a process
3484@cindex rewind program state
3485
3486On certain operating systems@footnote{Currently, only
3487@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3488program's state, called a @dfn{checkpoint}, and come back to it
3489later.
3490
3491Returning to a checkpoint effectively undoes everything that has
3492happened in the program since the @code{checkpoint} was saved. This
3493includes changes in memory, registers, and even (within some limits)
3494system state. Effectively, it is like going back in time to the
3495moment when the checkpoint was saved.
3496
3497Thus, if you're stepping thru a program and you think you're
3498getting close to the point where things go wrong, you can save
3499a checkpoint. Then, if you accidentally go too far and miss
3500the critical statement, instead of having to restart your program
3501from the beginning, you can just go back to the checkpoint and
3502start again from there.
3503
3504This can be especially useful if it takes a lot of time or
3505steps to reach the point where you think the bug occurs.
3506
3507To use the @code{checkpoint}/@code{restart} method of debugging:
3508
3509@table @code
3510@kindex checkpoint
3511@item checkpoint
3512Save a snapshot of the debugged program's current execution state.
3513The @code{checkpoint} command takes no arguments, but each checkpoint
3514is assigned a small integer id, similar to a breakpoint id.
3515
3516@kindex info checkpoints
3517@item info checkpoints
3518List the checkpoints that have been saved in the current debugging
3519session. For each checkpoint, the following information will be
3520listed:
3521
3522@table @code
3523@item Checkpoint ID
3524@item Process ID
3525@item Code Address
3526@item Source line, or label
3527@end table
3528
3529@kindex restart @var{checkpoint-id}
3530@item restart @var{checkpoint-id}
3531Restore the program state that was saved as checkpoint number
3532@var{checkpoint-id}. All program variables, registers, stack frames
3533etc.@: will be returned to the values that they had when the checkpoint
3534was saved. In essence, gdb will ``wind back the clock'' to the point
3535in time when the checkpoint was saved.
3536
3537Note that breakpoints, @value{GDBN} variables, command history etc.
3538are not affected by restoring a checkpoint. In general, a checkpoint
3539only restores things that reside in the program being debugged, not in
3540the debugger.
3541
b8db102d
MS
3542@kindex delete checkpoint @var{checkpoint-id}
3543@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
3544Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
3545
3546@end table
3547
3548Returning to a previously saved checkpoint will restore the user state
3549of the program being debugged, plus a significant subset of the system
3550(OS) state, including file pointers. It won't ``un-write'' data from
3551a file, but it will rewind the file pointer to the previous location,
3552so that the previously written data can be overwritten. For files
3553opened in read mode, the pointer will also be restored so that the
3554previously read data can be read again.
3555
3556Of course, characters that have been sent to a printer (or other
3557external device) cannot be ``snatched back'', and characters received
3558from eg.@: a serial device can be removed from internal program buffers,
3559but they cannot be ``pushed back'' into the serial pipeline, ready to
3560be received again. Similarly, the actual contents of files that have
3561been changed cannot be restored (at this time).
3562
3563However, within those constraints, you actually can ``rewind'' your
3564program to a previously saved point in time, and begin debugging it
3565again --- and you can change the course of events so as to debug a
3566different execution path this time.
3567
3568@cindex checkpoints and process id
3569Finally, there is one bit of internal program state that will be
3570different when you return to a checkpoint --- the program's process
3571id. Each checkpoint will have a unique process id (or @var{pid}),
3572and each will be different from the program's original @var{pid}.
3573If your program has saved a local copy of its process id, this could
3574potentially pose a problem.
3575
79a6e687 3576@subsection A Non-obvious Benefit of Using Checkpoints
5c95884b
MS
3577
3578On some systems such as @sc{gnu}/Linux, address space randomization
3579is performed on new processes for security reasons. This makes it
3580difficult or impossible to set a breakpoint, or watchpoint, on an
3581absolute address if you have to restart the program, since the
3582absolute location of a symbol will change from one execution to the
3583next.
3584
3585A checkpoint, however, is an @emph{identical} copy of a process.
3586Therefore if you create a checkpoint at (eg.@:) the start of main,
3587and simply return to that checkpoint instead of restarting the
3588process, you can avoid the effects of address randomization and
3589your symbols will all stay in the same place.
3590
6d2ebf8b 3591@node Stopping
c906108c
SS
3592@chapter Stopping and Continuing
3593
3594The principal purposes of using a debugger are so that you can stop your
3595program before it terminates; or so that, if your program runs into
3596trouble, you can investigate and find out why.
3597
7a292a7a
SS
3598Inside @value{GDBN}, your program may stop for any of several reasons,
3599such as a signal, a breakpoint, or reaching a new line after a
3600@value{GDBN} command such as @code{step}. You may then examine and
3601change variables, set new breakpoints or remove old ones, and then
3602continue execution. Usually, the messages shown by @value{GDBN} provide
3603ample explanation of the status of your program---but you can also
3604explicitly request this information at any time.
c906108c
SS
3605
3606@table @code
3607@kindex info program
3608@item info program
3609Display information about the status of your program: whether it is
7a292a7a 3610running or not, what process it is, and why it stopped.
c906108c
SS
3611@end table
3612
3613@menu
3614* Breakpoints:: Breakpoints, watchpoints, and catchpoints
3615* Continuing and Stepping:: Resuming execution
aad1c02c
TT
3616* Skipping Over Functions and Files::
3617 Skipping over functions and files
c906108c 3618* Signals:: Signals
c906108c 3619* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
3620@end menu
3621
6d2ebf8b 3622@node Breakpoints
79a6e687 3623@section Breakpoints, Watchpoints, and Catchpoints
c906108c
SS
3624
3625@cindex breakpoints
3626A @dfn{breakpoint} makes your program stop whenever a certain point in
3627the program is reached. For each breakpoint, you can add conditions to
3628control in finer detail whether your program stops. You can set
3629breakpoints with the @code{break} command and its variants (@pxref{Set
79a6e687 3630Breaks, ,Setting Breakpoints}), to specify the place where your program
c906108c
SS
3631should stop by line number, function name or exact address in the
3632program.
3633
09d4efe1 3634On some systems, you can set breakpoints in shared libraries before
b1236ac3 3635the executable is run.
c906108c
SS
3636
3637@cindex watchpoints
fd60e0df 3638@cindex data breakpoints
c906108c
SS
3639@cindex memory tracing
3640@cindex breakpoint on memory address
3641@cindex breakpoint on variable modification
3642A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 3643when the value of an expression changes. The expression may be a value
0ced0c34 3644of a variable, or it could involve values of one or more variables
fd60e0df
EZ
3645combined by operators, such as @samp{a + b}. This is sometimes called
3646@dfn{data breakpoints}. You must use a different command to set
79a6e687 3647watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
fd60e0df
EZ
3648from that, you can manage a watchpoint like any other breakpoint: you
3649enable, disable, and delete both breakpoints and watchpoints using the
3650same commands.
c906108c
SS
3651
3652You can arrange to have values from your program displayed automatically
3653whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
79a6e687 3654Automatic Display}.
c906108c
SS
3655
3656@cindex catchpoints
3657@cindex breakpoint on events
3658A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 3659when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
3660exception or the loading of a library. As with watchpoints, you use a
3661different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
79a6e687 3662Catchpoints}), but aside from that, you can manage a catchpoint like any
c906108c 3663other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 3664@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
3665
3666@cindex breakpoint numbers
3667@cindex numbers for breakpoints
3668@value{GDBN} assigns a number to each breakpoint, watchpoint, or
3669catchpoint when you create it; these numbers are successive integers
3670starting with one. In many of the commands for controlling various
3671features of breakpoints you use the breakpoint number to say which
3672breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
3673@dfn{disabled}; if disabled, it has no effect on your program until you
3674enable it again.
3675
c5394b80 3676@cindex breakpoint ranges
18da0c51 3677@cindex breakpoint lists
c5394b80 3678@cindex ranges of breakpoints
18da0c51
MG
3679@cindex lists of breakpoints
3680Some @value{GDBN} commands accept a space-separated list of breakpoints
3681on which to operate. A list element can be either a single breakpoint number,
3682like @samp{5}, or a range of such numbers, like @samp{5-7}.
3683When a breakpoint list is given to a command, all breakpoints in that list
3684are operated on.
c5394b80 3685
c906108c
SS
3686@menu
3687* Set Breaks:: Setting breakpoints
3688* Set Watchpoints:: Setting watchpoints
3689* Set Catchpoints:: Setting catchpoints
3690* Delete Breaks:: Deleting breakpoints
3691* Disabling:: Disabling breakpoints
3692* Conditions:: Break conditions
3693* Break Commands:: Breakpoint command lists
e7e0cddf 3694* Dynamic Printf:: Dynamic printf
6149aea9 3695* Save Breakpoints:: How to save breakpoints in a file
62e5f89c 3696* Static Probe Points:: Listing static probe points
d4f3574e 3697* Error in Breakpoints:: ``Cannot insert breakpoints''
79a6e687 3698* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
c906108c
SS
3699@end menu
3700
6d2ebf8b 3701@node Set Breaks
79a6e687 3702@subsection Setting Breakpoints
c906108c 3703
5d161b24 3704@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
3705@c consider in particular declaration with/without initialization.
3706@c
3707@c FIXME 2 is there stuff on this already? break at fun start, already init?
3708
3709@kindex break
41afff9a
EZ
3710@kindex b @r{(@code{break})}
3711@vindex $bpnum@r{, convenience variable}
c906108c
SS
3712@cindex latest breakpoint
3713Breakpoints are set with the @code{break} command (abbreviated
5d161b24 3714@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 3715number of the breakpoint you've set most recently; see @ref{Convenience
79a6e687 3716Vars,, Convenience Variables}, for a discussion of what you can do with
c906108c
SS
3717convenience variables.
3718
c906108c 3719@table @code
2a25a5ba
EZ
3720@item break @var{location}
3721Set a breakpoint at the given @var{location}, which can specify a
3722function name, a line number, or an address of an instruction.
3723(@xref{Specify Location}, for a list of all the possible ways to
3724specify a @var{location}.) The breakpoint will stop your program just
3725before it executes any of the code in the specified @var{location}.
3726
c906108c 3727When using source languages that permit overloading of symbols, such as
2a25a5ba 3728C@t{++}, a function name may refer to more than one possible place to break.
6ba66d6a
JB
3729@xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
3730that situation.
c906108c 3731
45ac276d 3732It is also possible to insert a breakpoint that will stop the program
2c88c651
JB
3733only if a specific thread (@pxref{Thread-Specific Breakpoints})
3734or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
45ac276d 3735
c906108c
SS
3736@item break
3737When called without any arguments, @code{break} sets a breakpoint at
3738the next instruction to be executed in the selected stack frame
3739(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
3740innermost, this makes your program stop as soon as control
3741returns to that frame. This is similar to the effect of a
3742@code{finish} command in the frame inside the selected frame---except
3743that @code{finish} does not leave an active breakpoint. If you use
3744@code{break} without an argument in the innermost frame, @value{GDBN} stops
3745the next time it reaches the current location; this may be useful
3746inside loops.
3747
3748@value{GDBN} normally ignores breakpoints when it resumes execution, until at
3749least one instruction has been executed. If it did not do this, you
3750would be unable to proceed past a breakpoint without first disabling the
3751breakpoint. This rule applies whether or not the breakpoint already
3752existed when your program stopped.
3753
3754@item break @dots{} if @var{cond}
3755Set a breakpoint with condition @var{cond}; evaluate the expression
3756@var{cond} each time the breakpoint is reached, and stop only if the
3757value is nonzero---that is, if @var{cond} evaluates as true.
3758@samp{@dots{}} stands for one of the possible arguments described
3759above (or no argument) specifying where to break. @xref{Conditions,
79a6e687 3760,Break Conditions}, for more information on breakpoint conditions.
c906108c
SS
3761
3762@kindex tbreak
3763@item tbreak @var{args}
697aa1b7 3764Set a breakpoint enabled only for one stop. The @var{args} are the
c906108c
SS
3765same as for the @code{break} command, and the breakpoint is set in the same
3766way, but the breakpoint is automatically deleted after the first time your
79a6e687 3767program stops there. @xref{Disabling, ,Disabling Breakpoints}.
c906108c 3768
c906108c 3769@kindex hbreak
ba04e063 3770@cindex hardware breakpoints
c906108c 3771@item hbreak @var{args}
697aa1b7 3772Set a hardware-assisted breakpoint. The @var{args} are the same as for the
d4f3574e 3773@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
3774breakpoint requires hardware support and some target hardware may not
3775have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
3776debugging, so you can set a breakpoint at an instruction without
3777changing the instruction. This can be used with the new trap-generation
09d4efe1 3778provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
3779will generate traps when a program accesses some data or instruction
3780address that is assigned to the debug registers. However the hardware
3781breakpoint registers can take a limited number of breakpoints. For
3782example, on the DSU, only two data breakpoints can be set at a time, and
3783@value{GDBN} will reject this command if more than two are used. Delete
3784or disable unused hardware breakpoints before setting new ones
79a6e687
BW
3785(@pxref{Disabling, ,Disabling Breakpoints}).
3786@xref{Conditions, ,Break Conditions}.
9c16f35a
EZ
3787For remote targets, you can restrict the number of hardware
3788breakpoints @value{GDBN} will use, see @ref{set remote
3789hardware-breakpoint-limit}.
501eef12 3790
c906108c
SS
3791@kindex thbreak
3792@item thbreak @var{args}
697aa1b7 3793Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
c906108c 3794are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 3795the same way. However, like the @code{tbreak} command,
c906108c
SS
3796the breakpoint is automatically deleted after the
3797first time your program stops there. Also, like the @code{hbreak}
5d161b24 3798command, the breakpoint requires hardware support and some target hardware
79a6e687
BW
3799may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
3800See also @ref{Conditions, ,Break Conditions}.
c906108c
SS
3801
3802@kindex rbreak
3803@cindex regular expression
8bd10a10 3804@cindex breakpoints at functions matching a regexp
c45da7e6 3805@cindex set breakpoints in many functions
c906108c 3806@item rbreak @var{regex}
c906108c 3807Set breakpoints on all functions matching the regular expression
11cf8741
JM
3808@var{regex}. This command sets an unconditional breakpoint on all
3809matches, printing a list of all breakpoints it set. Once these
3810breakpoints are set, they are treated just like the breakpoints set with
3811the @code{break} command. You can delete them, disable them, or make
3812them conditional the same way as any other breakpoint.
3813
3814The syntax of the regular expression is the standard one used with tools
3815like @file{grep}. Note that this is different from the syntax used by
3816shells, so for instance @code{foo*} matches all functions that include
3817an @code{fo} followed by zero or more @code{o}s. There is an implicit
3818@code{.*} leading and trailing the regular expression you supply, so to
3819match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 3820
f7dc1244 3821@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 3822When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
3823breakpoints on overloaded functions that are not members of any special
3824classes.
c906108c 3825
f7dc1244
EZ
3826@cindex set breakpoints on all functions
3827The @code{rbreak} command can be used to set breakpoints in
3828@strong{all} the functions in a program, like this:
3829
3830@smallexample
3831(@value{GDBP}) rbreak .
3832@end smallexample
3833
8bd10a10
CM
3834@item rbreak @var{file}:@var{regex}
3835If @code{rbreak} is called with a filename qualification, it limits
3836the search for functions matching the given regular expression to the
3837specified @var{file}. This can be used, for example, to set breakpoints on
3838every function in a given file:
3839
3840@smallexample
3841(@value{GDBP}) rbreak file.c:.
3842@end smallexample
3843
3844The colon separating the filename qualifier from the regex may
3845optionally be surrounded by spaces.
3846
c906108c
SS
3847@kindex info breakpoints
3848@cindex @code{$_} and @code{info breakpoints}
18da0c51
MG
3849@item info breakpoints @r{[}@var{list}@dots{}@r{]}
3850@itemx info break @r{[}@var{list}@dots{}@r{]}
c906108c 3851Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734 3852not deleted. Optional argument @var{n} means print information only
e5a67952
MS
3853about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
3854For each breakpoint, following columns are printed:
c906108c
SS
3855
3856@table @emph
3857@item Breakpoint Numbers
3858@item Type
3859Breakpoint, watchpoint, or catchpoint.
3860@item Disposition
3861Whether the breakpoint is marked to be disabled or deleted when hit.
3862@item Enabled or Disabled
3863Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
b3db7447 3864that are not enabled.
c906108c 3865@item Address
fe6fbf8b 3866Where the breakpoint is in your program, as a memory address. For a
b3db7447
NR
3867pending breakpoint whose address is not yet known, this field will
3868contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
3869library that has the symbol or line referred by breakpoint is loaded.
3870See below for details. A breakpoint with several locations will
3b784c4f 3871have @samp{<MULTIPLE>} in this field---see below for details.
c906108c
SS
3872@item What
3873Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
3874line number. For a pending breakpoint, the original string passed to
3875the breakpoint command will be listed as it cannot be resolved until
3876the appropriate shared library is loaded in the future.
c906108c
SS
3877@end table
3878
3879@noindent
83364271
LM
3880If a breakpoint is conditional, there are two evaluation modes: ``host'' and
3881``target''. If mode is ``host'', breakpoint condition evaluation is done by
3882@value{GDBN} on the host's side. If it is ``target'', then the condition
3883is evaluated by the target. The @code{info break} command shows
3884the condition on the line following the affected breakpoint, together with
3885its condition evaluation mode in between parentheses.
3886
3887Breakpoint commands, if any, are listed after that. A pending breakpoint is
3888allowed to have a condition specified for it. The condition is not parsed for
3889validity until a shared library is loaded that allows the pending
3890breakpoint to resolve to a valid location.
c906108c
SS
3891
3892@noindent
3893@code{info break} with a breakpoint
3894number @var{n} as argument lists only that breakpoint. The
3895convenience variable @code{$_} and the default examining-address for
3896the @code{x} command are set to the address of the last breakpoint
79a6e687 3897listed (@pxref{Memory, ,Examining Memory}).
c906108c
SS
3898
3899@noindent
3900@code{info break} displays a count of the number of times the breakpoint
3901has been hit. This is especially useful in conjunction with the
3902@code{ignore} command. You can ignore a large number of breakpoint
3903hits, look at the breakpoint info to see how many times the breakpoint
3904was hit, and then run again, ignoring one less than that number. This
3905will get you quickly to the last hit of that breakpoint.
816338b5
SS
3906
3907@noindent
3908For a breakpoints with an enable count (xref) greater than 1,
3909@code{info break} also displays that count.
3910
c906108c
SS
3911@end table
3912
3913@value{GDBN} allows you to set any number of breakpoints at the same place in
3914your program. There is nothing silly or meaningless about this. When
3915the breakpoints are conditional, this is even useful
79a6e687 3916(@pxref{Conditions, ,Break Conditions}).
c906108c 3917
2e9132cc
EZ
3918@cindex multiple locations, breakpoints
3919@cindex breakpoints, multiple locations
fcda367b 3920It is possible that a breakpoint corresponds to several locations
fe6fbf8b
VP
3921in your program. Examples of this situation are:
3922
3923@itemize @bullet
f8eba3c6
TT
3924@item
3925Multiple functions in the program may have the same name.
3926
fe6fbf8b
VP
3927@item
3928For a C@t{++} constructor, the @value{NGCC} compiler generates several
3929instances of the function body, used in different cases.
3930
3931@item
3932For a C@t{++} template function, a given line in the function can
3933correspond to any number of instantiations.
3934
3935@item
3936For an inlined function, a given source line can correspond to
3937several places where that function is inlined.
fe6fbf8b
VP
3938@end itemize
3939
3940In all those cases, @value{GDBN} will insert a breakpoint at all
f8eba3c6 3941the relevant locations.
fe6fbf8b 3942
3b784c4f
EZ
3943A breakpoint with multiple locations is displayed in the breakpoint
3944table using several rows---one header row, followed by one row for
3945each breakpoint location. The header row has @samp{<MULTIPLE>} in the
3946address column. The rows for individual locations contain the actual
3947addresses for locations, and show the functions to which those
3948locations belong. The number column for a location is of the form
fe6fbf8b
VP
3949@var{breakpoint-number}.@var{location-number}.
3950
3951For example:
3b784c4f 3952
fe6fbf8b
VP
3953@smallexample
3954Num Type Disp Enb Address What
39551 breakpoint keep y <MULTIPLE>
3956 stop only if i==1
3957 breakpoint already hit 1 time
39581.1 y 0x080486a2 in void foo<int>() at t.cc:8
39591.2 y 0x080486ca in void foo<double>() at t.cc:8
3960@end smallexample
3961
d0fe4701
XR
3962You cannot delete the individual locations from a breakpoint. However,
3963each location can be individually enabled or disabled by passing
fe6fbf8b 3964@var{breakpoint-number}.@var{location-number} as argument to the
d0fe4701
XR
3965@code{enable} and @code{disable} commands. It's also possible to
3966@code{enable} and @code{disable} a range of @var{location-number}
3967locations using a @var{breakpoint-number} and two @var{location-number}s,
3968in increasing order, separated by a hyphen, like
3969@kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
3970in which case @value{GDBN} acts on all the locations in the range (inclusive).
3971Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
3972all of the locations that belong to that breakpoint.
fe6fbf8b 3973
2650777c 3974@cindex pending breakpoints
fe6fbf8b 3975It's quite common to have a breakpoint inside a shared library.
3b784c4f 3976Shared libraries can be loaded and unloaded explicitly,
fe6fbf8b
VP
3977and possibly repeatedly, as the program is executed. To support
3978this use case, @value{GDBN} updates breakpoint locations whenever
3979any shared library is loaded or unloaded. Typically, you would
fcda367b 3980set a breakpoint in a shared library at the beginning of your
fe6fbf8b
VP
3981debugging session, when the library is not loaded, and when the
3982symbols from the library are not available. When you try to set
3983breakpoint, @value{GDBN} will ask you if you want to set
3b784c4f 3984a so called @dfn{pending breakpoint}---breakpoint whose address
fe6fbf8b
VP
3985is not yet resolved.
3986
3987After the program is run, whenever a new shared library is loaded,
3988@value{GDBN} reevaluates all the breakpoints. When a newly loaded
3989shared library contains the symbol or line referred to by some
3990pending breakpoint, that breakpoint is resolved and becomes an
3991ordinary breakpoint. When a library is unloaded, all breakpoints
3992that refer to its symbols or source lines become pending again.
3993
3994This logic works for breakpoints with multiple locations, too. For
3995example, if you have a breakpoint in a C@t{++} template function, and
3996a newly loaded shared library has an instantiation of that template,
3997a new location is added to the list of locations for the breakpoint.
3998
3999Except for having unresolved address, pending breakpoints do not
4000differ from regular breakpoints. You can set conditions or commands,
4001enable and disable them and perform other breakpoint operations.
4002
4003@value{GDBN} provides some additional commands for controlling what
4004happens when the @samp{break} command cannot resolve breakpoint
4005address specification to an address:
dd79a6cf
JJ
4006
4007@kindex set breakpoint pending
4008@kindex show breakpoint pending
4009@table @code
4010@item set breakpoint pending auto
4011This is the default behavior. When @value{GDBN} cannot find the breakpoint
4012location, it queries you whether a pending breakpoint should be created.
4013
4014@item set breakpoint pending on
4015This indicates that an unrecognized breakpoint location should automatically
4016result in a pending breakpoint being created.
4017
4018@item set breakpoint pending off
4019This indicates that pending breakpoints are not to be created. Any
4020unrecognized breakpoint location results in an error. This setting does
4021not affect any pending breakpoints previously created.
4022
4023@item show breakpoint pending
4024Show the current behavior setting for creating pending breakpoints.
4025@end table
2650777c 4026
fe6fbf8b
VP
4027The settings above only affect the @code{break} command and its
4028variants. Once breakpoint is set, it will be automatically updated
4029as shared libraries are loaded and unloaded.
2650777c 4030
765dc015
VP
4031@cindex automatic hardware breakpoints
4032For some targets, @value{GDBN} can automatically decide if hardware or
4033software breakpoints should be used, depending on whether the
4034breakpoint address is read-only or read-write. This applies to
4035breakpoints set with the @code{break} command as well as to internal
4036breakpoints set by commands like @code{next} and @code{finish}. For
fcda367b 4037breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
765dc015
VP
4038breakpoints.
4039
18da0c51 4040You can control this automatic behaviour with the following commands:
765dc015
VP
4041
4042@kindex set breakpoint auto-hw
4043@kindex show breakpoint auto-hw
4044@table @code
4045@item set breakpoint auto-hw on
4046This is the default behavior. When @value{GDBN} sets a breakpoint, it
4047will try to use the target memory map to decide if software or hardware
4048breakpoint must be used.
4049
4050@item set breakpoint auto-hw off
4051This indicates @value{GDBN} should not automatically select breakpoint
4052type. If the target provides a memory map, @value{GDBN} will warn when
4053trying to set software breakpoint at a read-only address.
4054@end table
4055
74960c60
VP
4056@value{GDBN} normally implements breakpoints by replacing the program code
4057at the breakpoint address with a special instruction, which, when
4058executed, given control to the debugger. By default, the program
4059code is so modified only when the program is resumed. As soon as
4060the program stops, @value{GDBN} restores the original instructions. This
4061behaviour guards against leaving breakpoints inserted in the
4062target should gdb abrubptly disconnect. However, with slow remote
4063targets, inserting and removing breakpoint can reduce the performance.
4064This behavior can be controlled with the following commands::
4065
4066@kindex set breakpoint always-inserted
4067@kindex show breakpoint always-inserted
4068@table @code
4069@item set breakpoint always-inserted off
33e5cbd6
PA
4070All breakpoints, including newly added by the user, are inserted in
4071the target only when the target is resumed. All breakpoints are
a25a5a45 4072removed from the target when it stops. This is the default mode.
74960c60
VP
4073
4074@item set breakpoint always-inserted on
4075Causes all breakpoints to be inserted in the target at all times. If
4076the user adds a new breakpoint, or changes an existing breakpoint, the
4077breakpoints in the target are updated immediately. A breakpoint is
a25a5a45 4078removed from the target only when breakpoint itself is deleted.
342cc091 4079@end table
765dc015 4080
83364271
LM
4081@value{GDBN} handles conditional breakpoints by evaluating these conditions
4082when a breakpoint breaks. If the condition is true, then the process being
4083debugged stops, otherwise the process is resumed.
4084
4085If the target supports evaluating conditions on its end, @value{GDBN} may
4086download the breakpoint, together with its conditions, to it.
4087
4088This feature can be controlled via the following commands:
4089
4090@kindex set breakpoint condition-evaluation
4091@kindex show breakpoint condition-evaluation
4092@table @code
4093@item set breakpoint condition-evaluation host
4094This option commands @value{GDBN} to evaluate the breakpoint
4095conditions on the host's side. Unconditional breakpoints are sent to
4096the target which in turn receives the triggers and reports them back to GDB
4097for condition evaluation. This is the standard evaluation mode.
4098
4099@item set breakpoint condition-evaluation target
4100This option commands @value{GDBN} to download breakpoint conditions
4101to the target at the moment of their insertion. The target
4102is responsible for evaluating the conditional expression and reporting
4103breakpoint stop events back to @value{GDBN} whenever the condition
4104is true. Due to limitations of target-side evaluation, some conditions
4105cannot be evaluated there, e.g., conditions that depend on local data
4106that is only known to the host. Examples include
4107conditional expressions involving convenience variables, complex types
4108that cannot be handled by the agent expression parser and expressions
4109that are too long to be sent over to the target, specially when the
4110target is a remote system. In these cases, the conditions will be
4111evaluated by @value{GDBN}.
4112
4113@item set breakpoint condition-evaluation auto
4114This is the default mode. If the target supports evaluating breakpoint
4115conditions on its end, @value{GDBN} will download breakpoint conditions to
4116the target (limitations mentioned previously apply). If the target does
4117not support breakpoint condition evaluation, then @value{GDBN} will fallback
4118to evaluating all these conditions on the host's side.
4119@end table
4120
4121
c906108c
SS
4122@cindex negative breakpoint numbers
4123@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
4124@value{GDBN} itself sometimes sets breakpoints in your program for
4125special purposes, such as proper handling of @code{longjmp} (in C
4126programs). These internal breakpoints are assigned negative numbers,
4127starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 4128You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 4129@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
4130
4131
6d2ebf8b 4132@node Set Watchpoints
79a6e687 4133@subsection Setting Watchpoints
c906108c
SS
4134
4135@cindex setting watchpoints
c906108c
SS
4136You can use a watchpoint to stop execution whenever the value of an
4137expression changes, without having to predict a particular place where
fd60e0df
EZ
4138this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4139The expression may be as simple as the value of a single variable, or
4140as complex as many variables combined by operators. Examples include:
4141
4142@itemize @bullet
4143@item
4144A reference to the value of a single variable.
4145
4146@item
4147An address cast to an appropriate data type. For example,
4148@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4149address (assuming an @code{int} occupies 4 bytes).
4150
4151@item
4152An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4153expression can use any operators valid in the program's native
4154language (@pxref{Languages}).
4155@end itemize
c906108c 4156
fa4727a6
DJ
4157You can set a watchpoint on an expression even if the expression can
4158not be evaluated yet. For instance, you can set a watchpoint on
4159@samp{*global_ptr} before @samp{global_ptr} is initialized.
4160@value{GDBN} will stop when your program sets @samp{global_ptr} and
4161the expression produces a valid value. If the expression becomes
4162valid in some other way than changing a variable (e.g.@: if the memory
4163pointed to by @samp{*global_ptr} becomes readable as the result of a
4164@code{malloc} call), @value{GDBN} may not stop until the next time
4165the expression changes.
4166
82f2d802
EZ
4167@cindex software watchpoints
4168@cindex hardware watchpoints
c906108c 4169Depending on your system, watchpoints may be implemented in software or
2df3850c 4170hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
4171program and testing the variable's value each time, which is hundreds of
4172times slower than normal execution. (But this may still be worth it, to
4173catch errors where you have no clue what part of your program is the
4174culprit.)
4175
b1236ac3
PA
4176On some systems, such as most PowerPC or x86-based targets,
4177@value{GDBN} includes support for hardware watchpoints, which do not
4178slow down the running of your program.
c906108c
SS
4179
4180@table @code
4181@kindex watch
5d5658a1 4182@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
fd60e0df
EZ
4183Set a watchpoint for an expression. @value{GDBN} will break when the
4184expression @var{expr} is written into by the program and its value
4185changes. The simplest (and the most popular) use of this command is
4186to watch the value of a single variable:
4187
4188@smallexample
4189(@value{GDBP}) watch foo
4190@end smallexample
c906108c 4191
5d5658a1 4192If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
9c06b0b4 4193argument, @value{GDBN} breaks only when the thread identified by
5d5658a1 4194@var{thread-id} changes the value of @var{expr}. If any other threads
d8b2a693
JB
4195change the value of @var{expr}, @value{GDBN} will not break. Note
4196that watchpoints restricted to a single thread in this way only work
4197with Hardware Watchpoints.
4198
06a64a0b
TT
4199Ordinarily a watchpoint respects the scope of variables in @var{expr}
4200(see below). The @code{-location} argument tells @value{GDBN} to
4201instead watch the memory referred to by @var{expr}. In this case,
4202@value{GDBN} will evaluate @var{expr}, take the address of the result,
4203and watch the memory at that address. The type of the result is used
4204to determine the size of the watched memory. If the expression's
4205result does not have an address, then @value{GDBN} will print an
4206error.
4207
9c06b0b4
TJB
4208The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4209of masked watchpoints, if the current architecture supports this
4210feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4211Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4212to an address to watch. The mask specifies that some bits of an address
4213(the bits which are reset in the mask) should be ignored when matching
4214the address accessed by the inferior against the watchpoint address.
4215Thus, a masked watchpoint watches many addresses simultaneously---those
4216addresses whose unmasked bits are identical to the unmasked bits in the
4217watchpoint address. The @code{mask} argument implies @code{-location}.
4218Examples:
4219
4220@smallexample
4221(@value{GDBP}) watch foo mask 0xffff00ff
4222(@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4223@end smallexample
4224
c906108c 4225@kindex rwatch
5d5658a1 4226@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4227Set a watchpoint that will break when the value of @var{expr} is read
4228by the program.
c906108c
SS
4229
4230@kindex awatch
5d5658a1 4231@item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4232Set a watchpoint that will break when @var{expr} is either read from
4233or written into by the program.
c906108c 4234
18da0c51
MG
4235@kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4236@item info watchpoints @r{[}@var{list}@dots{}@r{]}
d77f58be
SS
4237This command prints a list of watchpoints, using the same format as
4238@code{info break} (@pxref{Set Breaks}).
c906108c
SS
4239@end table
4240
65d79d4b
SDJ
4241If you watch for a change in a numerically entered address you need to
4242dereference it, as the address itself is just a constant number which will
4243never change. @value{GDBN} refuses to create a watchpoint that watches
4244a never-changing value:
4245
4246@smallexample
4247(@value{GDBP}) watch 0x600850
4248Cannot watch constant value 0x600850.
4249(@value{GDBP}) watch *(int *) 0x600850
4250Watchpoint 1: *(int *) 6293584
4251@end smallexample
4252
c906108c
SS
4253@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4254watchpoints execute very quickly, and the debugger reports a change in
4255value at the exact instruction where the change occurs. If @value{GDBN}
4256cannot set a hardware watchpoint, it sets a software watchpoint, which
4257executes more slowly and reports the change in value at the next
82f2d802
EZ
4258@emph{statement}, not the instruction, after the change occurs.
4259
82f2d802
EZ
4260@cindex use only software watchpoints
4261You can force @value{GDBN} to use only software watchpoints with the
4262@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4263zero, @value{GDBN} will never try to use hardware watchpoints, even if
4264the underlying system supports them. (Note that hardware-assisted
4265watchpoints that were set @emph{before} setting
4266@code{can-use-hw-watchpoints} to zero will still use the hardware
d3e8051b 4267mechanism of watching expression values.)
c906108c 4268
9c16f35a
EZ
4269@table @code
4270@item set can-use-hw-watchpoints
4271@kindex set can-use-hw-watchpoints
4272Set whether or not to use hardware watchpoints.
4273
4274@item show can-use-hw-watchpoints
4275@kindex show can-use-hw-watchpoints
4276Show the current mode of using hardware watchpoints.
4277@end table
4278
4279For remote targets, you can restrict the number of hardware
4280watchpoints @value{GDBN} will use, see @ref{set remote
4281hardware-breakpoint-limit}.
4282
c906108c
SS
4283When you issue the @code{watch} command, @value{GDBN} reports
4284
474c8240 4285@smallexample
c906108c 4286Hardware watchpoint @var{num}: @var{expr}
474c8240 4287@end smallexample
c906108c
SS
4288
4289@noindent
4290if it was able to set a hardware watchpoint.
4291
7be570e7
JM
4292Currently, the @code{awatch} and @code{rwatch} commands can only set
4293hardware watchpoints, because accesses to data that don't change the
4294value of the watched expression cannot be detected without examining
4295every instruction as it is being executed, and @value{GDBN} does not do
4296that currently. If @value{GDBN} finds that it is unable to set a
4297hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4298will print a message like this:
4299
4300@smallexample
4301Expression cannot be implemented with read/access watchpoint.
4302@end smallexample
4303
4304Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4305data type of the watched expression is wider than what a hardware
4306watchpoint on the target machine can handle. For example, some systems
4307can only watch regions that are up to 4 bytes wide; on such systems you
4308cannot set hardware watchpoints for an expression that yields a
4309double-precision floating-point number (which is typically 8 bytes
4310wide). As a work-around, it might be possible to break the large region
4311into a series of smaller ones and watch them with separate watchpoints.
4312
4313If you set too many hardware watchpoints, @value{GDBN} might be unable
4314to insert all of them when you resume the execution of your program.
4315Since the precise number of active watchpoints is unknown until such
4316time as the program is about to be resumed, @value{GDBN} might not be
4317able to warn you about this when you set the watchpoints, and the
4318warning will be printed only when the program is resumed:
4319
4320@smallexample
4321Hardware watchpoint @var{num}: Could not insert watchpoint
4322@end smallexample
4323
4324@noindent
4325If this happens, delete or disable some of the watchpoints.
4326
fd60e0df
EZ
4327Watching complex expressions that reference many variables can also
4328exhaust the resources available for hardware-assisted watchpoints.
4329That's because @value{GDBN} needs to watch every variable in the
4330expression with separately allocated resources.
4331
c906108c 4332If you call a function interactively using @code{print} or @code{call},
2df3850c 4333any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
4334kind of breakpoint or the call completes.
4335
7be570e7
JM
4336@value{GDBN} automatically deletes watchpoints that watch local
4337(automatic) variables, or expressions that involve such variables, when
4338they go out of scope, that is, when the execution leaves the block in
4339which these variables were defined. In particular, when the program
4340being debugged terminates, @emph{all} local variables go out of scope,
4341and so only watchpoints that watch global variables remain set. If you
4342rerun the program, you will need to set all such watchpoints again. One
4343way of doing that would be to set a code breakpoint at the entry to the
4344@code{main} function and when it breaks, set all the watchpoints.
4345
c906108c
SS
4346@cindex watchpoints and threads
4347@cindex threads and watchpoints
d983da9c
DJ
4348In multi-threaded programs, watchpoints will detect changes to the
4349watched expression from every thread.
4350
4351@quotation
4352@emph{Warning:} In multi-threaded programs, software watchpoints
53a5351d
JM
4353have only limited usefulness. If @value{GDBN} creates a software
4354watchpoint, it can only watch the value of an expression @emph{in a
4355single thread}. If you are confident that the expression can only
4356change due to the current thread's activity (and if you are also
4357confident that no other thread can become current), then you can use
4358software watchpoints as usual. However, @value{GDBN} may not notice
4359when a non-current thread's activity changes the expression. (Hardware
4360watchpoints, in contrast, watch an expression in all threads.)
c906108c 4361@end quotation
c906108c 4362
501eef12
AC
4363@xref{set remote hardware-watchpoint-limit}.
4364
6d2ebf8b 4365@node Set Catchpoints
79a6e687 4366@subsection Setting Catchpoints
d4f3574e 4367@cindex catchpoints, setting
c906108c
SS
4368@cindex exception handlers
4369@cindex event handling
4370
4371You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 4372kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
4373shared library. Use the @code{catch} command to set a catchpoint.
4374
4375@table @code
4376@kindex catch
4377@item catch @var{event}
697aa1b7 4378Stop when @var{event} occurs. The @var{event} can be any of the following:
591f19e8 4379
c906108c 4380@table @code
cc16e6c9
TT
4381@item throw @r{[}@var{regexp}@r{]}
4382@itemx rethrow @r{[}@var{regexp}@r{]}
4383@itemx catch @r{[}@var{regexp}@r{]}
1a4f73eb
TT
4384@kindex catch throw
4385@kindex catch rethrow
4386@kindex catch catch
4644b6e3 4387@cindex stop on C@t{++} exceptions
591f19e8
TT
4388The throwing, re-throwing, or catching of a C@t{++} exception.
4389
cc16e6c9
TT
4390If @var{regexp} is given, then only exceptions whose type matches the
4391regular expression will be caught.
4392
72f1fe8a
TT
4393@vindex $_exception@r{, convenience variable}
4394The convenience variable @code{$_exception} is available at an
4395exception-related catchpoint, on some systems. This holds the
4396exception being thrown.
4397
591f19e8
TT
4398There are currently some limitations to C@t{++} exception handling in
4399@value{GDBN}:
c906108c 4400
591f19e8
TT
4401@itemize @bullet
4402@item
4403The support for these commands is system-dependent. Currently, only
4404systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
4405supported.
4406
72f1fe8a 4407@item
cc16e6c9
TT
4408The regular expression feature and the @code{$_exception} convenience
4409variable rely on the presence of some SDT probes in @code{libstdc++}.
4410If these probes are not present, then these features cannot be used.
dee368d3
TT
4411These probes were first available in the GCC 4.8 release, but whether
4412or not they are available in your GCC also depends on how it was
4413built.
72f1fe8a
TT
4414
4415@item
4416The @code{$_exception} convenience variable is only valid at the
4417instruction at which an exception-related catchpoint is set.
4418
591f19e8
TT
4419@item
4420When an exception-related catchpoint is hit, @value{GDBN} stops at a
4421location in the system library which implements runtime exception
4422support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
4423(@pxref{Selection}) to get to your code.
4424
4425@item
4426If you call a function interactively, @value{GDBN} normally returns
4427control to you when the function has finished executing. If the call
4428raises an exception, however, the call may bypass the mechanism that
4429returns control to you and cause your program either to abort or to
4430simply continue running until it hits a breakpoint, catches a signal
4431that @value{GDBN} is listening for, or exits. This is the case even if
4432you set a catchpoint for the exception; catchpoints on exceptions are
4433disabled within interactive calls. @xref{Calling}, for information on
4434controlling this with @code{set unwind-on-terminating-exception}.
4435
4436@item
4437You cannot raise an exception interactively.
4438
4439@item
4440You cannot install an exception handler interactively.
4441@end itemize
c906108c 4442
8936fcda 4443@item exception
1a4f73eb 4444@kindex catch exception
8936fcda
JB
4445@cindex Ada exception catching
4446@cindex catch Ada exceptions
4447An Ada exception being raised. If an exception name is specified
4448at the end of the command (eg @code{catch exception Program_Error}),
4449the debugger will stop only when this specific exception is raised.
4450Otherwise, the debugger stops execution when any Ada exception is raised.
4451
87f67dba
JB
4452When inserting an exception catchpoint on a user-defined exception whose
4453name is identical to one of the exceptions defined by the language, the
4454fully qualified name must be used as the exception name. Otherwise,
4455@value{GDBN} will assume that it should stop on the pre-defined exception
4456rather than the user-defined one. For instance, assuming an exception
4457called @code{Constraint_Error} is defined in package @code{Pck}, then
4458the command to use to catch such exceptions is @kbd{catch exception
4459Pck.Constraint_Error}.
4460
9f757bf7
XR
4461@item handlers
4462@kindex catch handlers
4463@cindex Ada exception handlers catching
4464@cindex catch Ada exceptions when handled
4465An Ada exception being handled. If an exception name is
4466specified at the end of the command
4467 (eg @kbd{catch handlers Program_Error}), the debugger will stop
4468only when this specific exception is handled.
4469Otherwise, the debugger stops execution when any Ada exception is handled.
4470
4471When inserting a handlers catchpoint on a user-defined
4472exception whose name is identical to one of the exceptions
4473defined by the language, the fully qualified name must be used
4474as the exception name. Otherwise, @value{GDBN} will assume that it
4475should stop on the pre-defined exception rather than the
4476user-defined one. For instance, assuming an exception called
4477 @code{Constraint_Error} is defined in package @code{Pck}, then the
4478command to use to catch such exceptions handling is
4479@kbd{catch handlers Pck.Constraint_Error}.
4480
8936fcda 4481@item exception unhandled
1a4f73eb 4482@kindex catch exception unhandled
8936fcda
JB
4483An exception that was raised but is not handled by the program.
4484
4485@item assert
1a4f73eb 4486@kindex catch assert
8936fcda
JB
4487A failed Ada assertion.
4488
c906108c 4489@item exec
1a4f73eb 4490@kindex catch exec
4644b6e3 4491@cindex break on fork/exec
b1236ac3 4492A call to @code{exec}.
c906108c 4493
a96d9b2e 4494@item syscall
e3487908 4495@itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
1a4f73eb 4496@kindex catch syscall
a96d9b2e
SDJ
4497@cindex break on a system call.
4498A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
4499syscall is a mechanism for application programs to request a service
4500from the operating system (OS) or one of the OS system services.
4501@value{GDBN} can catch some or all of the syscalls issued by the
4502debuggee, and show the related information for each syscall. If no
4503argument is specified, calls to and returns from all system calls
4504will be caught.
4505
4506@var{name} can be any system call name that is valid for the
4507underlying OS. Just what syscalls are valid depends on the OS. On
4508GNU and Unix systems, you can find the full list of valid syscall
4509names on @file{/usr/include/asm/unistd.h}.
4510
4511@c For MS-Windows, the syscall names and the corresponding numbers
4512@c can be found, e.g., on this URL:
4513@c http://www.metasploit.com/users/opcode/syscalls.html
4514@c but we don't support Windows syscalls yet.
4515
4516Normally, @value{GDBN} knows in advance which syscalls are valid for
4517each OS, so you can use the @value{GDBN} command-line completion
4518facilities (@pxref{Completion,, command completion}) to list the
4519available choices.
4520
4521You may also specify the system call numerically. A syscall's
4522number is the value passed to the OS's syscall dispatcher to
4523identify the requested service. When you specify the syscall by its
4524name, @value{GDBN} uses its database of syscalls to convert the name
4525into the corresponding numeric code, but using the number directly
4526may be useful if @value{GDBN}'s database does not have the complete
4527list of syscalls on your system (e.g., because @value{GDBN} lags
4528behind the OS upgrades).
4529
e3487908
GKB
4530You may specify a group of related syscalls to be caught at once using
4531the @code{group:} syntax (@code{g:} is a shorter equivalent). For
4532instance, on some platforms @value{GDBN} allows you to catch all
4533network related syscalls, by passing the argument @code{group:network}
4534to @code{catch syscall}. Note that not all syscall groups are
4535available in every system. You can use the command completion
4536facilities (@pxref{Completion,, command completion}) to list the
4537syscall groups available on your environment.
4538
a96d9b2e
SDJ
4539The example below illustrates how this command works if you don't provide
4540arguments to it:
4541
4542@smallexample
4543(@value{GDBP}) catch syscall
4544Catchpoint 1 (syscall)
4545(@value{GDBP}) r
4546Starting program: /tmp/catch-syscall
4547
4548Catchpoint 1 (call to syscall 'close'), \
4549 0xffffe424 in __kernel_vsyscall ()
4550(@value{GDBP}) c
4551Continuing.
4552
4553Catchpoint 1 (returned from syscall 'close'), \
4554 0xffffe424 in __kernel_vsyscall ()
4555(@value{GDBP})
4556@end smallexample
4557
4558Here is an example of catching a system call by name:
4559
4560@smallexample
4561(@value{GDBP}) catch syscall chroot
4562Catchpoint 1 (syscall 'chroot' [61])
4563(@value{GDBP}) r
4564Starting program: /tmp/catch-syscall
4565
4566Catchpoint 1 (call to syscall 'chroot'), \
4567 0xffffe424 in __kernel_vsyscall ()
4568(@value{GDBP}) c
4569Continuing.
4570
4571Catchpoint 1 (returned from syscall 'chroot'), \
4572 0xffffe424 in __kernel_vsyscall ()
4573(@value{GDBP})
4574@end smallexample
4575
4576An example of specifying a system call numerically. In the case
4577below, the syscall number has a corresponding entry in the XML
4578file, so @value{GDBN} finds its name and prints it:
4579
4580@smallexample
4581(@value{GDBP}) catch syscall 252
4582Catchpoint 1 (syscall(s) 'exit_group')
4583(@value{GDBP}) r
4584Starting program: /tmp/catch-syscall
4585
4586Catchpoint 1 (call to syscall 'exit_group'), \
4587 0xffffe424 in __kernel_vsyscall ()
4588(@value{GDBP}) c
4589Continuing.
4590
4591Program exited normally.
4592(@value{GDBP})
4593@end smallexample
4594
e3487908
GKB
4595Here is an example of catching a syscall group:
4596
4597@smallexample
4598(@value{GDBP}) catch syscall group:process
4599Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
4600'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
4601'exit_group' [252] 'waitid' [284] 'unshare' [310])
4602(@value{GDBP}) r
4603Starting program: /tmp/catch-syscall
4604
4605Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
4606 from /lib64/ld-linux-x86-64.so.2
4607
4608(@value{GDBP}) c
4609Continuing.
4610@end smallexample
4611
a96d9b2e
SDJ
4612However, there can be situations when there is no corresponding name
4613in XML file for that syscall number. In this case, @value{GDBN} prints
4614a warning message saying that it was not able to find the syscall name,
4615but the catchpoint will be set anyway. See the example below:
4616
4617@smallexample
4618(@value{GDBP}) catch syscall 764
4619warning: The number '764' does not represent a known syscall.
4620Catchpoint 2 (syscall 764)
4621(@value{GDBP})
4622@end smallexample
4623
4624If you configure @value{GDBN} using the @samp{--without-expat} option,
4625it will not be able to display syscall names. Also, if your
4626architecture does not have an XML file describing its system calls,
4627you will not be able to see the syscall names. It is important to
4628notice that these two features are used for accessing the syscall
4629name database. In either case, you will see a warning like this:
4630
4631@smallexample
4632(@value{GDBP}) catch syscall
4633warning: Could not open "syscalls/i386-linux.xml"
4634warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
4635GDB will not be able to display syscall names.
4636Catchpoint 1 (syscall)
4637(@value{GDBP})
4638@end smallexample
4639
4640Of course, the file name will change depending on your architecture and system.
4641
4642Still using the example above, you can also try to catch a syscall by its
4643number. In this case, you would see something like:
4644
4645@smallexample
4646(@value{GDBP}) catch syscall 252
4647Catchpoint 1 (syscall(s) 252)
4648@end smallexample
4649
4650Again, in this case @value{GDBN} would not be able to display syscall's names.
4651
c906108c 4652@item fork
1a4f73eb 4653@kindex catch fork
b1236ac3 4654A call to @code{fork}.
c906108c
SS
4655
4656@item vfork
1a4f73eb 4657@kindex catch vfork
b1236ac3 4658A call to @code{vfork}.
c906108c 4659
edcc5120
TT
4660@item load @r{[}regexp@r{]}
4661@itemx unload @r{[}regexp@r{]}
1a4f73eb
TT
4662@kindex catch load
4663@kindex catch unload
edcc5120
TT
4664The loading or unloading of a shared library. If @var{regexp} is
4665given, then the catchpoint will stop only if the regular expression
4666matches one of the affected libraries.
4667
ab04a2af 4668@item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
1a4f73eb 4669@kindex catch signal
ab04a2af
TT
4670The delivery of a signal.
4671
4672With no arguments, this catchpoint will catch any signal that is not
4673used internally by @value{GDBN}, specifically, all signals except
4674@samp{SIGTRAP} and @samp{SIGINT}.
4675
4676With the argument @samp{all}, all signals, including those used by
4677@value{GDBN}, will be caught. This argument cannot be used with other
4678signal names.
4679
4680Otherwise, the arguments are a list of signal names as given to
4681@code{handle} (@pxref{Signals}). Only signals specified in this list
4682will be caught.
4683
4684One reason that @code{catch signal} can be more useful than
4685@code{handle} is that you can attach commands and conditions to the
4686catchpoint.
4687
4688When a signal is caught by a catchpoint, the signal's @code{stop} and
4689@code{print} settings, as specified by @code{handle}, are ignored.
4690However, whether the signal is still delivered to the inferior depends
4691on the @code{pass} setting; this can be changed in the catchpoint's
4692commands.
4693
c906108c
SS
4694@end table
4695
4696@item tcatch @var{event}
1a4f73eb 4697@kindex tcatch
c906108c
SS
4698Set a catchpoint that is enabled only for one stop. The catchpoint is
4699automatically deleted after the first time the event is caught.
4700
4701@end table
4702
4703Use the @code{info break} command to list the current catchpoints.
4704
c906108c 4705
6d2ebf8b 4706@node Delete Breaks
79a6e687 4707@subsection Deleting Breakpoints
c906108c
SS
4708
4709@cindex clearing breakpoints, watchpoints, catchpoints
4710@cindex deleting breakpoints, watchpoints, catchpoints
4711It is often necessary to eliminate a breakpoint, watchpoint, or
4712catchpoint once it has done its job and you no longer want your program
4713to stop there. This is called @dfn{deleting} the breakpoint. A
4714breakpoint that has been deleted no longer exists; it is forgotten.
4715
4716With the @code{clear} command you can delete breakpoints according to
4717where they are in your program. With the @code{delete} command you can
4718delete individual breakpoints, watchpoints, or catchpoints by specifying
4719their breakpoint numbers.
4720
4721It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
4722automatically ignores breakpoints on the first instruction to be executed
4723when you continue execution without changing the execution address.
4724
4725@table @code
4726@kindex clear
4727@item clear
4728Delete any breakpoints at the next instruction to be executed in the
79a6e687 4729selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
c906108c
SS
4730the innermost frame is selected, this is a good way to delete a
4731breakpoint where your program just stopped.
4732
2a25a5ba
EZ
4733@item clear @var{location}
4734Delete any breakpoints set at the specified @var{location}.
4735@xref{Specify Location}, for the various forms of @var{location}; the
4736most useful ones are listed below:
4737
4738@table @code
c906108c
SS
4739@item clear @var{function}
4740@itemx clear @var{filename}:@var{function}
09d4efe1 4741Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
4742
4743@item clear @var{linenum}
4744@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
4745Delete any breakpoints set at or within the code of the specified
4746@var{linenum} of the specified @var{filename}.
2a25a5ba 4747@end table
c906108c
SS
4748
4749@cindex delete breakpoints
4750@kindex delete
41afff9a 4751@kindex d @r{(@code{delete})}
18da0c51 4752@item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c5394b80 4753Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
18da0c51 4754list specified as argument. If no argument is specified, delete all
c906108c
SS
4755breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
4756confirm off}). You can abbreviate this command as @code{d}.
4757@end table
4758
6d2ebf8b 4759@node Disabling
79a6e687 4760@subsection Disabling Breakpoints
c906108c 4761
4644b6e3 4762@cindex enable/disable a breakpoint
c906108c
SS
4763Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
4764prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
4765it had been deleted, but remembers the information on the breakpoint so
4766that you can @dfn{enable} it again later.
4767
4768You disable and enable breakpoints, watchpoints, and catchpoints with
d77f58be
SS
4769the @code{enable} and @code{disable} commands, optionally specifying
4770one or more breakpoint numbers as arguments. Use @code{info break} to
4771print a list of all breakpoints, watchpoints, and catchpoints if you
4772do not know which numbers to use.
c906108c 4773
3b784c4f
EZ
4774Disabling and enabling a breakpoint that has multiple locations
4775affects all of its locations.
4776
816338b5
SS
4777A breakpoint, watchpoint, or catchpoint can have any of several
4778different states of enablement:
c906108c
SS
4779
4780@itemize @bullet
4781@item
4782Enabled. The breakpoint stops your program. A breakpoint set
4783with the @code{break} command starts out in this state.
4784@item
4785Disabled. The breakpoint has no effect on your program.
4786@item
4787Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 4788disabled.
c906108c 4789@item
816338b5
SS
4790Enabled for a count. The breakpoint stops your program for the next
4791N times, then becomes disabled.
4792@item
c906108c 4793Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
4794immediately after it does so it is deleted permanently. A breakpoint
4795set with the @code{tbreak} command starts out in this state.
c906108c
SS
4796@end itemize
4797
4798You can use the following commands to enable or disable breakpoints,
4799watchpoints, and catchpoints:
4800
4801@table @code
c906108c 4802@kindex disable
41afff9a 4803@kindex dis @r{(@code{disable})}
18da0c51 4804@item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c906108c
SS
4805Disable the specified breakpoints---or all breakpoints, if none are
4806listed. A disabled breakpoint has no effect but is not forgotten. All
4807options such as ignore-counts, conditions and commands are remembered in
4808case the breakpoint is enabled again later. You may abbreviate
4809@code{disable} as @code{dis}.
4810
c906108c 4811@kindex enable
18da0c51 4812@item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c906108c
SS
4813Enable the specified breakpoints (or all defined breakpoints). They
4814become effective once again in stopping your program.
4815
18da0c51 4816@item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
c906108c
SS
4817Enable the specified breakpoints temporarily. @value{GDBN} disables any
4818of these breakpoints immediately after stopping your program.
4819
18da0c51 4820@item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
816338b5
SS
4821Enable the specified breakpoints temporarily. @value{GDBN} records
4822@var{count} with each of the specified breakpoints, and decrements a
4823breakpoint's count when it is hit. When any count reaches 0,
4824@value{GDBN} disables that breakpoint. If a breakpoint has an ignore
4825count (@pxref{Conditions, ,Break Conditions}), that will be
4826decremented to 0 before @var{count} is affected.
4827
18da0c51 4828@item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
c906108c
SS
4829Enable the specified breakpoints to work once, then die. @value{GDBN}
4830deletes any of these breakpoints as soon as your program stops there.
09d4efe1 4831Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
4832@end table
4833
d4f3574e
SS
4834@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
4835@c confusing: tbreak is also initially enabled.
c906108c 4836Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
79a6e687 4837,Setting Breakpoints}), breakpoints that you set are initially enabled;
c906108c
SS
4838subsequently, they become disabled or enabled only when you use one of
4839the commands above. (The command @code{until} can set and delete a
4840breakpoint of its own, but it does not change the state of your other
4841breakpoints; see @ref{Continuing and Stepping, ,Continuing and
79a6e687 4842Stepping}.)
c906108c 4843
6d2ebf8b 4844@node Conditions
79a6e687 4845@subsection Break Conditions
c906108c
SS
4846@cindex conditional breakpoints
4847@cindex breakpoint conditions
4848
4849@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 4850@c in particular for a watchpoint?
c906108c
SS
4851The simplest sort of breakpoint breaks every time your program reaches a
4852specified place. You can also specify a @dfn{condition} for a
4853breakpoint. A condition is just a Boolean expression in your
4854programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
4855a condition evaluates the expression each time your program reaches it,
4856and your program stops only if the condition is @emph{true}.
4857
4858This is the converse of using assertions for program validation; in that
4859situation, you want to stop when the assertion is violated---that is,
4860when the condition is false. In C, if you want to test an assertion expressed
4861by the condition @var{assert}, you should set the condition
4862@samp{! @var{assert}} on the appropriate breakpoint.
4863
4864Conditions are also accepted for watchpoints; you may not need them,
4865since a watchpoint is inspecting the value of an expression anyhow---but
4866it might be simpler, say, to just set a watchpoint on a variable name,
4867and specify a condition that tests whether the new value is an interesting
4868one.
4869
4870Break conditions can have side effects, and may even call functions in
4871your program. This can be useful, for example, to activate functions
4872that log program progress, or to use your own print functions to
99e008fe 4873format special data structures. The effects are completely predictable
c906108c
SS
4874unless there is another enabled breakpoint at the same address. (In
4875that case, @value{GDBN} might see the other breakpoint first and stop your
4876program without checking the condition of this one.) Note that
d4f3574e
SS
4877breakpoint commands are usually more convenient and flexible than break
4878conditions for the
c906108c 4879purpose of performing side effects when a breakpoint is reached
79a6e687 4880(@pxref{Break Commands, ,Breakpoint Command Lists}).
c906108c 4881
83364271
LM
4882Breakpoint conditions can also be evaluated on the target's side if
4883the target supports it. Instead of evaluating the conditions locally,
4884@value{GDBN} encodes the expression into an agent expression
4885(@pxref{Agent Expressions}) suitable for execution on the target,
4886independently of @value{GDBN}. Global variables become raw memory
4887locations, locals become stack accesses, and so forth.
4888
4889In this case, @value{GDBN} will only be notified of a breakpoint trigger
4890when its condition evaluates to true. This mechanism may provide faster
4891response times depending on the performance characteristics of the target
4892since it does not need to keep @value{GDBN} informed about
4893every breakpoint trigger, even those with false conditions.
4894
c906108c
SS
4895Break conditions can be specified when a breakpoint is set, by using
4896@samp{if} in the arguments to the @code{break} command. @xref{Set
79a6e687 4897Breaks, ,Setting Breakpoints}. They can also be changed at any time
c906108c 4898with the @code{condition} command.
53a5351d 4899
c906108c
SS
4900You can also use the @code{if} keyword with the @code{watch} command.
4901The @code{catch} command does not recognize the @code{if} keyword;
4902@code{condition} is the only way to impose a further condition on a
4903catchpoint.
c906108c
SS
4904
4905@table @code
4906@kindex condition
4907@item condition @var{bnum} @var{expression}
4908Specify @var{expression} as the break condition for breakpoint,
4909watchpoint, or catchpoint number @var{bnum}. After you set a condition,
4910breakpoint @var{bnum} stops your program only if the value of
4911@var{expression} is true (nonzero, in C). When you use
4912@code{condition}, @value{GDBN} checks @var{expression} immediately for
4913syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
4914referents in the context of your breakpoint. If @var{expression} uses
4915symbols not referenced in the context of the breakpoint, @value{GDBN}
4916prints an error message:
4917
474c8240 4918@smallexample
d4f3574e 4919No symbol "foo" in current context.
474c8240 4920@end smallexample
d4f3574e
SS
4921
4922@noindent
c906108c
SS
4923@value{GDBN} does
4924not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
4925command (or a command that sets a breakpoint with a condition, like
4926@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
4927
4928@item condition @var{bnum}
4929Remove the condition from breakpoint number @var{bnum}. It becomes
4930an ordinary unconditional breakpoint.
4931@end table
4932
4933@cindex ignore count (of breakpoint)
4934A special case of a breakpoint condition is to stop only when the
4935breakpoint has been reached a certain number of times. This is so
4936useful that there is a special way to do it, using the @dfn{ignore
4937count} of the breakpoint. Every breakpoint has an ignore count, which
4938is an integer. Most of the time, the ignore count is zero, and
4939therefore has no effect. But if your program reaches a breakpoint whose
4940ignore count is positive, then instead of stopping, it just decrements
4941the ignore count by one and continues. As a result, if the ignore count
4942value is @var{n}, the breakpoint does not stop the next @var{n} times
4943your program reaches it.
4944
4945@table @code
4946@kindex ignore
4947@item ignore @var{bnum} @var{count}
4948Set the ignore count of breakpoint number @var{bnum} to @var{count}.
4949The next @var{count} times the breakpoint is reached, your program's
4950execution does not stop; other than to decrement the ignore count, @value{GDBN}
4951takes no action.
4952
4953To make the breakpoint stop the next time it is reached, specify
4954a count of zero.
4955
4956When you use @code{continue} to resume execution of your program from a
4957breakpoint, you can specify an ignore count directly as an argument to
4958@code{continue}, rather than using @code{ignore}. @xref{Continuing and
79a6e687 4959Stepping,,Continuing and Stepping}.
c906108c
SS
4960
4961If a breakpoint has a positive ignore count and a condition, the
4962condition is not checked. Once the ignore count reaches zero,
4963@value{GDBN} resumes checking the condition.
4964
4965You could achieve the effect of the ignore count with a condition such
4966as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
4967is decremented each time. @xref{Convenience Vars, ,Convenience
79a6e687 4968Variables}.
c906108c
SS
4969@end table
4970
4971Ignore counts apply to breakpoints, watchpoints, and catchpoints.
4972
4973
6d2ebf8b 4974@node Break Commands
79a6e687 4975@subsection Breakpoint Command Lists
c906108c
SS
4976
4977@cindex breakpoint commands
4978You can give any breakpoint (or watchpoint or catchpoint) a series of
4979commands to execute when your program stops due to that breakpoint. For
4980example, you might want to print the values of certain expressions, or
4981enable other breakpoints.
4982
4983@table @code
4984@kindex commands
ca91424e 4985@kindex end@r{ (breakpoint commands)}
18da0c51 4986@item commands @r{[}@var{list}@dots{}@r{]}
c906108c
SS
4987@itemx @dots{} @var{command-list} @dots{}
4988@itemx end
95a42b64 4989Specify a list of commands for the given breakpoints. The commands
c906108c
SS
4990themselves appear on the following lines. Type a line containing just
4991@code{end} to terminate the commands.
4992
4993To remove all commands from a breakpoint, type @code{commands} and
4994follow it immediately with @code{end}; that is, give no commands.
4995
95a42b64
TT
4996With no argument, @code{commands} refers to the last breakpoint,
4997watchpoint, or catchpoint set (not to the breakpoint most recently
4998encountered). If the most recent breakpoints were set with a single
4999command, then the @code{commands} will apply to all the breakpoints
5000set by that command. This applies to breakpoints set by
86b17b60
PA
5001@code{rbreak}, and also applies when a single @code{break} command
5002creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5003Expressions}).
c906108c
SS
5004@end table
5005
5006Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5007disabled within a @var{command-list}.
5008
5009You can use breakpoint commands to start your program up again. Simply
5010use the @code{continue} command, or @code{step}, or any other command
5011that resumes execution.
5012
5013Any other commands in the command list, after a command that resumes
5014execution, are ignored. This is because any time you resume execution
5015(even with a simple @code{next} or @code{step}), you may encounter
5016another breakpoint---which could have its own command list, leading to
5017ambiguities about which list to execute.
5018
5019@kindex silent
5020If the first command you specify in a command list is @code{silent}, the
5021usual message about stopping at a breakpoint is not printed. This may
5022be desirable for breakpoints that are to print a specific message and
5023then continue. If none of the remaining commands print anything, you
5024see no sign that the breakpoint was reached. @code{silent} is
5025meaningful only at the beginning of a breakpoint command list.
5026
5027The commands @code{echo}, @code{output}, and @code{printf} allow you to
5028print precisely controlled output, and are often useful in silent
79a6e687 5029breakpoints. @xref{Output, ,Commands for Controlled Output}.
c906108c
SS
5030
5031For example, here is how you could use breakpoint commands to print the
5032value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5033
474c8240 5034@smallexample
c906108c
SS
5035break foo if x>0
5036commands
5037silent
5038printf "x is %d\n",x
5039cont
5040end
474c8240 5041@end smallexample
c906108c
SS
5042
5043One application for breakpoint commands is to compensate for one bug so
5044you can test for another. Put a breakpoint just after the erroneous line
5045of code, give it a condition to detect the case in which something
5046erroneous has been done, and give it commands to assign correct values
5047to any variables that need them. End with the @code{continue} command
5048so that your program does not stop, and start with the @code{silent}
5049command so that no output is produced. Here is an example:
5050
474c8240 5051@smallexample
c906108c
SS
5052break 403
5053commands
5054silent
5055set x = y + 4
5056cont
5057end
474c8240 5058@end smallexample
c906108c 5059
e7e0cddf
SS
5060@node Dynamic Printf
5061@subsection Dynamic Printf
5062
5063@cindex dynamic printf
5064@cindex dprintf
5065The dynamic printf command @code{dprintf} combines a breakpoint with
5066formatted printing of your program's data to give you the effect of
5067inserting @code{printf} calls into your program on-the-fly, without
5068having to recompile it.
5069
5070In its most basic form, the output goes to the GDB console. However,
5071you can set the variable @code{dprintf-style} for alternate handling.
5072For instance, you can ask to format the output by calling your
5073program's @code{printf} function. This has the advantage that the
5074characters go to the program's output device, so they can recorded in
5075redirects to files and so forth.
5076
d3ce09f5
SS
5077If you are doing remote debugging with a stub or agent, you can also
5078ask to have the printf handled by the remote agent. In addition to
5079ensuring that the output goes to the remote program's device along
5080with any other output the program might produce, you can also ask that
5081the dprintf remain active even after disconnecting from the remote
5082target. Using the stub/agent is also more efficient, as it can do
5083everything without needing to communicate with @value{GDBN}.
5084
e7e0cddf
SS
5085@table @code
5086@kindex dprintf
5087@item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
5088Whenever execution reaches @var{location}, print the values of one or
5089more @var{expressions} under the control of the string @var{template}.
5090To print several values, separate them with commas.
5091
5092@item set dprintf-style @var{style}
5093Set the dprintf output to be handled in one of several different
5094styles enumerated below. A change of style affects all existing
5095dynamic printfs immediately. (If you need individual control over the
5096print commands, simply define normal breakpoints with
5097explicitly-supplied command lists.)
5098
18da0c51 5099@table @code
e7e0cddf
SS
5100@item gdb
5101@kindex dprintf-style gdb
5102Handle the output using the @value{GDBN} @code{printf} command.
5103
5104@item call
5105@kindex dprintf-style call
5106Handle the output by calling a function in your program (normally
5107@code{printf}).
5108
d3ce09f5
SS
5109@item agent
5110@kindex dprintf-style agent
5111Have the remote debugging agent (such as @code{gdbserver}) handle
5112the output itself. This style is only available for agents that
5113support running commands on the target.
18da0c51 5114@end table
d3ce09f5 5115
e7e0cddf
SS
5116@item set dprintf-function @var{function}
5117Set the function to call if the dprintf style is @code{call}. By
5118default its value is @code{printf}. You may set it to any expression.
5119that @value{GDBN} can evaluate to a function, as per the @code{call}
5120command.
5121
5122@item set dprintf-channel @var{channel}
5123Set a ``channel'' for dprintf. If set to a non-empty value,
5124@value{GDBN} will evaluate it as an expression and pass the result as
5125a first argument to the @code{dprintf-function}, in the manner of
5126@code{fprintf} and similar functions. Otherwise, the dprintf format
5127string will be the first argument, in the manner of @code{printf}.
5128
5129As an example, if you wanted @code{dprintf} output to go to a logfile
5130that is a standard I/O stream assigned to the variable @code{mylog},
5131you could do the following:
5132
5133@example
5134(gdb) set dprintf-style call
5135(gdb) set dprintf-function fprintf
5136(gdb) set dprintf-channel mylog
5137(gdb) dprintf 25,"at line 25, glob=%d\n",glob
5138Dprintf 1 at 0x123456: file main.c, line 25.
5139(gdb) info break
51401 dprintf keep y 0x00123456 in main at main.c:25
5141 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5142 continue
5143(gdb)
5144@end example
5145
5146Note that the @code{info break} displays the dynamic printf commands
5147as normal breakpoint commands; you can thus easily see the effect of
5148the variable settings.
5149
d3ce09f5
SS
5150@item set disconnected-dprintf on
5151@itemx set disconnected-dprintf off
5152@kindex set disconnected-dprintf
5153Choose whether @code{dprintf} commands should continue to run if
5154@value{GDBN} has disconnected from the target. This only applies
5155if the @code{dprintf-style} is @code{agent}.
5156
5157@item show disconnected-dprintf off
5158@kindex show disconnected-dprintf
5159Show the current choice for disconnected @code{dprintf}.
5160
e7e0cddf
SS
5161@end table
5162
5163@value{GDBN} does not check the validity of function and channel,
5164relying on you to supply values that are meaningful for the contexts
5165in which they are being used. For instance, the function and channel
5166may be the values of local variables, but if that is the case, then
5167all enabled dynamic prints must be at locations within the scope of
5168those locals. If evaluation fails, @value{GDBN} will report an error.
5169
6149aea9
PA
5170@node Save Breakpoints
5171@subsection How to save breakpoints to a file
5172
5173To save breakpoint definitions to a file use the @w{@code{save
5174breakpoints}} command.
5175
5176@table @code
5177@kindex save breakpoints
5178@cindex save breakpoints to a file for future sessions
5179@item save breakpoints [@var{filename}]
5180This command saves all current breakpoint definitions together with
5181their commands and ignore counts, into a file @file{@var{filename}}
5182suitable for use in a later debugging session. This includes all
5183types of breakpoints (breakpoints, watchpoints, catchpoints,
5184tracepoints). To read the saved breakpoint definitions, use the
5185@code{source} command (@pxref{Command Files}). Note that watchpoints
5186with expressions involving local variables may fail to be recreated
5187because it may not be possible to access the context where the
5188watchpoint is valid anymore. Because the saved breakpoint definitions
5189are simply a sequence of @value{GDBN} commands that recreate the
5190breakpoints, you can edit the file in your favorite editing program,
5191and remove the breakpoint definitions you're not interested in, or
5192that can no longer be recreated.
5193@end table
5194
62e5f89c
SDJ
5195@node Static Probe Points
5196@subsection Static Probe Points
5197
5198@cindex static probe point, SystemTap
3133f8c1 5199@cindex static probe point, DTrace
62e5f89c
SDJ
5200@value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5201for Statically Defined Tracing, and the probes are designed to have a tiny
3133f8c1
JM
5202runtime code and data footprint, and no dynamic relocations.
5203
5204Currently, the following types of probes are supported on
5205ELF-compatible systems:
5206
5207@itemize @bullet
62e5f89c 5208
3133f8c1
JM
5209@item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5210@acronym{SDT} probes@footnote{See
62e5f89c 5211@uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
3133f8c1
JM
5212for more information on how to add @code{SystemTap} @acronym{SDT}
5213probes in your applications.}. @code{SystemTap} probes are usable
5214from assembly, C and C@t{++} languages@footnote{See
5215@uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5216for a good reference on how the @acronym{SDT} probes are implemented.}.
5217
5218@item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5219@acronym{USDT} probes. @code{DTrace} probes are usable from C and
5220C@t{++} languages.
5221@end itemize
62e5f89c
SDJ
5222
5223@cindex semaphores on static probe points
3133f8c1
JM
5224Some @code{SystemTap} probes have an associated semaphore variable;
5225for instance, this happens automatically if you defined your probe
5226using a DTrace-style @file{.d} file. If your probe has a semaphore,
5227@value{GDBN} will automatically enable it when you specify a
5228breakpoint using the @samp{-probe-stap} notation. But, if you put a
5229breakpoint at a probe's location by some other method (e.g.,
5230@code{break file:line}), then @value{GDBN} will not automatically set
5231the semaphore. @code{DTrace} probes do not support semaphores.
62e5f89c
SDJ
5232
5233You can examine the available static static probes using @code{info
5234probes}, with optional arguments:
5235
5236@table @code
5237@kindex info probes
3133f8c1
JM
5238@item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5239If given, @var{type} is either @code{stap} for listing
5240@code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5241probes. If omitted all probes are listed regardless of their types.
5242
62e5f89c
SDJ
5243If given, @var{provider} is a regular expression used to match against provider
5244names when selecting which probes to list. If omitted, probes by all
5245probes from all providers are listed.
5246
5247If given, @var{name} is a regular expression to match against probe names
5248when selecting which probes to list. If omitted, probe names are not
5249considered when deciding whether to display them.
5250
5251If given, @var{objfile} is a regular expression used to select which
5252object files (executable or shared libraries) to examine. If not
5253given, all object files are considered.
5254
5255@item info probes all
5256List the available static probes, from all types.
5257@end table
5258
9aca2ff8
JM
5259@cindex enabling and disabling probes
5260Some probe points can be enabled and/or disabled. The effect of
5261enabling or disabling a probe depends on the type of probe being
3133f8c1
JM
5262handled. Some @code{DTrace} probes can be enabled or
5263disabled, but @code{SystemTap} probes cannot be disabled.
9aca2ff8
JM
5264
5265You can enable (or disable) one or more probes using the following
5266commands, with optional arguments:
5267
5268@table @code
5269@kindex enable probes
5270@item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5271If given, @var{provider} is a regular expression used to match against
5272provider names when selecting which probes to enable. If omitted,
5273all probes from all providers are enabled.
5274
5275If given, @var{name} is a regular expression to match against probe
5276names when selecting which probes to enable. If omitted, probe names
5277are not considered when deciding whether to enable them.
5278
5279If given, @var{objfile} is a regular expression used to select which
5280object files (executable or shared libraries) to examine. If not
5281given, all object files are considered.
5282
5283@kindex disable probes
5284@item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5285See the @code{enable probes} command above for a description of the
5286optional arguments accepted by this command.
5287@end table
5288
62e5f89c
SDJ
5289@vindex $_probe_arg@r{, convenience variable}
5290A probe may specify up to twelve arguments. These are available at the
5291point at which the probe is defined---that is, when the current PC is
5292at the probe's location. The arguments are available using the
5293convenience variables (@pxref{Convenience Vars})
3133f8c1
JM
5294@code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
5295probes each probe argument is an integer of the appropriate size;
5296types are not preserved. In @code{DTrace} probes types are preserved
5297provided that they are recognized as such by @value{GDBN}; otherwise
5298the value of the probe argument will be a long integer. The
62e5f89c
SDJ
5299convenience variable @code{$_probe_argc} holds the number of arguments
5300at the current probe point.
5301
5302These variables are always available, but attempts to access them at
5303any location other than a probe point will cause @value{GDBN} to give
5304an error message.
5305
5306
c906108c 5307@c @ifclear BARETARGET
6d2ebf8b 5308@node Error in Breakpoints
d4f3574e 5309@subsection ``Cannot insert breakpoints''
c906108c 5310
fa3a767f
PA
5311If you request too many active hardware-assisted breakpoints and
5312watchpoints, you will see this error message:
d4f3574e
SS
5313
5314@c FIXME: the precise wording of this message may change; the relevant
5315@c source change is not committed yet (Sep 3, 1999).
5316@smallexample
5317Stopped; cannot insert breakpoints.
5318You may have requested too many hardware breakpoints and watchpoints.
5319@end smallexample
5320
5321@noindent
5322This message is printed when you attempt to resume the program, since
5323only then @value{GDBN} knows exactly how many hardware breakpoints and
5324watchpoints it needs to insert.
5325
5326When this message is printed, you need to disable or remove some of the
5327hardware-assisted breakpoints and watchpoints, and then continue.
5328
79a6e687 5329@node Breakpoint-related Warnings
1485d690
KB
5330@subsection ``Breakpoint address adjusted...''
5331@cindex breakpoint address adjusted
5332
5333Some processor architectures place constraints on the addresses at
5334which breakpoints may be placed. For architectures thus constrained,
5335@value{GDBN} will attempt to adjust the breakpoint's address to comply
5336with the constraints dictated by the architecture.
5337
5338One example of such an architecture is the Fujitsu FR-V. The FR-V is
5339a VLIW architecture in which a number of RISC-like instructions may be
5340bundled together for parallel execution. The FR-V architecture
5341constrains the location of a breakpoint instruction within such a
5342bundle to the instruction with the lowest address. @value{GDBN}
5343honors this constraint by adjusting a breakpoint's address to the
5344first in the bundle.
5345
5346It is not uncommon for optimized code to have bundles which contain
5347instructions from different source statements, thus it may happen that
5348a breakpoint's address will be adjusted from one source statement to
5349another. Since this adjustment may significantly alter @value{GDBN}'s
5350breakpoint related behavior from what the user expects, a warning is
5351printed when the breakpoint is first set and also when the breakpoint
5352is hit.
5353
5354A warning like the one below is printed when setting a breakpoint
5355that's been subject to address adjustment:
5356
5357@smallexample
5358warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
5359@end smallexample
5360
5361Such warnings are printed both for user settable and @value{GDBN}'s
5362internal breakpoints. If you see one of these warnings, you should
5363verify that a breakpoint set at the adjusted address will have the
5364desired affect. If not, the breakpoint in question may be removed and
b383017d 5365other breakpoints may be set which will have the desired behavior.
1485d690
KB
5366E.g., it may be sufficient to place the breakpoint at a later
5367instruction. A conditional breakpoint may also be useful in some
5368cases to prevent the breakpoint from triggering too often.
5369
5370@value{GDBN} will also issue a warning when stopping at one of these
5371adjusted breakpoints:
5372
5373@smallexample
5374warning: Breakpoint 1 address previously adjusted from 0x00010414
5375to 0x00010410.
5376@end smallexample
5377
5378When this warning is encountered, it may be too late to take remedial
5379action except in cases where the breakpoint is hit earlier or more
5380frequently than expected.
d4f3574e 5381
6d2ebf8b 5382@node Continuing and Stepping
79a6e687 5383@section Continuing and Stepping
c906108c
SS
5384
5385@cindex stepping
5386@cindex continuing
5387@cindex resuming execution
5388@dfn{Continuing} means resuming program execution until your program
5389completes normally. In contrast, @dfn{stepping} means executing just
5390one more ``step'' of your program, where ``step'' may mean either one
5391line of source code, or one machine instruction (depending on what
7a292a7a
SS
5392particular command you use). Either when continuing or when stepping,
5393your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e 5394it stops due to a signal, you may want to use @code{handle}, or use
e5f8a7cc
PA
5395@samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
5396or you may step into the signal's handler (@pxref{stepping and signal
5397handlers}).)
c906108c
SS
5398
5399@table @code
5400@kindex continue
41afff9a
EZ
5401@kindex c @r{(@code{continue})}
5402@kindex fg @r{(resume foreground execution)}
c906108c
SS
5403@item continue @r{[}@var{ignore-count}@r{]}
5404@itemx c @r{[}@var{ignore-count}@r{]}
5405@itemx fg @r{[}@var{ignore-count}@r{]}
5406Resume program execution, at the address where your program last stopped;
5407any breakpoints set at that address are bypassed. The optional argument
5408@var{ignore-count} allows you to specify a further number of times to
5409ignore a breakpoint at this location; its effect is like that of
79a6e687 5410@code{ignore} (@pxref{Conditions, ,Break Conditions}).
c906108c
SS
5411
5412The argument @var{ignore-count} is meaningful only when your program
5413stopped due to a breakpoint. At other times, the argument to
5414@code{continue} is ignored.
5415
d4f3574e
SS
5416The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
5417debugged program is deemed to be the foreground program) are provided
5418purely for convenience, and have exactly the same behavior as
5419@code{continue}.
c906108c
SS
5420@end table
5421
5422To resume execution at a different place, you can use @code{return}
79a6e687 5423(@pxref{Returning, ,Returning from a Function}) to go back to the
c906108c 5424calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
79a6e687 5425Different Address}) to go to an arbitrary location in your program.
c906108c
SS
5426
5427A typical technique for using stepping is to set a breakpoint
79a6e687 5428(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
c906108c
SS
5429beginning of the function or the section of your program where a problem
5430is believed to lie, run your program until it stops at that breakpoint,
5431and then step through the suspect area, examining the variables that are
5432interesting, until you see the problem happen.
5433
5434@table @code
5435@kindex step
41afff9a 5436@kindex s @r{(@code{step})}
c906108c
SS
5437@item step
5438Continue running your program until control reaches a different source
5439line, then stop it and return control to @value{GDBN}. This command is
5440abbreviated @code{s}.
5441
5442@quotation
5443@c "without debugging information" is imprecise; actually "without line
5444@c numbers in the debugging information". (gcc -g1 has debugging info but
5445@c not line numbers). But it seems complex to try to make that
5446@c distinction here.
5447@emph{Warning:} If you use the @code{step} command while control is
5448within a function that was compiled without debugging information,
5449execution proceeds until control reaches a function that does have
5450debugging information. Likewise, it will not step into a function which
5451is compiled without debugging information. To step through functions
5452without debugging information, use the @code{stepi} command, described
5453below.
5454@end quotation
5455
4a92d011
EZ
5456The @code{step} command only stops at the first instruction of a source
5457line. This prevents the multiple stops that could otherwise occur in
5458@code{switch} statements, @code{for} loops, etc. @code{step} continues
5459to stop if a function that has debugging information is called within
5460the line. In other words, @code{step} @emph{steps inside} any functions
5461called within the line.
c906108c 5462
d4f3574e
SS
5463Also, the @code{step} command only enters a function if there is line
5464number information for the function. Otherwise it acts like the
5d161b24 5465@code{next} command. This avoids problems when using @code{cc -gl}
eb17f351 5466on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5d161b24 5467was any debugging information about the routine.
c906108c
SS
5468
5469@item step @var{count}
5470Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
5471breakpoint is reached, or a signal not related to stepping occurs before
5472@var{count} steps, stepping stops right away.
c906108c
SS
5473
5474@kindex next
41afff9a 5475@kindex n @r{(@code{next})}
c906108c
SS
5476@item next @r{[}@var{count}@r{]}
5477Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
5478This is similar to @code{step}, but function calls that appear within
5479the line of code are executed without stopping. Execution stops when
5480control reaches a different line of code at the original stack level
5481that was executing when you gave the @code{next} command. This command
5482is abbreviated @code{n}.
c906108c
SS
5483
5484An argument @var{count} is a repeat count, as for @code{step}.
5485
5486
5487@c FIX ME!! Do we delete this, or is there a way it fits in with
5488@c the following paragraph? --- Vctoria
5489@c
5490@c @code{next} within a function that lacks debugging information acts like
5491@c @code{step}, but any function calls appearing within the code of the
5492@c function are executed without stopping.
5493
d4f3574e
SS
5494The @code{next} command only stops at the first instruction of a
5495source line. This prevents multiple stops that could otherwise occur in
4a92d011 5496@code{switch} statements, @code{for} loops, etc.
c906108c 5497
b90a5f51
CF
5498@kindex set step-mode
5499@item set step-mode
5500@cindex functions without line info, and stepping
5501@cindex stepping into functions with no line info
5502@itemx set step-mode on
4a92d011 5503The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
5504stop at the first instruction of a function which contains no debug line
5505information rather than stepping over it.
5506
4a92d011
EZ
5507This is useful in cases where you may be interested in inspecting the
5508machine instructions of a function which has no symbolic info and do not
5509want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
5510
5511@item set step-mode off
4a92d011 5512Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
5513debug information. This is the default.
5514
9c16f35a
EZ
5515@item show step-mode
5516Show whether @value{GDBN} will stop in or step over functions without
5517source line debug information.
5518
c906108c 5519@kindex finish
8dfa32fc 5520@kindex fin @r{(@code{finish})}
c906108c
SS
5521@item finish
5522Continue running until just after function in the selected stack frame
8dfa32fc
JB
5523returns. Print the returned value (if any). This command can be
5524abbreviated as @code{fin}.
c906108c
SS
5525
5526Contrast this with the @code{return} command (@pxref{Returning,
79a6e687 5527,Returning from a Function}).
c906108c
SS
5528
5529@kindex until
41afff9a 5530@kindex u @r{(@code{until})}
09d4efe1 5531@cindex run until specified location
c906108c
SS
5532@item until
5533@itemx u
5534Continue running until a source line past the current line, in the
5535current stack frame, is reached. This command is used to avoid single
5536stepping through a loop more than once. It is like the @code{next}
5537command, except that when @code{until} encounters a jump, it
5538automatically continues execution until the program counter is greater
5539than the address of the jump.
5540
5541This means that when you reach the end of a loop after single stepping
5542though it, @code{until} makes your program continue execution until it
5543exits the loop. In contrast, a @code{next} command at the end of a loop
5544simply steps back to the beginning of the loop, which forces you to step
5545through the next iteration.
5546
5547@code{until} always stops your program if it attempts to exit the current
5548stack frame.
5549
5550@code{until} may produce somewhat counterintuitive results if the order
5551of machine code does not match the order of the source lines. For
5552example, in the following excerpt from a debugging session, the @code{f}
5553(@code{frame}) command shows that execution is stopped at line
5554@code{206}; yet when we use @code{until}, we get to line @code{195}:
5555
474c8240 5556@smallexample
c906108c
SS
5557(@value{GDBP}) f
5558#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
5559206 expand_input();
5560(@value{GDBP}) until
5561195 for ( ; argc > 0; NEXTARG) @{
474c8240 5562@end smallexample
c906108c
SS
5563
5564This happened because, for execution efficiency, the compiler had
5565generated code for the loop closure test at the end, rather than the
5566start, of the loop---even though the test in a C @code{for}-loop is
5567written before the body of the loop. The @code{until} command appeared
5568to step back to the beginning of the loop when it advanced to this
5569expression; however, it has not really gone to an earlier
5570statement---not in terms of the actual machine code.
5571
5572@code{until} with no argument works by means of single
5573instruction stepping, and hence is slower than @code{until} with an
5574argument.
5575
5576@item until @var{location}
5577@itemx u @var{location}
697aa1b7
EZ
5578Continue running your program until either the specified @var{location} is
5579reached, or the current stack frame returns. The location is any of
2a25a5ba
EZ
5580the forms described in @ref{Specify Location}.
5581This form of the command uses temporary breakpoints, and
c60eb6f1
EZ
5582hence is quicker than @code{until} without an argument. The specified
5583location is actually reached only if it is in the current frame. This
5584implies that @code{until} can be used to skip over recursive function
5585invocations. For instance in the code below, if the current location is
5586line @code{96}, issuing @code{until 99} will execute the program up to
db2e3e2e 5587line @code{99} in the same invocation of factorial, i.e., after the inner
c60eb6f1
EZ
5588invocations have returned.
5589
5590@smallexample
559194 int factorial (int value)
559295 @{
559396 if (value > 1) @{
559497 value *= factorial (value - 1);
559598 @}
559699 return (value);
5597100 @}
5598@end smallexample
5599
5600
5601@kindex advance @var{location}
984359d2 5602@item advance @var{location}
09d4efe1 5603Continue running the program up to the given @var{location}. An argument is
2a25a5ba
EZ
5604required, which should be of one of the forms described in
5605@ref{Specify Location}.
5606Execution will also stop upon exit from the current stack
c60eb6f1
EZ
5607frame. This command is similar to @code{until}, but @code{advance} will
5608not skip over recursive function calls, and the target location doesn't
5609have to be in the same frame as the current one.
5610
c906108c
SS
5611
5612@kindex stepi
41afff9a 5613@kindex si @r{(@code{stepi})}
c906108c 5614@item stepi
96a2c332 5615@itemx stepi @var{arg}
c906108c
SS
5616@itemx si
5617Execute one machine instruction, then stop and return to the debugger.
5618
5619It is often useful to do @samp{display/i $pc} when stepping by machine
5620instructions. This makes @value{GDBN} automatically display the next
5621instruction to be executed, each time your program stops. @xref{Auto
79a6e687 5622Display,, Automatic Display}.
c906108c
SS
5623
5624An argument is a repeat count, as in @code{step}.
5625
5626@need 750
5627@kindex nexti
41afff9a 5628@kindex ni @r{(@code{nexti})}
c906108c 5629@item nexti
96a2c332 5630@itemx nexti @var{arg}
c906108c
SS
5631@itemx ni
5632Execute one machine instruction, but if it is a function call,
5633proceed until the function returns.
5634
5635An argument is a repeat count, as in @code{next}.
c1e36e3e
PA
5636
5637@end table
5638
5639@anchor{range stepping}
5640@cindex range stepping
5641@cindex target-assisted range stepping
5642By default, and if available, @value{GDBN} makes use of
5643target-assisted @dfn{range stepping}. In other words, whenever you
5644use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
5645tells the target to step the corresponding range of instruction
5646addresses instead of issuing multiple single-steps. This speeds up
5647line stepping, particularly for remote targets. Ideally, there should
5648be no reason you would want to turn range stepping off. However, it's
5649possible that a bug in the debug info, a bug in the remote stub (for
5650remote targets), or even a bug in @value{GDBN} could make line
5651stepping behave incorrectly when target-assisted range stepping is
5652enabled. You can use the following command to turn off range stepping
5653if necessary:
5654
5655@table @code
5656@kindex set range-stepping
5657@kindex show range-stepping
5658@item set range-stepping
5659@itemx show range-stepping
5660Control whether range stepping is enabled.
5661
5662If @code{on}, and the target supports it, @value{GDBN} tells the
5663target to step a range of addresses itself, instead of issuing
5664multiple single-steps. If @code{off}, @value{GDBN} always issues
5665single-steps, even if range stepping is supported by the target. The
5666default is @code{on}.
5667
c906108c
SS
5668@end table
5669
aad1c02c
TT
5670@node Skipping Over Functions and Files
5671@section Skipping Over Functions and Files
1bfeeb0f
JL
5672@cindex skipping over functions and files
5673
5674The program you are debugging may contain some functions which are
8244c20d 5675uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
cce0e923
DE
5676skip a function, all functions in a file or a particular function in
5677a particular file when stepping.
1bfeeb0f
JL
5678
5679For example, consider the following C function:
5680
5681@smallexample
5682101 int func()
5683102 @{
5684103 foo(boring());
5685104 bar(boring());
5686105 @}
5687@end smallexample
5688
5689@noindent
5690Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
5691are not interested in stepping through @code{boring}. If you run @code{step}
5692at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
5693step over both @code{foo} and @code{boring}!
5694
5695One solution is to @code{step} into @code{boring} and use the @code{finish}
5696command to immediately exit it. But this can become tedious if @code{boring}
5697is called from many places.
5698
5699A more flexible solution is to execute @kbd{skip boring}. This instructs
5700@value{GDBN} never to step into @code{boring}. Now when you execute
5701@code{step} at line 103, you'll step over @code{boring} and directly into
5702@code{foo}.
5703
cce0e923
DE
5704Functions may be skipped by providing either a function name, linespec
5705(@pxref{Specify Location}), regular expression that matches the function's
5706name, file name or a @code{glob}-style pattern that matches the file name.
5707
5708On Posix systems the form of the regular expression is
5709``Extended Regular Expressions''. See for example @samp{man 7 regex}
5710on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
5711expression is whatever is provided by the @code{regcomp} function of
5712the underlying system.
5713See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
5714description of @code{glob}-style patterns.
5715
5716@table @code
5717@kindex skip
5718@item skip @r{[}@var{options}@r{]}
5719The basic form of the @code{skip} command takes zero or more options
5720that specify what to skip.
5721The @var{options} argument is any useful combination of the following:
1bfeeb0f
JL
5722
5723@table @code
cce0e923
DE
5724@item -file @var{file}
5725@itemx -fi @var{file}
5726Functions in @var{file} will be skipped over when stepping.
5727
5728@item -gfile @var{file-glob-pattern}
5729@itemx -gfi @var{file-glob-pattern}
5730@cindex skipping over files via glob-style patterns
5731Functions in files matching @var{file-glob-pattern} will be skipped
5732over when stepping.
5733
5734@smallexample
5735(gdb) skip -gfi utils/*.c
5736@end smallexample
5737
5738@item -function @var{linespec}
5739@itemx -fu @var{linespec}
5740Functions named by @var{linespec} or the function containing the line
5741named by @var{linespec} will be skipped over when stepping.
5742@xref{Specify Location}.
5743
5744@item -rfunction @var{regexp}
5745@itemx -rfu @var{regexp}
5746@cindex skipping over functions via regular expressions
5747Functions whose name matches @var{regexp} will be skipped over when stepping.
5748
5749This form is useful for complex function names.
5750For example, there is generally no need to step into C@t{++} @code{std::string}
5751constructors or destructors. Plus with C@t{++} templates it can be hard to
5752write out the full name of the function, and often it doesn't matter what
5753the template arguments are. Specifying the function to be skipped as a
5754regular expression makes this easier.
5755
5756@smallexample
5757(gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
5758@end smallexample
5759
5760If you want to skip every templated C@t{++} constructor and destructor
5761in the @code{std} namespace you can do:
5762
5763@smallexample
5764(gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
5765@end smallexample
5766@end table
5767
5768If no options are specified, the function you're currently debugging
5769will be skipped.
5770
1bfeeb0f 5771@kindex skip function
cce0e923 5772@item skip function @r{[}@var{linespec}@r{]}
1bfeeb0f
JL
5773After running this command, the function named by @var{linespec} or the
5774function containing the line named by @var{linespec} will be skipped over when
983fb131 5775stepping. @xref{Specify Location}.
1bfeeb0f
JL
5776
5777If you do not specify @var{linespec}, the function you're currently debugging
5778will be skipped.
5779
5780(If you have a function called @code{file} that you want to skip, use
5781@kbd{skip function file}.)
5782
5783@kindex skip file
5784@item skip file @r{[}@var{filename}@r{]}
5785After running this command, any function whose source lives in @var{filename}
5786will be skipped over when stepping.
5787
cce0e923
DE
5788@smallexample
5789(gdb) skip file boring.c
5790File boring.c will be skipped when stepping.
5791@end smallexample
5792
1bfeeb0f
JL
5793If you do not specify @var{filename}, functions whose source lives in the file
5794you're currently debugging will be skipped.
5795@end table
5796
5797Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
5798These are the commands for managing your list of skips:
5799
5800@table @code
5801@kindex info skip
5802@item info skip @r{[}@var{range}@r{]}
5803Print details about the specified skip(s). If @var{range} is not specified,
5804print a table with details about all functions and files marked for skipping.
5805@code{info skip} prints the following information about each skip:
5806
5807@table @emph
5808@item Identifier
5809A number identifying this skip.
1bfeeb0f 5810@item Enabled or Disabled
cce0e923
DE
5811Enabled skips are marked with @samp{y}.
5812Disabled skips are marked with @samp{n}.
5813@item Glob
5814If the file name is a @samp{glob} pattern this is @samp{y}.
5815Otherwise it is @samp{n}.
5816@item File
5817The name or @samp{glob} pattern of the file to be skipped.
5818If no file is specified this is @samp{<none>}.
5819@item RE
5820If the function name is a @samp{regular expression} this is @samp{y}.
5821Otherwise it is @samp{n}.
5822@item Function
5823The name or regular expression of the function to skip.
5824If no function is specified this is @samp{<none>}.
1bfeeb0f
JL
5825@end table
5826
5827@kindex skip delete
5828@item skip delete @r{[}@var{range}@r{]}
5829Delete the specified skip(s). If @var{range} is not specified, delete all
5830skips.
5831
5832@kindex skip enable
5833@item skip enable @r{[}@var{range}@r{]}
5834Enable the specified skip(s). If @var{range} is not specified, enable all
5835skips.
5836
5837@kindex skip disable
5838@item skip disable @r{[}@var{range}@r{]}
5839Disable the specified skip(s). If @var{range} is not specified, disable all
5840skips.
5841
5842@end table
5843
6d2ebf8b 5844@node Signals
c906108c
SS
5845@section Signals
5846@cindex signals
5847
5848A signal is an asynchronous event that can happen in a program. The
5849operating system defines the possible kinds of signals, and gives each
5850kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 5851signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
5852@code{SIGSEGV} is the signal a program gets from referencing a place in
5853memory far away from all the areas in use; @code{SIGALRM} occurs when
5854the alarm clock timer goes off (which happens only if your program has
5855requested an alarm).
5856
5857@cindex fatal signals
5858Some signals, including @code{SIGALRM}, are a normal part of the
5859functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 5860errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
5861program has not specified in advance some other way to handle the signal.
5862@code{SIGINT} does not indicate an error in your program, but it is normally
5863fatal so it can carry out the purpose of the interrupt: to kill the program.
5864
5865@value{GDBN} has the ability to detect any occurrence of a signal in your
5866program. You can tell @value{GDBN} in advance what to do for each kind of
5867signal.
5868
5869@cindex handling signals
24f93129
EZ
5870Normally, @value{GDBN} is set up to let the non-erroneous signals like
5871@code{SIGALRM} be silently passed to your program
5872(so as not to interfere with their role in the program's functioning)
c906108c
SS
5873but to stop your program immediately whenever an error signal happens.
5874You can change these settings with the @code{handle} command.
5875
5876@table @code
5877@kindex info signals
09d4efe1 5878@kindex info handle
c906108c 5879@item info signals
96a2c332 5880@itemx info handle
c906108c
SS
5881Print a table of all the kinds of signals and how @value{GDBN} has been told to
5882handle each one. You can use this to see the signal numbers of all
5883the defined types of signals.
5884
45ac1734
EZ
5885@item info signals @var{sig}
5886Similar, but print information only about the specified signal number.
5887
d4f3574e 5888@code{info handle} is an alias for @code{info signals}.
c906108c 5889
ab04a2af
TT
5890@item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
5891Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
5892for details about this command.
5893
c906108c 5894@kindex handle
45ac1734 5895@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
697aa1b7 5896Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
5ece1a18 5897can be the number of a signal or its name (with or without the
24f93129 5898@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 5899@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
5900known signals. Optional arguments @var{keywords}, described below,
5901say what change to make.
c906108c
SS
5902@end table
5903
5904@c @group
5905The keywords allowed by the @code{handle} command can be abbreviated.
5906Their full names are:
5907
5908@table @code
5909@item nostop
5910@value{GDBN} should not stop your program when this signal happens. It may
5911still print a message telling you that the signal has come in.
5912
5913@item stop
5914@value{GDBN} should stop your program when this signal happens. This implies
5915the @code{print} keyword as well.
5916
5917@item print
5918@value{GDBN} should print a message when this signal happens.
5919
5920@item noprint
5921@value{GDBN} should not mention the occurrence of the signal at all. This
5922implies the @code{nostop} keyword as well.
5923
5924@item pass
5ece1a18 5925@itemx noignore
c906108c
SS
5926@value{GDBN} should allow your program to see this signal; your program
5927can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 5928and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
5929
5930@item nopass
5ece1a18 5931@itemx ignore
c906108c 5932@value{GDBN} should not allow your program to see this signal.
5ece1a18 5933@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
5934@end table
5935@c @end group
5936
d4f3574e
SS
5937When a signal stops your program, the signal is not visible to the
5938program until you
c906108c
SS
5939continue. Your program sees the signal then, if @code{pass} is in
5940effect for the signal in question @emph{at that time}. In other words,
5941after @value{GDBN} reports a signal, you can use the @code{handle}
5942command with @code{pass} or @code{nopass} to control whether your
5943program sees that signal when you continue.
5944
24f93129
EZ
5945The default is set to @code{nostop}, @code{noprint}, @code{pass} for
5946non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
5947@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
5948erroneous signals.
5949
c906108c
SS
5950You can also use the @code{signal} command to prevent your program from
5951seeing a signal, or cause it to see a signal it normally would not see,
5952or to give it any signal at any time. For example, if your program stopped
5953due to some sort of memory reference error, you might store correct
5954values into the erroneous variables and continue, hoping to see more
5955execution; but your program would probably terminate immediately as
5956a result of the fatal signal once it saw the signal. To prevent this,
5957you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
79a6e687 5958Program a Signal}.
c906108c 5959
e5f8a7cc
PA
5960@cindex stepping and signal handlers
5961@anchor{stepping and signal handlers}
5962
5963@value{GDBN} optimizes for stepping the mainline code. If a signal
5964that has @code{handle nostop} and @code{handle pass} set arrives while
5965a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
5966in progress, @value{GDBN} lets the signal handler run and then resumes
5967stepping the mainline code once the signal handler returns. In other
5968words, @value{GDBN} steps over the signal handler. This prevents
5969signals that you've specified as not interesting (with @code{handle
5970nostop}) from changing the focus of debugging unexpectedly. Note that
5971the signal handler itself may still hit a breakpoint, stop for another
5972signal that has @code{handle stop} in effect, or for any other event
5973that normally results in stopping the stepping command sooner. Also
5974note that @value{GDBN} still informs you that the program received a
5975signal if @code{handle print} is set.
5976
5977@anchor{stepping into signal handlers}
5978
5979If you set @code{handle pass} for a signal, and your program sets up a
5980handler for it, then issuing a stepping command, such as @code{step}
5981or @code{stepi}, when your program is stopped due to the signal will
5982step @emph{into} the signal handler (if the target supports that).
5983
5984Likewise, if you use the @code{queue-signal} command to queue a signal
5985to be delivered to the current thread when execution of the thread
5986resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
5987stepping command will step into the signal handler.
5988
5989Here's an example, using @code{stepi} to step to the first instruction
5990of @code{SIGUSR1}'s handler:
5991
5992@smallexample
5993(@value{GDBP}) handle SIGUSR1
5994Signal Stop Print Pass to program Description
5995SIGUSR1 Yes Yes Yes User defined signal 1
5996(@value{GDBP}) c
5997Continuing.
5998
5999Program received signal SIGUSR1, User defined signal 1.
6000main () sigusr1.c:28
600128 p = 0;
6002(@value{GDBP}) si
6003sigusr1_handler () at sigusr1.c:9
60049 @{
6005@end smallexample
6006
6007The same, but using @code{queue-signal} instead of waiting for the
6008program to receive the signal first:
6009
6010@smallexample
6011(@value{GDBP}) n
601228 p = 0;
6013(@value{GDBP}) queue-signal SIGUSR1
6014(@value{GDBP}) si
6015sigusr1_handler () at sigusr1.c:9
60169 @{
6017(@value{GDBP})
6018@end smallexample
6019
4aa995e1
PA
6020@cindex extra signal information
6021@anchor{extra signal information}
6022
6023On some targets, @value{GDBN} can inspect extra signal information
6024associated with the intercepted signal, before it is actually
6025delivered to the program being debugged. This information is exported
6026by the convenience variable @code{$_siginfo}, and consists of data
6027that is passed by the kernel to the signal handler at the time of the
6028receipt of a signal. The data type of the information itself is
6029target dependent. You can see the data type using the @code{ptype
6030$_siginfo} command. On Unix systems, it typically corresponds to the
6031standard @code{siginfo_t} type, as defined in the @file{signal.h}
6032system header.
6033
6034Here's an example, on a @sc{gnu}/Linux system, printing the stray
6035referenced address that raised a segmentation fault.
6036
6037@smallexample
6038@group
6039(@value{GDBP}) continue
6040Program received signal SIGSEGV, Segmentation fault.
60410x0000000000400766 in main ()
604269 *(int *)p = 0;
6043(@value{GDBP}) ptype $_siginfo
6044type = struct @{
6045 int si_signo;
6046 int si_errno;
6047 int si_code;
6048 union @{
6049 int _pad[28];
6050 struct @{...@} _kill;
6051 struct @{...@} _timer;
6052 struct @{...@} _rt;
6053 struct @{...@} _sigchld;
6054 struct @{...@} _sigfault;
6055 struct @{...@} _sigpoll;
6056 @} _sifields;
6057@}
6058(@value{GDBP}) ptype $_siginfo._sifields._sigfault
6059type = struct @{
6060 void *si_addr;
6061@}
6062(@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6063$1 = (void *) 0x7ffff7ff7000
6064@end group
6065@end smallexample
6066
6067Depending on target support, @code{$_siginfo} may also be writable.
6068
012b3a21
WT
6069@cindex Intel MPX boundary violations
6070@cindex boundary violations, Intel MPX
6071On some targets, a @code{SIGSEGV} can be caused by a boundary
6072violation, i.e., accessing an address outside of the allowed range.
6073In those cases @value{GDBN} may displays additional information,
6074depending on how @value{GDBN} has been told to handle the signal.
6075With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6076kind: "Upper" or "Lower", the memory address accessed and the
6077bounds, while with @code{handle nostop SIGSEGV} no additional
6078information is displayed.
6079
6080The usual output of a segfault is:
6081@smallexample
6082Program received signal SIGSEGV, Segmentation fault
60830x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
608468 value = *(p + len);
6085@end smallexample
6086
6087While a bound violation is presented as:
6088@smallexample
6089Program received signal SIGSEGV, Segmentation fault
6090Upper bound violation while accessing address 0x7fffffffc3b3
6091Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
60920x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
609368 value = *(p + len);
6094@end smallexample
6095
6d2ebf8b 6096@node Thread Stops
79a6e687 6097@section Stopping and Starting Multi-thread Programs
c906108c 6098
0606b73b
SL
6099@cindex stopped threads
6100@cindex threads, stopped
6101
6102@cindex continuing threads
6103@cindex threads, continuing
6104
6105@value{GDBN} supports debugging programs with multiple threads
6106(@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6107are two modes of controlling execution of your program within the
6108debugger. In the default mode, referred to as @dfn{all-stop mode},
6109when any thread in your program stops (for example, at a breakpoint
6110or while being stepped), all other threads in the program are also stopped by
6111@value{GDBN}. On some targets, @value{GDBN} also supports
6112@dfn{non-stop mode}, in which other threads can continue to run freely while
6113you examine the stopped thread in the debugger.
6114
6115@menu
6116* All-Stop Mode:: All threads stop when GDB takes control
6117* Non-Stop Mode:: Other threads continue to execute
6118* Background Execution:: Running your program asynchronously
6119* Thread-Specific Breakpoints:: Controlling breakpoints
6120* Interrupted System Calls:: GDB may interfere with system calls
d914c394 6121* Observer Mode:: GDB does not alter program behavior
0606b73b
SL
6122@end menu
6123
6124@node All-Stop Mode
6125@subsection All-Stop Mode
6126
6127@cindex all-stop mode
6128
6129In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6130@emph{all} threads of execution stop, not just the current thread. This
6131allows you to examine the overall state of the program, including
6132switching between threads, without worrying that things may change
6133underfoot.
6134
6135Conversely, whenever you restart the program, @emph{all} threads start
6136executing. @emph{This is true even when single-stepping} with commands
6137like @code{step} or @code{next}.
6138
6139In particular, @value{GDBN} cannot single-step all threads in lockstep.
6140Since thread scheduling is up to your debugging target's operating
6141system (not controlled by @value{GDBN}), other threads may
6142execute more than one statement while the current thread completes a
6143single step. Moreover, in general other threads stop in the middle of a
6144statement, rather than at a clean statement boundary, when the program
6145stops.
6146
6147You might even find your program stopped in another thread after
6148continuing or even single-stepping. This happens whenever some other
6149thread runs into a breakpoint, a signal, or an exception before the
6150first thread completes whatever you requested.
6151
6152@cindex automatic thread selection
6153@cindex switching threads automatically
6154@cindex threads, automatic switching
6155Whenever @value{GDBN} stops your program, due to a breakpoint or a
6156signal, it automatically selects the thread where that breakpoint or
6157signal happened. @value{GDBN} alerts you to the context switch with a
6158message such as @samp{[Switching to Thread @var{n}]} to identify the
6159thread.
6160
6161On some OSes, you can modify @value{GDBN}'s default behavior by
6162locking the OS scheduler to allow only a single thread to run.
6163
6164@table @code
6165@item set scheduler-locking @var{mode}
6166@cindex scheduler locking mode
6167@cindex lock scheduler
f2665db5
MM
6168Set the scheduler locking mode. It applies to normal execution,
6169record mode, and replay mode. If it is @code{off}, then there is no
6170locking and any thread may run at any time. If @code{on}, then only
6171the current thread may run when the inferior is resumed. The
6172@code{step} mode optimizes for single-stepping; it prevents other
6173threads from preempting the current thread while you are stepping, so
6174that the focus of debugging does not change unexpectedly. Other
6175threads never get a chance to run when you step, and they are
6176completely free to run when you use commands like @samp{continue},
6177@samp{until}, or @samp{finish}. However, unless another thread hits a
6178breakpoint during its timeslice, @value{GDBN} does not change the
6179current thread away from the thread that you are debugging. The
6180@code{replay} mode behaves like @code{off} in record mode and like
6181@code{on} in replay mode.
0606b73b
SL
6182
6183@item show scheduler-locking
6184Display the current scheduler locking mode.
6185@end table
6186
d4db2f36
PA
6187@cindex resume threads of multiple processes simultaneously
6188By default, when you issue one of the execution commands such as
6189@code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6190threads of the current inferior to run. For example, if @value{GDBN}
6191is attached to two inferiors, each with two threads, the
6192@code{continue} command resumes only the two threads of the current
6193inferior. This is useful, for example, when you debug a program that
6194forks and you want to hold the parent stopped (so that, for instance,
6195it doesn't run to exit), while you debug the child. In other
6196situations, you may not be interested in inspecting the current state
6197of any of the processes @value{GDBN} is attached to, and you may want
6198to resume them all until some breakpoint is hit. In the latter case,
6199you can instruct @value{GDBN} to allow all threads of all the
6200inferiors to run with the @w{@code{set schedule-multiple}} command.
6201
6202@table @code
6203@kindex set schedule-multiple
6204@item set schedule-multiple
6205Set the mode for allowing threads of multiple processes to be resumed
6206when an execution command is issued. When @code{on}, all threads of
6207all processes are allowed to run. When @code{off}, only the threads
6208of the current process are resumed. The default is @code{off}. The
6209@code{scheduler-locking} mode takes precedence when set to @code{on},
6210or while you are stepping and set to @code{step}.
6211
6212@item show schedule-multiple
6213Display the current mode for resuming the execution of threads of
6214multiple processes.
6215@end table
6216
0606b73b
SL
6217@node Non-Stop Mode
6218@subsection Non-Stop Mode
6219
6220@cindex non-stop mode
6221
6222@c This section is really only a place-holder, and needs to be expanded
97d8f0ee 6223@c with more details.
0606b73b
SL
6224
6225For some multi-threaded targets, @value{GDBN} supports an optional
6226mode of operation in which you can examine stopped program threads in
6227the debugger while other threads continue to execute freely. This
97d8f0ee
DE
6228minimizes intrusion when debugging live systems, such as programs
6229where some threads have real-time constraints or must continue to
0606b73b
SL
6230respond to external events. This is referred to as @dfn{non-stop} mode.
6231
6232In non-stop mode, when a thread stops to report a debugging event,
6233@emph{only} that thread is stopped; @value{GDBN} does not stop other
6234threads as well, in contrast to the all-stop mode behavior. Additionally,
6235execution commands such as @code{continue} and @code{step} apply by default
6236only to the current thread in non-stop mode, rather than all threads as
6237in all-stop mode. This allows you to control threads explicitly in
97d8f0ee 6238ways that are not possible in all-stop mode --- for example, stepping
0606b73b 6239one thread while allowing others to run freely, stepping
97d8f0ee 6240one thread while holding all others stopped, or stepping several threads
0606b73b
SL
6241independently and simultaneously.
6242
6243To enter non-stop mode, use this sequence of commands before you run
6244or attach to your program:
6245
0606b73b 6246@smallexample
0606b73b
SL
6247# If using the CLI, pagination breaks non-stop.
6248set pagination off
6249
6250# Finally, turn it on!
6251set non-stop on
6252@end smallexample
6253
6254You can use these commands to manipulate the non-stop mode setting:
6255
6256@table @code
6257@kindex set non-stop
6258@item set non-stop on
6259Enable selection of non-stop mode.
6260@item set non-stop off
6261Disable selection of non-stop mode.
6262@kindex show non-stop
6263@item show non-stop
6264Show the current non-stop enablement setting.
6265@end table
6266
6267Note these commands only reflect whether non-stop mode is enabled,
97d8f0ee 6268not whether the currently-executing program is being run in non-stop mode.
0606b73b 6269In particular, the @code{set non-stop} preference is only consulted when
97d8f0ee 6270@value{GDBN} starts or connects to the target program, and it is generally
0606b73b
SL
6271not possible to switch modes once debugging has started. Furthermore,
6272since not all targets support non-stop mode, even when you have enabled
6273non-stop mode, @value{GDBN} may still fall back to all-stop operation by
6274default.
6275
6276In non-stop mode, all execution commands apply only to the current thread
97d8f0ee 6277by default. That is, @code{continue} only continues one thread.
0606b73b
SL
6278To continue all threads, issue @code{continue -a} or @code{c -a}.
6279
97d8f0ee 6280You can use @value{GDBN}'s background execution commands
0606b73b 6281(@pxref{Background Execution}) to run some threads in the background
97d8f0ee 6282while you continue to examine or step others from @value{GDBN}.
0606b73b
SL
6283The MI execution commands (@pxref{GDB/MI Program Execution}) are
6284always executed asynchronously in non-stop mode.
6285
6286Suspending execution is done with the @code{interrupt} command when
97d8f0ee
DE
6287running in the background, or @kbd{Ctrl-c} during foreground execution.
6288In all-stop mode, this stops the whole process;
6289but in non-stop mode the interrupt applies only to the current thread.
0606b73b
SL
6290To stop the whole program, use @code{interrupt -a}.
6291
6292Other execution commands do not currently support the @code{-a} option.
6293
6294In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
6295that thread current, as it does in all-stop mode. This is because the
97d8f0ee 6296thread stop notifications are asynchronous with respect to @value{GDBN}'s
0606b73b
SL
6297command interpreter, and it would be confusing if @value{GDBN} unexpectedly
6298changed to a different thread just as you entered a command to operate on the
6299previously current thread.
6300
6301@node Background Execution
6302@subsection Background Execution
6303
6304@cindex foreground execution
6305@cindex background execution
6306@cindex asynchronous execution
6307@cindex execution, foreground, background and asynchronous
6308
6309@value{GDBN}'s execution commands have two variants: the normal
6310foreground (synchronous) behavior, and a background
97d8f0ee 6311(asynchronous) behavior. In foreground execution, @value{GDBN} waits for
0606b73b
SL
6312the program to report that some thread has stopped before prompting for
6313another command. In background execution, @value{GDBN} immediately gives
6314a command prompt so that you can issue other commands while your program runs.
6315
32fc0df9
PA
6316If the target doesn't support async mode, @value{GDBN} issues an error
6317message if you attempt to use the background execution commands.
6318
0606b73b
SL
6319To specify background execution, add a @code{&} to the command. For example,
6320the background form of the @code{continue} command is @code{continue&}, or
6321just @code{c&}. The execution commands that accept background execution
6322are:
6323
6324@table @code
6325@kindex run&
6326@item run
6327@xref{Starting, , Starting your Program}.
6328
6329@item attach
6330@kindex attach&
6331@xref{Attach, , Debugging an Already-running Process}.
6332
6333@item step
6334@kindex step&
6335@xref{Continuing and Stepping, step}.
6336
6337@item stepi
6338@kindex stepi&
6339@xref{Continuing and Stepping, stepi}.
6340
6341@item next
6342@kindex next&
6343@xref{Continuing and Stepping, next}.
6344
7ce58dd2
DE
6345@item nexti
6346@kindex nexti&
6347@xref{Continuing and Stepping, nexti}.
6348
0606b73b
SL
6349@item continue
6350@kindex continue&
6351@xref{Continuing and Stepping, continue}.
6352
6353@item finish
6354@kindex finish&
6355@xref{Continuing and Stepping, finish}.
6356
6357@item until
6358@kindex until&
6359@xref{Continuing and Stepping, until}.
6360
6361@end table
6362
6363Background execution is especially useful in conjunction with non-stop
6364mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
6365However, you can also use these commands in the normal all-stop mode with
6366the restriction that you cannot issue another execution command until the
6367previous one finishes. Examples of commands that are valid in all-stop
6368mode while the program is running include @code{help} and @code{info break}.
6369
6370You can interrupt your program while it is running in the background by
6371using the @code{interrupt} command.
6372
6373@table @code
6374@kindex interrupt
6375@item interrupt
6376@itemx interrupt -a
6377
97d8f0ee 6378Suspend execution of the running program. In all-stop mode,
0606b73b 6379@code{interrupt} stops the whole process, but in non-stop mode, it stops
97d8f0ee 6380only the current thread. To stop the whole program in non-stop mode,
0606b73b
SL
6381use @code{interrupt -a}.
6382@end table
6383
0606b73b
SL
6384@node Thread-Specific Breakpoints
6385@subsection Thread-Specific Breakpoints
6386
c906108c 6387When your program has multiple threads (@pxref{Threads,, Debugging
79a6e687 6388Programs with Multiple Threads}), you can choose whether to set
c906108c
SS
6389breakpoints on all threads, or on a particular thread.
6390
6391@table @code
6392@cindex breakpoints and threads
6393@cindex thread breakpoints
5d5658a1
PA
6394@kindex break @dots{} thread @var{thread-id}
6395@item break @var{location} thread @var{thread-id}
6396@itemx break @var{location} thread @var{thread-id} if @dots{}
629500fa 6397@var{location} specifies source lines; there are several ways of
2a25a5ba
EZ
6398writing them (@pxref{Specify Location}), but the effect is always to
6399specify some source line.
c906108c 6400
5d5658a1 6401Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
c906108c 6402to specify that you only want @value{GDBN} to stop the program when a
5d5658a1
PA
6403particular thread reaches this breakpoint. The @var{thread-id} specifier
6404is one of the thread identifiers assigned by @value{GDBN}, shown
697aa1b7 6405in the first column of the @samp{info threads} display.
c906108c 6406
5d5658a1 6407If you do not specify @samp{thread @var{thread-id}} when you set a
c906108c
SS
6408breakpoint, the breakpoint applies to @emph{all} threads of your
6409program.
6410
6411You can use the @code{thread} qualifier on conditional breakpoints as
5d5658a1 6412well; in this case, place @samp{thread @var{thread-id}} before or
b6199126 6413after the breakpoint condition, like this:
c906108c
SS
6414
6415@smallexample
2df3850c 6416(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
6417@end smallexample
6418
6419@end table
6420
f4fb82a1
PA
6421Thread-specific breakpoints are automatically deleted when
6422@value{GDBN} detects the corresponding thread is no longer in the
6423thread list. For example:
6424
6425@smallexample
6426(@value{GDBP}) c
6427Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
6428@end smallexample
6429
6430There are several ways for a thread to disappear, such as a regular
6431thread exit, but also when you detach from the process with the
6432@code{detach} command (@pxref{Attach, ,Debugging an Already-running
6433Process}), or if @value{GDBN} loses the remote connection
6434(@pxref{Remote Debugging}), etc. Note that with some targets,
6435@value{GDBN} is only able to detect a thread has exited when the user
6436explictly asks for the thread list with the @code{info threads}
6437command.
6438
0606b73b
SL
6439@node Interrupted System Calls
6440@subsection Interrupted System Calls
c906108c 6441
36d86913
MC
6442@cindex thread breakpoints and system calls
6443@cindex system calls and thread breakpoints
6444@cindex premature return from system calls
0606b73b
SL
6445There is an unfortunate side effect when using @value{GDBN} to debug
6446multi-threaded programs. If one thread stops for a
36d86913
MC
6447breakpoint, or for some other reason, and another thread is blocked in a
6448system call, then the system call may return prematurely. This is a
6449consequence of the interaction between multiple threads and the signals
6450that @value{GDBN} uses to implement breakpoints and other events that
6451stop execution.
6452
6453To handle this problem, your program should check the return value of
6454each system call and react appropriately. This is good programming
6455style anyways.
6456
6457For example, do not write code like this:
6458
6459@smallexample
6460 sleep (10);
6461@end smallexample
6462
6463The call to @code{sleep} will return early if a different thread stops
6464at a breakpoint or for some other reason.
6465
6466Instead, write this:
6467
6468@smallexample
6469 int unslept = 10;
6470 while (unslept > 0)
6471 unslept = sleep (unslept);
6472@end smallexample
6473
6474A system call is allowed to return early, so the system is still
6475conforming to its specification. But @value{GDBN} does cause your
6476multi-threaded program to behave differently than it would without
6477@value{GDBN}.
6478
6479Also, @value{GDBN} uses internal breakpoints in the thread library to
6480monitor certain events such as thread creation and thread destruction.
6481When such an event happens, a system call in another thread may return
6482prematurely, even though your program does not appear to stop.
6483
d914c394
SS
6484@node Observer Mode
6485@subsection Observer Mode
6486
6487If you want to build on non-stop mode and observe program behavior
6488without any chance of disruption by @value{GDBN}, you can set
6489variables to disable all of the debugger's attempts to modify state,
6490whether by writing memory, inserting breakpoints, etc. These operate
6491at a low level, intercepting operations from all commands.
6492
6493When all of these are set to @code{off}, then @value{GDBN} is said to
6494be @dfn{observer mode}. As a convenience, the variable
6495@code{observer} can be set to disable these, plus enable non-stop
6496mode.
6497
6498Note that @value{GDBN} will not prevent you from making nonsensical
6499combinations of these settings. For instance, if you have enabled
6500@code{may-insert-breakpoints} but disabled @code{may-write-memory},
6501then breakpoints that work by writing trap instructions into the code
6502stream will still not be able to be placed.
6503
6504@table @code
6505
6506@kindex observer
6507@item set observer on
6508@itemx set observer off
6509When set to @code{on}, this disables all the permission variables
6510below (except for @code{insert-fast-tracepoints}), plus enables
6511non-stop debugging. Setting this to @code{off} switches back to
6512normal debugging, though remaining in non-stop mode.
6513
6514@item show observer
6515Show whether observer mode is on or off.
6516
6517@kindex may-write-registers
6518@item set may-write-registers on
6519@itemx set may-write-registers off
6520This controls whether @value{GDBN} will attempt to alter the values of
6521registers, such as with assignment expressions in @code{print}, or the
6522@code{jump} command. It defaults to @code{on}.
6523
6524@item show may-write-registers
6525Show the current permission to write registers.
6526
6527@kindex may-write-memory
6528@item set may-write-memory on
6529@itemx set may-write-memory off
6530This controls whether @value{GDBN} will attempt to alter the contents
6531of memory, such as with assignment expressions in @code{print}. It
6532defaults to @code{on}.
6533
6534@item show may-write-memory
6535Show the current permission to write memory.
6536
6537@kindex may-insert-breakpoints
6538@item set may-insert-breakpoints on
6539@itemx set may-insert-breakpoints off
6540This controls whether @value{GDBN} will attempt to insert breakpoints.
6541This affects all breakpoints, including internal breakpoints defined
6542by @value{GDBN}. It defaults to @code{on}.
6543
6544@item show may-insert-breakpoints
6545Show the current permission to insert breakpoints.
6546
6547@kindex may-insert-tracepoints
6548@item set may-insert-tracepoints on
6549@itemx set may-insert-tracepoints off
6550This controls whether @value{GDBN} will attempt to insert (regular)
6551tracepoints at the beginning of a tracing experiment. It affects only
6552non-fast tracepoints, fast tracepoints being under the control of
6553@code{may-insert-fast-tracepoints}. It defaults to @code{on}.
6554
6555@item show may-insert-tracepoints
6556Show the current permission to insert tracepoints.
6557
6558@kindex may-insert-fast-tracepoints
6559@item set may-insert-fast-tracepoints on
6560@itemx set may-insert-fast-tracepoints off
6561This controls whether @value{GDBN} will attempt to insert fast
6562tracepoints at the beginning of a tracing experiment. It affects only
6563fast tracepoints, regular (non-fast) tracepoints being under the
6564control of @code{may-insert-tracepoints}. It defaults to @code{on}.
6565
6566@item show may-insert-fast-tracepoints
6567Show the current permission to insert fast tracepoints.
6568
6569@kindex may-interrupt
6570@item set may-interrupt on
6571@itemx set may-interrupt off
6572This controls whether @value{GDBN} will attempt to interrupt or stop
6573program execution. When this variable is @code{off}, the
6574@code{interrupt} command will have no effect, nor will
6575@kbd{Ctrl-c}. It defaults to @code{on}.
6576
6577@item show may-interrupt
6578Show the current permission to interrupt or stop the program.
6579
6580@end table
c906108c 6581
bacec72f
MS
6582@node Reverse Execution
6583@chapter Running programs backward
6584@cindex reverse execution
6585@cindex running programs backward
6586
6587When you are debugging a program, it is not unusual to realize that
6588you have gone too far, and some event of interest has already happened.
6589If the target environment supports it, @value{GDBN} can allow you to
6590``rewind'' the program by running it backward.
6591
6592A target environment that supports reverse execution should be able
6593to ``undo'' the changes in machine state that have taken place as the
6594program was executing normally. Variables, registers etc.@: should
6595revert to their previous values. Obviously this requires a great
6596deal of sophistication on the part of the target environment; not
6597all target environments can support reverse execution.
6598
6599When a program is executed in reverse, the instructions that
6600have most recently been executed are ``un-executed'', in reverse
6601order. The program counter runs backward, following the previous
6602thread of execution in reverse. As each instruction is ``un-executed'',
6603the values of memory and/or registers that were changed by that
6604instruction are reverted to their previous states. After executing
6605a piece of source code in reverse, all side effects of that code
6606should be ``undone'', and all variables should be returned to their
6607prior values@footnote{
6608Note that some side effects are easier to undo than others. For instance,
6609memory and registers are relatively easy, but device I/O is hard. Some
6610targets may be able undo things like device I/O, and some may not.
6611
6612The contract between @value{GDBN} and the reverse executing target
6613requires only that the target do something reasonable when
6614@value{GDBN} tells it to execute backwards, and then report the
6615results back to @value{GDBN}. Whatever the target reports back to
6616@value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
6617assumes that the memory and registers that the target reports are in a
6618consistant state, but @value{GDBN} accepts whatever it is given.
6619}.
6620
6621If you are debugging in a target environment that supports
6622reverse execution, @value{GDBN} provides the following commands.
6623
6624@table @code
6625@kindex reverse-continue
6626@kindex rc @r{(@code{reverse-continue})}
6627@item reverse-continue @r{[}@var{ignore-count}@r{]}
6628@itemx rc @r{[}@var{ignore-count}@r{]}
6629Beginning at the point where your program last stopped, start executing
6630in reverse. Reverse execution will stop for breakpoints and synchronous
6631exceptions (signals), just like normal execution. Behavior of
6632asynchronous signals depends on the target environment.
6633
6634@kindex reverse-step
6635@kindex rs @r{(@code{step})}
6636@item reverse-step @r{[}@var{count}@r{]}
6637Run the program backward until control reaches the start of a
6638different source line; then stop it, and return control to @value{GDBN}.
6639
6640Like the @code{step} command, @code{reverse-step} will only stop
6641at the beginning of a source line. It ``un-executes'' the previously
6642executed source line. If the previous source line included calls to
6643debuggable functions, @code{reverse-step} will step (backward) into
6644the called function, stopping at the beginning of the @emph{last}
6645statement in the called function (typically a return statement).
6646
6647Also, as with the @code{step} command, if non-debuggable functions are
6648called, @code{reverse-step} will run thru them backward without stopping.
6649
6650@kindex reverse-stepi
6651@kindex rsi @r{(@code{reverse-stepi})}
6652@item reverse-stepi @r{[}@var{count}@r{]}
6653Reverse-execute one machine instruction. Note that the instruction
6654to be reverse-executed is @emph{not} the one pointed to by the program
6655counter, but the instruction executed prior to that one. For instance,
6656if the last instruction was a jump, @code{reverse-stepi} will take you
6657back from the destination of the jump to the jump instruction itself.
6658
6659@kindex reverse-next
6660@kindex rn @r{(@code{reverse-next})}
6661@item reverse-next @r{[}@var{count}@r{]}
6662Run backward to the beginning of the previous line executed in
6663the current (innermost) stack frame. If the line contains function
6664calls, they will be ``un-executed'' without stopping. Starting from
6665the first line of a function, @code{reverse-next} will take you back
6666to the caller of that function, @emph{before} the function was called,
6667just as the normal @code{next} command would take you from the last
6668line of a function back to its return to its caller
16af530a 6669@footnote{Unless the code is too heavily optimized.}.
bacec72f
MS
6670
6671@kindex reverse-nexti
6672@kindex rni @r{(@code{reverse-nexti})}
6673@item reverse-nexti @r{[}@var{count}@r{]}
6674Like @code{nexti}, @code{reverse-nexti} executes a single instruction
6675in reverse, except that called functions are ``un-executed'' atomically.
6676That is, if the previously executed instruction was a return from
540aa8e7 6677another function, @code{reverse-nexti} will continue to execute
bacec72f
MS
6678in reverse until the call to that function (from the current stack
6679frame) is reached.
6680
6681@kindex reverse-finish
6682@item reverse-finish
6683Just as the @code{finish} command takes you to the point where the
6684current function returns, @code{reverse-finish} takes you to the point
6685where it was called. Instead of ending up at the end of the current
6686function invocation, you end up at the beginning.
6687
6688@kindex set exec-direction
6689@item set exec-direction
6690Set the direction of target execution.
984359d2 6691@item set exec-direction reverse
bacec72f
MS
6692@cindex execute forward or backward in time
6693@value{GDBN} will perform all execution commands in reverse, until the
6694exec-direction mode is changed to ``forward''. Affected commands include
6695@code{step, stepi, next, nexti, continue, and finish}. The @code{return}
6696command cannot be used in reverse mode.
6697@item set exec-direction forward
6698@value{GDBN} will perform all execution commands in the normal fashion.
6699This is the default.
6700@end table
6701
c906108c 6702
a2311334
EZ
6703@node Process Record and Replay
6704@chapter Recording Inferior's Execution and Replaying It
53cc454a
HZ
6705@cindex process record and replay
6706@cindex recording inferior's execution and replaying it
6707
8e05493c
EZ
6708On some platforms, @value{GDBN} provides a special @dfn{process record
6709and replay} target that can record a log of the process execution, and
6710replay it later with both forward and reverse execution commands.
a2311334
EZ
6711
6712@cindex replay mode
6713When this target is in use, if the execution log includes the record
6714for the next instruction, @value{GDBN} will debug in @dfn{replay
6715mode}. In the replay mode, the inferior does not really execute code
6716instructions. Instead, all the events that normally happen during
6717code execution are taken from the execution log. While code is not
6718really executed in replay mode, the values of registers (including the
6719program counter register) and the memory of the inferior are still
8e05493c
EZ
6720changed as they normally would. Their contents are taken from the
6721execution log.
a2311334
EZ
6722
6723@cindex record mode
6724If the record for the next instruction is not in the execution log,
6725@value{GDBN} will debug in @dfn{record mode}. In this mode, the
6726inferior executes normally, and @value{GDBN} records the execution log
6727for future replay.
6728
8e05493c
EZ
6729The process record and replay target supports reverse execution
6730(@pxref{Reverse Execution}), even if the platform on which the
6731inferior runs does not. However, the reverse execution is limited in
6732this case by the range of the instructions recorded in the execution
6733log. In other words, reverse execution on platforms that don't
6734support it directly can only be done in the replay mode.
6735
6736When debugging in the reverse direction, @value{GDBN} will work in
6737replay mode as long as the execution log includes the record for the
6738previous instruction; otherwise, it will work in record mode, if the
6739platform supports reverse execution, or stop if not.
6740
a2311334
EZ
6741For architecture environments that support process record and replay,
6742@value{GDBN} provides the following commands:
53cc454a
HZ
6743
6744@table @code
6745@kindex target record
59ea5688
MM
6746@kindex target record-full
6747@kindex target record-btrace
53cc454a 6748@kindex record
59ea5688
MM
6749@kindex record full
6750@kindex record btrace
f4abbc16 6751@kindex record btrace bts
b20a6524 6752@kindex record btrace pt
f4abbc16 6753@kindex record bts
b20a6524 6754@kindex record pt
53cc454a 6755@kindex rec
59ea5688
MM
6756@kindex rec full
6757@kindex rec btrace
f4abbc16 6758@kindex rec btrace bts
b20a6524 6759@kindex rec btrace pt
f4abbc16 6760@kindex rec bts
b20a6524 6761@kindex rec pt
59ea5688
MM
6762@item record @var{method}
6763This command starts the process record and replay target. The
6764recording method can be specified as parameter. Without a parameter
6765the command uses the @code{full} recording method. The following
6766recording methods are available:
a2311334 6767
59ea5688
MM
6768@table @code
6769@item full
6770Full record/replay recording using @value{GDBN}'s software record and
6771replay implementation. This method allows replaying and reverse
6772execution.
6773
f4abbc16 6774@item btrace @var{format}
52834460
MM
6775Hardware-supported instruction recording. This method does not record
6776data. Further, the data is collected in a ring buffer so old data will
b20a6524
MM
6777be overwritten when the buffer is full. It allows limited reverse
6778execution. Variables and registers are not available during reverse
c0272db5
TW
6779execution. In remote debugging, recording continues on disconnect.
6780Recorded data can be inspected after reconnecting. The recording may
6781be stopped using @code{record stop}.
59ea5688 6782
f4abbc16
MM
6783The recording format can be specified as parameter. Without a parameter
6784the command chooses the recording format. The following recording
6785formats are available:
6786
6787@table @code
6788@item bts
6789@cindex branch trace store
6790Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
6791this format, the processor stores a from/to record for each executed
6792branch in the btrace ring buffer.
b20a6524
MM
6793
6794@item pt
bc504a31
PA
6795@cindex Intel Processor Trace
6796Use the @dfn{Intel Processor Trace} recording format. In this
b20a6524
MM
6797format, the processor stores the execution trace in a compressed form
6798that is afterwards decoded by @value{GDBN}.
6799
6800The trace can be recorded with very low overhead. The compressed
6801trace format also allows small trace buffers to already contain a big
6802number of instructions compared to @acronym{BTS}.
6803
6804Decoding the recorded execution trace, on the other hand, is more
6805expensive than decoding @acronym{BTS} trace. This is mostly due to the
6806increased number of instructions to process. You should increase the
6807buffer-size with care.
f4abbc16
MM
6808@end table
6809
6810Not all recording formats may be available on all processors.
59ea5688
MM
6811@end table
6812
6813The process record and replay target can only debug a process that is
6814already running. Therefore, you need first to start the process with
6815the @kbd{run} or @kbd{start} commands, and then start the recording
6816with the @kbd{record @var{method}} command.
6817
a2311334
EZ
6818@cindex displaced stepping, and process record and replay
6819Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
6820will be automatically disabled when process record and replay target
6821is started. That's because the process record and replay target
6822doesn't support displaced stepping.
6823
6824@cindex non-stop mode, and process record and replay
6825@cindex asynchronous execution, and process record and replay
6826If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
59ea5688
MM
6827the asynchronous execution mode (@pxref{Background Execution}), not
6828all recording methods are available. The @code{full} recording method
6829does not support these two modes.
53cc454a
HZ
6830
6831@kindex record stop
6832@kindex rec s
6833@item record stop
a2311334
EZ
6834Stop the process record and replay target. When process record and
6835replay target stops, the entire execution log will be deleted and the
6836inferior will either be terminated, or will remain in its final state.
53cc454a 6837
a2311334
EZ
6838When you stop the process record and replay target in record mode (at
6839the end of the execution log), the inferior will be stopped at the
6840next instruction that would have been recorded. In other words, if
6841you record for a while and then stop recording, the inferior process
6842will be left in the same state as if the recording never happened.
53cc454a 6843
a2311334
EZ
6844On the other hand, if the process record and replay target is stopped
6845while in replay mode (that is, not at the end of the execution log,
6846but at some earlier point), the inferior process will become ``live''
6847at that earlier state, and it will then be possible to continue the
6848usual ``live'' debugging of the process from that state.
53cc454a 6849
a2311334
EZ
6850When the inferior process exits, or @value{GDBN} detaches from it,
6851process record and replay target will automatically stop itself.
53cc454a 6852
742ce053
MM
6853@kindex record goto
6854@item record goto
6855Go to a specific location in the execution log. There are several
6856ways to specify the location to go to:
6857
6858@table @code
6859@item record goto begin
6860@itemx record goto start
6861Go to the beginning of the execution log.
6862
6863@item record goto end
6864Go to the end of the execution log.
6865
6866@item record goto @var{n}
6867Go to instruction number @var{n} in the execution log.
6868@end table
6869
24e933df
HZ
6870@kindex record save
6871@item record save @var{filename}
6872Save the execution log to a file @file{@var{filename}}.
6873Default filename is @file{gdb_record.@var{process_id}}, where
6874@var{process_id} is the process ID of the inferior.
6875
59ea5688
MM
6876This command may not be available for all recording methods.
6877
24e933df
HZ
6878@kindex record restore
6879@item record restore @var{filename}
6880Restore the execution log from a file @file{@var{filename}}.
6881File must have been created with @code{record save}.
6882
59ea5688
MM
6883@kindex set record full
6884@item set record full insn-number-max @var{limit}
f81d1120 6885@itemx set record full insn-number-max unlimited
59ea5688
MM
6886Set the limit of instructions to be recorded for the @code{full}
6887recording method. Default value is 200000.
53cc454a 6888
a2311334
EZ
6889If @var{limit} is a positive number, then @value{GDBN} will start
6890deleting instructions from the log once the number of the record
6891instructions becomes greater than @var{limit}. For every new recorded
6892instruction, @value{GDBN} will delete the earliest recorded
6893instruction to keep the number of recorded instructions at the limit.
6894(Since deleting recorded instructions loses information, @value{GDBN}
6895lets you control what happens when the limit is reached, by means of
6896the @code{stop-at-limit} option, described below.)
53cc454a 6897
f81d1120
PA
6898If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
6899delete recorded instructions from the execution log. The number of
6900recorded instructions is limited only by the available memory.
53cc454a 6901
59ea5688
MM
6902@kindex show record full
6903@item show record full insn-number-max
6904Show the limit of instructions to be recorded with the @code{full}
6905recording method.
53cc454a 6906
59ea5688
MM
6907@item set record full stop-at-limit
6908Control the behavior of the @code{full} recording method when the
6909number of recorded instructions reaches the limit. If ON (the
6910default), @value{GDBN} will stop when the limit is reached for the
6911first time and ask you whether you want to stop the inferior or
6912continue running it and recording the execution log. If you decide
6913to continue recording, each new recorded instruction will cause the
6914oldest one to be deleted.
53cc454a 6915
a2311334
EZ
6916If this option is OFF, @value{GDBN} will automatically delete the
6917oldest record to make room for each new one, without asking.
53cc454a 6918
59ea5688 6919@item show record full stop-at-limit
a2311334 6920Show the current setting of @code{stop-at-limit}.
53cc454a 6921
59ea5688 6922@item set record full memory-query
bb08c432 6923Control the behavior when @value{GDBN} is unable to record memory
59ea5688
MM
6924changes caused by an instruction for the @code{full} recording method.
6925If ON, @value{GDBN} will query whether to stop the inferior in that
6926case.
bb08c432
HZ
6927
6928If this option is OFF (the default), @value{GDBN} will automatically
6929ignore the effect of such instructions on memory. Later, when
6930@value{GDBN} replays this execution log, it will mark the log of this
6931instruction as not accessible, and it will not affect the replay
6932results.
6933
59ea5688 6934@item show record full memory-query
bb08c432
HZ
6935Show the current setting of @code{memory-query}.
6936
67b5c0c1
MM
6937@kindex set record btrace
6938The @code{btrace} record target does not trace data. As a
6939convenience, when replaying, @value{GDBN} reads read-only memory off
6940the live program directly, assuming that the addresses of the
6941read-only areas don't change. This for example makes it possible to
6942disassemble code while replaying, but not to print variables.
6943In some cases, being able to inspect variables might be useful.
6944You can use the following command for that:
6945
6946@item set record btrace replay-memory-access
6947Control the behavior of the @code{btrace} recording method when
6948accessing memory during replay. If @code{read-only} (the default),
6949@value{GDBN} will only allow accesses to read-only memory.
6950If @code{read-write}, @value{GDBN} will allow accesses to read-only
6951and to read-write memory. Beware that the accessed memory corresponds
6952to the live target and not necessarily to the current replay
6953position.
6954
6955@kindex show record btrace
6956@item show record btrace replay-memory-access
6957Show the current setting of @code{replay-memory-access}.
6958
d33501a5
MM
6959@kindex set record btrace bts
6960@item set record btrace bts buffer-size @var{size}
6961@itemx set record btrace bts buffer-size unlimited
6962Set the requested ring buffer size for branch tracing in @acronym{BTS}
6963format. Default is 64KB.
6964
6965If @var{size} is a positive number, then @value{GDBN} will try to
6966allocate a buffer of at least @var{size} bytes for each new thread
6967that uses the btrace recording method and the @acronym{BTS} format.
6968The actually obtained buffer size may differ from the requested
6969@var{size}. Use the @code{info record} command to see the actual
6970buffer size for each thread that uses the btrace recording method and
6971the @acronym{BTS} format.
6972
6973If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
6974allocate a buffer of 4MB.
6975
6976Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
6977also need longer to process the branch trace data before it can be used.
6978
6979@item show record btrace bts buffer-size @var{size}
6980Show the current setting of the requested ring buffer size for branch
6981tracing in @acronym{BTS} format.
6982
b20a6524
MM
6983@kindex set record btrace pt
6984@item set record btrace pt buffer-size @var{size}
6985@itemx set record btrace pt buffer-size unlimited
bc504a31 6986Set the requested ring buffer size for branch tracing in Intel
b20a6524
MM
6987Processor Trace format. Default is 16KB.
6988
6989If @var{size} is a positive number, then @value{GDBN} will try to
6990allocate a buffer of at least @var{size} bytes for each new thread
bc504a31 6991that uses the btrace recording method and the Intel Processor Trace
b20a6524
MM
6992format. The actually obtained buffer size may differ from the
6993requested @var{size}. Use the @code{info record} command to see the
6994actual buffer size for each thread.
6995
6996If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
6997allocate a buffer of 4MB.
6998
6999Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7000also need longer to process the branch trace data before it can be used.
7001
7002@item show record btrace pt buffer-size @var{size}
7003Show the current setting of the requested ring buffer size for branch
bc504a31 7004tracing in Intel Processor Trace format.
b20a6524 7005
29153c24
MS
7006@kindex info record
7007@item info record
59ea5688
MM
7008Show various statistics about the recording depending on the recording
7009method:
7010
7011@table @code
7012@item full
7013For the @code{full} recording method, it shows the state of process
7014record and its in-memory execution log buffer, including:
29153c24
MS
7015
7016@itemize @bullet
7017@item
7018Whether in record mode or replay mode.
7019@item
7020Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7021@item
7022Highest recorded instruction number.
7023@item
7024Current instruction about to be replayed (if in replay mode).
7025@item
7026Number of instructions contained in the execution log.
7027@item
7028Maximum number of instructions that may be contained in the execution log.
7029@end itemize
53cc454a 7030
59ea5688 7031@item btrace
d33501a5
MM
7032For the @code{btrace} recording method, it shows:
7033
7034@itemize @bullet
7035@item
7036Recording format.
7037@item
7038Number of instructions that have been recorded.
7039@item
7040Number of blocks of sequential control-flow formed by the recorded
7041instructions.
7042@item
7043Whether in record mode or replay mode.
7044@end itemize
7045
7046For the @code{bts} recording format, it also shows:
7047@itemize @bullet
7048@item
7049Size of the perf ring buffer.
7050@end itemize
b20a6524
MM
7051
7052For the @code{pt} recording format, it also shows:
7053@itemize @bullet
7054@item
7055Size of the perf ring buffer.
7056@end itemize
59ea5688
MM
7057@end table
7058
53cc454a
HZ
7059@kindex record delete
7060@kindex rec del
7061@item record delete
a2311334 7062When record target runs in replay mode (``in the past''), delete the
53cc454a 7063subsequent execution log and begin to record a new execution log starting
a2311334 7064from the current address. This means you will abandon the previously
53cc454a 7065recorded ``future'' and begin recording a new ``future''.
59ea5688
MM
7066
7067@kindex record instruction-history
7068@kindex rec instruction-history
7069@item record instruction-history
7070Disassembles instructions from the recorded execution log. By
7071default, ten instructions are disassembled. This can be changed using
7072the @code{set record instruction-history-size} command. Instructions
da8c46d2
MM
7073are printed in execution order.
7074
0c532a29
MM
7075It can also print mixed source+disassembly if you specify the the
7076@code{/m} or @code{/s} modifier, and print the raw instructions in hex
7077as well as in symbolic form by specifying the @code{/r} modifier.
7078
7079The current position marker is printed for the instruction at the
7080current program counter value. This instruction can appear multiple
7081times in the trace and the current position marker will be printed
7082every time. To omit the current position marker, specify the
7083@code{/p} modifier.
7084
7085To better align the printed instructions when the trace contains
7086instructions from more than one function, the function name may be
7087omitted by specifying the @code{/f} modifier.
7088
da8c46d2
MM
7089Speculatively executed instructions are prefixed with @samp{?}. This
7090feature is not available for all recording formats.
7091
7092There are several ways to specify what part of the execution log to
7093disassemble:
59ea5688
MM
7094
7095@table @code
7096@item record instruction-history @var{insn}
7097Disassembles ten instructions starting from instruction number
7098@var{insn}.
7099
7100@item record instruction-history @var{insn}, +/-@var{n}
7101Disassembles @var{n} instructions around instruction number
7102@var{insn}. If @var{n} is preceded with @code{+}, disassembles
7103@var{n} instructions after instruction number @var{insn}. If
7104@var{n} is preceded with @code{-}, disassembles @var{n}
7105instructions before instruction number @var{insn}.
7106
7107@item record instruction-history
7108Disassembles ten more instructions after the last disassembly.
7109
7110@item record instruction-history -
7111Disassembles ten more instructions before the last disassembly.
7112
792005b0 7113@item record instruction-history @var{begin}, @var{end}
59ea5688
MM
7114Disassembles instructions beginning with instruction number
7115@var{begin} until instruction number @var{end}. The instruction
0688d04e 7116number @var{end} is included.
59ea5688
MM
7117@end table
7118
7119This command may not be available for all recording methods.
7120
7121@kindex set record
f81d1120
PA
7122@item set record instruction-history-size @var{size}
7123@itemx set record instruction-history-size unlimited
59ea5688
MM
7124Define how many instructions to disassemble in the @code{record
7125instruction-history} command. The default value is 10.
f81d1120 7126A @var{size} of @code{unlimited} means unlimited instructions.
59ea5688
MM
7127
7128@kindex show record
7129@item show record instruction-history-size
7130Show how many instructions to disassemble in the @code{record
7131instruction-history} command.
7132
7133@kindex record function-call-history
7134@kindex rec function-call-history
7135@item record function-call-history
7136Prints the execution history at function granularity. It prints one
7137line for each sequence of instructions that belong to the same
7138function giving the name of that function, the source lines
7139for this instruction sequence (if the @code{/l} modifier is
7140specified), and the instructions numbers that form the sequence (if
8710b709
MM
7141the @code{/i} modifier is specified). The function names are indented
7142to reflect the call stack depth if the @code{/c} modifier is
7143specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be
7144given together.
59ea5688
MM
7145
7146@smallexample
7147(@value{GDBP}) @b{list 1, 10}
71481 void foo (void)
71492 @{
71503 @}
71514
71525 void bar (void)
71536 @{
71547 ...
71558 foo ();
71569 ...
715710 @}
8710b709
MM
7158(@value{GDBP}) @b{record function-call-history /ilc}
71591 bar inst 1,4 at foo.c:6,8
71602 foo inst 5,10 at foo.c:2,3
71613 bar inst 11,13 at foo.c:9,10
59ea5688
MM
7162@end smallexample
7163
7164By default, ten lines are printed. This can be changed using the
7165@code{set record function-call-history-size} command. Functions are
7166printed in execution order. There are several ways to specify what
7167to print:
7168
7169@table @code
7170@item record function-call-history @var{func}
7171Prints ten functions starting from function number @var{func}.
7172
7173@item record function-call-history @var{func}, +/-@var{n}
7174Prints @var{n} functions around function number @var{func}. If
7175@var{n} is preceded with @code{+}, prints @var{n} functions after
7176function number @var{func}. If @var{n} is preceded with @code{-},
7177prints @var{n} functions before function number @var{func}.
7178
7179@item record function-call-history
7180Prints ten more functions after the last ten-line print.
7181
7182@item record function-call-history -
7183Prints ten more functions before the last ten-line print.
7184
792005b0 7185@item record function-call-history @var{begin}, @var{end}
59ea5688 7186Prints functions beginning with function number @var{begin} until
0688d04e 7187function number @var{end}. The function number @var{end} is included.
59ea5688
MM
7188@end table
7189
7190This command may not be available for all recording methods.
7191
f81d1120
PA
7192@item set record function-call-history-size @var{size}
7193@itemx set record function-call-history-size unlimited
59ea5688
MM
7194Define how many lines to print in the
7195@code{record function-call-history} command. The default value is 10.
f81d1120 7196A size of @code{unlimited} means unlimited lines.
59ea5688
MM
7197
7198@item show record function-call-history-size
7199Show how many lines to print in the
7200@code{record function-call-history} command.
53cc454a
HZ
7201@end table
7202
7203
6d2ebf8b 7204@node Stack
c906108c
SS
7205@chapter Examining the Stack
7206
7207When your program has stopped, the first thing you need to know is where it
7208stopped and how it got there.
7209
7210@cindex call stack
5d161b24
DB
7211Each time your program performs a function call, information about the call
7212is generated.
7213That information includes the location of the call in your program,
7214the arguments of the call,
c906108c 7215and the local variables of the function being called.
5d161b24 7216The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
7217The stack frames are allocated in a region of memory called the @dfn{call
7218stack}.
7219
7220When your program stops, the @value{GDBN} commands for examining the
7221stack allow you to see all of this information.
7222
7223@cindex selected frame
7224One of the stack frames is @dfn{selected} by @value{GDBN} and many
7225@value{GDBN} commands refer implicitly to the selected frame. In
7226particular, whenever you ask @value{GDBN} for the value of a variable in
7227your program, the value is found in the selected frame. There are
7228special @value{GDBN} commands to select whichever frame you are
79a6e687 7229interested in. @xref{Selection, ,Selecting a Frame}.
c906108c
SS
7230
7231When your program stops, @value{GDBN} automatically selects the
5d161b24 7232currently executing frame and describes it briefly, similar to the
79a6e687 7233@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
c906108c
SS
7234
7235@menu
7236* Frames:: Stack frames
7237* Backtrace:: Backtraces
7238* Selection:: Selecting a frame
7239* Frame Info:: Information on a frame
0f59c28f 7240* Frame Filter Management:: Managing frame filters
c906108c
SS
7241
7242@end menu
7243
6d2ebf8b 7244@node Frames
79a6e687 7245@section Stack Frames
c906108c 7246
d4f3574e 7247@cindex frame, definition
c906108c
SS
7248@cindex stack frame
7249The call stack is divided up into contiguous pieces called @dfn{stack
7250frames}, or @dfn{frames} for short; each frame is the data associated
7251with one call to one function. The frame contains the arguments given
7252to the function, the function's local variables, and the address at
7253which the function is executing.
7254
7255@cindex initial frame
7256@cindex outermost frame
7257@cindex innermost frame
7258When your program is started, the stack has only one frame, that of the
7259function @code{main}. This is called the @dfn{initial} frame or the
7260@dfn{outermost} frame. Each time a function is called, a new frame is
7261made. Each time a function returns, the frame for that function invocation
7262is eliminated. If a function is recursive, there can be many frames for
7263the same function. The frame for the function in which execution is
7264actually occurring is called the @dfn{innermost} frame. This is the most
7265recently created of all the stack frames that still exist.
7266
7267@cindex frame pointer
7268Inside your program, stack frames are identified by their addresses. A
7269stack frame consists of many bytes, each of which has its own address; each
7270kind of computer has a convention for choosing one byte whose
7271address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
7272in a register called the @dfn{frame pointer register}
7273(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
7274
7275@cindex frame number
7276@value{GDBN} assigns numbers to all existing stack frames, starting with
7277zero for the innermost frame, one for the frame that called it,
7278and so on upward. These numbers do not really exist in your program;
7279they are assigned by @value{GDBN} to give you a way of designating stack
7280frames in @value{GDBN} commands.
7281
6d2ebf8b
SS
7282@c The -fomit-frame-pointer below perennially causes hbox overflow
7283@c underflow problems.
c906108c
SS
7284@cindex frameless execution
7285Some compilers provide a way to compile functions so that they operate
e22ea452 7286without stack frames. (For example, the @value{NGCC} option
474c8240 7287@smallexample
6d2ebf8b 7288@samp{-fomit-frame-pointer}
474c8240 7289@end smallexample
6d2ebf8b 7290generates functions without a frame.)
c906108c
SS
7291This is occasionally done with heavily used library functions to save
7292the frame setup time. @value{GDBN} has limited facilities for dealing
7293with these function invocations. If the innermost function invocation
7294has no stack frame, @value{GDBN} nevertheless regards it as though
7295it had a separate frame, which is numbered zero as usual, allowing
7296correct tracing of the function call chain. However, @value{GDBN} has
7297no provision for frameless functions elsewhere in the stack.
7298
6d2ebf8b 7299@node Backtrace
c906108c
SS
7300@section Backtraces
7301
09d4efe1
EZ
7302@cindex traceback
7303@cindex call stack traces
c906108c
SS
7304A backtrace is a summary of how your program got where it is. It shows one
7305line per frame, for many frames, starting with the currently executing
7306frame (frame zero), followed by its caller (frame one), and on up the
7307stack.
7308
1e611234 7309@anchor{backtrace-command}
c906108c
SS
7310@table @code
7311@kindex backtrace
41afff9a 7312@kindex bt @r{(@code{backtrace})}
c906108c
SS
7313@item backtrace
7314@itemx bt
7315Print a backtrace of the entire stack: one line per frame for all
7316frames in the stack.
7317
7318You can stop the backtrace at any time by typing the system interrupt
c8aa23ab 7319character, normally @kbd{Ctrl-c}.
c906108c
SS
7320
7321@item backtrace @var{n}
7322@itemx bt @var{n}
7323Similar, but print only the innermost @var{n} frames.
7324
7325@item backtrace -@var{n}
7326@itemx bt -@var{n}
7327Similar, but print only the outermost @var{n} frames.
0f061b69
NR
7328
7329@item backtrace full
0f061b69 7330@itemx bt full
dd74f6ae
NR
7331@itemx bt full @var{n}
7332@itemx bt full -@var{n}
697aa1b7
EZ
7333Print the values of the local variables also. As described above,
7334@var{n} specifies the number of frames to print.
1e611234
PM
7335
7336@item backtrace no-filters
7337@itemx bt no-filters
7338@itemx bt no-filters @var{n}
7339@itemx bt no-filters -@var{n}
7340@itemx bt no-filters full
7341@itemx bt no-filters full @var{n}
7342@itemx bt no-filters full -@var{n}
7343Do not run Python frame filters on this backtrace. @xref{Frame
7344Filter API}, for more information. Additionally use @ref{disable
7345frame-filter all} to turn off all frame filters. This is only
7346relevant when @value{GDBN} has been configured with @code{Python}
7347support.
c906108c
SS
7348@end table
7349
7350@kindex where
7351@kindex info stack
c906108c
SS
7352The names @code{where} and @code{info stack} (abbreviated @code{info s})
7353are additional aliases for @code{backtrace}.
7354
839c27b7
EZ
7355@cindex multiple threads, backtrace
7356In a multi-threaded program, @value{GDBN} by default shows the
7357backtrace only for the current thread. To display the backtrace for
7358several or all of the threads, use the command @code{thread apply}
7359(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
7360apply all backtrace}, @value{GDBN} will display the backtrace for all
7361the threads; this is handy when you debug a core dump of a
7362multi-threaded program.
7363
c906108c
SS
7364Each line in the backtrace shows the frame number and the function name.
7365The program counter value is also shown---unless you use @code{set
7366print address off}. The backtrace also shows the source file name and
7367line number, as well as the arguments to the function. The program
7368counter value is omitted if it is at the beginning of the code for that
7369line number.
7370
7371Here is an example of a backtrace. It was made with the command
7372@samp{bt 3}, so it shows the innermost three frames.
7373
7374@smallexample
7375@group
5d161b24 7376#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c 7377 at builtin.c:993
4f5376b2 7378#1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
c906108c
SS
7379#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
7380 at macro.c:71
7381(More stack frames follow...)
7382@end group
7383@end smallexample
7384
7385@noindent
7386The display for frame zero does not begin with a program counter
7387value, indicating that your program has stopped at the beginning of the
7388code for line @code{993} of @code{builtin.c}.
7389
4f5376b2
JB
7390@noindent
7391The value of parameter @code{data} in frame 1 has been replaced by
7392@code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
7393only if it is a scalar (integer, pointer, enumeration, etc). See command
7394@kbd{set print frame-arguments} in @ref{Print Settings} for more details
7395on how to configure the way function parameter values are printed.
7396
585fdaa1 7397@cindex optimized out, in backtrace
18999be5
EZ
7398@cindex function call arguments, optimized out
7399If your program was compiled with optimizations, some compilers will
7400optimize away arguments passed to functions if those arguments are
7401never used after the call. Such optimizations generate code that
7402passes arguments through registers, but doesn't store those arguments
7403in the stack frame. @value{GDBN} has no way of displaying such
7404arguments in stack frames other than the innermost one. Here's what
7405such a backtrace might look like:
7406
7407@smallexample
7408@group
7409#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
7410 at builtin.c:993
585fdaa1
PA
7411#1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
7412#2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
18999be5
EZ
7413 at macro.c:71
7414(More stack frames follow...)
7415@end group
7416@end smallexample
7417
7418@noindent
7419The values of arguments that were not saved in their stack frames are
585fdaa1 7420shown as @samp{<optimized out>}.
18999be5
EZ
7421
7422If you need to display the values of such optimized-out arguments,
7423either deduce that from other variables whose values depend on the one
7424you are interested in, or recompile without optimizations.
7425
a8f24a35
EZ
7426@cindex backtrace beyond @code{main} function
7427@cindex program entry point
7428@cindex startup code, and backtrace
25d29d70
AC
7429Most programs have a standard user entry point---a place where system
7430libraries and startup code transition into user code. For C this is
d416eeec
EZ
7431@code{main}@footnote{
7432Note that embedded programs (the so-called ``free-standing''
7433environment) are not required to have a @code{main} function as the
7434entry point. They could even have multiple entry points.}.
7435When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
7436it will terminate the backtrace, to avoid tracing into highly
7437system-specific (and generally uninteresting) code.
7438
7439If you need to examine the startup code, or limit the number of levels
7440in a backtrace, you can change this behavior:
95f90d25
DJ
7441
7442@table @code
25d29d70
AC
7443@item set backtrace past-main
7444@itemx set backtrace past-main on
4644b6e3 7445@kindex set backtrace
25d29d70
AC
7446Backtraces will continue past the user entry point.
7447
7448@item set backtrace past-main off
95f90d25
DJ
7449Backtraces will stop when they encounter the user entry point. This is the
7450default.
7451
25d29d70 7452@item show backtrace past-main
4644b6e3 7453@kindex show backtrace
25d29d70
AC
7454Display the current user entry point backtrace policy.
7455
2315ffec
RC
7456@item set backtrace past-entry
7457@itemx set backtrace past-entry on
a8f24a35 7458Backtraces will continue past the internal entry point of an application.
2315ffec
RC
7459This entry point is encoded by the linker when the application is built,
7460and is likely before the user entry point @code{main} (or equivalent) is called.
7461
7462@item set backtrace past-entry off
d3e8051b 7463Backtraces will stop when they encounter the internal entry point of an
2315ffec
RC
7464application. This is the default.
7465
7466@item show backtrace past-entry
7467Display the current internal entry point backtrace policy.
7468
25d29d70
AC
7469@item set backtrace limit @var{n}
7470@itemx set backtrace limit 0
f81d1120 7471@itemx set backtrace limit unlimited
25d29d70 7472@cindex backtrace limit
f81d1120
PA
7473Limit the backtrace to @var{n} levels. A value of @code{unlimited}
7474or zero means unlimited levels.
95f90d25 7475
25d29d70
AC
7476@item show backtrace limit
7477Display the current limit on backtrace levels.
95f90d25
DJ
7478@end table
7479
1b56eb55
JK
7480You can control how file names are displayed.
7481
7482@table @code
7483@item set filename-display
7484@itemx set filename-display relative
7485@cindex filename-display
7486Display file names relative to the compilation directory. This is the default.
7487
7488@item set filename-display basename
7489Display only basename of a filename.
7490
7491@item set filename-display absolute
7492Display an absolute filename.
7493
7494@item show filename-display
7495Show the current way to display filenames.
7496@end table
7497
6d2ebf8b 7498@node Selection
79a6e687 7499@section Selecting a Frame
c906108c
SS
7500
7501Most commands for examining the stack and other data in your program work on
7502whichever stack frame is selected at the moment. Here are the commands for
7503selecting a stack frame; all of them finish by printing a brief description
7504of the stack frame just selected.
7505
7506@table @code
d4f3574e 7507@kindex frame@r{, selecting}
41afff9a 7508@kindex f @r{(@code{frame})}
c906108c
SS
7509@item frame @var{n}
7510@itemx f @var{n}
7511Select frame number @var{n}. Recall that frame zero is the innermost
7512(currently executing) frame, frame one is the frame that called the
7513innermost one, and so on. The highest-numbered frame is the one for
7514@code{main}.
7515
7c7f93f6
AB
7516@item frame @var{stack-addr} [ @var{pc-addr} ]
7517@itemx f @var{stack-addr} [ @var{pc-addr} ]
7518Select the frame at address @var{stack-addr}. This is useful mainly if the
c906108c
SS
7519chaining of stack frames has been damaged by a bug, making it
7520impossible for @value{GDBN} to assign numbers properly to all frames. In
7521addition, this can be useful when your program has multiple stacks and
7c7f93f6
AB
7522switches between them. The optional @var{pc-addr} can also be given to
7523specify the value of PC for the stack frame.
c906108c
SS
7524
7525@kindex up
7526@item up @var{n}
697aa1b7
EZ
7527Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
7528numbers @var{n}, this advances toward the outermost frame, to higher
7529frame numbers, to frames that have existed longer.
c906108c
SS
7530
7531@kindex down
41afff9a 7532@kindex do @r{(@code{down})}
c906108c 7533@item down @var{n}
697aa1b7
EZ
7534Move @var{n} frames down the stack; @var{n} defaults to 1. For
7535positive numbers @var{n}, this advances toward the innermost frame, to
7536lower frame numbers, to frames that were created more recently.
7537You may abbreviate @code{down} as @code{do}.
c906108c
SS
7538@end table
7539
7540All of these commands end by printing two lines of output describing the
7541frame. The first line shows the frame number, the function name, the
7542arguments, and the source file and line number of execution in that
5d161b24 7543frame. The second line shows the text of that source line.
c906108c
SS
7544
7545@need 1000
7546For example:
7547
7548@smallexample
7549@group
7550(@value{GDBP}) up
7551#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
7552 at env.c:10
755310 read_input_file (argv[i]);
7554@end group
7555@end smallexample
7556
7557After such a printout, the @code{list} command with no arguments
7558prints ten lines centered on the point of execution in the frame.
87885426
FN
7559You can also edit the program at the point of execution with your favorite
7560editing program by typing @code{edit}.
79a6e687 7561@xref{List, ,Printing Source Lines},
87885426 7562for details.
c906108c
SS
7563
7564@table @code
fc58fa65
AB
7565@kindex select-frame
7566@item select-frame
7567The @code{select-frame} command is a variant of @code{frame} that does
7568not display the new frame after selecting it. This command is
7569intended primarily for use in @value{GDBN} command scripts, where the
7570output might be unnecessary and distracting.
7571
c906108c
SS
7572@kindex down-silently
7573@kindex up-silently
7574@item up-silently @var{n}
7575@itemx down-silently @var{n}
7576These two commands are variants of @code{up} and @code{down},
7577respectively; they differ in that they do their work silently, without
7578causing display of the new frame. They are intended primarily for use
7579in @value{GDBN} command scripts, where the output might be unnecessary and
7580distracting.
7581@end table
7582
6d2ebf8b 7583@node Frame Info
79a6e687 7584@section Information About a Frame
c906108c
SS
7585
7586There are several other commands to print information about the selected
7587stack frame.
7588
7589@table @code
7590@item frame
7591@itemx f
7592When used without any argument, this command does not change which
7593frame is selected, but prints a brief description of the currently
7594selected stack frame. It can be abbreviated @code{f}. With an
7595argument, this command is used to select a stack frame.
79a6e687 7596@xref{Selection, ,Selecting a Frame}.
c906108c
SS
7597
7598@kindex info frame
41afff9a 7599@kindex info f @r{(@code{info frame})}
c906108c
SS
7600@item info frame
7601@itemx info f
7602This command prints a verbose description of the selected stack frame,
7603including:
7604
7605@itemize @bullet
5d161b24
DB
7606@item
7607the address of the frame
c906108c
SS
7608@item
7609the address of the next frame down (called by this frame)
7610@item
7611the address of the next frame up (caller of this frame)
7612@item
7613the language in which the source code corresponding to this frame is written
7614@item
7615the address of the frame's arguments
7616@item
d4f3574e
SS
7617the address of the frame's local variables
7618@item
c906108c
SS
7619the program counter saved in it (the address of execution in the caller frame)
7620@item
7621which registers were saved in the frame
7622@end itemize
7623
7624@noindent The verbose description is useful when
7625something has gone wrong that has made the stack format fail to fit
7626the usual conventions.
7627
7628@item info frame @var{addr}
7629@itemx info f @var{addr}
7630Print a verbose description of the frame at address @var{addr}, without
7631selecting that frame. The selected frame remains unchanged by this
7632command. This requires the same kind of address (more than one for some
7633architectures) that you specify in the @code{frame} command.
79a6e687 7634@xref{Selection, ,Selecting a Frame}.
c906108c
SS
7635
7636@kindex info args
7637@item info args
7638Print the arguments of the selected frame, each on a separate line.
7639
7640@item info locals
7641@kindex info locals
7642Print the local variables of the selected frame, each on a separate
7643line. These are all variables (declared either static or automatic)
7644accessible at the point of execution of the selected frame.
7645
c906108c
SS
7646@end table
7647
fc58fa65
AB
7648@node Frame Filter Management
7649@section Management of Frame Filters.
7650@cindex managing frame filters
7651
7652Frame filters are Python based utilities to manage and decorate the
7653output of frames. @xref{Frame Filter API}, for further information.
7654
7655Managing frame filters is performed by several commands available
7656within @value{GDBN}, detailed here.
7657
7658@table @code
7659@kindex info frame-filter
7660@item info frame-filter
7661Print a list of installed frame filters from all dictionaries, showing
7662their name, priority and enabled status.
7663
7664@kindex disable frame-filter
7665@anchor{disable frame-filter all}
7666@item disable frame-filter @var{filter-dictionary} @var{filter-name}
7667Disable a frame filter in the dictionary matching
7668@var{filter-dictionary} and @var{filter-name}. The
7669@var{filter-dictionary} may be @code{all}, @code{global},
7670@code{progspace}, or the name of the object file where the frame filter
7671dictionary resides. When @code{all} is specified, all frame filters
7672across all dictionaries are disabled. The @var{filter-name} is the name
7673of the frame filter and is used when @code{all} is not the option for
7674@var{filter-dictionary}. A disabled frame-filter is not deleted, it
7675may be enabled again later.
7676
7677@kindex enable frame-filter
7678@item enable frame-filter @var{filter-dictionary} @var{filter-name}
7679Enable a frame filter in the dictionary matching
7680@var{filter-dictionary} and @var{filter-name}. The
7681@var{filter-dictionary} may be @code{all}, @code{global},
7682@code{progspace} or the name of the object file where the frame filter
7683dictionary resides. When @code{all} is specified, all frame filters across
7684all dictionaries are enabled. The @var{filter-name} is the name of the frame
7685filter and is used when @code{all} is not the option for
7686@var{filter-dictionary}.
7687
7688Example:
7689
7690@smallexample
7691(gdb) info frame-filter
7692
7693global frame-filters:
7694 Priority Enabled Name
7695 1000 No PrimaryFunctionFilter
7696 100 Yes Reverse
7697
7698progspace /build/test frame-filters:
7699 Priority Enabled Name
7700 100 Yes ProgspaceFilter
7701
7702objfile /build/test frame-filters:
7703 Priority Enabled Name
7704 999 Yes BuildProgra Filter
7705
7706(gdb) disable frame-filter /build/test BuildProgramFilter
7707(gdb) info frame-filter
7708
7709global frame-filters:
7710 Priority Enabled Name
7711 1000 No PrimaryFunctionFilter
7712 100 Yes Reverse
7713
7714progspace /build/test frame-filters:
7715 Priority Enabled Name
7716 100 Yes ProgspaceFilter
7717
7718objfile /build/test frame-filters:
7719 Priority Enabled Name
7720 999 No BuildProgramFilter
7721
7722(gdb) enable frame-filter global PrimaryFunctionFilter
7723(gdb) info frame-filter
7724
7725global frame-filters:
7726 Priority Enabled Name
7727 1000 Yes PrimaryFunctionFilter
7728 100 Yes Reverse
7729
7730progspace /build/test frame-filters:
7731 Priority Enabled Name
7732 100 Yes ProgspaceFilter
7733
7734objfile /build/test frame-filters:
7735 Priority Enabled Name
7736 999 No BuildProgramFilter
7737@end smallexample
7738
7739@kindex set frame-filter priority
7740@item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
7741Set the @var{priority} of a frame filter in the dictionary matching
7742@var{filter-dictionary}, and the frame filter name matching
7743@var{filter-name}. The @var{filter-dictionary} may be @code{global},
7744@code{progspace} or the name of the object file where the frame filter
7745dictionary resides. The @var{priority} is an integer.
7746
7747@kindex show frame-filter priority
7748@item show frame-filter priority @var{filter-dictionary} @var{filter-name}
7749Show the @var{priority} of a frame filter in the dictionary matching
7750@var{filter-dictionary}, and the frame filter name matching
7751@var{filter-name}. The @var{filter-dictionary} may be @code{global},
7752@code{progspace} or the name of the object file where the frame filter
7753dictionary resides.
7754
7755Example:
7756
7757@smallexample
7758(gdb) info frame-filter
7759
7760global frame-filters:
7761 Priority Enabled Name
7762 1000 Yes PrimaryFunctionFilter
7763 100 Yes Reverse
7764
7765progspace /build/test frame-filters:
7766 Priority Enabled Name
7767 100 Yes ProgspaceFilter
7768
7769objfile /build/test frame-filters:
7770 Priority Enabled Name
7771 999 No BuildProgramFilter
7772
7773(gdb) set frame-filter priority global Reverse 50
7774(gdb) info frame-filter
7775
7776global frame-filters:
7777 Priority Enabled Name
7778 1000 Yes PrimaryFunctionFilter
7779 50 Yes Reverse
7780
7781progspace /build/test frame-filters:
7782 Priority Enabled Name
7783 100 Yes ProgspaceFilter
7784
7785objfile /build/test frame-filters:
7786 Priority Enabled Name
7787 999 No BuildProgramFilter
7788@end smallexample
7789@end table
c906108c 7790
6d2ebf8b 7791@node Source
c906108c
SS
7792@chapter Examining Source Files
7793
7794@value{GDBN} can print parts of your program's source, since the debugging
7795information recorded in the program tells @value{GDBN} what source files were
7796used to build it. When your program stops, @value{GDBN} spontaneously prints
7797the line where it stopped. Likewise, when you select a stack frame
79a6e687 7798(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
c906108c
SS
7799execution in that frame has stopped. You can print other portions of
7800source files by explicit command.
7801
7a292a7a 7802If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 7803prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 7804@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
7805
7806@menu
7807* List:: Printing source lines
2a25a5ba 7808* Specify Location:: How to specify code locations
87885426 7809* Edit:: Editing source files
c906108c 7810* Search:: Searching source files
c906108c
SS
7811* Source Path:: Specifying source directories
7812* Machine Code:: Source and machine code
7813@end menu
7814
6d2ebf8b 7815@node List
79a6e687 7816@section Printing Source Lines
c906108c
SS
7817
7818@kindex list
41afff9a 7819@kindex l @r{(@code{list})}
c906108c 7820To print lines from a source file, use the @code{list} command
5d161b24 7821(abbreviated @code{l}). By default, ten lines are printed.
2a25a5ba
EZ
7822There are several ways to specify what part of the file you want to
7823print; see @ref{Specify Location}, for the full list.
c906108c
SS
7824
7825Here are the forms of the @code{list} command most commonly used:
7826
7827@table @code
7828@item list @var{linenum}
7829Print lines centered around line number @var{linenum} in the
7830current source file.
7831
7832@item list @var{function}
7833Print lines centered around the beginning of function
7834@var{function}.
7835
7836@item list
7837Print more lines. If the last lines printed were printed with a
7838@code{list} command, this prints lines following the last lines
7839printed; however, if the last line printed was a solitary line printed
7840as part of displaying a stack frame (@pxref{Stack, ,Examining the
7841Stack}), this prints lines centered around that line.
7842
7843@item list -
7844Print lines just before the lines last printed.
7845@end table
7846
9c16f35a 7847@cindex @code{list}, how many lines to display
c906108c
SS
7848By default, @value{GDBN} prints ten source lines with any of these forms of
7849the @code{list} command. You can change this using @code{set listsize}:
7850
7851@table @code
7852@kindex set listsize
7853@item set listsize @var{count}
f81d1120 7854@itemx set listsize unlimited
c906108c
SS
7855Make the @code{list} command display @var{count} source lines (unless
7856the @code{list} argument explicitly specifies some other number).
f81d1120 7857Setting @var{count} to @code{unlimited} or 0 means there's no limit.
c906108c
SS
7858
7859@kindex show listsize
7860@item show listsize
7861Display the number of lines that @code{list} prints.
7862@end table
7863
7864Repeating a @code{list} command with @key{RET} discards the argument,
7865so it is equivalent to typing just @code{list}. This is more useful
7866than listing the same lines again. An exception is made for an
7867argument of @samp{-}; that argument is preserved in repetition so that
7868each repetition moves up in the source file.
7869
c906108c 7870In general, the @code{list} command expects you to supply zero, one or two
629500fa 7871@dfn{locations}. Locations specify source lines; there are several ways
2a25a5ba
EZ
7872of writing them (@pxref{Specify Location}), but the effect is always
7873to specify some source line.
7874
c906108c
SS
7875Here is a complete description of the possible arguments for @code{list}:
7876
7877@table @code
629500fa
KS
7878@item list @var{location}
7879Print lines centered around the line specified by @var{location}.
c906108c
SS
7880
7881@item list @var{first},@var{last}
7882Print lines from @var{first} to @var{last}. Both arguments are
629500fa
KS
7883locations. When a @code{list} command has two locations, and the
7884source file of the second location is omitted, this refers to
7885the same source file as the first location.
c906108c
SS
7886
7887@item list ,@var{last}
7888Print lines ending with @var{last}.
7889
7890@item list @var{first},
7891Print lines starting with @var{first}.
7892
7893@item list +
7894Print lines just after the lines last printed.
7895
7896@item list -
7897Print lines just before the lines last printed.
7898
7899@item list
7900As described in the preceding table.
7901@end table
7902
2a25a5ba
EZ
7903@node Specify Location
7904@section Specifying a Location
7905@cindex specifying location
629500fa
KS
7906@cindex location
7907@cindex source location
7908
7909@menu
7910* Linespec Locations:: Linespec locations
7911* Explicit Locations:: Explicit locations
7912* Address Locations:: Address locations
7913@end menu
c906108c 7914
2a25a5ba
EZ
7915Several @value{GDBN} commands accept arguments that specify a location
7916of your program's code. Since @value{GDBN} is a source-level
629500fa
KS
7917debugger, a location usually specifies some line in the source code.
7918Locations may be specified using three different formats:
7919linespec locations, explicit locations, or address locations.
c906108c 7920
629500fa
KS
7921@node Linespec Locations
7922@subsection Linespec Locations
7923@cindex linespec locations
7924
7925A @dfn{linespec} is a colon-separated list of source location parameters such
7926as file name, function name, etc. Here are all the different ways of
7927specifying a linespec:
c906108c 7928
2a25a5ba
EZ
7929@table @code
7930@item @var{linenum}
7931Specifies the line number @var{linenum} of the current source file.
c906108c 7932
2a25a5ba
EZ
7933@item -@var{offset}
7934@itemx +@var{offset}
7935Specifies the line @var{offset} lines before or after the @dfn{current
7936line}. For the @code{list} command, the current line is the last one
7937printed; for the breakpoint commands, this is the line at which
7938execution stopped in the currently selected @dfn{stack frame}
7939(@pxref{Frames, ,Frames}, for a description of stack frames.) When
7940used as the second of the two linespecs in a @code{list} command,
7941this specifies the line @var{offset} lines up or down from the first
7942linespec.
7943
7944@item @var{filename}:@var{linenum}
7945Specifies the line @var{linenum} in the source file @var{filename}.
4aac40c8
TT
7946If @var{filename} is a relative file name, then it will match any
7947source file name with the same trailing components. For example, if
7948@var{filename} is @samp{gcc/expr.c}, then it will match source file
7949name of @file{/build/trunk/gcc/expr.c}, but not
7950@file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
c906108c
SS
7951
7952@item @var{function}
7953Specifies the line that begins the body of the function @var{function}.
2a25a5ba 7954For example, in C, this is the line with the open brace.
c906108c 7955
a20714ff
PA
7956By default, in C@t{++} and Ada, @var{function} is interpreted as
7957specifying all functions named @var{function} in all scopes. For
7958C@t{++}, this means in all namespaces and classes. For Ada, this
7959means in all packages.
7960
7961For example, assuming a program with C@t{++} symbols named
7962@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
7963func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
7964
7965Commands that accept a linespec let you override this with the
7966@code{-qualified} option. For example, @w{@kbd{break -qualified
7967func}} sets a breakpoint on a free-function named @code{func} ignoring
7968any C@t{++} class methods and namespace functions called @code{func}.
7969
7970@xref{Explicit Locations}.
7971
9ef07c8c
TT
7972@item @var{function}:@var{label}
7973Specifies the line where @var{label} appears in @var{function}.
7974
c906108c 7975@item @var{filename}:@var{function}
2a25a5ba
EZ
7976Specifies the line that begins the body of the function @var{function}
7977in the file @var{filename}. You only need the file name with a
7978function name to avoid ambiguity when there are identically named
7979functions in different source files.
c906108c 7980
0f5238ed 7981@item @var{label}
629500fa
KS
7982Specifies the line at which the label named @var{label} appears
7983in the function corresponding to the currently selected stack frame.
7984If there is no current selected stack frame (for instance, if the inferior
7985is not running), then @value{GDBN} will not search for a label.
7986
7987@cindex breakpoint at static probe point
7988@item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
7989The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
7990applications to embed static probes. @xref{Static Probe Points}, for more
7991information on finding and using static probes. This form of linespec
7992specifies the location of such a static probe.
7993
7994If @var{objfile} is given, only probes coming from that shared library
7995or executable matching @var{objfile} as a regular expression are considered.
7996If @var{provider} is given, then only probes from that provider are considered.
7997If several probes match the spec, @value{GDBN} will insert a breakpoint at
7998each one of those probes.
7999@end table
8000
8001@node Explicit Locations
8002@subsection Explicit Locations
8003@cindex explicit locations
8004
8005@dfn{Explicit locations} allow the user to directly specify the source
8006location's parameters using option-value pairs.
8007
8008Explicit locations are useful when several functions, labels, or
8009file names have the same name (base name for files) in the program's
8010sources. In these cases, explicit locations point to the source
8011line you meant more accurately and unambiguously. Also, using
8012explicit locations might be faster in large programs.
8013
8014For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
8015defined in the file named @file{foo} or the label @code{bar} in a function
8016named @code{foo}. @value{GDBN} must search either the file system or
8017the symbol table to know.
8018
8019The list of valid explicit location options is summarized in the
8020following table:
8021
8022@table @code
8023@item -source @var{filename}
8024The value specifies the source file name. To differentiate between
8025files with the same base name, prepend as many directories as is necessary
8026to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
8027@value{GDBN} will use the first file it finds with the given base
8028name. This option requires the use of either @code{-function} or @code{-line}.
8029
8030@item -function @var{function}
8031The value specifies the name of a function. Operations
8032on function locations unmodified by other options (such as @code{-label}
8033or @code{-line}) refer to the line that begins the body of the function.
8034In C, for example, this is the line with the open brace.
8035
a20714ff
PA
8036By default, in C@t{++} and Ada, @var{function} is interpreted as
8037specifying all functions named @var{function} in all scopes. For
8038C@t{++}, this means in all namespaces and classes. For Ada, this
8039means in all packages.
8040
8041For example, assuming a program with C@t{++} symbols named
8042@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8043-function func}} and @w{@kbd{break -function B::func}} set a
8044breakpoint on both symbols.
8045
8046You can use the @kbd{-qualified} flag to override this (see below).
8047
8048@item -qualified
8049
8050This flag makes @value{GDBN} interpret a function name specified with
8051@kbd{-function} as a complete fully-qualified name.
8052
8053For example, assuming a C@t{++} program with symbols named
8054@code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
8055-function B::func}} command sets a breakpoint on @code{B::func}, only.
8056
8057(Note: the @kbd{-qualified} option can precede a linespec as well
8058(@pxref{Linespec Locations}), so the particular example above could be
8059simplified as @w{@kbd{break -qualified B::func}}.)
8060
629500fa
KS
8061@item -label @var{label}
8062The value specifies the name of a label. When the function
8063name is not specified, the label is searched in the function of the currently
8064selected stack frame.
8065
8066@item -line @var{number}
8067The value specifies a line offset for the location. The offset may either
8068be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
8069the command. When specified without any other options, the line offset is
8070relative to the current line.
8071@end table
8072
8073Explicit location options may be abbreviated by omitting any non-unique
a20714ff 8074trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
629500fa
KS
8075
8076@node Address Locations
8077@subsection Address Locations
8078@cindex address locations
8079
8080@dfn{Address locations} indicate a specific program address. They have
8081the generalized form *@var{address}.
8082
8083For line-oriented commands, such as @code{list} and @code{edit}, this
8084specifies a source line that contains @var{address}. For @code{break} and
8085other breakpoint-oriented commands, this can be used to set breakpoints in
2a25a5ba
EZ
8086parts of your program which do not have debugging information or
8087source files.
8088
8089Here @var{address} may be any expression valid in the current working
8090language (@pxref{Languages, working language}) that specifies a code
5fa54e5d 8091address. In addition, as a convenience, @value{GDBN} extends the
629500fa
KS
8092semantics of expressions used in locations to cover several situations
8093that frequently occur during debugging. Here are the various forms
5fa54e5d 8094of @var{address}:
2a25a5ba
EZ
8095
8096@table @code
8097@item @var{expression}
8098Any expression valid in the current working language.
8099
8100@item @var{funcaddr}
8101An address of a function or procedure derived from its name. In C,
9c37b5ae 8102C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
2a25a5ba
EZ
8103simply the function's name @var{function} (and actually a special case
8104of a valid expression). In Pascal and Modula-2, this is
8105@code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
8106(although the Pascal form also works).
8107
8108This form specifies the address of the function's first instruction,
8109before the stack frame and arguments have been set up.
8110
9a284c97 8111@item '@var{filename}':@var{funcaddr}
2a25a5ba
EZ
8112Like @var{funcaddr} above, but also specifies the name of the source
8113file explicitly. This is useful if the name of the function does not
8114specify the function unambiguously, e.g., if there are several
8115functions with identical names in different source files.
c906108c
SS
8116@end table
8117
87885426 8118@node Edit
79a6e687 8119@section Editing Source Files
87885426
FN
8120@cindex editing source files
8121
8122@kindex edit
8123@kindex e @r{(@code{edit})}
8124To edit the lines in a source file, use the @code{edit} command.
8125The editing program of your choice
8126is invoked with the current line set to
8127the active line in the program.
8128Alternatively, there are several ways to specify what part of the file you
2a25a5ba 8129want to print if you want to see other parts of the program:
87885426
FN
8130
8131@table @code
2a25a5ba
EZ
8132@item edit @var{location}
8133Edit the source file specified by @code{location}. Editing starts at
8134that @var{location}, e.g., at the specified source line of the
8135specified file. @xref{Specify Location}, for all the possible forms
8136of the @var{location} argument; here are the forms of the @code{edit}
8137command most commonly used:
87885426 8138
2a25a5ba 8139@table @code
87885426
FN
8140@item edit @var{number}
8141Edit the current source file with @var{number} as the active line number.
8142
8143@item edit @var{function}
8144Edit the file containing @var{function} at the beginning of its definition.
2a25a5ba 8145@end table
87885426 8146
87885426
FN
8147@end table
8148
79a6e687 8149@subsection Choosing your Editor
87885426
FN
8150You can customize @value{GDBN} to use any editor you want
8151@footnote{
8152The only restriction is that your editor (say @code{ex}), recognizes the
8153following command-line syntax:
10998722 8154@smallexample
87885426 8155ex +@var{number} file
10998722 8156@end smallexample
15387254
EZ
8157The optional numeric value +@var{number} specifies the number of the line in
8158the file where to start editing.}.
8159By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
8160by setting the environment variable @code{EDITOR} before using
8161@value{GDBN}. For example, to configure @value{GDBN} to use the
8162@code{vi} editor, you could use these commands with the @code{sh} shell:
8163@smallexample
87885426
FN
8164EDITOR=/usr/bin/vi
8165export EDITOR
15387254 8166gdb @dots{}
10998722 8167@end smallexample
87885426 8168or in the @code{csh} shell,
10998722 8169@smallexample
87885426 8170setenv EDITOR /usr/bin/vi
15387254 8171gdb @dots{}
10998722 8172@end smallexample
87885426 8173
6d2ebf8b 8174@node Search
79a6e687 8175@section Searching Source Files
15387254 8176@cindex searching source files
c906108c
SS
8177
8178There are two commands for searching through the current source file for a
8179regular expression.
8180
8181@table @code
8182@kindex search
8183@kindex forward-search
1e96de83 8184@kindex fo @r{(@code{forward-search})}
c906108c
SS
8185@item forward-search @var{regexp}
8186@itemx search @var{regexp}
8187The command @samp{forward-search @var{regexp}} checks each line,
8188starting with the one following the last line listed, for a match for
5d161b24 8189@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
8190synonym @samp{search @var{regexp}} or abbreviate the command name as
8191@code{fo}.
8192
09d4efe1 8193@kindex reverse-search
c906108c
SS
8194@item reverse-search @var{regexp}
8195The command @samp{reverse-search @var{regexp}} checks each line, starting
8196with the one before the last line listed and going backward, for a match
8197for @var{regexp}. It lists the line that is found. You can abbreviate
8198this command as @code{rev}.
8199@end table
c906108c 8200
6d2ebf8b 8201@node Source Path
79a6e687 8202@section Specifying Source Directories
c906108c
SS
8203
8204@cindex source path
8205@cindex directories for source files
8206Executable programs sometimes do not record the directories of the source
8207files from which they were compiled, just the names. Even when they do,
8208the directories could be moved between the compilation and your debugging
8209session. @value{GDBN} has a list of directories to search for source files;
8210this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
8211it tries all the directories in the list, in the order they are present
0b66e38c
EZ
8212in the list, until it finds a file with the desired name.
8213
8214For example, suppose an executable references the file
8215@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
8216@file{/mnt/cross}. The file is first looked up literally; if this
8217fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
8218fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
8219message is printed. @value{GDBN} does not look up the parts of the
8220source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
8221Likewise, the subdirectories of the source path are not searched: if
8222the source path is @file{/mnt/cross}, and the binary refers to
8223@file{foo.c}, @value{GDBN} would not find it under
8224@file{/mnt/cross/usr/src/foo-1.0/lib}.
8225
8226Plain file names, relative file names with leading directories, file
8227names containing dots, etc.@: are all treated as described above; for
8228instance, if the source path is @file{/mnt/cross}, and the source file
8229is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
8230@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
8231that---@file{/mnt/cross/foo.c}.
8232
8233Note that the executable search path is @emph{not} used to locate the
cd852561 8234source files.
c906108c
SS
8235
8236Whenever you reset or rearrange the source path, @value{GDBN} clears out
8237any information it has cached about where source files are found and where
8238each line is in the file.
8239
8240@kindex directory
8241@kindex dir
d4f3574e
SS
8242When you start @value{GDBN}, its source path includes only @samp{cdir}
8243and @samp{cwd}, in that order.
c906108c
SS
8244To add other directories, use the @code{directory} command.
8245
4b505b12
AS
8246The search path is used to find both program source files and @value{GDBN}
8247script files (read using the @samp{-command} option and @samp{source} command).
8248
30daae6c
JB
8249In addition to the source path, @value{GDBN} provides a set of commands
8250that manage a list of source path substitution rules. A @dfn{substitution
8251rule} specifies how to rewrite source directories stored in the program's
8252debug information in case the sources were moved to a different
8253directory between compilation and debugging. A rule is made of
8254two strings, the first specifying what needs to be rewritten in
8255the path, and the second specifying how it should be rewritten.
8256In @ref{set substitute-path}, we name these two parts @var{from} and
8257@var{to} respectively. @value{GDBN} does a simple string replacement
8258of @var{from} with @var{to} at the start of the directory part of the
8259source file name, and uses that result instead of the original file
8260name to look up the sources.
8261
8262Using the previous example, suppose the @file{foo-1.0} tree has been
8263moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
3f94c067 8264@value{GDBN} to replace @file{/usr/src} in all source path names with
30daae6c
JB
8265@file{/mnt/cross}. The first lookup will then be
8266@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
8267of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
8268substitution rule, use the @code{set substitute-path} command
8269(@pxref{set substitute-path}).
8270
8271To avoid unexpected substitution results, a rule is applied only if the
8272@var{from} part of the directory name ends at a directory separator.
8273For instance, a rule substituting @file{/usr/source} into
8274@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
8275not to @file{/usr/sourceware/foo-2.0}. And because the substitution
d3e8051b 8276is applied only at the beginning of the directory name, this rule will
30daae6c
JB
8277not be applied to @file{/root/usr/source/baz.c} either.
8278
8279In many cases, you can achieve the same result using the @code{directory}
8280command. However, @code{set substitute-path} can be more efficient in
8281the case where the sources are organized in a complex tree with multiple
8282subdirectories. With the @code{directory} command, you need to add each
8283subdirectory of your project. If you moved the entire tree while
8284preserving its internal organization, then @code{set substitute-path}
8285allows you to direct the debugger to all the sources with one single
8286command.
8287
8288@code{set substitute-path} is also more than just a shortcut command.
8289The source path is only used if the file at the original location no
8290longer exists. On the other hand, @code{set substitute-path} modifies
8291the debugger behavior to look at the rewritten location instead. So, if
8292for any reason a source file that is not relevant to your executable is
8293located at the original location, a substitution rule is the only
3f94c067 8294method available to point @value{GDBN} at the new location.
30daae6c 8295
29b0e8a2
JM
8296@cindex @samp{--with-relocated-sources}
8297@cindex default source path substitution
8298You can configure a default source path substitution rule by
8299configuring @value{GDBN} with the
8300@samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
8301should be the name of a directory under @value{GDBN}'s configured
8302prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
8303directory names in debug information under @var{dir} will be adjusted
8304automatically if the installed @value{GDBN} is moved to a new
8305location. This is useful if @value{GDBN}, libraries or executables
8306with debug information and corresponding source code are being moved
8307together.
8308
c906108c
SS
8309@table @code
8310@item directory @var{dirname} @dots{}
8311@item dir @var{dirname} @dots{}
8312Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
8313directory names may be given to this command, separated by @samp{:}
8314(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
8315part of absolute file names) or
c906108c
SS
8316whitespace. You may specify a directory that is already in the source
8317path; this moves it forward, so @value{GDBN} searches it sooner.
8318
8319@kindex cdir
8320@kindex cwd
41afff9a 8321@vindex $cdir@r{, convenience variable}
d3e8051b 8322@vindex $cwd@r{, convenience variable}
c906108c
SS
8323@cindex compilation directory
8324@cindex current directory
8325@cindex working directory
8326@cindex directory, current
8327@cindex directory, compilation
8328You can use the string @samp{$cdir} to refer to the compilation
8329directory (if one is recorded), and @samp{$cwd} to refer to the current
8330working directory. @samp{$cwd} is not the same as @samp{.}---the former
8331tracks the current working directory as it changes during your @value{GDBN}
8332session, while the latter is immediately expanded to the current
8333directory at the time you add an entry to the source path.
8334
8335@item directory
cd852561 8336Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
8337
8338@c RET-repeat for @code{directory} is explicitly disabled, but since
8339@c repeating it would be a no-op we do not say that. (thanks to RMS)
8340
99e7ae30
DE
8341@item set directories @var{path-list}
8342@kindex set directories
8343Set the source path to @var{path-list}.
8344@samp{$cdir:$cwd} are added if missing.
8345
c906108c
SS
8346@item show directories
8347@kindex show directories
8348Print the source path: show which directories it contains.
30daae6c
JB
8349
8350@anchor{set substitute-path}
8351@item set substitute-path @var{from} @var{to}
8352@kindex set substitute-path
8353Define a source path substitution rule, and add it at the end of the
8354current list of existing substitution rules. If a rule with the same
8355@var{from} was already defined, then the old rule is also deleted.
8356
8357For example, if the file @file{/foo/bar/baz.c} was moved to
8358@file{/mnt/cross/baz.c}, then the command
8359
8360@smallexample
c58b006b 8361(@value{GDBP}) set substitute-path /foo/bar /mnt/cross
30daae6c
JB
8362@end smallexample
8363
8364@noindent
c58b006b 8365will tell @value{GDBN} to replace @samp{/foo/bar} with
30daae6c
JB
8366@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
8367@file{baz.c} even though it was moved.
8368
8369In the case when more than one substitution rule have been defined,
8370the rules are evaluated one by one in the order where they have been
8371defined. The first one matching, if any, is selected to perform
8372the substitution.
8373
8374For instance, if we had entered the following commands:
8375
8376@smallexample
8377(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
8378(@value{GDBP}) set substitute-path /usr/src /mnt/src
8379@end smallexample
8380
8381@noindent
8382@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
8383@file{/mnt/include/defs.h} by using the first rule. However, it would
8384use the second rule to rewrite @file{/usr/src/lib/foo.c} into
8385@file{/mnt/src/lib/foo.c}.
8386
8387
8388@item unset substitute-path [path]
8389@kindex unset substitute-path
8390If a path is specified, search the current list of substitution rules
8391for a rule that would rewrite that path. Delete that rule if found.
8392A warning is emitted by the debugger if no rule could be found.
8393
8394If no path is specified, then all substitution rules are deleted.
8395
8396@item show substitute-path [path]
8397@kindex show substitute-path
8398If a path is specified, then print the source path substitution rule
8399which would rewrite that path, if any.
8400
8401If no path is specified, then print all existing source path substitution
8402rules.
8403
c906108c
SS
8404@end table
8405
8406If your source path is cluttered with directories that are no longer of
8407interest, @value{GDBN} may sometimes cause confusion by finding the wrong
8408versions of source. You can correct the situation as follows:
8409
8410@enumerate
8411@item
cd852561 8412Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
8413
8414@item
8415Use @code{directory} with suitable arguments to reinstall the
8416directories you want in the source path. You can add all the
8417directories in one command.
8418@end enumerate
8419
6d2ebf8b 8420@node Machine Code
79a6e687 8421@section Source and Machine Code
15387254 8422@cindex source line and its code address
c906108c
SS
8423
8424You can use the command @code{info line} to map source lines to program
8425addresses (and vice versa), and the command @code{disassemble} to display
91440f57
HZ
8426a range of addresses as machine instructions. You can use the command
8427@code{set disassemble-next-line} to set whether to disassemble next
8428source line when execution stops. When run under @sc{gnu} Emacs
d4f3574e 8429mode, the @code{info line} command causes the arrow to point to the
5d161b24 8430line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
8431well as hex.
8432
8433@table @code
8434@kindex info line
db1ae9c5
AB
8435@item info line
8436@itemx info line @var{location}
c906108c 8437Print the starting and ending addresses of the compiled code for
629500fa 8438source line @var{location}. You can specify source lines in any of
db1ae9c5
AB
8439the ways documented in @ref{Specify Location}. With no @var{location}
8440information about the current source line is printed.
c906108c
SS
8441@end table
8442
8443For example, we can use @code{info line} to discover the location of
8444the object code for the first line of function
8445@code{m4_changequote}:
8446
8447@smallexample
96a2c332 8448(@value{GDBP}) info line m4_changequote
db1ae9c5
AB
8449Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
8450 ends at 0x6350 <m4_changequote+4>.
c906108c
SS
8451@end smallexample
8452
8453@noindent
15387254 8454@cindex code address and its source line
c906108c 8455We can also inquire (using @code{*@var{addr}} as the form for
629500fa 8456@var{location}) what source line covers a particular address:
c906108c
SS
8457@smallexample
8458(@value{GDBP}) info line *0x63ff
db1ae9c5
AB
8459Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
8460 ends at 0x6404 <m4_changequote+184>.
c906108c
SS
8461@end smallexample
8462
8463@cindex @code{$_} and @code{info line}
15387254 8464@cindex @code{x} command, default address
41afff9a 8465@kindex x@r{(examine), and} info line
c906108c
SS
8466After @code{info line}, the default address for the @code{x} command
8467is changed to the starting address of the line, so that @samp{x/i} is
8468sufficient to begin examining the machine code (@pxref{Memory,
79a6e687 8469,Examining Memory}). Also, this address is saved as the value of the
c906108c 8470convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
79a6e687 8471Variables}).
c906108c 8472
db1ae9c5
AB
8473@cindex info line, repeated calls
8474After @code{info line}, using @code{info line} again without
8475specifying a location will display information about the next source
8476line.
8477
c906108c
SS
8478@table @code
8479@kindex disassemble
8480@cindex assembly instructions
8481@cindex instructions, assembly
8482@cindex machine instructions
8483@cindex listing machine instructions
8484@item disassemble
d14508fe 8485@itemx disassemble /m
6ff0ba5f 8486@itemx disassemble /s
9b117ef3 8487@itemx disassemble /r
c906108c 8488This specialized command dumps a range of memory as machine
d14508fe 8489instructions. It can also print mixed source+disassembly by specifying
6ff0ba5f
DE
8490the @code{/m} or @code{/s} modifier and print the raw instructions in hex
8491as well as in symbolic form by specifying the @code{/r} modifier.
d14508fe 8492The default memory range is the function surrounding the
c906108c
SS
8493program counter of the selected frame. A single argument to this
8494command is a program counter value; @value{GDBN} dumps the function
21a0512e
PP
8495surrounding this value. When two arguments are given, they should
8496be separated by a comma, possibly surrounded by whitespace. The
53a71c06
CR
8497arguments specify a range of addresses to dump, in one of two forms:
8498
8499@table @code
8500@item @var{start},@var{end}
8501the addresses from @var{start} (inclusive) to @var{end} (exclusive)
8502@item @var{start},+@var{length}
8503the addresses from @var{start} (inclusive) to
8504@code{@var{start}+@var{length}} (exclusive).
8505@end table
8506
8507@noindent
8508When 2 arguments are specified, the name of the function is also
8509printed (since there could be several functions in the given range).
21a0512e
PP
8510
8511The argument(s) can be any expression yielding a numeric value, such as
8512@samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
2b28d209
PP
8513
8514If the range of memory being disassembled contains current program counter,
8515the instruction at that location is shown with a @code{=>} marker.
c906108c
SS
8516@end table
8517
c906108c
SS
8518The following example shows the disassembly of a range of addresses of
8519HP PA-RISC 2.0 code:
8520
8521@smallexample
21a0512e 8522(@value{GDBP}) disas 0x32c4, 0x32e4
c906108c 8523Dump of assembler code from 0x32c4 to 0x32e4:
2b28d209
PP
8524 0x32c4 <main+204>: addil 0,dp
8525 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
8526 0x32cc <main+212>: ldil 0x3000,r31
8527 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
8528 0x32d4 <main+220>: ldo 0(r31),rp
8529 0x32d8 <main+224>: addil -0x800,dp
8530 0x32dc <main+228>: ldo 0x588(r1),r26
8531 0x32e0 <main+232>: ldil 0x3000,r31
c906108c
SS
8532End of assembler dump.
8533@end smallexample
c906108c 8534
6ff0ba5f
DE
8535Here is an example showing mixed source+assembly for Intel x86
8536with @code{/m} or @code{/s}, when the program is stopped just after
8537function prologue in a non-optimized function with no inline code.
d14508fe
DE
8538
8539@smallexample
8540(@value{GDBP}) disas /m main
8541Dump of assembler code for function main:
85425 @{
9c419145
PP
8543 0x08048330 <+0>: push %ebp
8544 0x08048331 <+1>: mov %esp,%ebp
8545 0x08048333 <+3>: sub $0x8,%esp
8546 0x08048336 <+6>: and $0xfffffff0,%esp
8547 0x08048339 <+9>: sub $0x10,%esp
d14508fe
DE
8548
85496 printf ("Hello.\n");
9c419145
PP
8550=> 0x0804833c <+12>: movl $0x8048440,(%esp)
8551 0x08048343 <+19>: call 0x8048284 <puts@@plt>
d14508fe
DE
8552
85537 return 0;
85548 @}
9c419145
PP
8555 0x08048348 <+24>: mov $0x0,%eax
8556 0x0804834d <+29>: leave
8557 0x0804834e <+30>: ret
d14508fe
DE
8558
8559End of assembler dump.
8560@end smallexample
8561
6ff0ba5f
DE
8562The @code{/m} option is deprecated as its output is not useful when
8563there is either inlined code or re-ordered code.
8564The @code{/s} option is the preferred choice.
8565Here is an example for AMD x86-64 showing the difference between
8566@code{/m} output and @code{/s} output.
8567This example has one inline function defined in a header file,
8568and the code is compiled with @samp{-O2} optimization.
8569Note how the @code{/m} output is missing the disassembly of
8570several instructions that are present in the @code{/s} output.
8571
8572@file{foo.h}:
8573
8574@smallexample
8575int
8576foo (int a)
8577@{
8578 if (a < 0)
8579 return a * 2;
8580 if (a == 0)
8581 return 1;
8582 return a + 10;
8583@}
8584@end smallexample
8585
8586@file{foo.c}:
8587
8588@smallexample
8589#include "foo.h"
8590volatile int x, y;
8591int
8592main ()
8593@{
8594 x = foo (y);
8595 return 0;
8596@}
8597@end smallexample
8598
8599@smallexample
8600(@value{GDBP}) disas /m main
8601Dump of assembler code for function main:
86025 @{
8603
86046 x = foo (y);
8605 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
8606 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
8607
86087 return 0;
86098 @}
8610 0x000000000040041d <+29>: xor %eax,%eax
8611 0x000000000040041f <+31>: retq
8612 0x0000000000400420 <+32>: add %eax,%eax
8613 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
8614
8615End of assembler dump.
8616(@value{GDBP}) disas /s main
8617Dump of assembler code for function main:
8618foo.c:
86195 @{
86206 x = foo (y);
8621 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
8622
8623foo.h:
86244 if (a < 0)
8625 0x0000000000400406 <+6>: test %eax,%eax
8626 0x0000000000400408 <+8>: js 0x400420 <main+32>
8627
86286 if (a == 0)
86297 return 1;
86308 return a + 10;
8631 0x000000000040040a <+10>: lea 0xa(%rax),%edx
8632 0x000000000040040d <+13>: test %eax,%eax
8633 0x000000000040040f <+15>: mov $0x1,%eax
8634 0x0000000000400414 <+20>: cmovne %edx,%eax
8635
8636foo.c:
86376 x = foo (y);
8638 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
8639
86407 return 0;
86418 @}
8642 0x000000000040041d <+29>: xor %eax,%eax
8643 0x000000000040041f <+31>: retq
8644
8645foo.h:
86465 return a * 2;
8647 0x0000000000400420 <+32>: add %eax,%eax
8648 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
8649End of assembler dump.
8650@end smallexample
8651
53a71c06
CR
8652Here is another example showing raw instructions in hex for AMD x86-64,
8653
8654@smallexample
8655(gdb) disas /r 0x400281,+10
8656Dump of assembler code from 0x400281 to 0x40028b:
8657 0x0000000000400281: 38 36 cmp %dh,(%rsi)
8658 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
8659 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
8660 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
8661End of assembler dump.
8662@end smallexample
8663
629500fa 8664Addresses cannot be specified as a location (@pxref{Specify Location}).
7e1e0340
DE
8665So, for example, if you want to disassemble function @code{bar}
8666in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
8667and not @samp{disassemble foo.c:bar}.
8668
c906108c
SS
8669Some architectures have more than one commonly-used set of instruction
8670mnemonics or other syntax.
8671
76d17f34
EZ
8672For programs that were dynamically linked and use shared libraries,
8673instructions that call functions or branch to locations in the shared
8674libraries might show a seemingly bogus location---it's actually a
8675location of the relocation table. On some architectures, @value{GDBN}
8676might be able to resolve these to actual function names.
8677
65b48a81
PB
8678@table @code
8679@kindex set disassembler-options
8680@cindex disassembler options
8681@item set disassembler-options @var{option1}[,@var{option2}@dots{}]
8682This command controls the passing of target specific information to
8683the disassembler. For a list of valid options, please refer to the
8684@code{-M}/@code{--disassembler-options} section of the @samp{objdump}
8685manual and/or the output of @kbd{objdump --help}
8686(@pxref{objdump,,objdump,binutils.info,The GNU Binary Utilities}).
8687The default value is the empty string.
8688
8689If it is necessary to specify more than one disassembler option, then
8690multiple options can be placed together into a comma separated list.
8691Currently this command is only supported on targets ARM, PowerPC
8692and S/390.
8693
8694@kindex show disassembler-options
8695@item show disassembler-options
8696Show the current setting of the disassembler options.
8697@end table
8698
c906108c 8699@table @code
d4f3574e 8700@kindex set disassembly-flavor
d4f3574e
SS
8701@cindex Intel disassembly flavor
8702@cindex AT&T disassembly flavor
8703@item set disassembly-flavor @var{instruction-set}
c906108c
SS
8704Select the instruction set to use when disassembling the
8705program via the @code{disassemble} or @code{x/i} commands.
8706
8707Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
8708can set @var{instruction-set} to either @code{intel} or @code{att}.
8709The default is @code{att}, the AT&T flavor used by default by Unix
8710assemblers for x86-based targets.
9c16f35a
EZ
8711
8712@kindex show disassembly-flavor
8713@item show disassembly-flavor
8714Show the current setting of the disassembly flavor.
c906108c
SS
8715@end table
8716
91440f57
HZ
8717@table @code
8718@kindex set disassemble-next-line
8719@kindex show disassemble-next-line
8720@item set disassemble-next-line
8721@itemx show disassemble-next-line
32ae1842
EZ
8722Control whether or not @value{GDBN} will disassemble the next source
8723line or instruction when execution stops. If ON, @value{GDBN} will
8724display disassembly of the next source line when execution of the
8725program being debugged stops. This is @emph{in addition} to
8726displaying the source line itself, which @value{GDBN} always does if
8727possible. If the next source line cannot be displayed for some reason
8728(e.g., if @value{GDBN} cannot find the source file, or there's no line
8729info in the debug info), @value{GDBN} will display disassembly of the
8730next @emph{instruction} instead of showing the next source line. If
8731AUTO, @value{GDBN} will display disassembly of next instruction only
8732if the source line cannot be displayed. This setting causes
8733@value{GDBN} to display some feedback when you step through a function
8734with no line info or whose source file is unavailable. The default is
8735OFF, which means never display the disassembly of the next line or
8736instruction.
91440f57
HZ
8737@end table
8738
c906108c 8739
6d2ebf8b 8740@node Data
c906108c
SS
8741@chapter Examining Data
8742
8743@cindex printing data
8744@cindex examining data
8745@kindex print
8746@kindex inspect
c906108c 8747The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
8748command (abbreviated @code{p}), or its synonym @code{inspect}. It
8749evaluates and prints the value of an expression of the language your
8750program is written in (@pxref{Languages, ,Using @value{GDBN} with
78e2826b
TT
8751Different Languages}). It may also print the expression using a
8752Python-based pretty-printer (@pxref{Pretty Printing}).
c906108c
SS
8753
8754@table @code
d4f3574e
SS
8755@item print @var{expr}
8756@itemx print /@var{f} @var{expr}
8757@var{expr} is an expression (in the source language). By default the
8758value of @var{expr} is printed in a format appropriate to its data type;
c906108c 8759you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 8760@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
79a6e687 8761Formats}.
c906108c
SS
8762
8763@item print
8764@itemx print /@var{f}
15387254 8765@cindex reprint the last value
d4f3574e 8766If you omit @var{expr}, @value{GDBN} displays the last value again (from the
79a6e687 8767@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
c906108c
SS
8768conveniently inspect the same value in an alternative format.
8769@end table
8770
8771A more low-level way of examining data is with the @code{x} command.
8772It examines data in memory at a specified address and prints it in a
79a6e687 8773specified format. @xref{Memory, ,Examining Memory}.
c906108c 8774
7a292a7a 8775If you are interested in information about types, or about how the
d4f3574e
SS
8776fields of a struct or a class are declared, use the @code{ptype @var{exp}}
8777command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 8778Table}.
c906108c 8779
06fc020f
SCR
8780@cindex exploring hierarchical data structures
8781@kindex explore
8782Another way of examining values of expressions and type information is
8783through the Python extension command @code{explore} (available only if
8784the @value{GDBN} build is configured with @code{--with-python}). It
8785offers an interactive way to start at the highest level (or, the most
8786abstract level) of the data type of an expression (or, the data type
8787itself) and explore all the way down to leaf scalar values/fields
8788embedded in the higher level data types.
8789
8790@table @code
8791@item explore @var{arg}
8792@var{arg} is either an expression (in the source language), or a type
8793visible in the current context of the program being debugged.
8794@end table
8795
8796The working of the @code{explore} command can be illustrated with an
8797example. If a data type @code{struct ComplexStruct} is defined in your
8798C program as
8799
8800@smallexample
8801struct SimpleStruct
8802@{
8803 int i;
8804 double d;
8805@};
8806
8807struct ComplexStruct
8808@{
8809 struct SimpleStruct *ss_p;
8810 int arr[10];
8811@};
8812@end smallexample
8813
8814@noindent
8815followed by variable declarations as
8816
8817@smallexample
8818struct SimpleStruct ss = @{ 10, 1.11 @};
8819struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
8820@end smallexample
8821
8822@noindent
8823then, the value of the variable @code{cs} can be explored using the
8824@code{explore} command as follows.
8825
8826@smallexample
8827(gdb) explore cs
8828The value of `cs' is a struct/class of type `struct ComplexStruct' with
8829the following fields:
8830
8831 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
8832 arr = <Enter 1 to explore this field of type `int [10]'>
8833
8834Enter the field number of choice:
8835@end smallexample
8836
8837@noindent
8838Since the fields of @code{cs} are not scalar values, you are being
8839prompted to chose the field you want to explore. Let's say you choose
8840the field @code{ss_p} by entering @code{0}. Then, since this field is a
8841pointer, you will be asked if it is pointing to a single value. From
8842the declaration of @code{cs} above, it is indeed pointing to a single
8843value, hence you enter @code{y}. If you enter @code{n}, then you will
8844be asked if it were pointing to an array of values, in which case this
8845field will be explored as if it were an array.
8846
8847@smallexample
8848`cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
8849Continue exploring it as a pointer to a single value [y/n]: y
8850The value of `*(cs.ss_p)' is a struct/class of type `struct
8851SimpleStruct' with the following fields:
8852
8853 i = 10 .. (Value of type `int')
8854 d = 1.1100000000000001 .. (Value of type `double')
8855
8856Press enter to return to parent value:
8857@end smallexample
8858
8859@noindent
8860If the field @code{arr} of @code{cs} was chosen for exploration by
8861entering @code{1} earlier, then since it is as array, you will be
8862prompted to enter the index of the element in the array that you want
8863to explore.
8864
8865@smallexample
8866`cs.arr' is an array of `int'.
8867Enter the index of the element you want to explore in `cs.arr': 5
8868
8869`(cs.arr)[5]' is a scalar value of type `int'.
8870
8871(cs.arr)[5] = 4
8872
8873Press enter to return to parent value:
8874@end smallexample
8875
8876In general, at any stage of exploration, you can go deeper towards the
8877leaf values by responding to the prompts appropriately, or hit the
8878return key to return to the enclosing data structure (the @i{higher}
8879level data structure).
8880
8881Similar to exploring values, you can use the @code{explore} command to
8882explore types. Instead of specifying a value (which is typically a
8883variable name or an expression valid in the current context of the
8884program being debugged), you specify a type name. If you consider the
8885same example as above, your can explore the type
8886@code{struct ComplexStruct} by passing the argument
8887@code{struct ComplexStruct} to the @code{explore} command.
8888
8889@smallexample
8890(gdb) explore struct ComplexStruct
8891@end smallexample
8892
8893@noindent
8894By responding to the prompts appropriately in the subsequent interactive
8895session, you can explore the type @code{struct ComplexStruct} in a
8896manner similar to how the value @code{cs} was explored in the above
8897example.
8898
8899The @code{explore} command also has two sub-commands,
8900@code{explore value} and @code{explore type}. The former sub-command is
8901a way to explicitly specify that value exploration of the argument is
8902being invoked, while the latter is a way to explicitly specify that type
8903exploration of the argument is being invoked.
8904
8905@table @code
8906@item explore value @var{expr}
8907@cindex explore value
8908This sub-command of @code{explore} explores the value of the
8909expression @var{expr} (if @var{expr} is an expression valid in the
8910current context of the program being debugged). The behavior of this
8911command is identical to that of the behavior of the @code{explore}
8912command being passed the argument @var{expr}.
8913
8914@item explore type @var{arg}
8915@cindex explore type
8916This sub-command of @code{explore} explores the type of @var{arg} (if
8917@var{arg} is a type visible in the current context of program being
8918debugged), or the type of the value/expression @var{arg} (if @var{arg}
8919is an expression valid in the current context of the program being
8920debugged). If @var{arg} is a type, then the behavior of this command is
8921identical to that of the @code{explore} command being passed the
8922argument @var{arg}. If @var{arg} is an expression, then the behavior of
8923this command will be identical to that of the @code{explore} command
8924being passed the type of @var{arg} as the argument.
8925@end table
8926
c906108c
SS
8927@menu
8928* Expressions:: Expressions
6ba66d6a 8929* Ambiguous Expressions:: Ambiguous Expressions
c906108c
SS
8930* Variables:: Program variables
8931* Arrays:: Artificial arrays
8932* Output Formats:: Output formats
8933* Memory:: Examining memory
8934* Auto Display:: Automatic display
8935* Print Settings:: Print settings
4c374409 8936* Pretty Printing:: Python pretty printing
c906108c
SS
8937* Value History:: Value history
8938* Convenience Vars:: Convenience variables
a72c3253 8939* Convenience Funs:: Convenience functions
c906108c 8940* Registers:: Registers
c906108c 8941* Floating Point Hardware:: Floating point hardware
53c69bd7 8942* Vector Unit:: Vector Unit
721c2651 8943* OS Information:: Auxiliary data provided by operating system
29e57380 8944* Memory Region Attributes:: Memory region attributes
16d9dec6 8945* Dump/Restore Files:: Copy between memory and a file
384ee23f 8946* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
8947* Character Sets:: Debugging programs that use a different
8948 character set than GDB does
b12039c6 8949* Caching Target Data:: Data caching for targets
08388c79 8950* Searching Memory:: Searching memory for a sequence of bytes
5fdf6324 8951* Value Sizes:: Managing memory allocated for values
c906108c
SS
8952@end menu
8953
6d2ebf8b 8954@node Expressions
c906108c
SS
8955@section Expressions
8956
8957@cindex expressions
8958@code{print} and many other @value{GDBN} commands accept an expression and
8959compute its value. Any kind of constant, variable or operator defined
8960by the programming language you are using is valid in an expression in
e2e0bcd1
JB
8961@value{GDBN}. This includes conditional expressions, function calls,
8962casts, and string constants. It also includes preprocessor macros, if
8963you compiled your program to include this information; see
8964@ref{Compilation}.
c906108c 8965
15387254 8966@cindex arrays in expressions
d4f3574e
SS
8967@value{GDBN} supports array constants in expressions input by
8968the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
63092375
DJ
8969you can use the command @code{print @{1, 2, 3@}} to create an array
8970of three integers. If you pass an array to a function or assign it
8971to a program variable, @value{GDBN} copies the array to memory that
8972is @code{malloc}ed in the target program.
c906108c 8973
c906108c
SS
8974Because C is so widespread, most of the expressions shown in examples in
8975this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
8976Languages}, for information on how to use expressions in other
8977languages.
8978
8979In this section, we discuss operators that you can use in @value{GDBN}
8980expressions regardless of your programming language.
8981
15387254 8982@cindex casts, in expressions
c906108c
SS
8983Casts are supported in all languages, not just in C, because it is so
8984useful to cast a number into a pointer in order to examine a structure
8985at that address in memory.
8986@c FIXME: casts supported---Mod2 true?
c906108c
SS
8987
8988@value{GDBN} supports these operators, in addition to those common
8989to programming languages:
8990
8991@table @code
8992@item @@
8993@samp{@@} is a binary operator for treating parts of memory as arrays.
79a6e687 8994@xref{Arrays, ,Artificial Arrays}, for more information.
c906108c
SS
8995
8996@item ::
8997@samp{::} allows you to specify a variable in terms of the file or
79a6e687 8998function where it is defined. @xref{Variables, ,Program Variables}.
c906108c
SS
8999
9000@cindex @{@var{type}@}
9001@cindex type casting memory
9002@cindex memory, viewing as typed object
9003@cindex casts, to view memory
9004@item @{@var{type}@} @var{addr}
9005Refers to an object of type @var{type} stored at address @var{addr} in
697aa1b7
EZ
9006memory. The address @var{addr} may be any expression whose value is
9007an integer or pointer (but parentheses are required around binary
9008operators, just as in a cast). This construct is allowed regardless
9009of what kind of data is normally supposed to reside at @var{addr}.
c906108c
SS
9010@end table
9011
6ba66d6a
JB
9012@node Ambiguous Expressions
9013@section Ambiguous Expressions
9014@cindex ambiguous expressions
9015
9016Expressions can sometimes contain some ambiguous elements. For instance,
9017some programming languages (notably Ada, C@t{++} and Objective-C) permit
9018a single function name to be defined several times, for application in
9019different contexts. This is called @dfn{overloading}. Another example
9020involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
9021templates and is typically instantiated several times, resulting in
9022the same function name being defined in different contexts.
9023
9024In some cases and depending on the language, it is possible to adjust
9025the expression to remove the ambiguity. For instance in C@t{++}, you
9026can specify the signature of the function you want to break on, as in
9027@kbd{break @var{function}(@var{types})}. In Ada, using the fully
9028qualified name of your function often makes the expression unambiguous
9029as well.
9030
9031When an ambiguity that needs to be resolved is detected, the debugger
9032has the capability to display a menu of numbered choices for each
9033possibility, and then waits for the selection with the prompt @samp{>}.
9034The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
9035aborts the current command. If the command in which the expression was
9036used allows more than one choice to be selected, the next option in the
9037menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
9038choices.
9039
9040For example, the following session excerpt shows an attempt to set a
9041breakpoint at the overloaded symbol @code{String::after}.
9042We choose three particular definitions of that function name:
9043
9044@c FIXME! This is likely to change to show arg type lists, at least
9045@smallexample
9046@group
9047(@value{GDBP}) b String::after
9048[0] cancel
9049[1] all
9050[2] file:String.cc; line number:867
9051[3] file:String.cc; line number:860
9052[4] file:String.cc; line number:875
9053[5] file:String.cc; line number:853
9054[6] file:String.cc; line number:846
9055[7] file:String.cc; line number:735
9056> 2 4 6
9057Breakpoint 1 at 0xb26c: file String.cc, line 867.
9058Breakpoint 2 at 0xb344: file String.cc, line 875.
9059Breakpoint 3 at 0xafcc: file String.cc, line 846.
9060Multiple breakpoints were set.
9061Use the "delete" command to delete unwanted
9062 breakpoints.
9063(@value{GDBP})
9064@end group
9065@end smallexample
9066
9067@table @code
9068@kindex set multiple-symbols
9069@item set multiple-symbols @var{mode}
9070@cindex multiple-symbols menu
9071
9072This option allows you to adjust the debugger behavior when an expression
9073is ambiguous.
9074
9075By default, @var{mode} is set to @code{all}. If the command with which
9076the expression is used allows more than one choice, then @value{GDBN}
9077automatically selects all possible choices. For instance, inserting
9078a breakpoint on a function using an ambiguous name results in a breakpoint
9079inserted on each possible match. However, if a unique choice must be made,
9080then @value{GDBN} uses the menu to help you disambiguate the expression.
9081For instance, printing the address of an overloaded function will result
9082in the use of the menu.
9083
9084When @var{mode} is set to @code{ask}, the debugger always uses the menu
9085when an ambiguity is detected.
9086
9087Finally, when @var{mode} is set to @code{cancel}, the debugger reports
9088an error due to the ambiguity and the command is aborted.
9089
9090@kindex show multiple-symbols
9091@item show multiple-symbols
9092Show the current value of the @code{multiple-symbols} setting.
9093@end table
9094
6d2ebf8b 9095@node Variables
79a6e687 9096@section Program Variables
c906108c
SS
9097
9098The most common kind of expression to use is the name of a variable
9099in your program.
9100
9101Variables in expressions are understood in the selected stack frame
79a6e687 9102(@pxref{Selection, ,Selecting a Frame}); they must be either:
c906108c
SS
9103
9104@itemize @bullet
9105@item
9106global (or file-static)
9107@end itemize
9108
5d161b24 9109@noindent or
c906108c
SS
9110
9111@itemize @bullet
9112@item
9113visible according to the scope rules of the
9114programming language from the point of execution in that frame
5d161b24 9115@end itemize
c906108c
SS
9116
9117@noindent This means that in the function
9118
474c8240 9119@smallexample
c906108c
SS
9120foo (a)
9121 int a;
9122@{
9123 bar (a);
9124 @{
9125 int b = test ();
9126 bar (b);
9127 @}
9128@}
474c8240 9129@end smallexample
c906108c
SS
9130
9131@noindent
9132you can examine and use the variable @code{a} whenever your program is
9133executing within the function @code{foo}, but you can only use or
9134examine the variable @code{b} while your program is executing inside
9135the block where @code{b} is declared.
9136
9137@cindex variable name conflict
9138There is an exception: you can refer to a variable or function whose
9139scope is a single source file even if the current execution point is not
9140in this file. But it is possible to have more than one such variable or
9141function with the same name (in different source files). If that
9142happens, referring to that name has unpredictable effects. If you wish,
72384ba3 9143you can specify a static variable in a particular function or file by
15387254 9144using the colon-colon (@code{::}) notation:
c906108c 9145
d4f3574e 9146@cindex colon-colon, context for variables/functions
12c27660 9147@ifnotinfo
c906108c 9148@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 9149@cindex @code{::}, context for variables/functions
12c27660 9150@end ifnotinfo
474c8240 9151@smallexample
c906108c
SS
9152@var{file}::@var{variable}
9153@var{function}::@var{variable}
474c8240 9154@end smallexample
c906108c
SS
9155
9156@noindent
9157Here @var{file} or @var{function} is the name of the context for the
9158static @var{variable}. In the case of file names, you can use quotes to
9159make sure @value{GDBN} parses the file name as a single word---for example,
9160to print a global value of @code{x} defined in @file{f2.c}:
9161
474c8240 9162@smallexample
c906108c 9163(@value{GDBP}) p 'f2.c'::x
474c8240 9164@end smallexample
c906108c 9165
72384ba3
PH
9166The @code{::} notation is normally used for referring to
9167static variables, since you typically disambiguate uses of local variables
9168in functions by selecting the appropriate frame and using the
9169simple name of the variable. However, you may also use this notation
9170to refer to local variables in frames enclosing the selected frame:
9171
9172@smallexample
9173void
9174foo (int a)
9175@{
9176 if (a < 10)
9177 bar (a);
9178 else
9179 process (a); /* Stop here */
9180@}
9181
9182int
9183bar (int a)
9184@{
9185 foo (a + 5);
9186@}
9187@end smallexample
9188
9189@noindent
9190For example, if there is a breakpoint at the commented line,
9191here is what you might see
9192when the program stops after executing the call @code{bar(0)}:
9193
9194@smallexample
9195(@value{GDBP}) p a
9196$1 = 10
9197(@value{GDBP}) p bar::a
9198$2 = 5
9199(@value{GDBP}) up 2
9200#2 0x080483d0 in foo (a=5) at foobar.c:12
9201(@value{GDBP}) p a
9202$3 = 5
9203(@value{GDBP}) p bar::a
9204$4 = 0
9205@end smallexample
9206
b37052ae 9207@cindex C@t{++} scope resolution
805e1f19
TT
9208These uses of @samp{::} are very rarely in conflict with the very
9209similar use of the same notation in C@t{++}. When they are in
9210conflict, the C@t{++} meaning takes precedence; however, this can be
9211overridden by quoting the file or function name with single quotes.
9212
9213For example, suppose the program is stopped in a method of a class
9214that has a field named @code{includefile}, and there is also an
9215include file named @file{includefile} that defines a variable,
9216@code{some_global}.
9217
9218@smallexample
9219(@value{GDBP}) p includefile
9220$1 = 23
9221(@value{GDBP}) p includefile::some_global
9222A syntax error in expression, near `'.
9223(@value{GDBP}) p 'includefile'::some_global
9224$2 = 27
9225@end smallexample
c906108c
SS
9226
9227@cindex wrong values
9228@cindex variable values, wrong
15387254
EZ
9229@cindex function entry/exit, wrong values of variables
9230@cindex optimized code, wrong values of variables
c906108c
SS
9231@quotation
9232@emph{Warning:} Occasionally, a local variable may appear to have the
9233wrong value at certain points in a function---just after entry to a new
9234scope, and just before exit.
9235@end quotation
9236You may see this problem when you are stepping by machine instructions.
9237This is because, on most machines, it takes more than one instruction to
9238set up a stack frame (including local variable definitions); if you are
9239stepping by machine instructions, variables may appear to have the wrong
9240values until the stack frame is completely built. On exit, it usually
9241also takes more than one machine instruction to destroy a stack frame;
9242after you begin stepping through that group of instructions, local
9243variable definitions may be gone.
9244
9245This may also happen when the compiler does significant optimizations.
9246To be sure of always seeing accurate values, turn off all optimization
9247when compiling.
9248
d4f3574e
SS
9249@cindex ``No symbol "foo" in current context''
9250Another possible effect of compiler optimizations is to optimize
9251unused variables out of existence, or assign variables to registers (as
9252opposed to memory addresses). Depending on the support for such cases
9253offered by the debug info format used by the compiler, @value{GDBN}
9254might not be able to display values for such local variables. If that
9255happens, @value{GDBN} will print a message like this:
9256
474c8240 9257@smallexample
d4f3574e 9258No symbol "foo" in current context.
474c8240 9259@end smallexample
d4f3574e
SS
9260
9261To solve such problems, either recompile without optimizations, or use a
9262different debug info format, if the compiler supports several such
e0f8f636
TT
9263formats. @xref{Compilation}, for more information on choosing compiler
9264options. @xref{C, ,C and C@t{++}}, for more information about debug
9265info formats that are best suited to C@t{++} programs.
d4f3574e 9266
ab1adacd
EZ
9267If you ask to print an object whose contents are unknown to
9268@value{GDBN}, e.g., because its data type is not completely specified
9269by the debug information, @value{GDBN} will say @samp{<incomplete
9270type>}. @xref{Symbols, incomplete type}, for more about this.
9271
d69cf9b2
PA
9272@cindex no debug info variables
9273If you try to examine or use the value of a (global) variable for
9274which @value{GDBN} has no type information, e.g., because the program
9275includes no debug information, @value{GDBN} displays an error message.
9276@xref{Symbols, unknown type}, for more about unknown types. If you
9277cast the variable to its declared type, @value{GDBN} gets the
9278variable's value using the cast-to type as the variable's type. For
9279example, in a C program:
9280
9281@smallexample
9282 (@value{GDBP}) p var
9283 'var' has unknown type; cast it to its declared type
9284 (@value{GDBP}) p (float) var
9285 $1 = 3.14
9286@end smallexample
9287
36b11add
JK
9288If you append @kbd{@@entry} string to a function parameter name you get its
9289value at the time the function got called. If the value is not available an
9290error message is printed. Entry values are available only with some compilers.
9291Entry values are normally also printed at the function parameter list according
9292to @ref{set print entry-values}.
9293
9294@smallexample
9295Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
929629 i++;
9297(gdb) next
929830 e (i);
9299(gdb) print i
9300$1 = 31
9301(gdb) print i@@entry
9302$2 = 30
9303@end smallexample
9304
3a60f64e
JK
9305Strings are identified as arrays of @code{char} values without specified
9306signedness. Arrays of either @code{signed char} or @code{unsigned char} get
9307printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
9308@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
9309defines literal string type @code{"char"} as @code{char} without a sign.
9310For program code
9311
9312@smallexample
9313char var0[] = "A";
9314signed char var1[] = "A";
9315@end smallexample
9316
9317You get during debugging
9318@smallexample
9319(gdb) print var0
9320$1 = "A"
9321(gdb) print var1
9322$2 = @{65 'A', 0 '\0'@}
9323@end smallexample
9324
6d2ebf8b 9325@node Arrays
79a6e687 9326@section Artificial Arrays
c906108c
SS
9327
9328@cindex artificial array
15387254 9329@cindex arrays
41afff9a 9330@kindex @@@r{, referencing memory as an array}
c906108c
SS
9331It is often useful to print out several successive objects of the
9332same type in memory; a section of an array, or an array of
9333dynamically determined size for which only a pointer exists in the
9334program.
9335
9336You can do this by referring to a contiguous span of memory as an
9337@dfn{artificial array}, using the binary operator @samp{@@}. The left
9338operand of @samp{@@} should be the first element of the desired array
9339and be an individual object. The right operand should be the desired length
9340of the array. The result is an array value whose elements are all of
9341the type of the left argument. The first element is actually the left
9342argument; the second element comes from bytes of memory immediately
9343following those that hold the first element, and so on. Here is an
9344example. If a program says
9345
474c8240 9346@smallexample
c906108c 9347int *array = (int *) malloc (len * sizeof (int));
474c8240 9348@end smallexample
c906108c
SS
9349
9350@noindent
9351you can print the contents of @code{array} with
9352
474c8240 9353@smallexample
c906108c 9354p *array@@len
474c8240 9355@end smallexample
c906108c
SS
9356
9357The left operand of @samp{@@} must reside in memory. Array values made
9358with @samp{@@} in this way behave just like other arrays in terms of
9359subscripting, and are coerced to pointers when used in expressions.
9360Artificial arrays most often appear in expressions via the value history
79a6e687 9361(@pxref{Value History, ,Value History}), after printing one out.
c906108c
SS
9362
9363Another way to create an artificial array is to use a cast.
9364This re-interprets a value as if it were an array.
9365The value need not be in memory:
474c8240 9366@smallexample
c906108c
SS
9367(@value{GDBP}) p/x (short[2])0x12345678
9368$1 = @{0x1234, 0x5678@}
474c8240 9369@end smallexample
c906108c
SS
9370
9371As a convenience, if you leave the array length out (as in
c3f6f71d 9372@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 9373the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 9374@smallexample
c906108c
SS
9375(@value{GDBP}) p/x (short[])0x12345678
9376$2 = @{0x1234, 0x5678@}
474c8240 9377@end smallexample
c906108c
SS
9378
9379Sometimes the artificial array mechanism is not quite enough; in
9380moderately complex data structures, the elements of interest may not
9381actually be adjacent---for example, if you are interested in the values
9382of pointers in an array. One useful work-around in this situation is
9383to use a convenience variable (@pxref{Convenience Vars, ,Convenience
79a6e687 9384Variables}) as a counter in an expression that prints the first
c906108c
SS
9385interesting value, and then repeat that expression via @key{RET}. For
9386instance, suppose you have an array @code{dtab} of pointers to
9387structures, and you are interested in the values of a field @code{fv}
9388in each structure. Here is an example of what you might type:
9389
474c8240 9390@smallexample
c906108c
SS
9391set $i = 0
9392p dtab[$i++]->fv
9393@key{RET}
9394@key{RET}
9395@dots{}
474c8240 9396@end smallexample
c906108c 9397
6d2ebf8b 9398@node Output Formats
79a6e687 9399@section Output Formats
c906108c
SS
9400
9401@cindex formatted output
9402@cindex output formats
9403By default, @value{GDBN} prints a value according to its data type. Sometimes
9404this is not what you want. For example, you might want to print a number
9405in hex, or a pointer in decimal. Or you might want to view data in memory
9406at a certain address as a character string or as an instruction. To do
9407these things, specify an @dfn{output format} when you print a value.
9408
9409The simplest use of output formats is to say how to print a value
9410already computed. This is done by starting the arguments of the
9411@code{print} command with a slash and a format letter. The format
9412letters supported are:
9413
9414@table @code
9415@item x
9416Regard the bits of the value as an integer, and print the integer in
9417hexadecimal.
9418
9419@item d
9420Print as integer in signed decimal.
9421
9422@item u
9423Print as integer in unsigned decimal.
9424
9425@item o
9426Print as integer in octal.
9427
9428@item t
9429Print as integer in binary. The letter @samp{t} stands for ``two''.
9430@footnote{@samp{b} cannot be used because these format letters are also
9431used with the @code{x} command, where @samp{b} stands for ``byte'';
79a6e687 9432see @ref{Memory,,Examining Memory}.}
c906108c
SS
9433
9434@item a
9435@cindex unknown address, locating
3d67e040 9436@cindex locate address
c906108c
SS
9437Print as an address, both absolute in hexadecimal and as an offset from
9438the nearest preceding symbol. You can use this format used to discover
9439where (in what function) an unknown address is located:
9440
474c8240 9441@smallexample
c906108c
SS
9442(@value{GDBP}) p/a 0x54320
9443$3 = 0x54320 <_initialize_vx+396>
474c8240 9444@end smallexample
c906108c 9445
3d67e040
EZ
9446@noindent
9447The command @code{info symbol 0x54320} yields similar results.
9448@xref{Symbols, info symbol}.
9449
c906108c 9450@item c
51274035
EZ
9451Regard as an integer and print it as a character constant. This
9452prints both the numerical value and its character representation. The
9453character representation is replaced with the octal escape @samp{\nnn}
9454for characters outside the 7-bit @sc{ascii} range.
c906108c 9455
ea37ba09
DJ
9456Without this format, @value{GDBN} displays @code{char},
9457@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
9458constants. Single-byte members of vectors are displayed as integer
9459data.
9460
c906108c
SS
9461@item f
9462Regard the bits of the value as a floating point number and print
9463using typical floating point syntax.
ea37ba09
DJ
9464
9465@item s
9466@cindex printing strings
9467@cindex printing byte arrays
9468Regard as a string, if possible. With this format, pointers to single-byte
9469data are displayed as null-terminated strings and arrays of single-byte data
9470are displayed as fixed-length strings. Other values are displayed in their
9471natural types.
9472
9473Without this format, @value{GDBN} displays pointers to and arrays of
9474@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
9475strings. Single-byte members of a vector are displayed as an integer
9476array.
a6bac58e 9477
6fbe845e
AB
9478@item z
9479Like @samp{x} formatting, the value is treated as an integer and
9480printed as hexadecimal, but leading zeros are printed to pad the value
9481to the size of the integer type.
9482
a6bac58e
TT
9483@item r
9484@cindex raw printing
9485Print using the @samp{raw} formatting. By default, @value{GDBN} will
78e2826b
TT
9486use a Python-based pretty-printer, if one is available (@pxref{Pretty
9487Printing}). This typically results in a higher-level display of the
9488value's contents. The @samp{r} format bypasses any Python
9489pretty-printer which might exist.
c906108c
SS
9490@end table
9491
9492For example, to print the program counter in hex (@pxref{Registers}), type
9493
474c8240 9494@smallexample
c906108c 9495p/x $pc
474c8240 9496@end smallexample
c906108c
SS
9497
9498@noindent
9499Note that no space is required before the slash; this is because command
9500names in @value{GDBN} cannot contain a slash.
9501
9502To reprint the last value in the value history with a different format,
9503you can use the @code{print} command with just a format and no
9504expression. For example, @samp{p/x} reprints the last value in hex.
9505
6d2ebf8b 9506@node Memory
79a6e687 9507@section Examining Memory
c906108c
SS
9508
9509You can use the command @code{x} (for ``examine'') to examine memory in
9510any of several formats, independently of your program's data types.
9511
9512@cindex examining memory
9513@table @code
41afff9a 9514@kindex x @r{(examine memory)}
c906108c
SS
9515@item x/@var{nfu} @var{addr}
9516@itemx x @var{addr}
9517@itemx x
9518Use the @code{x} command to examine memory.
9519@end table
9520
9521@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
9522much memory to display and how to format it; @var{addr} is an
9523expression giving the address where you want to start displaying memory.
9524If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
9525Several commands set convenient defaults for @var{addr}.
9526
9527@table @r
9528@item @var{n}, the repeat count
9529The repeat count is a decimal integer; the default is 1. It specifies
bb556f1f
TK
9530how much memory (counting by units @var{u}) to display. If a negative
9531number is specified, memory is examined backward from @var{addr}.
c906108c
SS
9532@c This really is **decimal**; unaffected by 'set radix' as of GDB
9533@c 4.1.2.
9534
9535@item @var{f}, the display format
51274035
EZ
9536The display format is one of the formats used by @code{print}
9537(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
ea37ba09
DJ
9538@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
9539The default is @samp{x} (hexadecimal) initially. The default changes
9540each time you use either @code{x} or @code{print}.
c906108c
SS
9541
9542@item @var{u}, the unit size
9543The unit size is any of
9544
9545@table @code
9546@item b
9547Bytes.
9548@item h
9549Halfwords (two bytes).
9550@item w
9551Words (four bytes). This is the initial default.
9552@item g
9553Giant words (eight bytes).
9554@end table
9555
9556Each time you specify a unit size with @code{x}, that size becomes the
9a22f0d0
PM
9557default unit the next time you use @code{x}. For the @samp{i} format,
9558the unit size is ignored and is normally not written. For the @samp{s} format,
9559the unit size defaults to @samp{b}, unless it is explicitly given.
9560Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
956132-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
9562Note that the results depend on the programming language of the
9563current compilation unit. If the language is C, the @samp{s}
9564modifier will use the UTF-16 encoding while @samp{w} will use
9565UTF-32. The encoding is set by the programming language and cannot
9566be altered.
c906108c
SS
9567
9568@item @var{addr}, starting display address
9569@var{addr} is the address where you want @value{GDBN} to begin displaying
9570memory. The expression need not have a pointer value (though it may);
9571it is always interpreted as an integer address of a byte of memory.
9572@xref{Expressions, ,Expressions}, for more information on expressions. The default for
9573@var{addr} is usually just after the last address examined---but several
9574other commands also set the default address: @code{info breakpoints} (to
9575the address of the last breakpoint listed), @code{info line} (to the
9576starting address of a line), and @code{print} (if you use it to display
9577a value from memory).
9578@end table
9579
9580For example, @samp{x/3uh 0x54320} is a request to display three halfwords
9581(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
9582starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
9583words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 9584@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c 9585
bb556f1f
TK
9586You can also specify a negative repeat count to examine memory backward
9587from the given address. For example, @samp{x/-3uh 0x54320} prints three
9588halfwords (@code{h}) at @code{0x54314}, @code{0x54328}, and @code{0x5431c}.
9589
c906108c
SS
9590Since the letters indicating unit sizes are all distinct from the
9591letters specifying output formats, you do not have to remember whether
9592unit size or format comes first; either order works. The output
9593specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
9594(However, the count @var{n} must come first; @samp{wx4} does not work.)
9595
9596Even though the unit size @var{u} is ignored for the formats @samp{s}
9597and @samp{i}, you might still want to use a count @var{n}; for example,
9598@samp{3i} specifies that you want to see three machine instructions,
a4642986
MR
9599including any operands. For convenience, especially when used with
9600the @code{display} command, the @samp{i} format also prints branch delay
9601slot instructions, if any, beyond the count specified, which immediately
9602follow the last instruction that is within the count. The command
9603@code{disassemble} gives an alternative way of inspecting machine
9604instructions; see @ref{Machine Code,,Source and Machine Code}.
c906108c 9605
bb556f1f
TK
9606If a negative repeat count is specified for the formats @samp{s} or @samp{i},
9607the command displays null-terminated strings or instructions before the given
9608address as many as the absolute value of the given number. For the @samp{i}
9609format, we use line number information in the debug info to accurately locate
9610instruction boundaries while disassembling backward. If line info is not
9611available, the command stops examining memory with an error message.
9612
c906108c
SS
9613All the defaults for the arguments to @code{x} are designed to make it
9614easy to continue scanning memory with minimal specifications each time
9615you use @code{x}. For example, after you have inspected three machine
9616instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
9617with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
9618the repeat count @var{n} is used again; the other arguments default as
9619for successive uses of @code{x}.
9620
2b28d209
PP
9621When examining machine instructions, the instruction at current program
9622counter is shown with a @code{=>} marker. For example:
9623
9624@smallexample
9625(@value{GDBP}) x/5i $pc-6
9626 0x804837f <main+11>: mov %esp,%ebp
9627 0x8048381 <main+13>: push %ecx
9628 0x8048382 <main+14>: sub $0x4,%esp
9629=> 0x8048385 <main+17>: movl $0x8048460,(%esp)
9630 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
9631@end smallexample
9632
c906108c
SS
9633@cindex @code{$_}, @code{$__}, and value history
9634The addresses and contents printed by the @code{x} command are not saved
9635in the value history because there is often too much of them and they
9636would get in the way. Instead, @value{GDBN} makes these values available for
9637subsequent use in expressions as values of the convenience variables
9638@code{$_} and @code{$__}. After an @code{x} command, the last address
9639examined is available for use in expressions in the convenience variable
9640@code{$_}. The contents of that address, as examined, are available in
9641the convenience variable @code{$__}.
9642
9643If the @code{x} command has a repeat count, the address and contents saved
9644are from the last memory unit printed; this is not the same as the last
9645address printed if several units were printed on the last line of output.
9646
a86c90e6
SM
9647@anchor{addressable memory unit}
9648@cindex addressable memory unit
9649Most targets have an addressable memory unit size of 8 bits. This means
9650that to each memory address are associated 8 bits of data. Some
9651targets, however, have other addressable memory unit sizes.
9652Within @value{GDBN} and this document, the term
9653@dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
9654when explicitly referring to a chunk of data of that size. The word
9655@dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
9656the addressable memory unit size of the target. For most systems,
9657addressable memory unit is a synonym of byte.
9658
09d4efe1 9659@cindex remote memory comparison
936d2992 9660@cindex target memory comparison
09d4efe1 9661@cindex verify remote memory image
936d2992 9662@cindex verify target memory image
09d4efe1 9663When you are debugging a program running on a remote target machine
936d2992
PA
9664(@pxref{Remote Debugging}), you may wish to verify the program's image
9665in the remote machine's memory against the executable file you
9666downloaded to the target. Or, on any target, you may want to check
9667whether the program has corrupted its own read-only sections. The
9668@code{compare-sections} command is provided for such situations.
09d4efe1
EZ
9669
9670@table @code
9671@kindex compare-sections
95cf3b38 9672@item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
09d4efe1
EZ
9673Compare the data of a loadable section @var{section-name} in the
9674executable file of the program being debugged with the same section in
936d2992 9675the target machine's memory, and report any mismatches. With no
95cf3b38 9676arguments, compares all loadable sections. With an argument of
936d2992
PA
9677@code{-r}, compares all loadable read-only sections.
9678
9679Note: for remote targets, this command can be accelerated if the
9680target supports computing the CRC checksum of a block of memory
9681(@pxref{qCRC packet}).
09d4efe1
EZ
9682@end table
9683
6d2ebf8b 9684@node Auto Display
79a6e687 9685@section Automatic Display
c906108c
SS
9686@cindex automatic display
9687@cindex display of expressions
9688
9689If you find that you want to print the value of an expression frequently
9690(to see how it changes), you might want to add it to the @dfn{automatic
9691display list} so that @value{GDBN} prints its value each time your program stops.
9692Each expression added to the list is given a number to identify it;
9693to remove an expression from the list, you specify that number.
9694The automatic display looks like this:
9695
474c8240 9696@smallexample
c906108c
SS
96972: foo = 38
96983: bar[5] = (struct hack *) 0x3804
474c8240 9699@end smallexample
c906108c
SS
9700
9701@noindent
9702This display shows item numbers, expressions and their current values. As with
9703displays you request manually using @code{x} or @code{print}, you can
9704specify the output format you prefer; in fact, @code{display} decides
ea37ba09
DJ
9705whether to use @code{print} or @code{x} depending your format
9706specification---it uses @code{x} if you specify either the @samp{i}
9707or @samp{s} format, or a unit size; otherwise it uses @code{print}.
c906108c
SS
9708
9709@table @code
9710@kindex display
d4f3574e
SS
9711@item display @var{expr}
9712Add the expression @var{expr} to the list of expressions to display
c906108c
SS
9713each time your program stops. @xref{Expressions, ,Expressions}.
9714
9715@code{display} does not repeat if you press @key{RET} again after using it.
9716
d4f3574e 9717@item display/@var{fmt} @var{expr}
c906108c 9718For @var{fmt} specifying only a display format and not a size or
d4f3574e 9719count, add the expression @var{expr} to the auto-display list but
c906108c 9720arrange to display it each time in the specified format @var{fmt}.
79a6e687 9721@xref{Output Formats,,Output Formats}.
c906108c
SS
9722
9723@item display/@var{fmt} @var{addr}
9724For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
9725number of units, add the expression @var{addr} as a memory address to
9726be examined each time your program stops. Examining means in effect
79a6e687 9727doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
c906108c
SS
9728@end table
9729
9730For example, @samp{display/i $pc} can be helpful, to see the machine
9731instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 9732is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
9733
9734@table @code
9735@kindex delete display
9736@kindex undisplay
9737@item undisplay @var{dnums}@dots{}
9738@itemx delete display @var{dnums}@dots{}
c9174737
PA
9739Remove items from the list of expressions to display. Specify the
9740numbers of the displays that you want affected with the command
9741argument @var{dnums}. It can be a single display number, one of the
9742numbers shown in the first field of the @samp{info display} display;
9743or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
9744
9745@code{undisplay} does not repeat if you press @key{RET} after using it.
9746(Otherwise you would just get the error @samp{No display number @dots{}}.)
9747
9748@kindex disable display
9749@item disable display @var{dnums}@dots{}
9750Disable the display of item numbers @var{dnums}. A disabled display
9751item is not printed automatically, but is not forgotten. It may be
c9174737
PA
9752enabled again later. Specify the numbers of the displays that you
9753want affected with the command argument @var{dnums}. It can be a
9754single display number, one of the numbers shown in the first field of
9755the @samp{info display} display; or it could be a range of display
9756numbers, as in @code{2-4}.
c906108c
SS
9757
9758@kindex enable display
9759@item enable display @var{dnums}@dots{}
9760Enable display of item numbers @var{dnums}. It becomes effective once
9761again in auto display of its expression, until you specify otherwise.
c9174737
PA
9762Specify the numbers of the displays that you want affected with the
9763command argument @var{dnums}. It can be a single display number, one
9764of the numbers shown in the first field of the @samp{info display}
9765display; or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
9766
9767@item display
9768Display the current values of the expressions on the list, just as is
9769done when your program stops.
9770
9771@kindex info display
9772@item info display
9773Print the list of expressions previously set up to display
9774automatically, each one with its item number, but without showing the
9775values. This includes disabled expressions, which are marked as such.
9776It also includes expressions which would not be displayed right now
9777because they refer to automatic variables not currently available.
9778@end table
9779
15387254 9780@cindex display disabled out of scope
c906108c
SS
9781If a display expression refers to local variables, then it does not make
9782sense outside the lexical context for which it was set up. Such an
9783expression is disabled when execution enters a context where one of its
9784variables is not defined. For example, if you give the command
9785@code{display last_char} while inside a function with an argument
9786@code{last_char}, @value{GDBN} displays this argument while your program
9787continues to stop inside that function. When it stops elsewhere---where
9788there is no variable @code{last_char}---the display is disabled
9789automatically. The next time your program stops where @code{last_char}
9790is meaningful, you can enable the display expression once again.
9791
6d2ebf8b 9792@node Print Settings
79a6e687 9793@section Print Settings
c906108c
SS
9794
9795@cindex format options
9796@cindex print settings
9797@value{GDBN} provides the following ways to control how arrays, structures,
9798and symbols are printed.
9799
9800@noindent
9801These settings are useful for debugging programs in any language:
9802
9803@table @code
4644b6e3 9804@kindex set print
c906108c
SS
9805@item set print address
9806@itemx set print address on
4644b6e3 9807@cindex print/don't print memory addresses
c906108c
SS
9808@value{GDBN} prints memory addresses showing the location of stack
9809traces, structure values, pointer values, breakpoints, and so forth,
9810even when it also displays the contents of those addresses. The default
9811is @code{on}. For example, this is what a stack frame display looks like with
9812@code{set print address on}:
9813
9814@smallexample
9815@group
9816(@value{GDBP}) f
9817#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
9818 at input.c:530
9819530 if (lquote != def_lquote)
9820@end group
9821@end smallexample
9822
9823@item set print address off
9824Do not print addresses when displaying their contents. For example,
9825this is the same stack frame displayed with @code{set print address off}:
9826
9827@smallexample
9828@group
9829(@value{GDBP}) set print addr off
9830(@value{GDBP}) f
9831#0 set_quotes (lq="<<", rq=">>") at input.c:530
9832530 if (lquote != def_lquote)
9833@end group
9834@end smallexample
9835
9836You can use @samp{set print address off} to eliminate all machine
9837dependent displays from the @value{GDBN} interface. For example, with
9838@code{print address off}, you should get the same text for backtraces on
9839all machines---whether or not they involve pointer arguments.
9840
4644b6e3 9841@kindex show print
c906108c
SS
9842@item show print address
9843Show whether or not addresses are to be printed.
9844@end table
9845
9846When @value{GDBN} prints a symbolic address, it normally prints the
9847closest earlier symbol plus an offset. If that symbol does not uniquely
9848identify the address (for example, it is a name whose scope is a single
9849source file), you may need to clarify. One way to do this is with
9850@code{info line}, for example @samp{info line *0x4537}. Alternately,
9851you can set @value{GDBN} to print the source file and line number when
9852it prints a symbolic address:
9853
9854@table @code
c906108c 9855@item set print symbol-filename on
9c16f35a
EZ
9856@cindex source file and line of a symbol
9857@cindex symbol, source file and line
c906108c
SS
9858Tell @value{GDBN} to print the source file name and line number of a
9859symbol in the symbolic form of an address.
9860
9861@item set print symbol-filename off
9862Do not print source file name and line number of a symbol. This is the
9863default.
9864
c906108c
SS
9865@item show print symbol-filename
9866Show whether or not @value{GDBN} will print the source file name and
9867line number of a symbol in the symbolic form of an address.
9868@end table
9869
9870Another situation where it is helpful to show symbol filenames and line
9871numbers is when disassembling code; @value{GDBN} shows you the line
9872number and source file that corresponds to each instruction.
9873
9874Also, you may wish to see the symbolic form only if the address being
9875printed is reasonably close to the closest earlier symbol:
9876
9877@table @code
c906108c 9878@item set print max-symbolic-offset @var{max-offset}
f81d1120 9879@itemx set print max-symbolic-offset unlimited
4644b6e3 9880@cindex maximum value for offset of closest symbol
c906108c
SS
9881Tell @value{GDBN} to only display the symbolic form of an address if the
9882offset between the closest earlier symbol and the address is less than
f81d1120
PA
9883@var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
9884to always print the symbolic form of an address if any symbol precedes
9885it. Zero is equivalent to @code{unlimited}.
c906108c 9886
c906108c
SS
9887@item show print max-symbolic-offset
9888Ask how large the maximum offset is that @value{GDBN} prints in a
9889symbolic address.
9890@end table
9891
9892@cindex wild pointer, interpreting
9893@cindex pointer, finding referent
9894If you have a pointer and you are not sure where it points, try
9895@samp{set print symbol-filename on}. Then you can determine the name
9896and source file location of the variable where it points, using
9897@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
9898For example, here @value{GDBN} shows that a variable @code{ptt} points
9899at another variable @code{t}, defined in @file{hi2.c}:
9900
474c8240 9901@smallexample
c906108c
SS
9902(@value{GDBP}) set print symbol-filename on
9903(@value{GDBP}) p/a ptt
9904$4 = 0xe008 <t in hi2.c>
474c8240 9905@end smallexample
c906108c
SS
9906
9907@quotation
9908@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
9909does not show the symbol name and filename of the referent, even with
9910the appropriate @code{set print} options turned on.
9911@end quotation
9912
9cb709b6
TT
9913You can also enable @samp{/a}-like formatting all the time using
9914@samp{set print symbol on}:
9915
9916@table @code
9917@item set print symbol on
9918Tell @value{GDBN} to print the symbol corresponding to an address, if
9919one exists.
9920
9921@item set print symbol off
9922Tell @value{GDBN} not to print the symbol corresponding to an
9923address. In this mode, @value{GDBN} will still print the symbol
9924corresponding to pointers to functions. This is the default.
9925
9926@item show print symbol
9927Show whether @value{GDBN} will display the symbol corresponding to an
9928address.
9929@end table
9930
c906108c
SS
9931Other settings control how different kinds of objects are printed:
9932
9933@table @code
c906108c
SS
9934@item set print array
9935@itemx set print array on
4644b6e3 9936@cindex pretty print arrays
c906108c
SS
9937Pretty print arrays. This format is more convenient to read,
9938but uses more space. The default is off.
9939
9940@item set print array off
9941Return to compressed format for arrays.
9942
c906108c
SS
9943@item show print array
9944Show whether compressed or pretty format is selected for displaying
9945arrays.
9946
3c9c013a
JB
9947@cindex print array indexes
9948@item set print array-indexes
9949@itemx set print array-indexes on
9950Print the index of each element when displaying arrays. May be more
9951convenient to locate a given element in the array or quickly find the
9952index of a given element in that printed array. The default is off.
9953
9954@item set print array-indexes off
9955Stop printing element indexes when displaying arrays.
9956
9957@item show print array-indexes
9958Show whether the index of each element is printed when displaying
9959arrays.
9960
c906108c 9961@item set print elements @var{number-of-elements}
f81d1120 9962@itemx set print elements unlimited
4644b6e3 9963@cindex number of array elements to print
9c16f35a 9964@cindex limit on number of printed array elements
c906108c
SS
9965Set a limit on how many elements of an array @value{GDBN} will print.
9966If @value{GDBN} is printing a large array, it stops printing after it has
9967printed the number of elements set by the @code{set print elements} command.
9968This limit also applies to the display of strings.
d4f3574e 9969When @value{GDBN} starts, this limit is set to 200.
f81d1120
PA
9970Setting @var{number-of-elements} to @code{unlimited} or zero means
9971that the number of elements to print is unlimited.
c906108c 9972
c906108c
SS
9973@item show print elements
9974Display the number of elements of a large array that @value{GDBN} will print.
9975If the number is 0, then the printing is unlimited.
9976
b4740add 9977@item set print frame-arguments @var{value}
a0381d3a 9978@kindex set print frame-arguments
b4740add
JB
9979@cindex printing frame argument values
9980@cindex print all frame argument values
9981@cindex print frame argument values for scalars only
9982@cindex do not print frame argument values
9983This command allows to control how the values of arguments are printed
9984when the debugger prints a frame (@pxref{Frames}). The possible
9985values are:
9986
9987@table @code
9988@item all
4f5376b2 9989The values of all arguments are printed.
b4740add
JB
9990
9991@item scalars
9992Print the value of an argument only if it is a scalar. The value of more
9993complex arguments such as arrays, structures, unions, etc, is replaced
4f5376b2
JB
9994by @code{@dots{}}. This is the default. Here is an example where
9995only scalar arguments are shown:
b4740add
JB
9996
9997@smallexample
9998#1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
9999 at frame-args.c:23
10000@end smallexample
10001
10002@item none
10003None of the argument values are printed. Instead, the value of each argument
10004is replaced by @code{@dots{}}. In this case, the example above now becomes:
10005
10006@smallexample
10007#1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
10008 at frame-args.c:23
10009@end smallexample
10010@end table
10011
4f5376b2
JB
10012By default, only scalar arguments are printed. This command can be used
10013to configure the debugger to print the value of all arguments, regardless
10014of their type. However, it is often advantageous to not print the value
10015of more complex parameters. For instance, it reduces the amount of
10016information printed in each frame, making the backtrace more readable.
10017Also, it improves performance when displaying Ada frames, because
10018the computation of large arguments can sometimes be CPU-intensive,
10019especially in large applications. Setting @code{print frame-arguments}
10020to @code{scalars} (the default) or @code{none} avoids this computation,
10021thus speeding up the display of each Ada frame.
b4740add
JB
10022
10023@item show print frame-arguments
10024Show how the value of arguments should be displayed when printing a frame.
10025
e7045703
DE
10026@item set print raw frame-arguments on
10027Print frame arguments in raw, non pretty-printed, form.
10028
10029@item set print raw frame-arguments off
10030Print frame arguments in pretty-printed form, if there is a pretty-printer
10031for the value (@pxref{Pretty Printing}),
10032otherwise print the value in raw form.
10033This is the default.
10034
10035@item show print raw frame-arguments
10036Show whether to print frame arguments in raw form.
10037
36b11add 10038@anchor{set print entry-values}
e18b2753
JK
10039@item set print entry-values @var{value}
10040@kindex set print entry-values
10041Set printing of frame argument values at function entry. In some cases
10042@value{GDBN} can determine the value of function argument which was passed by
10043the function caller, even if the value was modified inside the called function
10044and therefore is different. With optimized code, the current value could be
10045unavailable, but the entry value may still be known.
10046
10047The default value is @code{default} (see below for its description). Older
10048@value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
10049this feature will behave in the @code{default} setting the same way as with the
10050@code{no} setting.
10051
10052This functionality is currently supported only by DWARF 2 debugging format and
216f72a1 10053the compiler has to produce @samp{DW_TAG_call_site} tags. With
e18b2753
JK
10054@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
10055this information.
10056
10057The @var{value} parameter can be one of the following:
10058
10059@table @code
10060@item no
10061Print only actual parameter values, never print values from function entry
10062point.
10063@smallexample
10064#0 equal (val=5)
10065#0 different (val=6)
10066#0 lost (val=<optimized out>)
10067#0 born (val=10)
10068#0 invalid (val=<optimized out>)
10069@end smallexample
10070
10071@item only
10072Print only parameter values from function entry point. The actual parameter
10073values are never printed.
10074@smallexample
10075#0 equal (val@@entry=5)
10076#0 different (val@@entry=5)
10077#0 lost (val@@entry=5)
10078#0 born (val@@entry=<optimized out>)
10079#0 invalid (val@@entry=<optimized out>)
10080@end smallexample
10081
10082@item preferred
10083Print only parameter values from function entry point. If value from function
10084entry point is not known while the actual value is known, print the actual
10085value for such parameter.
10086@smallexample
10087#0 equal (val@@entry=5)
10088#0 different (val@@entry=5)
10089#0 lost (val@@entry=5)
10090#0 born (val=10)
10091#0 invalid (val@@entry=<optimized out>)
10092@end smallexample
10093
10094@item if-needed
10095Print actual parameter values. If actual parameter value is not known while
10096value from function entry point is known, print the entry point value for such
10097parameter.
10098@smallexample
10099#0 equal (val=5)
10100#0 different (val=6)
10101#0 lost (val@@entry=5)
10102#0 born (val=10)
10103#0 invalid (val=<optimized out>)
10104@end smallexample
10105
10106@item both
10107Always print both the actual parameter value and its value from function entry
10108point, even if values of one or both are not available due to compiler
10109optimizations.
10110@smallexample
10111#0 equal (val=5, val@@entry=5)
10112#0 different (val=6, val@@entry=5)
10113#0 lost (val=<optimized out>, val@@entry=5)
10114#0 born (val=10, val@@entry=<optimized out>)
10115#0 invalid (val=<optimized out>, val@@entry=<optimized out>)
10116@end smallexample
10117
10118@item compact
10119Print the actual parameter value if it is known and also its value from
10120function entry point if it is known. If neither is known, print for the actual
10121value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
10122values are known and identical, print the shortened
10123@code{param=param@@entry=VALUE} notation.
10124@smallexample
10125#0 equal (val=val@@entry=5)
10126#0 different (val=6, val@@entry=5)
10127#0 lost (val@@entry=5)
10128#0 born (val=10)
10129#0 invalid (val=<optimized out>)
10130@end smallexample
10131
10132@item default
10133Always print the actual parameter value. Print also its value from function
10134entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
10135if both values are known and identical, print the shortened
10136@code{param=param@@entry=VALUE} notation.
10137@smallexample
10138#0 equal (val=val@@entry=5)
10139#0 different (val=6, val@@entry=5)
10140#0 lost (val=<optimized out>, val@@entry=5)
10141#0 born (val=10)
10142#0 invalid (val=<optimized out>)
10143@end smallexample
10144@end table
10145
10146For analysis messages on possible failures of frame argument values at function
10147entry resolution see @ref{set debug entry-values}.
10148
10149@item show print entry-values
10150Show the method being used for printing of frame argument values at function
10151entry.
10152
f81d1120
PA
10153@item set print repeats @var{number-of-repeats}
10154@itemx set print repeats unlimited
9c16f35a
EZ
10155@cindex repeated array elements
10156Set the threshold for suppressing display of repeated array
d3e8051b 10157elements. When the number of consecutive identical elements of an
9c16f35a
EZ
10158array exceeds the threshold, @value{GDBN} prints the string
10159@code{"<repeats @var{n} times>"}, where @var{n} is the number of
10160identical repetitions, instead of displaying the identical elements
f81d1120
PA
10161themselves. Setting the threshold to @code{unlimited} or zero will
10162cause all elements to be individually printed. The default threshold
10163is 10.
9c16f35a
EZ
10164
10165@item show print repeats
10166Display the current threshold for printing repeated identical
10167elements.
10168
c906108c 10169@item set print null-stop
4644b6e3 10170@cindex @sc{null} elements in arrays
c906108c 10171Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 10172@sc{null} is encountered. This is useful when large arrays actually
c906108c 10173contain only short strings.
d4f3574e 10174The default is off.
c906108c 10175
9c16f35a
EZ
10176@item show print null-stop
10177Show whether @value{GDBN} stops printing an array on the first
10178@sc{null} character.
10179
c906108c 10180@item set print pretty on
9c16f35a
EZ
10181@cindex print structures in indented form
10182@cindex indentation in structure display
5d161b24 10183Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
10184per line, like this:
10185
10186@smallexample
10187@group
10188$1 = @{
10189 next = 0x0,
10190 flags = @{
10191 sweet = 1,
10192 sour = 1
10193 @},
10194 meat = 0x54 "Pork"
10195@}
10196@end group
10197@end smallexample
10198
10199@item set print pretty off
10200Cause @value{GDBN} to print structures in a compact format, like this:
10201
10202@smallexample
10203@group
10204$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
10205meat = 0x54 "Pork"@}
10206@end group
10207@end smallexample
10208
10209@noindent
10210This is the default format.
10211
c906108c
SS
10212@item show print pretty
10213Show which format @value{GDBN} is using to print structures.
10214
c906108c 10215@item set print sevenbit-strings on
4644b6e3
EZ
10216@cindex eight-bit characters in strings
10217@cindex octal escapes in strings
c906108c
SS
10218Print using only seven-bit characters; if this option is set,
10219@value{GDBN} displays any eight-bit characters (in strings or
10220character values) using the notation @code{\}@var{nnn}. This setting is
10221best if you are working in English (@sc{ascii}) and you use the
10222high-order bit of characters as a marker or ``meta'' bit.
10223
10224@item set print sevenbit-strings off
10225Print full eight-bit characters. This allows the use of more
10226international character sets, and is the default.
10227
c906108c
SS
10228@item show print sevenbit-strings
10229Show whether or not @value{GDBN} is printing only seven-bit characters.
10230
c906108c 10231@item set print union on
4644b6e3 10232@cindex unions in structures, printing
9c16f35a
EZ
10233Tell @value{GDBN} to print unions which are contained in structures
10234and other unions. This is the default setting.
c906108c
SS
10235
10236@item set print union off
9c16f35a
EZ
10237Tell @value{GDBN} not to print unions which are contained in
10238structures and other unions. @value{GDBN} will print @code{"@{...@}"}
10239instead.
c906108c 10240
c906108c
SS
10241@item show print union
10242Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 10243structures and other unions.
c906108c
SS
10244
10245For example, given the declarations
10246
10247@smallexample
10248typedef enum @{Tree, Bug@} Species;
10249typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 10250typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
10251 Bug_forms;
10252
10253struct thing @{
10254 Species it;
10255 union @{
10256 Tree_forms tree;
10257 Bug_forms bug;
10258 @} form;
10259@};
10260
10261struct thing foo = @{Tree, @{Acorn@}@};
10262@end smallexample
10263
10264@noindent
10265with @code{set print union on} in effect @samp{p foo} would print
10266
10267@smallexample
10268$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
10269@end smallexample
10270
10271@noindent
10272and with @code{set print union off} in effect it would print
10273
10274@smallexample
10275$1 = @{it = Tree, form = @{...@}@}
10276@end smallexample
9c16f35a
EZ
10277
10278@noindent
10279@code{set print union} affects programs written in C-like languages
10280and in Pascal.
c906108c
SS
10281@end table
10282
c906108c
SS
10283@need 1000
10284@noindent
b37052ae 10285These settings are of interest when debugging C@t{++} programs:
c906108c
SS
10286
10287@table @code
4644b6e3 10288@cindex demangling C@t{++} names
c906108c
SS
10289@item set print demangle
10290@itemx set print demangle on
b37052ae 10291Print C@t{++} names in their source form rather than in the encoded
c906108c 10292(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 10293linkage. The default is on.
c906108c 10294
c906108c 10295@item show print demangle
b37052ae 10296Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 10297
c906108c
SS
10298@item set print asm-demangle
10299@itemx set print asm-demangle on
b37052ae 10300Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
10301in assembler code printouts such as instruction disassemblies.
10302The default is off.
10303
c906108c 10304@item show print asm-demangle
b37052ae 10305Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
10306or demangled form.
10307
b37052ae
EZ
10308@cindex C@t{++} symbol decoding style
10309@cindex symbol decoding style, C@t{++}
a8f24a35 10310@kindex set demangle-style
c906108c
SS
10311@item set demangle-style @var{style}
10312Choose among several encoding schemes used by different compilers to
b37052ae 10313represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
10314
10315@table @code
10316@item auto
10317Allow @value{GDBN} to choose a decoding style by inspecting your program.
891df0ea 10318This is the default.
c906108c
SS
10319
10320@item gnu
b37052ae 10321Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c
SS
10322
10323@item hp
b37052ae 10324Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
10325
10326@item lucid
b37052ae 10327Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
10328
10329@item arm
b37052ae 10330Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
10331@strong{Warning:} this setting alone is not sufficient to allow
10332debugging @code{cfront}-generated executables. @value{GDBN} would
10333require further enhancement to permit that.
10334
10335@end table
10336If you omit @var{style}, you will see a list of possible formats.
10337
c906108c 10338@item show demangle-style
b37052ae 10339Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 10340
c906108c
SS
10341@item set print object
10342@itemx set print object on
4644b6e3 10343@cindex derived type of an object, printing
9c16f35a 10344@cindex display derived types
c906108c
SS
10345When displaying a pointer to an object, identify the @emph{actual}
10346(derived) type of the object rather than the @emph{declared} type, using
625c0d47
TT
10347the virtual function table. Note that the virtual function table is
10348required---this feature can only work for objects that have run-time
10349type identification; a single virtual method in the object's declared
8264ba82
AG
10350type is sufficient. Note that this setting is also taken into account when
10351working with variable objects via MI (@pxref{GDB/MI}).
c906108c
SS
10352
10353@item set print object off
10354Display only the declared type of objects, without reference to the
10355virtual function table. This is the default setting.
10356
c906108c
SS
10357@item show print object
10358Show whether actual, or declared, object types are displayed.
10359
c906108c
SS
10360@item set print static-members
10361@itemx set print static-members on
4644b6e3 10362@cindex static members of C@t{++} objects
b37052ae 10363Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
10364
10365@item set print static-members off
b37052ae 10366Do not print static members when displaying a C@t{++} object.
c906108c 10367
c906108c 10368@item show print static-members
9c16f35a
EZ
10369Show whether C@t{++} static members are printed or not.
10370
10371@item set print pascal_static-members
10372@itemx set print pascal_static-members on
d3e8051b
EZ
10373@cindex static members of Pascal objects
10374@cindex Pascal objects, static members display
9c16f35a
EZ
10375Print static members when displaying a Pascal object. The default is on.
10376
10377@item set print pascal_static-members off
10378Do not print static members when displaying a Pascal object.
10379
10380@item show print pascal_static-members
10381Show whether Pascal static members are printed or not.
c906108c
SS
10382
10383@c These don't work with HP ANSI C++ yet.
c906108c
SS
10384@item set print vtbl
10385@itemx set print vtbl on
4644b6e3 10386@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
10387@cindex virtual functions (C@t{++}) display
10388@cindex VTBL display
b37052ae 10389Pretty print C@t{++} virtual function tables. The default is off.
c906108c 10390(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 10391ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
10392
10393@item set print vtbl off
b37052ae 10394Do not pretty print C@t{++} virtual function tables.
c906108c 10395
c906108c 10396@item show print vtbl
b37052ae 10397Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 10398@end table
c906108c 10399
4c374409
JK
10400@node Pretty Printing
10401@section Pretty Printing
10402
10403@value{GDBN} provides a mechanism to allow pretty-printing of values using
10404Python code. It greatly simplifies the display of complex objects. This
10405mechanism works for both MI and the CLI.
10406
7b51bc51
DE
10407@menu
10408* Pretty-Printer Introduction:: Introduction to pretty-printers
10409* Pretty-Printer Example:: An example pretty-printer
10410* Pretty-Printer Commands:: Pretty-printer commands
10411@end menu
10412
10413@node Pretty-Printer Introduction
10414@subsection Pretty-Printer Introduction
10415
10416When @value{GDBN} prints a value, it first sees if there is a pretty-printer
10417registered for the value. If there is then @value{GDBN} invokes the
10418pretty-printer to print the value. Otherwise the value is printed normally.
10419
10420Pretty-printers are normally named. This makes them easy to manage.
10421The @samp{info pretty-printer} command will list all the installed
10422pretty-printers with their names.
10423If a pretty-printer can handle multiple data types, then its
10424@dfn{subprinters} are the printers for the individual data types.
10425Each such subprinter has its own name.
4e04c971 10426The format of the name is @var{printer-name};@var{subprinter-name}.
7b51bc51
DE
10427
10428Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
10429Typically they are automatically loaded and registered when the corresponding
10430debug information is loaded, thus making them available without having to
10431do anything special.
10432
10433There are three places where a pretty-printer can be registered.
10434
10435@itemize @bullet
10436@item
10437Pretty-printers registered globally are available when debugging
10438all inferiors.
10439
10440@item
10441Pretty-printers registered with a program space are available only
10442when debugging that program.
10443@xref{Progspaces In Python}, for more details on program spaces in Python.
10444
10445@item
10446Pretty-printers registered with an objfile are loaded and unloaded
10447with the corresponding objfile (e.g., shared library).
10448@xref{Objfiles In Python}, for more details on objfiles in Python.
10449@end itemize
10450
10451@xref{Selecting Pretty-Printers}, for further information on how
10452pretty-printers are selected,
10453
10454@xref{Writing a Pretty-Printer}, for implementing pretty printers
10455for new types.
10456
10457@node Pretty-Printer Example
10458@subsection Pretty-Printer Example
10459
10460Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
4c374409
JK
10461
10462@smallexample
10463(@value{GDBP}) print s
10464$1 = @{
10465 static npos = 4294967295,
10466 _M_dataplus = @{
10467 <std::allocator<char>> = @{
10468 <__gnu_cxx::new_allocator<char>> = @{
10469 <No data fields>@}, <No data fields>
10470 @},
10471 members of std::basic_string<char, std::char_traits<char>,
10472 std::allocator<char> >::_Alloc_hider:
10473 _M_p = 0x804a014 "abcd"
10474 @}
10475@}
10476@end smallexample
10477
10478With a pretty-printer for @code{std::string} only the contents are printed:
10479
10480@smallexample
10481(@value{GDBP}) print s
10482$2 = "abcd"
10483@end smallexample
10484
7b51bc51
DE
10485@node Pretty-Printer Commands
10486@subsection Pretty-Printer Commands
10487@cindex pretty-printer commands
10488
10489@table @code
10490@kindex info pretty-printer
10491@item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
10492Print the list of installed pretty-printers.
10493This includes disabled pretty-printers, which are marked as such.
10494
10495@var{object-regexp} is a regular expression matching the objects
10496whose pretty-printers to list.
10497Objects can be @code{global}, the program space's file
10498(@pxref{Progspaces In Python}),
10499and the object files within that program space (@pxref{Objfiles In Python}).
10500@xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
10501looks up a printer from these three objects.
10502
10503@var{name-regexp} is a regular expression matching the name of the printers
10504to list.
10505
10506@kindex disable pretty-printer
10507@item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
10508Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
10509A disabled pretty-printer is not forgotten, it may be enabled again later.
10510
10511@kindex enable pretty-printer
10512@item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
10513Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
10514@end table
10515
10516Example:
10517
10518Suppose we have three pretty-printers installed: one from library1.so
10519named @code{foo} that prints objects of type @code{foo}, and
10520another from library2.so named @code{bar} that prints two types of objects,
10521@code{bar1} and @code{bar2}.
10522
10523@smallexample
10524(gdb) info pretty-printer
10525library1.so:
10526 foo
10527library2.so:
10528 bar
10529 bar1
10530 bar2
10531(gdb) info pretty-printer library2
10532library2.so:
10533 bar
10534 bar1
10535 bar2
10536(gdb) disable pretty-printer library1
105371 printer disabled
105382 of 3 printers enabled
10539(gdb) info pretty-printer
10540library1.so:
10541 foo [disabled]
10542library2.so:
10543 bar
10544 bar1
10545 bar2
10546(gdb) disable pretty-printer library2 bar:bar1
105471 printer disabled
105481 of 3 printers enabled
10549(gdb) info pretty-printer library2
10550library1.so:
10551 foo [disabled]
10552library2.so:
10553 bar
10554 bar1 [disabled]
10555 bar2
10556(gdb) disable pretty-printer library2 bar
105571 printer disabled
105580 of 3 printers enabled
10559(gdb) info pretty-printer library2
10560library1.so:
10561 foo [disabled]
10562library2.so:
10563 bar [disabled]
10564 bar1 [disabled]
10565 bar2
10566@end smallexample
10567
10568Note that for @code{bar} the entire printer can be disabled,
10569as can each individual subprinter.
4c374409 10570
6d2ebf8b 10571@node Value History
79a6e687 10572@section Value History
c906108c
SS
10573
10574@cindex value history
9c16f35a 10575@cindex history of values printed by @value{GDBN}
5d161b24
DB
10576Values printed by the @code{print} command are saved in the @value{GDBN}
10577@dfn{value history}. This allows you to refer to them in other expressions.
10578Values are kept until the symbol table is re-read or discarded
10579(for example with the @code{file} or @code{symbol-file} commands).
10580When the symbol table changes, the value history is discarded,
10581since the values may contain pointers back to the types defined in the
c906108c
SS
10582symbol table.
10583
10584@cindex @code{$}
10585@cindex @code{$$}
10586@cindex history number
10587The values printed are given @dfn{history numbers} by which you can
10588refer to them. These are successive integers starting with one.
10589@code{print} shows you the history number assigned to a value by
10590printing @samp{$@var{num} = } before the value; here @var{num} is the
10591history number.
10592
10593To refer to any previous value, use @samp{$} followed by the value's
10594history number. The way @code{print} labels its output is designed to
10595remind you of this. Just @code{$} refers to the most recent value in
10596the history, and @code{$$} refers to the value before that.
10597@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
10598is the value just prior to @code{$$}, @code{$$1} is equivalent to
10599@code{$$}, and @code{$$0} is equivalent to @code{$}.
10600
10601For example, suppose you have just printed a pointer to a structure and
10602want to see the contents of the structure. It suffices to type
10603
474c8240 10604@smallexample
c906108c 10605p *$
474c8240 10606@end smallexample
c906108c
SS
10607
10608If you have a chain of structures where the component @code{next} points
10609to the next one, you can print the contents of the next one with this:
10610
474c8240 10611@smallexample
c906108c 10612p *$.next
474c8240 10613@end smallexample
c906108c
SS
10614
10615@noindent
10616You can print successive links in the chain by repeating this
10617command---which you can do by just typing @key{RET}.
10618
10619Note that the history records values, not expressions. If the value of
10620@code{x} is 4 and you type these commands:
10621
474c8240 10622@smallexample
c906108c
SS
10623print x
10624set x=5
474c8240 10625@end smallexample
c906108c
SS
10626
10627@noindent
10628then the value recorded in the value history by the @code{print} command
10629remains 4 even though the value of @code{x} has changed.
10630
10631@table @code
10632@kindex show values
10633@item show values
10634Print the last ten values in the value history, with their item numbers.
10635This is like @samp{p@ $$9} repeated ten times, except that @code{show
10636values} does not change the history.
10637
10638@item show values @var{n}
10639Print ten history values centered on history item number @var{n}.
10640
10641@item show values +
10642Print ten history values just after the values last printed. If no more
10643values are available, @code{show values +} produces no display.
10644@end table
10645
10646Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
10647same effect as @samp{show values +}.
10648
6d2ebf8b 10649@node Convenience Vars
79a6e687 10650@section Convenience Variables
c906108c
SS
10651
10652@cindex convenience variables
9c16f35a 10653@cindex user-defined variables
c906108c
SS
10654@value{GDBN} provides @dfn{convenience variables} that you can use within
10655@value{GDBN} to hold on to a value and refer to it later. These variables
10656exist entirely within @value{GDBN}; they are not part of your program, and
10657setting a convenience variable has no direct effect on further execution
10658of your program. That is why you can use them freely.
10659
10660Convenience variables are prefixed with @samp{$}. Any name preceded by
10661@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 10662the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c 10663(Value history references, in contrast, are @emph{numbers} preceded
79a6e687 10664by @samp{$}. @xref{Value History, ,Value History}.)
c906108c
SS
10665
10666You can save a value in a convenience variable with an assignment
10667expression, just as you would set a variable in your program.
10668For example:
10669
474c8240 10670@smallexample
c906108c 10671set $foo = *object_ptr
474c8240 10672@end smallexample
c906108c
SS
10673
10674@noindent
10675would save in @code{$foo} the value contained in the object pointed to by
10676@code{object_ptr}.
10677
10678Using a convenience variable for the first time creates it, but its
10679value is @code{void} until you assign a new value. You can alter the
10680value with another assignment at any time.
10681
10682Convenience variables have no fixed types. You can assign a convenience
10683variable any type of value, including structures and arrays, even if
10684that variable already has a value of a different type. The convenience
10685variable, when used as an expression, has the type of its current value.
10686
10687@table @code
10688@kindex show convenience
f47f77df 10689@cindex show all user variables and functions
c906108c 10690@item show convenience
f47f77df
DE
10691Print a list of convenience variables used so far, and their values,
10692as well as a list of the convenience functions.
d4f3574e 10693Abbreviated @code{show conv}.
53e5f3cf
AS
10694
10695@kindex init-if-undefined
10696@cindex convenience variables, initializing
10697@item init-if-undefined $@var{variable} = @var{expression}
10698Set a convenience variable if it has not already been set. This is useful
10699for user-defined commands that keep some state. It is similar, in concept,
10700to using local static variables with initializers in C (except that
10701convenience variables are global). It can also be used to allow users to
10702override default values used in a command script.
10703
10704If the variable is already defined then the expression is not evaluated so
10705any side-effects do not occur.
c906108c
SS
10706@end table
10707
10708One of the ways to use a convenience variable is as a counter to be
10709incremented or a pointer to be advanced. For example, to print
10710a field from successive elements of an array of structures:
10711
474c8240 10712@smallexample
c906108c
SS
10713set $i = 0
10714print bar[$i++]->contents
474c8240 10715@end smallexample
c906108c 10716
d4f3574e
SS
10717@noindent
10718Repeat that command by typing @key{RET}.
c906108c
SS
10719
10720Some convenience variables are created automatically by @value{GDBN} and given
10721values likely to be useful.
10722
10723@table @code
41afff9a 10724@vindex $_@r{, convenience variable}
c906108c
SS
10725@item $_
10726The variable @code{$_} is automatically set by the @code{x} command to
79a6e687 10727the last address examined (@pxref{Memory, ,Examining Memory}). Other
c906108c
SS
10728commands which provide a default address for @code{x} to examine also
10729set @code{$_} to that address; these commands include @code{info line}
10730and @code{info breakpoint}. The type of @code{$_} is @code{void *}
10731except when set by the @code{x} command, in which case it is a pointer
10732to the type of @code{$__}.
10733
41afff9a 10734@vindex $__@r{, convenience variable}
c906108c
SS
10735@item $__
10736The variable @code{$__} is automatically set by the @code{x} command
10737to the value found in the last address examined. Its type is chosen
10738to match the format in which the data was printed.
10739
10740@item $_exitcode
41afff9a 10741@vindex $_exitcode@r{, convenience variable}
0c557179
SDJ
10742When the program being debugged terminates normally, @value{GDBN}
10743automatically sets this variable to the exit code of the program, and
10744resets @code{$_exitsignal} to @code{void}.
10745
10746@item $_exitsignal
10747@vindex $_exitsignal@r{, convenience variable}
10748When the program being debugged dies due to an uncaught signal,
10749@value{GDBN} automatically sets this variable to that signal's number,
10750and resets @code{$_exitcode} to @code{void}.
10751
10752To distinguish between whether the program being debugged has exited
10753(i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
10754@code{$_exitsignal} is not @code{void}), the convenience function
10755@code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
10756Functions}). For example, considering the following source code:
10757
10758@smallexample
10759#include <signal.h>
10760
10761int
10762main (int argc, char *argv[])
10763@{
10764 raise (SIGALRM);
10765 return 0;
10766@}
10767@end smallexample
10768
10769A valid way of telling whether the program being debugged has exited
10770or signalled would be:
10771
10772@smallexample
10773(@value{GDBP}) define has_exited_or_signalled
10774Type commands for definition of ``has_exited_or_signalled''.
10775End with a line saying just ``end''.
10776>if $_isvoid ($_exitsignal)
10777 >echo The program has exited\n
10778 >else
10779 >echo The program has signalled\n
10780 >end
10781>end
10782(@value{GDBP}) run
10783Starting program:
10784
10785Program terminated with signal SIGALRM, Alarm clock.
10786The program no longer exists.
10787(@value{GDBP}) has_exited_or_signalled
10788The program has signalled
10789@end smallexample
10790
10791As can be seen, @value{GDBN} correctly informs that the program being
10792debugged has signalled, since it calls @code{raise} and raises a
10793@code{SIGALRM} signal. If the program being debugged had not called
10794@code{raise}, then @value{GDBN} would report a normal exit:
10795
10796@smallexample
10797(@value{GDBP}) has_exited_or_signalled
10798The program has exited
10799@end smallexample
4aa995e1 10800
72f1fe8a
TT
10801@item $_exception
10802The variable @code{$_exception} is set to the exception object being
10803thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
10804
62e5f89c
SDJ
10805@item $_probe_argc
10806@itemx $_probe_arg0@dots{}$_probe_arg11
10807Arguments to a static probe. @xref{Static Probe Points}.
10808
0fb4aa4b
PA
10809@item $_sdata
10810@vindex $_sdata@r{, inspect, convenience variable}
10811The variable @code{$_sdata} contains extra collected static tracepoint
10812data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
10813@code{$_sdata} could be empty, if not inspecting a trace buffer, or
10814if extra static tracepoint data has not been collected.
10815
4aa995e1
PA
10816@item $_siginfo
10817@vindex $_siginfo@r{, convenience variable}
ec7e75e7
PP
10818The variable @code{$_siginfo} contains extra signal information
10819(@pxref{extra signal information}). Note that @code{$_siginfo}
10820could be empty, if the application has not yet received any signals.
10821For example, it will be empty before you execute the @code{run} command.
711e434b
PM
10822
10823@item $_tlb
10824@vindex $_tlb@r{, convenience variable}
10825The variable @code{$_tlb} is automatically set when debugging
10826applications running on MS-Windows in native mode or connected to
10827gdbserver that supports the @code{qGetTIBAddr} request.
10828@xref{General Query Packets}.
10829This variable contains the address of the thread information block.
10830
e3940304
PA
10831@item $_inferior
10832The number of the current inferior. @xref{Inferiors and
10833Programs, ,Debugging Multiple Inferiors and Programs}.
10834
5d5658a1
PA
10835@item $_thread
10836The thread number of the current thread. @xref{thread numbers}.
10837
663f6d42
PA
10838@item $_gthread
10839The global number of the current thread. @xref{global thread numbers}.
10840
c906108c
SS
10841@end table
10842
a72c3253
DE
10843@node Convenience Funs
10844@section Convenience Functions
10845
bc3b79fd
TJB
10846@cindex convenience functions
10847@value{GDBN} also supplies some @dfn{convenience functions}. These
10848have a syntax similar to convenience variables. A convenience
10849function can be used in an expression just like an ordinary function;
10850however, a convenience function is implemented internally to
10851@value{GDBN}.
10852
a280dbd1
SDJ
10853These functions do not require @value{GDBN} to be configured with
10854@code{Python} support, which means that they are always available.
10855
10856@table @code
10857
10858@item $_isvoid (@var{expr})
10859@findex $_isvoid@r{, convenience function}
10860Return one if the expression @var{expr} is @code{void}. Otherwise it
10861returns zero.
10862
10863A @code{void} expression is an expression where the type of the result
10864is @code{void}. For example, you can examine a convenience variable
10865(see @ref{Convenience Vars,, Convenience Variables}) to check whether
10866it is @code{void}:
10867
10868@smallexample
10869(@value{GDBP}) print $_exitcode
10870$1 = void
10871(@value{GDBP}) print $_isvoid ($_exitcode)
10872$2 = 1
10873(@value{GDBP}) run
10874Starting program: ./a.out
10875[Inferior 1 (process 29572) exited normally]
10876(@value{GDBP}) print $_exitcode
10877$3 = 0
10878(@value{GDBP}) print $_isvoid ($_exitcode)
10879$4 = 0
10880@end smallexample
10881
10882In the example above, we used @code{$_isvoid} to check whether
10883@code{$_exitcode} is @code{void} before and after the execution of the
10884program being debugged. Before the execution there is no exit code to
10885be examined, therefore @code{$_exitcode} is @code{void}. After the
10886execution the program being debugged returned zero, therefore
10887@code{$_exitcode} is zero, which means that it is not @code{void}
10888anymore.
10889
10890The @code{void} expression can also be a call of a function from the
10891program being debugged. For example, given the following function:
10892
10893@smallexample
10894void
10895foo (void)
10896@{
10897@}
10898@end smallexample
10899
10900The result of calling it inside @value{GDBN} is @code{void}:
10901
10902@smallexample
10903(@value{GDBP}) print foo ()
10904$1 = void
10905(@value{GDBP}) print $_isvoid (foo ())
10906$2 = 1
10907(@value{GDBP}) set $v = foo ()
10908(@value{GDBP}) print $v
10909$3 = void
10910(@value{GDBP}) print $_isvoid ($v)
10911$4 = 1
10912@end smallexample
10913
10914@end table
10915
a72c3253
DE
10916These functions require @value{GDBN} to be configured with
10917@code{Python} support.
10918
10919@table @code
10920
10921@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
10922@findex $_memeq@r{, convenience function}
10923Returns one if the @var{length} bytes at the addresses given by
10924@var{buf1} and @var{buf2} are equal.
10925Otherwise it returns zero.
10926
10927@item $_regex(@var{str}, @var{regex})
10928@findex $_regex@r{, convenience function}
10929Returns one if the string @var{str} matches the regular expression
10930@var{regex}. Otherwise it returns zero.
10931The syntax of the regular expression is that specified by @code{Python}'s
10932regular expression support.
10933
10934@item $_streq(@var{str1}, @var{str2})
10935@findex $_streq@r{, convenience function}
10936Returns one if the strings @var{str1} and @var{str2} are equal.
10937Otherwise it returns zero.
10938
10939@item $_strlen(@var{str})
10940@findex $_strlen@r{, convenience function}
10941Returns the length of string @var{str}.
10942
faa42425
DE
10943@item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
10944@findex $_caller_is@r{, convenience function}
10945Returns one if the calling function's name is equal to @var{name}.
10946Otherwise it returns zero.
10947
10948If the optional argument @var{number_of_frames} is provided,
10949it is the number of frames up in the stack to look.
10950The default is 1.
10951
10952Example:
10953
10954@smallexample
10955(gdb) backtrace
10956#0 bottom_func ()
10957 at testsuite/gdb.python/py-caller-is.c:21
10958#1 0x00000000004005a0 in middle_func ()
10959 at testsuite/gdb.python/py-caller-is.c:27
10960#2 0x00000000004005ab in top_func ()
10961 at testsuite/gdb.python/py-caller-is.c:33
10962#3 0x00000000004005b6 in main ()
10963 at testsuite/gdb.python/py-caller-is.c:39
10964(gdb) print $_caller_is ("middle_func")
10965$1 = 1
10966(gdb) print $_caller_is ("top_func", 2)
10967$1 = 1
10968@end smallexample
10969
10970@item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
10971@findex $_caller_matches@r{, convenience function}
10972Returns one if the calling function's name matches the regular expression
10973@var{regexp}. Otherwise it returns zero.
10974
10975If the optional argument @var{number_of_frames} is provided,
10976it is the number of frames up in the stack to look.
10977The default is 1.
10978
10979@item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
10980@findex $_any_caller_is@r{, convenience function}
10981Returns one if any calling function's name is equal to @var{name}.
10982Otherwise it returns zero.
10983
10984If the optional argument @var{number_of_frames} is provided,
10985it is the number of frames up in the stack to look.
10986The default is 1.
10987
10988This function differs from @code{$_caller_is} in that this function
10989checks all stack frames from the immediate caller to the frame specified
10990by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
10991frame specified by @var{number_of_frames}.
10992
10993@item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
10994@findex $_any_caller_matches@r{, convenience function}
10995Returns one if any calling function's name matches the regular expression
10996@var{regexp}. Otherwise it returns zero.
10997
10998If the optional argument @var{number_of_frames} is provided,
10999it is the number of frames up in the stack to look.
11000The default is 1.
11001
11002This function differs from @code{$_caller_matches} in that this function
11003checks all stack frames from the immediate caller to the frame specified
11004by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
11005frame specified by @var{number_of_frames}.
11006
f2f3ccb9
SM
11007@item $_as_string(@var{value})
11008@findex $_as_string@r{, convenience function}
11009Return the string representation of @var{value}.
11010
11011This function is useful to obtain the textual label (enumerator) of an
11012enumeration value. For example, assuming the variable @var{node} is of
11013an enumerated type:
11014
11015@smallexample
11016(gdb) printf "Visiting node of type %s\n", $_as_string(node)
11017Visiting node of type NODE_INTEGER
11018@end smallexample
11019
a72c3253
DE
11020@end table
11021
11022@value{GDBN} provides the ability to list and get help on
11023convenience functions.
11024
bc3b79fd
TJB
11025@table @code
11026@item help function
11027@kindex help function
11028@cindex show all convenience functions
11029Print a list of all convenience functions.
11030@end table
11031
6d2ebf8b 11032@node Registers
c906108c
SS
11033@section Registers
11034
11035@cindex registers
11036You can refer to machine register contents, in expressions, as variables
11037with names starting with @samp{$}. The names of registers are different
11038for each machine; use @code{info registers} to see the names used on
11039your machine.
11040
11041@table @code
11042@kindex info registers
11043@item info registers
11044Print the names and values of all registers except floating-point
c85508ee 11045and vector registers (in the selected stack frame).
c906108c
SS
11046
11047@kindex info all-registers
11048@cindex floating point registers
11049@item info all-registers
11050Print the names and values of all registers, including floating-point
c85508ee 11051and vector registers (in the selected stack frame).
c906108c 11052
b67d92b0
SH
11053@item info registers @var{reggroup} @dots{}
11054Print the name and value of the registers in each of the specified
11055@var{reggroup}s. The @var{reggoup} can be any of those returned by
11056@code{maint print reggroups} (@pxref{Maintenance Commands}).
11057
c906108c
SS
11058@item info registers @var{regname} @dots{}
11059Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24 11060As discussed in detail below, register values are normally relative to
697aa1b7 11061the selected stack frame. The @var{regname} may be any register name valid on
c906108c
SS
11062the machine you are using, with or without the initial @samp{$}.
11063@end table
11064
f5b95c01 11065@anchor{standard registers}
e09f16f9
EZ
11066@cindex stack pointer register
11067@cindex program counter register
11068@cindex process status register
11069@cindex frame pointer register
11070@cindex standard registers
c906108c
SS
11071@value{GDBN} has four ``standard'' register names that are available (in
11072expressions) on most machines---whenever they do not conflict with an
11073architecture's canonical mnemonics for registers. The register names
11074@code{$pc} and @code{$sp} are used for the program counter register and
11075the stack pointer. @code{$fp} is used for a register that contains a
11076pointer to the current stack frame, and @code{$ps} is used for a
11077register that contains the processor status. For example,
11078you could print the program counter in hex with
11079
474c8240 11080@smallexample
c906108c 11081p/x $pc
474c8240 11082@end smallexample
c906108c
SS
11083
11084@noindent
11085or print the instruction to be executed next with
11086
474c8240 11087@smallexample
c906108c 11088x/i $pc
474c8240 11089@end smallexample
c906108c
SS
11090
11091@noindent
11092or add four to the stack pointer@footnote{This is a way of removing
11093one word from the stack, on machines where stacks grow downward in
11094memory (most machines, nowadays). This assumes that the innermost
11095stack frame is selected; setting @code{$sp} is not allowed when other
11096stack frames are selected. To pop entire frames off the stack,
11097regardless of machine architecture, use @code{return};
79a6e687 11098see @ref{Returning, ,Returning from a Function}.} with
c906108c 11099
474c8240 11100@smallexample
c906108c 11101set $sp += 4
474c8240 11102@end smallexample
c906108c
SS
11103
11104Whenever possible, these four standard register names are available on
11105your machine even though the machine has different canonical mnemonics,
11106so long as there is no conflict. The @code{info registers} command
11107shows the canonical names. For example, on the SPARC, @code{info
11108registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
11109can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
11110is an alias for the @sc{eflags} register.
c906108c
SS
11111
11112@value{GDBN} always considers the contents of an ordinary register as an
11113integer when the register is examined in this way. Some machines have
11114special registers which can hold nothing but floating point; these
11115registers are considered to have floating point values. There is no way
11116to refer to the contents of an ordinary register as floating point value
11117(although you can @emph{print} it as a floating point value with
11118@samp{print/f $@var{regname}}).
11119
11120Some registers have distinct ``raw'' and ``virtual'' data formats. This
11121means that the data format in which the register contents are saved by
11122the operating system is not the same one that your program normally
11123sees. For example, the registers of the 68881 floating point
11124coprocessor are always saved in ``extended'' (raw) format, but all C
11125programs expect to work with ``double'' (virtual) format. In such
5d161b24 11126cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
11127that makes sense for your program), but the @code{info registers} command
11128prints the data in both formats.
11129
36b80e65
EZ
11130@cindex SSE registers (x86)
11131@cindex MMX registers (x86)
11132Some machines have special registers whose contents can be interpreted
11133in several different ways. For example, modern x86-based machines
11134have SSE and MMX registers that can hold several values packed
11135together in several different formats. @value{GDBN} refers to such
11136registers in @code{struct} notation:
11137
11138@smallexample
11139(@value{GDBP}) print $xmm1
11140$1 = @{
11141 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
11142 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
11143 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
11144 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
11145 v4_int32 = @{0, 20657912, 11, 13@},
11146 v2_int64 = @{88725056443645952, 55834574859@},
11147 uint128 = 0x0000000d0000000b013b36f800000000
11148@}
11149@end smallexample
11150
11151@noindent
11152To set values of such registers, you need to tell @value{GDBN} which
11153view of the register you wish to change, as if you were assigning
11154value to a @code{struct} member:
11155
11156@smallexample
11157 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
11158@end smallexample
11159
c906108c 11160Normally, register values are relative to the selected stack frame
79a6e687 11161(@pxref{Selection, ,Selecting a Frame}). This means that you get the
c906108c
SS
11162value that the register would contain if all stack frames farther in
11163were exited and their saved registers restored. In order to see the
11164true contents of hardware registers, you must select the innermost
11165frame (with @samp{frame 0}).
11166
901461f8
PA
11167@cindex caller-saved registers
11168@cindex call-clobbered registers
11169@cindex volatile registers
11170@cindex <not saved> values
11171Usually ABIs reserve some registers as not needed to be saved by the
11172callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
11173registers). It may therefore not be possible for @value{GDBN} to know
11174the value a register had before the call (in other words, in the outer
11175frame), if the register value has since been changed by the callee.
11176@value{GDBN} tries to deduce where the inner frame saved
11177(``callee-saved'') registers, from the debug info, unwind info, or the
11178machine code generated by your compiler. If some register is not
11179saved, and @value{GDBN} knows the register is ``caller-saved'' (via
11180its own knowledge of the ABI, or because the debug/unwind info
11181explicitly says the register's value is undefined), @value{GDBN}
11182displays @w{@samp{<not saved>}} as the register's value. With targets
11183that @value{GDBN} has no knowledge of the register saving convention,
11184if a register was not saved by the callee, then its value and location
11185in the outer frame are assumed to be the same of the inner frame.
11186This is usually harmless, because if the register is call-clobbered,
11187the caller either does not care what is in the register after the
11188call, or has code to restore the value that it does care about. Note,
11189however, that if you change such a register in the outer frame, you
11190may also be affecting the inner frame. Also, the more ``outer'' the
11191frame is you're looking at, the more likely a call-clobbered
11192register's value is to be wrong, in the sense that it doesn't actually
11193represent the value the register had just before the call.
c906108c 11194
6d2ebf8b 11195@node Floating Point Hardware
79a6e687 11196@section Floating Point Hardware
c906108c
SS
11197@cindex floating point
11198
11199Depending on the configuration, @value{GDBN} may be able to give
11200you more information about the status of the floating point hardware.
11201
11202@table @code
11203@kindex info float
11204@item info float
11205Display hardware-dependent information about the floating
11206point unit. The exact contents and layout vary depending on the
11207floating point chip. Currently, @samp{info float} is supported on
11208the ARM and x86 machines.
11209@end table
c906108c 11210
e76f1f2e
AC
11211@node Vector Unit
11212@section Vector Unit
11213@cindex vector unit
11214
11215Depending on the configuration, @value{GDBN} may be able to give you
11216more information about the status of the vector unit.
11217
11218@table @code
11219@kindex info vector
11220@item info vector
11221Display information about the vector unit. The exact contents and
11222layout vary depending on the hardware.
11223@end table
11224
721c2651 11225@node OS Information
79a6e687 11226@section Operating System Auxiliary Information
721c2651
EZ
11227@cindex OS information
11228
11229@value{GDBN} provides interfaces to useful OS facilities that can help
11230you debug your program.
11231
b383017d
RM
11232@cindex auxiliary vector
11233@cindex vector, auxiliary
b383017d
RM
11234Some operating systems supply an @dfn{auxiliary vector} to programs at
11235startup. This is akin to the arguments and environment that you
11236specify for a program, but contains a system-dependent variety of
11237binary values that tell system libraries important details about the
11238hardware, operating system, and process. Each value's purpose is
11239identified by an integer tag; the meanings are well-known but system-specific.
11240Depending on the configuration and operating system facilities,
9c16f35a
EZ
11241@value{GDBN} may be able to show you this information. For remote
11242targets, this functionality may further depend on the remote stub's
427c3a89
DJ
11243support of the @samp{qXfer:auxv:read} packet, see
11244@ref{qXfer auxiliary vector read}.
b383017d
RM
11245
11246@table @code
11247@kindex info auxv
11248@item info auxv
11249Display the auxiliary vector of the inferior, which can be either a
e4937fc1 11250live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
11251numerically, and also shows names and text descriptions for recognized
11252tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 11253pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
11254most appropriate form for a recognized tag, and in hexadecimal for
11255an unrecognized tag.
11256@end table
11257
85d4a676
SS
11258On some targets, @value{GDBN} can access operating system-specific
11259information and show it to you. The types of information available
11260will differ depending on the type of operating system running on the
11261target. The mechanism used to fetch the data is described in
11262@ref{Operating System Information}. For remote targets, this
11263functionality depends on the remote stub's support of the
07e059b5
VP
11264@samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
11265
11266@table @code
a61408f8 11267@kindex info os
85d4a676
SS
11268@item info os @var{infotype}
11269
11270Display OS information of the requested type.
a61408f8 11271
85d4a676
SS
11272On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
11273
11274@anchor{linux info os infotypes}
11275@table @code
d33279b3
AT
11276@kindex info os cpus
11277@item cpus
11278Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
11279the available fields from /proc/cpuinfo. For each supported architecture
11280different fields are available. Two common entries are processor which gives
11281CPU number and bogomips; a system constant that is calculated during
11282kernel initialization.
11283
11284@kindex info os files
11285@item files
11286Display the list of open file descriptors on the target. For each
11287file descriptor, @value{GDBN} prints the identifier of the process
11288owning the descriptor, the command of the owning process, the value
11289of the descriptor, and the target of the descriptor.
11290
11291@kindex info os modules
11292@item modules
11293Display the list of all loaded kernel modules on the target. For each
11294module, @value{GDBN} prints the module name, the size of the module in
11295bytes, the number of times the module is used, the dependencies of the
11296module, the status of the module, and the address of the loaded module
11297in memory.
11298
11299@kindex info os msg
11300@item msg
11301Display the list of all System V message queues on the target. For each
11302message queue, @value{GDBN} prints the message queue key, the message
11303queue identifier, the access permissions, the current number of bytes
11304on the queue, the current number of messages on the queue, the processes
11305that last sent and received a message on the queue, the user and group
11306of the owner and creator of the message queue, the times at which a
11307message was last sent and received on the queue, and the time at which
11308the message queue was last changed.
11309
07e059b5 11310@kindex info os processes
85d4a676 11311@item processes
07e059b5 11312Display the list of processes on the target. For each process,
85d4a676
SS
11313@value{GDBN} prints the process identifier, the name of the user, the
11314command corresponding to the process, and the list of processor cores
11315that the process is currently running on. (To understand what these
11316properties mean, for this and the following info types, please consult
11317the general @sc{gnu}/Linux documentation.)
11318
11319@kindex info os procgroups
11320@item procgroups
11321Display the list of process groups on the target. For each process,
11322@value{GDBN} prints the identifier of the process group that it belongs
11323to, the command corresponding to the process group leader, the process
11324identifier, and the command line of the process. The list is sorted
11325first by the process group identifier, then by the process identifier,
11326so that processes belonging to the same process group are grouped together
11327and the process group leader is listed first.
11328
d33279b3
AT
11329@kindex info os semaphores
11330@item semaphores
11331Display the list of all System V semaphore sets on the target. For each
11332semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
11333set identifier, the access permissions, the number of semaphores in the
11334set, the user and group of the owner and creator of the semaphore set,
11335and the times at which the semaphore set was operated upon and changed.
85d4a676
SS
11336
11337@kindex info os shm
11338@item shm
11339Display the list of all System V shared-memory regions on the target.
11340For each shared-memory region, @value{GDBN} prints the region key,
11341the shared-memory identifier, the access permissions, the size of the
11342region, the process that created the region, the process that last
11343attached to or detached from the region, the current number of live
11344attaches to the region, and the times at which the region was last
11345attached to, detach from, and changed.
11346
d33279b3
AT
11347@kindex info os sockets
11348@item sockets
11349Display the list of Internet-domain sockets on the target. For each
11350socket, @value{GDBN} prints the address and port of the local and
11351remote endpoints, the current state of the connection, the creator of
11352the socket, the IP address family of the socket, and the type of the
11353connection.
85d4a676 11354
d33279b3
AT
11355@kindex info os threads
11356@item threads
11357Display the list of threads running on the target. For each thread,
11358@value{GDBN} prints the identifier of the process that the thread
11359belongs to, the command of the process, the thread identifier, and the
11360processor core that it is currently running on. The main thread of a
11361process is not listed.
85d4a676
SS
11362@end table
11363
11364@item info os
11365If @var{infotype} is omitted, then list the possible values for
11366@var{infotype} and the kind of OS information available for each
11367@var{infotype}. If the target does not return a list of possible
11368types, this command will report an error.
07e059b5 11369@end table
721c2651 11370
29e57380 11371@node Memory Region Attributes
79a6e687 11372@section Memory Region Attributes
29e57380
C
11373@cindex memory region attributes
11374
b383017d 11375@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
11376required by regions of your target's memory. @value{GDBN} uses
11377attributes to determine whether to allow certain types of memory
11378accesses; whether to use specific width accesses; and whether to cache
11379target memory. By default the description of memory regions is
11380fetched from the target (if the current target supports this), but the
11381user can override the fetched regions.
29e57380
C
11382
11383Defined memory regions can be individually enabled and disabled. When a
11384memory region is disabled, @value{GDBN} uses the default attributes when
11385accessing memory in that region. Similarly, if no memory regions have
11386been defined, @value{GDBN} uses the default attributes when accessing
11387all memory.
11388
b383017d 11389When a memory region is defined, it is given a number to identify it;
29e57380
C
11390to enable, disable, or remove a memory region, you specify that number.
11391
11392@table @code
11393@kindex mem
bfac230e 11394@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
11395Define a memory region bounded by @var{lower} and @var{upper} with
11396attributes @var{attributes}@dots{}, and add it to the list of regions
11397monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
d3e8051b 11398case: it is treated as the target's maximum memory address.
bfac230e 11399(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 11400
fd79ecee
DJ
11401@item mem auto
11402Discard any user changes to the memory regions and use target-supplied
11403regions, if available, or no regions if the target does not support.
11404
29e57380
C
11405@kindex delete mem
11406@item delete mem @var{nums}@dots{}
09d4efe1
EZ
11407Remove memory regions @var{nums}@dots{} from the list of regions
11408monitored by @value{GDBN}.
29e57380
C
11409
11410@kindex disable mem
11411@item disable mem @var{nums}@dots{}
09d4efe1 11412Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 11413A disabled memory region is not forgotten.
29e57380
C
11414It may be enabled again later.
11415
11416@kindex enable mem
11417@item enable mem @var{nums}@dots{}
09d4efe1 11418Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
11419
11420@kindex info mem
11421@item info mem
11422Print a table of all defined memory regions, with the following columns
09d4efe1 11423for each region:
29e57380
C
11424
11425@table @emph
11426@item Memory Region Number
11427@item Enabled or Disabled.
b383017d 11428Enabled memory regions are marked with @samp{y}.
29e57380
C
11429Disabled memory regions are marked with @samp{n}.
11430
11431@item Lo Address
11432The address defining the inclusive lower bound of the memory region.
11433
11434@item Hi Address
11435The address defining the exclusive upper bound of the memory region.
11436
11437@item Attributes
11438The list of attributes set for this memory region.
11439@end table
11440@end table
11441
11442
11443@subsection Attributes
11444
b383017d 11445@subsubsection Memory Access Mode
29e57380
C
11446The access mode attributes set whether @value{GDBN} may make read or
11447write accesses to a memory region.
11448
11449While these attributes prevent @value{GDBN} from performing invalid
11450memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 11451etc.@: from accessing memory.
29e57380
C
11452
11453@table @code
11454@item ro
11455Memory is read only.
11456@item wo
11457Memory is write only.
11458@item rw
6ca652b0 11459Memory is read/write. This is the default.
29e57380
C
11460@end table
11461
11462@subsubsection Memory Access Size
d3e8051b 11463The access size attribute tells @value{GDBN} to use specific sized
29e57380
C
11464accesses in the memory region. Often memory mapped device registers
11465require specific sized accesses. If no access size attribute is
11466specified, @value{GDBN} may use accesses of any size.
11467
11468@table @code
11469@item 8
11470Use 8 bit memory accesses.
11471@item 16
11472Use 16 bit memory accesses.
11473@item 32
11474Use 32 bit memory accesses.
11475@item 64
11476Use 64 bit memory accesses.
11477@end table
11478
11479@c @subsubsection Hardware/Software Breakpoints
11480@c The hardware/software breakpoint attributes set whether @value{GDBN}
11481@c will use hardware or software breakpoints for the internal breakpoints
11482@c used by the step, next, finish, until, etc. commands.
11483@c
11484@c @table @code
11485@c @item hwbreak
b383017d 11486@c Always use hardware breakpoints
29e57380
C
11487@c @item swbreak (default)
11488@c @end table
11489
11490@subsubsection Data Cache
11491The data cache attributes set whether @value{GDBN} will cache target
11492memory. While this generally improves performance by reducing debug
11493protocol overhead, it can lead to incorrect results because @value{GDBN}
11494does not know about volatile variables or memory mapped device
11495registers.
11496
11497@table @code
11498@item cache
b383017d 11499Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
11500@item nocache
11501Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
11502@end table
11503
4b5752d0
VP
11504@subsection Memory Access Checking
11505@value{GDBN} can be instructed to refuse accesses to memory that is
11506not explicitly described. This can be useful if accessing such
11507regions has undesired effects for a specific target, or to provide
11508better error checking. The following commands control this behaviour.
11509
11510@table @code
11511@kindex set mem inaccessible-by-default
11512@item set mem inaccessible-by-default [on|off]
11513If @code{on} is specified, make @value{GDBN} treat memory not
11514explicitly described by the memory ranges as non-existent and refuse accesses
11515to such memory. The checks are only performed if there's at least one
11516memory range defined. If @code{off} is specified, make @value{GDBN}
11517treat the memory not explicitly described by the memory ranges as RAM.
56cf5405 11518The default value is @code{on}.
4b5752d0
VP
11519@kindex show mem inaccessible-by-default
11520@item show mem inaccessible-by-default
11521Show the current handling of accesses to unknown memory.
11522@end table
11523
11524
29e57380 11525@c @subsubsection Memory Write Verification
b383017d 11526@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
11527@c will re-reads data after each write to verify the write was successful.
11528@c
11529@c @table @code
11530@c @item verify
11531@c @item noverify (default)
11532@c @end table
11533
16d9dec6 11534@node Dump/Restore Files
79a6e687 11535@section Copy Between Memory and a File
16d9dec6
MS
11536@cindex dump/restore files
11537@cindex append data to a file
11538@cindex dump data to a file
11539@cindex restore data from a file
16d9dec6 11540
df5215a6
JB
11541You can use the commands @code{dump}, @code{append}, and
11542@code{restore} to copy data between target memory and a file. The
11543@code{dump} and @code{append} commands write data to a file, and the
11544@code{restore} command reads data from a file back into the inferior's
cf75d6c3
AB
11545memory. Files may be in binary, Motorola S-record, Intel hex,
11546Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
11547append to binary files, and cannot read from Verilog Hex files.
df5215a6
JB
11548
11549@table @code
11550
11551@kindex dump
11552@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
11553@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
11554Dump the contents of memory from @var{start_addr} to @var{end_addr},
11555or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 11556
df5215a6 11557The @var{format} parameter may be any one of:
16d9dec6 11558@table @code
df5215a6
JB
11559@item binary
11560Raw binary form.
11561@item ihex
11562Intel hex format.
11563@item srec
11564Motorola S-record format.
11565@item tekhex
11566Tektronix Hex format.
cf75d6c3
AB
11567@item verilog
11568Verilog Hex format.
df5215a6
JB
11569@end table
11570
11571@value{GDBN} uses the same definitions of these formats as the
11572@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
11573@var{format} is omitted, @value{GDBN} dumps the data in raw binary
11574form.
11575
11576@kindex append
11577@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
11578@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
11579Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 11580or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
11581(@value{GDBN} can only append data to files in raw binary form.)
11582
11583@kindex restore
11584@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
11585Restore the contents of file @var{filename} into memory. The
11586@code{restore} command can automatically recognize any known @sc{bfd}
11587file format, except for raw binary. To restore a raw binary file you
11588must specify the optional keyword @code{binary} after the filename.
16d9dec6 11589
b383017d 11590If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
11591contained in the file. Binary files always start at address zero, so
11592they will be restored at address @var{bias}. Other bfd files have
11593a built-in location; they will be restored at offset @var{bias}
11594from that location.
11595
11596If @var{start} and/or @var{end} are non-zero, then only data between
11597file offset @var{start} and file offset @var{end} will be restored.
b383017d 11598These offsets are relative to the addresses in the file, before
16d9dec6
MS
11599the @var{bias} argument is applied.
11600
11601@end table
11602
384ee23f
EZ
11603@node Core File Generation
11604@section How to Produce a Core File from Your Program
11605@cindex dump core from inferior
11606
11607A @dfn{core file} or @dfn{core dump} is a file that records the memory
11608image of a running process and its process status (register values
11609etc.). Its primary use is post-mortem debugging of a program that
11610crashed while it ran outside a debugger. A program that crashes
11611automatically produces a core file, unless this feature is disabled by
11612the user. @xref{Files}, for information on invoking @value{GDBN} in
11613the post-mortem debugging mode.
11614
11615Occasionally, you may wish to produce a core file of the program you
11616are debugging in order to preserve a snapshot of its state.
11617@value{GDBN} has a special command for that.
11618
11619@table @code
11620@kindex gcore
11621@kindex generate-core-file
11622@item generate-core-file [@var{file}]
11623@itemx gcore [@var{file}]
11624Produce a core dump of the inferior process. The optional argument
11625@var{file} specifies the file name where to put the core dump. If not
11626specified, the file name defaults to @file{core.@var{pid}}, where
11627@var{pid} is the inferior process ID.
11628
11629Note that this command is implemented only for some systems (as of
05b4bd79 11630this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
df8411da
SDJ
11631
11632On @sc{gnu}/Linux, this command can take into account the value of the
11633file @file{/proc/@var{pid}/coredump_filter} when generating the core
1e52e849
SL
11634dump (@pxref{set use-coredump-filter}), and by default honors the
11635@code{VM_DONTDUMP} flag for mappings where it is present in the file
11636@file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
df8411da
SDJ
11637
11638@kindex set use-coredump-filter
11639@anchor{set use-coredump-filter}
11640@item set use-coredump-filter on
11641@itemx set use-coredump-filter off
11642Enable or disable the use of the file
11643@file{/proc/@var{pid}/coredump_filter} when generating core dump
11644files. This file is used by the Linux kernel to decide what types of
11645memory mappings will be dumped or ignored when generating a core dump
11646file. @var{pid} is the process ID of a currently running process.
11647
11648To make use of this feature, you have to write in the
11649@file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
11650which is a bit mask representing the memory mapping types. If a bit
11651is set in the bit mask, then the memory mappings of the corresponding
11652types will be dumped; otherwise, they will be ignored. This
11653configuration is inherited by child processes. For more information
11654about the bits that can be set in the
11655@file{/proc/@var{pid}/coredump_filter} file, please refer to the
11656manpage of @code{core(5)}.
11657
11658By default, this option is @code{on}. If this option is turned
11659@code{off}, @value{GDBN} does not read the @file{coredump_filter} file
11660and instead uses the same default value as the Linux kernel in order
11661to decide which pages will be dumped in the core dump file. This
11662value is currently @code{0x33}, which means that bits @code{0}
11663(anonymous private mappings), @code{1} (anonymous shared mappings),
11664@code{4} (ELF headers) and @code{5} (private huge pages) are active.
11665This will cause these memory mappings to be dumped automatically.
1e52e849
SL
11666
11667@kindex set dump-excluded-mappings
11668@anchor{set dump-excluded-mappings}
11669@item set dump-excluded-mappings on
11670@itemx set dump-excluded-mappings off
11671If @code{on} is specified, @value{GDBN} will dump memory mappings
11672marked with the @code{VM_DONTDUMP} flag. This flag is represented in
11673the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
11674
11675The default value is @code{off}.
384ee23f
EZ
11676@end table
11677
a0eb71c5
KB
11678@node Character Sets
11679@section Character Sets
11680@cindex character sets
11681@cindex charset
11682@cindex translating between character sets
11683@cindex host character set
11684@cindex target character set
11685
11686If the program you are debugging uses a different character set to
11687represent characters and strings than the one @value{GDBN} uses itself,
11688@value{GDBN} can automatically translate between the character sets for
11689you. The character set @value{GDBN} uses we call the @dfn{host
11690character set}; the one the inferior program uses we call the
11691@dfn{target character set}.
11692
11693For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
11694uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
ea35711c 11695remote protocol (@pxref{Remote Debugging}) to debug a program
a0eb71c5
KB
11696running on an IBM mainframe, which uses the @sc{ebcdic} character set,
11697then the host character set is Latin-1, and the target character set is
11698@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 11699target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
11700@sc{ebcdic} and Latin 1 as you print character or string values, or use
11701character and string literals in expressions.
11702
11703@value{GDBN} has no way to automatically recognize which character set
11704the inferior program uses; you must tell it, using the @code{set
11705target-charset} command, described below.
11706
11707Here are the commands for controlling @value{GDBN}'s character set
11708support:
11709
11710@table @code
11711@item set target-charset @var{charset}
11712@kindex set target-charset
10af6951
EZ
11713Set the current target character set to @var{charset}. To display the
11714list of supported target character sets, type
11715@kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
a0eb71c5 11716
a0eb71c5
KB
11717@item set host-charset @var{charset}
11718@kindex set host-charset
11719Set the current host character set to @var{charset}.
11720
11721By default, @value{GDBN} uses a host character set appropriate to the
11722system it is running on; you can override that default using the
732f6a93
TT
11723@code{set host-charset} command. On some systems, @value{GDBN} cannot
11724automatically determine the appropriate host character set. In this
11725case, @value{GDBN} uses @samp{UTF-8}.
a0eb71c5
KB
11726
11727@value{GDBN} can only use certain character sets as its host character
c1b6b909 11728set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
10af6951 11729@value{GDBN} will list the host character sets it supports.
a0eb71c5
KB
11730
11731@item set charset @var{charset}
11732@kindex set charset
e33d66ec 11733Set the current host and target character sets to @var{charset}. As
10af6951
EZ
11734above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
11735@value{GDBN} will list the names of the character sets that can be used
e33d66ec
EZ
11736for both host and target.
11737
a0eb71c5 11738@item show charset
a0eb71c5 11739@kindex show charset
10af6951 11740Show the names of the current host and target character sets.
e33d66ec 11741
10af6951 11742@item show host-charset
a0eb71c5 11743@kindex show host-charset
10af6951 11744Show the name of the current host character set.
e33d66ec 11745
10af6951 11746@item show target-charset
a0eb71c5 11747@kindex show target-charset
10af6951 11748Show the name of the current target character set.
a0eb71c5 11749
10af6951
EZ
11750@item set target-wide-charset @var{charset}
11751@kindex set target-wide-charset
11752Set the current target's wide character set to @var{charset}. This is
11753the character set used by the target's @code{wchar_t} type. To
11754display the list of supported wide character sets, type
11755@kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
11756
11757@item show target-wide-charset
11758@kindex show target-wide-charset
11759Show the name of the current target's wide character set.
a0eb71c5
KB
11760@end table
11761
a0eb71c5
KB
11762Here is an example of @value{GDBN}'s character set support in action.
11763Assume that the following source code has been placed in the file
11764@file{charset-test.c}:
11765
11766@smallexample
11767#include <stdio.h>
11768
11769char ascii_hello[]
11770 = @{72, 101, 108, 108, 111, 44, 32, 119,
11771 111, 114, 108, 100, 33, 10, 0@};
11772char ibm1047_hello[]
11773 = @{200, 133, 147, 147, 150, 107, 64, 166,
11774 150, 153, 147, 132, 90, 37, 0@};
11775
11776main ()
11777@{
11778 printf ("Hello, world!\n");
11779@}
10998722 11780@end smallexample
a0eb71c5
KB
11781
11782In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
11783containing the string @samp{Hello, world!} followed by a newline,
11784encoded in the @sc{ascii} and @sc{ibm1047} character sets.
11785
11786We compile the program, and invoke the debugger on it:
11787
11788@smallexample
11789$ gcc -g charset-test.c -o charset-test
11790$ gdb -nw charset-test
11791GNU gdb 2001-12-19-cvs
11792Copyright 2001 Free Software Foundation, Inc.
11793@dots{}
f7dc1244 11794(@value{GDBP})
10998722 11795@end smallexample
a0eb71c5
KB
11796
11797We can use the @code{show charset} command to see what character sets
11798@value{GDBN} is currently using to interpret and display characters and
11799strings:
11800
11801@smallexample
f7dc1244 11802(@value{GDBP}) show charset
e33d66ec 11803The current host and target character set is `ISO-8859-1'.
f7dc1244 11804(@value{GDBP})
10998722 11805@end smallexample
a0eb71c5
KB
11806
11807For the sake of printing this manual, let's use @sc{ascii} as our
11808initial character set:
11809@smallexample
f7dc1244
EZ
11810(@value{GDBP}) set charset ASCII
11811(@value{GDBP}) show charset
e33d66ec 11812The current host and target character set is `ASCII'.
f7dc1244 11813(@value{GDBP})
10998722 11814@end smallexample
a0eb71c5
KB
11815
11816Let's assume that @sc{ascii} is indeed the correct character set for our
11817host system --- in other words, let's assume that if @value{GDBN} prints
11818characters using the @sc{ascii} character set, our terminal will display
11819them properly. Since our current target character set is also
11820@sc{ascii}, the contents of @code{ascii_hello} print legibly:
11821
11822@smallexample
f7dc1244 11823(@value{GDBP}) print ascii_hello
a0eb71c5 11824$1 = 0x401698 "Hello, world!\n"
f7dc1244 11825(@value{GDBP}) print ascii_hello[0]
a0eb71c5 11826$2 = 72 'H'
f7dc1244 11827(@value{GDBP})
10998722 11828@end smallexample
a0eb71c5
KB
11829
11830@value{GDBN} uses the target character set for character and string
11831literals you use in expressions:
11832
11833@smallexample
f7dc1244 11834(@value{GDBP}) print '+'
a0eb71c5 11835$3 = 43 '+'
f7dc1244 11836(@value{GDBP})
10998722 11837@end smallexample
a0eb71c5
KB
11838
11839The @sc{ascii} character set uses the number 43 to encode the @samp{+}
11840character.
11841
11842@value{GDBN} relies on the user to tell it which character set the
11843target program uses. If we print @code{ibm1047_hello} while our target
11844character set is still @sc{ascii}, we get jibberish:
11845
11846@smallexample
f7dc1244 11847(@value{GDBP}) print ibm1047_hello
a0eb71c5 11848$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 11849(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 11850$5 = 200 '\310'
f7dc1244 11851(@value{GDBP})
10998722 11852@end smallexample
a0eb71c5 11853
e33d66ec 11854If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
11855@value{GDBN} tells us the character sets it supports:
11856
11857@smallexample
f7dc1244 11858(@value{GDBP}) set target-charset
b383017d 11859ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 11860(@value{GDBP}) set target-charset
10998722 11861@end smallexample
a0eb71c5
KB
11862
11863We can select @sc{ibm1047} as our target character set, and examine the
11864program's strings again. Now the @sc{ascii} string is wrong, but
11865@value{GDBN} translates the contents of @code{ibm1047_hello} from the
11866target character set, @sc{ibm1047}, to the host character set,
11867@sc{ascii}, and they display correctly:
11868
11869@smallexample
f7dc1244
EZ
11870(@value{GDBP}) set target-charset IBM1047
11871(@value{GDBP}) show charset
e33d66ec
EZ
11872The current host character set is `ASCII'.
11873The current target character set is `IBM1047'.
f7dc1244 11874(@value{GDBP}) print ascii_hello
a0eb71c5 11875$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 11876(@value{GDBP}) print ascii_hello[0]
a0eb71c5 11877$7 = 72 '\110'
f7dc1244 11878(@value{GDBP}) print ibm1047_hello
a0eb71c5 11879$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 11880(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 11881$9 = 200 'H'
f7dc1244 11882(@value{GDBP})
10998722 11883@end smallexample
a0eb71c5
KB
11884
11885As above, @value{GDBN} uses the target character set for character and
11886string literals you use in expressions:
11887
11888@smallexample
f7dc1244 11889(@value{GDBP}) print '+'
a0eb71c5 11890$10 = 78 '+'
f7dc1244 11891(@value{GDBP})
10998722 11892@end smallexample
a0eb71c5 11893
e33d66ec 11894The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
11895character.
11896
b12039c6
YQ
11897@node Caching Target Data
11898@section Caching Data of Targets
11899@cindex caching data of targets
11900
11901@value{GDBN} caches data exchanged between the debugger and a target.
b26dfc9a
YQ
11902Each cache is associated with the address space of the inferior.
11903@xref{Inferiors and Programs}, about inferior and address space.
b12039c6
YQ
11904Such caching generally improves performance in remote debugging
11905(@pxref{Remote Debugging}), because it reduces the overhead of the
11906remote protocol by bundling memory reads and writes into large chunks.
11907Unfortunately, simply caching everything would lead to incorrect results,
11908since @value{GDBN} does not necessarily know anything about volatile
11909values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
11910(@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
11911is executing.
29b090c0
DE
11912Therefore, by default, @value{GDBN} only caches data
11913known to be on the stack@footnote{In non-stop mode, it is moderately
11914rare for a running thread to modify the stack of a stopped thread
11915in a way that would interfere with a backtrace, and caching of
29453a14
YQ
11916stack reads provides a significant speed up of remote backtraces.} or
11917in the code segment.
29b090c0 11918Other regions of memory can be explicitly marked as
27b81af3 11919cacheable; @pxref{Memory Region Attributes}.
09d4efe1
EZ
11920
11921@table @code
11922@kindex set remotecache
11923@item set remotecache on
11924@itemx set remotecache off
4e5d721f
DE
11925This option no longer does anything; it exists for compatibility
11926with old scripts.
09d4efe1
EZ
11927
11928@kindex show remotecache
11929@item show remotecache
4e5d721f
DE
11930Show the current state of the obsolete remotecache flag.
11931
11932@kindex set stack-cache
11933@item set stack-cache on
11934@itemx set stack-cache off
6dd315ba
YQ
11935Enable or disable caching of stack accesses. When @code{on}, use
11936caching. By default, this option is @code{on}.
4e5d721f
DE
11937
11938@kindex show stack-cache
11939@item show stack-cache
11940Show the current state of data caching for memory accesses.
09d4efe1 11941
29453a14
YQ
11942@kindex set code-cache
11943@item set code-cache on
11944@itemx set code-cache off
11945Enable or disable caching of code segment accesses. When @code{on},
11946use caching. By default, this option is @code{on}. This improves
11947performance of disassembly in remote debugging.
11948
11949@kindex show code-cache
11950@item show code-cache
11951Show the current state of target memory cache for code segment
11952accesses.
11953
09d4efe1 11954@kindex info dcache
4e5d721f 11955@item info dcache @r{[}line@r{]}
b26dfc9a
YQ
11956Print the information about the performance of data cache of the
11957current inferior's address space. The information displayed
11958includes the dcache width and depth, and for each cache line, its
11959number, address, and how many times it was referenced. This
11960command is useful for debugging the data cache operation.
4e5d721f
DE
11961
11962If a line number is specified, the contents of that line will be
11963printed in hex.
1a532630
PP
11964
11965@item set dcache size @var{size}
11966@cindex dcache size
11967@kindex set dcache size
11968Set maximum number of entries in dcache (dcache depth above).
11969
11970@item set dcache line-size @var{line-size}
11971@cindex dcache line-size
11972@kindex set dcache line-size
11973Set number of bytes each dcache entry caches (dcache width above).
11974Must be a power of 2.
11975
11976@item show dcache size
11977@kindex show dcache size
b12039c6 11978Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
1a532630
PP
11979
11980@item show dcache line-size
11981@kindex show dcache line-size
b12039c6 11982Show default size of dcache lines.
1a532630 11983
09d4efe1
EZ
11984@end table
11985
08388c79
DE
11986@node Searching Memory
11987@section Search Memory
11988@cindex searching memory
11989
11990Memory can be searched for a particular sequence of bytes with the
11991@code{find} command.
11992
11993@table @code
11994@kindex find
11995@item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
11996@itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
11997Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
11998etc. The search begins at address @var{start_addr} and continues for either
11999@var{len} bytes or through to @var{end_addr} inclusive.
12000@end table
12001
12002@var{s} and @var{n} are optional parameters.
12003They may be specified in either order, apart or together.
12004
12005@table @r
12006@item @var{s}, search query size
12007The size of each search query value.
12008
12009@table @code
12010@item b
12011bytes
12012@item h
12013halfwords (two bytes)
12014@item w
12015words (four bytes)
12016@item g
12017giant words (eight bytes)
12018@end table
12019
12020All values are interpreted in the current language.
12021This means, for example, that if the current source language is C/C@t{++}
12022then searching for the string ``hello'' includes the trailing '\0'.
ee9a09e9
DC
12023The null terminator can be removed from searching by using casts,
12024e.g.: @samp{@{char[5]@}"hello"}.
08388c79
DE
12025
12026If the value size is not specified, it is taken from the
12027value's type in the current language.
12028This is useful when one wants to specify the search
12029pattern as a mixture of types.
12030Note that this means, for example, that in the case of C-like languages
12031a search for an untyped 0x42 will search for @samp{(int) 0x42}
12032which is typically four bytes.
12033
12034@item @var{n}, maximum number of finds
12035The maximum number of matches to print. The default is to print all finds.
12036@end table
12037
12038You can use strings as search values. Quote them with double-quotes
12039 (@code{"}).
12040The string value is copied into the search pattern byte by byte,
12041regardless of the endianness of the target and the size specification.
12042
12043The address of each match found is printed as well as a count of the
12044number of matches found.
12045
12046The address of the last value found is stored in convenience variable
12047@samp{$_}.
12048A count of the number of matches is stored in @samp{$numfound}.
12049
12050For example, if stopped at the @code{printf} in this function:
12051
12052@smallexample
12053void
12054hello ()
12055@{
12056 static char hello[] = "hello-hello";
12057 static struct @{ char c; short s; int i; @}
12058 __attribute__ ((packed)) mixed
12059 = @{ 'c', 0x1234, 0x87654321 @};
12060 printf ("%s\n", hello);
12061@}
12062@end smallexample
12063
12064@noindent
12065you get during debugging:
12066
12067@smallexample
12068(gdb) find &hello[0], +sizeof(hello), "hello"
120690x804956d <hello.1620+6>
120701 pattern found
12071(gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
120720x8049567 <hello.1620>
120730x804956d <hello.1620+6>
ee9a09e9
DC
120742 patterns found.
12075(gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
120760x8049567 <hello.1620>
120770x804956d <hello.1620+6>
120782 patterns found.
08388c79
DE
12079(gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
120800x8049567 <hello.1620>
120811 pattern found
12082(gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
120830x8049560 <mixed.1625>
120841 pattern found
12085(gdb) print $numfound
12086$1 = 1
12087(gdb) print $_
12088$2 = (void *) 0x8049560
12089@end smallexample
a0eb71c5 12090
5fdf6324
AB
12091@node Value Sizes
12092@section Value Sizes
12093
12094Whenever @value{GDBN} prints a value memory will be allocated within
12095@value{GDBN} to hold the contents of the value. It is possible in
12096some languages with dynamic typing systems, that an invalid program
12097may indicate a value that is incorrectly large, this in turn may cause
12098@value{GDBN} to try and allocate an overly large ammount of memory.
12099
12100@table @code
12101@kindex set max-value-size
713cdcbf 12102@item set max-value-size @var{bytes}
5fdf6324
AB
12103@itemx set max-value-size unlimited
12104Set the maximum size of memory that @value{GDBN} will allocate for the
12105contents of a value to @var{bytes}, trying to display a value that
12106requires more memory than that will result in an error.
12107
12108Setting this variable does not effect values that have already been
12109allocated within @value{GDBN}, only future allocations.
12110
12111There's a minimum size that @code{max-value-size} can be set to in
12112order that @value{GDBN} can still operate correctly, this minimum is
12113currently 16 bytes.
12114
12115The limit applies to the results of some subexpressions as well as to
12116complete expressions. For example, an expression denoting a simple
12117integer component, such as @code{x.y.z}, may fail if the size of
12118@var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
12119@value{GDBN} is sometimes clever; the expression @code{A[i]}, where
12120@var{A} is an array variable with non-constant size, will generally
12121succeed regardless of the bounds on @var{A}, as long as the component
12122size is less than @var{bytes}.
12123
12124The default value of @code{max-value-size} is currently 64k.
12125
12126@kindex show max-value-size
12127@item show max-value-size
12128Show the maximum size of memory, in bytes, that @value{GDBN} will
12129allocate for the contents of a value.
12130@end table
12131
edb3359d
DJ
12132@node Optimized Code
12133@chapter Debugging Optimized Code
12134@cindex optimized code, debugging
12135@cindex debugging optimized code
12136
12137Almost all compilers support optimization. With optimization
12138disabled, the compiler generates assembly code that corresponds
12139directly to your source code, in a simplistic way. As the compiler
12140applies more powerful optimizations, the generated assembly code
12141diverges from your original source code. With help from debugging
12142information generated by the compiler, @value{GDBN} can map from
12143the running program back to constructs from your original source.
12144
12145@value{GDBN} is more accurate with optimization disabled. If you
12146can recompile without optimization, it is easier to follow the
12147progress of your program during debugging. But, there are many cases
12148where you may need to debug an optimized version.
12149
12150When you debug a program compiled with @samp{-g -O}, remember that the
12151optimizer has rearranged your code; the debugger shows you what is
12152really there. Do not be too surprised when the execution path does not
12153exactly match your source file! An extreme example: if you define a
12154variable, but never use it, @value{GDBN} never sees that
12155variable---because the compiler optimizes it out of existence.
12156
12157Some things do not work as well with @samp{-g -O} as with just
12158@samp{-g}, particularly on machines with instruction scheduling. If in
12159doubt, recompile with @samp{-g} alone, and if this fixes the problem,
12160please report it to us as a bug (including a test case!).
12161@xref{Variables}, for more information about debugging optimized code.
12162
12163@menu
12164* Inline Functions:: How @value{GDBN} presents inlining
111c6489 12165* Tail Call Frames:: @value{GDBN} analysis of jumps to functions
edb3359d
DJ
12166@end menu
12167
12168@node Inline Functions
12169@section Inline Functions
12170@cindex inline functions, debugging
12171
12172@dfn{Inlining} is an optimization that inserts a copy of the function
12173body directly at each call site, instead of jumping to a shared
12174routine. @value{GDBN} displays inlined functions just like
12175non-inlined functions. They appear in backtraces. You can view their
12176arguments and local variables, step into them with @code{step}, skip
12177them with @code{next}, and escape from them with @code{finish}.
12178You can check whether a function was inlined by using the
12179@code{info frame} command.
12180
12181For @value{GDBN} to support inlined functions, the compiler must
12182record information about inlining in the debug information ---
12183@value{NGCC} using the @sc{dwarf 2} format does this, and several
12184other compilers do also. @value{GDBN} only supports inlined functions
12185when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
12186do not emit two required attributes (@samp{DW_AT_call_file} and
12187@samp{DW_AT_call_line}); @value{GDBN} does not display inlined
12188function calls with earlier versions of @value{NGCC}. It instead
12189displays the arguments and local variables of inlined functions as
12190local variables in the caller.
12191
12192The body of an inlined function is directly included at its call site;
12193unlike a non-inlined function, there are no instructions devoted to
12194the call. @value{GDBN} still pretends that the call site and the
12195start of the inlined function are different instructions. Stepping to
12196the call site shows the call site, and then stepping again shows
12197the first line of the inlined function, even though no additional
12198instructions are executed.
12199
12200This makes source-level debugging much clearer; you can see both the
12201context of the call and then the effect of the call. Only stepping by
12202a single instruction using @code{stepi} or @code{nexti} does not do
12203this; single instruction steps always show the inlined body.
12204
12205There are some ways that @value{GDBN} does not pretend that inlined
12206function calls are the same as normal calls:
12207
12208@itemize @bullet
edb3359d
DJ
12209@item
12210Setting breakpoints at the call site of an inlined function may not
12211work, because the call site does not contain any code. @value{GDBN}
12212may incorrectly move the breakpoint to the next line of the enclosing
12213function, after the call. This limitation will be removed in a future
12214version of @value{GDBN}; until then, set a breakpoint on an earlier line
12215or inside the inlined function instead.
12216
12217@item
12218@value{GDBN} cannot locate the return value of inlined calls after
12219using the @code{finish} command. This is a limitation of compiler-generated
12220debugging information; after @code{finish}, you can step to the next line
12221and print a variable where your program stored the return value.
12222
12223@end itemize
12224
111c6489
JK
12225@node Tail Call Frames
12226@section Tail Call Frames
12227@cindex tail call frames, debugging
12228
12229Function @code{B} can call function @code{C} in its very last statement. In
12230unoptimized compilation the call of @code{C} is immediately followed by return
12231instruction at the end of @code{B} code. Optimizing compiler may replace the
12232call and return in function @code{B} into one jump to function @code{C}
12233instead. Such use of a jump instruction is called @dfn{tail call}.
12234
12235During execution of function @code{C}, there will be no indication in the
12236function call stack frames that it was tail-called from @code{B}. If function
12237@code{A} regularly calls function @code{B} which tail-calls function @code{C},
12238then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
12239some cases @value{GDBN} can determine that @code{C} was tail-called from
12240@code{B}, and it will then create fictitious call frame for that, with the
12241return address set up as if @code{B} called @code{C} normally.
12242
12243This functionality is currently supported only by DWARF 2 debugging format and
216f72a1 12244the compiler has to produce @samp{DW_TAG_call_site} tags. With
111c6489
JK
12245@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
12246this information.
12247
12248@kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
12249kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
12250
12251@smallexample
12252(gdb) x/i $pc - 2
12253 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
12254(gdb) info frame
12255Stack level 1, frame at 0x7fffffffda30:
12256 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
12257 tail call frame, caller of frame at 0x7fffffffda30
12258 source language c++.
12259 Arglist at unknown address.
12260 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
12261@end smallexample
12262
12263The detection of all the possible code path executions can find them ambiguous.
12264There is no execution history stored (possible @ref{Reverse Execution} is never
12265used for this purpose) and the last known caller could have reached the known
12266callee by multiple different jump sequences. In such case @value{GDBN} still
12267tries to show at least all the unambiguous top tail callers and all the
12268unambiguous bottom tail calees, if any.
12269
12270@table @code
e18b2753 12271@anchor{set debug entry-values}
111c6489
JK
12272@item set debug entry-values
12273@kindex set debug entry-values
12274When set to on, enables printing of analysis messages for both frame argument
12275values at function entry and tail calls. It will show all the possible valid
12276tail calls code paths it has considered. It will also print the intersection
12277of them with the final unambiguous (possibly partial or even empty) code path
12278result.
12279
12280@item show debug entry-values
12281@kindex show debug entry-values
12282Show the current state of analysis messages printing for both frame argument
12283values at function entry and tail calls.
12284@end table
12285
12286The analysis messages for tail calls can for example show why the virtual tail
12287call frame for function @code{c} has not been recognized (due to the indirect
12288reference by variable @code{x}):
12289
12290@smallexample
12291static void __attribute__((noinline, noclone)) c (void);
12292void (*x) (void) = c;
12293static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
12294static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
12295int main (void) @{ x (); return 0; @}
12296
216f72a1
JK
12297Breakpoint 1, DW_OP_entry_value resolving cannot find
12298DW_TAG_call_site 0x40039a in main
111c6489
JK
12299a () at t.c:3
123003 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
12301(gdb) bt
12302#0 a () at t.c:3
12303#1 0x000000000040039a in main () at t.c:5
12304@end smallexample
12305
12306Another possibility is an ambiguous virtual tail call frames resolution:
12307
12308@smallexample
12309int i;
12310static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
12311static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
12312static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
12313static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
12314static void __attribute__((noinline, noclone)) b (void)
12315@{ if (i) c (); else e (); @}
12316static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
12317int main (void) @{ a (); return 0; @}
12318
12319tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
12320tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
12321tailcall: reduced: 0x4004d2(a) |
12322(gdb) bt
12323#0 f () at t.c:2
12324#1 0x00000000004004d2 in a () at t.c:8
12325#2 0x0000000000400395 in main () at t.c:9
12326@end smallexample
12327
5048e516
JK
12328@set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
12329@set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
12330
12331@c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
12332@ifset HAVE_MAKEINFO_CLICK
12333@set ARROW @click{}
12334@set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
12335@set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
12336@end ifset
12337@ifclear HAVE_MAKEINFO_CLICK
12338@set ARROW ->
12339@set CALLSEQ1B @value{CALLSEQ1A}
12340@set CALLSEQ2B @value{CALLSEQ2A}
12341@end ifclear
12342
12343Frames #0 and #2 are real, #1 is a virtual tail call frame.
12344The code can have possible execution paths @value{CALLSEQ1B} or
12345@value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
111c6489
JK
12346
12347@code{initial:} state shows some random possible calling sequence @value{GDBN}
12348has found. It then finds another possible calling sequcen - that one is
12349prefixed by @code{compare:}. The non-ambiguous intersection of these two is
12350printed as the @code{reduced:} calling sequence. That one could have many
12351futher @code{compare:} and @code{reduced:} statements as long as there remain
12352any non-ambiguous sequence entries.
12353
12354For the frame of function @code{b} in both cases there are different possible
12355@code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
12356also ambigous. The only non-ambiguous frame is the one for function @code{a},
12357therefore this one is displayed to the user while the ambiguous frames are
12358omitted.
edb3359d 12359
e18b2753
JK
12360There can be also reasons why printing of frame argument values at function
12361entry may fail:
12362
12363@smallexample
12364int v;
12365static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
12366static void __attribute__((noinline, noclone)) a (int i);
12367static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
12368static void __attribute__((noinline, noclone)) a (int i)
12369@{ if (i) b (i - 1); else c (0); @}
12370int main (void) @{ a (5); return 0; @}
12371
12372(gdb) bt
12373#0 c (i=i@@entry=0) at t.c:2
216f72a1 12374#1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
e18b2753
JK
12375function "a" at 0x400420 can call itself via tail calls
12376i=<optimized out>) at t.c:6
12377#2 0x000000000040036e in main () at t.c:7
12378@end smallexample
12379
12380@value{GDBN} cannot find out from the inferior state if and how many times did
12381function @code{a} call itself (via function @code{b}) as these calls would be
12382tail calls. Such tail calls would modify thue @code{i} variable, therefore
12383@value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
12384prints @code{<optimized out>} instead.
12385
e2e0bcd1
JB
12386@node Macros
12387@chapter C Preprocessor Macros
12388
49efadf5 12389Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
12390``preprocessor macros'' which expand into strings of tokens.
12391@value{GDBN} can evaluate expressions containing macro invocations, show
12392the result of macro expansion, and show a macro's definition, including
12393where it was defined.
12394
12395You may need to compile your program specially to provide @value{GDBN}
12396with information about preprocessor macros. Most compilers do not
12397include macros in their debugging information, even when you compile
12398with the @option{-g} flag. @xref{Compilation}.
12399
12400A program may define a macro at one point, remove that definition later,
12401and then provide a different definition after that. Thus, at different
12402points in the program, a macro may have different definitions, or have
12403no definition at all. If there is a current stack frame, @value{GDBN}
12404uses the macros in scope at that frame's source code line. Otherwise,
12405@value{GDBN} uses the macros in scope at the current listing location;
12406see @ref{List}.
12407
e2e0bcd1
JB
12408Whenever @value{GDBN} evaluates an expression, it always expands any
12409macro invocations present in the expression. @value{GDBN} also provides
12410the following commands for working with macros explicitly.
12411
12412@table @code
12413
12414@kindex macro expand
12415@cindex macro expansion, showing the results of preprocessor
12416@cindex preprocessor macro expansion, showing the results of
12417@cindex expanding preprocessor macros
12418@item macro expand @var{expression}
12419@itemx macro exp @var{expression}
12420Show the results of expanding all preprocessor macro invocations in
12421@var{expression}. Since @value{GDBN} simply expands macros, but does
12422not parse the result, @var{expression} need not be a valid expression;
12423it can be any string of tokens.
12424
09d4efe1 12425@kindex macro exp1
e2e0bcd1
JB
12426@item macro expand-once @var{expression}
12427@itemx macro exp1 @var{expression}
4644b6e3 12428@cindex expand macro once
e2e0bcd1
JB
12429@i{(This command is not yet implemented.)} Show the results of
12430expanding those preprocessor macro invocations that appear explicitly in
12431@var{expression}. Macro invocations appearing in that expansion are
12432left unchanged. This command allows you to see the effect of a
12433particular macro more clearly, without being confused by further
12434expansions. Since @value{GDBN} simply expands macros, but does not
12435parse the result, @var{expression} need not be a valid expression; it
12436can be any string of tokens.
12437
475b0867 12438@kindex info macro
e2e0bcd1 12439@cindex macro definition, showing
9b158ba0 12440@cindex definition of a macro, showing
12441@cindex macros, from debug info
71eba9c2 12442@item info macro [-a|-all] [--] @var{macro}
12443Show the current definition or all definitions of the named @var{macro},
12444and describe the source location or compiler command-line where that
12445definition was established. The optional double dash is to signify the end of
12446argument processing and the beginning of @var{macro} for non C-like macros where
12447the macro may begin with a hyphen.
e2e0bcd1 12448
9b158ba0 12449@kindex info macros
629500fa 12450@item info macros @var{location}
9b158ba0 12451Show all macro definitions that are in effect at the location specified
629500fa 12452by @var{location}, and describe the source location or compiler
9b158ba0 12453command-line where those definitions were established.
12454
e2e0bcd1
JB
12455@kindex macro define
12456@cindex user-defined macros
12457@cindex defining macros interactively
12458@cindex macros, user-defined
12459@item macro define @var{macro} @var{replacement-list}
12460@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
d7d9f01e
TT
12461Introduce a definition for a preprocessor macro named @var{macro},
12462invocations of which are replaced by the tokens given in
12463@var{replacement-list}. The first form of this command defines an
12464``object-like'' macro, which takes no arguments; the second form
12465defines a ``function-like'' macro, which takes the arguments given in
12466@var{arglist}.
12467
12468A definition introduced by this command is in scope in every
12469expression evaluated in @value{GDBN}, until it is removed with the
12470@code{macro undef} command, described below. The definition overrides
12471all definitions for @var{macro} present in the program being debugged,
12472as well as any previous user-supplied definition.
e2e0bcd1
JB
12473
12474@kindex macro undef
12475@item macro undef @var{macro}
d7d9f01e
TT
12476Remove any user-supplied definition for the macro named @var{macro}.
12477This command only affects definitions provided with the @code{macro
12478define} command, described above; it cannot remove definitions present
12479in the program being debugged.
e2e0bcd1 12480
09d4efe1
EZ
12481@kindex macro list
12482@item macro list
d7d9f01e 12483List all the macros defined using the @code{macro define} command.
e2e0bcd1
JB
12484@end table
12485
12486@cindex macros, example of debugging with
12487Here is a transcript showing the above commands in action. First, we
12488show our source files:
12489
12490@smallexample
12491$ cat sample.c
12492#include <stdio.h>
12493#include "sample.h"
12494
12495#define M 42
12496#define ADD(x) (M + x)
12497
12498main ()
12499@{
12500#define N 28
12501 printf ("Hello, world!\n");
12502#undef N
12503 printf ("We're so creative.\n");
12504#define N 1729
12505 printf ("Goodbye, world!\n");
12506@}
12507$ cat sample.h
12508#define Q <
12509$
12510@end smallexample
12511
e0f8f636
TT
12512Now, we compile the program using the @sc{gnu} C compiler,
12513@value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
12514minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
12515and @option{-gdwarf-4}; we recommend always choosing the most recent
12516version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
12517includes information about preprocessor macros in the debugging
e2e0bcd1
JB
12518information.
12519
12520@smallexample
12521$ gcc -gdwarf-2 -g3 sample.c -o sample
12522$
12523@end smallexample
12524
12525Now, we start @value{GDBN} on our sample program:
12526
12527@smallexample
12528$ gdb -nw sample
12529GNU gdb 2002-05-06-cvs
12530Copyright 2002 Free Software Foundation, Inc.
12531GDB is free software, @dots{}
f7dc1244 12532(@value{GDBP})
e2e0bcd1
JB
12533@end smallexample
12534
12535We can expand macros and examine their definitions, even when the
12536program is not running. @value{GDBN} uses the current listing position
12537to decide which macro definitions are in scope:
12538
12539@smallexample
f7dc1244 12540(@value{GDBP}) list main
e2e0bcd1
JB
125413
125424 #define M 42
125435 #define ADD(x) (M + x)
125446
125457 main ()
125468 @{
125479 #define N 28
1254810 printf ("Hello, world!\n");
1254911 #undef N
1255012 printf ("We're so creative.\n");
f7dc1244 12551(@value{GDBP}) info macro ADD
e2e0bcd1
JB
12552Defined at /home/jimb/gdb/macros/play/sample.c:5
12553#define ADD(x) (M + x)
f7dc1244 12554(@value{GDBP}) info macro Q
e2e0bcd1
JB
12555Defined at /home/jimb/gdb/macros/play/sample.h:1
12556 included at /home/jimb/gdb/macros/play/sample.c:2
12557#define Q <
f7dc1244 12558(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 12559expands to: (42 + 1)
f7dc1244 12560(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 12561expands to: once (M + 1)
f7dc1244 12562(@value{GDBP})
e2e0bcd1
JB
12563@end smallexample
12564
d7d9f01e 12565In the example above, note that @code{macro expand-once} expands only
e2e0bcd1
JB
12566the macro invocation explicit in the original text --- the invocation of
12567@code{ADD} --- but does not expand the invocation of the macro @code{M},
12568which was introduced by @code{ADD}.
12569
3f94c067
BW
12570Once the program is running, @value{GDBN} uses the macro definitions in
12571force at the source line of the current stack frame:
e2e0bcd1
JB
12572
12573@smallexample
f7dc1244 12574(@value{GDBP}) break main
e2e0bcd1 12575Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 12576(@value{GDBP}) run
b383017d 12577Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
12578
12579Breakpoint 1, main () at sample.c:10
1258010 printf ("Hello, world!\n");
f7dc1244 12581(@value{GDBP})
e2e0bcd1
JB
12582@end smallexample
12583
12584At line 10, the definition of the macro @code{N} at line 9 is in force:
12585
12586@smallexample
f7dc1244 12587(@value{GDBP}) info macro N
e2e0bcd1
JB
12588Defined at /home/jimb/gdb/macros/play/sample.c:9
12589#define N 28
f7dc1244 12590(@value{GDBP}) macro expand N Q M
e2e0bcd1 12591expands to: 28 < 42
f7dc1244 12592(@value{GDBP}) print N Q M
e2e0bcd1 12593$1 = 1
f7dc1244 12594(@value{GDBP})
e2e0bcd1
JB
12595@end smallexample
12596
12597As we step over directives that remove @code{N}'s definition, and then
12598give it a new definition, @value{GDBN} finds the definition (or lack
12599thereof) in force at each point:
12600
12601@smallexample
f7dc1244 12602(@value{GDBP}) next
e2e0bcd1
JB
12603Hello, world!
1260412 printf ("We're so creative.\n");
f7dc1244 12605(@value{GDBP}) info macro N
e2e0bcd1
JB
12606The symbol `N' has no definition as a C/C++ preprocessor macro
12607at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 12608(@value{GDBP}) next
e2e0bcd1
JB
12609We're so creative.
1261014 printf ("Goodbye, world!\n");
f7dc1244 12611(@value{GDBP}) info macro N
e2e0bcd1
JB
12612Defined at /home/jimb/gdb/macros/play/sample.c:13
12613#define N 1729
f7dc1244 12614(@value{GDBP}) macro expand N Q M
e2e0bcd1 12615expands to: 1729 < 42
f7dc1244 12616(@value{GDBP}) print N Q M
e2e0bcd1 12617$2 = 0
f7dc1244 12618(@value{GDBP})
e2e0bcd1
JB
12619@end smallexample
12620
484086b7
JK
12621In addition to source files, macros can be defined on the compilation command
12622line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
12623such a way, @value{GDBN} displays the location of their definition as line zero
12624of the source file submitted to the compiler.
12625
12626@smallexample
12627(@value{GDBP}) info macro __STDC__
12628Defined at /home/jimb/gdb/macros/play/sample.c:0
12629-D__STDC__=1
12630(@value{GDBP})
12631@end smallexample
12632
e2e0bcd1 12633
b37052ae
EZ
12634@node Tracepoints
12635@chapter Tracepoints
12636@c This chapter is based on the documentation written by Michael
12637@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
12638
12639@cindex tracepoints
12640In some applications, it is not feasible for the debugger to interrupt
12641the program's execution long enough for the developer to learn
12642anything helpful about its behavior. If the program's correctness
12643depends on its real-time behavior, delays introduced by a debugger
12644might cause the program to change its behavior drastically, or perhaps
12645fail, even when the code itself is correct. It is useful to be able
12646to observe the program's behavior without interrupting it.
12647
12648Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
12649specify locations in the program, called @dfn{tracepoints}, and
12650arbitrary expressions to evaluate when those tracepoints are reached.
12651Later, using the @code{tfind} command, you can examine the values
12652those expressions had when the program hit the tracepoints. The
12653expressions may also denote objects in memory---structures or arrays,
12654for example---whose values @value{GDBN} should record; while visiting
12655a particular tracepoint, you may inspect those objects as if they were
12656in memory at that moment. However, because @value{GDBN} records these
12657values without interacting with you, it can do so quickly and
12658unobtrusively, hopefully not disturbing the program's behavior.
12659
12660The tracepoint facility is currently available only for remote
9d29849a
JB
12661targets. @xref{Targets}. In addition, your remote target must know
12662how to collect trace data. This functionality is implemented in the
12663remote stub; however, none of the stubs distributed with @value{GDBN}
12664support tracepoints as of this writing. The format of the remote
12665packets used to implement tracepoints are described in @ref{Tracepoint
12666Packets}.
b37052ae 12667
00bf0b85
SS
12668It is also possible to get trace data from a file, in a manner reminiscent
12669of corefiles; you specify the filename, and use @code{tfind} to search
12670through the file. @xref{Trace Files}, for more details.
12671
b37052ae
EZ
12672This chapter describes the tracepoint commands and features.
12673
12674@menu
b383017d
RM
12675* Set Tracepoints::
12676* Analyze Collected Data::
12677* Tracepoint Variables::
00bf0b85 12678* Trace Files::
b37052ae
EZ
12679@end menu
12680
12681@node Set Tracepoints
12682@section Commands to Set Tracepoints
12683
12684Before running such a @dfn{trace experiment}, an arbitrary number of
1042e4c0
SS
12685tracepoints can be set. A tracepoint is actually a special type of
12686breakpoint (@pxref{Set Breaks}), so you can manipulate it using
12687standard breakpoint commands. For instance, as with breakpoints,
12688tracepoint numbers are successive integers starting from one, and many
12689of the commands associated with tracepoints take the tracepoint number
12690as their argument, to identify which tracepoint to work on.
b37052ae
EZ
12691
12692For each tracepoint, you can specify, in advance, some arbitrary set
12693of data that you want the target to collect in the trace buffer when
12694it hits that tracepoint. The collected data can include registers,
12695local variables, or global data. Later, you can use @value{GDBN}
12696commands to examine the values these data had at the time the
12697tracepoint was hit.
12698
7d13fe92
SS
12699Tracepoints do not support every breakpoint feature. Ignore counts on
12700tracepoints have no effect, and tracepoints cannot run @value{GDBN}
12701commands when they are hit. Tracepoints may not be thread-specific
12702either.
1042e4c0 12703
7a697b8d
SS
12704@cindex fast tracepoints
12705Some targets may support @dfn{fast tracepoints}, which are inserted in
12706a different way (such as with a jump instead of a trap), that is
12707faster but possibly restricted in where they may be installed.
12708
0fb4aa4b
PA
12709@cindex static tracepoints
12710@cindex markers, static tracepoints
12711@cindex probing markers, static tracepoints
12712Regular and fast tracepoints are dynamic tracing facilities, meaning
12713that they can be used to insert tracepoints at (almost) any location
12714in the target. Some targets may also support controlling @dfn{static
12715tracepoints} from @value{GDBN}. With static tracing, a set of
12716instrumentation points, also known as @dfn{markers}, are embedded in
12717the target program, and can be activated or deactivated by name or
12718address. These are usually placed at locations which facilitate
12719investigating what the target is actually doing. @value{GDBN}'s
12720support for static tracing includes being able to list instrumentation
12721points, and attach them with @value{GDBN} defined high level
12722tracepoints that expose the whole range of convenience of
8786b2bd 12723@value{GDBN}'s tracepoints support. Namely, support for collecting
0fb4aa4b
PA
12724registers values and values of global or local (to the instrumentation
12725point) variables; tracepoint conditions and trace state variables.
12726The act of installing a @value{GDBN} static tracepoint on an
12727instrumentation point, or marker, is referred to as @dfn{probing} a
12728static tracepoint marker.
12729
fa593d66
PA
12730@code{gdbserver} supports tracepoints on some target systems.
12731@xref{Server,,Tracepoints support in @code{gdbserver}}.
12732
b37052ae
EZ
12733This section describes commands to set tracepoints and associated
12734conditions and actions.
12735
12736@menu
b383017d
RM
12737* Create and Delete Tracepoints::
12738* Enable and Disable Tracepoints::
12739* Tracepoint Passcounts::
782b2b07 12740* Tracepoint Conditions::
f61e138d 12741* Trace State Variables::
b383017d
RM
12742* Tracepoint Actions::
12743* Listing Tracepoints::
0fb4aa4b 12744* Listing Static Tracepoint Markers::
79a6e687 12745* Starting and Stopping Trace Experiments::
c9429232 12746* Tracepoint Restrictions::
b37052ae
EZ
12747@end menu
12748
12749@node Create and Delete Tracepoints
12750@subsection Create and Delete Tracepoints
12751
12752@table @code
12753@cindex set tracepoint
12754@kindex trace
1042e4c0 12755@item trace @var{location}
b37052ae 12756The @code{trace} command is very similar to the @code{break} command.
629500fa
KS
12757Its argument @var{location} can be any valid location.
12758@xref{Specify Location}. The @code{trace} command defines a tracepoint,
12759which is a point in the target program where the debugger will briefly stop,
12760collect some data, and then allow the program to continue. Setting a tracepoint
12761or changing its actions takes effect immediately if the remote stub
1e4d1764
YQ
12762supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
12763in tracing}).
12764If remote stub doesn't support the @samp{InstallInTrace} feature, all
12765these changes don't take effect until the next @code{tstart}
1042e4c0 12766command, and once a trace experiment is running, further changes will
bfccc43c
YQ
12767not have any effect until the next trace experiment starts. In addition,
12768@value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
12769address is not yet resolved. (This is similar to pending breakpoints.)
12770Pending tracepoints are not downloaded to the target and not installed
12771until they are resolved. The resolution of pending tracepoints requires
12772@value{GDBN} support---when debugging with the remote target, and
12773@value{GDBN} disconnects from the remote stub (@pxref{disconnected
12774tracing}), pending tracepoints can not be resolved (and downloaded to
12775the remote stub) while @value{GDBN} is disconnected.
b37052ae
EZ
12776
12777Here are some examples of using the @code{trace} command:
12778
12779@smallexample
12780(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
12781
12782(@value{GDBP}) @b{trace +2} // 2 lines forward
12783
12784(@value{GDBP}) @b{trace my_function} // first source line of function
12785
12786(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
12787
12788(@value{GDBP}) @b{trace *0x2117c4} // an address
12789@end smallexample
12790
12791@noindent
12792You can abbreviate @code{trace} as @code{tr}.
12793
782b2b07
SS
12794@item trace @var{location} if @var{cond}
12795Set a tracepoint with condition @var{cond}; evaluate the expression
12796@var{cond} each time the tracepoint is reached, and collect data only
12797if the value is nonzero---that is, if @var{cond} evaluates as true.
12798@xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
12799information on tracepoint conditions.
12800
7a697b8d
SS
12801@item ftrace @var{location} [ if @var{cond} ]
12802@cindex set fast tracepoint
74c761c1 12803@cindex fast tracepoints, setting
7a697b8d
SS
12804@kindex ftrace
12805The @code{ftrace} command sets a fast tracepoint. For targets that
12806support them, fast tracepoints will use a more efficient but possibly
12807less general technique to trigger data collection, such as a jump
12808instruction instead of a trap, or some sort of hardware support. It
12809may not be possible to create a fast tracepoint at the desired
12810location, in which case the command will exit with an explanatory
12811message.
12812
12813@value{GDBN} handles arguments to @code{ftrace} exactly as for
12814@code{trace}.
12815
405f8e94
SS
12816On 32-bit x86-architecture systems, fast tracepoints normally need to
12817be placed at an instruction that is 5 bytes or longer, but can be
12818placed at 4-byte instructions if the low 64K of memory of the target
12819program is available to install trampolines. Some Unix-type systems,
12820such as @sc{gnu}/Linux, exclude low addresses from the program's
12821address space; but for instance with the Linux kernel it is possible
12822to let @value{GDBN} use this area by doing a @command{sysctl} command
12823to set the @code{mmap_min_addr} kernel parameter, as in
12824
12825@example
12826sudo sysctl -w vm.mmap_min_addr=32768
12827@end example
12828
12829@noindent
12830which sets the low address to 32K, which leaves plenty of room for
12831trampolines. The minimum address should be set to a page boundary.
12832
0fb4aa4b 12833@item strace @var{location} [ if @var{cond} ]
74c761c1
PA
12834@cindex set static tracepoint
12835@cindex static tracepoints, setting
12836@cindex probe static tracepoint marker
0fb4aa4b
PA
12837@kindex strace
12838The @code{strace} command sets a static tracepoint. For targets that
12839support it, setting a static tracepoint probes a static
12840instrumentation point, or marker, found at @var{location}. It may not
12841be possible to set a static tracepoint at the desired location, in
12842which case the command will exit with an explanatory message.
12843
12844@value{GDBN} handles arguments to @code{strace} exactly as for
12845@code{trace}, with the addition that the user can also specify
12846@code{-m @var{marker}} as @var{location}. This probes the marker
12847identified by the @var{marker} string identifier. This identifier
12848depends on the static tracepoint backend library your program is
12849using. You can find all the marker identifiers in the @samp{ID} field
12850of the @code{info static-tracepoint-markers} command output.
12851@xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
12852Markers}. For example, in the following small program using the UST
12853tracing engine:
12854
12855@smallexample
12856main ()
12857@{
12858 trace_mark(ust, bar33, "str %s", "FOOBAZ");
12859@}
12860@end smallexample
12861
12862@noindent
12863the marker id is composed of joining the first two arguments to the
12864@code{trace_mark} call with a slash, which translates to:
12865
12866@smallexample
12867(@value{GDBP}) info static-tracepoint-markers
12868Cnt Enb ID Address What
128691 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
12870 Data: "str %s"
12871[etc...]
12872@end smallexample
12873
12874@noindent
12875so you may probe the marker above with:
12876
12877@smallexample
12878(@value{GDBP}) strace -m ust/bar33
12879@end smallexample
12880
12881Static tracepoints accept an extra collect action --- @code{collect
12882$_sdata}. This collects arbitrary user data passed in the probe point
12883call to the tracing library. In the UST example above, you'll see
12884that the third argument to @code{trace_mark} is a printf-like format
12885string. The user data is then the result of running that formating
12886string against the following arguments. Note that @code{info
12887static-tracepoint-markers} command output lists that format string in
12888the @samp{Data:} field.
12889
12890You can inspect this data when analyzing the trace buffer, by printing
12891the $_sdata variable like any other variable available to
12892@value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
12893
b37052ae
EZ
12894@vindex $tpnum
12895@cindex last tracepoint number
12896@cindex recent tracepoint number
12897@cindex tracepoint number
12898The convenience variable @code{$tpnum} records the tracepoint number
12899of the most recently set tracepoint.
12900
12901@kindex delete tracepoint
12902@cindex tracepoint deletion
12903@item delete tracepoint @r{[}@var{num}@r{]}
12904Permanently delete one or more tracepoints. With no argument, the
1042e4c0
SS
12905default is to delete all tracepoints. Note that the regular
12906@code{delete} command can remove tracepoints also.
b37052ae
EZ
12907
12908Examples:
12909
12910@smallexample
12911(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
12912
12913(@value{GDBP}) @b{delete trace} // remove all tracepoints
12914@end smallexample
12915
12916@noindent
12917You can abbreviate this command as @code{del tr}.
12918@end table
12919
12920@node Enable and Disable Tracepoints
12921@subsection Enable and Disable Tracepoints
12922
1042e4c0
SS
12923These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
12924
b37052ae
EZ
12925@table @code
12926@kindex disable tracepoint
12927@item disable tracepoint @r{[}@var{num}@r{]}
12928Disable tracepoint @var{num}, or all tracepoints if no argument
12929@var{num} is given. A disabled tracepoint will have no effect during
d248b706 12930a trace experiment, but it is not forgotten. You can re-enable
b37052ae 12931a disabled tracepoint using the @code{enable tracepoint} command.
d248b706
KY
12932If the command is issued during a trace experiment and the debug target
12933has support for disabling tracepoints during a trace experiment, then the
12934change will be effective immediately. Otherwise, it will be applied to the
12935next trace experiment.
b37052ae
EZ
12936
12937@kindex enable tracepoint
12938@item enable tracepoint @r{[}@var{num}@r{]}
d248b706
KY
12939Enable tracepoint @var{num}, or all tracepoints. If this command is
12940issued during a trace experiment and the debug target supports enabling
12941tracepoints during a trace experiment, then the enabled tracepoints will
12942become effective immediately. Otherwise, they will become effective the
12943next time a trace experiment is run.
b37052ae
EZ
12944@end table
12945
12946@node Tracepoint Passcounts
12947@subsection Tracepoint Passcounts
12948
12949@table @code
12950@kindex passcount
12951@cindex tracepoint pass count
12952@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
12953Set the @dfn{passcount} of a tracepoint. The passcount is a way to
12954automatically stop a trace experiment. If a tracepoint's passcount is
12955@var{n}, then the trace experiment will be automatically stopped on
12956the @var{n}'th time that tracepoint is hit. If the tracepoint number
12957@var{num} is not specified, the @code{passcount} command sets the
12958passcount of the most recently defined tracepoint. If no passcount is
12959given, the trace experiment will run until stopped explicitly by the
12960user.
12961
12962Examples:
12963
12964@smallexample
b383017d 12965(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 12966@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
12967
12968(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 12969@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
12970(@value{GDBP}) @b{trace foo}
12971(@value{GDBP}) @b{pass 3}
12972(@value{GDBP}) @b{trace bar}
12973(@value{GDBP}) @b{pass 2}
12974(@value{GDBP}) @b{trace baz}
12975(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
12976@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
12977@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
12978@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
12979@end smallexample
12980@end table
12981
782b2b07
SS
12982@node Tracepoint Conditions
12983@subsection Tracepoint Conditions
12984@cindex conditional tracepoints
12985@cindex tracepoint conditions
12986
12987The simplest sort of tracepoint collects data every time your program
12988reaches a specified place. You can also specify a @dfn{condition} for
12989a tracepoint. A condition is just a Boolean expression in your
12990programming language (@pxref{Expressions, ,Expressions}). A
12991tracepoint with a condition evaluates the expression each time your
12992program reaches it, and data collection happens only if the condition
12993is true.
12994
12995Tracepoint conditions can be specified when a tracepoint is set, by
12996using @samp{if} in the arguments to the @code{trace} command.
12997@xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
12998also be set or changed at any time with the @code{condition} command,
12999just as with breakpoints.
13000
13001Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
13002the conditional expression itself. Instead, @value{GDBN} encodes the
6dcd5565 13003expression into an agent expression (@pxref{Agent Expressions})
782b2b07
SS
13004suitable for execution on the target, independently of @value{GDBN}.
13005Global variables become raw memory locations, locals become stack
13006accesses, and so forth.
13007
13008For instance, suppose you have a function that is usually called
13009frequently, but should not be called after an error has occurred. You
13010could use the following tracepoint command to collect data about calls
13011of that function that happen while the error code is propagating
13012through the program; an unconditional tracepoint could end up
13013collecting thousands of useless trace frames that you would have to
13014search through.
13015
13016@smallexample
13017(@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
13018@end smallexample
13019
f61e138d
SS
13020@node Trace State Variables
13021@subsection Trace State Variables
13022@cindex trace state variables
13023
13024A @dfn{trace state variable} is a special type of variable that is
13025created and managed by target-side code. The syntax is the same as
13026that for GDB's convenience variables (a string prefixed with ``$''),
13027but they are stored on the target. They must be created explicitly,
13028using a @code{tvariable} command. They are always 64-bit signed
13029integers.
13030
13031Trace state variables are remembered by @value{GDBN}, and downloaded
13032to the target along with tracepoint information when the trace
13033experiment starts. There are no intrinsic limits on the number of
13034trace state variables, beyond memory limitations of the target.
13035
13036@cindex convenience variables, and trace state variables
13037Although trace state variables are managed by the target, you can use
13038them in print commands and expressions as if they were convenience
13039variables; @value{GDBN} will get the current value from the target
13040while the trace experiment is running. Trace state variables share
13041the same namespace as other ``$'' variables, which means that you
13042cannot have trace state variables with names like @code{$23} or
13043@code{$pc}, nor can you have a trace state variable and a convenience
13044variable with the same name.
13045
13046@table @code
13047
13048@item tvariable $@var{name} [ = @var{expression} ]
13049@kindex tvariable
13050The @code{tvariable} command creates a new trace state variable named
13051@code{$@var{name}}, and optionally gives it an initial value of
697aa1b7 13052@var{expression}. The @var{expression} is evaluated when this command is
f61e138d
SS
13053entered; the result will be converted to an integer if possible,
13054otherwise @value{GDBN} will report an error. A subsequent
13055@code{tvariable} command specifying the same name does not create a
13056variable, but instead assigns the supplied initial value to the
13057existing variable of that name, overwriting any previous initial
13058value. The default initial value is 0.
13059
13060@item info tvariables
13061@kindex info tvariables
13062List all the trace state variables along with their initial values.
13063Their current values may also be displayed, if the trace experiment is
13064currently running.
13065
13066@item delete tvariable @r{[} $@var{name} @dots{} @r{]}
13067@kindex delete tvariable
13068Delete the given trace state variables, or all of them if no arguments
13069are specified.
13070
13071@end table
13072
b37052ae
EZ
13073@node Tracepoint Actions
13074@subsection Tracepoint Action Lists
13075
13076@table @code
13077@kindex actions
13078@cindex tracepoint actions
13079@item actions @r{[}@var{num}@r{]}
13080This command will prompt for a list of actions to be taken when the
13081tracepoint is hit. If the tracepoint number @var{num} is not
13082specified, this command sets the actions for the one that was most
13083recently defined (so that you can define a tracepoint and then say
13084@code{actions} without bothering about its number). You specify the
13085actions themselves on the following lines, one action at a time, and
13086terminate the actions list with a line containing just @code{end}. So
7d13fe92 13087far, the only defined actions are @code{collect}, @code{teval}, and
b37052ae
EZ
13088@code{while-stepping}.
13089
5a9351ae
SS
13090@code{actions} is actually equivalent to @code{commands} (@pxref{Break
13091Commands, ,Breakpoint Command Lists}), except that only the defined
13092actions are allowed; any other @value{GDBN} command is rejected.
13093
b37052ae
EZ
13094@cindex remove actions from a tracepoint
13095To remove all actions from a tracepoint, type @samp{actions @var{num}}
13096and follow it immediately with @samp{end}.
13097
13098@smallexample
13099(@value{GDBP}) @b{collect @var{data}} // collect some data
13100
6826cf00 13101(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 13102
6826cf00 13103(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
13104@end smallexample
13105
13106In the following example, the action list begins with @code{collect}
13107commands indicating the things to be collected when the tracepoint is
13108hit. Then, in order to single-step and collect additional data
13109following the tracepoint, a @code{while-stepping} command is used,
7d13fe92
SS
13110followed by the list of things to be collected after each step in a
13111sequence of single steps. The @code{while-stepping} command is
13112terminated by its own separate @code{end} command. Lastly, the action
13113list is terminated by an @code{end} command.
b37052ae
EZ
13114
13115@smallexample
13116(@value{GDBP}) @b{trace foo}
13117(@value{GDBP}) @b{actions}
13118Enter actions for tracepoint 1, one per line:
13119> collect bar,baz
13120> collect $regs
13121> while-stepping 12
5a9351ae 13122 > collect $pc, arr[i]
b37052ae
EZ
13123 > end
13124end
13125@end smallexample
13126
13127@kindex collect @r{(tracepoints)}
3065dfb6 13128@item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
b37052ae
EZ
13129Collect values of the given expressions when the tracepoint is hit.
13130This command accepts a comma-separated list of any valid expressions.
13131In addition to global, static, or local variables, the following
13132special arguments are supported:
13133
13134@table @code
13135@item $regs
0fb4aa4b 13136Collect all registers.
b37052ae
EZ
13137
13138@item $args
0fb4aa4b 13139Collect all function arguments.
b37052ae
EZ
13140
13141@item $locals
0fb4aa4b
PA
13142Collect all local variables.
13143
6710bf39
SS
13144@item $_ret
13145Collect the return address. This is helpful if you want to see more
13146of a backtrace.
13147
2a60e18f 13148@emph{Note:} The return address location can not always be reliably
45fa2529
PA
13149determined up front, and the wrong address / registers may end up
13150collected instead. On some architectures the reliability is higher
13151for tracepoints at function entry, while on others it's the opposite.
13152When this happens, backtracing will stop because the return address is
13153found unavailable (unless another collect rule happened to match it).
13154
62e5f89c
SDJ
13155@item $_probe_argc
13156Collects the number of arguments from the static probe at which the
13157tracepoint is located.
13158@xref{Static Probe Points}.
13159
13160@item $_probe_arg@var{n}
13161@var{n} is an integer between 0 and 11. Collects the @var{n}th argument
13162from the static probe at which the tracepoint is located.
13163@xref{Static Probe Points}.
13164
0fb4aa4b
PA
13165@item $_sdata
13166@vindex $_sdata@r{, collect}
13167Collect static tracepoint marker specific data. Only available for
13168static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
13169Lists}. On the UST static tracepoints library backend, an
13170instrumentation point resembles a @code{printf} function call. The
13171tracing library is able to collect user specified data formatted to a
13172character string using the format provided by the programmer that
13173instrumented the program. Other backends have similar mechanisms.
13174Here's an example of a UST marker call:
13175
13176@smallexample
13177 const char master_name[] = "$your_name";
13178 trace_mark(channel1, marker1, "hello %s", master_name)
13179@end smallexample
13180
13181In this case, collecting @code{$_sdata} collects the string
13182@samp{hello $yourname}. When analyzing the trace buffer, you can
13183inspect @samp{$_sdata} like any other variable available to
13184@value{GDBN}.
b37052ae
EZ
13185@end table
13186
13187You can give several consecutive @code{collect} commands, each one
13188with a single argument, or one @code{collect} command with several
5a9351ae 13189arguments separated by commas; the effect is the same.
b37052ae 13190
3065dfb6
SS
13191The optional @var{mods} changes the usual handling of the arguments.
13192@code{s} requests that pointers to chars be handled as strings, in
13193particular collecting the contents of the memory being pointed at, up
13194to the first zero. The upper bound is by default the value of the
13195@code{print elements} variable; if @code{s} is followed by a decimal
13196number, that is the upper bound instead. So for instance
13197@samp{collect/s25 mystr} collects as many as 25 characters at
13198@samp{mystr}.
13199
f5c37c66
EZ
13200The command @code{info scope} (@pxref{Symbols, info scope}) is
13201particularly useful for figuring out what data to collect.
13202
6da95a67
SS
13203@kindex teval @r{(tracepoints)}
13204@item teval @var{expr1}, @var{expr2}, @dots{}
13205Evaluate the given expressions when the tracepoint is hit. This
13206command accepts a comma-separated list of expressions. The results
13207are discarded, so this is mainly useful for assigning values to trace
13208state variables (@pxref{Trace State Variables}) without adding those
13209values to the trace buffer, as would be the case if the @code{collect}
13210action were used.
13211
b37052ae
EZ
13212@kindex while-stepping @r{(tracepoints)}
13213@item while-stepping @var{n}
c9429232 13214Perform @var{n} single-step instruction traces after the tracepoint,
7d13fe92 13215collecting new data after each step. The @code{while-stepping}
c9429232
SS
13216command is followed by the list of what to collect while stepping
13217(followed by its own @code{end} command):
b37052ae
EZ
13218
13219@smallexample
13220> while-stepping 12
13221 > collect $regs, myglobal
13222 > end
13223>
13224@end smallexample
13225
13226@noindent
7d13fe92
SS
13227Note that @code{$pc} is not automatically collected by
13228@code{while-stepping}; you need to explicitly collect that register if
13229you need it. You may abbreviate @code{while-stepping} as @code{ws} or
b37052ae 13230@code{stepping}.
236f1d4d
SS
13231
13232@item set default-collect @var{expr1}, @var{expr2}, @dots{}
13233@kindex set default-collect
13234@cindex default collection action
13235This variable is a list of expressions to collect at each tracepoint
13236hit. It is effectively an additional @code{collect} action prepended
13237to every tracepoint action list. The expressions are parsed
13238individually for each tracepoint, so for instance a variable named
13239@code{xyz} may be interpreted as a global for one tracepoint, and a
13240local for another, as appropriate to the tracepoint's location.
13241
13242@item show default-collect
13243@kindex show default-collect
13244Show the list of expressions that are collected by default at each
13245tracepoint hit.
13246
b37052ae
EZ
13247@end table
13248
13249@node Listing Tracepoints
13250@subsection Listing Tracepoints
13251
13252@table @code
e5a67952
MS
13253@kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
13254@kindex info tp @r{[}@var{n}@dots{}@r{]}
b37052ae 13255@cindex information about tracepoints
e5a67952 13256@item info tracepoints @r{[}@var{num}@dots{}@r{]}
1042e4c0
SS
13257Display information about the tracepoint @var{num}. If you don't
13258specify a tracepoint number, displays information about all the
13259tracepoints defined so far. The format is similar to that used for
13260@code{info breakpoints}; in fact, @code{info tracepoints} is the same
13261command, simply restricting itself to tracepoints.
13262
13263A tracepoint's listing may include additional information specific to
13264tracing:
b37052ae
EZ
13265
13266@itemize @bullet
13267@item
b37052ae 13268its passcount as given by the @code{passcount @var{n}} command
f2a8bc8a
YQ
13269
13270@item
13271the state about installed on target of each location
b37052ae
EZ
13272@end itemize
13273
13274@smallexample
13275(@value{GDBP}) @b{info trace}
1042e4c0
SS
13276Num Type Disp Enb Address What
132771 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
5a9351ae
SS
13278 while-stepping 20
13279 collect globfoo, $regs
13280 end
13281 collect globfoo2
13282 end
1042e4c0 13283 pass count 1200
f2a8bc8a
YQ
132842 tracepoint keep y <MULTIPLE>
13285 collect $eip
132862.1 y 0x0804859c in func4 at change-loc.h:35
13287 installed on target
132882.2 y 0xb7ffc480 in func4 at change-loc.h:35
13289 installed on target
132902.3 y <PENDING> set_tracepoint
132913 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
13292 not installed on target
b37052ae
EZ
13293(@value{GDBP})
13294@end smallexample
13295
13296@noindent
13297This command can be abbreviated @code{info tp}.
13298@end table
13299
0fb4aa4b
PA
13300@node Listing Static Tracepoint Markers
13301@subsection Listing Static Tracepoint Markers
13302
13303@table @code
13304@kindex info static-tracepoint-markers
13305@cindex information about static tracepoint markers
13306@item info static-tracepoint-markers
13307Display information about all static tracepoint markers defined in the
13308program.
13309
13310For each marker, the following columns are printed:
13311
13312@table @emph
13313@item Count
13314An incrementing counter, output to help readability. This is not a
13315stable identifier.
13316@item ID
13317The marker ID, as reported by the target.
13318@item Enabled or Disabled
13319Probed markers are tagged with @samp{y}. @samp{n} identifies marks
13320that are not enabled.
13321@item Address
13322Where the marker is in your program, as a memory address.
13323@item What
13324Where the marker is in the source for your program, as a file and line
13325number. If the debug information included in the program does not
13326allow @value{GDBN} to locate the source of the marker, this column
13327will be left blank.
13328@end table
13329
13330@noindent
13331In addition, the following information may be printed for each marker:
13332
13333@table @emph
13334@item Data
13335User data passed to the tracing library by the marker call. In the
13336UST backend, this is the format string passed as argument to the
13337marker call.
13338@item Static tracepoints probing the marker
13339The list of static tracepoints attached to the marker.
13340@end table
13341
13342@smallexample
13343(@value{GDBP}) info static-tracepoint-markers
13344Cnt ID Enb Address What
133451 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
13346 Data: number1 %d number2 %d
13347 Probed by static tracepoints: #2
133482 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
13349 Data: str %s
13350(@value{GDBP})
13351@end smallexample
13352@end table
13353
79a6e687
BW
13354@node Starting and Stopping Trace Experiments
13355@subsection Starting and Stopping Trace Experiments
b37052ae
EZ
13356
13357@table @code
f196051f 13358@kindex tstart [ @var{notes} ]
b37052ae
EZ
13359@cindex start a new trace experiment
13360@cindex collected data discarded
13361@item tstart
f196051f
SS
13362This command starts the trace experiment, and begins collecting data.
13363It has the side effect of discarding all the data collected in the
13364trace buffer during the previous trace experiment. If any arguments
13365are supplied, they are taken as a note and stored with the trace
13366experiment's state. The notes may be arbitrary text, and are
13367especially useful with disconnected tracing in a multi-user context;
13368the notes can explain what the trace is doing, supply user contact
13369information, and so forth.
13370
13371@kindex tstop [ @var{notes} ]
b37052ae
EZ
13372@cindex stop a running trace experiment
13373@item tstop
f196051f
SS
13374This command stops the trace experiment. If any arguments are
13375supplied, they are recorded with the experiment as a note. This is
13376useful if you are stopping a trace started by someone else, for
13377instance if the trace is interfering with the system's behavior and
13378needs to be stopped quickly.
b37052ae 13379
68c71a2e 13380@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
13381automatically if any tracepoint's passcount is reached
13382(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
13383
13384@kindex tstatus
13385@cindex status of trace data collection
13386@cindex trace experiment, status of
13387@item tstatus
13388This command displays the status of the current trace data
13389collection.
13390@end table
13391
13392Here is an example of the commands we described so far:
13393
13394@smallexample
13395(@value{GDBP}) @b{trace gdb_c_test}
13396(@value{GDBP}) @b{actions}
13397Enter actions for tracepoint #1, one per line.
13398> collect $regs,$locals,$args
13399> while-stepping 11
13400 > collect $regs
13401 > end
13402> end
13403(@value{GDBP}) @b{tstart}
13404 [time passes @dots{}]
13405(@value{GDBP}) @b{tstop}
13406@end smallexample
13407
03f2bd59 13408@anchor{disconnected tracing}
d5551862
SS
13409@cindex disconnected tracing
13410You can choose to continue running the trace experiment even if
13411@value{GDBN} disconnects from the target, voluntarily or
13412involuntarily. For commands such as @code{detach}, the debugger will
13413ask what you want to do with the trace. But for unexpected
13414terminations (@value{GDBN} crash, network outage), it would be
13415unfortunate to lose hard-won trace data, so the variable
13416@code{disconnected-tracing} lets you decide whether the trace should
13417continue running without @value{GDBN}.
13418
13419@table @code
13420@item set disconnected-tracing on
13421@itemx set disconnected-tracing off
13422@kindex set disconnected-tracing
13423Choose whether a tracing run should continue to run if @value{GDBN}
13424has disconnected from the target. Note that @code{detach} or
13425@code{quit} will ask you directly what to do about a running trace no
13426matter what this variable's setting, so the variable is mainly useful
13427for handling unexpected situations, such as loss of the network.
13428
13429@item show disconnected-tracing
13430@kindex show disconnected-tracing
13431Show the current choice for disconnected tracing.
13432
13433@end table
13434
13435When you reconnect to the target, the trace experiment may or may not
13436still be running; it might have filled the trace buffer in the
13437meantime, or stopped for one of the other reasons. If it is running,
13438it will continue after reconnection.
13439
13440Upon reconnection, the target will upload information about the
13441tracepoints in effect. @value{GDBN} will then compare that
13442information to the set of tracepoints currently defined, and attempt
13443to match them up, allowing for the possibility that the numbers may
13444have changed due to creation and deletion in the meantime. If one of
13445the target's tracepoints does not match any in @value{GDBN}, the
13446debugger will create a new tracepoint, so that you have a number with
13447which to specify that tracepoint. This matching-up process is
13448necessarily heuristic, and it may result in useless tracepoints being
13449created; you may simply delete them if they are of no use.
b37052ae 13450
4daf5ac0
SS
13451@cindex circular trace buffer
13452If your target agent supports a @dfn{circular trace buffer}, then you
13453can run a trace experiment indefinitely without filling the trace
13454buffer; when space runs out, the agent deletes already-collected trace
13455frames, oldest first, until there is enough room to continue
13456collecting. This is especially useful if your tracepoints are being
13457hit too often, and your trace gets terminated prematurely because the
13458buffer is full. To ask for a circular trace buffer, simply set
81896e36 13459@samp{circular-trace-buffer} to on. You can set this at any time,
4daf5ac0
SS
13460including during tracing; if the agent can do it, it will change
13461buffer handling on the fly, otherwise it will not take effect until
13462the next run.
13463
13464@table @code
13465@item set circular-trace-buffer on
13466@itemx set circular-trace-buffer off
13467@kindex set circular-trace-buffer
13468Choose whether a tracing run should use a linear or circular buffer
13469for trace data. A linear buffer will not lose any trace data, but may
13470fill up prematurely, while a circular buffer will discard old trace
13471data, but it will have always room for the latest tracepoint hits.
13472
13473@item show circular-trace-buffer
13474@kindex show circular-trace-buffer
13475Show the current choice for the trace buffer. Note that this may not
13476match the agent's current buffer handling, nor is it guaranteed to
13477match the setting that might have been in effect during a past run,
13478for instance if you are looking at frames from a trace file.
13479
13480@end table
13481
f6f899bf
HAQ
13482@table @code
13483@item set trace-buffer-size @var{n}
f81d1120 13484@itemx set trace-buffer-size unlimited
f6f899bf
HAQ
13485@kindex set trace-buffer-size
13486Request that the target use a trace buffer of @var{n} bytes. Not all
13487targets will honor the request; they may have a compiled-in size for
13488the trace buffer, or some other limitation. Set to a value of
f81d1120
PA
13489@code{unlimited} or @code{-1} to let the target use whatever size it
13490likes. This is also the default.
f6f899bf
HAQ
13491
13492@item show trace-buffer-size
13493@kindex show trace-buffer-size
13494Show the current requested size for the trace buffer. Note that this
13495will only match the actual size if the target supports size-setting,
13496and was able to handle the requested size. For instance, if the
13497target can only change buffer size between runs, this variable will
13498not reflect the change until the next run starts. Use @code{tstatus}
13499to get a report of the actual buffer size.
13500@end table
13501
f196051f
SS
13502@table @code
13503@item set trace-user @var{text}
13504@kindex set trace-user
13505
13506@item show trace-user
13507@kindex show trace-user
13508
13509@item set trace-notes @var{text}
13510@kindex set trace-notes
13511Set the trace run's notes.
13512
13513@item show trace-notes
13514@kindex show trace-notes
13515Show the trace run's notes.
13516
13517@item set trace-stop-notes @var{text}
13518@kindex set trace-stop-notes
13519Set the trace run's stop notes. The handling of the note is as for
13520@code{tstop} arguments; the set command is convenient way to fix a
13521stop note that is mistaken or incomplete.
13522
13523@item show trace-stop-notes
13524@kindex show trace-stop-notes
13525Show the trace run's stop notes.
13526
13527@end table
13528
c9429232
SS
13529@node Tracepoint Restrictions
13530@subsection Tracepoint Restrictions
13531
13532@cindex tracepoint restrictions
13533There are a number of restrictions on the use of tracepoints. As
13534described above, tracepoint data gathering occurs on the target
13535without interaction from @value{GDBN}. Thus the full capabilities of
13536the debugger are not available during data gathering, and then at data
13537examination time, you will be limited by only having what was
13538collected. The following items describe some common problems, but it
13539is not exhaustive, and you may run into additional difficulties not
13540mentioned here.
13541
13542@itemize @bullet
13543
13544@item
13545Tracepoint expressions are intended to gather objects (lvalues). Thus
13546the full flexibility of GDB's expression evaluator is not available.
13547You cannot call functions, cast objects to aggregate types, access
13548convenience variables or modify values (except by assignment to trace
13549state variables). Some language features may implicitly call
13550functions (for instance Objective-C fields with accessors), and therefore
13551cannot be collected either.
13552
13553@item
13554Collection of local variables, either individually or in bulk with
13555@code{$locals} or @code{$args}, during @code{while-stepping} may
13556behave erratically. The stepping action may enter a new scope (for
13557instance by stepping into a function), or the location of the variable
13558may change (for instance it is loaded into a register). The
13559tracepoint data recorded uses the location information for the
13560variables that is correct for the tracepoint location. When the
13561tracepoint is created, it is not possible, in general, to determine
13562where the steps of a @code{while-stepping} sequence will advance the
13563program---particularly if a conditional branch is stepped.
13564
13565@item
13566Collection of an incompletely-initialized or partially-destroyed object
13567may result in something that @value{GDBN} cannot display, or displays
13568in a misleading way.
13569
13570@item
13571When @value{GDBN} displays a pointer to character it automatically
13572dereferences the pointer to also display characters of the string
13573being pointed to. However, collecting the pointer during tracing does
13574not automatically collect the string. You need to explicitly
13575dereference the pointer and provide size information if you want to
13576collect not only the pointer, but the memory pointed to. For example,
13577@code{*ptr@@50} can be used to collect the 50 element array pointed to
13578by @code{ptr}.
13579
13580@item
13581It is not possible to collect a complete stack backtrace at a
13582tracepoint. Instead, you may collect the registers and a few hundred
d99f7e48 13583bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
c9429232
SS
13584(adjust to use the name of the actual stack pointer register on your
13585target architecture, and the amount of stack you wish to capture).
13586Then the @code{backtrace} command will show a partial backtrace when
13587using a trace frame. The number of stack frames that can be examined
13588depends on the sizes of the frames in the collected stack. Note that
13589if you ask for a block so large that it goes past the bottom of the
13590stack, the target agent may report an error trying to read from an
13591invalid address.
13592
af54718e
SS
13593@item
13594If you do not collect registers at a tracepoint, @value{GDBN} can
13595infer that the value of @code{$pc} must be the same as the address of
13596the tracepoint and use that when you are looking at a trace frame
13597for that tracepoint. However, this cannot work if the tracepoint has
13598multiple locations (for instance if it was set in a function that was
13599inlined), or if it has a @code{while-stepping} loop. In those cases
13600@value{GDBN} will warn you that it can't infer @code{$pc}, and default
13601it to zero.
13602
c9429232
SS
13603@end itemize
13604
b37052ae 13605@node Analyze Collected Data
79a6e687 13606@section Using the Collected Data
b37052ae
EZ
13607
13608After the tracepoint experiment ends, you use @value{GDBN} commands
13609for examining the trace data. The basic idea is that each tracepoint
13610collects a trace @dfn{snapshot} every time it is hit and another
13611snapshot every time it single-steps. All these snapshots are
13612consecutively numbered from zero and go into a buffer, and you can
13613examine them later. The way you examine them is to @dfn{focus} on a
13614specific trace snapshot. When the remote stub is focused on a trace
13615snapshot, it will respond to all @value{GDBN} requests for memory and
13616registers by reading from the buffer which belongs to that snapshot,
13617rather than from @emph{real} memory or registers of the program being
13618debugged. This means that @strong{all} @value{GDBN} commands
13619(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
13620behave as if we were currently debugging the program state as it was
13621when the tracepoint occurred. Any requests for data that are not in
13622the buffer will fail.
13623
13624@menu
13625* tfind:: How to select a trace snapshot
13626* tdump:: How to display all data for a snapshot
6149aea9 13627* save tracepoints:: How to save tracepoints for a future run
b37052ae
EZ
13628@end menu
13629
13630@node tfind
13631@subsection @code{tfind @var{n}}
13632
13633@kindex tfind
13634@cindex select trace snapshot
13635@cindex find trace snapshot
13636The basic command for selecting a trace snapshot from the buffer is
13637@code{tfind @var{n}}, which finds trace snapshot number @var{n},
13638counting from zero. If no argument @var{n} is given, the next
13639snapshot is selected.
13640
13641Here are the various forms of using the @code{tfind} command.
13642
13643@table @code
13644@item tfind start
13645Find the first snapshot in the buffer. This is a synonym for
13646@code{tfind 0} (since 0 is the number of the first snapshot).
13647
13648@item tfind none
13649Stop debugging trace snapshots, resume @emph{live} debugging.
13650
13651@item tfind end
13652Same as @samp{tfind none}.
13653
13654@item tfind
310cdbb6
YQ
13655No argument means find the next trace snapshot or find the first
13656one if no trace snapshot is selected.
b37052ae
EZ
13657
13658@item tfind -
13659Find the previous trace snapshot before the current one. This permits
13660retracing earlier steps.
13661
13662@item tfind tracepoint @var{num}
13663Find the next snapshot associated with tracepoint @var{num}. Search
13664proceeds forward from the last examined trace snapshot. If no
13665argument @var{num} is given, it means find the next snapshot collected
13666for the same tracepoint as the current snapshot.
13667
13668@item tfind pc @var{addr}
13669Find the next snapshot associated with the value @var{addr} of the
13670program counter. Search proceeds forward from the last examined trace
13671snapshot. If no argument @var{addr} is given, it means find the next
13672snapshot with the same value of PC as the current snapshot.
13673
13674@item tfind outside @var{addr1}, @var{addr2}
13675Find the next snapshot whose PC is outside the given range of
081dfbf7 13676addresses (exclusive).
b37052ae
EZ
13677
13678@item tfind range @var{addr1}, @var{addr2}
13679Find the next snapshot whose PC is between @var{addr1} and
081dfbf7 13680@var{addr2} (inclusive).
b37052ae
EZ
13681
13682@item tfind line @r{[}@var{file}:@r{]}@var{n}
13683Find the next snapshot associated with the source line @var{n}. If
13684the optional argument @var{file} is given, refer to line @var{n} in
13685that source file. Search proceeds forward from the last examined
13686trace snapshot. If no argument @var{n} is given, it means find the
13687next line other than the one currently being examined; thus saying
13688@code{tfind line} repeatedly can appear to have the same effect as
13689stepping from line to line in a @emph{live} debugging session.
13690@end table
13691
13692The default arguments for the @code{tfind} commands are specifically
13693designed to make it easy to scan through the trace buffer. For
13694instance, @code{tfind} with no argument selects the next trace
13695snapshot, and @code{tfind -} with no argument selects the previous
13696trace snapshot. So, by giving one @code{tfind} command, and then
13697simply hitting @key{RET} repeatedly you can examine all the trace
13698snapshots in order. Or, by saying @code{tfind -} and then hitting
13699@key{RET} repeatedly you can examine the snapshots in reverse order.
13700The @code{tfind line} command with no argument selects the snapshot
13701for the next source line executed. The @code{tfind pc} command with
13702no argument selects the next snapshot with the same program counter
13703(PC) as the current frame. The @code{tfind tracepoint} command with
13704no argument selects the next trace snapshot collected by the same
13705tracepoint as the current one.
13706
13707In addition to letting you scan through the trace buffer manually,
13708these commands make it easy to construct @value{GDBN} scripts that
13709scan through the trace buffer and print out whatever collected data
13710you are interested in. Thus, if we want to examine the PC, FP, and SP
13711registers from each trace frame in the buffer, we can say this:
13712
13713@smallexample
13714(@value{GDBP}) @b{tfind start}
13715(@value{GDBP}) @b{while ($trace_frame != -1)}
13716> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
13717 $trace_frame, $pc, $sp, $fp
13718> tfind
13719> end
13720
13721Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
13722Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
13723Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
13724Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
13725Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
13726Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
13727Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
13728Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
13729Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
13730Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
13731Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
13732@end smallexample
13733
13734Or, if we want to examine the variable @code{X} at each source line in
13735the buffer:
13736
13737@smallexample
13738(@value{GDBP}) @b{tfind start}
13739(@value{GDBP}) @b{while ($trace_frame != -1)}
13740> printf "Frame %d, X == %d\n", $trace_frame, X
13741> tfind line
13742> end
13743
13744Frame 0, X = 1
13745Frame 7, X = 2
13746Frame 13, X = 255
13747@end smallexample
13748
13749@node tdump
13750@subsection @code{tdump}
13751@kindex tdump
13752@cindex dump all data collected at tracepoint
13753@cindex tracepoint data, display
13754
13755This command takes no arguments. It prints all the data collected at
13756the current trace snapshot.
13757
13758@smallexample
13759(@value{GDBP}) @b{trace 444}
13760(@value{GDBP}) @b{actions}
13761Enter actions for tracepoint #2, one per line:
13762> collect $regs, $locals, $args, gdb_long_test
13763> end
13764
13765(@value{GDBP}) @b{tstart}
13766
13767(@value{GDBP}) @b{tfind line 444}
13768#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
13769at gdb_test.c:444
13770444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
13771
13772(@value{GDBP}) @b{tdump}
13773Data collected at tracepoint 2, trace frame 1:
13774d0 0xc4aa0085 -995491707
13775d1 0x18 24
13776d2 0x80 128
13777d3 0x33 51
13778d4 0x71aea3d 119204413
13779d5 0x22 34
13780d6 0xe0 224
13781d7 0x380035 3670069
13782a0 0x19e24a 1696330
13783a1 0x3000668 50333288
13784a2 0x100 256
13785a3 0x322000 3284992
13786a4 0x3000698 50333336
13787a5 0x1ad3cc 1758156
13788fp 0x30bf3c 0x30bf3c
13789sp 0x30bf34 0x30bf34
13790ps 0x0 0
13791pc 0x20b2c8 0x20b2c8
13792fpcontrol 0x0 0
13793fpstatus 0x0 0
13794fpiaddr 0x0 0
13795p = 0x20e5b4 "gdb-test"
13796p1 = (void *) 0x11
13797p2 = (void *) 0x22
13798p3 = (void *) 0x33
13799p4 = (void *) 0x44
13800p5 = (void *) 0x55
13801p6 = (void *) 0x66
13802gdb_long_test = 17 '\021'
13803
13804(@value{GDBP})
13805@end smallexample
13806
af54718e
SS
13807@code{tdump} works by scanning the tracepoint's current collection
13808actions and printing the value of each expression listed. So
13809@code{tdump} can fail, if after a run, you change the tracepoint's
13810actions to mention variables that were not collected during the run.
13811
13812Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
13813uses the collected value of @code{$pc} to distinguish between trace
13814frames that were collected at the tracepoint hit, and frames that were
13815collected while stepping. This allows it to correctly choose whether
13816to display the basic list of collections, or the collections from the
13817body of the while-stepping loop. However, if @code{$pc} was not collected,
13818then @code{tdump} will always attempt to dump using the basic collection
13819list, and may fail if a while-stepping frame does not include all the
13820same data that is collected at the tracepoint hit.
13821@c This is getting pretty arcane, example would be good.
13822
6149aea9
PA
13823@node save tracepoints
13824@subsection @code{save tracepoints @var{filename}}
13825@kindex save tracepoints
b37052ae
EZ
13826@kindex save-tracepoints
13827@cindex save tracepoints for future sessions
13828
13829This command saves all current tracepoint definitions together with
13830their actions and passcounts, into a file @file{@var{filename}}
13831suitable for use in a later debugging session. To read the saved
13832tracepoint definitions, use the @code{source} command (@pxref{Command
6149aea9
PA
13833Files}). The @w{@code{save-tracepoints}} command is a deprecated
13834alias for @w{@code{save tracepoints}}
b37052ae
EZ
13835
13836@node Tracepoint Variables
13837@section Convenience Variables for Tracepoints
13838@cindex tracepoint variables
13839@cindex convenience variables for tracepoints
13840
13841@table @code
13842@vindex $trace_frame
13843@item (int) $trace_frame
13844The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
13845snapshot is selected.
13846
13847@vindex $tracepoint
13848@item (int) $tracepoint
13849The tracepoint for the current trace snapshot.
13850
13851@vindex $trace_line
13852@item (int) $trace_line
13853The line number for the current trace snapshot.
13854
13855@vindex $trace_file
13856@item (char []) $trace_file
13857The source file for the current trace snapshot.
13858
13859@vindex $trace_func
13860@item (char []) $trace_func
13861The name of the function containing @code{$tracepoint}.
13862@end table
13863
13864Note: @code{$trace_file} is not suitable for use in @code{printf},
13865use @code{output} instead.
13866
13867Here's a simple example of using these convenience variables for
13868stepping through all the trace snapshots and printing some of their
f61e138d
SS
13869data. Note that these are not the same as trace state variables,
13870which are managed by the target.
b37052ae
EZ
13871
13872@smallexample
13873(@value{GDBP}) @b{tfind start}
13874
13875(@value{GDBP}) @b{while $trace_frame != -1}
13876> output $trace_file
13877> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
13878> tfind
13879> end
13880@end smallexample
13881
00bf0b85
SS
13882@node Trace Files
13883@section Using Trace Files
13884@cindex trace files
13885
13886In some situations, the target running a trace experiment may no
13887longer be available; perhaps it crashed, or the hardware was needed
13888for a different activity. To handle these cases, you can arrange to
13889dump the trace data into a file, and later use that file as a source
13890of trace data, via the @code{target tfile} command.
13891
13892@table @code
13893
13894@kindex tsave
13895@item tsave [ -r ] @var{filename}
d0353e76 13896@itemx tsave [-ctf] @var{dirname}
00bf0b85
SS
13897Save the trace data to @var{filename}. By default, this command
13898assumes that @var{filename} refers to the host filesystem, so if
13899necessary @value{GDBN} will copy raw trace data up from the target and
13900then save it. If the target supports it, you can also supply the
13901optional argument @code{-r} (``remote'') to direct the target to save
13902the data directly into @var{filename} in its own filesystem, which may be
13903more efficient if the trace buffer is very large. (Note, however, that
13904@code{target tfile} can only read from files accessible to the host.)
d0353e76 13905By default, this command will save trace frame in tfile format.
be06ba8c 13906You can supply the optional argument @code{-ctf} to save data in CTF
d0353e76
YQ
13907format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
13908that can be shared by multiple debugging and tracing tools. Please go to
13909@indicateurl{http://www.efficios.com/ctf} to get more information.
00bf0b85
SS
13910
13911@kindex target tfile
13912@kindex tfile
393fd4c3
YQ
13913@kindex target ctf
13914@kindex ctf
00bf0b85 13915@item target tfile @var{filename}
393fd4c3
YQ
13916@itemx target ctf @var{dirname}
13917Use the file named @var{filename} or directory named @var{dirname} as
13918a source of trace data. Commands that examine data work as they do with
13919a live target, but it is not possible to run any new trace experiments.
13920@code{tstatus} will report the state of the trace run at the moment
13921the data was saved, as well as the current trace frame you are examining.
697aa1b7 13922Both @var{filename} and @var{dirname} must be on a filesystem accessible to
393fd4c3
YQ
13923the host.
13924
13925@smallexample
13926(@value{GDBP}) target ctf ctf.ctf
13927(@value{GDBP}) tfind
13928Found trace frame 0, tracepoint 2
1392939 ++a; /* set tracepoint 1 here */
13930(@value{GDBP}) tdump
13931Data collected at tracepoint 2, trace frame 0:
13932i = 0
13933a = 0
13934b = 1 '\001'
13935c = @{"123", "456", "789", "123", "456", "789"@}
13936d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
13937(@value{GDBP}) p b
13938$1 = 1
13939@end smallexample
00bf0b85
SS
13940
13941@end table
13942
df0cd8c5
JB
13943@node Overlays
13944@chapter Debugging Programs That Use Overlays
13945@cindex overlays
13946
13947If your program is too large to fit completely in your target system's
13948memory, you can sometimes use @dfn{overlays} to work around this
13949problem. @value{GDBN} provides some support for debugging programs that
13950use overlays.
13951
13952@menu
13953* How Overlays Work:: A general explanation of overlays.
13954* Overlay Commands:: Managing overlays in @value{GDBN}.
13955* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
13956 mapped by asking the inferior.
13957* Overlay Sample Program:: A sample program using overlays.
13958@end menu
13959
13960@node How Overlays Work
13961@section How Overlays Work
13962@cindex mapped overlays
13963@cindex unmapped overlays
13964@cindex load address, overlay's
13965@cindex mapped address
13966@cindex overlay area
13967
13968Suppose you have a computer whose instruction address space is only 64
13969kilobytes long, but which has much more memory which can be accessed by
13970other means: special instructions, segment registers, or memory
13971management hardware, for example. Suppose further that you want to
13972adapt a program which is larger than 64 kilobytes to run on this system.
13973
13974One solution is to identify modules of your program which are relatively
13975independent, and need not call each other directly; call these modules
13976@dfn{overlays}. Separate the overlays from the main program, and place
13977their machine code in the larger memory. Place your main program in
13978instruction memory, but leave at least enough space there to hold the
13979largest overlay as well.
13980
13981Now, to call a function located in an overlay, you must first copy that
13982overlay's machine code from the large memory into the space set aside
13983for it in the instruction memory, and then jump to its entry point
13984there.
13985
c928edc0
AC
13986@c NB: In the below the mapped area's size is greater or equal to the
13987@c size of all overlays. This is intentional to remind the developer
13988@c that overlays don't necessarily need to be the same size.
13989
474c8240 13990@smallexample
df0cd8c5 13991@group
c928edc0
AC
13992 Data Instruction Larger
13993Address Space Address Space Address Space
13994+-----------+ +-----------+ +-----------+
13995| | | | | |
13996+-----------+ +-----------+ +-----------+<-- overlay 1
13997| program | | main | .----| overlay 1 | load address
13998| variables | | program | | +-----------+
13999| and heap | | | | | |
14000+-----------+ | | | +-----------+<-- overlay 2
14001| | +-----------+ | | | load address
14002+-----------+ | | | .-| overlay 2 |
14003 | | | | | |
14004 mapped --->+-----------+ | | +-----------+
14005 address | | | | | |
14006 | overlay | <-' | | |
14007 | area | <---' +-----------+<-- overlay 3
14008 | | <---. | | load address
14009 +-----------+ `--| overlay 3 |
14010 | | | |
14011 +-----------+ | |
14012 +-----------+
14013 | |
14014 +-----------+
14015
14016 @anchor{A code overlay}A code overlay
df0cd8c5 14017@end group
474c8240 14018@end smallexample
df0cd8c5 14019
c928edc0
AC
14020The diagram (@pxref{A code overlay}) shows a system with separate data
14021and instruction address spaces. To map an overlay, the program copies
14022its code from the larger address space to the instruction address space.
14023Since the overlays shown here all use the same mapped address, only one
14024may be mapped at a time. For a system with a single address space for
14025data and instructions, the diagram would be similar, except that the
14026program variables and heap would share an address space with the main
14027program and the overlay area.
df0cd8c5
JB
14028
14029An overlay loaded into instruction memory and ready for use is called a
14030@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
14031instruction memory. An overlay not present (or only partially present)
14032in instruction memory is called @dfn{unmapped}; its @dfn{load address}
14033is its address in the larger memory. The mapped address is also called
14034the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
14035called the @dfn{load memory address}, or @dfn{LMA}.
14036
14037Unfortunately, overlays are not a completely transparent way to adapt a
14038program to limited instruction memory. They introduce a new set of
14039global constraints you must keep in mind as you design your program:
14040
14041@itemize @bullet
14042
14043@item
14044Before calling or returning to a function in an overlay, your program
14045must make sure that overlay is actually mapped. Otherwise, the call or
14046return will transfer control to the right address, but in the wrong
14047overlay, and your program will probably crash.
14048
14049@item
14050If the process of mapping an overlay is expensive on your system, you
14051will need to choose your overlays carefully to minimize their effect on
14052your program's performance.
14053
14054@item
14055The executable file you load onto your system must contain each
14056overlay's instructions, appearing at the overlay's load address, not its
14057mapped address. However, each overlay's instructions must be relocated
14058and its symbols defined as if the overlay were at its mapped address.
14059You can use GNU linker scripts to specify different load and relocation
14060addresses for pieces of your program; see @ref{Overlay Description,,,
14061ld.info, Using ld: the GNU linker}.
14062
14063@item
14064The procedure for loading executable files onto your system must be able
14065to load their contents into the larger address space as well as the
14066instruction and data spaces.
14067
14068@end itemize
14069
14070The overlay system described above is rather simple, and could be
14071improved in many ways:
14072
14073@itemize @bullet
14074
14075@item
14076If your system has suitable bank switch registers or memory management
14077hardware, you could use those facilities to make an overlay's load area
14078contents simply appear at their mapped address in instruction space.
14079This would probably be faster than copying the overlay to its mapped
14080area in the usual way.
14081
14082@item
14083If your overlays are small enough, you could set aside more than one
14084overlay area, and have more than one overlay mapped at a time.
14085
14086@item
14087You can use overlays to manage data, as well as instructions. In
14088general, data overlays are even less transparent to your design than
14089code overlays: whereas code overlays only require care when you call or
14090return to functions, data overlays require care every time you access
14091the data. Also, if you change the contents of a data overlay, you
14092must copy its contents back out to its load address before you can copy a
14093different data overlay into the same mapped area.
14094
14095@end itemize
14096
14097
14098@node Overlay Commands
14099@section Overlay Commands
14100
14101To use @value{GDBN}'s overlay support, each overlay in your program must
14102correspond to a separate section of the executable file. The section's
14103virtual memory address and load memory address must be the overlay's
14104mapped and load addresses. Identifying overlays with sections allows
14105@value{GDBN} to determine the appropriate address of a function or
14106variable, depending on whether the overlay is mapped or not.
14107
14108@value{GDBN}'s overlay commands all start with the word @code{overlay};
14109you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
14110
14111@table @code
14112@item overlay off
4644b6e3 14113@kindex overlay
df0cd8c5
JB
14114Disable @value{GDBN}'s overlay support. When overlay support is
14115disabled, @value{GDBN} assumes that all functions and variables are
14116always present at their mapped addresses. By default, @value{GDBN}'s
14117overlay support is disabled.
14118
14119@item overlay manual
df0cd8c5
JB
14120@cindex manual overlay debugging
14121Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
14122relies on you to tell it which overlays are mapped, and which are not,
14123using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
14124commands described below.
14125
14126@item overlay map-overlay @var{overlay}
14127@itemx overlay map @var{overlay}
df0cd8c5
JB
14128@cindex map an overlay
14129Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
14130be the name of the object file section containing the overlay. When an
14131overlay is mapped, @value{GDBN} assumes it can find the overlay's
14132functions and variables at their mapped addresses. @value{GDBN} assumes
14133that any other overlays whose mapped ranges overlap that of
14134@var{overlay} are now unmapped.
14135
14136@item overlay unmap-overlay @var{overlay}
14137@itemx overlay unmap @var{overlay}
df0cd8c5
JB
14138@cindex unmap an overlay
14139Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
14140must be the name of the object file section containing the overlay.
14141When an overlay is unmapped, @value{GDBN} assumes it can find the
14142overlay's functions and variables at their load addresses.
14143
14144@item overlay auto
df0cd8c5
JB
14145Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
14146consults a data structure the overlay manager maintains in the inferior
14147to see which overlays are mapped. For details, see @ref{Automatic
14148Overlay Debugging}.
14149
14150@item overlay load-target
14151@itemx overlay load
df0cd8c5
JB
14152@cindex reloading the overlay table
14153Re-read the overlay table from the inferior. Normally, @value{GDBN}
14154re-reads the table @value{GDBN} automatically each time the inferior
14155stops, so this command should only be necessary if you have changed the
14156overlay mapping yourself using @value{GDBN}. This command is only
14157useful when using automatic overlay debugging.
14158
14159@item overlay list-overlays
14160@itemx overlay list
14161@cindex listing mapped overlays
14162Display a list of the overlays currently mapped, along with their mapped
14163addresses, load addresses, and sizes.
14164
14165@end table
14166
14167Normally, when @value{GDBN} prints a code address, it includes the name
14168of the function the address falls in:
14169
474c8240 14170@smallexample
f7dc1244 14171(@value{GDBP}) print main
df0cd8c5 14172$3 = @{int ()@} 0x11a0 <main>
474c8240 14173@end smallexample
df0cd8c5
JB
14174@noindent
14175When overlay debugging is enabled, @value{GDBN} recognizes code in
14176unmapped overlays, and prints the names of unmapped functions with
14177asterisks around them. For example, if @code{foo} is a function in an
14178unmapped overlay, @value{GDBN} prints it this way:
14179
474c8240 14180@smallexample
f7dc1244 14181(@value{GDBP}) overlay list
df0cd8c5 14182No sections are mapped.
f7dc1244 14183(@value{GDBP}) print foo
df0cd8c5 14184$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 14185@end smallexample
df0cd8c5
JB
14186@noindent
14187When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
14188name normally:
14189
474c8240 14190@smallexample
f7dc1244 14191(@value{GDBP}) overlay list
b383017d 14192Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 14193 mapped at 0x1016 - 0x104a
f7dc1244 14194(@value{GDBP}) print foo
df0cd8c5 14195$6 = @{int (int)@} 0x1016 <foo>
474c8240 14196@end smallexample
df0cd8c5
JB
14197
14198When overlay debugging is enabled, @value{GDBN} can find the correct
14199address for functions and variables in an overlay, whether or not the
14200overlay is mapped. This allows most @value{GDBN} commands, like
14201@code{break} and @code{disassemble}, to work normally, even on unmapped
14202code. However, @value{GDBN}'s breakpoint support has some limitations:
14203
14204@itemize @bullet
14205@item
14206@cindex breakpoints in overlays
14207@cindex overlays, setting breakpoints in
14208You can set breakpoints in functions in unmapped overlays, as long as
14209@value{GDBN} can write to the overlay at its load address.
14210@item
14211@value{GDBN} can not set hardware or simulator-based breakpoints in
14212unmapped overlays. However, if you set a breakpoint at the end of your
14213overlay manager (and tell @value{GDBN} which overlays are now mapped, if
14214you are using manual overlay management), @value{GDBN} will re-set its
14215breakpoints properly.
14216@end itemize
14217
14218
14219@node Automatic Overlay Debugging
14220@section Automatic Overlay Debugging
14221@cindex automatic overlay debugging
14222
14223@value{GDBN} can automatically track which overlays are mapped and which
14224are not, given some simple co-operation from the overlay manager in the
14225inferior. If you enable automatic overlay debugging with the
14226@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
14227looks in the inferior's memory for certain variables describing the
14228current state of the overlays.
14229
14230Here are the variables your overlay manager must define to support
14231@value{GDBN}'s automatic overlay debugging:
14232
14233@table @asis
14234
14235@item @code{_ovly_table}:
14236This variable must be an array of the following structures:
14237
474c8240 14238@smallexample
df0cd8c5
JB
14239struct
14240@{
14241 /* The overlay's mapped address. */
14242 unsigned long vma;
14243
14244 /* The size of the overlay, in bytes. */
14245 unsigned long size;
14246
14247 /* The overlay's load address. */
14248 unsigned long lma;
14249
14250 /* Non-zero if the overlay is currently mapped;
14251 zero otherwise. */
14252 unsigned long mapped;
14253@}
474c8240 14254@end smallexample
df0cd8c5
JB
14255
14256@item @code{_novlys}:
14257This variable must be a four-byte signed integer, holding the total
14258number of elements in @code{_ovly_table}.
14259
14260@end table
14261
14262To decide whether a particular overlay is mapped or not, @value{GDBN}
14263looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
14264@code{lma} members equal the VMA and LMA of the overlay's section in the
14265executable file. When @value{GDBN} finds a matching entry, it consults
14266the entry's @code{mapped} member to determine whether the overlay is
14267currently mapped.
14268
81d46470 14269In addition, your overlay manager may define a function called
def71bfa 14270@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
14271will silently set a breakpoint there. If the overlay manager then
14272calls this function whenever it has changed the overlay table, this
14273will enable @value{GDBN} to accurately keep track of which overlays
14274are in program memory, and update any breakpoints that may be set
b383017d 14275in overlays. This will allow breakpoints to work even if the
81d46470
MS
14276overlays are kept in ROM or other non-writable memory while they
14277are not being executed.
df0cd8c5
JB
14278
14279@node Overlay Sample Program
14280@section Overlay Sample Program
14281@cindex overlay example program
14282
14283When linking a program which uses overlays, you must place the overlays
14284at their load addresses, while relocating them to run at their mapped
14285addresses. To do this, you must write a linker script (@pxref{Overlay
14286Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
14287since linker scripts are specific to a particular host system, target
14288architecture, and target memory layout, this manual cannot provide
14289portable sample code demonstrating @value{GDBN}'s overlay support.
14290
14291However, the @value{GDBN} source distribution does contain an overlaid
14292program, with linker scripts for a few systems, as part of its test
14293suite. The program consists of the following files from
14294@file{gdb/testsuite/gdb.base}:
14295
14296@table @file
14297@item overlays.c
14298The main program file.
14299@item ovlymgr.c
14300A simple overlay manager, used by @file{overlays.c}.
14301@item foo.c
14302@itemx bar.c
14303@itemx baz.c
14304@itemx grbx.c
14305Overlay modules, loaded and used by @file{overlays.c}.
14306@item d10v.ld
14307@itemx m32r.ld
14308Linker scripts for linking the test program on the @code{d10v-elf}
14309and @code{m32r-elf} targets.
14310@end table
14311
14312You can build the test program using the @code{d10v-elf} GCC
14313cross-compiler like this:
14314
474c8240 14315@smallexample
df0cd8c5
JB
14316$ d10v-elf-gcc -g -c overlays.c
14317$ d10v-elf-gcc -g -c ovlymgr.c
14318$ d10v-elf-gcc -g -c foo.c
14319$ d10v-elf-gcc -g -c bar.c
14320$ d10v-elf-gcc -g -c baz.c
14321$ d10v-elf-gcc -g -c grbx.c
14322$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
14323 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 14324@end smallexample
df0cd8c5
JB
14325
14326The build process is identical for any other architecture, except that
14327you must substitute the appropriate compiler and linker script for the
14328target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
14329
14330
6d2ebf8b 14331@node Languages
c906108c
SS
14332@chapter Using @value{GDBN} with Different Languages
14333@cindex languages
14334
c906108c
SS
14335Although programming languages generally have common aspects, they are
14336rarely expressed in the same manner. For instance, in ANSI C,
14337dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
14338Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 14339represented (and displayed) differently. Hex numbers in C appear as
c906108c 14340@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
14341
14342@cindex working language
14343Language-specific information is built into @value{GDBN} for some languages,
14344allowing you to express operations like the above in your program's
14345native language, and allowing @value{GDBN} to output values in a manner
14346consistent with the syntax of your program's native language. The
14347language you use to build expressions is called the @dfn{working
14348language}.
14349
14350@menu
14351* Setting:: Switching between source languages
14352* Show:: Displaying the language
c906108c 14353* Checks:: Type and range checks
79a6e687
BW
14354* Supported Languages:: Supported languages
14355* Unsupported Languages:: Unsupported languages
c906108c
SS
14356@end menu
14357
6d2ebf8b 14358@node Setting
79a6e687 14359@section Switching Between Source Languages
c906108c
SS
14360
14361There are two ways to control the working language---either have @value{GDBN}
14362set it automatically, or select it manually yourself. You can use the
14363@code{set language} command for either purpose. On startup, @value{GDBN}
14364defaults to setting the language automatically. The working language is
14365used to determine how expressions you type are interpreted, how values
14366are printed, etc.
14367
14368In addition to the working language, every source file that
14369@value{GDBN} knows about has its own working language. For some object
14370file formats, the compiler might indicate which language a particular
14371source file is in. However, most of the time @value{GDBN} infers the
14372language from the name of the file. The language of a source file
b37052ae 14373controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 14374show each frame appropriately for its own language. There is no way to
d4f3574e
SS
14375set the language of a source file from within @value{GDBN}, but you can
14376set the language associated with a filename extension. @xref{Show, ,
79a6e687 14377Displaying the Language}.
c906108c
SS
14378
14379This is most commonly a problem when you use a program, such
5d161b24 14380as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
14381another language. In that case, make the
14382program use @code{#line} directives in its C output; that way
14383@value{GDBN} will know the correct language of the source code of the original
14384program, and will display that source code, not the generated C code.
14385
14386@menu
14387* Filenames:: Filename extensions and languages.
14388* Manually:: Setting the working language manually
14389* Automatically:: Having @value{GDBN} infer the source language
14390@end menu
14391
6d2ebf8b 14392@node Filenames
79a6e687 14393@subsection List of Filename Extensions and Languages
c906108c
SS
14394
14395If a source file name ends in one of the following extensions, then
14396@value{GDBN} infers that its language is the one indicated.
14397
14398@table @file
e07c999f
PH
14399@item .ada
14400@itemx .ads
14401@itemx .adb
14402@itemx .a
14403Ada source file.
c906108c
SS
14404
14405@item .c
14406C source file
14407
14408@item .C
14409@itemx .cc
14410@itemx .cp
14411@itemx .cpp
14412@itemx .cxx
14413@itemx .c++
b37052ae 14414C@t{++} source file
c906108c 14415
6aecb9c2
JB
14416@item .d
14417D source file
14418
b37303ee
AF
14419@item .m
14420Objective-C source file
14421
c906108c
SS
14422@item .f
14423@itemx .F
14424Fortran source file
14425
c906108c
SS
14426@item .mod
14427Modula-2 source file
c906108c
SS
14428
14429@item .s
14430@itemx .S
14431Assembler source file. This actually behaves almost like C, but
14432@value{GDBN} does not skip over function prologues when stepping.
14433@end table
14434
14435In addition, you may set the language associated with a filename
79a6e687 14436extension. @xref{Show, , Displaying the Language}.
c906108c 14437
6d2ebf8b 14438@node Manually
79a6e687 14439@subsection Setting the Working Language
c906108c
SS
14440
14441If you allow @value{GDBN} to set the language automatically,
14442expressions are interpreted the same way in your debugging session and
14443your program.
14444
14445@kindex set language
14446If you wish, you may set the language manually. To do this, issue the
14447command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 14448a language, such as
c906108c 14449@code{c} or @code{modula-2}.
c906108c
SS
14450For a list of the supported languages, type @samp{set language}.
14451
c906108c
SS
14452Setting the language manually prevents @value{GDBN} from updating the working
14453language automatically. This can lead to confusion if you try
14454to debug a program when the working language is not the same as the
14455source language, when an expression is acceptable to both
14456languages---but means different things. For instance, if the current
14457source file were written in C, and @value{GDBN} was parsing Modula-2, a
14458command such as:
14459
474c8240 14460@smallexample
c906108c 14461print a = b + c
474c8240 14462@end smallexample
c906108c
SS
14463
14464@noindent
14465might not have the effect you intended. In C, this means to add
14466@code{b} and @code{c} and place the result in @code{a}. The result
14467printed would be the value of @code{a}. In Modula-2, this means to compare
14468@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 14469
6d2ebf8b 14470@node Automatically
79a6e687 14471@subsection Having @value{GDBN} Infer the Source Language
c906108c
SS
14472
14473To have @value{GDBN} set the working language automatically, use
14474@samp{set language local} or @samp{set language auto}. @value{GDBN}
14475then infers the working language. That is, when your program stops in a
14476frame (usually by encountering a breakpoint), @value{GDBN} sets the
14477working language to the language recorded for the function in that
14478frame. If the language for a frame is unknown (that is, if the function
14479or block corresponding to the frame was defined in a source file that
14480does not have a recognized extension), the current working language is
14481not changed, and @value{GDBN} issues a warning.
14482
14483This may not seem necessary for most programs, which are written
14484entirely in one source language. However, program modules and libraries
14485written in one source language can be used by a main program written in
14486a different source language. Using @samp{set language auto} in this
14487case frees you from having to set the working language manually.
14488
6d2ebf8b 14489@node Show
79a6e687 14490@section Displaying the Language
c906108c
SS
14491
14492The following commands help you find out which language is the
14493working language, and also what language source files were written in.
14494
c906108c
SS
14495@table @code
14496@item show language
403cb6b1 14497@anchor{show language}
9c16f35a 14498@kindex show language
c906108c
SS
14499Display the current working language. This is the
14500language you can use with commands such as @code{print} to
14501build and compute expressions that may involve variables in your program.
14502
14503@item info frame
4644b6e3 14504@kindex info frame@r{, show the source language}
5d161b24 14505Display the source language for this frame. This language becomes the
c906108c 14506working language if you use an identifier from this frame.
79a6e687 14507@xref{Frame Info, ,Information about a Frame}, to identify the other
c906108c
SS
14508information listed here.
14509
14510@item info source
4644b6e3 14511@kindex info source@r{, show the source language}
c906108c 14512Display the source language of this source file.
5d161b24 14513@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
14514information listed here.
14515@end table
14516
14517In unusual circumstances, you may have source files with extensions
14518not in the standard list. You can then set the extension associated
14519with a language explicitly:
14520
c906108c 14521@table @code
09d4efe1 14522@item set extension-language @var{ext} @var{language}
9c16f35a 14523@kindex set extension-language
09d4efe1
EZ
14524Tell @value{GDBN} that source files with extension @var{ext} are to be
14525assumed as written in the source language @var{language}.
c906108c
SS
14526
14527@item info extensions
9c16f35a 14528@kindex info extensions
c906108c
SS
14529List all the filename extensions and the associated languages.
14530@end table
14531
6d2ebf8b 14532@node Checks
79a6e687 14533@section Type and Range Checking
c906108c 14534
c906108c
SS
14535Some languages are designed to guard you against making seemingly common
14536errors through a series of compile- and run-time checks. These include
a451cb65 14537checking the type of arguments to functions and operators and making
c906108c
SS
14538sure mathematical overflows are caught at run time. Checks such as
14539these help to ensure a program's correctness once it has been compiled
a451cb65 14540by eliminating type mismatches and providing active checks for range
c906108c
SS
14541errors when your program is running.
14542
a451cb65
KS
14543By default @value{GDBN} checks for these errors according to the
14544rules of the current source language. Although @value{GDBN} does not check
14545the statements in your program, it can check expressions entered directly
14546into @value{GDBN} for evaluation via the @code{print} command, for example.
c906108c
SS
14547
14548@menu
14549* Type Checking:: An overview of type checking
14550* Range Checking:: An overview of range checking
14551@end menu
14552
14553@cindex type checking
14554@cindex checks, type
6d2ebf8b 14555@node Type Checking
79a6e687 14556@subsection An Overview of Type Checking
c906108c 14557
a451cb65 14558Some languages, such as C and C@t{++}, are strongly typed, meaning that the
c906108c
SS
14559arguments to operators and functions have to be of the correct type,
14560otherwise an error occurs. These checks prevent type mismatch
14561errors from ever causing any run-time problems. For example,
14562
14563@smallexample
a451cb65
KS
14564int klass::my_method(char *b) @{ return b ? 1 : 2; @}
14565
14566(@value{GDBP}) print obj.my_method (0)
14567$1 = 2
c906108c 14568@exdent but
a451cb65
KS
14569(@value{GDBP}) print obj.my_method (0x1234)
14570Cannot resolve method klass::my_method to any overloaded instance
c906108c
SS
14571@end smallexample
14572
a451cb65
KS
14573The second example fails because in C@t{++} the integer constant
14574@samp{0x1234} is not type-compatible with the pointer parameter type.
c906108c 14575
a451cb65
KS
14576For the expressions you use in @value{GDBN} commands, you can tell
14577@value{GDBN} to not enforce strict type checking or
5d161b24 14578to treat any mismatches as errors and abandon the expression;
a451cb65
KS
14579When type checking is disabled, @value{GDBN} successfully evaluates
14580expressions like the second example above.
c906108c 14581
a451cb65 14582Even if type checking is off, there may be other reasons
5d161b24
DB
14583related to type that prevent @value{GDBN} from evaluating an expression.
14584For instance, @value{GDBN} does not know how to add an @code{int} and
14585a @code{struct foo}. These particular type errors have nothing to do
a451cb65
KS
14586with the language in use and usually arise from expressions which make
14587little sense to evaluate anyway.
c906108c 14588
a451cb65 14589@value{GDBN} provides some additional commands for controlling type checking:
c906108c 14590
c906108c
SS
14591@kindex set check type
14592@kindex show check type
14593@table @code
c906108c
SS
14594@item set check type on
14595@itemx set check type off
a451cb65 14596Set strict type checking on or off. If any type mismatches occur in
d4f3574e 14597evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
14598message and aborts evaluation of the expression.
14599
a451cb65
KS
14600@item show check type
14601Show the current setting of type checking and whether @value{GDBN}
14602is enforcing strict type checking rules.
c906108c
SS
14603@end table
14604
14605@cindex range checking
14606@cindex checks, range
6d2ebf8b 14607@node Range Checking
79a6e687 14608@subsection An Overview of Range Checking
c906108c
SS
14609
14610In some languages (such as Modula-2), it is an error to exceed the
14611bounds of a type; this is enforced with run-time checks. Such range
14612checking is meant to ensure program correctness by making sure
14613computations do not overflow, or indices on an array element access do
14614not exceed the bounds of the array.
14615
14616For expressions you use in @value{GDBN} commands, you can tell
14617@value{GDBN} to treat range errors in one of three ways: ignore them,
14618always treat them as errors and abandon the expression, or issue
14619warnings but evaluate the expression anyway.
14620
14621A range error can result from numerical overflow, from exceeding an
14622array index bound, or when you type a constant that is not a member
14623of any type. Some languages, however, do not treat overflows as an
14624error. In many implementations of C, mathematical overflow causes the
14625result to ``wrap around'' to lower values---for example, if @var{m} is
14626the largest integer value, and @var{s} is the smallest, then
14627
474c8240 14628@smallexample
c906108c 14629@var{m} + 1 @result{} @var{s}
474c8240 14630@end smallexample
c906108c
SS
14631
14632This, too, is specific to individual languages, and in some cases
79a6e687
BW
14633specific to individual compilers or machines. @xref{Supported Languages, ,
14634Supported Languages}, for further details on specific languages.
c906108c
SS
14635
14636@value{GDBN} provides some additional commands for controlling the range checker:
14637
c906108c
SS
14638@kindex set check range
14639@kindex show check range
14640@table @code
14641@item set check range auto
14642Set range checking on or off based on the current working language.
79a6e687 14643@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
14644each language.
14645
14646@item set check range on
14647@itemx set check range off
14648Set range checking on or off, overriding the default setting for the
14649current working language. A warning is issued if the setting does not
c3f6f71d
JM
14650match the language default. If a range error occurs and range checking is on,
14651then a message is printed and evaluation of the expression is aborted.
c906108c
SS
14652
14653@item set check range warn
14654Output messages when the @value{GDBN} range checker detects a range error,
14655but attempt to evaluate the expression anyway. Evaluating the
14656expression may still be impossible for other reasons, such as accessing
14657memory that the process does not own (a typical example from many Unix
14658systems).
14659
14660@item show range
14661Show the current setting of the range checker, and whether or not it is
14662being set automatically by @value{GDBN}.
14663@end table
c906108c 14664
79a6e687
BW
14665@node Supported Languages
14666@section Supported Languages
c906108c 14667
9c37b5ae 14668@value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
0bdfa368 14669OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
cce74817 14670@c This is false ...
c906108c
SS
14671Some @value{GDBN} features may be used in expressions regardless of the
14672language you use: the @value{GDBN} @code{@@} and @code{::} operators,
14673and the @samp{@{type@}addr} construct (@pxref{Expressions,
14674,Expressions}) can be used with the constructs of any supported
14675language.
14676
14677The following sections detail to what degree each source language is
14678supported by @value{GDBN}. These sections are not meant to be language
14679tutorials or references, but serve only as a reference guide to what the
14680@value{GDBN} expression parser accepts, and what input and output
14681formats should look like for different languages. There are many good
14682books written on each of these languages; please look to these for a
14683language reference or tutorial.
14684
c906108c 14685@menu
b37303ee 14686* C:: C and C@t{++}
6aecb9c2 14687* D:: D
a766d390 14688* Go:: Go
b383017d 14689* Objective-C:: Objective-C
f4b8a18d 14690* OpenCL C:: OpenCL C
09d4efe1 14691* Fortran:: Fortran
9c16f35a 14692* Pascal:: Pascal
0bdfa368 14693* Rust:: Rust
b37303ee 14694* Modula-2:: Modula-2
e07c999f 14695* Ada:: Ada
c906108c
SS
14696@end menu
14697
6d2ebf8b 14698@node C
b37052ae 14699@subsection C and C@t{++}
7a292a7a 14700
b37052ae
EZ
14701@cindex C and C@t{++}
14702@cindex expressions in C or C@t{++}
c906108c 14703
b37052ae 14704Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
14705to both languages. Whenever this is the case, we discuss those languages
14706together.
14707
41afff9a
EZ
14708@cindex C@t{++}
14709@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
14710@cindex @sc{gnu} C@t{++}
14711The C@t{++} debugging facilities are jointly implemented by the C@t{++}
14712compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
14713effectively, you must compile your C@t{++} programs with a supported
14714C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
14715compiler (@code{aCC}).
14716
c906108c 14717@menu
b37052ae
EZ
14718* C Operators:: C and C@t{++} operators
14719* C Constants:: C and C@t{++} constants
79a6e687 14720* C Plus Plus Expressions:: C@t{++} expressions
b37052ae
EZ
14721* C Defaults:: Default settings for C and C@t{++}
14722* C Checks:: C and C@t{++} type and range checks
c906108c 14723* Debugging C:: @value{GDBN} and C
79a6e687 14724* Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
febe4383 14725* Decimal Floating Point:: Numbers in Decimal Floating Point format
c906108c 14726@end menu
c906108c 14727
6d2ebf8b 14728@node C Operators
79a6e687 14729@subsubsection C and C@t{++} Operators
7a292a7a 14730
b37052ae 14731@cindex C and C@t{++} operators
c906108c
SS
14732
14733Operators must be defined on values of specific types. For instance,
14734@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 14735often defined on groups of types.
c906108c 14736
b37052ae 14737For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
14738
14739@itemize @bullet
53a5351d 14740
c906108c 14741@item
c906108c 14742@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 14743specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
14744
14745@item
d4f3574e
SS
14746@emph{Floating-point types} include @code{float}, @code{double}, and
14747@code{long double} (if supported by the target platform).
c906108c
SS
14748
14749@item
53a5351d 14750@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
14751
14752@item
14753@emph{Scalar types} include all of the above.
53a5351d 14754
c906108c
SS
14755@end itemize
14756
14757@noindent
14758The following operators are supported. They are listed here
14759in order of increasing precedence:
14760
14761@table @code
14762@item ,
14763The comma or sequencing operator. Expressions in a comma-separated list
14764are evaluated from left to right, with the result of the entire
14765expression being the last expression evaluated.
14766
14767@item =
14768Assignment. The value of an assignment expression is the value
14769assigned. Defined on scalar types.
14770
14771@item @var{op}=
14772Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
14773and translated to @w{@code{@var{a} = @var{a op b}}}.
697aa1b7 14774@w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
c906108c
SS
14775@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
14776@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
14777
14778@item ?:
14779The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
697aa1b7
EZ
14780of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
14781should be of an integral type.
c906108c
SS
14782
14783@item ||
14784Logical @sc{or}. Defined on integral types.
14785
14786@item &&
14787Logical @sc{and}. Defined on integral types.
14788
14789@item |
14790Bitwise @sc{or}. Defined on integral types.
14791
14792@item ^
14793Bitwise exclusive-@sc{or}. Defined on integral types.
14794
14795@item &
14796Bitwise @sc{and}. Defined on integral types.
14797
14798@item ==@r{, }!=
14799Equality and inequality. Defined on scalar types. The value of these
14800expressions is 0 for false and non-zero for true.
14801
14802@item <@r{, }>@r{, }<=@r{, }>=
14803Less than, greater than, less than or equal, greater than or equal.
14804Defined on scalar types. The value of these expressions is 0 for false
14805and non-zero for true.
14806
14807@item <<@r{, }>>
14808left shift, and right shift. Defined on integral types.
14809
14810@item @@
14811The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
14812
14813@item +@r{, }-
14814Addition and subtraction. Defined on integral types, floating-point types and
14815pointer types.
14816
14817@item *@r{, }/@r{, }%
14818Multiplication, division, and modulus. Multiplication and division are
14819defined on integral and floating-point types. Modulus is defined on
14820integral types.
14821
14822@item ++@r{, }--
14823Increment and decrement. When appearing before a variable, the
14824operation is performed before the variable is used in an expression;
14825when appearing after it, the variable's value is used before the
14826operation takes place.
14827
14828@item *
14829Pointer dereferencing. Defined on pointer types. Same precedence as
14830@code{++}.
14831
14832@item &
14833Address operator. Defined on variables. Same precedence as @code{++}.
14834
b37052ae
EZ
14835For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
14836allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
b17828ca 14837to examine the address
b37052ae 14838where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 14839stored.
c906108c
SS
14840
14841@item -
14842Negative. Defined on integral and floating-point types. Same
14843precedence as @code{++}.
14844
14845@item !
14846Logical negation. Defined on integral types. Same precedence as
14847@code{++}.
14848
14849@item ~
14850Bitwise complement operator. Defined on integral types. Same precedence as
14851@code{++}.
14852
14853
14854@item .@r{, }->
14855Structure member, and pointer-to-structure member. For convenience,
14856@value{GDBN} regards the two as equivalent, choosing whether to dereference a
14857pointer based on the stored type information.
14858Defined on @code{struct} and @code{union} data.
14859
c906108c
SS
14860@item .*@r{, }->*
14861Dereferences of pointers to members.
c906108c
SS
14862
14863@item []
14864Array indexing. @code{@var{a}[@var{i}]} is defined as
14865@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
14866
14867@item ()
14868Function parameter list. Same precedence as @code{->}.
14869
c906108c 14870@item ::
b37052ae 14871C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 14872and @code{class} types.
c906108c
SS
14873
14874@item ::
7a292a7a
SS
14875Doubled colons also represent the @value{GDBN} scope operator
14876(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
14877above.
c906108c
SS
14878@end table
14879
c906108c
SS
14880If an operator is redefined in the user code, @value{GDBN} usually
14881attempts to invoke the redefined version instead of using the operator's
14882predefined meaning.
c906108c 14883
6d2ebf8b 14884@node C Constants
79a6e687 14885@subsubsection C and C@t{++} Constants
c906108c 14886
b37052ae 14887@cindex C and C@t{++} constants
c906108c 14888
b37052ae 14889@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 14890following ways:
c906108c
SS
14891
14892@itemize @bullet
14893@item
14894Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
14895specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
14896by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
14897@samp{l}, specifying that the constant should be treated as a
14898@code{long} value.
14899
14900@item
14901Floating point constants are a sequence of digits, followed by a decimal
14902point, followed by a sequence of digits, and optionally followed by an
14903exponent. An exponent is of the form:
14904@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
14905sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
14906A floating-point constant may also end with a letter @samp{f} or
14907@samp{F}, specifying that the constant should be treated as being of
14908the @code{float} (as opposed to the default @code{double}) type; or with
14909a letter @samp{l} or @samp{L}, which specifies a @code{long double}
14910constant.
c906108c
SS
14911
14912@item
14913Enumerated constants consist of enumerated identifiers, or their
14914integral equivalents.
14915
14916@item
14917Character constants are a single character surrounded by single quotes
14918(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 14919(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
14920be represented by a letter or by @dfn{escape sequences}, which are of
14921the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
14922of the character's ordinal value; or of the form @samp{\@var{x}}, where
14923@samp{@var{x}} is a predefined special character---for example,
14924@samp{\n} for newline.
14925
e0f8f636
TT
14926Wide character constants can be written by prefixing a character
14927constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
14928form of @samp{x}. The target wide character set is used when
14929computing the value of this constant (@pxref{Character Sets}).
14930
c906108c 14931@item
96a2c332
SS
14932String constants are a sequence of character constants surrounded by
14933double quotes (@code{"}). Any valid character constant (as described
14934above) may appear. Double quotes within the string must be preceded by
14935a backslash, so for instance @samp{"a\"b'c"} is a string of five
14936characters.
c906108c 14937
e0f8f636
TT
14938Wide string constants can be written by prefixing a string constant
14939with @samp{L}, as in C. The target wide character set is used when
14940computing the value of this constant (@pxref{Character Sets}).
14941
c906108c
SS
14942@item
14943Pointer constants are an integral value. You can also write pointers
14944to constants using the C operator @samp{&}.
14945
14946@item
14947Array constants are comma-separated lists surrounded by braces @samp{@{}
14948and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
14949integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
14950and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
14951@end itemize
14952
79a6e687
BW
14953@node C Plus Plus Expressions
14954@subsubsection C@t{++} Expressions
b37052ae
EZ
14955
14956@cindex expressions in C@t{++}
14957@value{GDBN} expression handling can interpret most C@t{++} expressions.
14958
0179ffac
DC
14959@cindex debugging C@t{++} programs
14960@cindex C@t{++} compilers
14961@cindex debug formats and C@t{++}
14962@cindex @value{NGCC} and C@t{++}
c906108c 14963@quotation
e0f8f636
TT
14964@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
14965the proper compiler and the proper debug format. Currently,
14966@value{GDBN} works best when debugging C@t{++} code that is compiled
14967with the most recent version of @value{NGCC} possible. The DWARF
14968debugging format is preferred; @value{NGCC} defaults to this on most
14969popular platforms. Other compilers and/or debug formats are likely to
14970work badly or not at all when using @value{GDBN} to debug C@t{++}
14971code. @xref{Compilation}.
c906108c 14972@end quotation
c906108c
SS
14973
14974@enumerate
14975
14976@cindex member functions
14977@item
14978Member function calls are allowed; you can use expressions like
14979
474c8240 14980@smallexample
c906108c 14981count = aml->GetOriginal(x, y)
474c8240 14982@end smallexample
c906108c 14983
41afff9a 14984@vindex this@r{, inside C@t{++} member functions}
b37052ae 14985@cindex namespace in C@t{++}
c906108c
SS
14986@item
14987While a member function is active (in the selected stack frame), your
14988expressions have the same namespace available as the member function;
14989that is, @value{GDBN} allows implicit references to the class instance
e0f8f636
TT
14990pointer @code{this} following the same rules as C@t{++}. @code{using}
14991declarations in the current scope are also respected by @value{GDBN}.
c906108c 14992
c906108c 14993@cindex call overloaded functions
d4f3574e 14994@cindex overloaded functions, calling
b37052ae 14995@cindex type conversions in C@t{++}
c906108c
SS
14996@item
14997You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 14998call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
14999perform overload resolution involving user-defined type conversions,
15000calls to constructors, or instantiations of templates that do not exist
15001in the program. It also cannot handle ellipsis argument lists or
15002default arguments.
15003
15004It does perform integral conversions and promotions, floating-point
15005promotions, arithmetic conversions, pointer conversions, conversions of
15006class objects to base classes, and standard conversions such as those of
15007functions or arrays to pointers; it requires an exact match on the
15008number of function arguments.
15009
15010Overload resolution is always performed, unless you have specified
79a6e687
BW
15011@code{set overload-resolution off}. @xref{Debugging C Plus Plus,
15012,@value{GDBN} Features for C@t{++}}.
c906108c 15013
d4f3574e 15014You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
15015explicit function signature to call an overloaded function, as in
15016@smallexample
15017p 'foo(char,int)'('x', 13)
15018@end smallexample
d4f3574e 15019
c906108c 15020The @value{GDBN} command-completion facility can simplify this;
79a6e687 15021see @ref{Completion, ,Command Completion}.
c906108c 15022
c906108c
SS
15023@cindex reference declarations
15024@item
c0f55cc6
AV
15025@value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
15026references; you can use them in expressions just as you do in C@t{++}
15027source---they are automatically dereferenced.
c906108c
SS
15028
15029In the parameter list shown when @value{GDBN} displays a frame, the values of
15030reference variables are not displayed (unlike other variables); this
15031avoids clutter, since references are often used for large structures.
15032The @emph{address} of a reference variable is always shown, unless
15033you have specified @samp{set print address off}.
15034
15035@item
b37052ae 15036@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
15037expressions can use it just as expressions in your program do. Since
15038one scope may be defined in another, you can use @code{::} repeatedly if
15039necessary, for example in an expression like
15040@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 15041resolving name scope by reference to source files, in both C and C@t{++}
79a6e687 15042debugging (@pxref{Variables, ,Program Variables}).
c906108c 15043
e0f8f636
TT
15044@item
15045@value{GDBN} performs argument-dependent lookup, following the C@t{++}
15046specification.
15047@end enumerate
c906108c 15048
6d2ebf8b 15049@node C Defaults
79a6e687 15050@subsubsection C and C@t{++} Defaults
7a292a7a 15051
b37052ae 15052@cindex C and C@t{++} defaults
c906108c 15053
a451cb65
KS
15054If you allow @value{GDBN} to set range checking automatically, it
15055defaults to @code{off} whenever the working language changes to
b37052ae 15056C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 15057selects the working language.
c906108c
SS
15058
15059If you allow @value{GDBN} to set the language automatically, it
15060recognizes source files whose names end with @file{.c}, @file{.C}, or
15061@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 15062these files, it sets the working language to C or C@t{++}.
79a6e687 15063@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
c906108c
SS
15064for further details.
15065
6d2ebf8b 15066@node C Checks
79a6e687 15067@subsubsection C and C@t{++} Type and Range Checks
7a292a7a 15068
b37052ae 15069@cindex C and C@t{++} checks
c906108c 15070
a451cb65
KS
15071By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
15072checking is used. However, if you turn type checking off, @value{GDBN}
15073will allow certain non-standard conversions, such as promoting integer
15074constants to pointers.
c906108c
SS
15075
15076Range checking, if turned on, is done on mathematical operations. Array
15077indices are not checked, since they are often used to index a pointer
15078that is not itself an array.
c906108c 15079
6d2ebf8b 15080@node Debugging C
c906108c 15081@subsubsection @value{GDBN} and C
c906108c
SS
15082
15083The @code{set print union} and @code{show print union} commands apply to
15084the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
15085inside a @code{struct} or @code{class} is also printed. Otherwise, it
15086appears as @samp{@{...@}}.
c906108c
SS
15087
15088The @code{@@} operator aids in the debugging of dynamic arrays, formed
15089with pointers and a memory allocation function. @xref{Expressions,
15090,Expressions}.
15091
79a6e687
BW
15092@node Debugging C Plus Plus
15093@subsubsection @value{GDBN} Features for C@t{++}
c906108c 15094
b37052ae 15095@cindex commands for C@t{++}
7a292a7a 15096
b37052ae
EZ
15097Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
15098designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
15099
15100@table @code
15101@cindex break in overloaded functions
15102@item @r{breakpoint menus}
15103When you want a breakpoint in a function whose name is overloaded,
6ba66d6a
JB
15104@value{GDBN} has the capability to display a menu of possible breakpoint
15105locations to help you specify which function definition you want.
15106@xref{Ambiguous Expressions,,Ambiguous Expressions}.
c906108c 15107
b37052ae 15108@cindex overloading in C@t{++}
c906108c
SS
15109@item rbreak @var{regex}
15110Setting breakpoints using regular expressions is helpful for setting
15111breakpoints on overloaded functions that are not members of any special
15112classes.
79a6e687 15113@xref{Set Breaks, ,Setting Breakpoints}.
c906108c 15114
b37052ae 15115@cindex C@t{++} exception handling
c906108c 15116@item catch throw
591f19e8 15117@itemx catch rethrow
c906108c 15118@itemx catch catch
b37052ae 15119Debug C@t{++} exception handling using these commands. @xref{Set
79a6e687 15120Catchpoints, , Setting Catchpoints}.
c906108c
SS
15121
15122@cindex inheritance
15123@item ptype @var{typename}
15124Print inheritance relationships as well as other information for type
15125@var{typename}.
15126@xref{Symbols, ,Examining the Symbol Table}.
15127
c4aeac85
TT
15128@item info vtbl @var{expression}.
15129The @code{info vtbl} command can be used to display the virtual
15130method tables of the object computed by @var{expression}. This shows
15131one entry per virtual table; there may be multiple virtual tables when
15132multiple inheritance is in use.
15133
439250fb
DE
15134@cindex C@t{++} demangling
15135@item demangle @var{name}
15136Demangle @var{name}.
15137@xref{Symbols}, for a more complete description of the @code{demangle} command.
15138
b37052ae 15139@cindex C@t{++} symbol display
c906108c
SS
15140@item set print demangle
15141@itemx show print demangle
15142@itemx set print asm-demangle
15143@itemx show print asm-demangle
b37052ae
EZ
15144Control whether C@t{++} symbols display in their source form, both when
15145displaying code as C@t{++} source and when displaying disassemblies.
79a6e687 15146@xref{Print Settings, ,Print Settings}.
c906108c
SS
15147
15148@item set print object
15149@itemx show print object
15150Choose whether to print derived (actual) or declared types of objects.
79a6e687 15151@xref{Print Settings, ,Print Settings}.
c906108c
SS
15152
15153@item set print vtbl
15154@itemx show print vtbl
15155Control the format for printing virtual function tables.
79a6e687 15156@xref{Print Settings, ,Print Settings}.
c906108c 15157(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 15158ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
15159
15160@kindex set overload-resolution
d4f3574e 15161@cindex overloaded functions, overload resolution
c906108c 15162@item set overload-resolution on
b37052ae 15163Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
15164is on. For overloaded functions, @value{GDBN} evaluates the arguments
15165and searches for a function whose signature matches the argument types,
79a6e687
BW
15166using the standard C@t{++} conversion rules (see @ref{C Plus Plus
15167Expressions, ,C@t{++} Expressions}, for details).
15168If it cannot find a match, it emits a message.
c906108c
SS
15169
15170@item set overload-resolution off
b37052ae 15171Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
15172overloaded functions that are not class member functions, @value{GDBN}
15173chooses the first function of the specified name that it finds in the
15174symbol table, whether or not its arguments are of the correct type. For
15175overloaded functions that are class member functions, @value{GDBN}
15176searches for a function whose signature @emph{exactly} matches the
15177argument types.
c906108c 15178
9c16f35a
EZ
15179@kindex show overload-resolution
15180@item show overload-resolution
15181Show the current setting of overload resolution.
15182
c906108c
SS
15183@item @r{Overloaded symbol names}
15184You can specify a particular definition of an overloaded symbol, using
b37052ae 15185the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
15186@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
15187also use the @value{GDBN} command-line word completion facilities to list the
15188available choices, or to finish the type list for you.
79a6e687 15189@xref{Completion,, Command Completion}, for details on how to do this.
bd69330d
PA
15190
15191@item @r{Breakpoints in functions with ABI tags}
15192
15193The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
15194correspond to changes in the ABI of a type, function, or variable that
15195would not otherwise be reflected in a mangled name. See
15196@url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
15197for more detail.
15198
15199The ABI tags are visible in C@t{++} demangled names. For example, a
15200function that returns a std::string:
15201
15202@smallexample
15203std::string function(int);
15204@end smallexample
15205
15206@noindent
15207when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
15208tag, and @value{GDBN} displays the symbol like this:
15209
15210@smallexample
15211function[abi:cxx11](int)
15212@end smallexample
15213
15214You can set a breakpoint on such functions simply as if they had no
15215tag. For example:
15216
15217@smallexample
15218(gdb) b function(int)
15219Breakpoint 2 at 0x40060d: file main.cc, line 10.
15220(gdb) info breakpoints
15221Num Type Disp Enb Address What
152221 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
15223 at main.cc:10
15224@end smallexample
15225
15226On the rare occasion you need to disambiguate between different ABI
15227tags, you can do so by simply including the ABI tag in the function
15228name, like:
15229
15230@smallexample
15231(@value{GDBP}) b ambiguous[abi:other_tag](int)
15232@end smallexample
c906108c 15233@end table
c906108c 15234
febe4383
TJB
15235@node Decimal Floating Point
15236@subsubsection Decimal Floating Point format
15237@cindex decimal floating point format
15238
15239@value{GDBN} can examine, set and perform computations with numbers in
15240decimal floating point format, which in the C language correspond to the
15241@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
15242specified by the extension to support decimal floating-point arithmetic.
15243
15244There are two encodings in use, depending on the architecture: BID (Binary
15245Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
4ac33720
UW
15246PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
15247configured target.
febe4383
TJB
15248
15249Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
15250to manipulate decimal floating point numbers, it is not possible to convert
15251(using a cast, for example) integers wider than 32-bit to decimal float.
15252
15253In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
15254point computations, error checking in decimal float operations ignores
15255underflow, overflow and divide by zero exceptions.
15256
4acd40f3 15257In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
99e008fe
EZ
15258to inspect @code{_Decimal128} values stored in floating point registers.
15259See @ref{PowerPC,,PowerPC} for more details.
4acd40f3 15260
6aecb9c2
JB
15261@node D
15262@subsection D
15263
15264@cindex D
15265@value{GDBN} can be used to debug programs written in D and compiled with
15266GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
15267specific feature --- dynamic arrays.
15268
a766d390
DE
15269@node Go
15270@subsection Go
15271
15272@cindex Go (programming language)
15273@value{GDBN} can be used to debug programs written in Go and compiled with
15274@file{gccgo} or @file{6g} compilers.
15275
15276Here is a summary of the Go-specific features and restrictions:
15277
15278@table @code
15279@cindex current Go package
15280@item The current Go package
15281The name of the current package does not need to be specified when
15282specifying global variables and functions.
15283
15284For example, given the program:
15285
15286@example
15287package main
15288var myglob = "Shall we?"
15289func main () @{
15290 // ...
15291@}
15292@end example
15293
15294When stopped inside @code{main} either of these work:
15295
15296@example
15297(gdb) p myglob
15298(gdb) p main.myglob
15299@end example
15300
15301@cindex builtin Go types
15302@item Builtin Go types
15303The @code{string} type is recognized by @value{GDBN} and is printed
15304as a string.
15305
15306@cindex builtin Go functions
15307@item Builtin Go functions
15308The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
15309function and handles it internally.
a766d390
DE
15310
15311@cindex restrictions on Go expressions
15312@item Restrictions on Go expressions
15313All Go operators are supported except @code{&^}.
15314The Go @code{_} ``blank identifier'' is not supported.
15315Automatic dereferencing of pointers is not supported.
50f042b9 15316@end table
a766d390 15317
b37303ee
AF
15318@node Objective-C
15319@subsection Objective-C
15320
15321@cindex Objective-C
15322This section provides information about some commands and command
721c2651
EZ
15323options that are useful for debugging Objective-C code. See also
15324@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
15325few more commands specific to Objective-C support.
b37303ee
AF
15326
15327@menu
b383017d
RM
15328* Method Names in Commands::
15329* The Print Command with Objective-C::
b37303ee
AF
15330@end menu
15331
c8f4133a 15332@node Method Names in Commands
b37303ee
AF
15333@subsubsection Method Names in Commands
15334
15335The following commands have been extended to accept Objective-C method
15336names as line specifications:
15337
15338@kindex clear@r{, and Objective-C}
15339@kindex break@r{, and Objective-C}
15340@kindex info line@r{, and Objective-C}
15341@kindex jump@r{, and Objective-C}
15342@kindex list@r{, and Objective-C}
15343@itemize
15344@item @code{clear}
15345@item @code{break}
15346@item @code{info line}
15347@item @code{jump}
15348@item @code{list}
15349@end itemize
15350
15351A fully qualified Objective-C method name is specified as
15352
15353@smallexample
15354-[@var{Class} @var{methodName}]
15355@end smallexample
15356
c552b3bb
JM
15357where the minus sign is used to indicate an instance method and a
15358plus sign (not shown) is used to indicate a class method. The class
15359name @var{Class} and method name @var{methodName} are enclosed in
15360brackets, similar to the way messages are specified in Objective-C
15361source code. For example, to set a breakpoint at the @code{create}
15362instance method of class @code{Fruit} in the program currently being
15363debugged, enter:
b37303ee
AF
15364
15365@smallexample
15366break -[Fruit create]
15367@end smallexample
15368
15369To list ten program lines around the @code{initialize} class method,
15370enter:
15371
15372@smallexample
15373list +[NSText initialize]
15374@end smallexample
15375
c552b3bb
JM
15376In the current version of @value{GDBN}, the plus or minus sign is
15377required. In future versions of @value{GDBN}, the plus or minus
15378sign will be optional, but you can use it to narrow the search. It
15379is also possible to specify just a method name:
b37303ee
AF
15380
15381@smallexample
15382break create
15383@end smallexample
15384
15385You must specify the complete method name, including any colons. If
15386your program's source files contain more than one @code{create} method,
15387you'll be presented with a numbered list of classes that implement that
15388method. Indicate your choice by number, or type @samp{0} to exit if
15389none apply.
15390
15391As another example, to clear a breakpoint established at the
15392@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
15393
15394@smallexample
15395clear -[NSWindow makeKeyAndOrderFront:]
15396@end smallexample
15397
15398@node The Print Command with Objective-C
15399@subsubsection The Print Command With Objective-C
721c2651 15400@cindex Objective-C, print objects
c552b3bb
JM
15401@kindex print-object
15402@kindex po @r{(@code{print-object})}
b37303ee 15403
c552b3bb 15404The print command has also been extended to accept methods. For example:
b37303ee
AF
15405
15406@smallexample
c552b3bb 15407print -[@var{object} hash]
b37303ee
AF
15408@end smallexample
15409
15410@cindex print an Objective-C object description
c552b3bb
JM
15411@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
15412@noindent
15413will tell @value{GDBN} to send the @code{hash} message to @var{object}
15414and print the result. Also, an additional command has been added,
15415@code{print-object} or @code{po} for short, which is meant to print
15416the description of an object. However, this command may only work
15417with certain Objective-C libraries that have a particular hook
15418function, @code{_NSPrintForDebugger}, defined.
b37303ee 15419
f4b8a18d
KW
15420@node OpenCL C
15421@subsection OpenCL C
15422
15423@cindex OpenCL C
15424This section provides information about @value{GDBN}s OpenCL C support.
15425
15426@menu
15427* OpenCL C Datatypes::
15428* OpenCL C Expressions::
15429* OpenCL C Operators::
15430@end menu
15431
15432@node OpenCL C Datatypes
15433@subsubsection OpenCL C Datatypes
15434
15435@cindex OpenCL C Datatypes
15436@value{GDBN} supports the builtin scalar and vector datatypes specified
15437by OpenCL 1.1. In addition the half- and double-precision floating point
15438data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
15439extensions are also known to @value{GDBN}.
15440
15441@node OpenCL C Expressions
15442@subsubsection OpenCL C Expressions
15443
15444@cindex OpenCL C Expressions
15445@value{GDBN} supports accesses to vector components including the access as
15446lvalue where possible. Since OpenCL C is based on C99 most C expressions
15447supported by @value{GDBN} can be used as well.
15448
15449@node OpenCL C Operators
15450@subsubsection OpenCL C Operators
15451
15452@cindex OpenCL C Operators
15453@value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
15454vector data types.
15455
09d4efe1
EZ
15456@node Fortran
15457@subsection Fortran
15458@cindex Fortran-specific support in @value{GDBN}
15459
814e32d7
WZ
15460@value{GDBN} can be used to debug programs written in Fortran, but it
15461currently supports only the features of Fortran 77 language.
15462
15463@cindex trailing underscore, in Fortran symbols
15464Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
15465among them) append an underscore to the names of variables and
15466functions. When you debug programs compiled by those compilers, you
15467will need to refer to variables and functions with a trailing
15468underscore.
15469
15470@menu
15471* Fortran Operators:: Fortran operators and expressions
15472* Fortran Defaults:: Default settings for Fortran
79a6e687 15473* Special Fortran Commands:: Special @value{GDBN} commands for Fortran
814e32d7
WZ
15474@end menu
15475
15476@node Fortran Operators
79a6e687 15477@subsubsection Fortran Operators and Expressions
814e32d7
WZ
15478
15479@cindex Fortran operators and expressions
15480
15481Operators must be defined on values of specific types. For instance,
15482@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 15483arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
15484
15485@table @code
15486@item **
99e008fe 15487The exponentiation operator. It raises the first operand to the power
814e32d7
WZ
15488of the second one.
15489
15490@item :
15491The range operator. Normally used in the form of array(low:high) to
15492represent a section of array.
68837c9d
MD
15493
15494@item %
15495The access component operator. Normally used to access elements in derived
15496types. Also suitable for unions. As unions aren't part of regular Fortran,
15497this can only happen when accessing a register that uses a gdbarch-defined
15498union type.
814e32d7
WZ
15499@end table
15500
15501@node Fortran Defaults
15502@subsubsection Fortran Defaults
15503
15504@cindex Fortran Defaults
15505
15506Fortran symbols are usually case-insensitive, so @value{GDBN} by
15507default uses case-insensitive matches for Fortran symbols. You can
15508change that with the @samp{set case-insensitive} command, see
15509@ref{Symbols}, for the details.
15510
79a6e687
BW
15511@node Special Fortran Commands
15512@subsubsection Special Fortran Commands
814e32d7
WZ
15513
15514@cindex Special Fortran commands
15515
db2e3e2e
BW
15516@value{GDBN} has some commands to support Fortran-specific features,
15517such as displaying common blocks.
814e32d7 15518
09d4efe1
EZ
15519@table @code
15520@cindex @code{COMMON} blocks, Fortran
15521@kindex info common
15522@item info common @r{[}@var{common-name}@r{]}
15523This command prints the values contained in the Fortran @code{COMMON}
15524block whose name is @var{common-name}. With no argument, the names of
d52fb0e9 15525all @code{COMMON} blocks visible at the current program location are
09d4efe1
EZ
15526printed.
15527@end table
15528
9c16f35a
EZ
15529@node Pascal
15530@subsection Pascal
15531
15532@cindex Pascal support in @value{GDBN}, limitations
15533Debugging Pascal programs which use sets, subranges, file variables, or
15534nested functions does not currently work. @value{GDBN} does not support
15535entering expressions, printing values, or similar features using Pascal
15536syntax.
15537
15538The Pascal-specific command @code{set print pascal_static-members}
15539controls whether static members of Pascal objects are displayed.
15540@xref{Print Settings, pascal_static-members}.
15541
0bdfa368
TT
15542@node Rust
15543@subsection Rust
15544
15545@value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
15546Programming Language}. Type- and value-printing, and expression
15547parsing, are reasonably complete. However, there are a few
15548peculiarities and holes to be aware of.
15549
15550@itemize @bullet
15551@item
15552Linespecs (@pxref{Specify Location}) are never relative to the current
15553crate. Instead, they act as if there were a global namespace of
15554crates, somewhat similar to the way @code{extern crate} behaves.
15555
15556That is, if @value{GDBN} is stopped at a breakpoint in a function in
15557crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
15558to set a breakpoint in a function named @samp{f} in a crate named
15559@samp{B}.
15560
15561As a consequence of this approach, linespecs also cannot refer to
15562items using @samp{self::} or @samp{super::}.
15563
15564@item
15565Because @value{GDBN} implements Rust name-lookup semantics in
15566expressions, it will sometimes prepend the current crate to a name.
15567For example, if @value{GDBN} is stopped at a breakpoint in the crate
15568@samp{K}, then @code{print ::x::y} will try to find the symbol
15569@samp{K::x::y}.
15570
15571However, since it is useful to be able to refer to other crates when
15572debugging, @value{GDBN} provides the @code{extern} extension to
15573circumvent this. To use the extension, just put @code{extern} before
15574a path expression to refer to the otherwise unavailable ``global''
15575scope.
15576
15577In the above example, if you wanted to refer to the symbol @samp{y} in
15578the crate @samp{x}, you would use @code{print extern x::y}.
15579
15580@item
15581The Rust expression evaluator does not support ``statement-like''
15582expressions such as @code{if} or @code{match}, or lambda expressions.
15583
15584@item
15585Tuple expressions are not implemented.
15586
15587@item
15588The Rust expression evaluator does not currently implement the
15589@code{Drop} trait. Objects that may be created by the evaluator will
15590never be destroyed.
15591
15592@item
15593@value{GDBN} does not implement type inference for generics. In order
15594to call generic functions or otherwise refer to generic items, you
15595will have to specify the type parameters manually.
15596
15597@item
15598@value{GDBN} currently uses the C@t{++} demangler for Rust. In most
15599cases this does not cause any problems. However, in an expression
15600context, completing a generic function name will give syntactically
15601invalid results. This happens because Rust requires the @samp{::}
15602operator between the function name and its generic arguments. For
15603example, @value{GDBN} might provide a completion like
15604@code{crate::f<u32>}, where the parser would require
15605@code{crate::f::<u32>}.
15606
15607@item
15608As of this writing, the Rust compiler (version 1.8) has a few holes in
15609the debugging information it generates. These holes prevent certain
15610features from being implemented by @value{GDBN}:
15611@itemize @bullet
15612
15613@item
15614Method calls cannot be made via traits.
15615
0bdfa368
TT
15616@item
15617Operator overloading is not implemented.
15618
15619@item
15620When debugging in a monomorphized function, you cannot use the generic
15621type names.
15622
15623@item
15624The type @code{Self} is not available.
15625
15626@item
15627@code{use} statements are not available, so some names may not be
15628available in the crate.
15629@end itemize
15630@end itemize
15631
09d4efe1 15632@node Modula-2
c906108c 15633@subsection Modula-2
7a292a7a 15634
d4f3574e 15635@cindex Modula-2, @value{GDBN} support
c906108c
SS
15636
15637The extensions made to @value{GDBN} to support Modula-2 only support
15638output from the @sc{gnu} Modula-2 compiler (which is currently being
15639developed). Other Modula-2 compilers are not currently supported, and
15640attempting to debug executables produced by them is most likely
15641to give an error as @value{GDBN} reads in the executable's symbol
15642table.
15643
15644@cindex expressions in Modula-2
15645@menu
15646* M2 Operators:: Built-in operators
15647* Built-In Func/Proc:: Built-in functions and procedures
15648* M2 Constants:: Modula-2 constants
72019c9c 15649* M2 Types:: Modula-2 types
c906108c
SS
15650* M2 Defaults:: Default settings for Modula-2
15651* Deviations:: Deviations from standard Modula-2
15652* M2 Checks:: Modula-2 type and range checks
15653* M2 Scope:: The scope operators @code{::} and @code{.}
15654* GDB/M2:: @value{GDBN} and Modula-2
15655@end menu
15656
6d2ebf8b 15657@node M2 Operators
c906108c
SS
15658@subsubsection Operators
15659@cindex Modula-2 operators
15660
15661Operators must be defined on values of specific types. For instance,
15662@code{+} is defined on numbers, but not on structures. Operators are
15663often defined on groups of types. For the purposes of Modula-2, the
15664following definitions hold:
15665
15666@itemize @bullet
15667
15668@item
15669@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
15670their subranges.
15671
15672@item
15673@emph{Character types} consist of @code{CHAR} and its subranges.
15674
15675@item
15676@emph{Floating-point types} consist of @code{REAL}.
15677
15678@item
15679@emph{Pointer types} consist of anything declared as @code{POINTER TO
15680@var{type}}.
15681
15682@item
15683@emph{Scalar types} consist of all of the above.
15684
15685@item
15686@emph{Set types} consist of @code{SET} and @code{BITSET} types.
15687
15688@item
15689@emph{Boolean types} consist of @code{BOOLEAN}.
15690@end itemize
15691
15692@noindent
15693The following operators are supported, and appear in order of
15694increasing precedence:
15695
15696@table @code
15697@item ,
15698Function argument or array index separator.
15699
15700@item :=
15701Assignment. The value of @var{var} @code{:=} @var{value} is
15702@var{value}.
15703
15704@item <@r{, }>
15705Less than, greater than on integral, floating-point, or enumerated
15706types.
15707
15708@item <=@r{, }>=
96a2c332 15709Less than or equal to, greater than or equal to
c906108c
SS
15710on integral, floating-point and enumerated types, or set inclusion on
15711set types. Same precedence as @code{<}.
15712
15713@item =@r{, }<>@r{, }#
15714Equality and two ways of expressing inequality, valid on scalar types.
15715Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
15716available for inequality, since @code{#} conflicts with the script
15717comment character.
15718
15719@item IN
15720Set membership. Defined on set types and the types of their members.
15721Same precedence as @code{<}.
15722
15723@item OR
15724Boolean disjunction. Defined on boolean types.
15725
15726@item AND@r{, }&
d4f3574e 15727Boolean conjunction. Defined on boolean types.
c906108c
SS
15728
15729@item @@
15730The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
15731
15732@item +@r{, }-
15733Addition and subtraction on integral and floating-point types, or union
15734and difference on set types.
15735
15736@item *
15737Multiplication on integral and floating-point types, or set intersection
15738on set types.
15739
15740@item /
15741Division on floating-point types, or symmetric set difference on set
15742types. Same precedence as @code{*}.
15743
15744@item DIV@r{, }MOD
15745Integer division and remainder. Defined on integral types. Same
15746precedence as @code{*}.
15747
15748@item -
99e008fe 15749Negative. Defined on @code{INTEGER} and @code{REAL} data.
c906108c
SS
15750
15751@item ^
15752Pointer dereferencing. Defined on pointer types.
15753
15754@item NOT
15755Boolean negation. Defined on boolean types. Same precedence as
15756@code{^}.
15757
15758@item .
15759@code{RECORD} field selector. Defined on @code{RECORD} data. Same
15760precedence as @code{^}.
15761
15762@item []
15763Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
15764
15765@item ()
15766Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
15767as @code{^}.
15768
15769@item ::@r{, }.
15770@value{GDBN} and Modula-2 scope operators.
15771@end table
15772
15773@quotation
72019c9c 15774@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
15775treats the use of the operator @code{IN}, or the use of operators
15776@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
15777@code{<=}, and @code{>=} on sets as an error.
15778@end quotation
15779
cb51c4e0 15780
6d2ebf8b 15781@node Built-In Func/Proc
79a6e687 15782@subsubsection Built-in Functions and Procedures
cb51c4e0 15783@cindex Modula-2 built-ins
c906108c
SS
15784
15785Modula-2 also makes available several built-in procedures and functions.
15786In describing these, the following metavariables are used:
15787
15788@table @var
15789
15790@item a
15791represents an @code{ARRAY} variable.
15792
15793@item c
15794represents a @code{CHAR} constant or variable.
15795
15796@item i
15797represents a variable or constant of integral type.
15798
15799@item m
15800represents an identifier that belongs to a set. Generally used in the
15801same function with the metavariable @var{s}. The type of @var{s} should
15802be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
15803
15804@item n
15805represents a variable or constant of integral or floating-point type.
15806
15807@item r
15808represents a variable or constant of floating-point type.
15809
15810@item t
15811represents a type.
15812
15813@item v
15814represents a variable.
15815
15816@item x
15817represents a variable or constant of one of many types. See the
15818explanation of the function for details.
15819@end table
15820
15821All Modula-2 built-in procedures also return a result, described below.
15822
15823@table @code
15824@item ABS(@var{n})
15825Returns the absolute value of @var{n}.
15826
15827@item CAP(@var{c})
15828If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 15829equivalent, otherwise it returns its argument.
c906108c
SS
15830
15831@item CHR(@var{i})
15832Returns the character whose ordinal value is @var{i}.
15833
15834@item DEC(@var{v})
c3f6f71d 15835Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
15836
15837@item DEC(@var{v},@var{i})
15838Decrements the value in the variable @var{v} by @var{i}. Returns the
15839new value.
15840
15841@item EXCL(@var{m},@var{s})
15842Removes the element @var{m} from the set @var{s}. Returns the new
15843set.
15844
15845@item FLOAT(@var{i})
15846Returns the floating point equivalent of the integer @var{i}.
15847
15848@item HIGH(@var{a})
15849Returns the index of the last member of @var{a}.
15850
15851@item INC(@var{v})
c3f6f71d 15852Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
15853
15854@item INC(@var{v},@var{i})
15855Increments the value in the variable @var{v} by @var{i}. Returns the
15856new value.
15857
15858@item INCL(@var{m},@var{s})
15859Adds the element @var{m} to the set @var{s} if it is not already
15860there. Returns the new set.
15861
15862@item MAX(@var{t})
15863Returns the maximum value of the type @var{t}.
15864
15865@item MIN(@var{t})
15866Returns the minimum value of the type @var{t}.
15867
15868@item ODD(@var{i})
15869Returns boolean TRUE if @var{i} is an odd number.
15870
15871@item ORD(@var{x})
15872Returns the ordinal value of its argument. For example, the ordinal
697aa1b7
EZ
15873value of a character is its @sc{ascii} value (on machines supporting
15874the @sc{ascii} character set). The argument @var{x} must be of an
15875ordered type, which include integral, character and enumerated types.
c906108c
SS
15876
15877@item SIZE(@var{x})
697aa1b7
EZ
15878Returns the size of its argument. The argument @var{x} can be a
15879variable or a type.
c906108c
SS
15880
15881@item TRUNC(@var{r})
15882Returns the integral part of @var{r}.
15883
844781a1 15884@item TSIZE(@var{x})
697aa1b7
EZ
15885Returns the size of its argument. The argument @var{x} can be a
15886variable or a type.
844781a1 15887
c906108c
SS
15888@item VAL(@var{t},@var{i})
15889Returns the member of the type @var{t} whose ordinal value is @var{i}.
15890@end table
15891
15892@quotation
15893@emph{Warning:} Sets and their operations are not yet supported, so
15894@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
15895an error.
15896@end quotation
15897
15898@cindex Modula-2 constants
6d2ebf8b 15899@node M2 Constants
c906108c
SS
15900@subsubsection Constants
15901
15902@value{GDBN} allows you to express the constants of Modula-2 in the following
15903ways:
15904
15905@itemize @bullet
15906
15907@item
15908Integer constants are simply a sequence of digits. When used in an
15909expression, a constant is interpreted to be type-compatible with the
15910rest of the expression. Hexadecimal integers are specified by a
15911trailing @samp{H}, and octal integers by a trailing @samp{B}.
15912
15913@item
15914Floating point constants appear as a sequence of digits, followed by a
15915decimal point and another sequence of digits. An optional exponent can
15916then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
15917@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
15918digits of the floating point constant must be valid decimal (base 10)
15919digits.
15920
15921@item
15922Character constants consist of a single character enclosed by a pair of
15923like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 15924also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
15925followed by a @samp{C}.
15926
15927@item
15928String constants consist of a sequence of characters enclosed by a
15929pair of like quotes, either single (@code{'}) or double (@code{"}).
15930Escape sequences in the style of C are also allowed. @xref{C
79a6e687 15931Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
c906108c
SS
15932sequences.
15933
15934@item
15935Enumerated constants consist of an enumerated identifier.
15936
15937@item
15938Boolean constants consist of the identifiers @code{TRUE} and
15939@code{FALSE}.
15940
15941@item
15942Pointer constants consist of integral values only.
15943
15944@item
15945Set constants are not yet supported.
15946@end itemize
15947
72019c9c
GM
15948@node M2 Types
15949@subsubsection Modula-2 Types
15950@cindex Modula-2 types
15951
15952Currently @value{GDBN} can print the following data types in Modula-2
15953syntax: array types, record types, set types, pointer types, procedure
15954types, enumerated types, subrange types and base types. You can also
15955print the contents of variables declared using these type.
15956This section gives a number of simple source code examples together with
15957sample @value{GDBN} sessions.
15958
15959The first example contains the following section of code:
15960
15961@smallexample
15962VAR
15963 s: SET OF CHAR ;
15964 r: [20..40] ;
15965@end smallexample
15966
15967@noindent
15968and you can request @value{GDBN} to interrogate the type and value of
15969@code{r} and @code{s}.
15970
15971@smallexample
15972(@value{GDBP}) print s
15973@{'A'..'C', 'Z'@}
15974(@value{GDBP}) ptype s
15975SET OF CHAR
15976(@value{GDBP}) print r
1597721
15978(@value{GDBP}) ptype r
15979[20..40]
15980@end smallexample
15981
15982@noindent
15983Likewise if your source code declares @code{s} as:
15984
15985@smallexample
15986VAR
15987 s: SET ['A'..'Z'] ;
15988@end smallexample
15989
15990@noindent
15991then you may query the type of @code{s} by:
15992
15993@smallexample
15994(@value{GDBP}) ptype s
15995type = SET ['A'..'Z']
15996@end smallexample
15997
15998@noindent
15999Note that at present you cannot interactively manipulate set
16000expressions using the debugger.
16001
16002The following example shows how you might declare an array in Modula-2
16003and how you can interact with @value{GDBN} to print its type and contents:
16004
16005@smallexample
16006VAR
16007 s: ARRAY [-10..10] OF CHAR ;
16008@end smallexample
16009
16010@smallexample
16011(@value{GDBP}) ptype s
16012ARRAY [-10..10] OF CHAR
16013@end smallexample
16014
16015Note that the array handling is not yet complete and although the type
16016is printed correctly, expression handling still assumes that all
16017arrays have a lower bound of zero and not @code{-10} as in the example
844781a1 16018above.
72019c9c
GM
16019
16020Here are some more type related Modula-2 examples:
16021
16022@smallexample
16023TYPE
16024 colour = (blue, red, yellow, green) ;
16025 t = [blue..yellow] ;
16026VAR
16027 s: t ;
16028BEGIN
16029 s := blue ;
16030@end smallexample
16031
16032@noindent
16033The @value{GDBN} interaction shows how you can query the data type
16034and value of a variable.
16035
16036@smallexample
16037(@value{GDBP}) print s
16038$1 = blue
16039(@value{GDBP}) ptype t
16040type = [blue..yellow]
16041@end smallexample
16042
16043@noindent
16044In this example a Modula-2 array is declared and its contents
16045displayed. Observe that the contents are written in the same way as
16046their @code{C} counterparts.
16047
16048@smallexample
16049VAR
16050 s: ARRAY [1..5] OF CARDINAL ;
16051BEGIN
16052 s[1] := 1 ;
16053@end smallexample
16054
16055@smallexample
16056(@value{GDBP}) print s
16057$1 = @{1, 0, 0, 0, 0@}
16058(@value{GDBP}) ptype s
16059type = ARRAY [1..5] OF CARDINAL
16060@end smallexample
16061
16062The Modula-2 language interface to @value{GDBN} also understands
16063pointer types as shown in this example:
16064
16065@smallexample
16066VAR
16067 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
16068BEGIN
16069 NEW(s) ;
16070 s^[1] := 1 ;
16071@end smallexample
16072
16073@noindent
16074and you can request that @value{GDBN} describes the type of @code{s}.
16075
16076@smallexample
16077(@value{GDBP}) ptype s
16078type = POINTER TO ARRAY [1..5] OF CARDINAL
16079@end smallexample
16080
16081@value{GDBN} handles compound types as we can see in this example.
16082Here we combine array types, record types, pointer types and subrange
16083types:
16084
16085@smallexample
16086TYPE
16087 foo = RECORD
16088 f1: CARDINAL ;
16089 f2: CHAR ;
16090 f3: myarray ;
16091 END ;
16092
16093 myarray = ARRAY myrange OF CARDINAL ;
16094 myrange = [-2..2] ;
16095VAR
16096 s: POINTER TO ARRAY myrange OF foo ;
16097@end smallexample
16098
16099@noindent
16100and you can ask @value{GDBN} to describe the type of @code{s} as shown
16101below.
16102
16103@smallexample
16104(@value{GDBP}) ptype s
16105type = POINTER TO ARRAY [-2..2] OF foo = RECORD
16106 f1 : CARDINAL;
16107 f2 : CHAR;
16108 f3 : ARRAY [-2..2] OF CARDINAL;
16109END
16110@end smallexample
16111
6d2ebf8b 16112@node M2 Defaults
79a6e687 16113@subsubsection Modula-2 Defaults
c906108c
SS
16114@cindex Modula-2 defaults
16115
16116If type and range checking are set automatically by @value{GDBN}, they
16117both default to @code{on} whenever the working language changes to
d4f3574e 16118Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
16119selected the working language.
16120
16121If you allow @value{GDBN} to set the language automatically, then entering
16122code compiled from a file whose name ends with @file{.mod} sets the
79a6e687
BW
16123working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
16124Infer the Source Language}, for further details.
c906108c 16125
6d2ebf8b 16126@node Deviations
79a6e687 16127@subsubsection Deviations from Standard Modula-2
c906108c
SS
16128@cindex Modula-2, deviations from
16129
16130A few changes have been made to make Modula-2 programs easier to debug.
16131This is done primarily via loosening its type strictness:
16132
16133@itemize @bullet
16134@item
16135Unlike in standard Modula-2, pointer constants can be formed by
16136integers. This allows you to modify pointer variables during
16137debugging. (In standard Modula-2, the actual address contained in a
16138pointer variable is hidden from you; it can only be modified
16139through direct assignment to another pointer variable or expression that
16140returned a pointer.)
16141
16142@item
16143C escape sequences can be used in strings and characters to represent
16144non-printable characters. @value{GDBN} prints out strings with these
16145escape sequences embedded. Single non-printable characters are
16146printed using the @samp{CHR(@var{nnn})} format.
16147
16148@item
16149The assignment operator (@code{:=}) returns the value of its right-hand
16150argument.
16151
16152@item
16153All built-in procedures both modify @emph{and} return their argument.
16154@end itemize
16155
6d2ebf8b 16156@node M2 Checks
79a6e687 16157@subsubsection Modula-2 Type and Range Checks
c906108c
SS
16158@cindex Modula-2 checks
16159
16160@quotation
16161@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
16162range checking.
16163@end quotation
16164@c FIXME remove warning when type/range checks added
16165
16166@value{GDBN} considers two Modula-2 variables type equivalent if:
16167
16168@itemize @bullet
16169@item
16170They are of types that have been declared equivalent via a @code{TYPE
16171@var{t1} = @var{t2}} statement
16172
16173@item
16174They have been declared on the same line. (Note: This is true of the
16175@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
16176@end itemize
16177
16178As long as type checking is enabled, any attempt to combine variables
16179whose types are not equivalent is an error.
16180
16181Range checking is done on all mathematical operations, assignment, array
16182index bounds, and all built-in functions and procedures.
16183
6d2ebf8b 16184@node M2 Scope
79a6e687 16185@subsubsection The Scope Operators @code{::} and @code{.}
c906108c 16186@cindex scope
41afff9a 16187@cindex @code{.}, Modula-2 scope operator
c906108c
SS
16188@cindex colon, doubled as scope operator
16189@ifinfo
41afff9a 16190@vindex colon-colon@r{, in Modula-2}
c906108c
SS
16191@c Info cannot handle :: but TeX can.
16192@end ifinfo
a67ec3f4 16193@ifnotinfo
41afff9a 16194@vindex ::@r{, in Modula-2}
a67ec3f4 16195@end ifnotinfo
c906108c
SS
16196
16197There are a few subtle differences between the Modula-2 scope operator
16198(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
16199similar syntax:
16200
474c8240 16201@smallexample
c906108c
SS
16202
16203@var{module} . @var{id}
16204@var{scope} :: @var{id}
474c8240 16205@end smallexample
c906108c
SS
16206
16207@noindent
16208where @var{scope} is the name of a module or a procedure,
16209@var{module} the name of a module, and @var{id} is any declared
16210identifier within your program, except another module.
16211
16212Using the @code{::} operator makes @value{GDBN} search the scope
16213specified by @var{scope} for the identifier @var{id}. If it is not
16214found in the specified scope, then @value{GDBN} searches all scopes
16215enclosing the one specified by @var{scope}.
16216
16217Using the @code{.} operator makes @value{GDBN} search the current scope for
16218the identifier specified by @var{id} that was imported from the
16219definition module specified by @var{module}. With this operator, it is
16220an error if the identifier @var{id} was not imported from definition
16221module @var{module}, or if @var{id} is not an identifier in
16222@var{module}.
16223
6d2ebf8b 16224@node GDB/M2
c906108c
SS
16225@subsubsection @value{GDBN} and Modula-2
16226
16227Some @value{GDBN} commands have little use when debugging Modula-2 programs.
16228Five subcommands of @code{set print} and @code{show print} apply
b37052ae 16229specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 16230@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 16231apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
16232analogue in Modula-2.
16233
16234The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 16235with any language, is not useful with Modula-2. Its
c906108c 16236intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 16237created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 16238address can be specified by an integral constant, the construct
d4f3574e 16239@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
16240
16241@cindex @code{#} in Modula-2
16242In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
16243interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 16244
e07c999f
PH
16245@node Ada
16246@subsection Ada
16247@cindex Ada
16248
16249The extensions made to @value{GDBN} for Ada only support
16250output from the @sc{gnu} Ada (GNAT) compiler.
16251Other Ada compilers are not currently supported, and
16252attempting to debug executables produced by them is most likely
16253to be difficult.
16254
16255
16256@cindex expressions in Ada
16257@menu
16258* Ada Mode Intro:: General remarks on the Ada syntax
16259 and semantics supported by Ada mode
16260 in @value{GDBN}.
16261* Omissions from Ada:: Restrictions on the Ada expression syntax.
16262* Additions to Ada:: Extensions of the Ada expression syntax.
3685b09f
PMR
16263* Overloading support for Ada:: Support for expressions involving overloaded
16264 subprograms.
e07c999f 16265* Stopping Before Main Program:: Debugging the program during elaboration.
58d06528 16266* Ada Exceptions:: Ada Exceptions
20924a55
JB
16267* Ada Tasks:: Listing and setting breakpoints in tasks.
16268* Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
6e1bb179
JB
16269* Ravenscar Profile:: Tasking Support when using the Ravenscar
16270 Profile
e07c999f
PH
16271* Ada Glitches:: Known peculiarities of Ada mode.
16272@end menu
16273
16274@node Ada Mode Intro
16275@subsubsection Introduction
16276@cindex Ada mode, general
16277
16278The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
16279syntax, with some extensions.
16280The philosophy behind the design of this subset is
16281
16282@itemize @bullet
16283@item
16284That @value{GDBN} should provide basic literals and access to operations for
16285arithmetic, dereferencing, field selection, indexing, and subprogram calls,
16286leaving more sophisticated computations to subprograms written into the
16287program (which therefore may be called from @value{GDBN}).
16288
16289@item
16290That type safety and strict adherence to Ada language restrictions
16291are not particularly important to the @value{GDBN} user.
16292
16293@item
16294That brevity is important to the @value{GDBN} user.
16295@end itemize
16296
f3a2dd1a
JB
16297Thus, for brevity, the debugger acts as if all names declared in
16298user-written packages are directly visible, even if they are not visible
16299according to Ada rules, thus making it unnecessary to fully qualify most
16300names with their packages, regardless of context. Where this causes
16301ambiguity, @value{GDBN} asks the user's intent.
e07c999f
PH
16302
16303The debugger will start in Ada mode if it detects an Ada main program.
16304As for other languages, it will enter Ada mode when stopped in a program that
16305was translated from an Ada source file.
16306
16307While in Ada mode, you may use `@t{--}' for comments. This is useful
16308mostly for documenting command files. The standard @value{GDBN} comment
16309(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
16310middle (to allow based literals).
16311
e07c999f
PH
16312@node Omissions from Ada
16313@subsubsection Omissions from Ada
16314@cindex Ada, omissions from
16315
16316Here are the notable omissions from the subset:
16317
16318@itemize @bullet
16319@item
16320Only a subset of the attributes are supported:
16321
16322@itemize @minus
16323@item
16324@t{'First}, @t{'Last}, and @t{'Length}
16325 on array objects (not on types and subtypes).
16326
16327@item
16328@t{'Min} and @t{'Max}.
16329
16330@item
16331@t{'Pos} and @t{'Val}.
16332
16333@item
16334@t{'Tag}.
16335
16336@item
16337@t{'Range} on array objects (not subtypes), but only as the right
16338operand of the membership (@code{in}) operator.
16339
16340@item
16341@t{'Access}, @t{'Unchecked_Access}, and
16342@t{'Unrestricted_Access} (a GNAT extension).
16343
16344@item
16345@t{'Address}.
16346@end itemize
16347
16348@item
16349The names in
16350@code{Characters.Latin_1} are not available and
16351concatenation is not implemented. Thus, escape characters in strings are
16352not currently available.
16353
16354@item
16355Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
16356equality of representations. They will generally work correctly
16357for strings and arrays whose elements have integer or enumeration types.
16358They may not work correctly for arrays whose element
16359types have user-defined equality, for arrays of real values
16360(in particular, IEEE-conformant floating point, because of negative
16361zeroes and NaNs), and for arrays whose elements contain unused bits with
16362indeterminate values.
16363
16364@item
16365The other component-by-component array operations (@code{and}, @code{or},
16366@code{xor}, @code{not}, and relational tests other than equality)
16367are not implemented.
16368
16369@item
860701dc
PH
16370@cindex array aggregates (Ada)
16371@cindex record aggregates (Ada)
16372@cindex aggregates (Ada)
16373There is limited support for array and record aggregates. They are
16374permitted only on the right sides of assignments, as in these examples:
16375
16376@smallexample
077e0a52
JB
16377(@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
16378(@value{GDBP}) set An_Array := (1, others => 0)
16379(@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
16380(@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
16381(@value{GDBP}) set A_Record := (1, "Peter", True);
16382(@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
860701dc
PH
16383@end smallexample
16384
16385Changing a
16386discriminant's value by assigning an aggregate has an
16387undefined effect if that discriminant is used within the record.
16388However, you can first modify discriminants by directly assigning to
16389them (which normally would not be allowed in Ada), and then performing an
16390aggregate assignment. For example, given a variable @code{A_Rec}
16391declared to have a type such as:
16392
16393@smallexample
16394type Rec (Len : Small_Integer := 0) is record
16395 Id : Integer;
16396 Vals : IntArray (1 .. Len);
16397end record;
16398@end smallexample
16399
16400you can assign a value with a different size of @code{Vals} with two
16401assignments:
16402
16403@smallexample
077e0a52
JB
16404(@value{GDBP}) set A_Rec.Len := 4
16405(@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
860701dc
PH
16406@end smallexample
16407
16408As this example also illustrates, @value{GDBN} is very loose about the usual
16409rules concerning aggregates. You may leave out some of the
16410components of an array or record aggregate (such as the @code{Len}
16411component in the assignment to @code{A_Rec} above); they will retain their
16412original values upon assignment. You may freely use dynamic values as
16413indices in component associations. You may even use overlapping or
16414redundant component associations, although which component values are
16415assigned in such cases is not defined.
e07c999f
PH
16416
16417@item
16418Calls to dispatching subprograms are not implemented.
16419
16420@item
16421The overloading algorithm is much more limited (i.e., less selective)
ae21e955
BW
16422than that of real Ada. It makes only limited use of the context in
16423which a subexpression appears to resolve its meaning, and it is much
16424looser in its rules for allowing type matches. As a result, some
16425function calls will be ambiguous, and the user will be asked to choose
16426the proper resolution.
e07c999f
PH
16427
16428@item
16429The @code{new} operator is not implemented.
16430
16431@item
16432Entry calls are not implemented.
16433
16434@item
16435Aside from printing, arithmetic operations on the native VAX floating-point
16436formats are not supported.
16437
16438@item
16439It is not possible to slice a packed array.
158c7665
PH
16440
16441@item
16442The names @code{True} and @code{False}, when not part of a qualified name,
16443are interpreted as if implicitly prefixed by @code{Standard}, regardless of
16444context.
16445Should your program
16446redefine these names in a package or procedure (at best a dubious practice),
16447you will have to use fully qualified names to access their new definitions.
e07c999f
PH
16448@end itemize
16449
16450@node Additions to Ada
16451@subsubsection Additions to Ada
16452@cindex Ada, deviations from
16453
16454As it does for other languages, @value{GDBN} makes certain generic
16455extensions to Ada (@pxref{Expressions}):
16456
16457@itemize @bullet
16458@item
ae21e955
BW
16459If the expression @var{E} is a variable residing in memory (typically
16460a local variable or array element) and @var{N} is a positive integer,
16461then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
16462@var{N}-1 adjacent variables following it in memory as an array. In
16463Ada, this operator is generally not necessary, since its prime use is
16464in displaying parts of an array, and slicing will usually do this in
16465Ada. However, there are occasional uses when debugging programs in
16466which certain debugging information has been optimized away.
e07c999f
PH
16467
16468@item
ae21e955
BW
16469@code{@var{B}::@var{var}} means ``the variable named @var{var} that
16470appears in function or file @var{B}.'' When @var{B} is a file name,
16471you must typically surround it in single quotes.
e07c999f
PH
16472
16473@item
16474The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
16475@var{type} that appears at address @var{addr}.''
16476
16477@item
16478A name starting with @samp{$} is a convenience variable
16479(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
16480@end itemize
16481
ae21e955
BW
16482In addition, @value{GDBN} provides a few other shortcuts and outright
16483additions specific to Ada:
e07c999f
PH
16484
16485@itemize @bullet
16486@item
16487The assignment statement is allowed as an expression, returning
16488its right-hand operand as its value. Thus, you may enter
16489
16490@smallexample
077e0a52
JB
16491(@value{GDBP}) set x := y + 3
16492(@value{GDBP}) print A(tmp := y + 1)
e07c999f
PH
16493@end smallexample
16494
16495@item
16496The semicolon is allowed as an ``operator,'' returning as its value
16497the value of its right-hand operand.
16498This allows, for example,
16499complex conditional breaks:
16500
16501@smallexample
077e0a52
JB
16502(@value{GDBP}) break f
16503(@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
e07c999f
PH
16504@end smallexample
16505
16506@item
16507Rather than use catenation and symbolic character names to introduce special
16508characters into strings, one may instead use a special bracket notation,
16509which is also used to print strings. A sequence of characters of the form
16510@samp{["@var{XX}"]} within a string or character literal denotes the
16511(single) character whose numeric encoding is @var{XX} in hexadecimal. The
16512sequence of characters @samp{["""]} also denotes a single quotation mark
16513in strings. For example,
16514@smallexample
16515 "One line.["0a"]Next line.["0a"]"
16516@end smallexample
16517@noindent
ae21e955
BW
16518contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
16519after each period.
e07c999f
PH
16520
16521@item
16522The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
16523@t{'Max} is optional (and is ignored in any case). For example, it is valid
16524to write
16525
16526@smallexample
077e0a52 16527(@value{GDBP}) print 'max(x, y)
e07c999f
PH
16528@end smallexample
16529
16530@item
16531When printing arrays, @value{GDBN} uses positional notation when the
16532array has a lower bound of 1, and uses a modified named notation otherwise.
ae21e955
BW
16533For example, a one-dimensional array of three integers with a lower bound
16534of 3 might print as
e07c999f
PH
16535
16536@smallexample
16537(3 => 10, 17, 1)
16538@end smallexample
16539
16540@noindent
16541That is, in contrast to valid Ada, only the first component has a @code{=>}
16542clause.
16543
16544@item
16545You may abbreviate attributes in expressions with any unique,
16546multi-character subsequence of
16547their names (an exact match gets preference).
16548For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
16549in place of @t{a'length}.
16550
16551@item
16552@cindex quoting Ada internal identifiers
16553Since Ada is case-insensitive, the debugger normally maps identifiers you type
16554to lower case. The GNAT compiler uses upper-case characters for
16555some of its internal identifiers, which are normally of no interest to users.
16556For the rare occasions when you actually have to look at them,
16557enclose them in angle brackets to avoid the lower-case mapping.
16558For example,
16559@smallexample
077e0a52 16560(@value{GDBP}) print <JMPBUF_SAVE>[0]
e07c999f
PH
16561@end smallexample
16562
16563@item
16564Printing an object of class-wide type or dereferencing an
16565access-to-class-wide value will display all the components of the object's
16566specific type (as indicated by its run-time tag). Likewise, component
16567selection on such a value will operate on the specific type of the
16568object.
16569
16570@end itemize
16571
3685b09f
PMR
16572@node Overloading support for Ada
16573@subsubsection Overloading support for Ada
16574@cindex overloading, Ada
16575
16576The debugger supports limited overloading. Given a subprogram call in which
16577the function symbol has multiple definitions, it will use the number of
16578actual parameters and some information about their types to attempt to narrow
16579the set of definitions. It also makes very limited use of context, preferring
16580procedures to functions in the context of the @code{call} command, and
16581functions to procedures elsewhere.
16582
16583If, after narrowing, the set of matching definitions still contains more than
16584one definition, @value{GDBN} will display a menu to query which one it should
16585use, for instance:
16586
16587@smallexample
16588(@value{GDBP}) print f(1)
16589Multiple matches for f
16590[0] cancel
16591[1] foo.f (integer) return boolean at foo.adb:23
16592[2] foo.f (foo.new_integer) return boolean at foo.adb:28
16593>
16594@end smallexample
16595
16596In this case, just select one menu entry either to cancel expression evaluation
16597(type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
16598instance (type the corresponding number and press @key{RET}).
16599
16600Here are a couple of commands to customize @value{GDBN}'s behavior in this
16601case:
16602
16603@table @code
16604
16605@kindex set ada print-signatures
16606@item set ada print-signatures
16607Control whether parameter types and return types are displayed in overloads
16608selection menus. It is @code{on} by default.
16609@xref{Overloading support for Ada}.
16610
16611@kindex show ada print-signatures
16612@item show ada print-signatures
16613Show the current setting for displaying parameter types and return types in
16614overloads selection menu.
16615@xref{Overloading support for Ada}.
16616
16617@end table
16618
e07c999f
PH
16619@node Stopping Before Main Program
16620@subsubsection Stopping at the Very Beginning
16621
16622@cindex breakpointing Ada elaboration code
16623It is sometimes necessary to debug the program during elaboration, and
16624before reaching the main procedure.
16625As defined in the Ada Reference
16626Manual, the elaboration code is invoked from a procedure called
16627@code{adainit}. To run your program up to the beginning of
16628elaboration, simply use the following two commands:
16629@code{tbreak adainit} and @code{run}.
16630
58d06528
JB
16631@node Ada Exceptions
16632@subsubsection Ada Exceptions
16633
16634A command is provided to list all Ada exceptions:
16635
16636@table @code
16637@kindex info exceptions
16638@item info exceptions
16639@itemx info exceptions @var{regexp}
16640The @code{info exceptions} command allows you to list all Ada exceptions
16641defined within the program being debugged, as well as their addresses.
16642With a regular expression, @var{regexp}, as argument, only those exceptions
16643whose names match @var{regexp} are listed.
16644@end table
16645
16646Below is a small example, showing how the command can be used, first
16647without argument, and next with a regular expression passed as an
16648argument.
16649
16650@smallexample
16651(@value{GDBP}) info exceptions
16652All defined Ada exceptions:
16653constraint_error: 0x613da0
16654program_error: 0x613d20
16655storage_error: 0x613ce0
16656tasking_error: 0x613ca0
16657const.aint_global_e: 0x613b00
16658(@value{GDBP}) info exceptions const.aint
16659All Ada exceptions matching regular expression "const.aint":
16660constraint_error: 0x613da0
16661const.aint_global_e: 0x613b00
16662@end smallexample
16663
16664It is also possible to ask @value{GDBN} to stop your program's execution
16665when an exception is raised. For more details, see @ref{Set Catchpoints}.
16666
20924a55
JB
16667@node Ada Tasks
16668@subsubsection Extensions for Ada Tasks
16669@cindex Ada, tasking
16670
16671Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
16672@value{GDBN} provides the following task-related commands:
16673
16674@table @code
16675@kindex info tasks
16676@item info tasks
16677This command shows a list of current Ada tasks, as in the following example:
16678
16679
16680@smallexample
16681@iftex
16682@leftskip=0.5cm
16683@end iftex
16684(@value{GDBP}) info tasks
16685 ID TID P-ID Pri State Name
16686 1 8088000 0 15 Child Activation Wait main_task
16687 2 80a4000 1 15 Accept Statement b
16688 3 809a800 1 15 Child Activation Wait a
32cd1edc 16689* 4 80ae800 3 15 Runnable c
20924a55
JB
16690
16691@end smallexample
16692
16693@noindent
16694In this listing, the asterisk before the last task indicates it to be the
16695task currently being inspected.
16696
16697@table @asis
16698@item ID
16699Represents @value{GDBN}'s internal task number.
16700
16701@item TID
16702The Ada task ID.
16703
16704@item P-ID
16705The parent's task ID (@value{GDBN}'s internal task number).
16706
16707@item Pri
16708The base priority of the task.
16709
16710@item State
16711Current state of the task.
16712
16713@table @code
16714@item Unactivated
16715The task has been created but has not been activated. It cannot be
16716executing.
16717
20924a55
JB
16718@item Runnable
16719The task is not blocked for any reason known to Ada. (It may be waiting
16720for a mutex, though.) It is conceptually "executing" in normal mode.
16721
16722@item Terminated
16723The task is terminated, in the sense of ARM 9.3 (5). Any dependents
16724that were waiting on terminate alternatives have been awakened and have
16725terminated themselves.
16726
16727@item Child Activation Wait
16728The task is waiting for created tasks to complete activation.
16729
16730@item Accept Statement
16731The task is waiting on an accept or selective wait statement.
16732
16733@item Waiting on entry call
16734The task is waiting on an entry call.
16735
16736@item Async Select Wait
16737The task is waiting to start the abortable part of an asynchronous
16738select statement.
16739
16740@item Delay Sleep
16741The task is waiting on a select statement with only a delay
16742alternative open.
16743
16744@item Child Termination Wait
16745The task is sleeping having completed a master within itself, and is
16746waiting for the tasks dependent on that master to become terminated or
16747waiting on a terminate Phase.
16748
16749@item Wait Child in Term Alt
16750The task is sleeping waiting for tasks on terminate alternatives to
16751finish terminating.
16752
16753@item Accepting RV with @var{taskno}
16754The task is accepting a rendez-vous with the task @var{taskno}.
16755@end table
16756
16757@item Name
16758Name of the task in the program.
16759
16760@end table
16761
16762@kindex info task @var{taskno}
16763@item info task @var{taskno}
16764This command shows detailled informations on the specified task, as in
16765the following example:
16766@smallexample
16767@iftex
16768@leftskip=0.5cm
16769@end iftex
16770(@value{GDBP}) info tasks
16771 ID TID P-ID Pri State Name
16772 1 8077880 0 15 Child Activation Wait main_task
32cd1edc 16773* 2 807c468 1 15 Runnable task_1
20924a55
JB
16774(@value{GDBP}) info task 2
16775Ada Task: 0x807c468
16776Name: task_1
16777Thread: 0x807f378
16778Parent: 1 (main_task)
16779Base Priority: 15
16780State: Runnable
16781@end smallexample
16782
16783@item task
16784@kindex task@r{ (Ada)}
16785@cindex current Ada task ID
16786This command prints the ID of the current task.
16787
16788@smallexample
16789@iftex
16790@leftskip=0.5cm
16791@end iftex
16792(@value{GDBP}) info tasks
16793 ID TID P-ID Pri State Name
16794 1 8077870 0 15 Child Activation Wait main_task
32cd1edc 16795* 2 807c458 1 15 Runnable t
20924a55
JB
16796(@value{GDBP}) task
16797[Current task is 2]
16798@end smallexample
16799
16800@item task @var{taskno}
16801@cindex Ada task switching
5d5658a1 16802This command is like the @code{thread @var{thread-id}}
20924a55
JB
16803command (@pxref{Threads}). It switches the context of debugging
16804from the current task to the given task.
16805
16806@smallexample
16807@iftex
16808@leftskip=0.5cm
16809@end iftex
16810(@value{GDBP}) info tasks
16811 ID TID P-ID Pri State Name
16812 1 8077870 0 15 Child Activation Wait main_task
32cd1edc 16813* 2 807c458 1 15 Runnable t
20924a55
JB
16814(@value{GDBP}) task 1
16815[Switching to task 1]
16816#0 0x8067726 in pthread_cond_wait ()
16817(@value{GDBP}) bt
16818#0 0x8067726 in pthread_cond_wait ()
16819#1 0x8056714 in system.os_interface.pthread_cond_wait ()
16820#2 0x805cb63 in system.task_primitives.operations.sleep ()
16821#3 0x806153e in system.tasking.stages.activate_tasks ()
16822#4 0x804aacc in un () at un.adb:5
16823@end smallexample
16824
629500fa
KS
16825@item break @var{location} task @var{taskno}
16826@itemx break @var{location} task @var{taskno} if @dots{}
45ac276d
JB
16827@cindex breakpoints and tasks, in Ada
16828@cindex task breakpoints, in Ada
16829@kindex break @dots{} task @var{taskno}@r{ (Ada)}
16830These commands are like the @code{break @dots{} thread @dots{}}
697aa1b7 16831command (@pxref{Thread Stops}). The
629500fa 16832@var{location} argument specifies source lines, as described
45ac276d
JB
16833in @ref{Specify Location}.
16834
16835Use the qualifier @samp{task @var{taskno}} with a breakpoint command
16836to specify that you only want @value{GDBN} to stop the program when a
697aa1b7 16837particular Ada task reaches this breakpoint. The @var{taskno} is one of the
45ac276d
JB
16838numeric task identifiers assigned by @value{GDBN}, shown in the first
16839column of the @samp{info tasks} display.
16840
16841If you do not specify @samp{task @var{taskno}} when you set a
16842breakpoint, the breakpoint applies to @emph{all} tasks of your
16843program.
16844
16845You can use the @code{task} qualifier on conditional breakpoints as
16846well; in this case, place @samp{task @var{taskno}} before the
16847breakpoint condition (before the @code{if}).
16848
16849For example,
16850
16851@smallexample
16852@iftex
16853@leftskip=0.5cm
16854@end iftex
16855(@value{GDBP}) info tasks
16856 ID TID P-ID Pri State Name
16857 1 140022020 0 15 Child Activation Wait main_task
16858 2 140045060 1 15 Accept/Select Wait t2
16859 3 140044840 1 15 Runnable t1
16860* 4 140056040 1 15 Runnable t3
16861(@value{GDBP}) b 15 task 2
16862Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
16863(@value{GDBP}) cont
16864Continuing.
16865task # 1 running
16866task # 2 running
16867
16868Breakpoint 5, test_task_debug () at test_task_debug.adb:15
1686915 flush;
16870(@value{GDBP}) info tasks
16871 ID TID P-ID Pri State Name
16872 1 140022020 0 15 Child Activation Wait main_task
16873* 2 140045060 1 15 Runnable t2
16874 3 140044840 1 15 Runnable t1
16875 4 140056040 1 15 Delay Sleep t3
16876@end smallexample
20924a55
JB
16877@end table
16878
16879@node Ada Tasks and Core Files
16880@subsubsection Tasking Support when Debugging Core Files
16881@cindex Ada tasking and core file debugging
16882
16883When inspecting a core file, as opposed to debugging a live program,
16884tasking support may be limited or even unavailable, depending on
16885the platform being used.
16886For instance, on x86-linux, the list of tasks is available, but task
32a8097b 16887switching is not supported.
20924a55 16888
32a8097b 16889On certain platforms, the debugger needs to perform some
20924a55
JB
16890memory writes in order to provide Ada tasking support. When inspecting
16891a core file, this means that the core file must be opened with read-write
16892privileges, using the command @samp{"set write on"} (@pxref{Patching}).
16893Under these circumstances, you should make a backup copy of the core
16894file before inspecting it with @value{GDBN}.
16895
6e1bb179
JB
16896@node Ravenscar Profile
16897@subsubsection Tasking Support when using the Ravenscar Profile
16898@cindex Ravenscar Profile
16899
16900The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
16901specifically designed for systems with safety-critical real-time
16902requirements.
16903
16904@table @code
16905@kindex set ravenscar task-switching on
16906@cindex task switching with program using Ravenscar Profile
16907@item set ravenscar task-switching on
16908Allows task switching when debugging a program that uses the Ravenscar
16909Profile. This is the default.
16910
16911@kindex set ravenscar task-switching off
16912@item set ravenscar task-switching off
16913Turn off task switching when debugging a program that uses the Ravenscar
16914Profile. This is mostly intended to disable the code that adds support
16915for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
16916the Ravenscar runtime is preventing @value{GDBN} from working properly.
16917To be effective, this command should be run before the program is started.
16918
16919@kindex show ravenscar task-switching
16920@item show ravenscar task-switching
16921Show whether it is possible to switch from task to task in a program
16922using the Ravenscar Profile.
16923
16924@end table
16925
e07c999f
PH
16926@node Ada Glitches
16927@subsubsection Known Peculiarities of Ada Mode
16928@cindex Ada, problems
16929
16930Besides the omissions listed previously (@pxref{Omissions from Ada}),
16931we know of several problems with and limitations of Ada mode in
16932@value{GDBN},
16933some of which will be fixed with planned future releases of the debugger
16934and the GNU Ada compiler.
16935
16936@itemize @bullet
e07c999f
PH
16937@item
16938Static constants that the compiler chooses not to materialize as objects in
16939storage are invisible to the debugger.
16940
16941@item
16942Named parameter associations in function argument lists are ignored (the
16943argument lists are treated as positional).
16944
16945@item
16946Many useful library packages are currently invisible to the debugger.
16947
16948@item
16949Fixed-point arithmetic, conversions, input, and output is carried out using
16950floating-point arithmetic, and may give results that only approximate those on
16951the host machine.
16952
e07c999f
PH
16953@item
16954The GNAT compiler never generates the prefix @code{Standard} for any of
16955the standard symbols defined by the Ada language. @value{GDBN} knows about
16956this: it will strip the prefix from names when you use it, and will never
16957look for a name you have so qualified among local symbols, nor match against
16958symbols in other packages or subprograms. If you have
16959defined entities anywhere in your program other than parameters and
16960local variables whose simple names match names in @code{Standard},
16961GNAT's lack of qualification here can cause confusion. When this happens,
16962you can usually resolve the confusion
16963by qualifying the problematic names with package
16964@code{Standard} explicitly.
16965@end itemize
16966
95433b34
JB
16967Older versions of the compiler sometimes generate erroneous debugging
16968information, resulting in the debugger incorrectly printing the value
16969of affected entities. In some cases, the debugger is able to work
16970around an issue automatically. In other cases, the debugger is able
16971to work around the issue, but the work-around has to be specifically
16972enabled.
16973
16974@kindex set ada trust-PAD-over-XVS
16975@kindex show ada trust-PAD-over-XVS
16976@table @code
16977
16978@item set ada trust-PAD-over-XVS on
16979Configure GDB to strictly follow the GNAT encoding when computing the
16980value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
16981types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
16982a complete description of the encoding used by the GNAT compiler).
16983This is the default.
16984
16985@item set ada trust-PAD-over-XVS off
16986This is related to the encoding using by the GNAT compiler. If @value{GDBN}
16987sometimes prints the wrong value for certain entities, changing @code{ada
16988trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
16989the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
16990@code{off}, but this incurs a slight performance penalty, so it is
16991recommended to leave this setting to @code{on} unless necessary.
16992
16993@end table
16994
c6044dd1
JB
16995@cindex GNAT descriptive types
16996@cindex GNAT encoding
16997Internally, the debugger also relies on the compiler following a number
16998of conventions known as the @samp{GNAT Encoding}, all documented in
16999@file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
17000how the debugging information should be generated for certain types.
17001In particular, this convention makes use of @dfn{descriptive types},
17002which are artificial types generated purely to help the debugger.
17003
17004These encodings were defined at a time when the debugging information
17005format used was not powerful enough to describe some of the more complex
17006types available in Ada. Since DWARF allows us to express nearly all
17007Ada features, the long-term goal is to slowly replace these descriptive
17008types by their pure DWARF equivalent. To facilitate that transition,
17009a new maintenance option is available to force the debugger to ignore
17010those descriptive types. It allows the user to quickly evaluate how
17011well @value{GDBN} works without them.
17012
17013@table @code
17014
17015@kindex maint ada set ignore-descriptive-types
17016@item maintenance ada set ignore-descriptive-types [on|off]
17017Control whether the debugger should ignore descriptive types.
17018The default is not to ignore descriptives types (@code{off}).
17019
17020@kindex maint ada show ignore-descriptive-types
17021@item maintenance ada show ignore-descriptive-types
17022Show if descriptive types are ignored by @value{GDBN}.
17023
17024@end table
17025
79a6e687
BW
17026@node Unsupported Languages
17027@section Unsupported Languages
4e562065
JB
17028
17029@cindex unsupported languages
17030@cindex minimal language
17031In addition to the other fully-supported programming languages,
17032@value{GDBN} also provides a pseudo-language, called @code{minimal}.
17033It does not represent a real programming language, but provides a set
17034of capabilities close to what the C or assembly languages provide.
17035This should allow most simple operations to be performed while debugging
17036an application that uses a language currently not supported by @value{GDBN}.
17037
17038If the language is set to @code{auto}, @value{GDBN} will automatically
17039select this language if the current frame corresponds to an unsupported
17040language.
17041
6d2ebf8b 17042@node Symbols
c906108c
SS
17043@chapter Examining the Symbol Table
17044
d4f3574e 17045The commands described in this chapter allow you to inquire about the
c906108c
SS
17046symbols (names of variables, functions and types) defined in your
17047program. This information is inherent in the text of your program and
17048does not change as your program executes. @value{GDBN} finds it in your
17049program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
17050(@pxref{File Options, ,Choosing Files}), or by one of the
17051file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
17052
17053@cindex symbol names
17054@cindex names of symbols
17055@cindex quoting names
d044bac8 17056@anchor{quoting names}
c906108c
SS
17057Occasionally, you may need to refer to symbols that contain unusual
17058characters, which @value{GDBN} ordinarily treats as word delimiters. The
17059most frequent case is in referring to static variables in other
79a6e687 17060source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
17061are recorded in object files as debugging symbols, but @value{GDBN} would
17062ordinarily parse a typical file name, like @file{foo.c}, as the three words
17063@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
17064@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
17065
474c8240 17066@smallexample
c906108c 17067p 'foo.c'::x
474c8240 17068@end smallexample
c906108c
SS
17069
17070@noindent
17071looks up the value of @code{x} in the scope of the file @file{foo.c}.
17072
17073@table @code
a8f24a35
EZ
17074@cindex case-insensitive symbol names
17075@cindex case sensitivity in symbol names
17076@kindex set case-sensitive
17077@item set case-sensitive on
17078@itemx set case-sensitive off
17079@itemx set case-sensitive auto
17080Normally, when @value{GDBN} looks up symbols, it matches their names
17081with case sensitivity determined by the current source language.
17082Occasionally, you may wish to control that. The command @code{set
17083case-sensitive} lets you do that by specifying @code{on} for
17084case-sensitive matches or @code{off} for case-insensitive ones. If
17085you specify @code{auto}, case sensitivity is reset to the default
17086suitable for the source language. The default is case-sensitive
17087matches for all languages except for Fortran, for which the default is
17088case-insensitive matches.
17089
9c16f35a
EZ
17090@kindex show case-sensitive
17091@item show case-sensitive
a8f24a35
EZ
17092This command shows the current setting of case sensitivity for symbols
17093lookups.
17094
53342f27
TT
17095@kindex set print type methods
17096@item set print type methods
17097@itemx set print type methods on
17098@itemx set print type methods off
17099Normally, when @value{GDBN} prints a class, it displays any methods
17100declared in that class. You can control this behavior either by
17101passing the appropriate flag to @code{ptype}, or using @command{set
17102print type methods}. Specifying @code{on} will cause @value{GDBN} to
17103display the methods; this is the default. Specifying @code{off} will
17104cause @value{GDBN} to omit the methods.
17105
17106@kindex show print type methods
17107@item show print type methods
17108This command shows the current setting of method display when printing
17109classes.
17110
883fd55a
KS
17111@kindex set print type nested-type-limit
17112@item set print type nested-type-limit @var{limit}
17113@itemx set print type nested-type-limit unlimited
17114Set the limit of displayed nested types that the type printer will
17115show. A @var{limit} of @code{unlimited} or @code{-1} will show all
17116nested definitions. By default, the type printer will not show any nested
17117types defined in classes.
17118
17119@kindex show print type nested-type-limit
17120@item show print type nested-type-limit
17121This command shows the current display limit of nested types when
17122printing classes.
17123
53342f27
TT
17124@kindex set print type typedefs
17125@item set print type typedefs
17126@itemx set print type typedefs on
17127@itemx set print type typedefs off
17128
17129Normally, when @value{GDBN} prints a class, it displays any typedefs
17130defined in that class. You can control this behavior either by
17131passing the appropriate flag to @code{ptype}, or using @command{set
17132print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
17133display the typedef definitions; this is the default. Specifying
17134@code{off} will cause @value{GDBN} to omit the typedef definitions.
17135Note that this controls whether the typedef definition itself is
17136printed, not whether typedef names are substituted when printing other
17137types.
17138
17139@kindex show print type typedefs
17140@item show print type typedefs
17141This command shows the current setting of typedef display when
17142printing classes.
17143
c906108c 17144@kindex info address
b37052ae 17145@cindex address of a symbol
c906108c
SS
17146@item info address @var{symbol}
17147Describe where the data for @var{symbol} is stored. For a register
17148variable, this says which register it is kept in. For a non-register
17149local variable, this prints the stack-frame offset at which the variable
17150is always stored.
17151
17152Note the contrast with @samp{print &@var{symbol}}, which does not work
17153at all for a register variable, and for a stack local variable prints
17154the exact address of the current instantiation of the variable.
17155
3d67e040 17156@kindex info symbol
b37052ae 17157@cindex symbol from address
9c16f35a 17158@cindex closest symbol and offset for an address
3d67e040
EZ
17159@item info symbol @var{addr}
17160Print the name of a symbol which is stored at the address @var{addr}.
17161If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
17162nearest symbol and an offset from it:
17163
474c8240 17164@smallexample
3d67e040
EZ
17165(@value{GDBP}) info symbol 0x54320
17166_initialize_vx + 396 in section .text
474c8240 17167@end smallexample
3d67e040
EZ
17168
17169@noindent
17170This is the opposite of the @code{info address} command. You can use
17171it to find out the name of a variable or a function given its address.
17172
c14c28ba
PP
17173For dynamically linked executables, the name of executable or shared
17174library containing the symbol is also printed:
17175
17176@smallexample
17177(@value{GDBP}) info symbol 0x400225
17178_start + 5 in section .text of /tmp/a.out
17179(@value{GDBP}) info symbol 0x2aaaac2811cf
17180__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
17181@end smallexample
17182
439250fb
DE
17183@kindex demangle
17184@cindex demangle
17185@item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
17186Demangle @var{name}.
17187If @var{language} is provided it is the name of the language to demangle
17188@var{name} in. Otherwise @var{name} is demangled in the current language.
17189
17190The @samp{--} option specifies the end of options,
17191and is useful when @var{name} begins with a dash.
17192
17193The parameter @code{demangle-style} specifies how to interpret the kind
17194of mangling used. @xref{Print Settings}.
17195
c906108c 17196@kindex whatis
53342f27 17197@item whatis[/@var{flags}] [@var{arg}]
177bc839
JK
17198Print the data type of @var{arg}, which can be either an expression
17199or a name of a data type. With no argument, print the data type of
17200@code{$}, the last value in the value history.
17201
17202If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
17203is not actually evaluated, and any side-effecting operations (such as
17204assignments or function calls) inside it do not take place.
17205
17206If @var{arg} is a variable or an expression, @code{whatis} prints its
17207literal type as it is used in the source code. If the type was
17208defined using a @code{typedef}, @code{whatis} will @emph{not} print
17209the data type underlying the @code{typedef}. If the type of the
17210variable or the expression is a compound data type, such as
17211@code{struct} or @code{class}, @code{whatis} never prints their
17212fields or methods. It just prints the @code{struct}/@code{class}
17213name (a.k.a.@: its @dfn{tag}). If you want to see the members of
17214such a compound data type, use @code{ptype}.
17215
17216If @var{arg} is a type name that was defined using @code{typedef},
17217@code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
17218Unrolling means that @code{whatis} will show the underlying type used
17219in the @code{typedef} declaration of @var{arg}. However, if that
17220underlying type is also a @code{typedef}, @code{whatis} will not
17221unroll it.
17222
17223For C code, the type names may also have the form @samp{class
17224@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
17225@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 17226
53342f27
TT
17227@var{flags} can be used to modify how the type is displayed.
17228Available flags are:
17229
17230@table @code
17231@item r
17232Display in ``raw'' form. Normally, @value{GDBN} substitutes template
17233parameters and typedefs defined in a class when printing the class'
17234members. The @code{/r} flag disables this.
17235
17236@item m
17237Do not print methods defined in the class.
17238
17239@item M
17240Print methods defined in the class. This is the default, but the flag
17241exists in case you change the default with @command{set print type methods}.
17242
17243@item t
17244Do not print typedefs defined in the class. Note that this controls
17245whether the typedef definition itself is printed, not whether typedef
17246names are substituted when printing other types.
17247
17248@item T
17249Print typedefs defined in the class. This is the default, but the flag
17250exists in case you change the default with @command{set print type typedefs}.
7c161838
SDJ
17251
17252@item o
17253Print the offsets and sizes of fields in a struct, similar to what the
17254@command{pahole} tool does. This option implies the @code{/tm} flags.
17255
17256For example, given the following declarations:
17257
17258@smallexample
17259struct tuv
17260@{
17261 int a1;
17262 char *a2;
17263 int a3;
17264@};
17265
17266struct xyz
17267@{
17268 int f1;
17269 char f2;
17270 void *f3;
17271 struct tuv f4;
17272@};
17273
17274union qwe
17275@{
17276 struct tuv fff1;
17277 struct xyz fff2;
17278@};
17279
17280struct tyu
17281@{
17282 int a1 : 1;
17283 int a2 : 3;
17284 int a3 : 23;
17285 char a4 : 2;
17286 int64_t a5;
17287 int a6 : 5;
17288 int64_t a7 : 3;
17289@};
17290@end smallexample
17291
17292Issuing a @kbd{ptype /o struct tuv} command would print:
17293
17294@smallexample
17295(@value{GDBP}) ptype /o struct tuv
17296/* offset | size */ type = struct tuv @{
17297/* 0 | 4 */ int a1;
17298/* XXX 4-byte hole */
17299/* 8 | 8 */ char *a2;
17300/* 16 | 4 */ int a3;
17301
17302 /* total size (bytes): 24 */
17303 @}
17304@end smallexample
17305
17306Notice the format of the first column of comments. There, you can
17307find two parts separated by the @samp{|} character: the @emph{offset},
17308which indicates where the field is located inside the struct, in
17309bytes, and the @emph{size} of the field. Another interesting line is
17310the marker of a @emph{hole} in the struct, indicating that it may be
17311possible to pack the struct and make it use less space by reorganizing
17312its fields.
17313
17314It is also possible to print offsets inside an union:
17315
17316@smallexample
17317(@value{GDBP}) ptype /o union qwe
17318/* offset | size */ type = union qwe @{
17319/* 24 */ struct tuv @{
17320/* 0 | 4 */ int a1;
17321/* XXX 4-byte hole */
17322/* 8 | 8 */ char *a2;
17323/* 16 | 4 */ int a3;
17324
17325 /* total size (bytes): 24 */
17326 @} fff1;
17327/* 40 */ struct xyz @{
17328/* 0 | 4 */ int f1;
17329/* 4 | 1 */ char f2;
17330/* XXX 3-byte hole */
17331/* 8 | 8 */ void *f3;
17332/* 16 | 24 */ struct tuv @{
17333/* 16 | 4 */ int a1;
17334/* XXX 4-byte hole */
17335/* 24 | 8 */ char *a2;
17336/* 32 | 4 */ int a3;
17337
17338 /* total size (bytes): 24 */
17339 @} f4;
17340
17341 /* total size (bytes): 40 */
17342 @} fff2;
17343
17344 /* total size (bytes): 40 */
17345 @}
17346@end smallexample
17347
17348In this case, since @code{struct tuv} and @code{struct xyz} occupy the
17349same space (because we are dealing with an union), the offset is not
17350printed for them. However, you can still examine the offset of each
17351of these structures' fields.
17352
17353Another useful scenario is printing the offsets of a struct containing
17354bitfields:
17355
17356@smallexample
17357(@value{GDBP}) ptype /o struct tyu
17358/* offset | size */ type = struct tyu @{
17359/* 0:31 | 4 */ int a1 : 1;
17360/* 0:28 | 4 */ int a2 : 3;
17361/* 0: 5 | 4 */ int a3 : 23;
17362/* 3: 3 | 1 */ signed char a4 : 2;
17363/* XXX 3-bit hole */
17364/* XXX 4-byte hole */
17365/* 8 | 8 */ int64_t a5;
17366/* 16:27 | 4 */ int a6 : 5;
17367/* 16:56 | 8 */ int64_t a7 : 3;
17368
17369 /* total size (bytes): 24 */
17370 @}
17371@end smallexample
17372
17373Note how the offset information is now extended to also include how
17374many bits are left to be used in each bitfield.
53342f27
TT
17375@end table
17376
c906108c 17377@kindex ptype
53342f27 17378@item ptype[/@var{flags}] [@var{arg}]
62f3a2ba
FF
17379@code{ptype} accepts the same arguments as @code{whatis}, but prints a
17380detailed description of the type, instead of just the name of the type.
17381@xref{Expressions, ,Expressions}.
c906108c 17382
177bc839
JK
17383Contrary to @code{whatis}, @code{ptype} always unrolls any
17384@code{typedef}s in its argument declaration, whether the argument is
17385a variable, expression, or a data type. This means that @code{ptype}
17386of a variable or an expression will not print literally its type as
17387present in the source code---use @code{whatis} for that. @code{typedef}s at
17388the pointer or reference targets are also unrolled. Only @code{typedef}s of
17389fields, methods and inner @code{class typedef}s of @code{struct}s,
17390@code{class}es and @code{union}s are not unrolled even with @code{ptype}.
17391
c906108c
SS
17392For example, for this variable declaration:
17393
474c8240 17394@smallexample
177bc839
JK
17395typedef double real_t;
17396struct complex @{ real_t real; double imag; @};
17397typedef struct complex complex_t;
17398complex_t var;
17399real_t *real_pointer_var;
474c8240 17400@end smallexample
c906108c
SS
17401
17402@noindent
17403the two commands give this output:
17404
474c8240 17405@smallexample
c906108c 17406@group
177bc839
JK
17407(@value{GDBP}) whatis var
17408type = complex_t
17409(@value{GDBP}) ptype var
17410type = struct complex @{
17411 real_t real;
17412 double imag;
17413@}
17414(@value{GDBP}) whatis complex_t
17415type = struct complex
17416(@value{GDBP}) whatis struct complex
c906108c 17417type = struct complex
177bc839 17418(@value{GDBP}) ptype struct complex
c906108c 17419type = struct complex @{
177bc839 17420 real_t real;
c906108c
SS
17421 double imag;
17422@}
177bc839
JK
17423(@value{GDBP}) whatis real_pointer_var
17424type = real_t *
17425(@value{GDBP}) ptype real_pointer_var
17426type = double *
c906108c 17427@end group
474c8240 17428@end smallexample
c906108c
SS
17429
17430@noindent
17431As with @code{whatis}, using @code{ptype} without an argument refers to
17432the type of @code{$}, the last value in the value history.
17433
ab1adacd
EZ
17434@cindex incomplete type
17435Sometimes, programs use opaque data types or incomplete specifications
17436of complex data structure. If the debug information included in the
17437program does not allow @value{GDBN} to display a full declaration of
17438the data type, it will say @samp{<incomplete type>}. For example,
17439given these declarations:
17440
17441@smallexample
17442 struct foo;
17443 struct foo *fooptr;
17444@end smallexample
17445
17446@noindent
17447but no definition for @code{struct foo} itself, @value{GDBN} will say:
17448
17449@smallexample
ddb50cd7 17450 (@value{GDBP}) ptype foo
ab1adacd
EZ
17451 $1 = <incomplete type>
17452@end smallexample
17453
17454@noindent
17455``Incomplete type'' is C terminology for data types that are not
17456completely specified.
17457
d69cf9b2
PA
17458@cindex unknown type
17459Othertimes, information about a variable's type is completely absent
17460from the debug information included in the program. This most often
17461happens when the program or library where the variable is defined
17462includes no debug information at all. @value{GDBN} knows the variable
17463exists from inspecting the linker/loader symbol table (e.g., the ELF
17464dynamic symbol table), but such symbols do not contain type
17465information. Inspecting the type of a (global) variable for which
17466@value{GDBN} has no type information shows:
17467
17468@smallexample
17469 (@value{GDBP}) ptype var
17470 type = <data variable, no debug info>
17471@end smallexample
17472
17473@xref{Variables, no debug info variables}, for how to print the values
17474of such variables.
17475
c906108c
SS
17476@kindex info types
17477@item info types @var{regexp}
17478@itemx info types
09d4efe1
EZ
17479Print a brief description of all types whose names match the regular
17480expression @var{regexp} (or all types in your program, if you supply
17481no argument). Each complete typename is matched as though it were a
17482complete line; thus, @samp{i type value} gives information on all
17483types in your program whose names include the string @code{value}, but
17484@samp{i type ^value$} gives information only on types whose complete
17485name is @code{value}.
c906108c
SS
17486
17487This command differs from @code{ptype} in two ways: first, like
17488@code{whatis}, it does not print a detailed description; second, it
17489lists all source files where a type is defined.
17490
18a9fc12
TT
17491@kindex info type-printers
17492@item info type-printers
17493Versions of @value{GDBN} that ship with Python scripting enabled may
17494have ``type printers'' available. When using @command{ptype} or
17495@command{whatis}, these printers are consulted when the name of a type
17496is needed. @xref{Type Printing API}, for more information on writing
17497type printers.
17498
17499@code{info type-printers} displays all the available type printers.
17500
17501@kindex enable type-printer
17502@kindex disable type-printer
17503@item enable type-printer @var{name}@dots{}
17504@item disable type-printer @var{name}@dots{}
17505These commands can be used to enable or disable type printers.
17506
b37052ae
EZ
17507@kindex info scope
17508@cindex local variables
09d4efe1 17509@item info scope @var{location}
b37052ae 17510List all the variables local to a particular scope. This command
09d4efe1
EZ
17511accepts a @var{location} argument---a function name, a source line, or
17512an address preceded by a @samp{*}, and prints all the variables local
2a25a5ba
EZ
17513to the scope defined by that location. (@xref{Specify Location}, for
17514details about supported forms of @var{location}.) For example:
b37052ae
EZ
17515
17516@smallexample
17517(@value{GDBP}) @b{info scope command_line_handler}
17518Scope for command_line_handler:
17519Symbol rl is an argument at stack/frame offset 8, length 4.
17520Symbol linebuffer is in static storage at address 0x150a18, length 4.
17521Symbol linelength is in static storage at address 0x150a1c, length 4.
17522Symbol p is a local variable in register $esi, length 4.
17523Symbol p1 is a local variable in register $ebx, length 4.
17524Symbol nline is a local variable in register $edx, length 4.
17525Symbol repeat is a local variable at frame offset -8, length 4.
17526@end smallexample
17527
f5c37c66
EZ
17528@noindent
17529This command is especially useful for determining what data to collect
17530during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
17531collect}.
17532
c906108c
SS
17533@kindex info source
17534@item info source
919d772c
JB
17535Show information about the current source file---that is, the source file for
17536the function containing the current point of execution:
17537@itemize @bullet
17538@item
17539the name of the source file, and the directory containing it,
17540@item
17541the directory it was compiled in,
17542@item
17543its length, in lines,
17544@item
17545which programming language it is written in,
17546@item
b6577aab
DE
17547if the debug information provides it, the program that compiled the file
17548(which may include, e.g., the compiler version and command line arguments),
17549@item
919d772c
JB
17550whether the executable includes debugging information for that file, and
17551if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
17552@item
17553whether the debugging information includes information about
17554preprocessor macros.
17555@end itemize
17556
c906108c
SS
17557
17558@kindex info sources
17559@item info sources
17560Print the names of all source files in your program for which there is
17561debugging information, organized into two lists: files whose symbols
17562have already been read, and files whose symbols will be read when needed.
17563
17564@kindex info functions
17565@item info functions
17566Print the names and data types of all defined functions.
17567
17568@item info functions @var{regexp}
17569Print the names and data types of all defined functions
17570whose names contain a match for regular expression @var{regexp}.
17571Thus, @samp{info fun step} finds all functions whose names
17572include @code{step}; @samp{info fun ^step} finds those whose names
b383017d 17573start with @code{step}. If a function name contains characters
c1468174 17574that conflict with the regular expression language (e.g.@:
1c5dfdad 17575@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
17576
17577@kindex info variables
17578@item info variables
0fe7935b 17579Print the names and data types of all variables that are defined
6ca652b0 17580outside of functions (i.e.@: excluding local variables).
c906108c
SS
17581
17582@item info variables @var{regexp}
17583Print the names and data types of all variables (except for local
17584variables) whose names contain a match for regular expression
17585@var{regexp}.
17586
b37303ee 17587@kindex info classes
721c2651 17588@cindex Objective-C, classes and selectors
b37303ee
AF
17589@item info classes
17590@itemx info classes @var{regexp}
17591Display all Objective-C classes in your program, or
17592(with the @var{regexp} argument) all those matching a particular regular
17593expression.
17594
17595@kindex info selectors
17596@item info selectors
17597@itemx info selectors @var{regexp}
17598Display all Objective-C selectors in your program, or
17599(with the @var{regexp} argument) all those matching a particular regular
17600expression.
17601
c906108c
SS
17602@ignore
17603This was never implemented.
17604@kindex info methods
17605@item info methods
17606@itemx info methods @var{regexp}
17607The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
17608methods within C@t{++} program, or (with the @var{regexp} argument) a
17609specific set of methods found in the various C@t{++} classes. Many
17610C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
17611from the @code{ptype} command can be overwhelming and hard to use. The
17612@code{info-methods} command filters the methods, printing only those
17613which match the regular-expression @var{regexp}.
17614@end ignore
17615
9c16f35a 17616@cindex opaque data types
c906108c
SS
17617@kindex set opaque-type-resolution
17618@item set opaque-type-resolution on
17619Tell @value{GDBN} to resolve opaque types. An opaque type is a type
17620declared as a pointer to a @code{struct}, @code{class}, or
17621@code{union}---for example, @code{struct MyType *}---that is used in one
17622source file although the full declaration of @code{struct MyType} is in
17623another source file. The default is on.
17624
17625A change in the setting of this subcommand will not take effect until
17626the next time symbols for a file are loaded.
17627
17628@item set opaque-type-resolution off
17629Tell @value{GDBN} not to resolve opaque types. In this case, the type
17630is printed as follows:
17631@smallexample
17632@{<no data fields>@}
17633@end smallexample
17634
17635@kindex show opaque-type-resolution
17636@item show opaque-type-resolution
17637Show whether opaque types are resolved or not.
c906108c 17638
770e7fc7
DE
17639@kindex set print symbol-loading
17640@cindex print messages when symbols are loaded
17641@item set print symbol-loading
17642@itemx set print symbol-loading full
17643@itemx set print symbol-loading brief
17644@itemx set print symbol-loading off
17645The @code{set print symbol-loading} command allows you to control the
17646printing of messages when @value{GDBN} loads symbol information.
17647By default a message is printed for the executable and one for each
17648shared library, and normally this is what you want. However, when
17649debugging apps with large numbers of shared libraries these messages
17650can be annoying.
17651When set to @code{brief} a message is printed for each executable,
17652and when @value{GDBN} loads a collection of shared libraries at once
17653it will only print one message regardless of the number of shared
17654libraries. When set to @code{off} no messages are printed.
17655
17656@kindex show print symbol-loading
17657@item show print symbol-loading
17658Show whether messages will be printed when a @value{GDBN} command
17659entered from the keyboard causes symbol information to be loaded.
17660
c906108c
SS
17661@kindex maint print symbols
17662@cindex symbol dump
17663@kindex maint print psymbols
17664@cindex partial symbol dump
7c57fa1e
YQ
17665@kindex maint print msymbols
17666@cindex minimal symbol dump
34c41c68
DE
17667@item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
17668@itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
17669@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
17670@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
17671@itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
17672Write a dump of debugging symbol data into the file @var{filename} or
17673the terminal if @var{filename} is unspecified.
17674If @code{-objfile @var{objfile}} is specified, only dump symbols for
17675that objfile.
17676If @code{-pc @var{address}} is specified, only dump symbols for the file
17677with code at that address. Note that @var{address} may be a symbol like
17678@code{main}.
17679If @code{-source @var{source}} is specified, only dump symbols for that
17680source file.
17681
17682These commands are used to debug the @value{GDBN} symbol-reading code.
17683These commands do not modify internal @value{GDBN} state, therefore
17684@samp{maint print symbols} will only print symbols for already expanded symbol
17685tables.
17686You can use the command @code{info sources} to find out which files these are.
17687If you use @samp{maint print psymbols} instead, the dump shows information
17688about symbols that @value{GDBN} only knows partially---that is, symbols
17689defined in files that @value{GDBN} has skimmed, but not yet read completely.
17690Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
17691``ELF symbols''.
17692
79a6e687 17693@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 17694@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 17695
5e7b2f39
JB
17696@kindex maint info symtabs
17697@kindex maint info psymtabs
44ea7b70
JB
17698@cindex listing @value{GDBN}'s internal symbol tables
17699@cindex symbol tables, listing @value{GDBN}'s internal
17700@cindex full symbol tables, listing @value{GDBN}'s internal
17701@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
17702@item maint info symtabs @r{[} @var{regexp} @r{]}
17703@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
17704
17705List the @code{struct symtab} or @code{struct partial_symtab}
17706structures whose names match @var{regexp}. If @var{regexp} is not
17707given, list them all. The output includes expressions which you can
17708copy into a @value{GDBN} debugging this one to examine a particular
17709structure in more detail. For example:
17710
17711@smallexample
5e7b2f39 17712(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
17713@{ objfile /home/gnu/build/gdb/gdb
17714 ((struct objfile *) 0x82e69d0)
b383017d 17715 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
17716 ((struct partial_symtab *) 0x8474b10)
17717 readin no
17718 fullname (null)
17719 text addresses 0x814d3c8 -- 0x8158074
17720 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
17721 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
17722 dependencies (none)
17723 @}
17724@}
5e7b2f39 17725(@value{GDBP}) maint info symtabs
44ea7b70
JB
17726(@value{GDBP})
17727@end smallexample
17728@noindent
17729We see that there is one partial symbol table whose filename contains
17730the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
17731and we see that @value{GDBN} has not read in any symtabs yet at all.
17732If we set a breakpoint on a function, that will cause @value{GDBN} to
17733read the symtab for the compilation unit containing that function:
17734
17735@smallexample
17736(@value{GDBP}) break dwarf2_psymtab_to_symtab
17737Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
17738line 1574.
5e7b2f39 17739(@value{GDBP}) maint info symtabs
b383017d 17740@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 17741 ((struct objfile *) 0x82e69d0)
b383017d 17742 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
17743 ((struct symtab *) 0x86c1f38)
17744 dirname (null)
17745 fullname (null)
17746 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 17747 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
17748 debugformat DWARF 2
17749 @}
17750@}
b383017d 17751(@value{GDBP})
44ea7b70 17752@end smallexample
44ea7b70 17753
f2403c39
AB
17754@kindex maint info line-table
17755@cindex listing @value{GDBN}'s internal line tables
17756@cindex line tables, listing @value{GDBN}'s internal
17757@item maint info line-table @r{[} @var{regexp} @r{]}
17758
17759List the @code{struct linetable} from all @code{struct symtab}
17760instances whose name matches @var{regexp}. If @var{regexp} is not
17761given, list the @code{struct linetable} from all @code{struct symtab}.
17762
f57d2163
DE
17763@kindex maint set symbol-cache-size
17764@cindex symbol cache size
17765@item maint set symbol-cache-size @var{size}
17766Set the size of the symbol cache to @var{size}.
17767The default size is intended to be good enough for debugging
17768most applications. This option exists to allow for experimenting
17769with different sizes.
17770
17771@kindex maint show symbol-cache-size
17772@item maint show symbol-cache-size
17773Show the size of the symbol cache.
17774
17775@kindex maint print symbol-cache
17776@cindex symbol cache, printing its contents
17777@item maint print symbol-cache
17778Print the contents of the symbol cache.
17779This is useful when debugging symbol cache issues.
17780
17781@kindex maint print symbol-cache-statistics
17782@cindex symbol cache, printing usage statistics
17783@item maint print symbol-cache-statistics
17784Print symbol cache usage statistics.
17785This helps determine how well the cache is being utilized.
17786
17787@kindex maint flush-symbol-cache
17788@cindex symbol cache, flushing
17789@item maint flush-symbol-cache
17790Flush the contents of the symbol cache, all entries are removed.
17791This command is useful when debugging the symbol cache.
17792It is also useful when collecting performance data.
17793
17794@end table
6a3ca067 17795
6d2ebf8b 17796@node Altering
c906108c
SS
17797@chapter Altering Execution
17798
17799Once you think you have found an error in your program, you might want to
17800find out for certain whether correcting the apparent error would lead to
17801correct results in the rest of the run. You can find the answer by
17802experiment, using the @value{GDBN} features for altering execution of the
17803program.
17804
17805For example, you can store new values into variables or memory
7a292a7a
SS
17806locations, give your program a signal, restart it at a different
17807address, or even return prematurely from a function.
c906108c
SS
17808
17809@menu
17810* Assignment:: Assignment to variables
17811* Jumping:: Continuing at a different address
c906108c 17812* Signaling:: Giving your program a signal
c906108c
SS
17813* Returning:: Returning from a function
17814* Calling:: Calling your program's functions
17815* Patching:: Patching your program
bb2ec1b3 17816* Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
c906108c
SS
17817@end menu
17818
6d2ebf8b 17819@node Assignment
79a6e687 17820@section Assignment to Variables
c906108c
SS
17821
17822@cindex assignment
17823@cindex setting variables
17824To alter the value of a variable, evaluate an assignment expression.
17825@xref{Expressions, ,Expressions}. For example,
17826
474c8240 17827@smallexample
c906108c 17828print x=4
474c8240 17829@end smallexample
c906108c
SS
17830
17831@noindent
17832stores the value 4 into the variable @code{x}, and then prints the
5d161b24 17833value of the assignment expression (which is 4).
c906108c
SS
17834@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
17835information on operators in supported languages.
c906108c
SS
17836
17837@kindex set variable
17838@cindex variables, setting
17839If you are not interested in seeing the value of the assignment, use the
17840@code{set} command instead of the @code{print} command. @code{set} is
17841really the same as @code{print} except that the expression's value is
17842not printed and is not put in the value history (@pxref{Value History,
79a6e687 17843,Value History}). The expression is evaluated only for its effects.
c906108c 17844
c906108c
SS
17845If the beginning of the argument string of the @code{set} command
17846appears identical to a @code{set} subcommand, use the @code{set
17847variable} command instead of just @code{set}. This command is identical
17848to @code{set} except for its lack of subcommands. For example, if your
17849program has a variable @code{width}, you get an error if you try to set
17850a new value with just @samp{set width=13}, because @value{GDBN} has the
17851command @code{set width}:
17852
474c8240 17853@smallexample
c906108c
SS
17854(@value{GDBP}) whatis width
17855type = double
17856(@value{GDBP}) p width
17857$4 = 13
17858(@value{GDBP}) set width=47
17859Invalid syntax in expression.
474c8240 17860@end smallexample
c906108c
SS
17861
17862@noindent
17863The invalid expression, of course, is @samp{=47}. In
17864order to actually set the program's variable @code{width}, use
17865
474c8240 17866@smallexample
c906108c 17867(@value{GDBP}) set var width=47
474c8240 17868@end smallexample
53a5351d 17869
c906108c
SS
17870Because the @code{set} command has many subcommands that can conflict
17871with the names of program variables, it is a good idea to use the
17872@code{set variable} command instead of just @code{set}. For example, if
17873your program has a variable @code{g}, you run into problems if you try
17874to set a new value with just @samp{set g=4}, because @value{GDBN} has
17875the command @code{set gnutarget}, abbreviated @code{set g}:
17876
474c8240 17877@smallexample
c906108c
SS
17878@group
17879(@value{GDBP}) whatis g
17880type = double
17881(@value{GDBP}) p g
17882$1 = 1
17883(@value{GDBP}) set g=4
2df3850c 17884(@value{GDBP}) p g
c906108c
SS
17885$2 = 1
17886(@value{GDBP}) r
17887The program being debugged has been started already.
17888Start it from the beginning? (y or n) y
17889Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
17890"/home/smith/cc_progs/a.out": can't open to read symbols:
17891 Invalid bfd target.
c906108c
SS
17892(@value{GDBP}) show g
17893The current BFD target is "=4".
17894@end group
474c8240 17895@end smallexample
c906108c
SS
17896
17897@noindent
17898The program variable @code{g} did not change, and you silently set the
17899@code{gnutarget} to an invalid value. In order to set the variable
17900@code{g}, use
17901
474c8240 17902@smallexample
c906108c 17903(@value{GDBP}) set var g=4
474c8240 17904@end smallexample
c906108c
SS
17905
17906@value{GDBN} allows more implicit conversions in assignments than C; you can
17907freely store an integer value into a pointer variable or vice versa,
17908and you can convert any structure to any other structure that is the
17909same length or shorter.
17910@comment FIXME: how do structs align/pad in these conversions?
17911@comment /doc@cygnus.com 18dec1990
17912
17913To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
17914construct to generate a value of specified type at a specified address
17915(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
17916to memory location @code{0x83040} as an integer (which implies a certain size
17917and representation in memory), and
17918
474c8240 17919@smallexample
c906108c 17920set @{int@}0x83040 = 4
474c8240 17921@end smallexample
c906108c
SS
17922
17923@noindent
17924stores the value 4 into that memory location.
17925
6d2ebf8b 17926@node Jumping
79a6e687 17927@section Continuing at a Different Address
c906108c
SS
17928
17929Ordinarily, when you continue your program, you do so at the place where
17930it stopped, with the @code{continue} command. You can instead continue at
17931an address of your own choosing, with the following commands:
17932
17933@table @code
17934@kindex jump
c1d780c2 17935@kindex j @r{(@code{jump})}
629500fa 17936@item jump @var{location}
c1d780c2 17937@itemx j @var{location}
629500fa
KS
17938Resume execution at @var{location}. Execution stops again immediately
17939if there is a breakpoint there. @xref{Specify Location}, for a description
17940of the different forms of @var{location}. It is common
2a25a5ba
EZ
17941practice to use the @code{tbreak} command in conjunction with
17942@code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
c906108c
SS
17943
17944The @code{jump} command does not change the current stack frame, or
17945the stack pointer, or the contents of any memory location or any
629500fa 17946register other than the program counter. If @var{location} is in
c906108c
SS
17947a different function from the one currently executing, the results may
17948be bizarre if the two functions expect different patterns of arguments or
17949of local variables. For this reason, the @code{jump} command requests
17950confirmation if the specified line is not in the function currently
17951executing. However, even bizarre results are predictable if you are
17952well acquainted with the machine-language code of your program.
c906108c
SS
17953@end table
17954
53a5351d
JM
17955On many systems, you can get much the same effect as the @code{jump}
17956command by storing a new value into the register @code{$pc}. The
17957difference is that this does not start your program running; it only
17958changes the address of where it @emph{will} run when you continue. For
17959example,
c906108c 17960
474c8240 17961@smallexample
c906108c 17962set $pc = 0x485
474c8240 17963@end smallexample
c906108c
SS
17964
17965@noindent
17966makes the next @code{continue} command or stepping command execute at
17967address @code{0x485}, rather than at the address where your program stopped.
79a6e687 17968@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
17969
17970The most common occasion to use the @code{jump} command is to back
17971up---perhaps with more breakpoints set---over a portion of a program
17972that has already executed, in order to examine its execution in more
17973detail.
17974
c906108c 17975@c @group
6d2ebf8b 17976@node Signaling
79a6e687 17977@section Giving your Program a Signal
9c16f35a 17978@cindex deliver a signal to a program
c906108c
SS
17979
17980@table @code
17981@kindex signal
17982@item signal @var{signal}
70509625 17983Resume execution where your program is stopped, but immediately give it the
697aa1b7 17984signal @var{signal}. The @var{signal} can be the name or the number of a
c906108c
SS
17985signal. For example, on many systems @code{signal 2} and @code{signal
17986SIGINT} are both ways of sending an interrupt signal.
17987
17988Alternatively, if @var{signal} is zero, continue execution without
17989giving a signal. This is useful when your program stopped on account of
ae606bee 17990a signal and would ordinarily see the signal when resumed with the
c906108c
SS
17991@code{continue} command; @samp{signal 0} causes it to resume without a
17992signal.
17993
70509625
PA
17994@emph{Note:} When resuming a multi-threaded program, @var{signal} is
17995delivered to the currently selected thread, not the thread that last
17996reported a stop. This includes the situation where a thread was
17997stopped due to a signal. So if you want to continue execution
17998suppressing the signal that stopped a thread, you should select that
17999same thread before issuing the @samp{signal 0} command. If you issue
18000the @samp{signal 0} command with another thread as the selected one,
18001@value{GDBN} detects that and asks for confirmation.
18002
c906108c
SS
18003Invoking the @code{signal} command is not the same as invoking the
18004@code{kill} utility from the shell. Sending a signal with @code{kill}
18005causes @value{GDBN} to decide what to do with the signal depending on
18006the signal handling tables (@pxref{Signals}). The @code{signal} command
18007passes the signal directly to your program.
18008
81219e53
DE
18009@code{signal} does not repeat when you press @key{RET} a second time
18010after executing the command.
18011
18012@kindex queue-signal
18013@item queue-signal @var{signal}
18014Queue @var{signal} to be delivered immediately to the current thread
18015when execution of the thread resumes. The @var{signal} can be the name or
18016the number of a signal. For example, on many systems @code{signal 2} and
18017@code{signal SIGINT} are both ways of sending an interrupt signal.
18018The handling of the signal must be set to pass the signal to the program,
18019otherwise @value{GDBN} will report an error.
18020You can control the handling of signals from @value{GDBN} with the
18021@code{handle} command (@pxref{Signals}).
18022
18023Alternatively, if @var{signal} is zero, any currently queued signal
18024for the current thread is discarded and when execution resumes no signal
18025will be delivered. This is useful when your program stopped on account
18026of a signal and would ordinarily see the signal when resumed with the
18027@code{continue} command.
18028
18029This command differs from the @code{signal} command in that the signal
18030is just queued, execution is not resumed. And @code{queue-signal} cannot
18031be used to pass a signal whose handling state has been set to @code{nopass}
18032(@pxref{Signals}).
18033@end table
18034@c @end group
c906108c 18035
e5f8a7cc
PA
18036@xref{stepping into signal handlers}, for information on how stepping
18037commands behave when the thread has a signal queued.
18038
6d2ebf8b 18039@node Returning
79a6e687 18040@section Returning from a Function
c906108c
SS
18041
18042@table @code
18043@cindex returning from a function
18044@kindex return
18045@item return
18046@itemx return @var{expression}
18047You can cancel execution of a function call with the @code{return}
18048command. If you give an
18049@var{expression} argument, its value is used as the function's return
18050value.
18051@end table
18052
18053When you use @code{return}, @value{GDBN} discards the selected stack frame
18054(and all frames within it). You can think of this as making the
18055discarded frame return prematurely. If you wish to specify a value to
18056be returned, give that value as the argument to @code{return}.
18057
18058This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 18059Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
18060innermost remaining frame. That frame becomes selected. The
18061specified value is stored in the registers used for returning values
18062of functions.
18063
18064The @code{return} command does not resume execution; it leaves the
18065program stopped in the state that would exist if the function had just
18066returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 18067and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
18068selected stack frame returns naturally.
18069
61ff14c6
JK
18070@value{GDBN} needs to know how the @var{expression} argument should be set for
18071the inferior. The concrete registers assignment depends on the OS ABI and the
18072type being returned by the selected stack frame. For example it is common for
18073OS ABI to return floating point values in FPU registers while integer values in
18074CPU registers. Still some ABIs return even floating point values in CPU
18075registers. Larger integer widths (such as @code{long long int}) also have
18076specific placement rules. @value{GDBN} already knows the OS ABI from its
18077current target so it needs to find out also the type being returned to make the
18078assignment into the right register(s).
18079
18080Normally, the selected stack frame has debug info. @value{GDBN} will always
18081use the debug info instead of the implicit type of @var{expression} when the
18082debug info is available. For example, if you type @kbd{return -1}, and the
18083function in the current stack frame is declared to return a @code{long long
18084int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
18085into a @code{long long int}:
18086
18087@smallexample
18088Breakpoint 1, func () at gdb.base/return-nodebug.c:29
1808929 return 31;
18090(@value{GDBP}) return -1
18091Make func return now? (y or n) y
18092#0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
1809343 printf ("result=%lld\n", func ());
18094(@value{GDBP})
18095@end smallexample
18096
18097However, if the selected stack frame does not have a debug info, e.g., if the
18098function was compiled without debug info, @value{GDBN} has to find out the type
18099to return from user. Specifying a different type by mistake may set the value
18100in different inferior registers than the caller code expects. For example,
18101typing @kbd{return -1} with its implicit type @code{int} would set only a part
18102of a @code{long long int} result for a debug info less function (on 32-bit
18103architectures). Therefore the user is required to specify the return type by
18104an appropriate cast explicitly:
18105
18106@smallexample
18107Breakpoint 2, 0x0040050b in func ()
18108(@value{GDBP}) return -1
18109Return value type not available for selected stack frame.
18110Please use an explicit cast of the value to return.
18111(@value{GDBP}) return (long long int) -1
18112Make selected stack frame return now? (y or n) y
18113#0 0x00400526 in main ()
18114(@value{GDBP})
18115@end smallexample
18116
6d2ebf8b 18117@node Calling
79a6e687 18118@section Calling Program Functions
c906108c 18119
f8568604 18120@table @code
c906108c 18121@cindex calling functions
f8568604
EZ
18122@cindex inferior functions, calling
18123@item print @var{expr}
d3e8051b 18124Evaluate the expression @var{expr} and display the resulting value.
697aa1b7 18125The expression may include calls to functions in the program being
f8568604
EZ
18126debugged.
18127
c906108c 18128@kindex call
c906108c
SS
18129@item call @var{expr}
18130Evaluate the expression @var{expr} without displaying @code{void}
18131returned values.
c906108c
SS
18132
18133You can use this variant of the @code{print} command if you want to
f8568604
EZ
18134execute a function from your program that does not return anything
18135(a.k.a.@: @dfn{a void function}), but without cluttering the output
18136with @code{void} returned values that @value{GDBN} will otherwise
18137print. If the result is not void, it is printed and saved in the
18138value history.
18139@end table
18140
9c16f35a
EZ
18141It is possible for the function you call via the @code{print} or
18142@code{call} command to generate a signal (e.g., if there's a bug in
18143the function, or if you passed it incorrect arguments). What happens
18144in that case is controlled by the @code{set unwindonsignal} command.
18145
7cd1089b
PM
18146Similarly, with a C@t{++} program it is possible for the function you
18147call via the @code{print} or @code{call} command to generate an
18148exception that is not handled due to the constraints of the dummy
18149frame. In this case, any exception that is raised in the frame, but has
18150an out-of-frame exception handler will not be found. GDB builds a
18151dummy-frame for the inferior function call, and the unwinder cannot
18152seek for exception handlers outside of this dummy-frame. What happens
18153in that case is controlled by the
18154@code{set unwind-on-terminating-exception} command.
18155
9c16f35a
EZ
18156@table @code
18157@item set unwindonsignal
18158@kindex set unwindonsignal
18159@cindex unwind stack in called functions
18160@cindex call dummy stack unwinding
18161Set unwinding of the stack if a signal is received while in a function
18162that @value{GDBN} called in the program being debugged. If set to on,
18163@value{GDBN} unwinds the stack it created for the call and restores
18164the context to what it was before the call. If set to off (the
18165default), @value{GDBN} stops in the frame where the signal was
18166received.
18167
18168@item show unwindonsignal
18169@kindex show unwindonsignal
18170Show the current setting of stack unwinding in the functions called by
18171@value{GDBN}.
7cd1089b
PM
18172
18173@item set unwind-on-terminating-exception
18174@kindex set unwind-on-terminating-exception
18175@cindex unwind stack in called functions with unhandled exceptions
18176@cindex call dummy stack unwinding on unhandled exception.
18177Set unwinding of the stack if a C@t{++} exception is raised, but left
18178unhandled while in a function that @value{GDBN} called in the program being
18179debugged. If set to on (the default), @value{GDBN} unwinds the stack
18180it created for the call and restores the context to what it was before
18181the call. If set to off, @value{GDBN} the exception is delivered to
18182the default C@t{++} exception handler and the inferior terminated.
18183
18184@item show unwind-on-terminating-exception
18185@kindex show unwind-on-terminating-exception
18186Show the current setting of stack unwinding in the functions called by
18187@value{GDBN}.
18188
9c16f35a
EZ
18189@end table
18190
d69cf9b2
PA
18191@subsection Calling functions with no debug info
18192
18193@cindex no debug info functions
18194Sometimes, a function you wish to call is missing debug information.
18195In such case, @value{GDBN} does not know the type of the function,
18196including the types of the function's parameters. To avoid calling
18197the inferior function incorrectly, which could result in the called
18198function functioning erroneously and even crash, @value{GDBN} refuses
18199to call the function unless you tell it the type of the function.
18200
18201For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
18202to do that. The simplest is to cast the call to the function's
18203declared return type. For example:
18204
18205@smallexample
18206(@value{GDBP}) p getenv ("PATH")
18207'getenv' has unknown return type; cast the call to its declared return type
18208(@value{GDBP}) p (char *) getenv ("PATH")
18209$1 = 0x7fffffffe7ba "/usr/local/bin:/"...
18210@end smallexample
18211
18212Casting the return type of a no-debug function is equivalent to
18213casting the function to a pointer to a prototyped function that has a
18214prototype that matches the types of the passed-in arguments, and
18215calling that. I.e., the call above is equivalent to:
18216
18217@smallexample
18218(@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
18219@end smallexample
18220
18221@noindent
18222and given this prototyped C or C++ function with float parameters:
18223
18224@smallexample
18225float multiply (float v1, float v2) @{ return v1 * v2; @}
18226@end smallexample
18227
18228@noindent
18229these calls are equivalent:
18230
18231@smallexample
18232(@value{GDBP}) p (float) multiply (2.0f, 3.0f)
18233(@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
18234@end smallexample
18235
18236If the function you wish to call is declared as unprototyped (i.e.@:
18237old K&R style), you must use the cast-to-function-pointer syntax, so
18238that @value{GDBN} knows that it needs to apply default argument
18239promotions (promote float arguments to double). @xref{ABI, float
18240promotion}. For example, given this unprototyped C function with
18241float parameters, and no debug info:
18242
18243@smallexample
18244float
18245multiply_noproto (v1, v2)
18246 float v1, v2;
18247@{
18248 return v1 * v2;
18249@}
18250@end smallexample
18251
18252@noindent
18253you call it like this:
18254
18255@smallexample
18256 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
18257@end smallexample
c906108c 18258
6d2ebf8b 18259@node Patching
79a6e687 18260@section Patching Programs
7a292a7a 18261
c906108c
SS
18262@cindex patching binaries
18263@cindex writing into executables
c906108c 18264@cindex writing into corefiles
c906108c 18265
7a292a7a
SS
18266By default, @value{GDBN} opens the file containing your program's
18267executable code (or the corefile) read-only. This prevents accidental
18268alterations to machine code; but it also prevents you from intentionally
18269patching your program's binary.
c906108c
SS
18270
18271If you'd like to be able to patch the binary, you can specify that
18272explicitly with the @code{set write} command. For example, you might
18273want to turn on internal debugging flags, or even to make emergency
18274repairs.
18275
18276@table @code
18277@kindex set write
18278@item set write on
18279@itemx set write off
7a292a7a 18280If you specify @samp{set write on}, @value{GDBN} opens executable and
20924a55 18281core files for both reading and writing; if you specify @kbd{set write
c906108c
SS
18282off} (the default), @value{GDBN} opens them read-only.
18283
18284If you have already loaded a file, you must load it again (using the
7a292a7a
SS
18285@code{exec-file} or @code{core-file} command) after changing @code{set
18286write}, for your new setting to take effect.
c906108c
SS
18287
18288@item show write
18289@kindex show write
7a292a7a
SS
18290Display whether executable files and core files are opened for writing
18291as well as reading.
c906108c
SS
18292@end table
18293
bb2ec1b3
TT
18294@node Compiling and Injecting Code
18295@section Compiling and injecting code in @value{GDBN}
18296@cindex injecting code
18297@cindex writing into executables
18298@cindex compiling code
18299
18300@value{GDBN} supports on-demand compilation and code injection into
18301programs running under @value{GDBN}. GCC 5.0 or higher built with
18302@file{libcc1.so} must be installed for this functionality to be enabled.
18303This functionality is implemented with the following commands.
18304
18305@table @code
18306@kindex compile code
18307@item compile code @var{source-code}
18308@itemx compile code -raw @var{--} @var{source-code}
18309Compile @var{source-code} with the compiler language found as the current
18310language in @value{GDBN} (@pxref{Languages}). If compilation and
18311injection is not supported with the current language specified in
18312@value{GDBN}, or the compiler does not support this feature, an error
18313message will be printed. If @var{source-code} compiles and links
18314successfully, @value{GDBN} will load the object-code emitted,
18315and execute it within the context of the currently selected inferior.
18316It is important to note that the compiled code is executed immediately.
18317After execution, the compiled code is removed from @value{GDBN} and any
18318new types or variables you have defined will be deleted.
18319
18320The command allows you to specify @var{source-code} in two ways.
18321The simplest method is to provide a single line of code to the command.
18322E.g.:
18323
18324@smallexample
18325compile code printf ("hello world\n");
18326@end smallexample
18327
18328If you specify options on the command line as well as source code, they
18329may conflict. The @samp{--} delimiter can be used to separate options
18330from actual source code. E.g.:
18331
18332@smallexample
18333compile code -r -- printf ("hello world\n");
18334@end smallexample
18335
18336Alternatively you can enter source code as multiple lines of text. To
18337enter this mode, invoke the @samp{compile code} command without any text
18338following the command. This will start the multiple-line editor and
18339allow you to type as many lines of source code as required. When you
18340have completed typing, enter @samp{end} on its own line to exit the
18341editor.
18342
18343@smallexample
18344compile code
18345>printf ("hello\n");
18346>printf ("world\n");
18347>end
18348@end smallexample
18349
18350Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
18351provided @var{source-code} in a callable scope. In this case, you must
18352specify the entry point of the code by defining a function named
18353@code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
18354inferior. Using @samp{-raw} option may be needed for example when
18355@var{source-code} requires @samp{#include} lines which may conflict with
18356inferior symbols otherwise.
18357
18358@kindex compile file
18359@item compile file @var{filename}
18360@itemx compile file -raw @var{filename}
18361Like @code{compile code}, but take the source code from @var{filename}.
18362
18363@smallexample
18364compile file /home/user/example.c
18365@end smallexample
18366@end table
18367
36de76f9
JK
18368@table @code
18369@item compile print @var{expr}
18370@itemx compile print /@var{f} @var{expr}
18371Compile and execute @var{expr} with the compiler language found as the
18372current language in @value{GDBN} (@pxref{Languages}). By default the
18373value of @var{expr} is printed in a format appropriate to its data type;
18374you can choose a different format by specifying @samp{/@var{f}}, where
18375@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
18376Formats}.
18377
18378@item compile print
18379@itemx compile print /@var{f}
18380@cindex reprint the last value
18381Alternatively you can enter the expression (source code producing it) as
18382multiple lines of text. To enter this mode, invoke the @samp{compile print}
18383command without any text following the command. This will start the
18384multiple-line editor.
18385@end table
18386
e7a8570f
JK
18387@noindent
18388The process of compiling and injecting the code can be inspected using:
18389
18390@table @code
18391@anchor{set debug compile}
18392@item set debug compile
18393@cindex compile command debugging info
18394Turns on or off display of @value{GDBN} process of compiling and
18395injecting the code. The default is off.
18396
18397@item show debug compile
18398Displays the current state of displaying @value{GDBN} process of
18399compiling and injecting the code.
18400@end table
18401
18402@subsection Compilation options for the @code{compile} command
18403
18404@value{GDBN} needs to specify the right compilation options for the code
18405to be injected, in part to make its ABI compatible with the inferior
18406and in part to make the injected code compatible with @value{GDBN}'s
18407injecting process.
18408
18409@noindent
18410The options used, in increasing precedence:
18411
18412@table @asis
18413@item target architecture and OS options (@code{gdbarch})
18414These options depend on target processor type and target operating
18415system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
18416(@code{-m64}) compilation option.
18417
18418@item compilation options recorded in the target
18419@value{NGCC} (since version 4.7) stores the options used for compilation
18420into @code{DW_AT_producer} part of DWARF debugging information according
18421to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
18422explicitly specify @code{-g} during inferior compilation otherwise
18423@value{NGCC} produces no DWARF. This feature is only relevant for
18424platforms where @code{-g} produces DWARF by default, otherwise one may
18425try to enforce DWARF by using @code{-gdwarf-4}.
18426
18427@item compilation options set by @code{set compile-args}
18428@end table
18429
18430@noindent
18431You can override compilation options using the following command:
18432
18433@table @code
18434@item set compile-args
18435@cindex compile command options override
18436Set compilation options used for compiling and injecting code with the
18437@code{compile} commands. These options override any conflicting ones
18438from the target architecture and/or options stored during inferior
18439compilation.
18440
18441@item show compile-args
18442Displays the current state of compilation options override.
18443This does not show all the options actually used during compilation,
18444use @ref{set debug compile} for that.
18445@end table
18446
bb2ec1b3
TT
18447@subsection Caveats when using the @code{compile} command
18448
18449There are a few caveats to keep in mind when using the @code{compile}
18450command. As the caveats are different per language, the table below
18451highlights specific issues on a per language basis.
18452
18453@table @asis
18454@item C code examples and caveats
18455When the language in @value{GDBN} is set to @samp{C}, the compiler will
18456attempt to compile the source code with a @samp{C} compiler. The source
18457code provided to the @code{compile} command will have much the same
18458access to variables and types as it normally would if it were part of
18459the program currently being debugged in @value{GDBN}.
18460
18461Below is a sample program that forms the basis of the examples that
18462follow. This program has been compiled and loaded into @value{GDBN},
18463much like any other normal debugging session.
18464
18465@smallexample
18466void function1 (void)
18467@{
18468 int i = 42;
18469 printf ("function 1\n");
18470@}
18471
18472void function2 (void)
18473@{
18474 int j = 12;
18475 function1 ();
18476@}
18477
18478int main(void)
18479@{
18480 int k = 6;
18481 int *p;
18482 function2 ();
18483 return 0;
18484@}
18485@end smallexample
18486
18487For the purposes of the examples in this section, the program above has
18488been compiled, loaded into @value{GDBN}, stopped at the function
18489@code{main}, and @value{GDBN} is awaiting input from the user.
18490
18491To access variables and types for any program in @value{GDBN}, the
18492program must be compiled and packaged with debug information. The
18493@code{compile} command is not an exception to this rule. Without debug
18494information, you can still use the @code{compile} command, but you will
18495be very limited in what variables and types you can access.
18496
18497So with that in mind, the example above has been compiled with debug
18498information enabled. The @code{compile} command will have access to
18499all variables and types (except those that may have been optimized
18500out). Currently, as @value{GDBN} has stopped the program in the
18501@code{main} function, the @code{compile} command would have access to
18502the variable @code{k}. You could invoke the @code{compile} command
18503and type some source code to set the value of @code{k}. You can also
18504read it, or do anything with that variable you would normally do in
18505@code{C}. Be aware that changes to inferior variables in the
18506@code{compile} command are persistent. In the following example:
18507
18508@smallexample
18509compile code k = 3;
18510@end smallexample
18511
18512@noindent
18513the variable @code{k} is now 3. It will retain that value until
18514something else in the example program changes it, or another
18515@code{compile} command changes it.
18516
18517Normal scope and access rules apply to source code compiled and
18518injected by the @code{compile} command. In the example, the variables
18519@code{j} and @code{k} are not accessible yet, because the program is
18520currently stopped in the @code{main} function, where these variables
18521are not in scope. Therefore, the following command
18522
18523@smallexample
18524compile code j = 3;
18525@end smallexample
18526
18527@noindent
18528will result in a compilation error message.
18529
18530Once the program is continued, execution will bring these variables in
18531scope, and they will become accessible; then the code you specify via
18532the @code{compile} command will be able to access them.
18533
18534You can create variables and types with the @code{compile} command as
18535part of your source code. Variables and types that are created as part
18536of the @code{compile} command are not visible to the rest of the program for
18537the duration of its run. This example is valid:
18538
18539@smallexample
18540compile code int ff = 5; printf ("ff is %d\n", ff);
18541@end smallexample
18542
18543However, if you were to type the following into @value{GDBN} after that
18544command has completed:
18545
18546@smallexample
18547compile code printf ("ff is %d\n'', ff);
18548@end smallexample
18549
18550@noindent
18551a compiler error would be raised as the variable @code{ff} no longer
18552exists. Object code generated and injected by the @code{compile}
18553command is removed when its execution ends. Caution is advised
18554when assigning to program variables values of variables created by the
18555code submitted to the @code{compile} command. This example is valid:
18556
18557@smallexample
18558compile code int ff = 5; k = ff;
18559@end smallexample
18560
18561The value of the variable @code{ff} is assigned to @code{k}. The variable
18562@code{k} does not require the existence of @code{ff} to maintain the value
18563it has been assigned. However, pointers require particular care in
18564assignment. If the source code compiled with the @code{compile} command
18565changed the address of a pointer in the example program, perhaps to a
18566variable created in the @code{compile} command, that pointer would point
18567to an invalid location when the command exits. The following example
18568would likely cause issues with your debugged program:
18569
18570@smallexample
18571compile code int ff = 5; p = &ff;
18572@end smallexample
18573
18574In this example, @code{p} would point to @code{ff} when the
18575@code{compile} command is executing the source code provided to it.
18576However, as variables in the (example) program persist with their
18577assigned values, the variable @code{p} would point to an invalid
18578location when the command exists. A general rule should be followed
18579in that you should either assign @code{NULL} to any assigned pointers,
18580or restore a valid location to the pointer before the command exits.
18581
18582Similar caution must be exercised with any structs, unions, and typedefs
18583defined in @code{compile} command. Types defined in the @code{compile}
18584command will no longer be available in the next @code{compile} command.
18585Therefore, if you cast a variable to a type defined in the
18586@code{compile} command, care must be taken to ensure that any future
18587need to resolve the type can be achieved.
18588
18589@smallexample
18590(gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
18591(gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
18592gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
18593Compilation failed.
18594(gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
1859542
18596@end smallexample
18597
18598Variables that have been optimized away by the compiler are not
18599accessible to the code submitted to the @code{compile} command.
18600Access to those variables will generate a compiler error which @value{GDBN}
18601will print to the console.
18602@end table
18603
e7a8570f
JK
18604@subsection Compiler search for the @code{compile} command
18605
6e41ddec
JK
18606@value{GDBN} needs to find @value{NGCC} for the inferior being debugged
18607which may not be obvious for remote targets of different architecture
18608than where @value{GDBN} is running. Environment variable @code{PATH} on
e7a8570f 18609@value{GDBN} host is searched for @value{NGCC} binary matching the
6e41ddec
JK
18610target architecture and operating system. This search can be overriden
18611by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is
18612taken from shell that executed @value{GDBN}, it is not the value set by
18613@value{GDBN} command @code{set environment}). @xref{Environment}.
18614
e7a8570f
JK
18615
18616Specifically @code{PATH} is searched for binaries matching regular expression
18617@code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
18618debugged. @var{arch} is processor name --- multiarch is supported, so for
18619example both @code{i386} and @code{x86_64} targets look for pattern
18620@code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
18621for pattern @code{s390x?}. @var{os} is currently supported only for
18622pattern @code{linux(-gnu)?}.
18623
6e41ddec
JK
18624On Posix hosts the compiler driver @value{GDBN} needs to find also
18625shared library @file{libcc1.so} from the compiler. It is searched in
18626default shared library search path (overridable with usual environment
18627variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set
18628compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
18629according to the installation of the found compiler --- as possibly
18630specified by the @code{set compile-gcc} command.
18631
18632@table @code
18633@item set compile-gcc
18634@cindex compile command driver filename override
18635Set compilation command used for compiling and injecting code with the
18636@code{compile} commands. If this option is not set (it is set to
18637an empty string), the search described above will occur --- that is the
18638default.
18639
18640@item show compile-gcc
18641Displays the current compile command @value{NGCC} driver filename.
18642If set, it is the main command @command{gcc}, found usually for example
18643under name @file{x86_64-linux-gnu-gcc}.
18644@end table
18645
6d2ebf8b 18646@node GDB Files
c906108c
SS
18647@chapter @value{GDBN} Files
18648
7a292a7a
SS
18649@value{GDBN} needs to know the file name of the program to be debugged,
18650both in order to read its symbol table and in order to start your
18651program. To debug a core dump of a previous run, you must also tell
18652@value{GDBN} the name of the core dump file.
c906108c
SS
18653
18654@menu
18655* Files:: Commands to specify files
2b4bf6af 18656* File Caching:: Information about @value{GDBN}'s file caching
5b5d99cf 18657* Separate Debug Files:: Debugging information in separate files
608e2dbb 18658* MiniDebugInfo:: Debugging information in a special section
9291a0cd 18659* Index Files:: Index files speed up GDB
c906108c 18660* Symbol Errors:: Errors reading symbol files
b14b1491 18661* Data Files:: GDB data files
c906108c
SS
18662@end menu
18663
6d2ebf8b 18664@node Files
79a6e687 18665@section Commands to Specify Files
c906108c 18666
7a292a7a 18667@cindex symbol table
c906108c 18668@cindex core dump file
7a292a7a
SS
18669
18670You may want to specify executable and core dump file names. The usual
18671way to do this is at start-up time, using the arguments to
18672@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
18673Out of @value{GDBN}}).
c906108c
SS
18674
18675Occasionally it is necessary to change to a different file during a
397ca115
EZ
18676@value{GDBN} session. Or you may run @value{GDBN} and forget to
18677specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
18678via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
18679Program}). In these situations the @value{GDBN} commands to specify
0869d01b 18680new files are useful.
c906108c
SS
18681
18682@table @code
18683@cindex executable file
18684@kindex file
18685@item file @var{filename}
18686Use @var{filename} as the program to be debugged. It is read for its
18687symbols and for the contents of pure memory. It is also the program
18688executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
18689directory and the file is not found in the @value{GDBN} working directory,
18690@value{GDBN} uses the environment variable @code{PATH} as a list of
18691directories to search, just as the shell does when looking for a program
18692to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
18693and your program, using the @code{path} command.
18694
fc8be69e
EZ
18695@cindex unlinked object files
18696@cindex patching object files
18697You can load unlinked object @file{.o} files into @value{GDBN} using
18698the @code{file} command. You will not be able to ``run'' an object
18699file, but you can disassemble functions and inspect variables. Also,
18700if the underlying BFD functionality supports it, you could use
18701@kbd{gdb -write} to patch object files using this technique. Note
18702that @value{GDBN} can neither interpret nor modify relocations in this
18703case, so branches and some initialized variables will appear to go to
18704the wrong place. But this feature is still handy from time to time.
18705
c906108c
SS
18706@item file
18707@code{file} with no argument makes @value{GDBN} discard any information it
18708has on both executable file and the symbol table.
18709
18710@kindex exec-file
18711@item exec-file @r{[} @var{filename} @r{]}
18712Specify that the program to be run (but not the symbol table) is found
18713in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
18714if necessary to locate your program. Omitting @var{filename} means to
18715discard information on the executable file.
18716
18717@kindex symbol-file
18718@item symbol-file @r{[} @var{filename} @r{]}
18719Read symbol table information from file @var{filename}. @code{PATH} is
18720searched when necessary. Use the @code{file} command to get both symbol
18721table and program to run from the same file.
18722
18723@code{symbol-file} with no argument clears out @value{GDBN} information on your
18724program's symbol table.
18725
ae5a43e0
DJ
18726The @code{symbol-file} command causes @value{GDBN} to forget the contents of
18727some breakpoints and auto-display expressions. This is because they may
18728contain pointers to the internal data recording symbols and data types,
18729which are part of the old symbol table data being discarded inside
18730@value{GDBN}.
c906108c
SS
18731
18732@code{symbol-file} does not repeat if you press @key{RET} again after
18733executing it once.
18734
18735When @value{GDBN} is configured for a particular environment, it
18736understands debugging information in whatever format is the standard
18737generated for that environment; you may use either a @sc{gnu} compiler, or
18738other compilers that adhere to the local conventions.
c906108c 18739Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 18740using @code{@value{NGCC}} you can generate debugging information for
c906108c 18741optimized code.
c906108c
SS
18742
18743For most kinds of object files, with the exception of old SVR3 systems
18744using COFF, the @code{symbol-file} command does not normally read the
18745symbol table in full right away. Instead, it scans the symbol table
18746quickly to find which source files and which symbols are present. The
18747details are read later, one source file at a time, as they are needed.
18748
18749The purpose of this two-stage reading strategy is to make @value{GDBN}
18750start up faster. For the most part, it is invisible except for
18751occasional pauses while the symbol table details for a particular source
18752file are being read. (The @code{set verbose} command can turn these
18753pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 18754Warnings and Messages}.)
c906108c 18755
c906108c
SS
18756We have not implemented the two-stage strategy for COFF yet. When the
18757symbol table is stored in COFF format, @code{symbol-file} reads the
18758symbol table data in full right away. Note that ``stabs-in-COFF''
18759still does the two-stage strategy, since the debug info is actually
18760in stabs format.
18761
18762@kindex readnow
18763@cindex reading symbols immediately
18764@cindex symbols, reading immediately
6ac33a4e
TT
18765@item symbol-file @r{[} -readnow @r{]} @var{filename}
18766@itemx file @r{[} -readnow @r{]} @var{filename}
c906108c
SS
18767You can override the @value{GDBN} two-stage strategy for reading symbol
18768tables by using the @samp{-readnow} option with any of the commands that
18769load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 18770entire symbol table available.
c906108c 18771
97cbe998
SDJ
18772@cindex @code{-readnever}, option for symbol-file command
18773@cindex never read symbols
18774@cindex symbols, never read
18775@item symbol-file @r{[} -readnever @r{]} @var{filename}
18776@itemx file @r{[} -readnever @r{]} @var{filename}
18777You can instruct @value{GDBN} to never read the symbolic information
18778contained in @var{filename} by using the @samp{-readnever} option.
18779@xref{--readnever}.
18780
c906108c
SS
18781@c FIXME: for now no mention of directories, since this seems to be in
18782@c flux. 13mar1992 status is that in theory GDB would look either in
18783@c current dir or in same dir as myprog; but issues like competing
18784@c GDB's, or clutter in system dirs, mean that in practice right now
18785@c only current dir is used. FFish says maybe a special GDB hierarchy
18786@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
18787@c files.
18788
c906108c 18789@kindex core-file
09d4efe1 18790@item core-file @r{[}@var{filename}@r{]}
4644b6e3 18791@itemx core
c906108c
SS
18792Specify the whereabouts of a core dump file to be used as the ``contents
18793of memory''. Traditionally, core files contain only some parts of the
18794address space of the process that generated them; @value{GDBN} can access the
18795executable file itself for other parts.
18796
18797@code{core-file} with no argument specifies that no core file is
18798to be used.
18799
18800Note that the core file is ignored when your program is actually running
7a292a7a
SS
18801under @value{GDBN}. So, if you have been running your program and you
18802wish to debug a core file instead, you must kill the subprocess in which
18803the program is running. To do this, use the @code{kill} command
79a6e687 18804(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 18805
c906108c
SS
18806@kindex add-symbol-file
18807@cindex dynamic linking
18808@item add-symbol-file @var{filename} @var{address}
97cbe998 18809@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{|} -readnever @r{]}
24bdad53 18810@itemx add-symbol-file @var{filename} @var{address} -s @var{section} @var{address} @dots{}
96a2c332
SS
18811The @code{add-symbol-file} command reads additional symbol table
18812information from the file @var{filename}. You would use this command
18813when @var{filename} has been dynamically loaded (by some other means)
697aa1b7 18814into the program that is running. The @var{address} should give the memory
96a2c332 18815address at which the file has been loaded; @value{GDBN} cannot figure
d167840f 18816this out for itself. You can additionally specify an arbitrary number
24bdad53 18817of @samp{-s @var{section} @var{address}} pairs, to give an explicit
d167840f
EZ
18818section name and base address for that section. You can specify any
18819@var{address} as an expression.
c906108c
SS
18820
18821The symbol table of the file @var{filename} is added to the symbol table
18822originally read with the @code{symbol-file} command. You can use the
96a2c332 18823@code{add-symbol-file} command any number of times; the new symbol data
98297bf6
NB
18824thus read is kept in addition to the old.
18825
18826Changes can be reverted using the command @code{remove-symbol-file}.
c906108c 18827
17d9d558
JB
18828@cindex relocatable object files, reading symbols from
18829@cindex object files, relocatable, reading symbols from
18830@cindex reading symbols from relocatable object files
18831@cindex symbols, reading from relocatable object files
18832@cindex @file{.o} files, reading symbols from
18833Although @var{filename} is typically a shared library file, an
18834executable file, or some other object file which has been fully
18835relocated for loading into a process, you can also load symbolic
18836information from relocatable @file{.o} files, as long as:
18837
18838@itemize @bullet
18839@item
18840the file's symbolic information refers only to linker symbols defined in
18841that file, not to symbols defined by other object files,
18842@item
18843every section the file's symbolic information refers to has actually
18844been loaded into the inferior, as it appears in the file, and
18845@item
18846you can determine the address at which every section was loaded, and
18847provide these to the @code{add-symbol-file} command.
18848@end itemize
18849
18850@noindent
18851Some embedded operating systems, like Sun Chorus and VxWorks, can load
18852relocatable files into an already running program; such systems
18853typically make the requirements above easy to meet. However, it's
18854important to recognize that many native systems use complex link
49efadf5 18855procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
18856assembly, for example) that make the requirements difficult to meet. In
18857general, one cannot assume that using @code{add-symbol-file} to read a
18858relocatable object file's symbolic information will have the same effect
18859as linking the relocatable object file into the program in the normal
18860way.
18861
c906108c
SS
18862@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
18863
98297bf6
NB
18864@kindex remove-symbol-file
18865@item remove-symbol-file @var{filename}
18866@item remove-symbol-file -a @var{address}
18867Remove a symbol file added via the @code{add-symbol-file} command. The
18868file to remove can be identified by its @var{filename} or by an @var{address}
18869that lies within the boundaries of this symbol file in memory. Example:
18870
18871@smallexample
18872(gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
18873add symbol table from file "/home/user/gdb/mylib.so" at
18874 .text_addr = 0x7ffff7ff9480
18875(y or n) y
18876Reading symbols from /home/user/gdb/mylib.so...done.
18877(gdb) remove-symbol-file -a 0x7ffff7ff9480
18878Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
18879(gdb)
18880@end smallexample
18881
18882
18883@code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
18884
c45da7e6
EZ
18885@kindex add-symbol-file-from-memory
18886@cindex @code{syscall DSO}
18887@cindex load symbols from memory
18888@item add-symbol-file-from-memory @var{address}
18889Load symbols from the given @var{address} in a dynamically loaded
18890object file whose image is mapped directly into the inferior's memory.
18891For example, the Linux kernel maps a @code{syscall DSO} into each
18892process's address space; this DSO provides kernel-specific code for
18893some system calls. The argument can be any expression whose
18894evaluation yields the address of the file's shared object file header.
18895For this command to work, you must have used @code{symbol-file} or
18896@code{exec-file} commands in advance.
18897
c906108c 18898@kindex section
09d4efe1
EZ
18899@item section @var{section} @var{addr}
18900The @code{section} command changes the base address of the named
18901@var{section} of the exec file to @var{addr}. This can be used if the
18902exec file does not contain section addresses, (such as in the
18903@code{a.out} format), or when the addresses specified in the file
18904itself are wrong. Each section must be changed separately. The
18905@code{info files} command, described below, lists all the sections and
18906their addresses.
c906108c
SS
18907
18908@kindex info files
18909@kindex info target
18910@item info files
18911@itemx info target
7a292a7a
SS
18912@code{info files} and @code{info target} are synonymous; both print the
18913current target (@pxref{Targets, ,Specifying a Debugging Target}),
18914including the names of the executable and core dump files currently in
18915use by @value{GDBN}, and the files from which symbols were loaded. The
18916command @code{help target} lists all possible targets rather than
18917current ones.
18918
fe95c787
MS
18919@kindex maint info sections
18920@item maint info sections
18921Another command that can give you extra information about program sections
18922is @code{maint info sections}. In addition to the section information
18923displayed by @code{info files}, this command displays the flags and file
18924offset of each section in the executable and core dump files. In addition,
18925@code{maint info sections} provides the following command options (which
18926may be arbitrarily combined):
18927
18928@table @code
18929@item ALLOBJ
18930Display sections for all loaded object files, including shared libraries.
18931@item @var{sections}
6600abed 18932Display info only for named @var{sections}.
fe95c787
MS
18933@item @var{section-flags}
18934Display info only for sections for which @var{section-flags} are true.
18935The section flags that @value{GDBN} currently knows about are:
18936@table @code
18937@item ALLOC
18938Section will have space allocated in the process when loaded.
18939Set for all sections except those containing debug information.
18940@item LOAD
18941Section will be loaded from the file into the child process memory.
18942Set for pre-initialized code and data, clear for @code{.bss} sections.
18943@item RELOC
18944Section needs to be relocated before loading.
18945@item READONLY
18946Section cannot be modified by the child process.
18947@item CODE
18948Section contains executable code only.
6600abed 18949@item DATA
fe95c787
MS
18950Section contains data only (no executable code).
18951@item ROM
18952Section will reside in ROM.
18953@item CONSTRUCTOR
18954Section contains data for constructor/destructor lists.
18955@item HAS_CONTENTS
18956Section is not empty.
18957@item NEVER_LOAD
18958An instruction to the linker to not output the section.
18959@item COFF_SHARED_LIBRARY
18960A notification to the linker that the section contains
18961COFF shared library information.
18962@item IS_COMMON
18963Section contains common symbols.
18964@end table
18965@end table
6763aef9 18966@kindex set trust-readonly-sections
9c16f35a 18967@cindex read-only sections
6763aef9
MS
18968@item set trust-readonly-sections on
18969Tell @value{GDBN} that readonly sections in your object file
6ca652b0 18970really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
18971In that case, @value{GDBN} can fetch values from these sections
18972out of the object file, rather than from the target program.
18973For some targets (notably embedded ones), this can be a significant
18974enhancement to debugging performance.
18975
18976The default is off.
18977
18978@item set trust-readonly-sections off
15110bc3 18979Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
18980the contents of the section might change while the program is running,
18981and must therefore be fetched from the target when needed.
9c16f35a
EZ
18982
18983@item show trust-readonly-sections
18984Show the current setting of trusting readonly sections.
c906108c
SS
18985@end table
18986
18987All file-specifying commands allow both absolute and relative file names
18988as arguments. @value{GDBN} always converts the file name to an absolute file
18989name and remembers it that way.
18990
c906108c 18991@cindex shared libraries
9cceb671 18992@anchor{Shared Libraries}
b1236ac3
PA
18993@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
18994Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
18995DSBT (TIC6X) shared libraries.
53a5351d 18996
9cceb671
DJ
18997On MS-Windows @value{GDBN} must be linked with the Expat library to support
18998shared libraries. @xref{Expat}.
18999
c906108c
SS
19000@value{GDBN} automatically loads symbol definitions from shared libraries
19001when you use the @code{run} command, or when you examine a core file.
19002(Before you issue the @code{run} command, @value{GDBN} does not understand
19003references to a function in a shared library, however---unless you are
19004debugging a core file).
53a5351d 19005
c906108c
SS
19006@c FIXME: some @value{GDBN} release may permit some refs to undef
19007@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
19008@c FIXME...lib; check this from time to time when updating manual
19009
b7209cb4
FF
19010There are times, however, when you may wish to not automatically load
19011symbol definitions from shared libraries, such as when they are
19012particularly large or there are many of them.
19013
19014To control the automatic loading of shared library symbols, use the
19015commands:
19016
19017@table @code
19018@kindex set auto-solib-add
19019@item set auto-solib-add @var{mode}
19020If @var{mode} is @code{on}, symbols from all shared object libraries
19021will be loaded automatically when the inferior begins execution, you
19022attach to an independently started inferior, or when the dynamic linker
19023informs @value{GDBN} that a new library has been loaded. If @var{mode}
19024is @code{off}, symbols must be loaded manually, using the
19025@code{sharedlibrary} command. The default value is @code{on}.
19026
dcaf7c2c
EZ
19027@cindex memory used for symbol tables
19028If your program uses lots of shared libraries with debug info that
19029takes large amounts of memory, you can decrease the @value{GDBN}
19030memory footprint by preventing it from automatically loading the
19031symbols from shared libraries. To that end, type @kbd{set
19032auto-solib-add off} before running the inferior, then load each
19033library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 19034@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
19035the libraries whose symbols you want to be loaded.
19036
b7209cb4
FF
19037@kindex show auto-solib-add
19038@item show auto-solib-add
19039Display the current autoloading mode.
19040@end table
19041
c45da7e6 19042@cindex load shared library
b7209cb4
FF
19043To explicitly load shared library symbols, use the @code{sharedlibrary}
19044command:
19045
c906108c
SS
19046@table @code
19047@kindex info sharedlibrary
19048@kindex info share
55333a84
DE
19049@item info share @var{regex}
19050@itemx info sharedlibrary @var{regex}
19051Print the names of the shared libraries which are currently loaded
19052that match @var{regex}. If @var{regex} is omitted then print
19053all shared libraries that are loaded.
c906108c 19054
b30a0bc3
JB
19055@kindex info dll
19056@item info dll @var{regex}
19057This is an alias of @code{info sharedlibrary}.
19058
c906108c
SS
19059@kindex sharedlibrary
19060@kindex share
19061@item sharedlibrary @var{regex}
19062@itemx share @var{regex}
c906108c
SS
19063Load shared object library symbols for files matching a
19064Unix regular expression.
19065As with files loaded automatically, it only loads shared libraries
19066required by your program for a core file or after typing @code{run}. If
19067@var{regex} is omitted all shared libraries required by your program are
19068loaded.
c45da7e6
EZ
19069
19070@item nosharedlibrary
19071@kindex nosharedlibrary
19072@cindex unload symbols from shared libraries
19073Unload all shared object library symbols. This discards all symbols
19074that have been loaded from all shared libraries. Symbols from shared
19075libraries that were loaded by explicit user requests are not
19076discarded.
c906108c
SS
19077@end table
19078
721c2651 19079Sometimes you may wish that @value{GDBN} stops and gives you control
edcc5120
TT
19080when any of shared library events happen. The best way to do this is
19081to use @code{catch load} and @code{catch unload} (@pxref{Set
19082Catchpoints}).
19083
19084@value{GDBN} also supports the the @code{set stop-on-solib-events}
19085command for this. This command exists for historical reasons. It is
19086less useful than setting a catchpoint, because it does not allow for
19087conditions or commands as a catchpoint does.
721c2651
EZ
19088
19089@table @code
19090@item set stop-on-solib-events
19091@kindex set stop-on-solib-events
19092This command controls whether @value{GDBN} should give you control
19093when the dynamic linker notifies it about some shared library event.
19094The most common event of interest is loading or unloading of a new
19095shared library.
19096
19097@item show stop-on-solib-events
19098@kindex show stop-on-solib-events
19099Show whether @value{GDBN} stops and gives you control when shared
19100library events happen.
19101@end table
19102
f5ebfba0 19103Shared libraries are also supported in many cross or remote debugging
f1838a98
UW
19104configurations. @value{GDBN} needs to have access to the target's libraries;
19105this can be accomplished either by providing copies of the libraries
19106on the host system, or by asking @value{GDBN} to automatically retrieve the
19107libraries from the target. If copies of the target libraries are
19108provided, they need to be the same as the target libraries, although the
f5ebfba0
DJ
19109copies on the target can be stripped as long as the copies on the host are
19110not.
19111
59b7b46f
EZ
19112@cindex where to look for shared libraries
19113For remote debugging, you need to tell @value{GDBN} where the target
19114libraries are, so that it can load the correct copies---otherwise, it
19115may try to load the host's libraries. @value{GDBN} has two variables
19116to specify the search directories for target libraries.
f5ebfba0
DJ
19117
19118@table @code
a9a5a3d1 19119@cindex prefix for executable and shared library file names
f822c95b 19120@cindex system root, alternate
f5ebfba0 19121@kindex set solib-absolute-prefix
f822c95b
DJ
19122@kindex set sysroot
19123@item set sysroot @var{path}
19124Use @var{path} as the system root for the program being debugged. Any
19125absolute shared library paths will be prefixed with @var{path}; many
19126runtime loaders store the absolute paths to the shared library in the
a9a5a3d1
GB
19127target program's memory. When starting processes remotely, and when
19128attaching to already-running processes (local or remote), their
19129executable filenames will be prefixed with @var{path} if reported to
19130@value{GDBN} as absolute by the operating system. If you use
19131@code{set sysroot} to find executables and shared libraries, they need
19132to be laid out in the same way that they are on the target, with
19133e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
19134@var{path}.
f822c95b 19135
599bd15c
GB
19136If @var{path} starts with the sequence @file{target:} and the target
19137system is remote then @value{GDBN} will retrieve the target binaries
19138from the remote system. This is only supported when using a remote
19139target that supports the @code{remote get} command (@pxref{File
19140Transfer,,Sending files to a remote system}). The part of @var{path}
19141following the initial @file{target:} (if present) is used as system
19142root prefix on the remote file system. If @var{path} starts with the
19143sequence @file{remote:} this is converted to the sequence
19144@file{target:} by @code{set sysroot}@footnote{Historically the
19145functionality to retrieve binaries from the remote system was
19146provided by prefixing @var{path} with @file{remote:}}. If you want
19147to specify a local system root using a directory that happens to be
19148named @file{target:} or @file{remote:}, you need to use some
19149equivalent variant of the name like @file{./target:}.
f1838a98 19150
ab38a727
PA
19151For targets with an MS-DOS based filesystem, such as MS-Windows and
19152SymbianOS, @value{GDBN} tries prefixing a few variants of the target
19153absolute file name with @var{path}. But first, on Unix hosts,
19154@value{GDBN} converts all backslash directory separators into forward
19155slashes, because the backslash is not a directory separator on Unix:
19156
19157@smallexample
19158 c:\foo\bar.dll @result{} c:/foo/bar.dll
19159@end smallexample
19160
19161Then, @value{GDBN} attempts prefixing the target file name with
19162@var{path}, and looks for the resulting file name in the host file
19163system:
19164
19165@smallexample
19166 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
19167@end smallexample
19168
a9a5a3d1 19169If that does not find the binary, @value{GDBN} tries removing
ab38a727
PA
19170the @samp{:} character from the drive spec, both for convenience, and,
19171for the case of the host file system not supporting file names with
19172colons:
19173
19174@smallexample
19175 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
19176@end smallexample
19177
19178This makes it possible to have a system root that mirrors a target
19179with more than one drive. E.g., you may want to setup your local
19180copies of the target system shared libraries like so (note @samp{c} vs
19181@samp{z}):
19182
19183@smallexample
19184 @file{/path/to/sysroot/c/sys/bin/foo.dll}
19185 @file{/path/to/sysroot/c/sys/bin/bar.dll}
19186 @file{/path/to/sysroot/z/sys/bin/bar.dll}
19187@end smallexample
19188
19189@noindent
19190and point the system root at @file{/path/to/sysroot}, so that
19191@value{GDBN} can find the correct copies of both
19192@file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
19193
a9a5a3d1 19194If that still does not find the binary, @value{GDBN} tries
ab38a727
PA
19195removing the whole drive spec from the target file name:
19196
19197@smallexample
19198 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
19199@end smallexample
19200
19201This last lookup makes it possible to not care about the drive name,
19202if you don't want or need to.
19203
f822c95b
DJ
19204The @code{set solib-absolute-prefix} command is an alias for @code{set
19205sysroot}.
19206
19207@cindex default system root
59b7b46f 19208@cindex @samp{--with-sysroot}
f822c95b
DJ
19209You can set the default system root by using the configure-time
19210@samp{--with-sysroot} option. If the system root is inside
19211@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
19212@samp{--exec-prefix}), then the default system root will be updated
19213automatically if the installed @value{GDBN} is moved to a new
19214location.
19215
19216@kindex show sysroot
19217@item show sysroot
a9a5a3d1 19218Display the current executable and shared library prefix.
f5ebfba0
DJ
19219
19220@kindex set solib-search-path
19221@item set solib-search-path @var{path}
f822c95b
DJ
19222If this variable is set, @var{path} is a colon-separated list of
19223directories to search for shared libraries. @samp{solib-search-path}
19224is used after @samp{sysroot} fails to locate the library, or if the
19225path to the library is relative instead of absolute. If you want to
19226use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 19227@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 19228finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 19229it to a nonexistent directory may interfere with automatic loading
f822c95b 19230of shared library symbols.
f5ebfba0
DJ
19231
19232@kindex show solib-search-path
19233@item show solib-search-path
19234Display the current shared library search path.
ab38a727
PA
19235
19236@cindex DOS file-name semantics of file names.
19237@kindex set target-file-system-kind (unix|dos-based|auto)
19238@kindex show target-file-system-kind
19239@item set target-file-system-kind @var{kind}
19240Set assumed file system kind for target reported file names.
19241
19242Shared library file names as reported by the target system may not
19243make sense as is on the system @value{GDBN} is running on. For
19244example, when remote debugging a target that has MS-DOS based file
19245system semantics, from a Unix host, the target may be reporting to
19246@value{GDBN} a list of loaded shared libraries with file names such as
19247@file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
19248drive letters, so the @samp{c:\} prefix is not normally understood as
19249indicating an absolute file name, and neither is the backslash
19250normally considered a directory separator character. In that case,
19251the native file system would interpret this whole absolute file name
19252as a relative file name with no directory components. This would make
19253it impossible to point @value{GDBN} at a copy of the remote target's
19254shared libraries on the host using @code{set sysroot}, and impractical
19255with @code{set solib-search-path}. Setting
19256@code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
19257to interpret such file names similarly to how the target would, and to
19258map them to file names valid on @value{GDBN}'s native file system
19259semantics. The value of @var{kind} can be @code{"auto"}, in addition
19260to one of the supported file system kinds. In that case, @value{GDBN}
19261tries to determine the appropriate file system variant based on the
19262current target's operating system (@pxref{ABI, ,Configuring the
19263Current ABI}). The supported file system settings are:
19264
19265@table @code
19266@item unix
19267Instruct @value{GDBN} to assume the target file system is of Unix
19268kind. Only file names starting the forward slash (@samp{/}) character
19269are considered absolute, and the directory separator character is also
19270the forward slash.
19271
19272@item dos-based
19273Instruct @value{GDBN} to assume the target file system is DOS based.
19274File names starting with either a forward slash, or a drive letter
19275followed by a colon (e.g., @samp{c:}), are considered absolute, and
19276both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
19277considered directory separators.
19278
19279@item auto
19280Instruct @value{GDBN} to use the file system kind associated with the
19281target operating system (@pxref{ABI, ,Configuring the Current ABI}).
19282This is the default.
19283@end table
f5ebfba0
DJ
19284@end table
19285
c011a4f4
DE
19286@cindex file name canonicalization
19287@cindex base name differences
19288When processing file names provided by the user, @value{GDBN}
19289frequently needs to compare them to the file names recorded in the
19290program's debug info. Normally, @value{GDBN} compares just the
19291@dfn{base names} of the files as strings, which is reasonably fast
19292even for very large programs. (The base name of a file is the last
19293portion of its name, after stripping all the leading directories.)
19294This shortcut in comparison is based upon the assumption that files
19295cannot have more than one base name. This is usually true, but
19296references to files that use symlinks or similar filesystem
19297facilities violate that assumption. If your program records files
19298using such facilities, or if you provide file names to @value{GDBN}
19299using symlinks etc., you can set @code{basenames-may-differ} to
19300@code{true} to instruct @value{GDBN} to completely canonicalize each
19301pair of file names it needs to compare. This will make file-name
19302comparisons accurate, but at a price of a significant slowdown.
19303
19304@table @code
19305@item set basenames-may-differ
19306@kindex set basenames-may-differ
19307Set whether a source file may have multiple base names.
19308
19309@item show basenames-may-differ
19310@kindex show basenames-may-differ
19311Show whether a source file may have multiple base names.
19312@end table
5b5d99cf 19313
18989b3c
AB
19314@node File Caching
19315@section File Caching
19316@cindex caching of opened files
19317@cindex caching of bfd objects
19318
19319To speed up file loading, and reduce memory usage, @value{GDBN} will
19320reuse the @code{bfd} objects used to track open files. @xref{Top, ,
19321BFD, bfd, The Binary File Descriptor Library}. The following commands
19322allow visibility and control of the caching behavior.
19323
19324@table @code
19325@kindex maint info bfds
19326@item maint info bfds
19327This prints information about each @code{bfd} object that is known to
19328@value{GDBN}.
19329
19330@kindex maint set bfd-sharing
19331@kindex maint show bfd-sharing
19332@kindex bfd caching
19333@item maint set bfd-sharing
19334@item maint show bfd-sharing
19335Control whether @code{bfd} objects can be shared. When sharing is
19336enabled @value{GDBN} reuses already open @code{bfd} objects rather
19337than reopening the same file. Turning sharing off does not cause
19338already shared @code{bfd} objects to be unshared, but all future files
19339that are opened will create a new @code{bfd} object. Similarly,
19340re-enabling sharing does not cause multiple existing @code{bfd}
19341objects to be collapsed into a single shared @code{bfd} object.
566f5e3b
AB
19342
19343@kindex set debug bfd-cache @var{level}
19344@kindex bfd caching
19345@item set debug bfd-cache @var{level}
19346Turns on debugging of the bfd cache, setting the level to @var{level}.
19347
19348@kindex show debug bfd-cache
19349@kindex bfd caching
19350@item show debug bfd-cache
19351Show the current debugging level of the bfd cache.
18989b3c
AB
19352@end table
19353
5b5d99cf
JB
19354@node Separate Debug Files
19355@section Debugging Information in Separate Files
19356@cindex separate debugging information files
19357@cindex debugging information in separate files
19358@cindex @file{.debug} subdirectories
19359@cindex debugging information directory, global
f307c045 19360@cindex global debugging information directories
c7e83d54
EZ
19361@cindex build ID, and separate debugging files
19362@cindex @file{.build-id} directory
5b5d99cf
JB
19363
19364@value{GDBN} allows you to put a program's debugging information in a
19365file separate from the executable itself, in a way that allows
19366@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
19367Since debugging information can be very large---sometimes larger
19368than the executable code itself---some systems distribute debugging
5b5d99cf
JB
19369information for their executables in separate files, which users can
19370install only when they need to debug a problem.
19371
c7e83d54
EZ
19372@value{GDBN} supports two ways of specifying the separate debug info
19373file:
5b5d99cf
JB
19374
19375@itemize @bullet
19376@item
c7e83d54
EZ
19377The executable contains a @dfn{debug link} that specifies the name of
19378the separate debug info file. The separate debug file's name is
19379usually @file{@var{executable}.debug}, where @var{executable} is the
19380name of the corresponding executable file without leading directories
19381(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
99e008fe
EZ
19382debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
19383checksum for the debug file, which @value{GDBN} uses to validate that
19384the executable and the debug file came from the same build.
c7e83d54
EZ
19385
19386@item
7e27a47a 19387The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 19388also present in the corresponding debug info file. (This is supported
c74f7d1c 19389only on some operating systems, when using the ELF or PE file formats
7e27a47a
EZ
19390for binary files and the @sc{gnu} Binutils.) For more details about
19391this feature, see the description of the @option{--build-id}
19392command-line option in @ref{Options, , Command Line Options, ld.info,
19393The GNU Linker}. The debug info file's name is not specified
19394explicitly by the build ID, but can be computed from the build ID, see
19395below.
d3750b24
JK
19396@end itemize
19397
c7e83d54
EZ
19398Depending on the way the debug info file is specified, @value{GDBN}
19399uses two different methods of looking for the debug file:
d3750b24
JK
19400
19401@itemize @bullet
19402@item
c7e83d54
EZ
19403For the ``debug link'' method, @value{GDBN} looks up the named file in
19404the directory of the executable file, then in a subdirectory of that
f307c045
JK
19405directory named @file{.debug}, and finally under each one of the global debug
19406directories, in a subdirectory whose name is identical to the leading
c7e83d54
EZ
19407directories of the executable's absolute file name.
19408
19409@item
83f83d7f 19410For the ``build ID'' method, @value{GDBN} looks in the
f307c045
JK
19411@file{.build-id} subdirectory of each one of the global debug directories for
19412a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
19413first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
19414are the rest of the bit string. (Real build ID strings are 32 or more
19415hex characters, not 10.)
c7e83d54
EZ
19416@end itemize
19417
19418So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
19419@file{/usr/bin/ls}, which has a debug link that specifies the
19420file @file{ls.debug}, and a build ID whose value in hex is
f307c045 19421@code{abcdef1234}. If the list of the global debug directories includes
c7e83d54
EZ
19422@file{/usr/lib/debug}, then @value{GDBN} will look for the following
19423debug information files, in the indicated order:
19424
19425@itemize @minus
19426@item
19427@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 19428@item
c7e83d54 19429@file{/usr/bin/ls.debug}
5b5d99cf 19430@item
c7e83d54 19431@file{/usr/bin/.debug/ls.debug}
5b5d99cf 19432@item
c7e83d54 19433@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 19434@end itemize
5b5d99cf 19435
1564a261
JK
19436@anchor{debug-file-directory}
19437Global debugging info directories default to what is set by @value{GDBN}
19438configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
19439you can also set the global debugging info directories, and view the list
19440@value{GDBN} is currently using.
5b5d99cf
JB
19441
19442@table @code
19443
19444@kindex set debug-file-directory
24ddea62
JK
19445@item set debug-file-directory @var{directories}
19446Set the directories which @value{GDBN} searches for separate debugging
d9242c17
JK
19447information files to @var{directory}. Multiple path components can be set
19448concatenating them by a path separator.
5b5d99cf
JB
19449
19450@kindex show debug-file-directory
19451@item show debug-file-directory
24ddea62 19452Show the directories @value{GDBN} searches for separate debugging
5b5d99cf
JB
19453information files.
19454
19455@end table
19456
19457@cindex @code{.gnu_debuglink} sections
c7e83d54 19458@cindex debug link sections
5b5d99cf
JB
19459A debug link is a special section of the executable file named
19460@code{.gnu_debuglink}. The section must contain:
19461
19462@itemize
19463@item
19464A filename, with any leading directory components removed, followed by
19465a zero byte,
19466@item
19467zero to three bytes of padding, as needed to reach the next four-byte
19468boundary within the section, and
19469@item
19470a four-byte CRC checksum, stored in the same endianness used for the
19471executable file itself. The checksum is computed on the debugging
19472information file's full contents by the function given below, passing
19473zero as the @var{crc} argument.
19474@end itemize
19475
19476Any executable file format can carry a debug link, as long as it can
19477contain a section named @code{.gnu_debuglink} with the contents
19478described above.
19479
d3750b24 19480@cindex @code{.note.gnu.build-id} sections
c7e83d54 19481@cindex build ID sections
7e27a47a
EZ
19482The build ID is a special section in the executable file (and in other
19483ELF binary files that @value{GDBN} may consider). This section is
19484often named @code{.note.gnu.build-id}, but that name is not mandatory.
19485It contains unique identification for the built files---the ID remains
19486the same across multiple builds of the same build tree. The default
19487algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
19488content for the build ID string. The same section with an identical
19489value is present in the original built binary with symbols, in its
19490stripped variant, and in the separate debugging information file.
d3750b24 19491
5b5d99cf
JB
19492The debugging information file itself should be an ordinary
19493executable, containing a full set of linker symbols, sections, and
19494debugging information. The sections of the debugging information file
c7e83d54
EZ
19495should have the same names, addresses, and sizes as the original file,
19496but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
19497in an ordinary executable.
19498
7e27a47a 19499The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
19500@samp{objcopy} utility that can produce
19501the separated executable / debugging information file pairs using the
19502following commands:
19503
19504@smallexample
19505@kbd{objcopy --only-keep-debug foo foo.debug}
19506@kbd{strip -g foo}
c7e83d54
EZ
19507@end smallexample
19508
19509@noindent
19510These commands remove the debugging
83f83d7f
JK
19511information from the executable file @file{foo} and place it in the file
19512@file{foo.debug}. You can use the first, second or both methods to link the
19513two files:
19514
19515@itemize @bullet
19516@item
19517The debug link method needs the following additional command to also leave
19518behind a debug link in @file{foo}:
19519
19520@smallexample
19521@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
19522@end smallexample
19523
19524Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 19525a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
19526foo.debug} has the same functionality as the two @code{objcopy} commands and
19527the @code{ln -s} command above, together.
19528
19529@item
19530Build ID gets embedded into the main executable using @code{ld --build-id} or
19531the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
19532compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 19533utilities (Binutils) package since version 2.18.
83f83d7f
JK
19534@end itemize
19535
19536@noindent
d3750b24 19537
99e008fe
EZ
19538@cindex CRC algorithm definition
19539The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
19540IEEE 802.3 using the polynomial:
19541
19542@c TexInfo requires naked braces for multi-digit exponents for Tex
19543@c output, but this causes HTML output to barf. HTML has to be set using
19544@c raw commands. So we end up having to specify this equation in 2
19545@c different ways!
19546@ifhtml
19547@display
19548@html
19549 <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>
19550 + <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
19551@end html
19552@end display
19553@end ifhtml
19554@ifnothtml
19555@display
19556 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
19557 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
19558@end display
19559@end ifnothtml
19560
19561The function is computed byte at a time, taking the least
19562significant bit of each byte first. The initial pattern
19563@code{0xffffffff} is used, to ensure leading zeros affect the CRC and
19564the final result is inverted to ensure trailing zeros also affect the
19565CRC.
19566
19567@emph{Note:} This is the same CRC polynomial as used in handling the
936d2992
PA
19568@dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
19569However in the case of the Remote Serial Protocol, the CRC is computed
19570@emph{most} significant bit first, and the result is not inverted, so
19571trailing zeros have no effect on the CRC value.
99e008fe
EZ
19572
19573To complete the description, we show below the code of the function
19574which produces the CRC used in @code{.gnu_debuglink}. Inverting the
19575initially supplied @code{crc} argument means that an initial call to
19576this function passing in zero will start computing the CRC using
19577@code{0xffffffff}.
5b5d99cf 19578
4644b6e3 19579@kindex gnu_debuglink_crc32
5b5d99cf
JB
19580@smallexample
19581unsigned long
19582gnu_debuglink_crc32 (unsigned long crc,
19583 unsigned char *buf, size_t len)
19584@{
19585 static const unsigned long crc32_table[256] =
19586 @{
19587 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
19588 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
19589 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
19590 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
19591 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
19592 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
19593 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
19594 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
19595 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
19596 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
19597 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
19598 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
19599 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
19600 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
19601 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
19602 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
19603 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
19604 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
19605 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
19606 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
19607 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
19608 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
19609 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
19610 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
19611 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
19612 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
19613 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
19614 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
19615 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
19616 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
19617 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
19618 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
19619 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
19620 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
19621 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
19622 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
19623 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
19624 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
19625 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
19626 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
19627 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
19628 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
19629 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
19630 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
19631 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
19632 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
19633 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
19634 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
19635 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
19636 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
19637 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
19638 0x2d02ef8d
19639 @};
19640 unsigned char *end;
19641
19642 crc = ~crc & 0xffffffff;
19643 for (end = buf + len; buf < end; ++buf)
19644 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 19645 return ~crc & 0xffffffff;
5b5d99cf
JB
19646@}
19647@end smallexample
19648
c7e83d54
EZ
19649@noindent
19650This computation does not apply to the ``build ID'' method.
19651
608e2dbb
TT
19652@node MiniDebugInfo
19653@section Debugging information in a special section
19654@cindex separate debug sections
19655@cindex @samp{.gnu_debugdata} section
19656
19657Some systems ship pre-built executables and libraries that have a
19658special @samp{.gnu_debugdata} section. This feature is called
19659@dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
19660is used to supply extra symbols for backtraces.
19661
19662The intent of this section is to provide extra minimal debugging
19663information for use in simple backtraces. It is not intended to be a
19664replacement for full separate debugging information (@pxref{Separate
19665Debug Files}). The example below shows the intended use; however,
19666@value{GDBN} does not currently put restrictions on what sort of
19667debugging information might be included in the section.
19668
19669@value{GDBN} has support for this extension. If the section exists,
19670then it is used provided that no other source of debugging information
19671can be found, and that @value{GDBN} was configured with LZMA support.
19672
19673This section can be easily created using @command{objcopy} and other
19674standard utilities:
19675
19676@smallexample
19677# Extract the dynamic symbols from the main binary, there is no need
5423b017 19678# to also have these in the normal symbol table.
608e2dbb
TT
19679nm -D @var{binary} --format=posix --defined-only \
19680 | awk '@{ print $1 @}' | sort > dynsyms
19681
5423b017 19682# Extract all the text (i.e. function) symbols from the debuginfo.
1d236d23
JK
19683# (Note that we actually also accept "D" symbols, for the benefit
19684# of platforms like PowerPC64 that use function descriptors.)
608e2dbb 19685nm @var{binary} --format=posix --defined-only \
1d236d23 19686 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
608e2dbb
TT
19687 | sort > funcsyms
19688
19689# Keep all the function symbols not already in the dynamic symbol
19690# table.
19691comm -13 dynsyms funcsyms > keep_symbols
19692
edf9f00c
JK
19693# Separate full debug info into debug binary.
19694objcopy --only-keep-debug @var{binary} debug
19695
608e2dbb
TT
19696# Copy the full debuginfo, keeping only a minimal set of symbols and
19697# removing some unnecessary sections.
19698objcopy -S --remove-section .gdb_index --remove-section .comment \
edf9f00c
JK
19699 --keep-symbols=keep_symbols debug mini_debuginfo
19700
19701# Drop the full debug info from the original binary.
19702strip --strip-all -R .comment @var{binary}
608e2dbb
TT
19703
19704# Inject the compressed data into the .gnu_debugdata section of the
19705# original binary.
19706xz mini_debuginfo
19707objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
19708@end smallexample
5b5d99cf 19709
9291a0cd
TT
19710@node Index Files
19711@section Index Files Speed Up @value{GDBN}
19712@cindex index files
19713@cindex @samp{.gdb_index} section
19714
19715When @value{GDBN} finds a symbol file, it scans the symbols in the
19716file in order to construct an internal symbol table. This lets most
19717@value{GDBN} operations work quickly---at the cost of a delay early
19718on. For large programs, this delay can be quite lengthy, so
19719@value{GDBN} provides a way to build an index, which speeds up
19720startup.
19721
ba643918
SDJ
19722For convenience, @value{GDBN} comes with a program,
19723@command{gdb-add-index}, which can be used to add the index to a
19724symbol file. It takes the symbol file as its only argument:
19725
19726@smallexample
19727$ gdb-add-index symfile
19728@end smallexample
19729
19730@xref{gdb-add-index}.
19731
19732It is also possible to do the work manually. Here is what
19733@command{gdb-add-index} does behind the curtains.
19734
9291a0cd
TT
19735The index is stored as a section in the symbol file. @value{GDBN} can
19736write the index to a file, then you can put it into the symbol file
19737using @command{objcopy}.
19738
19739To create an index file, use the @code{save gdb-index} command:
19740
19741@table @code
437afbb8 19742@item save gdb-index [-dwarf-5] @var{directory}
9291a0cd 19743@kindex save gdb-index
437afbb8
JK
19744Create index files for all symbol files currently known by
19745@value{GDBN}. For each known @var{symbol-file}, this command by
19746default creates it produces a single file
19747@file{@var{symbol-file}.gdb-index}. If you invoke this command with
19748the @option{-dwarf-5} option, it produces 2 files:
19749@file{@var{symbol-file}.debug_names} and
19750@file{@var{symbol-file}.debug_str}. The files are created in the
19751given @var{directory}.
9291a0cd
TT
19752@end table
19753
19754Once you have created an index file you can merge it into your symbol
19755file, here named @file{symfile}, using @command{objcopy}:
19756
19757@smallexample
19758$ objcopy --add-section .gdb_index=symfile.gdb-index \
19759 --set-section-flags .gdb_index=readonly symfile symfile
19760@end smallexample
19761
437afbb8
JK
19762Or for @code{-dwarf-5}:
19763
19764@smallexample
19765$ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
19766$ cat symfile.debug_str >>symfile.debug_str.new
19767$ objcopy --add-section .debug_names=symfile.gdb-index \
19768 --set-section-flags .debug_names=readonly \
19769 --update-section .debug_str=symfile.debug_str.new symfile symfile
19770@end smallexample
19771
e615022a
DE
19772@value{GDBN} will normally ignore older versions of @file{.gdb_index}
19773sections that have been deprecated. Usually they are deprecated because
19774they are missing a new feature or have performance issues.
19775To tell @value{GDBN} to use a deprecated index section anyway
19776specify @code{set use-deprecated-index-sections on}.
19777The default is @code{off}.
19778This can speed up startup, but may result in some functionality being lost.
19779@xref{Index Section Format}.
19780
19781@emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
19782must be done before gdb reads the file. The following will not work:
19783
19784@smallexample
19785$ gdb -ex "set use-deprecated-index-sections on" <program>
19786@end smallexample
19787
19788Instead you must do, for example,
19789
19790@smallexample
19791$ gdb -iex "set use-deprecated-index-sections on" <program>
19792@end smallexample
19793
9291a0cd
TT
19794There are currently some limitation on indices. They only work when
19795for DWARF debugging information, not stabs. And, they do not
19796currently work for programs using Ada.
19797
6d2ebf8b 19798@node Symbol Errors
79a6e687 19799@section Errors Reading Symbol Files
c906108c
SS
19800
19801While reading a symbol file, @value{GDBN} occasionally encounters problems,
19802such as symbol types it does not recognize, or known bugs in compiler
19803output. By default, @value{GDBN} does not notify you of such problems, since
19804they are relatively common and primarily of interest to people
19805debugging compilers. If you are interested in seeing information
19806about ill-constructed symbol tables, you can either ask @value{GDBN} to print
19807only one message about each such type of problem, no matter how many
19808times the problem occurs; or you can ask @value{GDBN} to print more messages,
19809to see how many times the problems occur, with the @code{set
79a6e687
BW
19810complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
19811Messages}).
c906108c
SS
19812
19813The messages currently printed, and their meanings, include:
19814
19815@table @code
19816@item inner block not inside outer block in @var{symbol}
19817
19818The symbol information shows where symbol scopes begin and end
19819(such as at the start of a function or a block of statements). This
19820error indicates that an inner scope block is not fully contained
19821in its outer scope blocks.
19822
19823@value{GDBN} circumvents the problem by treating the inner block as if it had
19824the same scope as the outer block. In the error message, @var{symbol}
19825may be shown as ``@code{(don't know)}'' if the outer block is not a
19826function.
19827
19828@item block at @var{address} out of order
19829
19830The symbol information for symbol scope blocks should occur in
19831order of increasing addresses. This error indicates that it does not
19832do so.
19833
19834@value{GDBN} does not circumvent this problem, and has trouble
19835locating symbols in the source file whose symbols it is reading. (You
19836can often determine what source file is affected by specifying
79a6e687
BW
19837@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
19838Messages}.)
c906108c
SS
19839
19840@item bad block start address patched
19841
19842The symbol information for a symbol scope block has a start address
19843smaller than the address of the preceding source line. This is known
19844to occur in the SunOS 4.1.1 (and earlier) C compiler.
19845
19846@value{GDBN} circumvents the problem by treating the symbol scope block as
19847starting on the previous source line.
19848
19849@item bad string table offset in symbol @var{n}
19850
19851@cindex foo
19852Symbol number @var{n} contains a pointer into the string table which is
19853larger than the size of the string table.
19854
19855@value{GDBN} circumvents the problem by considering the symbol to have the
19856name @code{foo}, which may cause other problems if many symbols end up
19857with this name.
19858
19859@item unknown symbol type @code{0x@var{nn}}
19860
7a292a7a
SS
19861The symbol information contains new data types that @value{GDBN} does
19862not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 19863uncomprehended information, in hexadecimal.
c906108c 19864
7a292a7a
SS
19865@value{GDBN} circumvents the error by ignoring this symbol information.
19866This usually allows you to debug your program, though certain symbols
c906108c 19867are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
19868debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
19869on @code{complain}, then go up to the function @code{read_dbx_symtab}
19870and examine @code{*bufp} to see the symbol.
c906108c
SS
19871
19872@item stub type has NULL name
c906108c 19873
7a292a7a 19874@value{GDBN} could not find the full definition for a struct or class.
c906108c 19875
7a292a7a 19876@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 19877The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
19878information that recent versions of the compiler should have output for
19879it.
c906108c
SS
19880
19881@item info mismatch between compiler and debugger
19882
19883@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 19884
c906108c
SS
19885@end table
19886
b14b1491
TT
19887@node Data Files
19888@section GDB Data Files
19889
19890@cindex prefix for data files
19891@value{GDBN} will sometimes read an auxiliary data file. These files
19892are kept in a directory known as the @dfn{data directory}.
19893
19894You can set the data directory's name, and view the name @value{GDBN}
19895is currently using.
19896
19897@table @code
19898@kindex set data-directory
19899@item set data-directory @var{directory}
19900Set the directory which @value{GDBN} searches for auxiliary data files
19901to @var{directory}.
19902
19903@kindex show data-directory
19904@item show data-directory
19905Show the directory @value{GDBN} searches for auxiliary data files.
19906@end table
19907
19908@cindex default data directory
19909@cindex @samp{--with-gdb-datadir}
19910You can set the default data directory by using the configure-time
19911@samp{--with-gdb-datadir} option. If the data directory is inside
19912@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
19913@samp{--exec-prefix}), then the default data directory will be updated
19914automatically if the installed @value{GDBN} is moved to a new
19915location.
19916
aae1c79a
DE
19917The data directory may also be specified with the
19918@code{--data-directory} command line option.
19919@xref{Mode Options}.
19920
6d2ebf8b 19921@node Targets
c906108c 19922@chapter Specifying a Debugging Target
7a292a7a 19923
c906108c 19924@cindex debugging target
c906108c 19925A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
19926
19927Often, @value{GDBN} runs in the same host environment as your program;
19928in that case, the debugging target is specified as a side effect when
19929you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
19930flexibility---for example, running @value{GDBN} on a physically separate
19931host, or controlling a standalone system over a serial port or a
53a5351d
JM
19932realtime system over a TCP/IP connection---you can use the @code{target}
19933command to specify one of the target types configured for @value{GDBN}
79a6e687 19934(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 19935
a8f24a35
EZ
19936@cindex target architecture
19937It is possible to build @value{GDBN} for several different @dfn{target
19938architectures}. When @value{GDBN} is built like that, you can choose
19939one of the available architectures with the @kbd{set architecture}
19940command.
19941
19942@table @code
19943@kindex set architecture
19944@kindex show architecture
19945@item set architecture @var{arch}
19946This command sets the current target architecture to @var{arch}. The
19947value of @var{arch} can be @code{"auto"}, in addition to one of the
19948supported architectures.
19949
19950@item show architecture
19951Show the current target architecture.
9c16f35a
EZ
19952
19953@item set processor
19954@itemx processor
19955@kindex set processor
19956@kindex show processor
19957These are alias commands for, respectively, @code{set architecture}
19958and @code{show architecture}.
a8f24a35
EZ
19959@end table
19960
c906108c
SS
19961@menu
19962* Active Targets:: Active targets
19963* Target Commands:: Commands for managing targets
c906108c 19964* Byte Order:: Choosing target byte order
c906108c
SS
19965@end menu
19966
6d2ebf8b 19967@node Active Targets
79a6e687 19968@section Active Targets
7a292a7a 19969
c906108c
SS
19970@cindex stacking targets
19971@cindex active targets
19972@cindex multiple targets
19973
8ea5bce5 19974There are multiple classes of targets such as: processes, executable files or
c0edd9ed
JK
19975recording sessions. Core files belong to the process class, making core file
19976and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
19977on multiple active targets, one in each class. This allows you to (for
19978example) start a process and inspect its activity, while still having access to
19979the executable file after the process finishes. Or if you start process
19980recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
19981presented a virtual layer of the recording target, while the process target
19982remains stopped at the chronologically last point of the process execution.
19983
19984Use the @code{core-file} and @code{exec-file} commands to select a new core
19985file or executable target (@pxref{Files, ,Commands to Specify Files}). To
19986specify as a target a process that is already running, use the @code{attach}
19987command (@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 19988
6d2ebf8b 19989@node Target Commands
79a6e687 19990@section Commands for Managing Targets
c906108c
SS
19991
19992@table @code
19993@item target @var{type} @var{parameters}
7a292a7a
SS
19994Connects the @value{GDBN} host environment to a target machine or
19995process. A target is typically a protocol for talking to debugging
19996facilities. You use the argument @var{type} to specify the type or
19997protocol of the target machine.
c906108c
SS
19998
19999Further @var{parameters} are interpreted by the target protocol, but
20000typically include things like device names or host names to connect
20001with, process numbers, and baud rates.
c906108c
SS
20002
20003The @code{target} command does not repeat if you press @key{RET} again
20004after executing the command.
20005
20006@kindex help target
20007@item help target
20008Displays the names of all targets available. To display targets
20009currently selected, use either @code{info target} or @code{info files}
79a6e687 20010(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
20011
20012@item help target @var{name}
20013Describe a particular target, including any parameters necessary to
20014select it.
20015
20016@kindex set gnutarget
20017@item set gnutarget @var{args}
5d161b24 20018@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 20019knows whether it is reading an @dfn{executable},
5d161b24
DB
20020a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
20021with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
20022with @code{gnutarget} the @code{target} refers to a program, not a machine.
20023
d4f3574e 20024@quotation
c906108c
SS
20025@emph{Warning:} To specify a file format with @code{set gnutarget},
20026you must know the actual BFD name.
d4f3574e 20027@end quotation
c906108c 20028
d4f3574e 20029@noindent
79a6e687 20030@xref{Files, , Commands to Specify Files}.
c906108c 20031
5d161b24 20032@kindex show gnutarget
c906108c
SS
20033@item show gnutarget
20034Use the @code{show gnutarget} command to display what file format
20035@code{gnutarget} is set to read. If you have not set @code{gnutarget},
20036@value{GDBN} will determine the file format for each file automatically,
c4957902 20037and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
c906108c
SS
20038@end table
20039
4644b6e3 20040@cindex common targets
c906108c
SS
20041Here are some common targets (available, or not, depending on the GDB
20042configuration):
c906108c
SS
20043
20044@table @code
4644b6e3 20045@kindex target
c906108c 20046@item target exec @var{program}
4644b6e3 20047@cindex executable file target
c906108c
SS
20048An executable file. @samp{target exec @var{program}} is the same as
20049@samp{exec-file @var{program}}.
20050
c906108c 20051@item target core @var{filename}
4644b6e3 20052@cindex core dump file target
c906108c
SS
20053A core dump file. @samp{target core @var{filename}} is the same as
20054@samp{core-file @var{filename}}.
c906108c 20055
1a10341b 20056@item target remote @var{medium}
4644b6e3 20057@cindex remote target
1a10341b
JB
20058A remote system connected to @value{GDBN} via a serial line or network
20059connection. This command tells @value{GDBN} to use its own remote
20060protocol over @var{medium} for debugging. @xref{Remote Debugging}.
20061
20062For example, if you have a board connected to @file{/dev/ttya} on the
20063machine running @value{GDBN}, you could say:
20064
20065@smallexample
20066target remote /dev/ttya
20067@end smallexample
20068
20069@code{target remote} supports the @code{load} command. This is only
20070useful if you have some other way of getting the stub to the target
20071system, and you can put it somewhere in memory where it won't get
20072clobbered by the download.
c906108c 20073
ee8e71d4 20074@item target sim @r{[}@var{simargs}@r{]} @dots{}
4644b6e3 20075@cindex built-in simulator target
2df3850c 20076Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 20077In general,
474c8240 20078@smallexample
104c1213
JM
20079 target sim
20080 load
20081 run
474c8240 20082@end smallexample
d4f3574e 20083@noindent
104c1213 20084works; however, you cannot assume that a specific memory map, device
d4f3574e 20085drivers, or even basic I/O is available, although some simulators do
104c1213
JM
20086provide these. For info about any processor-specific simulator details,
20087see the appropriate section in @ref{Embedded Processors, ,Embedded
20088Processors}.
20089
6a3cb8e8
PA
20090@item target native
20091@cindex native target
20092Setup for local/native process debugging. Useful to make the
20093@code{run} command spawn native processes (likewise @code{attach},
20094etc.@:) even when @code{set auto-connect-native-target} is @code{off}
20095(@pxref{set auto-connect-native-target}).
20096
c906108c
SS
20097@end table
20098
5d161b24 20099Different targets are available on different configurations of @value{GDBN};
c906108c 20100your configuration may have more or fewer targets.
c906108c 20101
721c2651
EZ
20102Many remote targets require you to download the executable's code once
20103you've successfully established a connection. You may wish to control
3d00d119
DJ
20104various aspects of this process.
20105
20106@table @code
721c2651
EZ
20107
20108@item set hash
20109@kindex set hash@r{, for remote monitors}
20110@cindex hash mark while downloading
20111This command controls whether a hash mark @samp{#} is displayed while
20112downloading a file to the remote monitor. If on, a hash mark is
20113displayed after each S-record is successfully downloaded to the
20114monitor.
20115
20116@item show hash
20117@kindex show hash@r{, for remote monitors}
20118Show the current status of displaying the hash mark.
20119
20120@item set debug monitor
20121@kindex set debug monitor
20122@cindex display remote monitor communications
20123Enable or disable display of communications messages between
20124@value{GDBN} and the remote monitor.
20125
20126@item show debug monitor
20127@kindex show debug monitor
20128Show the current status of displaying communications between
20129@value{GDBN} and the remote monitor.
a8f24a35 20130@end table
c906108c
SS
20131
20132@table @code
20133
5cf30ebf
LM
20134@kindex load @var{filename} @var{offset}
20135@item load @var{filename} @var{offset}
8edfe269 20136@anchor{load}
c906108c
SS
20137Depending on what remote debugging facilities are configured into
20138@value{GDBN}, the @code{load} command may be available. Where it exists, it
20139is meant to make @var{filename} (an executable) available for debugging
20140on the remote system---by downloading, or dynamic linking, for example.
20141@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
20142the @code{add-symbol-file} command.
20143
20144If your @value{GDBN} does not have a @code{load} command, attempting to
20145execute it gets the error message ``@code{You can't do that when your
20146target is @dots{}}''
c906108c
SS
20147
20148The file is loaded at whatever address is specified in the executable.
20149For some object file formats, you can specify the load address when you
20150link the program; for other formats, like a.out, the object file format
20151specifies a fixed address.
20152@c FIXME! This would be a good place for an xref to the GNU linker doc.
20153
5cf30ebf
LM
20154It is also possible to tell @value{GDBN} to load the executable file at a
20155specific offset described by the optional argument @var{offset}. When
20156@var{offset} is provided, @var{filename} must also be provided.
20157
68437a39
DJ
20158Depending on the remote side capabilities, @value{GDBN} may be able to
20159load programs into flash memory.
20160
c906108c
SS
20161@code{load} does not repeat if you press @key{RET} again after using it.
20162@end table
20163
78cbbba8
LM
20164@table @code
20165
20166@kindex flash-erase
20167@item flash-erase
20168@anchor{flash-erase}
20169
20170Erases all known flash memory regions on the target.
20171
20172@end table
20173
6d2ebf8b 20174@node Byte Order
79a6e687 20175@section Choosing Target Byte Order
7a292a7a 20176
c906108c
SS
20177@cindex choosing target byte order
20178@cindex target byte order
c906108c 20179
eb17f351 20180Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
c906108c
SS
20181offer the ability to run either big-endian or little-endian byte
20182orders. Usually the executable or symbol will include a bit to
20183designate the endian-ness, and you will not need to worry about
20184which to use. However, you may still find it useful to adjust
d4f3574e 20185@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
20186
20187@table @code
4644b6e3 20188@kindex set endian
c906108c
SS
20189@item set endian big
20190Instruct @value{GDBN} to assume the target is big-endian.
20191
c906108c
SS
20192@item set endian little
20193Instruct @value{GDBN} to assume the target is little-endian.
20194
c906108c
SS
20195@item set endian auto
20196Instruct @value{GDBN} to use the byte order associated with the
20197executable.
20198
20199@item show endian
20200Display @value{GDBN}'s current idea of the target byte order.
20201
20202@end table
20203
20204Note that these commands merely adjust interpretation of symbolic
20205data on the host, and that they have absolutely no effect on the
20206target system.
20207
ea35711c
DJ
20208
20209@node Remote Debugging
20210@chapter Debugging Remote Programs
c906108c
SS
20211@cindex remote debugging
20212
20213If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
20214@value{GDBN} in the usual way, it is often useful to use remote debugging.
20215For example, you might use remote debugging on an operating system kernel,
c906108c
SS
20216or on a small system which does not have a general purpose operating system
20217powerful enough to run a full-featured debugger.
20218
20219Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
20220to make this work with particular debugging targets. In addition,
5d161b24 20221@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
20222but not specific to any particular target system) which you can use if you
20223write the remote stubs---the code that runs on the remote system to
20224communicate with @value{GDBN}.
20225
20226Other remote targets may be available in your
20227configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 20228
6b2f586d 20229@menu
07f31aa6 20230* Connecting:: Connecting to a remote target
a6b151f1 20231* File Transfer:: Sending files to a remote system
6b2f586d 20232* Server:: Using the gdbserver program
79a6e687
BW
20233* Remote Configuration:: Remote configuration
20234* Remote Stub:: Implementing a remote stub
6b2f586d
AC
20235@end menu
20236
07f31aa6 20237@node Connecting
79a6e687 20238@section Connecting to a Remote Target
19d9d4ef
DB
20239@cindex remote debugging, connecting
20240@cindex @code{gdbserver}, connecting
20241@cindex remote debugging, types of connections
20242@cindex @code{gdbserver}, types of connections
20243@cindex @code{gdbserver}, @code{target remote} mode
20244@cindex @code{gdbserver}, @code{target extended-remote} mode
20245
20246This section describes how to connect to a remote target, including the
20247types of connections and their differences, how to set up executable and
20248symbol files on the host and target, and the commands used for
20249connecting to and disconnecting from the remote target.
20250
20251@subsection Types of Remote Connections
20252
20253@value{GDBN} supports two types of remote connections, @code{target remote}
20254mode and @code{target extended-remote} mode. Note that many remote targets
20255support only @code{target remote} mode. There are several major
20256differences between the two types of connections, enumerated here:
20257
20258@table @asis
20259
20260@cindex remote debugging, detach and program exit
20261@item Result of detach or program exit
20262@strong{With target remote mode:} When the debugged program exits or you
20263detach from it, @value{GDBN} disconnects from the target. When using
20264@code{gdbserver}, @code{gdbserver} will exit.
20265
20266@strong{With target extended-remote mode:} When the debugged program exits or
20267you detach from it, @value{GDBN} remains connected to the target, even
20268though no program is running. You can rerun the program, attach to a
20269running program, or use @code{monitor} commands specific to the target.
20270
20271When using @code{gdbserver} in this case, it does not exit unless it was
20272invoked using the @option{--once} option. If the @option{--once} option
20273was not used, you can ask @code{gdbserver} to exit using the
20274@code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
20275
20276@item Specifying the program to debug
20277For both connection types you use the @code{file} command to specify the
20278program on the host system. If you are using @code{gdbserver} there are
20279some differences in how to specify the location of the program on the
20280target.
20281
20282@strong{With target remote mode:} You must either specify the program to debug
20283on the @code{gdbserver} command line or use the @option{--attach} option
20284(@pxref{Attaching to a program,,Attaching to a Running Program}).
20285
20286@cindex @option{--multi}, @code{gdbserver} option
20287@strong{With target extended-remote mode:} You may specify the program to debug
20288on the @code{gdbserver} command line, or you can load the program or attach
20289to it using @value{GDBN} commands after connecting to @code{gdbserver}.
20290
20291@anchor{--multi Option in Types of Remote Connnections}
20292You can start @code{gdbserver} without supplying an initial command to run
20293or process ID to attach. To do this, use the @option{--multi} command line
20294option. Then you can connect using @code{target extended-remote} and start
20295the program you want to debug (see below for details on using the
20296@code{run} command in this scenario). Note that the conditions under which
20297@code{gdbserver} terminates depend on how @value{GDBN} connects to it
20298(@code{target remote} or @code{target extended-remote}). The
20299@option{--multi} option to @code{gdbserver} has no influence on that.
07f31aa6 20300
19d9d4ef
DB
20301@item The @code{run} command
20302@strong{With target remote mode:} The @code{run} command is not
20303supported. Once a connection has been established, you can use all
20304the usual @value{GDBN} commands to examine and change data. The
20305remote program is already running, so you can use commands like
20306@kbd{step} and @kbd{continue}.
20307
20308@strong{With target extended-remote mode:} The @code{run} command is
20309supported. The @code{run} command uses the value set by
20310@code{set remote exec-file} (@pxref{set remote exec-file}) to select
20311the program to run. Command line arguments are supported, except for
20312wildcard expansion and I/O redirection (@pxref{Arguments}).
20313
20314If you specify the program to debug on the command line, then the
20315@code{run} command is not required to start execution, and you can
20316resume using commands like @kbd{step} and @kbd{continue} as with
20317@code{target remote} mode.
20318
20319@anchor{Attaching in Types of Remote Connections}
20320@item Attaching
20321@strong{With target remote mode:} The @value{GDBN} command @code{attach} is
20322not supported. To attach to a running program using @code{gdbserver}, you
20323must use the @option{--attach} option (@pxref{Running gdbserver}).
20324
20325@strong{With target extended-remote mode:} To attach to a running program,
20326you may use the @code{attach} command after the connection has been
20327established. If you are using @code{gdbserver}, you may also invoke
20328@code{gdbserver} using the @option{--attach} option
20329(@pxref{Running gdbserver}).
20330
20331@end table
20332
20333@anchor{Host and target files}
20334@subsection Host and Target Files
20335@cindex remote debugging, symbol files
20336@cindex symbol files, remote debugging
20337
20338@value{GDBN}, running on the host, needs access to symbol and debugging
20339information for your program running on the target. This requires
20340access to an unstripped copy of your program, and possibly any associated
20341symbol files. Note that this section applies equally to both @code{target
20342remote} mode and @code{target extended-remote} mode.
20343
20344Some remote targets (@pxref{qXfer executable filename read}, and
20345@pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
20346the same connection used to communicate with @value{GDBN}. With such a
20347target, if the remote program is unstripped, the only command you need is
20348@code{target remote} (or @code{target extended-remote}).
20349
20350If the remote program is stripped, or the target does not support remote
20351program file access, start up @value{GDBN} using the name of the local
1b6e6f5c 20352unstripped copy of your program as the first argument, or use the
19d9d4ef
DB
20353@code{file} command. Use @code{set sysroot} to specify the location (on
20354the host) of target libraries (unless your @value{GDBN} was compiled with
20355the correct sysroot using @code{--with-sysroot}). Alternatively, you
20356may use @code{set solib-search-path} to specify how @value{GDBN} locates
20357target libraries.
20358
20359The symbol file and target libraries must exactly match the executable
20360and libraries on the target, with one exception: the files on the host
20361system should not be stripped, even if the files on the target system
20362are. Mismatched or missing files will lead to confusing results
20363during debugging. On @sc{gnu}/Linux targets, mismatched or missing
20364files may also prevent @code{gdbserver} from debugging multi-threaded
20365programs.
07f31aa6 20366
19d9d4ef
DB
20367@subsection Remote Connection Commands
20368@cindex remote connection commands
86941c27
JB
20369@value{GDBN} can communicate with the target over a serial line, or
20370over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
20371each case, @value{GDBN} uses the same protocol for debugging your
20372program; only the medium carrying the debugging packets varies. The
19d9d4ef
DB
20373@code{target remote} and @code{target extended-remote} commands
20374establish a connection to the target. Both commands accept the same
20375arguments, which indicate the medium to use:
86941c27
JB
20376
20377@table @code
20378
20379@item target remote @var{serial-device}
19d9d4ef 20380@itemx target extended-remote @var{serial-device}
07f31aa6 20381@cindex serial line, @code{target remote}
86941c27
JB
20382Use @var{serial-device} to communicate with the target. For example,
20383to use a serial line connected to the device named @file{/dev/ttyb}:
20384
20385@smallexample
20386target remote /dev/ttyb
20387@end smallexample
20388
07f31aa6 20389If you're using a serial line, you may want to give @value{GDBN} the
2446f5ea 20390@samp{--baud} option, or use the @code{set serial baud} command
0d12017b 20391(@pxref{Remote Configuration, set serial baud}) before the
9c16f35a 20392@code{target} command.
07f31aa6 20393
86941c27
JB
20394@item target remote @code{@var{host}:@var{port}}
20395@itemx target remote @code{tcp:@var{host}:@var{port}}
19d9d4ef
DB
20396@itemx target extended-remote @code{@var{host}:@var{port}}
20397@itemx target extended-remote @code{tcp:@var{host}:@var{port}}
86941c27
JB
20398@cindex @acronym{TCP} port, @code{target remote}
20399Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
20400The @var{host} may be either a host name or a numeric @acronym{IP}
20401address; @var{port} must be a decimal number. The @var{host} could be
20402the target machine itself, if it is directly connected to the net, or
20403it might be a terminal server which in turn has a serial line to the
20404target.
07f31aa6 20405
86941c27
JB
20406For example, to connect to port 2828 on a terminal server named
20407@code{manyfarms}:
07f31aa6
DJ
20408
20409@smallexample
20410target remote manyfarms:2828
20411@end smallexample
20412
86941c27
JB
20413If your remote target is actually running on the same machine as your
20414debugger session (e.g.@: a simulator for your target running on the
20415same host), you can omit the hostname. For example, to connect to
20416port 1234 on your local machine:
07f31aa6
DJ
20417
20418@smallexample
20419target remote :1234
20420@end smallexample
20421@noindent
20422
20423Note that the colon is still required here.
20424
86941c27 20425@item target remote @code{udp:@var{host}:@var{port}}
19d9d4ef 20426@itemx target extended-remote @code{udp:@var{host}:@var{port}}
86941c27
JB
20427@cindex @acronym{UDP} port, @code{target remote}
20428Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
20429connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
20430
20431@smallexample
20432target remote udp:manyfarms:2828
20433@end smallexample
20434
86941c27
JB
20435When using a @acronym{UDP} connection for remote debugging, you should
20436keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
20437can silently drop packets on busy or unreliable networks, which will
20438cause havoc with your debugging session.
20439
66b8c7f6 20440@item target remote | @var{command}
19d9d4ef 20441@itemx target extended-remote | @var{command}
66b8c7f6
JB
20442@cindex pipe, @code{target remote} to
20443Run @var{command} in the background and communicate with it using a
20444pipe. The @var{command} is a shell command, to be parsed and expanded
20445by the system's command shell, @code{/bin/sh}; it should expect remote
20446protocol packets on its standard input, and send replies on its
20447standard output. You could use this to run a stand-alone simulator
20448that speaks the remote debugging protocol, to make net connections
20449using programs like @code{ssh}, or for other similar tricks.
20450
20451If @var{command} closes its standard output (perhaps by exiting),
20452@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
20453program has already exited, this will have no effect.)
20454
86941c27 20455@end table
07f31aa6 20456
07f31aa6
DJ
20457@cindex interrupting remote programs
20458@cindex remote programs, interrupting
20459Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 20460interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
20461program. This may or may not succeed, depending in part on the hardware
20462and the serial drivers the remote system uses. If you type the
20463interrupt character once again, @value{GDBN} displays this prompt:
20464
20465@smallexample
20466Interrupted while waiting for the program.
20467Give up (and stop debugging it)? (y or n)
20468@end smallexample
20469
19d9d4ef
DB
20470In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
20471the remote debugging session. (If you decide you want to try again later,
20472you can use @kbd{target remote} again to connect once more.) If you type
20473@kbd{n}, @value{GDBN} goes back to waiting.
20474
20475In @code{target extended-remote} mode, typing @kbd{n} will leave
20476@value{GDBN} connected to the target.
07f31aa6
DJ
20477
20478@table @code
20479@kindex detach (remote)
20480@item detach
20481When you have finished debugging the remote program, you can use the
20482@code{detach} command to release it from @value{GDBN} control.
20483Detaching from the target normally resumes its execution, but the results
20484will depend on your particular remote stub. After the @code{detach}
19d9d4ef
DB
20485command in @code{target remote} mode, @value{GDBN} is free to connect to
20486another target. In @code{target extended-remote} mode, @value{GDBN} is
20487still connected to the target.
07f31aa6
DJ
20488
20489@kindex disconnect
20490@item disconnect
19d9d4ef 20491The @code{disconnect} command closes the connection to the target, and
07f31aa6
DJ
20492the target is generally not resumed. It will wait for @value{GDBN}
20493(this instance or another one) to connect and continue debugging. After
20494the @code{disconnect} command, @value{GDBN} is again free to connect to
20495another target.
09d4efe1
EZ
20496
20497@cindex send command to remote monitor
fad38dfa
EZ
20498@cindex extend @value{GDBN} for remote targets
20499@cindex add new commands for external monitor
09d4efe1
EZ
20500@kindex monitor
20501@item monitor @var{cmd}
fad38dfa
EZ
20502This command allows you to send arbitrary commands directly to the
20503remote monitor. Since @value{GDBN} doesn't care about the commands it
20504sends like this, this command is the way to extend @value{GDBN}---you
20505can add new commands that only the external monitor will understand
20506and implement.
07f31aa6
DJ
20507@end table
20508
a6b151f1
DJ
20509@node File Transfer
20510@section Sending files to a remote system
20511@cindex remote target, file transfer
20512@cindex file transfer
20513@cindex sending files to remote systems
20514
20515Some remote targets offer the ability to transfer files over the same
20516connection used to communicate with @value{GDBN}. This is convenient
20517for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
20518running @code{gdbserver} over a network interface. For other targets,
20519e.g.@: embedded devices with only a single serial port, this may be
20520the only way to upload or download files.
20521
20522Not all remote targets support these commands.
20523
20524@table @code
20525@kindex remote put
20526@item remote put @var{hostfile} @var{targetfile}
20527Copy file @var{hostfile} from the host system (the machine running
20528@value{GDBN}) to @var{targetfile} on the target system.
20529
20530@kindex remote get
20531@item remote get @var{targetfile} @var{hostfile}
20532Copy file @var{targetfile} from the target system to @var{hostfile}
20533on the host system.
20534
20535@kindex remote delete
20536@item remote delete @var{targetfile}
20537Delete @var{targetfile} from the target system.
20538
20539@end table
20540
6f05cf9f 20541@node Server
79a6e687 20542@section Using the @code{gdbserver} Program
6f05cf9f
AC
20543
20544@kindex gdbserver
20545@cindex remote connection without stubs
20546@code{gdbserver} is a control program for Unix-like systems, which
20547allows you to connect your program with a remote @value{GDBN} via
19d9d4ef
DB
20548@code{target remote} or @code{target extended-remote}---but without
20549linking in the usual debugging stub.
6f05cf9f
AC
20550
20551@code{gdbserver} is not a complete replacement for the debugging stubs,
20552because it requires essentially the same operating-system facilities
20553that @value{GDBN} itself does. In fact, a system that can run
20554@code{gdbserver} to connect to a remote @value{GDBN} could also run
20555@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
20556because it is a much smaller program than @value{GDBN} itself. It is
20557also easier to port than all of @value{GDBN}, so you may be able to get
20558started more quickly on a new system by using @code{gdbserver}.
20559Finally, if you develop code for real-time systems, you may find that
20560the tradeoffs involved in real-time operation make it more convenient to
20561do as much development work as possible on another system, for example
20562by cross-compiling. You can use @code{gdbserver} to make a similar
20563choice for debugging.
20564
20565@value{GDBN} and @code{gdbserver} communicate via either a serial line
20566or a TCP connection, using the standard @value{GDBN} remote serial
20567protocol.
20568
2d717e4f
DJ
20569@quotation
20570@emph{Warning:} @code{gdbserver} does not have any built-in security.
20571Do not run @code{gdbserver} connected to any public network; a
20572@value{GDBN} connection to @code{gdbserver} provides access to the
20573target system with the same privileges as the user running
20574@code{gdbserver}.
20575@end quotation
20576
19d9d4ef 20577@anchor{Running gdbserver}
2d717e4f
DJ
20578@subsection Running @code{gdbserver}
20579@cindex arguments, to @code{gdbserver}
d9b1a651 20580@cindex @code{gdbserver}, command-line arguments
2d717e4f
DJ
20581
20582Run @code{gdbserver} on the target system. You need a copy of the
20583program you want to debug, including any libraries it requires.
6f05cf9f
AC
20584@code{gdbserver} does not need your program's symbol table, so you can
20585strip the program if necessary to save space. @value{GDBN} on the host
20586system does all the symbol handling.
20587
20588To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 20589the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
20590syntax is:
20591
20592@smallexample
20593target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
20594@end smallexample
20595
e0f9f062
DE
20596@var{comm} is either a device name (to use a serial line), or a TCP
20597hostname and portnumber, or @code{-} or @code{stdio} to use
20598stdin/stdout of @code{gdbserver}.
20599For example, to debug Emacs with the argument
6f05cf9f
AC
20600@samp{foo.txt} and communicate with @value{GDBN} over the serial port
20601@file{/dev/com1}:
20602
20603@smallexample
20604target> gdbserver /dev/com1 emacs foo.txt
20605@end smallexample
20606
20607@code{gdbserver} waits passively for the host @value{GDBN} to communicate
20608with it.
20609
20610To use a TCP connection instead of a serial line:
20611
20612@smallexample
20613target> gdbserver host:2345 emacs foo.txt
20614@end smallexample
20615
20616The only difference from the previous example is the first argument,
20617specifying that you are communicating with the host @value{GDBN} via
20618TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
20619expect a TCP connection from machine @samp{host} to local TCP port 2345.
20620(Currently, the @samp{host} part is ignored.) You can choose any number
20621you want for the port number as long as it does not conflict with any
20622TCP ports already in use on the target system (for example, @code{23} is
20623reserved for @code{telnet}).@footnote{If you choose a port number that
20624conflicts with another service, @code{gdbserver} prints an error message
20625and exits.} You must use the same port number with the host @value{GDBN}
20626@code{target remote} command.
20627
e0f9f062
DE
20628The @code{stdio} connection is useful when starting @code{gdbserver}
20629with ssh:
20630
20631@smallexample
20632(gdb) target remote | ssh -T hostname gdbserver - hello
20633@end smallexample
20634
20635The @samp{-T} option to ssh is provided because we don't need a remote pty,
20636and we don't want escape-character handling. Ssh does this by default when
20637a command is provided, the flag is provided to make it explicit.
20638You could elide it if you want to.
20639
20640Programs started with stdio-connected gdbserver have @file{/dev/null} for
20641@code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
20642display through a pipe connected to gdbserver.
20643Both @code{stdout} and @code{stderr} use the same pipe.
20644
19d9d4ef 20645@anchor{Attaching to a program}
2d717e4f 20646@subsubsection Attaching to a Running Program
d9b1a651
EZ
20647@cindex attach to a program, @code{gdbserver}
20648@cindex @option{--attach}, @code{gdbserver} option
2d717e4f 20649
56460a61
DJ
20650On some targets, @code{gdbserver} can also attach to running programs.
20651This is accomplished via the @code{--attach} argument. The syntax is:
20652
20653@smallexample
2d717e4f 20654target> gdbserver --attach @var{comm} @var{pid}
56460a61
DJ
20655@end smallexample
20656
19d9d4ef
DB
20657@var{pid} is the process ID of a currently running process. It isn't
20658necessary to point @code{gdbserver} at a binary for the running process.
20659
20660In @code{target extended-remote} mode, you can also attach using the
20661@value{GDBN} attach command
20662(@pxref{Attaching in Types of Remote Connections}).
56460a61 20663
b1fe9455 20664@pindex pidof
b1fe9455
DJ
20665You can debug processes by name instead of process ID if your target has the
20666@code{pidof} utility:
20667
20668@smallexample
2d717e4f 20669target> gdbserver --attach @var{comm} `pidof @var{program}`
b1fe9455
DJ
20670@end smallexample
20671
f822c95b 20672In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
20673has multiple threads, most versions of @code{pidof} support the
20674@code{-s} option to only return the first process ID.
20675
03f2bd59
JK
20676@subsubsection TCP port allocation lifecycle of @code{gdbserver}
20677
19d9d4ef
DB
20678This section applies only when @code{gdbserver} is run to listen on a TCP
20679port.
03f2bd59
JK
20680
20681@code{gdbserver} normally terminates after all of its debugged processes have
20682terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
20683extended-remote}, @code{gdbserver} stays running even with no processes left.
20684@value{GDBN} normally terminates the spawned debugged process on its exit,
20685which normally also terminates @code{gdbserver} in the @kbd{target remote}
20686mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
20687cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
20688stays running even in the @kbd{target remote} mode.
20689
20690When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
20691Such reconnecting is useful for features like @ref{disconnected tracing}. For
20692completeness, at most one @value{GDBN} can be connected at a time.
20693
20694@cindex @option{--once}, @code{gdbserver} option
20695By default, @code{gdbserver} keeps the listening TCP port open, so that
6e8c5661 20696subsequent connections are possible. However, if you start @code{gdbserver}
03f2bd59
JK
20697with the @option{--once} option, it will stop listening for any further
20698connection attempts after connecting to the first @value{GDBN} session. This
20699means no further connections to @code{gdbserver} will be possible after the
20700first one. It also means @code{gdbserver} will terminate after the first
20701connection with remote @value{GDBN} has closed, even for unexpectedly closed
20702connections and even in the @kbd{target extended-remote} mode. The
20703@option{--once} option allows reusing the same port number for connecting to
20704multiple instances of @code{gdbserver} running on the same host, since each
20705instance closes its port after the first connection.
2d717e4f 20706
87ce2a04 20707@anchor{Other Command-Line Arguments for gdbserver}
2d717e4f
DJ
20708@subsubsection Other Command-Line Arguments for @code{gdbserver}
20709
19d9d4ef
DB
20710You can use the @option{--multi} option to start @code{gdbserver} without
20711specifying a program to debug or a process to attach to. Then you can
20712attach in @code{target extended-remote} mode and run or attach to a
20713program. For more information,
20714@pxref{--multi Option in Types of Remote Connnections}.
20715
d9b1a651 20716@cindex @option{--debug}, @code{gdbserver} option
62709adf 20717The @option{--debug} option tells @code{gdbserver} to display extra
d9b1a651
EZ
20718status information about the debugging process.
20719@cindex @option{--remote-debug}, @code{gdbserver} option
20720The @option{--remote-debug} option tells @code{gdbserver} to display
62709adf
PA
20721remote protocol debug output. These options are intended for
20722@code{gdbserver} development and for bug reports to the developers.
2d717e4f 20723
87ce2a04
DE
20724@cindex @option{--debug-format}, @code{gdbserver} option
20725The @option{--debug-format=option1[,option2,...]} option tells
20726@code{gdbserver} to include additional information in each output.
20727Possible options are:
20728
20729@table @code
20730@item none
20731Turn off all extra information in debugging output.
20732@item all
20733Turn on all extra information in debugging output.
20734@item timestamps
20735Include a timestamp in each line of debugging output.
20736@end table
20737
20738Options are processed in order. Thus, for example, if @option{none}
20739appears last then no additional information is added to debugging output.
20740
d9b1a651 20741@cindex @option{--wrapper}, @code{gdbserver} option
ccd213ac
DJ
20742The @option{--wrapper} option specifies a wrapper to launch programs
20743for debugging. The option should be followed by the name of the
20744wrapper, then any command-line arguments to pass to the wrapper, then
20745@kbd{--} indicating the end of the wrapper arguments.
20746
20747@code{gdbserver} runs the specified wrapper program with a combined
20748command line including the wrapper arguments, then the name of the
20749program to debug, then any arguments to the program. The wrapper
20750runs until it executes your program, and then @value{GDBN} gains control.
20751
20752You can use any program that eventually calls @code{execve} with
20753its arguments as a wrapper. Several standard Unix utilities do
20754this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
20755with @code{exec "$@@"} will also work.
20756
20757For example, you can use @code{env} to pass an environment variable to
20758the debugged program, without setting the variable in @code{gdbserver}'s
20759environment:
20760
20761@smallexample
20762$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
20763@end smallexample
20764
6d580b63
YQ
20765@cindex @option{--selftest}
20766The @option{--selftest} option runs the self tests in @code{gdbserver}:
20767
20768@smallexample
20769$ gdbserver --selftest
20770Ran 2 unit tests, 0 failed
20771@end smallexample
20772
20773These tests are disabled in release.
2d717e4f
DJ
20774@subsection Connecting to @code{gdbserver}
20775
19d9d4ef
DB
20776The basic procedure for connecting to the remote target is:
20777@itemize
2d717e4f 20778
19d9d4ef
DB
20779@item
20780Run @value{GDBN} on the host system.
f822c95b 20781
19d9d4ef
DB
20782@item
20783Make sure you have the necessary symbol files
20784(@pxref{Host and target files}).
20785Load symbols for your application using the @code{file} command before you
20786connect. Use @code{set sysroot} to locate target libraries (unless your
20787@value{GDBN} was compiled with the correct sysroot using
20788@code{--with-sysroot}).
f822c95b 20789
19d9d4ef 20790@item
79a6e687 20791Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f 20792For TCP connections, you must start up @code{gdbserver} prior to using
19d9d4ef 20793the @code{target} command. Otherwise you may get an error whose
6f05cf9f 20794text depends on the host system, but which usually looks something like
2d717e4f 20795@samp{Connection refused}. Don't use the @code{load}
19d9d4ef
DB
20796command in @value{GDBN} when using @code{target remote} mode, since the
20797program is already on the target.
20798
20799@end itemize
07f31aa6 20800
19d9d4ef 20801@anchor{Monitor Commands for gdbserver}
79a6e687 20802@subsection Monitor Commands for @code{gdbserver}
c74d0ad8
DJ
20803@cindex monitor commands, for @code{gdbserver}
20804
20805During a @value{GDBN} session using @code{gdbserver}, you can use the
20806@code{monitor} command to send special requests to @code{gdbserver}.
2d717e4f 20807Here are the available commands.
c74d0ad8
DJ
20808
20809@table @code
20810@item monitor help
20811List the available monitor commands.
20812
20813@item monitor set debug 0
20814@itemx monitor set debug 1
20815Disable or enable general debugging messages.
20816
20817@item monitor set remote-debug 0
20818@itemx monitor set remote-debug 1
20819Disable or enable specific debugging messages associated with the remote
20820protocol (@pxref{Remote Protocol}).
20821
87ce2a04
DE
20822@item monitor set debug-format option1@r{[},option2,...@r{]}
20823Specify additional text to add to debugging messages.
20824Possible options are:
20825
20826@table @code
20827@item none
20828Turn off all extra information in debugging output.
20829@item all
20830Turn on all extra information in debugging output.
20831@item timestamps
20832Include a timestamp in each line of debugging output.
20833@end table
20834
20835Options are processed in order. Thus, for example, if @option{none}
20836appears last then no additional information is added to debugging output.
20837
cdbfd419
PP
20838@item monitor set libthread-db-search-path [PATH]
20839@cindex gdbserver, search path for @code{libthread_db}
20840When this command is issued, @var{path} is a colon-separated list of
20841directories to search for @code{libthread_db} (@pxref{Threads,,set
20842libthread-db-search-path}). If you omit @var{path},
84e578fb 20843@samp{libthread-db-search-path} will be reset to its default value.
cdbfd419 20844
98a5dd13
DE
20845The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
20846not supported in @code{gdbserver}.
20847
2d717e4f
DJ
20848@item monitor exit
20849Tell gdbserver to exit immediately. This command should be followed by
20850@code{disconnect} to close the debugging session. @code{gdbserver} will
20851detach from any attached processes and kill any processes it created.
20852Use @code{monitor exit} to terminate @code{gdbserver} at the end
20853of a multi-process mode debug session.
20854
c74d0ad8
DJ
20855@end table
20856
fa593d66
PA
20857@subsection Tracepoints support in @code{gdbserver}
20858@cindex tracepoints support in @code{gdbserver}
20859
0fb4aa4b
PA
20860On some targets, @code{gdbserver} supports tracepoints, fast
20861tracepoints and static tracepoints.
fa593d66 20862
0fb4aa4b 20863For fast or static tracepoints to work, a special library called the
fa593d66
PA
20864@dfn{in-process agent} (IPA), must be loaded in the inferior process.
20865This library is built and distributed as an integral part of
0fb4aa4b
PA
20866@code{gdbserver}. In addition, support for static tracepoints
20867requires building the in-process agent library with static tracepoints
20868support. At present, the UST (LTTng Userspace Tracer,
20869@url{http://lttng.org/ust}) tracing engine is supported. This support
20870is automatically available if UST development headers are found in the
20871standard include path when @code{gdbserver} is built, or if
20872@code{gdbserver} was explicitly configured using @option{--with-ust}
20873to point at such headers. You can explicitly disable the support
20874using @option{--with-ust=no}.
fa593d66
PA
20875
20876There are several ways to load the in-process agent in your program:
20877
20878@table @code
20879@item Specifying it as dependency at link time
20880
20881You can link your program dynamically with the in-process agent
20882library. On most systems, this is accomplished by adding
20883@code{-linproctrace} to the link command.
20884
20885@item Using the system's preloading mechanisms
20886
20887You can force loading the in-process agent at startup time by using
20888your system's support for preloading shared libraries. Many Unixes
20889support the concept of preloading user defined libraries. In most
20890cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
20891in the environment. See also the description of @code{gdbserver}'s
20892@option{--wrapper} command line option.
20893
20894@item Using @value{GDBN} to force loading the agent at run time
20895
20896On some systems, you can force the inferior to load a shared library,
20897by calling a dynamic loader function in the inferior that takes care
20898of dynamically looking up and loading a shared library. On most Unix
20899systems, the function is @code{dlopen}. You'll use the @code{call}
20900command for that. For example:
20901
20902@smallexample
20903(@value{GDBP}) call dlopen ("libinproctrace.so", ...)
20904@end smallexample
20905
20906Note that on most Unix systems, for the @code{dlopen} function to be
20907available, the program needs to be linked with @code{-ldl}.
20908@end table
20909
20910On systems that have a userspace dynamic loader, like most Unix
20911systems, when you connect to @code{gdbserver} using @code{target
20912remote}, you'll find that the program is stopped at the dynamic
20913loader's entry point, and no shared library has been loaded in the
20914program's address space yet, including the in-process agent. In that
0fb4aa4b
PA
20915case, before being able to use any of the fast or static tracepoints
20916features, you need to let the loader run and load the shared
20917libraries. The simplest way to do that is to run the program to the
20918main procedure. E.g., if debugging a C or C@t{++} program, start
fa593d66
PA
20919@code{gdbserver} like so:
20920
20921@smallexample
20922$ gdbserver :9999 myprogram
20923@end smallexample
20924
20925Start GDB and connect to @code{gdbserver} like so, and run to main:
20926
20927@smallexample
20928$ gdb myprogram
20929(@value{GDBP}) target remote myhost:9999
209300x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
20931(@value{GDBP}) b main
20932(@value{GDBP}) continue
20933@end smallexample
20934
20935The in-process tracing agent library should now be loaded into the
20936process; you can confirm it with the @code{info sharedlibrary}
20937command, which will list @file{libinproctrace.so} as loaded in the
0fb4aa4b
PA
20938process. You are now ready to install fast tracepoints, list static
20939tracepoint markers, probe static tracepoints markers, and start
fa593d66
PA
20940tracing.
20941
79a6e687
BW
20942@node Remote Configuration
20943@section Remote Configuration
501eef12 20944
9c16f35a
EZ
20945@kindex set remote
20946@kindex show remote
20947This section documents the configuration options available when
20948debugging remote programs. For the options related to the File I/O
fc320d37 20949extensions of the remote protocol, see @ref{system,
9c16f35a 20950system-call-allowed}.
501eef12
AC
20951
20952@table @code
9c16f35a 20953@item set remoteaddresssize @var{bits}
d3e8051b 20954@cindex address size for remote targets
9c16f35a
EZ
20955@cindex bits in remote address
20956Set the maximum size of address in a memory packet to the specified
20957number of bits. @value{GDBN} will mask off the address bits above
20958that number, when it passes addresses to the remote target. The
20959default value is the number of bits in the target's address.
20960
20961@item show remoteaddresssize
20962Show the current value of remote address size in bits.
20963
0d12017b 20964@item set serial baud @var{n}
9c16f35a
EZ
20965@cindex baud rate for remote targets
20966Set the baud rate for the remote serial I/O to @var{n} baud. The
20967value is used to set the speed of the serial port used for debugging
20968remote targets.
20969
0d12017b 20970@item show serial baud
9c16f35a
EZ
20971Show the current speed of the remote connection.
20972
236af5e3
YG
20973@item set serial parity @var{parity}
20974Set the parity for the remote serial I/O. Supported values of @var{parity} are:
20975@code{even}, @code{none}, and @code{odd}. The default is @code{none}.
20976
20977@item show serial parity
20978Show the current parity of the serial port.
20979
9c16f35a
EZ
20980@item set remotebreak
20981@cindex interrupt remote programs
20982@cindex BREAK signal instead of Ctrl-C
9a6253be 20983@anchor{set remotebreak}
9c16f35a 20984If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 20985when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 20986on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
20987character instead. The default is off, since most remote systems
20988expect to see @samp{Ctrl-C} as the interrupt signal.
20989
20990@item show remotebreak
20991Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
20992interrupt the remote program.
20993
23776285
MR
20994@item set remoteflow on
20995@itemx set remoteflow off
20996@kindex set remoteflow
20997Enable or disable hardware flow control (@code{RTS}/@code{CTS})
20998on the serial port used to communicate to the remote target.
20999
21000@item show remoteflow
21001@kindex show remoteflow
21002Show the current setting of hardware flow control.
21003
9c16f35a
EZ
21004@item set remotelogbase @var{base}
21005Set the base (a.k.a.@: radix) of logging serial protocol
21006communications to @var{base}. Supported values of @var{base} are:
21007@code{ascii}, @code{octal}, and @code{hex}. The default is
21008@code{ascii}.
21009
21010@item show remotelogbase
21011Show the current setting of the radix for logging remote serial
21012protocol.
21013
21014@item set remotelogfile @var{file}
21015@cindex record serial communications on file
21016Record remote serial communications on the named @var{file}. The
21017default is not to record at all.
21018
21019@item show remotelogfile.
21020Show the current setting of the file name on which to record the
21021serial communications.
21022
21023@item set remotetimeout @var{num}
21024@cindex timeout for serial communications
21025@cindex remote timeout
21026Set the timeout limit to wait for the remote target to respond to
21027@var{num} seconds. The default is 2 seconds.
21028
21029@item show remotetimeout
21030Show the current number of seconds to wait for the remote target
21031responses.
21032
21033@cindex limit hardware breakpoints and watchpoints
21034@cindex remote target, limit break- and watchpoints
501eef12
AC
21035@anchor{set remote hardware-watchpoint-limit}
21036@anchor{set remote hardware-breakpoint-limit}
21037@item set remote hardware-watchpoint-limit @var{limit}
21038@itemx set remote hardware-breakpoint-limit @var{limit}
21039Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
21040watchpoints. A limit of -1, the default, is treated as unlimited.
2d717e4f 21041
480a3f21
PW
21042@cindex limit hardware watchpoints length
21043@cindex remote target, limit watchpoints length
21044@anchor{set remote hardware-watchpoint-length-limit}
21045@item set remote hardware-watchpoint-length-limit @var{limit}
21046Restrict @value{GDBN} to using @var{limit} bytes for the maximum length of
21047a remote hardware watchpoint. A limit of -1, the default, is treated
21048as unlimited.
21049
21050@item show remote hardware-watchpoint-length-limit
21051Show the current limit (in bytes) of the maximum length of
21052a remote hardware watchpoint.
21053
2d717e4f
DJ
21054@item set remote exec-file @var{filename}
21055@itemx show remote exec-file
21056@anchor{set remote exec-file}
21057@cindex executable file, for remote target
21058Select the file used for @code{run} with @code{target
21059extended-remote}. This should be set to a filename valid on the
21060target system. If it is not set, the target will use a default
21061filename (e.g.@: the last program run).
84603566 21062
9a7071a8
JB
21063@item set remote interrupt-sequence
21064@cindex interrupt remote programs
21065@cindex select Ctrl-C, BREAK or BREAK-g
21066Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
21067@samp{BREAK-g} as the
21068sequence to the remote target in order to interrupt the execution.
21069@samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
21070is high level of serial line for some certain time.
21071Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
21072It is @code{BREAK} signal followed by character @code{g}.
21073
21074@item show interrupt-sequence
21075Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
21076is sent by @value{GDBN} to interrupt the remote program.
21077@code{BREAK-g} is BREAK signal followed by @code{g} and
21078also known as Magic SysRq g.
21079
21080@item set remote interrupt-on-connect
21081@cindex send interrupt-sequence on start
21082Specify whether interrupt-sequence is sent to remote target when
21083@value{GDBN} connects to it. This is mostly needed when you debug
21084Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
21085which is known as Magic SysRq g in order to connect @value{GDBN}.
21086
21087@item show interrupt-on-connect
21088Show whether interrupt-sequence is sent
21089to remote target when @value{GDBN} connects to it.
21090
84603566
SL
21091@kindex set tcp
21092@kindex show tcp
21093@item set tcp auto-retry on
21094@cindex auto-retry, for remote TCP target
21095Enable auto-retry for remote TCP connections. This is useful if the remote
21096debugging agent is launched in parallel with @value{GDBN}; there is a race
21097condition because the agent may not become ready to accept the connection
21098before @value{GDBN} attempts to connect. When auto-retry is
21099enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
21100to establish the connection using the timeout specified by
21101@code{set tcp connect-timeout}.
21102
21103@item set tcp auto-retry off
21104Do not auto-retry failed TCP connections.
21105
21106@item show tcp auto-retry
21107Show the current auto-retry setting.
21108
21109@item set tcp connect-timeout @var{seconds}
f81d1120 21110@itemx set tcp connect-timeout unlimited
84603566
SL
21111@cindex connection timeout, for remote TCP target
21112@cindex timeout, for remote target connection
21113Set the timeout for establishing a TCP connection to the remote target to
21114@var{seconds}. The timeout affects both polling to retry failed connections
21115(enabled by @code{set tcp auto-retry on}) and waiting for connections
21116that are merely slow to complete, and represents an approximate cumulative
f81d1120
PA
21117value. If @var{seconds} is @code{unlimited}, there is no timeout and
21118@value{GDBN} will keep attempting to establish a connection forever,
21119unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
84603566
SL
21120
21121@item show tcp connect-timeout
21122Show the current connection timeout setting.
501eef12
AC
21123@end table
21124
427c3a89
DJ
21125@cindex remote packets, enabling and disabling
21126The @value{GDBN} remote protocol autodetects the packets supported by
21127your debugging stub. If you need to override the autodetection, you
21128can use these commands to enable or disable individual packets. Each
21129packet can be set to @samp{on} (the remote target supports this
21130packet), @samp{off} (the remote target does not support this packet),
21131or @samp{auto} (detect remote target support for this packet). They
21132all default to @samp{auto}. For more information about each packet,
21133see @ref{Remote Protocol}.
21134
21135During normal use, you should not have to use any of these commands.
21136If you do, that may be a bug in your remote debugging stub, or a bug
21137in @value{GDBN}. You may want to report the problem to the
21138@value{GDBN} developers.
21139
cfa9d6d9
DJ
21140For each packet @var{name}, the command to enable or disable the
21141packet is @code{set remote @var{name}-packet}. The available settings
21142are:
427c3a89 21143
cfa9d6d9 21144@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
21145@item Command Name
21146@tab Remote Packet
21147@tab Related Features
21148
cfa9d6d9 21149@item @code{fetch-register}
427c3a89
DJ
21150@tab @code{p}
21151@tab @code{info registers}
21152
cfa9d6d9 21153@item @code{set-register}
427c3a89
DJ
21154@tab @code{P}
21155@tab @code{set}
21156
cfa9d6d9 21157@item @code{binary-download}
427c3a89
DJ
21158@tab @code{X}
21159@tab @code{load}, @code{set}
21160
cfa9d6d9 21161@item @code{read-aux-vector}
427c3a89
DJ
21162@tab @code{qXfer:auxv:read}
21163@tab @code{info auxv}
21164
cfa9d6d9 21165@item @code{symbol-lookup}
427c3a89
DJ
21166@tab @code{qSymbol}
21167@tab Detecting multiple threads
21168
2d717e4f
DJ
21169@item @code{attach}
21170@tab @code{vAttach}
21171@tab @code{attach}
21172
cfa9d6d9 21173@item @code{verbose-resume}
427c3a89
DJ
21174@tab @code{vCont}
21175@tab Stepping or resuming multiple threads
21176
2d717e4f
DJ
21177@item @code{run}
21178@tab @code{vRun}
21179@tab @code{run}
21180
cfa9d6d9 21181@item @code{software-breakpoint}
427c3a89
DJ
21182@tab @code{Z0}
21183@tab @code{break}
21184
cfa9d6d9 21185@item @code{hardware-breakpoint}
427c3a89
DJ
21186@tab @code{Z1}
21187@tab @code{hbreak}
21188
cfa9d6d9 21189@item @code{write-watchpoint}
427c3a89
DJ
21190@tab @code{Z2}
21191@tab @code{watch}
21192
cfa9d6d9 21193@item @code{read-watchpoint}
427c3a89
DJ
21194@tab @code{Z3}
21195@tab @code{rwatch}
21196
cfa9d6d9 21197@item @code{access-watchpoint}
427c3a89
DJ
21198@tab @code{Z4}
21199@tab @code{awatch}
21200
c78fa86a
GB
21201@item @code{pid-to-exec-file}
21202@tab @code{qXfer:exec-file:read}
21203@tab @code{attach}, @code{run}
21204
cfa9d6d9
DJ
21205@item @code{target-features}
21206@tab @code{qXfer:features:read}
21207@tab @code{set architecture}
21208
21209@item @code{library-info}
21210@tab @code{qXfer:libraries:read}
21211@tab @code{info sharedlibrary}
21212
21213@item @code{memory-map}
21214@tab @code{qXfer:memory-map:read}
21215@tab @code{info mem}
21216
0fb4aa4b
PA
21217@item @code{read-sdata-object}
21218@tab @code{qXfer:sdata:read}
21219@tab @code{print $_sdata}
21220
cfa9d6d9
DJ
21221@item @code{read-spu-object}
21222@tab @code{qXfer:spu:read}
21223@tab @code{info spu}
21224
21225@item @code{write-spu-object}
21226@tab @code{qXfer:spu:write}
21227@tab @code{info spu}
21228
4aa995e1
PA
21229@item @code{read-siginfo-object}
21230@tab @code{qXfer:siginfo:read}
21231@tab @code{print $_siginfo}
21232
21233@item @code{write-siginfo-object}
21234@tab @code{qXfer:siginfo:write}
21235@tab @code{set $_siginfo}
21236
dc146f7c
VP
21237@item @code{threads}
21238@tab @code{qXfer:threads:read}
21239@tab @code{info threads}
21240
cfa9d6d9 21241@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
21242@tab @code{qGetTLSAddr}
21243@tab Displaying @code{__thread} variables
21244
711e434b
PM
21245@item @code{get-thread-information-block-address}
21246@tab @code{qGetTIBAddr}
21247@tab Display MS-Windows Thread Information Block.
21248
08388c79
DE
21249@item @code{search-memory}
21250@tab @code{qSearch:memory}
21251@tab @code{find}
21252
427c3a89
DJ
21253@item @code{supported-packets}
21254@tab @code{qSupported}
21255@tab Remote communications parameters
21256
82075af2
JS
21257@item @code{catch-syscalls}
21258@tab @code{QCatchSyscalls}
21259@tab @code{catch syscall}
21260
cfa9d6d9 21261@item @code{pass-signals}
89be2091
DJ
21262@tab @code{QPassSignals}
21263@tab @code{handle @var{signal}}
21264
9b224c5e
PA
21265@item @code{program-signals}
21266@tab @code{QProgramSignals}
21267@tab @code{handle @var{signal}}
21268
a6b151f1
DJ
21269@item @code{hostio-close-packet}
21270@tab @code{vFile:close}
21271@tab @code{remote get}, @code{remote put}
21272
21273@item @code{hostio-open-packet}
21274@tab @code{vFile:open}
21275@tab @code{remote get}, @code{remote put}
21276
21277@item @code{hostio-pread-packet}
21278@tab @code{vFile:pread}
21279@tab @code{remote get}, @code{remote put}
21280
21281@item @code{hostio-pwrite-packet}
21282@tab @code{vFile:pwrite}
21283@tab @code{remote get}, @code{remote put}
21284
21285@item @code{hostio-unlink-packet}
21286@tab @code{vFile:unlink}
21287@tab @code{remote delete}
a6f3e723 21288
b9e7b9c3
UW
21289@item @code{hostio-readlink-packet}
21290@tab @code{vFile:readlink}
21291@tab Host I/O
21292
0a93529c
GB
21293@item @code{hostio-fstat-packet}
21294@tab @code{vFile:fstat}
21295@tab Host I/O
21296
15a201c8
GB
21297@item @code{hostio-setfs-packet}
21298@tab @code{vFile:setfs}
21299@tab Host I/O
21300
a6f3e723
SL
21301@item @code{noack-packet}
21302@tab @code{QStartNoAckMode}
21303@tab Packet acknowledgment
07e059b5
VP
21304
21305@item @code{osdata}
21306@tab @code{qXfer:osdata:read}
21307@tab @code{info os}
0b16c5cf
PA
21308
21309@item @code{query-attached}
21310@tab @code{qAttached}
21311@tab Querying remote process attach state.
b3b9301e 21312
a46c1e42
PA
21313@item @code{trace-buffer-size}
21314@tab @code{QTBuffer:size}
21315@tab @code{set trace-buffer-size}
21316
bd3eecc3
PA
21317@item @code{trace-status}
21318@tab @code{qTStatus}
21319@tab @code{tstatus}
21320
b3b9301e
PA
21321@item @code{traceframe-info}
21322@tab @code{qXfer:traceframe-info:read}
21323@tab Traceframe info
03583c20 21324
1e4d1764
YQ
21325@item @code{install-in-trace}
21326@tab @code{InstallInTrace}
21327@tab Install tracepoint in tracing
21328
03583c20
UW
21329@item @code{disable-randomization}
21330@tab @code{QDisableRandomization}
21331@tab @code{set disable-randomization}
83364271 21332
aefd8b33
SDJ
21333@item @code{startup-with-shell}
21334@tab @code{QStartupWithShell}
21335@tab @code{set startup-with-shell}
21336
0a2dde4a
SDJ
21337@item @code{environment-hex-encoded}
21338@tab @code{QEnvironmentHexEncoded}
21339@tab @code{set environment}
21340
21341@item @code{environment-unset}
21342@tab @code{QEnvironmentUnset}
21343@tab @code{unset environment}
21344
21345@item @code{environment-reset}
21346@tab @code{QEnvironmentReset}
21347@tab @code{Reset the inferior environment (i.e., unset user-set variables)}
21348
bc3b087d
SDJ
21349@item @code{set-working-dir}
21350@tab @code{QSetWorkingDir}
21351@tab @code{set cwd}
21352
83364271
LM
21353@item @code{conditional-breakpoints-packet}
21354@tab @code{Z0 and Z1}
21355@tab @code{Support for target-side breakpoint condition evaluation}
f7e6eed5 21356
73b8c1fd
PA
21357@item @code{multiprocess-extensions}
21358@tab @code{multiprocess extensions}
21359@tab Debug multiple processes and remote process PID awareness
21360
f7e6eed5
PA
21361@item @code{swbreak-feature}
21362@tab @code{swbreak stop reason}
21363@tab @code{break}
21364
21365@item @code{hwbreak-feature}
21366@tab @code{hwbreak stop reason}
21367@tab @code{hbreak}
21368
0d71eef5
DB
21369@item @code{fork-event-feature}
21370@tab @code{fork stop reason}
21371@tab @code{fork}
21372
21373@item @code{vfork-event-feature}
21374@tab @code{vfork stop reason}
21375@tab @code{vfork}
21376
b459a59b
DB
21377@item @code{exec-event-feature}
21378@tab @code{exec stop reason}
21379@tab @code{exec}
21380
65706a29
PA
21381@item @code{thread-events}
21382@tab @code{QThreadEvents}
21383@tab Tracking thread lifetime.
21384
f2faf941
PA
21385@item @code{no-resumed-stop-reply}
21386@tab @code{no resumed thread left stop reply}
21387@tab Tracking thread lifetime.
21388
427c3a89
DJ
21389@end multitable
21390
79a6e687
BW
21391@node Remote Stub
21392@section Implementing a Remote Stub
7a292a7a 21393
8e04817f
AC
21394@cindex debugging stub, example
21395@cindex remote stub, example
21396@cindex stub example, remote debugging
21397The stub files provided with @value{GDBN} implement the target side of the
21398communication protocol, and the @value{GDBN} side is implemented in the
21399@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
21400these subroutines to communicate, and ignore the details. (If you're
21401implementing your own stub file, you can still ignore the details: start
21402with one of the existing stub files. @file{sparc-stub.c} is the best
21403organized, and therefore the easiest to read.)
21404
104c1213
JM
21405@cindex remote serial debugging, overview
21406To debug a program running on another machine (the debugging
21407@dfn{target} machine), you must first arrange for all the usual
21408prerequisites for the program to run by itself. For example, for a C
21409program, you need:
c906108c 21410
104c1213
JM
21411@enumerate
21412@item
21413A startup routine to set up the C runtime environment; these usually
21414have a name like @file{crt0}. The startup routine may be supplied by
21415your hardware supplier, or you may have to write your own.
96baa820 21416
5d161b24 21417@item
d4f3574e 21418A C subroutine library to support your program's
104c1213 21419subroutine calls, notably managing input and output.
96baa820 21420
104c1213
JM
21421@item
21422A way of getting your program to the other machine---for example, a
21423download program. These are often supplied by the hardware
21424manufacturer, but you may have to write your own from hardware
21425documentation.
21426@end enumerate
96baa820 21427
104c1213
JM
21428The next step is to arrange for your program to use a serial port to
21429communicate with the machine where @value{GDBN} is running (the @dfn{host}
21430machine). In general terms, the scheme looks like this:
96baa820 21431
104c1213
JM
21432@table @emph
21433@item On the host,
21434@value{GDBN} already understands how to use this protocol; when everything
21435else is set up, you can simply use the @samp{target remote} command
21436(@pxref{Targets,,Specifying a Debugging Target}).
21437
21438@item On the target,
21439you must link with your program a few special-purpose subroutines that
21440implement the @value{GDBN} remote serial protocol. The file containing these
21441subroutines is called a @dfn{debugging stub}.
21442
21443On certain remote targets, you can use an auxiliary program
21444@code{gdbserver} instead of linking a stub into your program.
79a6e687 21445@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 21446@end table
96baa820 21447
104c1213
JM
21448The debugging stub is specific to the architecture of the remote
21449machine; for example, use @file{sparc-stub.c} to debug programs on
21450@sc{sparc} boards.
96baa820 21451
104c1213
JM
21452@cindex remote serial stub list
21453These working remote stubs are distributed with @value{GDBN}:
96baa820 21454
104c1213
JM
21455@table @code
21456
21457@item i386-stub.c
41afff9a 21458@cindex @file{i386-stub.c}
104c1213
JM
21459@cindex Intel
21460@cindex i386
21461For Intel 386 and compatible architectures.
21462
21463@item m68k-stub.c
41afff9a 21464@cindex @file{m68k-stub.c}
104c1213
JM
21465@cindex Motorola 680x0
21466@cindex m680x0
21467For Motorola 680x0 architectures.
21468
21469@item sh-stub.c
41afff9a 21470@cindex @file{sh-stub.c}
172c2a43 21471@cindex Renesas
104c1213 21472@cindex SH
172c2a43 21473For Renesas SH architectures.
104c1213
JM
21474
21475@item sparc-stub.c
41afff9a 21476@cindex @file{sparc-stub.c}
104c1213
JM
21477@cindex Sparc
21478For @sc{sparc} architectures.
21479
21480@item sparcl-stub.c
41afff9a 21481@cindex @file{sparcl-stub.c}
104c1213
JM
21482@cindex Fujitsu
21483@cindex SparcLite
21484For Fujitsu @sc{sparclite} architectures.
21485
21486@end table
21487
21488The @file{README} file in the @value{GDBN} distribution may list other
21489recently added stubs.
21490
21491@menu
21492* Stub Contents:: What the stub can do for you
21493* Bootstrapping:: What you must do for the stub
21494* Debug Session:: Putting it all together
104c1213
JM
21495@end menu
21496
6d2ebf8b 21497@node Stub Contents
79a6e687 21498@subsection What the Stub Can Do for You
104c1213
JM
21499
21500@cindex remote serial stub
21501The debugging stub for your architecture supplies these three
21502subroutines:
21503
21504@table @code
21505@item set_debug_traps
4644b6e3 21506@findex set_debug_traps
104c1213
JM
21507@cindex remote serial stub, initialization
21508This routine arranges for @code{handle_exception} to run when your
2fb860fc
PA
21509program stops. You must call this subroutine explicitly in your
21510program's startup code.
104c1213
JM
21511
21512@item handle_exception
4644b6e3 21513@findex handle_exception
104c1213
JM
21514@cindex remote serial stub, main routine
21515This is the central workhorse, but your program never calls it
21516explicitly---the setup code arranges for @code{handle_exception} to
21517run when a trap is triggered.
21518
21519@code{handle_exception} takes control when your program stops during
21520execution (for example, on a breakpoint), and mediates communications
21521with @value{GDBN} on the host machine. This is where the communications
21522protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 21523representative on the target machine. It begins by sending summary
104c1213
JM
21524information on the state of your program, then continues to execute,
21525retrieving and transmitting any information @value{GDBN} needs, until you
21526execute a @value{GDBN} command that makes your program resume; at that point,
21527@code{handle_exception} returns control to your own code on the target
5d161b24 21528machine.
104c1213
JM
21529
21530@item breakpoint
21531@cindex @code{breakpoint} subroutine, remote
21532Use this auxiliary subroutine to make your program contain a
21533breakpoint. Depending on the particular situation, this may be the only
21534way for @value{GDBN} to get control. For instance, if your target
21535machine has some sort of interrupt button, you won't need to call this;
21536pressing the interrupt button transfers control to
21537@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
21538simply receiving characters on the serial port may also trigger a trap;
21539again, in that situation, you don't need to call @code{breakpoint} from
21540your own program---simply running @samp{target remote} from the host
5d161b24 21541@value{GDBN} session gets control.
104c1213
JM
21542
21543Call @code{breakpoint} if none of these is true, or if you simply want
21544to make certain your program stops at a predetermined point for the
21545start of your debugging session.
21546@end table
21547
6d2ebf8b 21548@node Bootstrapping
79a6e687 21549@subsection What You Must Do for the Stub
104c1213
JM
21550
21551@cindex remote stub, support routines
21552The debugging stubs that come with @value{GDBN} are set up for a particular
21553chip architecture, but they have no information about the rest of your
21554debugging target machine.
21555
21556First of all you need to tell the stub how to communicate with the
21557serial port.
21558
21559@table @code
21560@item int getDebugChar()
4644b6e3 21561@findex getDebugChar
104c1213
JM
21562Write this subroutine to read a single character from the serial port.
21563It may be identical to @code{getchar} for your target system; a
21564different name is used to allow you to distinguish the two if you wish.
21565
21566@item void putDebugChar(int)
4644b6e3 21567@findex putDebugChar
104c1213 21568Write this subroutine to write a single character to the serial port.
5d161b24 21569It may be identical to @code{putchar} for your target system; a
104c1213
JM
21570different name is used to allow you to distinguish the two if you wish.
21571@end table
21572
21573@cindex control C, and remote debugging
21574@cindex interrupting remote targets
21575If you want @value{GDBN} to be able to stop your program while it is
21576running, you need to use an interrupt-driven serial driver, and arrange
21577for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
21578character). That is the character which @value{GDBN} uses to tell the
21579remote system to stop.
21580
21581Getting the debugging target to return the proper status to @value{GDBN}
21582probably requires changes to the standard stub; one quick and dirty way
21583is to just execute a breakpoint instruction (the ``dirty'' part is that
21584@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
21585
21586Other routines you need to supply are:
21587
21588@table @code
21589@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 21590@findex exceptionHandler
104c1213
JM
21591Write this function to install @var{exception_address} in the exception
21592handling tables. You need to do this because the stub does not have any
21593way of knowing what the exception handling tables on your target system
21594are like (for example, the processor's table might be in @sc{rom},
21595containing entries which point to a table in @sc{ram}).
697aa1b7 21596The @var{exception_number} specifies the exception which should be changed;
104c1213
JM
21597its meaning is architecture-dependent (for example, different numbers
21598might represent divide by zero, misaligned access, etc). When this
21599exception occurs, control should be transferred directly to
21600@var{exception_address}, and the processor state (stack, registers,
21601and so on) should be just as it is when a processor exception occurs. So if
21602you want to use a jump instruction to reach @var{exception_address}, it
21603should be a simple jump, not a jump to subroutine.
21604
21605For the 386, @var{exception_address} should be installed as an interrupt
21606gate so that interrupts are masked while the handler runs. The gate
21607should be at privilege level 0 (the most privileged level). The
21608@sc{sparc} and 68k stubs are able to mask interrupts themselves without
21609help from @code{exceptionHandler}.
21610
21611@item void flush_i_cache()
4644b6e3 21612@findex flush_i_cache
d4f3574e 21613On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
21614instruction cache, if any, on your target machine. If there is no
21615instruction cache, this subroutine may be a no-op.
21616
21617On target machines that have instruction caches, @value{GDBN} requires this
21618function to make certain that the state of your program is stable.
21619@end table
21620
21621@noindent
21622You must also make sure this library routine is available:
21623
21624@table @code
21625@item void *memset(void *, int, int)
4644b6e3 21626@findex memset
104c1213
JM
21627This is the standard library function @code{memset} that sets an area of
21628memory to a known value. If you have one of the free versions of
21629@code{libc.a}, @code{memset} can be found there; otherwise, you must
21630either obtain it from your hardware manufacturer, or write your own.
21631@end table
21632
21633If you do not use the GNU C compiler, you may need other standard
21634library subroutines as well; this varies from one stub to another,
21635but in general the stubs are likely to use any of the common library
e22ea452 21636subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
21637
21638
6d2ebf8b 21639@node Debug Session
79a6e687 21640@subsection Putting it All Together
104c1213
JM
21641
21642@cindex remote serial debugging summary
21643In summary, when your program is ready to debug, you must follow these
21644steps.
21645
21646@enumerate
21647@item
6d2ebf8b 21648Make sure you have defined the supporting low-level routines
79a6e687 21649(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
21650@display
21651@code{getDebugChar}, @code{putDebugChar},
21652@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
21653@end display
21654
21655@item
2fb860fc
PA
21656Insert these lines in your program's startup code, before the main
21657procedure is called:
104c1213 21658
474c8240 21659@smallexample
104c1213
JM
21660set_debug_traps();
21661breakpoint();
474c8240 21662@end smallexample
104c1213 21663
2fb860fc
PA
21664On some machines, when a breakpoint trap is raised, the hardware
21665automatically makes the PC point to the instruction after the
21666breakpoint. If your machine doesn't do that, you may need to adjust
21667@code{handle_exception} to arrange for it to return to the instruction
21668after the breakpoint on this first invocation, so that your program
21669doesn't keep hitting the initial breakpoint instead of making
21670progress.
21671
104c1213
JM
21672@item
21673For the 680x0 stub only, you need to provide a variable called
21674@code{exceptionHook}. Normally you just use:
21675
474c8240 21676@smallexample
104c1213 21677void (*exceptionHook)() = 0;
474c8240 21678@end smallexample
104c1213 21679
d4f3574e 21680@noindent
104c1213 21681but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 21682function in your program, that function is called when
104c1213
JM
21683@code{@value{GDBN}} continues after stopping on a trap (for example, bus
21684error). The function indicated by @code{exceptionHook} is called with
21685one parameter: an @code{int} which is the exception number.
21686
21687@item
21688Compile and link together: your program, the @value{GDBN} debugging stub for
21689your target architecture, and the supporting subroutines.
21690
21691@item
21692Make sure you have a serial connection between your target machine and
21693the @value{GDBN} host, and identify the serial port on the host.
21694
21695@item
21696@c The "remote" target now provides a `load' command, so we should
21697@c document that. FIXME.
21698Download your program to your target machine (or get it there by
21699whatever means the manufacturer provides), and start it.
21700
21701@item
07f31aa6 21702Start @value{GDBN} on the host, and connect to the target
79a6e687 21703(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 21704
104c1213
JM
21705@end enumerate
21706
8e04817f
AC
21707@node Configurations
21708@chapter Configuration-Specific Information
104c1213 21709
8e04817f
AC
21710While nearly all @value{GDBN} commands are available for all native and
21711cross versions of the debugger, there are some exceptions. This chapter
21712describes things that are only available in certain configurations.
104c1213 21713
8e04817f
AC
21714There are three major categories of configurations: native
21715configurations, where the host and target are the same, embedded
21716operating system configurations, which are usually the same for several
21717different processor architectures, and bare embedded processors, which
21718are quite different from each other.
104c1213 21719
8e04817f
AC
21720@menu
21721* Native::
21722* Embedded OS::
21723* Embedded Processors::
21724* Architectures::
21725@end menu
104c1213 21726
8e04817f
AC
21727@node Native
21728@section Native
104c1213 21729
8e04817f
AC
21730This section describes details specific to particular native
21731configurations.
6cf7e474 21732
8e04817f 21733@menu
7561d450 21734* BSD libkvm Interface:: Debugging BSD kernel memory images
2d97a5d9 21735* Process Information:: Process information
8e04817f 21736* DJGPP Native:: Features specific to the DJGPP port
78c47bea 21737* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 21738* Hurd Native:: Features specific to @sc{gnu} Hurd
a80b95ba 21739* Darwin:: Features specific to Darwin
8e04817f 21740@end menu
6cf7e474 21741
7561d450
MK
21742@node BSD libkvm Interface
21743@subsection BSD libkvm Interface
21744
21745@cindex libkvm
21746@cindex kernel memory image
21747@cindex kernel crash dump
21748
21749BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
21750interface that provides a uniform interface for accessing kernel virtual
21751memory images, including live systems and crash dumps. @value{GDBN}
21752uses this interface to allow you to debug live kernels and kernel crash
21753dumps on many native BSD configurations. This is implemented as a
21754special @code{kvm} debugging target. For debugging a live system, load
21755the currently running kernel into @value{GDBN} and connect to the
21756@code{kvm} target:
21757
21758@smallexample
21759(@value{GDBP}) @b{target kvm}
21760@end smallexample
21761
21762For debugging crash dumps, provide the file name of the crash dump as an
21763argument:
21764
21765@smallexample
21766(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
21767@end smallexample
21768
21769Once connected to the @code{kvm} target, the following commands are
21770available:
21771
21772@table @code
21773@kindex kvm
21774@item kvm pcb
721c2651 21775Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
21776
21777@item kvm proc
21778Set current context from proc address. This command isn't available on
21779modern FreeBSD systems.
21780@end table
21781
2d97a5d9
JB
21782@node Process Information
21783@subsection Process Information
60bf7e09
EZ
21784@cindex /proc
21785@cindex examine process image
21786@cindex process info via @file{/proc}
104c1213 21787
2d97a5d9
JB
21788Some operating systems provide interfaces to fetch additional
21789information about running processes beyond memory and per-thread
21790register state. If @value{GDBN} is configured for an operating system
21791with a supported interface, the command @code{info proc} is available
21792to report information about the process running your program, or about
21793any process running on your system.
451b7c33 21794
2d97a5d9
JB
21795One supported interface is a facility called @samp{/proc} that can be
21796used to examine the image of a running process using file-system
21797subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
21798systems.
451b7c33 21799
2d97a5d9
JB
21800On FreeBSD systems, system control nodes are used to query process
21801information.
21802
21803In addition, some systems may provide additional process information
21804in core files. Note that a core file may include a subset of the
21805information available from a live process. Process information is
21806currently avaiable from cores created on @sc{gnu}/Linux and FreeBSD
21807systems.
104c1213 21808
8e04817f
AC
21809@table @code
21810@kindex info proc
60bf7e09 21811@cindex process ID
8e04817f 21812@item info proc
60bf7e09
EZ
21813@itemx info proc @var{process-id}
21814Summarize available information about any running process. If a
21815process ID is specified by @var{process-id}, display information about
21816that process; otherwise display information about the program being
21817debugged. The summary includes the debugged process ID, the command
21818line used to invoke it, its current working directory, and its
21819executable file's absolute file name.
21820
21821On some systems, @var{process-id} can be of the form
21822@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
21823within a process. If the optional @var{pid} part is missing, it means
21824a thread from the process being debugged (the leading @samp{/} still
21825needs to be present, or else @value{GDBN} will interpret the number as
21826a process ID rather than a thread ID).
6cf7e474 21827
0c631110
TT
21828@item info proc cmdline
21829@cindex info proc cmdline
21830Show the original command line of the process. This command is
2d97a5d9 21831supported on @sc{gnu}/Linux and FreeBSD.
0c631110
TT
21832
21833@item info proc cwd
21834@cindex info proc cwd
21835Show the current working directory of the process. This command is
2d97a5d9 21836supported on @sc{gnu}/Linux and FreeBSD.
0c631110
TT
21837
21838@item info proc exe
21839@cindex info proc exe
2d97a5d9
JB
21840Show the name of executable of the process. This command is supported
21841on @sc{gnu}/Linux and FreeBSD.
0c631110 21842
8e04817f 21843@item info proc mappings
60bf7e09 21844@cindex memory address space mappings
2d97a5d9
JB
21845Report the memory address space ranges accessible in the program. On
21846Solaris and FreeBSD systems, each memory range includes information on
21847whether the process has read, write, or execute access rights to each
21848range. On @sc{gnu}/Linux and FreeBSD systems, each memory range
21849includes the object file which is mapped to that range.
60bf7e09
EZ
21850
21851@item info proc stat
21852@itemx info proc status
21853@cindex process detailed status information
2d97a5d9
JB
21854Show additional process-related information, including the user ID and
21855group ID; virtual memory usage; the signals that are pending, blocked,
21856and ignored; its TTY; its consumption of system and user time; its
21857stack size; its @samp{nice} value; etc. These commands are supported
21858on @sc{gnu}/Linux and FreeBSD.
21859
21860For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
21861information (type @kbd{man 5 proc} from your shell prompt).
21862
21863For FreeBSD systems, @code{info proc stat} is an alias for @code{info
21864proc status}.
60bf7e09
EZ
21865
21866@item info proc all
21867Show all the information about the process described under all of the
21868above @code{info proc} subcommands.
21869
8e04817f
AC
21870@ignore
21871@comment These sub-options of 'info proc' were not included when
21872@comment procfs.c was re-written. Keep their descriptions around
21873@comment against the day when someone finds the time to put them back in.
21874@kindex info proc times
21875@item info proc times
21876Starting time, user CPU time, and system CPU time for your program and
21877its children.
6cf7e474 21878
8e04817f
AC
21879@kindex info proc id
21880@item info proc id
21881Report on the process IDs related to your program: its own process ID,
21882the ID of its parent, the process group ID, and the session ID.
8e04817f 21883@end ignore
721c2651
EZ
21884
21885@item set procfs-trace
21886@kindex set procfs-trace
21887@cindex @code{procfs} API calls
21888This command enables and disables tracing of @code{procfs} API calls.
21889
21890@item show procfs-trace
21891@kindex show procfs-trace
21892Show the current state of @code{procfs} API call tracing.
21893
21894@item set procfs-file @var{file}
21895@kindex set procfs-file
21896Tell @value{GDBN} to write @code{procfs} API trace to the named
21897@var{file}. @value{GDBN} appends the trace info to the previous
21898contents of the file. The default is to display the trace on the
21899standard output.
21900
21901@item show procfs-file
21902@kindex show procfs-file
21903Show the file to which @code{procfs} API trace is written.
21904
21905@item proc-trace-entry
21906@itemx proc-trace-exit
21907@itemx proc-untrace-entry
21908@itemx proc-untrace-exit
21909@kindex proc-trace-entry
21910@kindex proc-trace-exit
21911@kindex proc-untrace-entry
21912@kindex proc-untrace-exit
21913These commands enable and disable tracing of entries into and exits
21914from the @code{syscall} interface.
21915
21916@item info pidlist
21917@kindex info pidlist
21918@cindex process list, QNX Neutrino
21919For QNX Neutrino only, this command displays the list of all the
21920processes and all the threads within each process.
21921
21922@item info meminfo
21923@kindex info meminfo
21924@cindex mapinfo list, QNX Neutrino
21925For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 21926@end table
104c1213 21927
8e04817f
AC
21928@node DJGPP Native
21929@subsection Features for Debugging @sc{djgpp} Programs
21930@cindex @sc{djgpp} debugging
21931@cindex native @sc{djgpp} debugging
21932@cindex MS-DOS-specific commands
104c1213 21933
514c4d71
EZ
21934@cindex DPMI
21935@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
21936MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
21937that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
21938top of real-mode DOS systems and their emulations.
104c1213 21939
8e04817f
AC
21940@value{GDBN} supports native debugging of @sc{djgpp} programs, and
21941defines a few commands specific to the @sc{djgpp} port. This
21942subsection describes those commands.
104c1213 21943
8e04817f
AC
21944@table @code
21945@kindex info dos
21946@item info dos
21947This is a prefix of @sc{djgpp}-specific commands which print
21948information about the target system and important OS structures.
f1251bdd 21949
8e04817f
AC
21950@kindex sysinfo
21951@cindex MS-DOS system info
21952@cindex free memory information (MS-DOS)
21953@item info dos sysinfo
21954This command displays assorted information about the underlying
21955platform: the CPU type and features, the OS version and flavor, the
21956DPMI version, and the available conventional and DPMI memory.
104c1213 21957
8e04817f
AC
21958@cindex GDT
21959@cindex LDT
21960@cindex IDT
21961@cindex segment descriptor tables
21962@cindex descriptor tables display
21963@item info dos gdt
21964@itemx info dos ldt
21965@itemx info dos idt
21966These 3 commands display entries from, respectively, Global, Local,
21967and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
21968tables are data structures which store a descriptor for each segment
21969that is currently in use. The segment's selector is an index into a
21970descriptor table; the table entry for that index holds the
21971descriptor's base address and limit, and its attributes and access
21972rights.
104c1213 21973
8e04817f
AC
21974A typical @sc{djgpp} program uses 3 segments: a code segment, a data
21975segment (used for both data and the stack), and a DOS segment (which
21976allows access to DOS/BIOS data structures and absolute addresses in
21977conventional memory). However, the DPMI host will usually define
21978additional segments in order to support the DPMI environment.
d4f3574e 21979
8e04817f
AC
21980@cindex garbled pointers
21981These commands allow to display entries from the descriptor tables.
21982Without an argument, all entries from the specified table are
21983displayed. An argument, which should be an integer expression, means
21984display a single entry whose index is given by the argument. For
21985example, here's a convenient way to display information about the
21986debugged program's data segment:
104c1213 21987
8e04817f
AC
21988@smallexample
21989@exdent @code{(@value{GDBP}) info dos ldt $ds}
21990@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
21991@end smallexample
104c1213 21992
8e04817f
AC
21993@noindent
21994This comes in handy when you want to see whether a pointer is outside
21995the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 21996
8e04817f
AC
21997@cindex page tables display (MS-DOS)
21998@item info dos pde
21999@itemx info dos pte
22000These two commands display entries from, respectively, the Page
22001Directory and the Page Tables. Page Directories and Page Tables are
22002data structures which control how virtual memory addresses are mapped
22003into physical addresses. A Page Table includes an entry for every
22004page of memory that is mapped into the program's address space; there
22005may be several Page Tables, each one holding up to 4096 entries. A
22006Page Directory has up to 4096 entries, one each for every Page Table
22007that is currently in use.
104c1213 22008
8e04817f
AC
22009Without an argument, @kbd{info dos pde} displays the entire Page
22010Directory, and @kbd{info dos pte} displays all the entries in all of
22011the Page Tables. An argument, an integer expression, given to the
22012@kbd{info dos pde} command means display only that entry from the Page
22013Directory table. An argument given to the @kbd{info dos pte} command
22014means display entries from a single Page Table, the one pointed to by
22015the specified entry in the Page Directory.
104c1213 22016
8e04817f
AC
22017@cindex direct memory access (DMA) on MS-DOS
22018These commands are useful when your program uses @dfn{DMA} (Direct
22019Memory Access), which needs physical addresses to program the DMA
22020controller.
104c1213 22021
8e04817f 22022These commands are supported only with some DPMI servers.
104c1213 22023
8e04817f
AC
22024@cindex physical address from linear address
22025@item info dos address-pte @var{addr}
22026This command displays the Page Table entry for a specified linear
514c4d71
EZ
22027address. The argument @var{addr} is a linear address which should
22028already have the appropriate segment's base address added to it,
22029because this command accepts addresses which may belong to @emph{any}
22030segment. For example, here's how to display the Page Table entry for
22031the page where a variable @code{i} is stored:
104c1213 22032
b383017d 22033@smallexample
8e04817f
AC
22034@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
22035@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 22036@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 22037@end smallexample
104c1213 22038
8e04817f
AC
22039@noindent
22040This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 22041whose physical base address is @code{0x02698000}, and shows all the
8e04817f 22042attributes of that page.
104c1213 22043
8e04817f
AC
22044Note that you must cast the addresses of variables to a @code{char *},
22045since otherwise the value of @code{__djgpp_base_address}, the base
22046address of all variables and functions in a @sc{djgpp} program, will
22047be added using the rules of C pointer arithmetics: if @code{i} is
22048declared an @code{int}, @value{GDBN} will add 4 times the value of
22049@code{__djgpp_base_address} to the address of @code{i}.
104c1213 22050
8e04817f
AC
22051Here's another example, it displays the Page Table entry for the
22052transfer buffer:
104c1213 22053
8e04817f
AC
22054@smallexample
22055@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
22056@exdent @code{Page Table entry for address 0x29110:}
22057@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
22058@end smallexample
104c1213 22059
8e04817f
AC
22060@noindent
22061(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
220623rd member of the @code{_go32_info_block} structure.) The output
22063clearly shows that this DPMI server maps the addresses in conventional
22064memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
22065linear (@code{0x29110}) addresses are identical.
104c1213 22066
8e04817f
AC
22067This command is supported only with some DPMI servers.
22068@end table
104c1213 22069
c45da7e6 22070@cindex DOS serial data link, remote debugging
a8f24a35
EZ
22071In addition to native debugging, the DJGPP port supports remote
22072debugging via a serial data link. The following commands are specific
22073to remote serial debugging in the DJGPP port of @value{GDBN}.
22074
22075@table @code
22076@kindex set com1base
22077@kindex set com1irq
22078@kindex set com2base
22079@kindex set com2irq
22080@kindex set com3base
22081@kindex set com3irq
22082@kindex set com4base
22083@kindex set com4irq
22084@item set com1base @var{addr}
22085This command sets the base I/O port address of the @file{COM1} serial
22086port.
22087
22088@item set com1irq @var{irq}
22089This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
22090for the @file{COM1} serial port.
22091
22092There are similar commands @samp{set com2base}, @samp{set com3irq},
22093etc.@: for setting the port address and the @code{IRQ} lines for the
22094other 3 COM ports.
22095
22096@kindex show com1base
22097@kindex show com1irq
22098@kindex show com2base
22099@kindex show com2irq
22100@kindex show com3base
22101@kindex show com3irq
22102@kindex show com4base
22103@kindex show com4irq
22104The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
22105display the current settings of the base address and the @code{IRQ}
22106lines used by the COM ports.
c45da7e6
EZ
22107
22108@item info serial
22109@kindex info serial
22110@cindex DOS serial port status
22111This command prints the status of the 4 DOS serial ports. For each
22112port, it prints whether it's active or not, its I/O base address and
22113IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
22114counts of various errors encountered so far.
a8f24a35
EZ
22115@end table
22116
22117
78c47bea 22118@node Cygwin Native
79a6e687 22119@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
22120@cindex MS Windows debugging
22121@cindex native Cygwin debugging
22122@cindex Cygwin-specific commands
22123
be448670 22124@value{GDBN} supports native debugging of MS Windows programs, including
cbb8f428
EZ
22125DLLs with and without symbolic debugging information.
22126
22127@cindex Ctrl-BREAK, MS-Windows
22128@cindex interrupt debuggee on MS-Windows
22129MS-Windows programs that call @code{SetConsoleMode} to switch off the
22130special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
22131by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
22132supports @kbd{C-@key{BREAK}} as an alternative interrupt key
22133sequence, which can be used to interrupt the debuggee even if it
22134ignores @kbd{C-c}.
22135
22136There are various additional Cygwin-specific commands, described in
22137this section. Working with DLLs that have no debugging symbols is
22138described in @ref{Non-debug DLL Symbols}.
78c47bea
PM
22139
22140@table @code
22141@kindex info w32
22142@item info w32
db2e3e2e 22143This is a prefix of MS Windows-specific commands which print
78c47bea
PM
22144information about the target system and important OS structures.
22145
22146@item info w32 selector
22147This command displays information returned by
22148the Win32 API @code{GetThreadSelectorEntry} function.
22149It takes an optional argument that is evaluated to
22150a long value to give the information about this given selector.
22151Without argument, this command displays information
d3e8051b 22152about the six segment registers.
78c47bea 22153
711e434b
PM
22154@item info w32 thread-information-block
22155This command displays thread specific information stored in the
22156Thread Information Block (readable on the X86 CPU family using @code{$fs}
22157selector for 32-bit programs and @code{$gs} for 64-bit programs).
22158
463888ab
РИ
22159@kindex signal-event
22160@item signal-event @var{id}
22161This command signals an event with user-provided @var{id}. Used to resume
22162crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
22163
22164To use it, create or edit the following keys in
22165@code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
22166@code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
22167(for x86_64 versions):
22168
22169@itemize @minus
22170@item
22171@code{Debugger} (REG_SZ) --- a command to launch the debugger.
22172Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
22173"attach %ld" -ex "signal-event %ld" -ex "continue"}.
22174
22175The first @code{%ld} will be replaced by the process ID of the
22176crashing process, the second @code{%ld} will be replaced by the ID of
22177the event that blocks the crashing process, waiting for @value{GDBN}
22178to attach.
22179
22180@item
22181@code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
22182make the system run debugger specified by the Debugger key
22183automatically, @code{0} will cause a dialog box with ``OK'' and
22184``Cancel'' buttons to appear, which allows the user to either
22185terminate the crashing process (OK) or debug it (Cancel).
22186@end itemize
22187
be90c084 22188@kindex set cygwin-exceptions
e16b02ee
EZ
22189@cindex debugging the Cygwin DLL
22190@cindex Cygwin DLL, debugging
be90c084 22191@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
22192If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
22193happen inside the Cygwin DLL. If @var{mode} is @code{off},
22194@value{GDBN} will delay recognition of exceptions, and may ignore some
22195exceptions which seem to be caused by internal Cygwin DLL
22196``bookkeeping''. This option is meant primarily for debugging the
22197Cygwin DLL itself; the default value is @code{off} to avoid annoying
22198@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
22199
22200@kindex show cygwin-exceptions
22201@item show cygwin-exceptions
e16b02ee
EZ
22202Displays whether @value{GDBN} will break on exceptions that happen
22203inside the Cygwin DLL itself.
be90c084 22204
b383017d 22205@kindex set new-console
78c47bea 22206@item set new-console @var{mode}
b383017d 22207If @var{mode} is @code{on} the debuggee will
78c47bea 22208be started in a new console on next start.
e03e5e7b 22209If @var{mode} is @code{off}, the debuggee will
78c47bea
PM
22210be started in the same console as the debugger.
22211
22212@kindex show new-console
22213@item show new-console
22214Displays whether a new console is used
22215when the debuggee is started.
22216
22217@kindex set new-group
22218@item set new-group @var{mode}
22219This boolean value controls whether the debuggee should
22220start a new group or stay in the same group as the debugger.
22221This affects the way the Windows OS handles
c8aa23ab 22222@samp{Ctrl-C}.
78c47bea
PM
22223
22224@kindex show new-group
22225@item show new-group
22226Displays current value of new-group boolean.
22227
22228@kindex set debugevents
22229@item set debugevents
219eec71
EZ
22230This boolean value adds debug output concerning kernel events related
22231to the debuggee seen by the debugger. This includes events that
22232signal thread and process creation and exit, DLL loading and
22233unloading, console interrupts, and debugging messages produced by the
22234Windows @code{OutputDebugString} API call.
78c47bea
PM
22235
22236@kindex set debugexec
22237@item set debugexec
b383017d 22238This boolean value adds debug output concerning execute events
219eec71 22239(such as resume thread) seen by the debugger.
78c47bea
PM
22240
22241@kindex set debugexceptions
22242@item set debugexceptions
219eec71
EZ
22243This boolean value adds debug output concerning exceptions in the
22244debuggee seen by the debugger.
78c47bea
PM
22245
22246@kindex set debugmemory
22247@item set debugmemory
219eec71
EZ
22248This boolean value adds debug output concerning debuggee memory reads
22249and writes by the debugger.
78c47bea
PM
22250
22251@kindex set shell
22252@item set shell
22253This boolean values specifies whether the debuggee is called
22254via a shell or directly (default value is on).
22255
22256@kindex show shell
22257@item show shell
22258Displays if the debuggee will be started with a shell.
22259
22260@end table
22261
be448670 22262@menu
79a6e687 22263* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
22264@end menu
22265
79a6e687
BW
22266@node Non-debug DLL Symbols
22267@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
22268@cindex DLLs with no debugging symbols
22269@cindex Minimal symbols and DLLs
22270
22271Very often on windows, some of the DLLs that your program relies on do
22272not include symbolic debugging information (for example,
db2e3e2e 22273@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 22274symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 22275information contained in the DLL's export table. This section
be448670
CF
22276describes working with such symbols, known internally to @value{GDBN} as
22277``minimal symbols''.
22278
22279Note that before the debugged program has started execution, no DLLs
db2e3e2e 22280will have been loaded. The easiest way around this problem is simply to
be448670 22281start the program --- either by setting a breakpoint or letting the
95060284 22282program run once to completion.
be448670 22283
79a6e687 22284@subsubsection DLL Name Prefixes
be448670
CF
22285
22286In keeping with the naming conventions used by the Microsoft debugging
22287tools, DLL export symbols are made available with a prefix based on the
22288DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
22289also entered into the symbol table, so @code{CreateFileA} is often
99e008fe 22290sufficient. In some cases there will be name clashes within a program
be448670
CF
22291(particularly if the executable itself includes full debugging symbols)
22292necessitating the use of the fully qualified name when referring to the
99e008fe 22293contents of the DLL. Use single-quotes around the name to avoid the
be448670
CF
22294exclamation mark (``!'') being interpreted as a language operator.
22295
22296Note that the internal name of the DLL may be all upper-case, even
99e008fe 22297though the file name of the DLL is lower-case, or vice-versa. Since
be448670
CF
22298symbols within @value{GDBN} are @emph{case-sensitive} this may cause
22299some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
22300@code{info variables} commands or even @code{maint print msymbols}
22301(@pxref{Symbols}). Here's an example:
be448670
CF
22302
22303@smallexample
f7dc1244 22304(@value{GDBP}) info function CreateFileA
be448670
CF
22305All functions matching regular expression "CreateFileA":
22306
22307Non-debugging symbols:
223080x77e885f4 CreateFileA
223090x77e885f4 KERNEL32!CreateFileA
22310@end smallexample
22311
22312@smallexample
f7dc1244 22313(@value{GDBP}) info function !
be448670
CF
22314All functions matching regular expression "!":
22315
22316Non-debugging symbols:
223170x6100114c cygwin1!__assert
223180x61004034 cygwin1!_dll_crt0@@0
223190x61004240 cygwin1!dll_crt0(per_process *)
22320[etc...]
22321@end smallexample
22322
79a6e687 22323@subsubsection Working with Minimal Symbols
be448670
CF
22324
22325Symbols extracted from a DLL's export table do not contain very much
22326type information. All that @value{GDBN} can do is guess whether a symbol
22327refers to a function or variable depending on the linker section that
22328contains the symbol. Also note that the actual contents of the memory
22329contained in a DLL are not available unless the program is running. This
22330means that you cannot examine the contents of a variable or disassemble
22331a function within a DLL without a running program.
22332
22333Variables are generally treated as pointers and dereferenced
22334automatically. For this reason, it is often necessary to prefix a
22335variable name with the address-of operator (``&'') and provide explicit
22336type information in the command. Here's an example of the type of
22337problem:
22338
22339@smallexample
f7dc1244 22340(@value{GDBP}) print 'cygwin1!__argv'
d69cf9b2 22341'cygwin1!__argv' has unknown type; cast it to its declared type
be448670
CF
22342@end smallexample
22343
22344@smallexample
f7dc1244 22345(@value{GDBP}) x 'cygwin1!__argv'
d69cf9b2 22346'cygwin1!__argv' has unknown type; cast it to its declared type
be448670
CF
22347@end smallexample
22348
22349And two possible solutions:
22350
22351@smallexample
f7dc1244 22352(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
22353$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
22354@end smallexample
22355
22356@smallexample
f7dc1244 22357(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 223580x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 22359(@value{GDBP}) x/x 0x10021608
be448670 223600x10021608: 0x0022fd98
f7dc1244 22361(@value{GDBP}) x/s 0x0022fd98
be448670
CF
223620x22fd98: "/cygdrive/c/mydirectory/myprogram"
22363@end smallexample
22364
22365Setting a break point within a DLL is possible even before the program
22366starts execution. However, under these circumstances, @value{GDBN} can't
22367examine the initial instructions of the function in order to skip the
22368function's frame set-up code. You can work around this by using ``*&''
22369to set the breakpoint at a raw memory address:
22370
22371@smallexample
f7dc1244 22372(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
22373Breakpoint 1 at 0x1e04eff0
22374@end smallexample
22375
22376The author of these extensions is not entirely convinced that setting a
22377break point within a shared DLL like @file{kernel32.dll} is completely
22378safe.
22379
14d6dd68 22380@node Hurd Native
79a6e687 22381@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
22382@cindex @sc{gnu} Hurd debugging
22383
22384This subsection describes @value{GDBN} commands specific to the
22385@sc{gnu} Hurd native debugging.
22386
22387@table @code
22388@item set signals
22389@itemx set sigs
22390@kindex set signals@r{, Hurd command}
22391@kindex set sigs@r{, Hurd command}
22392This command toggles the state of inferior signal interception by
22393@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
22394affected by this command. @code{sigs} is a shorthand alias for
22395@code{signals}.
22396
22397@item show signals
22398@itemx show sigs
22399@kindex show signals@r{, Hurd command}
22400@kindex show sigs@r{, Hurd command}
22401Show the current state of intercepting inferior's signals.
22402
22403@item set signal-thread
22404@itemx set sigthread
22405@kindex set signal-thread
22406@kindex set sigthread
22407This command tells @value{GDBN} which thread is the @code{libc} signal
22408thread. That thread is run when a signal is delivered to a running
22409process. @code{set sigthread} is the shorthand alias of @code{set
22410signal-thread}.
22411
22412@item show signal-thread
22413@itemx show sigthread
22414@kindex show signal-thread
22415@kindex show sigthread
22416These two commands show which thread will run when the inferior is
22417delivered a signal.
22418
22419@item set stopped
22420@kindex set stopped@r{, Hurd command}
22421This commands tells @value{GDBN} that the inferior process is stopped,
22422as with the @code{SIGSTOP} signal. The stopped process can be
22423continued by delivering a signal to it.
22424
22425@item show stopped
22426@kindex show stopped@r{, Hurd command}
22427This command shows whether @value{GDBN} thinks the debuggee is
22428stopped.
22429
22430@item set exceptions
22431@kindex set exceptions@r{, Hurd command}
22432Use this command to turn off trapping of exceptions in the inferior.
22433When exception trapping is off, neither breakpoints nor
22434single-stepping will work. To restore the default, set exception
22435trapping on.
22436
22437@item show exceptions
22438@kindex show exceptions@r{, Hurd command}
22439Show the current state of trapping exceptions in the inferior.
22440
22441@item set task pause
22442@kindex set task@r{, Hurd commands}
22443@cindex task attributes (@sc{gnu} Hurd)
22444@cindex pause current task (@sc{gnu} Hurd)
22445This command toggles task suspension when @value{GDBN} has control.
22446Setting it to on takes effect immediately, and the task is suspended
22447whenever @value{GDBN} gets control. Setting it to off will take
22448effect the next time the inferior is continued. If this option is set
22449to off, you can use @code{set thread default pause on} or @code{set
22450thread pause on} (see below) to pause individual threads.
22451
22452@item show task pause
22453@kindex show task@r{, Hurd commands}
22454Show the current state of task suspension.
22455
22456@item set task detach-suspend-count
22457@cindex task suspend count
22458@cindex detach from task, @sc{gnu} Hurd
22459This command sets the suspend count the task will be left with when
22460@value{GDBN} detaches from it.
22461
22462@item show task detach-suspend-count
22463Show the suspend count the task will be left with when detaching.
22464
22465@item set task exception-port
22466@itemx set task excp
22467@cindex task exception port, @sc{gnu} Hurd
22468This command sets the task exception port to which @value{GDBN} will
22469forward exceptions. The argument should be the value of the @dfn{send
22470rights} of the task. @code{set task excp} is a shorthand alias.
22471
22472@item set noninvasive
22473@cindex noninvasive task options
22474This command switches @value{GDBN} to a mode that is the least
22475invasive as far as interfering with the inferior is concerned. This
22476is the same as using @code{set task pause}, @code{set exceptions}, and
22477@code{set signals} to values opposite to the defaults.
22478
22479@item info send-rights
22480@itemx info receive-rights
22481@itemx info port-rights
22482@itemx info port-sets
22483@itemx info dead-names
22484@itemx info ports
22485@itemx info psets
22486@cindex send rights, @sc{gnu} Hurd
22487@cindex receive rights, @sc{gnu} Hurd
22488@cindex port rights, @sc{gnu} Hurd
22489@cindex port sets, @sc{gnu} Hurd
22490@cindex dead names, @sc{gnu} Hurd
22491These commands display information about, respectively, send rights,
22492receive rights, port rights, port sets, and dead names of a task.
22493There are also shorthand aliases: @code{info ports} for @code{info
22494port-rights} and @code{info psets} for @code{info port-sets}.
22495
22496@item set thread pause
22497@kindex set thread@r{, Hurd command}
22498@cindex thread properties, @sc{gnu} Hurd
22499@cindex pause current thread (@sc{gnu} Hurd)
22500This command toggles current thread suspension when @value{GDBN} has
22501control. Setting it to on takes effect immediately, and the current
22502thread is suspended whenever @value{GDBN} gets control. Setting it to
22503off will take effect the next time the inferior is continued.
22504Normally, this command has no effect, since when @value{GDBN} has
22505control, the whole task is suspended. However, if you used @code{set
22506task pause off} (see above), this command comes in handy to suspend
22507only the current thread.
22508
22509@item show thread pause
22510@kindex show thread@r{, Hurd command}
22511This command shows the state of current thread suspension.
22512
22513@item set thread run
d3e8051b 22514This command sets whether the current thread is allowed to run.
14d6dd68
EZ
22515
22516@item show thread run
22517Show whether the current thread is allowed to run.
22518
22519@item set thread detach-suspend-count
22520@cindex thread suspend count, @sc{gnu} Hurd
22521@cindex detach from thread, @sc{gnu} Hurd
22522This command sets the suspend count @value{GDBN} will leave on a
22523thread when detaching. This number is relative to the suspend count
22524found by @value{GDBN} when it notices the thread; use @code{set thread
22525takeover-suspend-count} to force it to an absolute value.
22526
22527@item show thread detach-suspend-count
22528Show the suspend count @value{GDBN} will leave on the thread when
22529detaching.
22530
22531@item set thread exception-port
22532@itemx set thread excp
22533Set the thread exception port to which to forward exceptions. This
22534overrides the port set by @code{set task exception-port} (see above).
22535@code{set thread excp} is the shorthand alias.
22536
22537@item set thread takeover-suspend-count
22538Normally, @value{GDBN}'s thread suspend counts are relative to the
22539value @value{GDBN} finds when it notices each thread. This command
22540changes the suspend counts to be absolute instead.
22541
22542@item set thread default
22543@itemx show thread default
22544@cindex thread default settings, @sc{gnu} Hurd
22545Each of the above @code{set thread} commands has a @code{set thread
22546default} counterpart (e.g., @code{set thread default pause}, @code{set
22547thread default exception-port}, etc.). The @code{thread default}
22548variety of commands sets the default thread properties for all
22549threads; you can then change the properties of individual threads with
22550the non-default commands.
22551@end table
22552
a80b95ba
TG
22553@node Darwin
22554@subsection Darwin
22555@cindex Darwin
22556
22557@value{GDBN} provides the following commands specific to the Darwin target:
22558
22559@table @code
22560@item set debug darwin @var{num}
22561@kindex set debug darwin
22562When set to a non zero value, enables debugging messages specific to
22563the Darwin support. Higher values produce more verbose output.
22564
22565@item show debug darwin
22566@kindex show debug darwin
22567Show the current state of Darwin messages.
22568
22569@item set debug mach-o @var{num}
22570@kindex set debug mach-o
22571When set to a non zero value, enables debugging messages while
22572@value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
22573file format used on Darwin for object and executable files.) Higher
22574values produce more verbose output. This is a command to diagnose
22575problems internal to @value{GDBN} and should not be needed in normal
22576usage.
22577
22578@item show debug mach-o
22579@kindex show debug mach-o
22580Show the current state of Mach-O file messages.
22581
22582@item set mach-exceptions on
22583@itemx set mach-exceptions off
22584@kindex set mach-exceptions
22585On Darwin, faults are first reported as a Mach exception and are then
22586mapped to a Posix signal. Use this command to turn on trapping of
22587Mach exceptions in the inferior. This might be sometimes useful to
22588better understand the cause of a fault. The default is off.
22589
22590@item show mach-exceptions
22591@kindex show mach-exceptions
22592Show the current state of exceptions trapping.
22593@end table
22594
a64548ea 22595
8e04817f
AC
22596@node Embedded OS
22597@section Embedded Operating Systems
104c1213 22598
8e04817f
AC
22599This section describes configurations involving the debugging of
22600embedded operating systems that are available for several different
22601architectures.
d4f3574e 22602
8e04817f
AC
22603@value{GDBN} includes the ability to debug programs running on
22604various real-time operating systems.
104c1213 22605
6d2ebf8b 22606@node Embedded Processors
104c1213
JM
22607@section Embedded Processors
22608
22609This section goes into details specific to particular embedded
22610configurations.
22611
c45da7e6
EZ
22612@cindex send command to simulator
22613Whenever a specific embedded processor has a simulator, @value{GDBN}
22614allows to send an arbitrary command to the simulator.
22615
22616@table @code
22617@item sim @var{command}
22618@kindex sim@r{, a command}
22619Send an arbitrary @var{command} string to the simulator. Consult the
22620documentation for the specific simulator in use for information about
22621acceptable commands.
22622@end table
22623
7d86b5d5 22624
104c1213 22625@menu
ad0a504f 22626* ARC:: Synopsys ARC
bb615428 22627* ARM:: ARM
104c1213 22628* M68K:: Motorola M68K
08be9d71 22629* MicroBlaze:: Xilinx MicroBlaze
104c1213 22630* MIPS Embedded:: MIPS Embedded
a994fec4 22631* OpenRISC 1000:: OpenRISC 1000 (or1k)
4acd40f3 22632* PowerPC Embedded:: PowerPC Embedded
a64548ea
EZ
22633* AVR:: Atmel AVR
22634* CRIS:: CRIS
22635* Super-H:: Renesas Super-H
104c1213
JM
22636@end menu
22637
ad0a504f
AK
22638@node ARC
22639@subsection Synopsys ARC
22640@cindex Synopsys ARC
22641@cindex ARC specific commands
22642@cindex ARC600
22643@cindex ARC700
22644@cindex ARC EM
22645@cindex ARC HS
22646
22647@value{GDBN} provides the following ARC-specific commands:
22648
22649@table @code
22650@item set debug arc
22651@kindex set debug arc
22652Control the level of ARC specific debug messages. Use 0 for no messages (the
fe5f7374 22653default), 1 for debug messages, and 2 for even more debug messages.
ad0a504f
AK
22654
22655@item show debug arc
22656@kindex show debug arc
22657Show the level of ARC specific debugging in operation.
22658
eea78757
AK
22659@item maint print arc arc-instruction @var{address}
22660@kindex maint print arc arc-instruction
22661Print internal disassembler information about instruction at a given address.
22662
ad0a504f
AK
22663@end table
22664
6d2ebf8b 22665@node ARM
104c1213 22666@subsection ARM
8e04817f 22667
e2f4edfd
EZ
22668@value{GDBN} provides the following ARM-specific commands:
22669
22670@table @code
22671@item set arm disassembler
22672@kindex set arm
22673This commands selects from a list of disassembly styles. The
22674@code{"std"} style is the standard style.
22675
22676@item show arm disassembler
22677@kindex show arm
22678Show the current disassembly style.
22679
22680@item set arm apcs32
22681@cindex ARM 32-bit mode
22682This command toggles ARM operation mode between 32-bit and 26-bit.
22683
22684@item show arm apcs32
22685Display the current usage of the ARM 32-bit mode.
22686
22687@item set arm fpu @var{fputype}
22688This command sets the ARM floating-point unit (FPU) type. The
22689argument @var{fputype} can be one of these:
22690
22691@table @code
22692@item auto
22693Determine the FPU type by querying the OS ABI.
22694@item softfpa
22695Software FPU, with mixed-endian doubles on little-endian ARM
22696processors.
22697@item fpa
22698GCC-compiled FPA co-processor.
22699@item softvfp
22700Software FPU with pure-endian doubles.
22701@item vfp
22702VFP co-processor.
22703@end table
22704
22705@item show arm fpu
22706Show the current type of the FPU.
22707
22708@item set arm abi
22709This command forces @value{GDBN} to use the specified ABI.
22710
22711@item show arm abi
22712Show the currently used ABI.
22713
0428b8f5
DJ
22714@item set arm fallback-mode (arm|thumb|auto)
22715@value{GDBN} uses the symbol table, when available, to determine
22716whether instructions are ARM or Thumb. This command controls
22717@value{GDBN}'s default behavior when the symbol table is not
22718available. The default is @samp{auto}, which causes @value{GDBN} to
22719use the current execution mode (from the @code{T} bit in the @code{CPSR}
22720register).
22721
22722@item show arm fallback-mode
22723Show the current fallback instruction mode.
22724
22725@item set arm force-mode (arm|thumb|auto)
22726This command overrides use of the symbol table to determine whether
22727instructions are ARM or Thumb. The default is @samp{auto}, which
22728causes @value{GDBN} to use the symbol table and then the setting
22729of @samp{set arm fallback-mode}.
22730
22731@item show arm force-mode
22732Show the current forced instruction mode.
22733
e2f4edfd
EZ
22734@item set debug arm
22735Toggle whether to display ARM-specific debugging messages from the ARM
22736target support subsystem.
22737
22738@item show debug arm
22739Show whether ARM-specific debugging messages are enabled.
22740@end table
22741
ee8e71d4
EZ
22742@table @code
22743@item target sim @r{[}@var{simargs}@r{]} @dots{}
22744The @value{GDBN} ARM simulator accepts the following optional arguments.
22745
22746@table @code
22747@item --swi-support=@var{type}
697aa1b7 22748Tell the simulator which SWI interfaces to support. The argument
ee8e71d4
EZ
22749@var{type} may be a comma separated list of the following values.
22750The default value is @code{all}.
22751
22752@table @code
22753@item none
22754@item demon
22755@item angel
22756@item redboot
22757@item all
22758@end table
22759@end table
22760@end table
e2f4edfd 22761
8e04817f
AC
22762@node M68K
22763@subsection M68k
22764
bb615428 22765The Motorola m68k configuration includes ColdFire support.
8e04817f 22766
08be9d71
ME
22767@node MicroBlaze
22768@subsection MicroBlaze
22769@cindex Xilinx MicroBlaze
22770@cindex XMD, Xilinx Microprocessor Debugger
22771
22772The MicroBlaze is a soft-core processor supported on various Xilinx
22773FPGAs, such as Spartan or Virtex series. Boards with these processors
22774usually have JTAG ports which connect to a host system running the Xilinx
22775Embedded Development Kit (EDK) or Software Development Kit (SDK).
22776This host system is used to download the configuration bitstream to
22777the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
22778communicates with the target board using the JTAG interface and
22779presents a @code{gdbserver} interface to the board. By default
22780@code{xmd} uses port @code{1234}. (While it is possible to change
22781this default port, it requires the use of undocumented @code{xmd}
22782commands. Contact Xilinx support if you need to do this.)
22783
22784Use these GDB commands to connect to the MicroBlaze target processor.
22785
22786@table @code
22787@item target remote :1234
22788Use this command to connect to the target if you are running @value{GDBN}
22789on the same system as @code{xmd}.
22790
22791@item target remote @var{xmd-host}:1234
22792Use this command to connect to the target if it is connected to @code{xmd}
22793running on a different system named @var{xmd-host}.
22794
22795@item load
22796Use this command to download a program to the MicroBlaze target.
22797
22798@item set debug microblaze @var{n}
22799Enable MicroBlaze-specific debugging messages if non-zero.
22800
22801@item show debug microblaze @var{n}
22802Show MicroBlaze-specific debugging level.
22803@end table
22804
8e04817f 22805@node MIPS Embedded
eb17f351 22806@subsection @acronym{MIPS} Embedded
8e04817f 22807
8e04817f 22808@noindent
f7c38292 22809@value{GDBN} supports these special commands for @acronym{MIPS} targets:
104c1213 22810
8e04817f 22811@table @code
8e04817f
AC
22812@item set mipsfpu double
22813@itemx set mipsfpu single
22814@itemx set mipsfpu none
a64548ea 22815@itemx set mipsfpu auto
8e04817f
AC
22816@itemx show mipsfpu
22817@kindex set mipsfpu
22818@kindex show mipsfpu
eb17f351
EZ
22819@cindex @acronym{MIPS} remote floating point
22820@cindex floating point, @acronym{MIPS} remote
22821If your target board does not support the @acronym{MIPS} floating point
8e04817f
AC
22822coprocessor, you should use the command @samp{set mipsfpu none} (if you
22823need this, you may wish to put the command in your @value{GDBN} init
22824file). This tells @value{GDBN} how to find the return value of
22825functions which return floating point values. It also allows
22826@value{GDBN} to avoid saving the floating point registers when calling
22827functions on the board. If you are using a floating point coprocessor
22828with only single precision floating point support, as on the @sc{r4650}
22829processor, use the command @samp{set mipsfpu single}. The default
22830double precision floating point coprocessor may be selected using
22831@samp{set mipsfpu double}.
104c1213 22832
8e04817f
AC
22833In previous versions the only choices were double precision or no
22834floating point, so @samp{set mipsfpu on} will select double precision
22835and @samp{set mipsfpu off} will select no floating point.
104c1213 22836
8e04817f
AC
22837As usual, you can inquire about the @code{mipsfpu} variable with
22838@samp{show mipsfpu}.
8e04817f 22839@end table
104c1213 22840
a994fec4
FJ
22841@node OpenRISC 1000
22842@subsection OpenRISC 1000
22843@cindex OpenRISC 1000
22844
22845@noindent
22846The OpenRISC 1000 provides a free RISC instruction set architecture. It is
22847mainly provided as a soft-core which can run on Xilinx, Altera and other
22848FPGA's.
22849
22850@value{GDBN} for OpenRISC supports the below commands when connecting to
22851a target:
22852
22853@table @code
22854
22855@kindex target sim
22856@item target sim
22857
22858Runs the builtin CPU simulator which can run very basic
22859programs but does not support most hardware functions like MMU.
22860For more complex use cases the user is advised to run an external
22861target, and connect using @samp{target remote}.
22862
22863Example: @code{target sim}
22864
22865@item set debug or1k
22866Toggle whether to display OpenRISC-specific debugging messages from the
22867OpenRISC target support subsystem.
22868
22869@item show debug or1k
22870Show whether OpenRISC-specific debugging messages are enabled.
22871@end table
22872
4acd40f3
TJB
22873@node PowerPC Embedded
22874@subsection PowerPC Embedded
104c1213 22875
66b73624
TJB
22876@cindex DVC register
22877@value{GDBN} supports using the DVC (Data Value Compare) register to
22878implement in hardware simple hardware watchpoint conditions of the form:
22879
22880@smallexample
22881(@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
22882 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
22883@end smallexample
22884
e09342b5
TJB
22885The DVC register will be automatically used when @value{GDBN} detects
22886such pattern in a condition expression, and the created watchpoint uses one
22887debug register (either the @code{exact-watchpoints} option is on and the
22888variable is scalar, or the variable has a length of one byte). This feature
22889is available in native @value{GDBN} running on a Linux kernel version 2.6.34
22890or newer.
22891
22892When running on PowerPC embedded processors, @value{GDBN} automatically uses
22893ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
22894in which case watchpoints using only one debug register are created when
22895watching variables of scalar types.
22896
22897You can create an artificial array to watch an arbitrary memory
22898region using one of the following commands (@pxref{Expressions}):
22899
22900@smallexample
22901(@value{GDBP}) watch *((char *) @var{address})@@@var{length}
22902(@value{GDBP}) watch @{char[@var{length}]@} @var{address}
22903@end smallexample
66b73624 22904
9c06b0b4
TJB
22905PowerPC embedded processors support masked watchpoints. See the discussion
22906about the @code{mask} argument in @ref{Set Watchpoints}.
22907
f1310107
TJB
22908@cindex ranged breakpoint
22909PowerPC embedded processors support hardware accelerated
22910@dfn{ranged breakpoints}. A ranged breakpoint stops execution of
22911the inferior whenever it executes an instruction at any address within
22912the range it specifies. To set a ranged breakpoint in @value{GDBN},
22913use the @code{break-range} command.
22914
55eddb0f
DJ
22915@value{GDBN} provides the following PowerPC-specific commands:
22916
104c1213 22917@table @code
f1310107
TJB
22918@kindex break-range
22919@item break-range @var{start-location}, @var{end-location}
697aa1b7
EZ
22920Set a breakpoint for an address range given by
22921@var{start-location} and @var{end-location}, which can specify a function name,
f1310107
TJB
22922a line number, an offset of lines from the current line or from the start
22923location, or an address of an instruction (see @ref{Specify Location},
22924for a list of all the possible ways to specify a @var{location}.)
22925The breakpoint will stop execution of the inferior whenever it
22926executes an instruction at any address within the specified range,
22927(including @var{start-location} and @var{end-location}.)
22928
55eddb0f
DJ
22929@kindex set powerpc
22930@item set powerpc soft-float
22931@itemx show powerpc soft-float
22932Force @value{GDBN} to use (or not use) a software floating point calling
22933convention. By default, @value{GDBN} selects the calling convention based
22934on the selected architecture and the provided executable file.
22935
22936@item set powerpc vector-abi
22937@itemx show powerpc vector-abi
22938Force @value{GDBN} to use the specified calling convention for vector
22939arguments and return values. The valid options are @samp{auto};
22940@samp{generic}, to avoid vector registers even if they are present;
22941@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
22942registers. By default, @value{GDBN} selects the calling convention
22943based on the selected architecture and the provided executable file.
22944
e09342b5
TJB
22945@item set powerpc exact-watchpoints
22946@itemx show powerpc exact-watchpoints
22947Allow @value{GDBN} to use only one debug register when watching a variable
22948of scalar type, thus assuming that the variable is accessed through the
22949address of its first byte.
22950
104c1213
JM
22951@end table
22952
a64548ea
EZ
22953@node AVR
22954@subsection Atmel AVR
22955@cindex AVR
22956
22957When configured for debugging the Atmel AVR, @value{GDBN} supports the
22958following AVR-specific commands:
22959
22960@table @code
22961@item info io_registers
22962@kindex info io_registers@r{, AVR}
22963@cindex I/O registers (Atmel AVR)
22964This command displays information about the AVR I/O registers. For
22965each register, @value{GDBN} prints its number and value.
22966@end table
22967
22968@node CRIS
22969@subsection CRIS
22970@cindex CRIS
22971
22972When configured for debugging CRIS, @value{GDBN} provides the
22973following CRIS-specific commands:
22974
22975@table @code
22976@item set cris-version @var{ver}
22977@cindex CRIS version
e22e55c9
OF
22978Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
22979The CRIS version affects register names and sizes. This command is useful in
22980case autodetection of the CRIS version fails.
a64548ea
EZ
22981
22982@item show cris-version
22983Show the current CRIS version.
22984
22985@item set cris-dwarf2-cfi
22986@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
22987Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
22988Change to @samp{off} when using @code{gcc-cris} whose version is below
22989@code{R59}.
a64548ea
EZ
22990
22991@item show cris-dwarf2-cfi
22992Show the current state of using DWARF-2 CFI.
e22e55c9
OF
22993
22994@item set cris-mode @var{mode}
22995@cindex CRIS mode
22996Set the current CRIS mode to @var{mode}. It should only be changed when
22997debugging in guru mode, in which case it should be set to
22998@samp{guru} (the default is @samp{normal}).
22999
23000@item show cris-mode
23001Show the current CRIS mode.
a64548ea
EZ
23002@end table
23003
23004@node Super-H
23005@subsection Renesas Super-H
23006@cindex Super-H
23007
23008For the Renesas Super-H processor, @value{GDBN} provides these
23009commands:
23010
23011@table @code
c055b101
CV
23012@item set sh calling-convention @var{convention}
23013@kindex set sh calling-convention
23014Set the calling-convention used when calling functions from @value{GDBN}.
23015Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
23016With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
23017convention. If the DWARF-2 information of the called function specifies
23018that the function follows the Renesas calling convention, the function
23019is called using the Renesas calling convention. If the calling convention
23020is set to @samp{renesas}, the Renesas calling convention is always used,
23021regardless of the DWARF-2 information. This can be used to override the
23022default of @samp{gcc} if debug information is missing, or the compiler
23023does not emit the DWARF-2 calling convention entry for a function.
23024
23025@item show sh calling-convention
23026@kindex show sh calling-convention
23027Show the current calling convention setting.
23028
a64548ea
EZ
23029@end table
23030
23031
8e04817f
AC
23032@node Architectures
23033@section Architectures
104c1213 23034
8e04817f
AC
23035This section describes characteristics of architectures that affect
23036all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 23037
8e04817f 23038@menu
430ed3f0 23039* AArch64::
9c16f35a 23040* i386::
8e04817f
AC
23041* Alpha::
23042* MIPS::
a64548ea 23043* HPPA:: HP PA architecture
23d964e7 23044* SPU:: Cell Broadband Engine SPU architecture
4acd40f3 23045* PowerPC::
a1217d97 23046* Nios II::
58afddc6 23047* Sparc64::
8e04817f 23048@end menu
104c1213 23049
430ed3f0
MS
23050@node AArch64
23051@subsection AArch64
23052@cindex AArch64 support
23053
23054When @value{GDBN} is debugging the AArch64 architecture, it provides the
23055following special commands:
23056
23057@table @code
23058@item set debug aarch64
23059@kindex set debug aarch64
23060This command determines whether AArch64 architecture-specific debugging
23061messages are to be displayed.
23062
23063@item show debug aarch64
23064Show whether AArch64 debugging messages are displayed.
23065
23066@end table
23067
9c16f35a 23068@node i386
db2e3e2e 23069@subsection x86 Architecture-specific Issues
9c16f35a
EZ
23070
23071@table @code
23072@item set struct-convention @var{mode}
23073@kindex set struct-convention
23074@cindex struct return convention
23075@cindex struct/union returned in registers
23076Set the convention used by the inferior to return @code{struct}s and
23077@code{union}s from functions to @var{mode}. Possible values of
23078@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
23079default). @code{"default"} or @code{"pcc"} means that @code{struct}s
23080are returned on the stack, while @code{"reg"} means that a
23081@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
23082be returned in a register.
23083
23084@item show struct-convention
23085@kindex show struct-convention
23086Show the current setting of the convention to return @code{struct}s
23087from functions.
966f0aef 23088@end table
29c1c244 23089
ca8941bb 23090
bc504a31
PA
23091@subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
23092@cindex Intel Memory Protection Extensions (MPX).
ca8941bb 23093
ca8941bb
WT
23094Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
23095@footnote{The register named with capital letters represent the architecture
23096registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
23097which are the lower bound and upper bound. Bounds are effective addresses or
23098memory locations. The upper bounds are architecturally represented in 1's
23099complement form. A bound having lower bound = 0, and upper bound = 0
23100(1's complement of all bits set) will allow access to the entire address space.
23101
23102@samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
23103through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
23104display the upper bound performing the complement of one operation on the
23105upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
23106@value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
23107can also be noted that the upper bounds are inclusive.
23108
23109As an example, assume that the register BND0 holds bounds for a pointer having
23110access allowed for the range between 0x32 and 0x71. The values present on
23111bnd0raw and bnd registers are presented as follows:
23112
23113@smallexample
23114 bnd0raw = @{0x32, 0xffffffff8e@}
23115 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
23116@end smallexample
23117
22f25c9d
EZ
23118This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
23119change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
23120counterpart. When the bnd0@dots{}bnd3 registers are displayed via
23121Python, the display includes the memory size, in bits, accessible to
23122the pointer.
9c16f35a 23123
29c1c244
WT
23124Bounds can also be stored in bounds tables, which are stored in
23125application memory. These tables store bounds for pointers by specifying
23126the bounds pointer's value along with its bounds. Evaluating and changing
23127bounds located in bound tables is therefore interesting while investigating
23128bugs on MPX context. @value{GDBN} provides commands for this purpose:
23129
966f0aef 23130@table @code
29c1c244
WT
23131@item show mpx bound @var{pointer}
23132@kindex show mpx bound
23133Display bounds of the given @var{pointer}.
23134
23135@item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
23136@kindex set mpx bound
23137Set the bounds of a pointer in the bound table.
23138This command takes three parameters: @var{pointer} is the pointers
23139whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
23140for lower and upper bounds respectively.
23141@end table
23142
4a612d6f
WT
23143When you call an inferior function on an Intel MPX enabled program,
23144GDB sets the inferior's bound registers to the init (disabled) state
23145before calling the function. As a consequence, bounds checks for the
23146pointer arguments passed to the function will always pass.
23147
23148This is necessary because when you call an inferior function, the
23149program is usually in the middle of the execution of other function.
23150Since at that point bound registers are in an arbitrary state, not
23151clearing them would lead to random bound violations in the called
23152function.
23153
23154You can still examine the influence of the bound registers on the
23155execution of the called function by stopping the execution of the
23156called function at its prologue, setting bound registers, and
23157continuing the execution. For example:
23158
23159@smallexample
23160 $ break *upper
23161 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
23162 $ print upper (a, b, c, d, 1)
23163 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
23164 $ print $bnd0
5cf70512 23165 @{lbound = 0x0, ubound = ffffffff@} : size -1
4a612d6f
WT
23166@end smallexample
23167
23168At this last step the value of bnd0 can be changed for investigation of bound
23169violations caused along the execution of the call. In order to know how to
23170set the bound registers or bound table for the call consult the ABI.
23171
8e04817f
AC
23172@node Alpha
23173@subsection Alpha
104c1213 23174
8e04817f 23175See the following section.
104c1213 23176
8e04817f 23177@node MIPS
eb17f351 23178@subsection @acronym{MIPS}
104c1213 23179
8e04817f 23180@cindex stack on Alpha
eb17f351 23181@cindex stack on @acronym{MIPS}
8e04817f 23182@cindex Alpha stack
eb17f351
EZ
23183@cindex @acronym{MIPS} stack
23184Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
8e04817f
AC
23185sometimes requires @value{GDBN} to search backward in the object code to
23186find the beginning of a function.
104c1213 23187
eb17f351 23188@cindex response time, @acronym{MIPS} debugging
8e04817f
AC
23189To improve response time (especially for embedded applications, where
23190@value{GDBN} may be restricted to a slow serial line for this search)
23191you may want to limit the size of this search, using one of these
23192commands:
104c1213 23193
8e04817f 23194@table @code
eb17f351 23195@cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
8e04817f
AC
23196@item set heuristic-fence-post @var{limit}
23197Restrict @value{GDBN} to examining at most @var{limit} bytes in its
23198search for the beginning of a function. A value of @var{0} (the
23199default) means there is no limit. However, except for @var{0}, the
23200larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
23201and therefore the longer it takes to run. You should only need to use
23202this command when debugging a stripped executable.
104c1213 23203
8e04817f
AC
23204@item show heuristic-fence-post
23205Display the current limit.
23206@end table
104c1213
JM
23207
23208@noindent
8e04817f 23209These commands are available @emph{only} when @value{GDBN} is configured
eb17f351 23210for debugging programs on Alpha or @acronym{MIPS} processors.
104c1213 23211
eb17f351 23212Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
a64548ea
EZ
23213programs:
23214
23215@table @code
a64548ea
EZ
23216@item set mips abi @var{arg}
23217@kindex set mips abi
eb17f351
EZ
23218@cindex set ABI for @acronym{MIPS}
23219Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
a64548ea
EZ
23220values of @var{arg} are:
23221
23222@table @samp
23223@item auto
23224The default ABI associated with the current binary (this is the
23225default).
23226@item o32
23227@item o64
23228@item n32
23229@item n64
23230@item eabi32
23231@item eabi64
a64548ea
EZ
23232@end table
23233
23234@item show mips abi
23235@kindex show mips abi
eb17f351 23236Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
a64548ea 23237
4cc0665f
MR
23238@item set mips compression @var{arg}
23239@kindex set mips compression
23240@cindex code compression, @acronym{MIPS}
23241Tell @value{GDBN} which @acronym{MIPS} compressed
23242@acronym{ISA, Instruction Set Architecture} encoding is used by the
23243inferior. @value{GDBN} uses this for code disassembly and other
23244internal interpretation purposes. This setting is only referred to
23245when no executable has been associated with the debugging session or
23246the executable does not provide information about the encoding it uses.
23247Otherwise this setting is automatically updated from information
23248provided by the executable.
23249
23250Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
23251The default compressed @acronym{ISA} encoding is @samp{mips16}, as
23252executables containing @acronym{MIPS16} code frequently are not
23253identified as such.
23254
23255This setting is ``sticky''; that is, it retains its value across
23256debugging sessions until reset either explicitly with this command or
23257implicitly from an executable.
23258
23259The compiler and/or assembler typically add symbol table annotations to
23260identify functions compiled for the @acronym{MIPS16} or
23261@acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
23262are present, @value{GDBN} uses them in preference to the global
23263compressed @acronym{ISA} encoding setting.
23264
23265@item show mips compression
23266@kindex show mips compression
23267Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
23268@value{GDBN} to debug the inferior.
23269
a64548ea
EZ
23270@item set mipsfpu
23271@itemx show mipsfpu
23272@xref{MIPS Embedded, set mipsfpu}.
23273
23274@item set mips mask-address @var{arg}
23275@kindex set mips mask-address
eb17f351 23276@cindex @acronym{MIPS} addresses, masking
a64548ea 23277This command determines whether the most-significant 32 bits of 64-bit
eb17f351 23278@acronym{MIPS} addresses are masked off. The argument @var{arg} can be
a64548ea
EZ
23279@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
23280setting, which lets @value{GDBN} determine the correct value.
23281
23282@item show mips mask-address
23283@kindex show mips mask-address
eb17f351 23284Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
a64548ea
EZ
23285not.
23286
23287@item set remote-mips64-transfers-32bit-regs
23288@kindex set remote-mips64-transfers-32bit-regs
eb17f351
EZ
23289This command controls compatibility with 64-bit @acronym{MIPS} targets that
23290transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
a64548ea
EZ
23291that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
23292and 64 bits for other registers, set this option to @samp{on}.
23293
23294@item show remote-mips64-transfers-32bit-regs
23295@kindex show remote-mips64-transfers-32bit-regs
eb17f351 23296Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
a64548ea
EZ
23297
23298@item set debug mips
23299@kindex set debug mips
eb17f351 23300This command turns on and off debugging messages for the @acronym{MIPS}-specific
a64548ea
EZ
23301target code in @value{GDBN}.
23302
23303@item show debug mips
23304@kindex show debug mips
eb17f351 23305Show the current setting of @acronym{MIPS} debugging messages.
a64548ea
EZ
23306@end table
23307
23308
23309@node HPPA
23310@subsection HPPA
23311@cindex HPPA support
23312
d3e8051b 23313When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
23314following special commands:
23315
23316@table @code
23317@item set debug hppa
23318@kindex set debug hppa
db2e3e2e 23319This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
23320messages are to be displayed.
23321
23322@item show debug hppa
23323Show whether HPPA debugging messages are displayed.
23324
23325@item maint print unwind @var{address}
23326@kindex maint print unwind@r{, HPPA}
23327This command displays the contents of the unwind table entry at the
23328given @var{address}.
23329
23330@end table
23331
104c1213 23332
23d964e7
UW
23333@node SPU
23334@subsection Cell Broadband Engine SPU architecture
23335@cindex Cell Broadband Engine
23336@cindex SPU
23337
23338When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
23339it provides the following special commands:
23340
23341@table @code
23342@item info spu event
23343@kindex info spu
23344Display SPU event facility status. Shows current event mask
23345and pending event status.
23346
23347@item info spu signal
23348Display SPU signal notification facility status. Shows pending
23349signal-control word and signal notification mode of both signal
23350notification channels.
23351
23352@item info spu mailbox
23353Display SPU mailbox facility status. Shows all pending entries,
23354in order of processing, in each of the SPU Write Outbound,
23355SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
23356
23357@item info spu dma
23358Display MFC DMA status. Shows all pending commands in the MFC
23359DMA queue. For each entry, opcode, tag, class IDs, effective
23360and local store addresses and transfer size are shown.
23361
23362@item info spu proxydma
23363Display MFC Proxy-DMA status. Shows all pending commands in the MFC
23364Proxy-DMA queue. For each entry, opcode, tag, class IDs, effective
23365and local store addresses and transfer size are shown.
23366
23367@end table
23368
3285f3fe
UW
23369When @value{GDBN} is debugging a combined PowerPC/SPU application
23370on the Cell Broadband Engine, it provides in addition the following
23371special commands:
23372
23373@table @code
23374@item set spu stop-on-load @var{arg}
23375@kindex set spu
23376Set whether to stop for new SPE threads. When set to @code{on}, @value{GDBN}
23377will give control to the user when a new SPE thread enters its @code{main}
23378function. The default is @code{off}.
23379
23380@item show spu stop-on-load
23381@kindex show spu
23382Show whether to stop for new SPE threads.
23383
ff1a52c6
UW
23384@item set spu auto-flush-cache @var{arg}
23385Set whether to automatically flush the software-managed cache. When set to
23386@code{on}, @value{GDBN} will automatically cause the SPE software-managed
23387cache to be flushed whenever SPE execution stops. This provides a consistent
23388view of PowerPC memory that is accessed via the cache. If an application
23389does not use the software-managed cache, this option has no effect.
23390
23391@item show spu auto-flush-cache
23392Show whether to automatically flush the software-managed cache.
23393
3285f3fe
UW
23394@end table
23395
4acd40f3
TJB
23396@node PowerPC
23397@subsection PowerPC
23398@cindex PowerPC architecture
23399
23400When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
23401pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
23402numbers stored in the floating point registers. These values must be stored
23403in two consecutive registers, always starting at an even register like
23404@code{f0} or @code{f2}.
23405
23406The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
23407by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
23408@code{f2} and @code{f3} for @code{$dl1} and so on.
23409
aeac0ff9 23410For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
677c5bb1
LM
23411wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
23412
a1217d97
SL
23413@node Nios II
23414@subsection Nios II
23415@cindex Nios II architecture
23416
23417When @value{GDBN} is debugging the Nios II architecture,
23418it provides the following special commands:
23419
23420@table @code
23421
23422@item set debug nios2
23423@kindex set debug nios2
23424This command turns on and off debugging messages for the Nios II
23425target code in @value{GDBN}.
23426
23427@item show debug nios2
23428@kindex show debug nios2
23429Show the current setting of Nios II debugging messages.
23430@end table
23d964e7 23431
58afddc6
WP
23432@node Sparc64
23433@subsection Sparc64
23434@cindex Sparc64 support
23435@cindex Application Data Integrity
23436@subsubsection ADI Support
23437
23438The M7 processor supports an Application Data Integrity (ADI) feature that
23439detects invalid data accesses. When software allocates memory and enables
23440ADI on the allocated memory, it chooses a 4-bit version number, sets the
23441version in the upper 4 bits of the 64-bit pointer to that data, and stores
23442the 4-bit version in every cacheline of that data. Hardware saves the latter
23443in spare bits in the cache and memory hierarchy. On each load and store,
23444the processor compares the upper 4 VA (virtual address) bits to the
23445cacheline's version. If there is a mismatch, the processor generates a
23446version mismatch trap which can be either precise or disrupting. The trap
23447is an error condition which the kernel delivers to the process as a SIGSEGV
23448signal.
23449
23450Note that only 64-bit applications can use ADI and need to be built with
23451ADI-enabled.
23452
23453Values of the ADI version tags, which are in granularity of a
23454cacheline (64 bytes), can be viewed or modified.
23455
23456
23457@table @code
23458@kindex adi examine
23459@item adi (examine | x) [ / @var{n} ] @var{addr}
23460
23461The @code{adi examine} command displays the value of one ADI version tag per
23462cacheline.
23463
23464@var{n} is a decimal integer specifying the number in bytes; the default
23465is 1. It specifies how much ADI version information, at the ratio of 1:ADI
23466block size, to display.
23467
23468@var{addr} is the address in user address space where you want @value{GDBN}
23469to begin displaying the ADI version tags.
23470
23471Below is an example of displaying ADI versions of variable "shmaddr".
23472
23473@smallexample
23474(@value{GDBP}) adi x/100 shmaddr
23475 0xfff800010002c000: 0 0
23476@end smallexample
23477
23478@kindex adi assign
23479@item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
23480
23481The @code{adi assign} command is used to assign new ADI version tag
23482to an address.
23483
23484@var{n} is a decimal integer specifying the number in bytes;
23485the default is 1. It specifies how much ADI version information, at the
23486ratio of 1:ADI block size, to modify.
23487
23488@var{addr} is the address in user address space where you want @value{GDBN}
23489to begin modifying the ADI version tags.
23490
23491@var{tag} is the new ADI version tag.
23492
23493For example, do the following to modify then verify ADI versions of
23494variable "shmaddr":
23495
23496@smallexample
23497(@value{GDBP}) adi a/100 shmaddr = 7
23498(@value{GDBP}) adi x/100 shmaddr
23499 0xfff800010002c000: 7 7
23500@end smallexample
23501
23502@end table
23503
8e04817f
AC
23504@node Controlling GDB
23505@chapter Controlling @value{GDBN}
23506
23507You can alter the way @value{GDBN} interacts with you by using the
23508@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 23509data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
23510described here.
23511
23512@menu
23513* Prompt:: Prompt
23514* Editing:: Command editing
d620b259 23515* Command History:: Command history
8e04817f
AC
23516* Screen Size:: Screen size
23517* Numbers:: Numbers
1e698235 23518* ABI:: Configuring the current ABI
bf88dd68 23519* Auto-loading:: Automatically loading associated files
8e04817f
AC
23520* Messages/Warnings:: Optional warnings and messages
23521* Debugging Output:: Optional messages about internal happenings
14fb1bac 23522* Other Misc Settings:: Other Miscellaneous Settings
8e04817f
AC
23523@end menu
23524
23525@node Prompt
23526@section Prompt
104c1213 23527
8e04817f 23528@cindex prompt
104c1213 23529
8e04817f
AC
23530@value{GDBN} indicates its readiness to read a command by printing a string
23531called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
23532can change the prompt string with the @code{set prompt} command. For
23533instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
23534the prompt in one of the @value{GDBN} sessions so that you can always tell
23535which one you are talking to.
104c1213 23536
8e04817f
AC
23537@emph{Note:} @code{set prompt} does not add a space for you after the
23538prompt you set. This allows you to set a prompt which ends in a space
23539or a prompt that does not.
104c1213 23540
8e04817f
AC
23541@table @code
23542@kindex set prompt
23543@item set prompt @var{newprompt}
23544Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 23545
8e04817f
AC
23546@kindex show prompt
23547@item show prompt
23548Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
23549@end table
23550
fa3a4f15
PM
23551Versions of @value{GDBN} that ship with Python scripting enabled have
23552prompt extensions. The commands for interacting with these extensions
23553are:
23554
23555@table @code
23556@kindex set extended-prompt
23557@item set extended-prompt @var{prompt}
23558Set an extended prompt that allows for substitutions.
23559@xref{gdb.prompt}, for a list of escape sequences that can be used for
23560substitution. Any escape sequences specified as part of the prompt
23561string are replaced with the corresponding strings each time the prompt
23562is displayed.
23563
23564For example:
23565
23566@smallexample
23567set extended-prompt Current working directory: \w (gdb)
23568@end smallexample
23569
23570Note that when an extended-prompt is set, it takes control of the
23571@var{prompt_hook} hook. @xref{prompt_hook}, for further information.
23572
23573@kindex show extended-prompt
23574@item show extended-prompt
23575Prints the extended prompt. Any escape sequences specified as part of
23576the prompt string with @code{set extended-prompt}, are replaced with the
23577corresponding strings each time the prompt is displayed.
23578@end table
23579
8e04817f 23580@node Editing
79a6e687 23581@section Command Editing
8e04817f
AC
23582@cindex readline
23583@cindex command line editing
104c1213 23584
703663ab 23585@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
23586@sc{gnu} library provides consistent behavior for programs which provide a
23587command line interface to the user. Advantages are @sc{gnu} Emacs-style
23588or @dfn{vi}-style inline editing of commands, @code{csh}-like history
23589substitution, and a storage and recall of command history across
23590debugging sessions.
104c1213 23591
8e04817f
AC
23592You may control the behavior of command line editing in @value{GDBN} with the
23593command @code{set}.
104c1213 23594
8e04817f
AC
23595@table @code
23596@kindex set editing
23597@cindex editing
23598@item set editing
23599@itemx set editing on
23600Enable command line editing (enabled by default).
104c1213 23601
8e04817f
AC
23602@item set editing off
23603Disable command line editing.
104c1213 23604
8e04817f
AC
23605@kindex show editing
23606@item show editing
23607Show whether command line editing is enabled.
104c1213
JM
23608@end table
23609
39037522
TT
23610@ifset SYSTEM_READLINE
23611@xref{Command Line Editing, , , rluserman, GNU Readline Library},
23612@end ifset
23613@ifclear SYSTEM_READLINE
23614@xref{Command Line Editing},
23615@end ifclear
23616for more details about the Readline
703663ab
EZ
23617interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
23618encouraged to read that chapter.
23619
d620b259 23620@node Command History
79a6e687 23621@section Command History
703663ab 23622@cindex command history
8e04817f
AC
23623
23624@value{GDBN} can keep track of the commands you type during your
23625debugging sessions, so that you can be certain of precisely what
23626happened. Use these commands to manage the @value{GDBN} command
23627history facility.
104c1213 23628
703663ab 23629@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
39037522
TT
23630package, to provide the history facility.
23631@ifset SYSTEM_READLINE
23632@xref{Using History Interactively, , , history, GNU History Library},
23633@end ifset
23634@ifclear SYSTEM_READLINE
23635@xref{Using History Interactively},
23636@end ifclear
23637for the detailed description of the History library.
703663ab 23638
d620b259 23639To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
23640the state which is seen by users, prefix it with @samp{server }
23641(@pxref{Server Prefix}). This
d620b259
NR
23642means that this command will not affect the command history, nor will it
23643affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
23644pressed on a line by itself.
23645
23646@cindex @code{server}, command prefix
23647The server prefix does not affect the recording of values into the value
23648history; to print a value without recording it into the value history,
23649use the @code{output} command instead of the @code{print} command.
23650
703663ab
EZ
23651Here is the description of @value{GDBN} commands related to command
23652history.
23653
104c1213 23654@table @code
8e04817f
AC
23655@cindex history substitution
23656@cindex history file
23657@kindex set history filename
4644b6e3 23658@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
23659@item set history filename @var{fname}
23660Set the name of the @value{GDBN} command history file to @var{fname}.
23661This is the file where @value{GDBN} reads an initial command history
23662list, and where it writes the command history from this session when it
23663exits. You can access this list through history expansion or through
23664the history command editing characters listed below. This file defaults
23665to the value of the environment variable @code{GDBHISTFILE}, or to
23666@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
23667is not set.
104c1213 23668
9c16f35a
EZ
23669@cindex save command history
23670@kindex set history save
8e04817f
AC
23671@item set history save
23672@itemx set history save on
23673Record command history in a file, whose name may be specified with the
23674@code{set history filename} command. By default, this option is disabled.
104c1213 23675
8e04817f
AC
23676@item set history save off
23677Stop recording command history in a file.
104c1213 23678
8e04817f 23679@cindex history size
9c16f35a 23680@kindex set history size
b58c513b 23681@cindex @env{GDBHISTSIZE}, environment variable
8e04817f 23682@item set history size @var{size}
f81d1120 23683@itemx set history size unlimited
8e04817f 23684Set the number of commands which @value{GDBN} keeps in its history list.
bc460514
PP
23685This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
23686to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
0eacb298
PP
23687are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
23688either a negative number or the empty string, then the number of commands
23689@value{GDBN} keeps in the history list is unlimited.
fc637f04
PP
23690
23691@cindex remove duplicate history
23692@kindex set history remove-duplicates
23693@item set history remove-duplicates @var{count}
23694@itemx set history remove-duplicates unlimited
23695Control the removal of duplicate history entries in the command history list.
23696If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
23697history entries and remove the first entry that is a duplicate of the current
23698entry being added to the command history list. If @var{count} is
23699@code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
23700removal of duplicate history entries is disabled.
23701
23702Only history entries added during the current session are considered for
23703removal. This option is set to 0 by default.
23704
104c1213
JM
23705@end table
23706
8e04817f 23707History expansion assigns special meaning to the character @kbd{!}.
39037522
TT
23708@ifset SYSTEM_READLINE
23709@xref{Event Designators, , , history, GNU History Library},
23710@end ifset
23711@ifclear SYSTEM_READLINE
23712@xref{Event Designators},
23713@end ifclear
23714for more details.
8e04817f 23715
703663ab 23716@cindex history expansion, turn on/off
8e04817f
AC
23717Since @kbd{!} is also the logical not operator in C, history expansion
23718is off by default. If you decide to enable history expansion with the
23719@code{set history expansion on} command, you may sometimes need to
23720follow @kbd{!} (when it is used as logical not, in an expression) with
23721a space or a tab to prevent it from being expanded. The readline
23722history facilities do not attempt substitution on the strings
23723@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
23724
23725The commands to control history expansion are:
104c1213
JM
23726
23727@table @code
8e04817f
AC
23728@item set history expansion on
23729@itemx set history expansion
703663ab 23730@kindex set history expansion
8e04817f 23731Enable history expansion. History expansion is off by default.
104c1213 23732
8e04817f
AC
23733@item set history expansion off
23734Disable history expansion.
104c1213 23735
8e04817f
AC
23736@c @group
23737@kindex show history
23738@item show history
23739@itemx show history filename
23740@itemx show history save
23741@itemx show history size
23742@itemx show history expansion
23743These commands display the state of the @value{GDBN} history parameters.
23744@code{show history} by itself displays all four states.
23745@c @end group
23746@end table
23747
23748@table @code
9c16f35a
EZ
23749@kindex show commands
23750@cindex show last commands
23751@cindex display command history
8e04817f
AC
23752@item show commands
23753Display the last ten commands in the command history.
104c1213 23754
8e04817f
AC
23755@item show commands @var{n}
23756Print ten commands centered on command number @var{n}.
23757
23758@item show commands +
23759Print ten commands just after the commands last printed.
104c1213
JM
23760@end table
23761
8e04817f 23762@node Screen Size
79a6e687 23763@section Screen Size
8e04817f 23764@cindex size of screen
f179cf97
EZ
23765@cindex screen size
23766@cindex pagination
23767@cindex page size
8e04817f 23768@cindex pauses in output
104c1213 23769
8e04817f
AC
23770Certain commands to @value{GDBN} may produce large amounts of
23771information output to the screen. To help you read all of it,
23772@value{GDBN} pauses and asks you for input at the end of each page of
23773output. Type @key{RET} when you want to continue the output, or @kbd{q}
23774to discard the remaining output. Also, the screen width setting
23775determines when to wrap lines of output. Depending on what is being
23776printed, @value{GDBN} tries to break the line at a readable place,
23777rather than simply letting it overflow onto the following line.
23778
23779Normally @value{GDBN} knows the size of the screen from the terminal
23780driver software. For example, on Unix @value{GDBN} uses the termcap data base
23781together with the value of the @code{TERM} environment variable and the
23782@code{stty rows} and @code{stty cols} settings. If this is not correct,
23783you can override it with the @code{set height} and @code{set
23784width} commands:
23785
23786@table @code
23787@kindex set height
23788@kindex set width
23789@kindex show width
23790@kindex show height
23791@item set height @var{lpp}
f81d1120 23792@itemx set height unlimited
8e04817f
AC
23793@itemx show height
23794@itemx set width @var{cpl}
f81d1120 23795@itemx set width unlimited
8e04817f
AC
23796@itemx show width
23797These @code{set} commands specify a screen height of @var{lpp} lines and
23798a screen width of @var{cpl} characters. The associated @code{show}
23799commands display the current settings.
104c1213 23800
f81d1120
PA
23801If you specify a height of either @code{unlimited} or zero lines,
23802@value{GDBN} does not pause during output no matter how long the
23803output is. This is useful if output is to a file or to an editor
23804buffer.
104c1213 23805
f81d1120
PA
23806Likewise, you can specify @samp{set width unlimited} or @samp{set
23807width 0} to prevent @value{GDBN} from wrapping its output.
9c16f35a
EZ
23808
23809@item set pagination on
23810@itemx set pagination off
23811@kindex set pagination
23812Turn the output pagination on or off; the default is on. Turning
f81d1120 23813pagination off is the alternative to @code{set height unlimited}. Note that
7c953934
TT
23814running @value{GDBN} with the @option{--batch} option (@pxref{Mode
23815Options, -batch}) also automatically disables pagination.
9c16f35a
EZ
23816
23817@item show pagination
23818@kindex show pagination
23819Show the current pagination mode.
104c1213
JM
23820@end table
23821
8e04817f
AC
23822@node Numbers
23823@section Numbers
23824@cindex number representation
23825@cindex entering numbers
104c1213 23826
8e04817f
AC
23827You can always enter numbers in octal, decimal, or hexadecimal in
23828@value{GDBN} by the usual conventions: octal numbers begin with
23829@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
23830begin with @samp{0x}. Numbers that neither begin with @samp{0} or
23831@samp{0x}, nor end with a @samp{.} are, by default, entered in base
2383210; likewise, the default display for numbers---when no particular
23833format is specified---is base 10. You can change the default base for
23834both input and output with the commands described below.
104c1213 23835
8e04817f
AC
23836@table @code
23837@kindex set input-radix
23838@item set input-radix @var{base}
23839Set the default base for numeric input. Supported choices
697aa1b7 23840for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 23841specified either unambiguously or using the current input radix; for
8e04817f 23842example, any of
104c1213 23843
8e04817f 23844@smallexample
9c16f35a
EZ
23845set input-radix 012
23846set input-radix 10.
23847set input-radix 0xa
8e04817f 23848@end smallexample
104c1213 23849
8e04817f 23850@noindent
9c16f35a 23851sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
23852leaves the input radix unchanged, no matter what it was, since
23853@samp{10}, being without any leading or trailing signs of its base, is
23854interpreted in the current radix. Thus, if the current radix is 16,
23855@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
23856change the radix.
104c1213 23857
8e04817f
AC
23858@kindex set output-radix
23859@item set output-radix @var{base}
23860Set the default base for numeric display. Supported choices
697aa1b7 23861for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 23862specified either unambiguously or using the current input radix.
104c1213 23863
8e04817f
AC
23864@kindex show input-radix
23865@item show input-radix
23866Display the current default base for numeric input.
104c1213 23867
8e04817f
AC
23868@kindex show output-radix
23869@item show output-radix
23870Display the current default base for numeric display.
9c16f35a
EZ
23871
23872@item set radix @r{[}@var{base}@r{]}
23873@itemx show radix
23874@kindex set radix
23875@kindex show radix
23876These commands set and show the default base for both input and output
23877of numbers. @code{set radix} sets the radix of input and output to
23878the same base; without an argument, it resets the radix back to its
23879default value of 10.
23880
8e04817f 23881@end table
104c1213 23882
1e698235 23883@node ABI
79a6e687 23884@section Configuring the Current ABI
1e698235
DJ
23885
23886@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
23887application automatically. However, sometimes you need to override its
23888conclusions. Use these commands to manage @value{GDBN}'s view of the
23889current ABI.
23890
98b45e30
DJ
23891@cindex OS ABI
23892@kindex set osabi
b4e9345d 23893@kindex show osabi
430ed3f0 23894@cindex Newlib OS ABI and its influence on the longjmp handling
98b45e30
DJ
23895
23896One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 23897system targets, either via remote debugging or native emulation.
98b45e30
DJ
23898@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
23899but you can override its conclusion using the @code{set osabi} command.
23900One example where this is useful is in debugging of binaries which use
23901an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
23902not have the same identifying marks that the standard C library for your
23903platform provides.
23904
430ed3f0
MS
23905When @value{GDBN} is debugging the AArch64 architecture, it provides a
23906``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
23907@code{longjmp} when debugging binaries that use the @sc{newlib} C library.
23908The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
23909
98b45e30
DJ
23910@table @code
23911@item show osabi
23912Show the OS ABI currently in use.
23913
23914@item set osabi
23915With no argument, show the list of registered available OS ABI's.
23916
23917@item set osabi @var{abi}
23918Set the current OS ABI to @var{abi}.
23919@end table
23920
1e698235 23921@cindex float promotion
1e698235
DJ
23922
23923Generally, the way that an argument of type @code{float} is passed to a
23924function depends on whether the function is prototyped. For a prototyped
23925(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
23926according to the architecture's convention for @code{float}. For unprototyped
23927(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
23928@code{double} and then passed.
23929
23930Unfortunately, some forms of debug information do not reliably indicate whether
23931a function is prototyped. If @value{GDBN} calls a function that is not marked
23932as prototyped, it consults @kbd{set coerce-float-to-double}.
23933
23934@table @code
a8f24a35 23935@kindex set coerce-float-to-double
1e698235
DJ
23936@item set coerce-float-to-double
23937@itemx set coerce-float-to-double on
23938Arguments of type @code{float} will be promoted to @code{double} when passed
23939to an unprototyped function. This is the default setting.
23940
23941@item set coerce-float-to-double off
23942Arguments of type @code{float} will be passed directly to unprototyped
23943functions.
9c16f35a
EZ
23944
23945@kindex show coerce-float-to-double
23946@item show coerce-float-to-double
23947Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
23948@end table
23949
f1212245
DJ
23950@kindex set cp-abi
23951@kindex show cp-abi
23952@value{GDBN} needs to know the ABI used for your program's C@t{++}
23953objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
23954used to build your application. @value{GDBN} only fully supports
23955programs with a single C@t{++} ABI; if your program contains code using
23956multiple C@t{++} ABI's or if @value{GDBN} can not identify your
23957program's ABI correctly, you can tell @value{GDBN} which ABI to use.
23958Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
23959before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
23960``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
23961use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
23962``auto''.
23963
23964@table @code
23965@item show cp-abi
23966Show the C@t{++} ABI currently in use.
23967
23968@item set cp-abi
23969With no argument, show the list of supported C@t{++} ABI's.
23970
23971@item set cp-abi @var{abi}
23972@itemx set cp-abi auto
23973Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
23974@end table
23975
bf88dd68
JK
23976@node Auto-loading
23977@section Automatically loading associated files
23978@cindex auto-loading
23979
23980@value{GDBN} sometimes reads files with commands and settings automatically,
23981without being explicitly told so by the user. We call this feature
23982@dfn{auto-loading}. While auto-loading is useful for automatically adapting
23983@value{GDBN} to the needs of your project, it can sometimes produce unexpected
23984results or introduce security risks (e.g., if the file comes from untrusted
23985sources).
23986
71b8c845
DE
23987@menu
23988* Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
23989* libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
23990
23991* Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
23992* Auto-loading verbose mode:: @samp{set/show debug auto-load}
23993@end menu
23994
23995There are various kinds of files @value{GDBN} can automatically load.
23996In addition to these files, @value{GDBN} supports auto-loading code written
23997in various extension languages. @xref{Auto-loading extensions}.
23998
c1668e4e
JK
23999Note that loading of these associated files (including the local @file{.gdbinit}
24000file) requires accordingly configured @code{auto-load safe-path}
24001(@pxref{Auto-loading safe path}).
24002
bf88dd68
JK
24003For these reasons, @value{GDBN} includes commands and options to let you
24004control when to auto-load files and which files should be auto-loaded.
24005
24006@table @code
24007@anchor{set auto-load off}
24008@kindex set auto-load off
24009@item set auto-load off
24010Globally disable loading of all auto-loaded files.
24011You may want to use this command with the @samp{-iex} option
24012(@pxref{Option -init-eval-command}) such as:
24013@smallexample
24014$ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
24015@end smallexample
24016
24017Be aware that system init file (@pxref{System-wide configuration})
24018and init files from your home directory (@pxref{Home Directory Init File})
24019still get read (as they come from generally trusted directories).
24020To prevent @value{GDBN} from auto-loading even those init files, use the
24021@option{-nx} option (@pxref{Mode Options}), in addition to
24022@code{set auto-load no}.
24023
24024@anchor{show auto-load}
24025@kindex show auto-load
24026@item show auto-load
24027Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
24028or disabled.
24029
24030@smallexample
24031(gdb) show auto-load
24032gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
24033libthread-db: Auto-loading of inferior specific libthread_db is on.
1ccacbcd
JK
24034local-gdbinit: Auto-loading of .gdbinit script from current directory
24035 is on.
bf88dd68 24036python-scripts: Auto-loading of Python scripts is on.
bccbefd2 24037safe-path: List of directories from which it is safe to auto-load files
1564a261 24038 is $debugdir:$datadir/auto-load.
7349ff92 24039scripts-directory: List of directories from which to load auto-loaded scripts
1564a261 24040 is $debugdir:$datadir/auto-load.
bf88dd68
JK
24041@end smallexample
24042
24043@anchor{info auto-load}
24044@kindex info auto-load
24045@item info auto-load
24046Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
24047not.
24048
24049@smallexample
24050(gdb) info auto-load
24051gdb-scripts:
24052Loaded Script
24053Yes /home/user/gdb/gdb-gdb.gdb
24054libthread-db: No auto-loaded libthread-db.
1ccacbcd
JK
24055local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
24056 loaded.
bf88dd68
JK
24057python-scripts:
24058Loaded Script
24059Yes /home/user/gdb/gdb-gdb.py
24060@end smallexample
24061@end table
24062
bf88dd68
JK
24063These are @value{GDBN} control commands for the auto-loading:
24064
24065@multitable @columnfractions .5 .5
24066@item @xref{set auto-load off}.
24067@tab Disable auto-loading globally.
24068@item @xref{show auto-load}.
24069@tab Show setting of all kinds of files.
24070@item @xref{info auto-load}.
24071@tab Show state of all kinds of files.
24072@item @xref{set auto-load gdb-scripts}.
24073@tab Control for @value{GDBN} command scripts.
24074@item @xref{show auto-load gdb-scripts}.
24075@tab Show setting of @value{GDBN} command scripts.
24076@item @xref{info auto-load gdb-scripts}.
24077@tab Show state of @value{GDBN} command scripts.
24078@item @xref{set auto-load python-scripts}.
24079@tab Control for @value{GDBN} Python scripts.
24080@item @xref{show auto-load python-scripts}.
24081@tab Show setting of @value{GDBN} Python scripts.
24082@item @xref{info auto-load python-scripts}.
24083@tab Show state of @value{GDBN} Python scripts.
ed3ef339
DE
24084@item @xref{set auto-load guile-scripts}.
24085@tab Control for @value{GDBN} Guile scripts.
24086@item @xref{show auto-load guile-scripts}.
24087@tab Show setting of @value{GDBN} Guile scripts.
24088@item @xref{info auto-load guile-scripts}.
24089@tab Show state of @value{GDBN} Guile scripts.
7349ff92
JK
24090@item @xref{set auto-load scripts-directory}.
24091@tab Control for @value{GDBN} auto-loaded scripts location.
24092@item @xref{show auto-load scripts-directory}.
24093@tab Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
24094@item @xref{add-auto-load-scripts-directory}.
24095@tab Add directory for auto-loaded scripts location list.
bf88dd68
JK
24096@item @xref{set auto-load local-gdbinit}.
24097@tab Control for init file in the current directory.
24098@item @xref{show auto-load local-gdbinit}.
24099@tab Show setting of init file in the current directory.
24100@item @xref{info auto-load local-gdbinit}.
24101@tab Show state of init file in the current directory.
24102@item @xref{set auto-load libthread-db}.
24103@tab Control for thread debugging library.
24104@item @xref{show auto-load libthread-db}.
24105@tab Show setting of thread debugging library.
24106@item @xref{info auto-load libthread-db}.
24107@tab Show state of thread debugging library.
bccbefd2
JK
24108@item @xref{set auto-load safe-path}.
24109@tab Control directories trusted for automatic loading.
24110@item @xref{show auto-load safe-path}.
24111@tab Show directories trusted for automatic loading.
24112@item @xref{add-auto-load-safe-path}.
24113@tab Add directory trusted for automatic loading.
bf88dd68
JK
24114@end multitable
24115
bf88dd68
JK
24116@node Init File in the Current Directory
24117@subsection Automatically loading init file in the current directory
24118@cindex auto-loading init file in the current directory
24119
24120By default, @value{GDBN} reads and executes the canned sequences of commands
24121from init file (if any) in the current working directory,
24122see @ref{Init File in the Current Directory during Startup}.
24123
c1668e4e
JK
24124Note that loading of this local @file{.gdbinit} file also requires accordingly
24125configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
24126
bf88dd68
JK
24127@table @code
24128@anchor{set auto-load local-gdbinit}
24129@kindex set auto-load local-gdbinit
24130@item set auto-load local-gdbinit [on|off]
24131Enable or disable the auto-loading of canned sequences of commands
24132(@pxref{Sequences}) found in init file in the current directory.
24133
24134@anchor{show auto-load local-gdbinit}
24135@kindex show auto-load local-gdbinit
24136@item show auto-load local-gdbinit
24137Show whether auto-loading of canned sequences of commands from init file in the
24138current directory is enabled or disabled.
24139
24140@anchor{info auto-load local-gdbinit}
24141@kindex info auto-load local-gdbinit
24142@item info auto-load local-gdbinit
24143Print whether canned sequences of commands from init file in the
24144current directory have been auto-loaded.
24145@end table
24146
24147@node libthread_db.so.1 file
24148@subsection Automatically loading thread debugging library
24149@cindex auto-loading libthread_db.so.1
24150
24151This feature is currently present only on @sc{gnu}/Linux native hosts.
24152
24153@value{GDBN} reads in some cases thread debugging library from places specific
24154to the inferior (@pxref{set libthread-db-search-path}).
24155
24156The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
24157without checking this @samp{set auto-load libthread-db} switch as system
24158libraries have to be trusted in general. In all other cases of
24159@samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
24160auto-load libthread-db} is enabled before trying to open such thread debugging
24161library.
24162
c1668e4e
JK
24163Note that loading of this debugging library also requires accordingly configured
24164@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
24165
bf88dd68
JK
24166@table @code
24167@anchor{set auto-load libthread-db}
24168@kindex set auto-load libthread-db
24169@item set auto-load libthread-db [on|off]
24170Enable or disable the auto-loading of inferior specific thread debugging library.
24171
24172@anchor{show auto-load libthread-db}
24173@kindex show auto-load libthread-db
24174@item show auto-load libthread-db
24175Show whether auto-loading of inferior specific thread debugging library is
24176enabled or disabled.
24177
24178@anchor{info auto-load libthread-db}
24179@kindex info auto-load libthread-db
24180@item info auto-load libthread-db
24181Print the list of all loaded inferior specific thread debugging libraries and
24182for each such library print list of inferior @var{pid}s using it.
24183@end table
24184
bccbefd2
JK
24185@node Auto-loading safe path
24186@subsection Security restriction for auto-loading
24187@cindex auto-loading safe-path
24188
24189As the files of inferior can come from untrusted source (such as submitted by
24190an application user) @value{GDBN} does not always load any files automatically.
24191@value{GDBN} provides the @samp{set auto-load safe-path} setting to list
24192directories trusted for loading files not explicitly requested by user.
202cbf1c 24193Each directory can also be a shell wildcard pattern.
bccbefd2
JK
24194
24195If the path is not set properly you will see a warning and the file will not
24196get loaded:
24197
24198@smallexample
24199$ ./gdb -q ./gdb
24200Reading symbols from /home/user/gdb/gdb...done.
24201warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
1564a261
JK
24202 declined by your `auto-load safe-path' set
24203 to "$debugdir:$datadir/auto-load".
bccbefd2 24204warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
1564a261
JK
24205 declined by your `auto-load safe-path' set
24206 to "$debugdir:$datadir/auto-load".
bccbefd2
JK
24207@end smallexample
24208
2c91021c
JK
24209@noindent
24210To instruct @value{GDBN} to go ahead and use the init files anyway,
24211invoke @value{GDBN} like this:
24212
24213@smallexample
24214$ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
24215@end smallexample
24216
bccbefd2
JK
24217The list of trusted directories is controlled by the following commands:
24218
24219@table @code
24220@anchor{set auto-load safe-path}
24221@kindex set auto-load safe-path
af2c1515 24222@item set auto-load safe-path @r{[}@var{directories}@r{]}
bccbefd2
JK
24223Set the list of directories (and their subdirectories) trusted for automatic
24224loading and execution of scripts. You can also enter a specific trusted file.
202cbf1c
JK
24225Each directory can also be a shell wildcard pattern; wildcards do not match
24226directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
24227(@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
af2c1515
JK
24228If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
24229its default value as specified during @value{GDBN} compilation.
24230
d9242c17 24231The list of directories uses path separator (@samp{:} on GNU and Unix
bccbefd2
JK
24232systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
24233to the @env{PATH} environment variable.
24234
24235@anchor{show auto-load safe-path}
24236@kindex show auto-load safe-path
24237@item show auto-load safe-path
24238Show the list of directories trusted for automatic loading and execution of
24239scripts.
24240
24241@anchor{add-auto-load-safe-path}
24242@kindex add-auto-load-safe-path
24243@item add-auto-load-safe-path
413b59ae
JK
24244Add an entry (or list of entries) to the list of directories trusted for
24245automatic loading and execution of scripts. Multiple entries may be delimited
24246by the host platform path separator in use.
bccbefd2
JK
24247@end table
24248
7349ff92 24249This variable defaults to what @code{--with-auto-load-dir} has been configured
1564a261
JK
24250to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
24251substitution applies the same as for @ref{set auto-load scripts-directory}.
24252The default @code{set auto-load safe-path} value can be also overriden by
24253@value{GDBN} configuration option @option{--with-auto-load-safe-path}.
6dea1fbd 24254
6dea1fbd
JK
24255Setting this variable to @file{/} disables this security protection,
24256corresponding @value{GDBN} configuration option is
24257@option{--without-auto-load-safe-path}.
bccbefd2
JK
24258This variable is supposed to be set to the system directories writable by the
24259system superuser only. Users can add their source directories in init files in
24260their home directories (@pxref{Home Directory Init File}). See also deprecated
24261init file in the current directory
24262(@pxref{Init File in the Current Directory during Startup}).
24263
24264To force @value{GDBN} to load the files it declined to load in the previous
24265example, you could use one of the following ways:
24266
0511cc75
JK
24267@table @asis
24268@item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
bccbefd2
JK
24269Specify this trusted directory (or a file) as additional component of the list.
24270You have to specify also any existing directories displayed by
24271by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
24272
174bb630 24273@item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
bccbefd2
JK
24274Specify this directory as in the previous case but just for a single
24275@value{GDBN} session.
24276
af2c1515 24277@item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
bccbefd2
JK
24278Disable auto-loading safety for a single @value{GDBN} session.
24279This assumes all the files you debug during this @value{GDBN} session will come
24280from trusted sources.
24281
24282@item @kbd{./configure --without-auto-load-safe-path}
24283During compilation of @value{GDBN} you may disable any auto-loading safety.
24284This assumes all the files you will ever debug with this @value{GDBN} come from
24285trusted sources.
0511cc75 24286@end table
bccbefd2
JK
24287
24288On the other hand you can also explicitly forbid automatic files loading which
24289also suppresses any such warning messages:
24290
0511cc75 24291@table @asis
174bb630 24292@item @kbd{gdb -iex "set auto-load no" @dots{}}
bccbefd2
JK
24293You can use @value{GDBN} command-line option for a single @value{GDBN} session.
24294
0511cc75 24295@item @file{~/.gdbinit}: @samp{set auto-load no}
bccbefd2
JK
24296Disable auto-loading globally for the user
24297(@pxref{Home Directory Init File}). While it is improbable, you could also
24298use system init file instead (@pxref{System-wide configuration}).
0511cc75 24299@end table
bccbefd2
JK
24300
24301This setting applies to the file names as entered by user. If no entry matches
24302@value{GDBN} tries as a last resort to also resolve all the file names into
24303their canonical form (typically resolving symbolic links) and compare the
24304entries again. @value{GDBN} already canonicalizes most of the filenames on its
24305own before starting the comparison so a canonical form of directories is
24306recommended to be entered.
24307
4dc84fd1
JK
24308@node Auto-loading verbose mode
24309@subsection Displaying files tried for auto-load
24310@cindex auto-loading verbose mode
24311
24312For better visibility of all the file locations where you can place scripts to
24313be auto-loaded with inferior --- or to protect yourself against accidental
24314execution of untrusted scripts --- @value{GDBN} provides a feature for printing
24315all the files attempted to be loaded. Both existing and non-existing files may
24316be printed.
24317
24318For example the list of directories from which it is safe to auto-load files
24319(@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
24320may not be too obvious while setting it up.
24321
24322@smallexample
0070f25a 24323(gdb) set debug auto-load on
4dc84fd1
JK
24324(gdb) file ~/src/t/true
24325auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
24326 for objfile "/tmp/true".
24327auto-load: Updating directories of "/usr:/opt".
24328auto-load: Using directory "/usr".
24329auto-load: Using directory "/opt".
24330warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
24331 by your `auto-load safe-path' set to "/usr:/opt".
24332@end smallexample
24333
24334@table @code
24335@anchor{set debug auto-load}
24336@kindex set debug auto-load
24337@item set debug auto-load [on|off]
24338Set whether to print the filenames attempted to be auto-loaded.
24339
24340@anchor{show debug auto-load}
24341@kindex show debug auto-load
24342@item show debug auto-load
24343Show whether printing of the filenames attempted to be auto-loaded is turned
24344on or off.
24345@end table
24346
8e04817f 24347@node Messages/Warnings
79a6e687 24348@section Optional Warnings and Messages
104c1213 24349
9c16f35a
EZ
24350@cindex verbose operation
24351@cindex optional warnings
8e04817f
AC
24352By default, @value{GDBN} is silent about its inner workings. If you are
24353running on a slow machine, you may want to use the @code{set verbose}
24354command. This makes @value{GDBN} tell you when it does a lengthy
24355internal operation, so you will not think it has crashed.
104c1213 24356
8e04817f
AC
24357Currently, the messages controlled by @code{set verbose} are those
24358which announce that the symbol table for a source file is being read;
79a6e687 24359see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 24360
8e04817f
AC
24361@table @code
24362@kindex set verbose
24363@item set verbose on
24364Enables @value{GDBN} output of certain informational messages.
104c1213 24365
8e04817f
AC
24366@item set verbose off
24367Disables @value{GDBN} output of certain informational messages.
104c1213 24368
8e04817f
AC
24369@kindex show verbose
24370@item show verbose
24371Displays whether @code{set verbose} is on or off.
24372@end table
104c1213 24373
8e04817f
AC
24374By default, if @value{GDBN} encounters bugs in the symbol table of an
24375object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
24376find this information useful (@pxref{Symbol Errors, ,Errors Reading
24377Symbol Files}).
104c1213 24378
8e04817f 24379@table @code
104c1213 24380
8e04817f
AC
24381@kindex set complaints
24382@item set complaints @var{limit}
24383Permits @value{GDBN} to output @var{limit} complaints about each type of
24384unusual symbols before becoming silent about the problem. Set
24385@var{limit} to zero to suppress all complaints; set it to a large number
24386to prevent complaints from being suppressed.
104c1213 24387
8e04817f
AC
24388@kindex show complaints
24389@item show complaints
24390Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 24391
8e04817f 24392@end table
104c1213 24393
d837706a 24394@anchor{confirmation requests}
8e04817f
AC
24395By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
24396lot of stupid questions to confirm certain commands. For example, if
24397you try to run a program which is already running:
104c1213 24398
474c8240 24399@smallexample
8e04817f
AC
24400(@value{GDBP}) run
24401The program being debugged has been started already.
24402Start it from the beginning? (y or n)
474c8240 24403@end smallexample
104c1213 24404
8e04817f
AC
24405If you are willing to unflinchingly face the consequences of your own
24406commands, you can disable this ``feature'':
104c1213 24407
8e04817f 24408@table @code
104c1213 24409
8e04817f
AC
24410@kindex set confirm
24411@cindex flinching
24412@cindex confirmation
24413@cindex stupid questions
24414@item set confirm off
7c953934
TT
24415Disables confirmation requests. Note that running @value{GDBN} with
24416the @option{--batch} option (@pxref{Mode Options, -batch}) also
24417automatically disables confirmation requests.
104c1213 24418
8e04817f
AC
24419@item set confirm on
24420Enables confirmation requests (the default).
104c1213 24421
8e04817f
AC
24422@kindex show confirm
24423@item show confirm
24424Displays state of confirmation requests.
24425
24426@end table
104c1213 24427
16026cd7
AS
24428@cindex command tracing
24429If you need to debug user-defined commands or sourced files you may find it
24430useful to enable @dfn{command tracing}. In this mode each command will be
24431printed as it is executed, prefixed with one or more @samp{+} symbols, the
24432quantity denoting the call depth of each command.
24433
24434@table @code
24435@kindex set trace-commands
24436@cindex command scripts, debugging
24437@item set trace-commands on
24438Enable command tracing.
24439@item set trace-commands off
24440Disable command tracing.
24441@item show trace-commands
24442Display the current state of command tracing.
24443@end table
24444
8e04817f 24445@node Debugging Output
79a6e687 24446@section Optional Messages about Internal Happenings
4644b6e3
EZ
24447@cindex optional debugging messages
24448
da316a69
EZ
24449@value{GDBN} has commands that enable optional debugging messages from
24450various @value{GDBN} subsystems; normally these commands are of
24451interest to @value{GDBN} maintainers, or when reporting a bug. This
24452section documents those commands.
24453
104c1213 24454@table @code
a8f24a35
EZ
24455@kindex set exec-done-display
24456@item set exec-done-display
24457Turns on or off the notification of asynchronous commands'
24458completion. When on, @value{GDBN} will print a message when an
24459asynchronous command finishes its execution. The default is off.
24460@kindex show exec-done-display
24461@item show exec-done-display
24462Displays the current setting of asynchronous command completion
24463notification.
4644b6e3 24464@kindex set debug
be9a8770
PA
24465@cindex ARM AArch64
24466@item set debug aarch64
24467Turns on or off display of debugging messages related to ARM AArch64.
24468The default is off.
24469@kindex show debug
24470@item show debug aarch64
24471Displays the current state of displaying debugging messages related to
24472ARM AArch64.
4644b6e3 24473@cindex gdbarch debugging info
a8f24a35 24474@cindex architecture debugging info
8e04817f 24475@item set debug arch
a8f24a35 24476Turns on or off display of gdbarch debugging info. The default is off
8e04817f
AC
24477@item show debug arch
24478Displays the current state of displaying gdbarch debugging info.
9a005eb9
JB
24479@item set debug aix-solib
24480@cindex AIX shared library debugging
24481Control display of debugging messages from the AIX shared library
24482support module. The default is off.
24483@item show debug aix-thread
24484Show the current state of displaying AIX shared library debugging messages.
721c2651
EZ
24485@item set debug aix-thread
24486@cindex AIX threads
24487Display debugging messages about inner workings of the AIX thread
24488module.
24489@item show debug aix-thread
24490Show the current state of AIX thread debugging info display.
900e11f9
JK
24491@item set debug check-physname
24492@cindex physname
24493Check the results of the ``physname'' computation. When reading DWARF
24494debugging information for C@t{++}, @value{GDBN} attempts to compute
24495each entity's name. @value{GDBN} can do this computation in two
24496different ways, depending on exactly what information is present.
24497When enabled, this setting causes @value{GDBN} to compute the names
24498both ways and display any discrepancies.
24499@item show debug check-physname
24500Show the current state of ``physname'' checking.
be9a8770
PA
24501@item set debug coff-pe-read
24502@cindex COFF/PE exported symbols
24503Control display of debugging messages related to reading of COFF/PE
24504exported symbols. The default is off.
24505@item show debug coff-pe-read
24506Displays the current state of displaying debugging messages related to
24507reading of COFF/PE exported symbols.
b4f54984
DE
24508@item set debug dwarf-die
24509@cindex DWARF DIEs
24510Dump DWARF DIEs after they are read in.
d97bc12b
DE
24511The value is the number of nesting levels to print.
24512A value of zero turns off the display.
b4f54984
DE
24513@item show debug dwarf-die
24514Show the current state of DWARF DIE debugging.
27e0867f
DE
24515@item set debug dwarf-line
24516@cindex DWARF Line Tables
24517Turns on or off display of debugging messages related to reading
24518DWARF line tables. The default is 0 (off).
24519A value of 1 provides basic information.
24520A value greater than 1 provides more verbose information.
24521@item show debug dwarf-line
24522Show the current state of DWARF line table debugging.
b4f54984
DE
24523@item set debug dwarf-read
24524@cindex DWARF Reading
45cfd468 24525Turns on or off display of debugging messages related to reading
73be47f5
DE
24526DWARF debug info. The default is 0 (off).
24527A value of 1 provides basic information.
24528A value greater than 1 provides more verbose information.
b4f54984
DE
24529@item show debug dwarf-read
24530Show the current state of DWARF reader debugging.
237fc4c9
PA
24531@item set debug displaced
24532@cindex displaced stepping debugging info
24533Turns on or off display of @value{GDBN} debugging info for the
24534displaced stepping support. The default is off.
24535@item show debug displaced
24536Displays the current state of displaying @value{GDBN} debugging info
24537related to displaced stepping.
8e04817f 24538@item set debug event
4644b6e3 24539@cindex event debugging info
a8f24a35 24540Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 24541default is off.
8e04817f
AC
24542@item show debug event
24543Displays the current state of displaying @value{GDBN} event debugging
24544info.
8e04817f 24545@item set debug expression
4644b6e3 24546@cindex expression debugging info
721c2651
EZ
24547Turns on or off display of debugging info about @value{GDBN}
24548expression parsing. The default is off.
8e04817f 24549@item show debug expression
721c2651
EZ
24550Displays the current state of displaying debugging info about
24551@value{GDBN} expression parsing.
6e9567fe
JB
24552@item set debug fbsd-lwp
24553@cindex FreeBSD LWP debug messages
24554Turns on or off debugging messages from the FreeBSD LWP debug support.
24555@item show debug fbsd-lwp
24556Show the current state of FreeBSD LWP debugging messages.
386a8676
JB
24557@item set debug fbsd-nat
24558@cindex FreeBSD native target debug messages
24559Turns on or off debugging messages from the FreeBSD native target.
24560@item show debug fbsd-nat
24561Show the current state of FreeBSD native target debugging messages.
7453dc06 24562@item set debug frame
4644b6e3 24563@cindex frame debugging info
7453dc06
AC
24564Turns on or off display of @value{GDBN} frame debugging info. The
24565default is off.
7453dc06
AC
24566@item show debug frame
24567Displays the current state of displaying @value{GDBN} frame debugging
24568info.
cbe54154
PA
24569@item set debug gnu-nat
24570@cindex @sc{gnu}/Hurd debug messages
67ebd9cb 24571Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
cbe54154
PA
24572@item show debug gnu-nat
24573Show the current state of @sc{gnu}/Hurd debugging messages.
30e91e0b
RC
24574@item set debug infrun
24575@cindex inferior debugging info
24576Turns on or off display of @value{GDBN} debugging info for running the inferior.
24577The default is off. @file{infrun.c} contains GDB's runtime state machine used
24578for implementing operations such as single-stepping the inferior.
24579@item show debug infrun
24580Displays the current state of @value{GDBN} inferior debugging.
a255712f
PP
24581@item set debug jit
24582@cindex just-in-time compilation, debugging messages
67ebd9cb 24583Turn on or off debugging messages from JIT debug support.
a255712f
PP
24584@item show debug jit
24585Displays the current state of @value{GDBN} JIT debugging.
da316a69
EZ
24586@item set debug lin-lwp
24587@cindex @sc{gnu}/Linux LWP debug messages
24588@cindex Linux lightweight processes
67ebd9cb 24589Turn on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
24590@item show debug lin-lwp
24591Show the current state of Linux LWP debugging messages.
7a6a1731
GB
24592@item set debug linux-namespaces
24593@cindex @sc{gnu}/Linux namespaces debug messages
67ebd9cb 24594Turn on or off debugging messages from the Linux namespaces debug support.
7a6a1731
GB
24595@item show debug linux-namespaces
24596Show the current state of Linux namespaces debugging messages.
be9a8770
PA
24597@item set debug mach-o
24598@cindex Mach-O symbols processing
24599Control display of debugging messages related to Mach-O symbols
24600processing. The default is off.
24601@item show debug mach-o
24602Displays the current state of displaying debugging messages related to
24603reading of COFF/PE exported symbols.
c9b6281a
YQ
24604@item set debug notification
24605@cindex remote async notification debugging info
67ebd9cb 24606Turn on or off debugging messages about remote async notification.
c9b6281a
YQ
24607The default is off.
24608@item show debug notification
24609Displays the current state of remote async notification debugging messages.
2b4855ab 24610@item set debug observer
4644b6e3 24611@cindex observer debugging info
2b4855ab
AC
24612Turns on or off display of @value{GDBN} observer debugging. This
24613includes info such as the notification of observable events.
2b4855ab
AC
24614@item show debug observer
24615Displays the current state of observer debugging.
8e04817f 24616@item set debug overload
4644b6e3 24617@cindex C@t{++} overload debugging info
8e04817f 24618Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 24619info. This includes info such as ranking of functions, etc. The default
8e04817f 24620is off.
8e04817f
AC
24621@item show debug overload
24622Displays the current state of displaying @value{GDBN} C@t{++} overload
24623debugging info.
92981e24
TT
24624@cindex expression parser, debugging info
24625@cindex debug expression parser
24626@item set debug parser
24627Turns on or off the display of expression parser debugging output.
24628Internally, this sets the @code{yydebug} variable in the expression
24629parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
24630details. The default is off.
24631@item show debug parser
24632Show the current state of expression parser debugging.
8e04817f
AC
24633@cindex packets, reporting on stdout
24634@cindex serial connections, debugging
605a56cb
DJ
24635@cindex debug remote protocol
24636@cindex remote protocol debugging
24637@cindex display remote packets
8e04817f
AC
24638@item set debug remote
24639Turns on or off display of reports on all packets sent back and forth across
24640the serial line to the remote machine. The info is printed on the
24641@value{GDBN} standard output stream. The default is off.
8e04817f
AC
24642@item show debug remote
24643Displays the state of display of remote packets.
c4dcb155
SM
24644
24645@item set debug separate-debug-file
24646Turns on or off display of debug output about separate debug file search.
24647@item show debug separate-debug-file
24648Displays the state of separate debug file search debug output.
24649
8e04817f
AC
24650@item set debug serial
24651Turns on or off display of @value{GDBN} serial debugging info. The
24652default is off.
8e04817f
AC
24653@item show debug serial
24654Displays the current state of displaying @value{GDBN} serial debugging
24655info.
c45da7e6
EZ
24656@item set debug solib-frv
24657@cindex FR-V shared-library debugging
67ebd9cb 24658Turn on or off debugging messages for FR-V shared-library code.
c45da7e6
EZ
24659@item show debug solib-frv
24660Display the current state of FR-V shared-library code debugging
24661messages.
cc485e62
DE
24662@item set debug symbol-lookup
24663@cindex symbol lookup
24664Turns on or off display of debugging messages related to symbol lookup.
24665The default is 0 (off).
24666A value of 1 provides basic information.
24667A value greater than 1 provides more verbose information.
24668@item show debug symbol-lookup
24669Show the current state of symbol lookup debugging messages.
8fb8eb5c
DE
24670@item set debug symfile
24671@cindex symbol file functions
24672Turns on or off display of debugging messages related to symbol file functions.
24673The default is off. @xref{Files}.
24674@item show debug symfile
24675Show the current state of symbol file debugging messages.
45cfd468
DE
24676@item set debug symtab-create
24677@cindex symbol table creation
24678Turns on or off display of debugging messages related to symbol table creation.
db0fec5c
DE
24679The default is 0 (off).
24680A value of 1 provides basic information.
24681A value greater than 1 provides more verbose information.
45cfd468
DE
24682@item show debug symtab-create
24683Show the current state of symbol table creation debugging.
8e04817f 24684@item set debug target
4644b6e3 24685@cindex target debugging info
8e04817f
AC
24686Turns on or off display of @value{GDBN} target debugging info. This info
24687includes what is going on at the target level of GDB, as it happens. The
701b08bb 24688default is 0. Set it to 1 to track events, and to 2 to also track the
3cecbbbe 24689value of large memory transfers.
8e04817f
AC
24690@item show debug target
24691Displays the current state of displaying @value{GDBN} target debugging
24692info.
75feb17d
DJ
24693@item set debug timestamp
24694@cindex timestampping debugging info
24695Turns on or off display of timestamps with @value{GDBN} debugging info.
24696When enabled, seconds and microseconds are displayed before each debugging
24697message.
24698@item show debug timestamp
24699Displays the current state of displaying timestamps with @value{GDBN}
24700debugging info.
f989a1c8 24701@item set debug varobj
4644b6e3 24702@cindex variable object debugging info
8e04817f
AC
24703Turns on or off display of @value{GDBN} variable object debugging
24704info. The default is off.
f989a1c8 24705@item show debug varobj
8e04817f
AC
24706Displays the current state of displaying @value{GDBN} variable object
24707debugging info.
e776119f
DJ
24708@item set debug xml
24709@cindex XML parser debugging
67ebd9cb 24710Turn on or off debugging messages for built-in XML parsers.
e776119f
DJ
24711@item show debug xml
24712Displays the current state of XML debugging messages.
8e04817f 24713@end table
104c1213 24714
14fb1bac
JB
24715@node Other Misc Settings
24716@section Other Miscellaneous Settings
24717@cindex miscellaneous settings
24718
24719@table @code
24720@kindex set interactive-mode
24721@item set interactive-mode
7bfc9434
JB
24722If @code{on}, forces @value{GDBN} to assume that GDB was started
24723in a terminal. In practice, this means that @value{GDBN} should wait
24724for the user to answer queries generated by commands entered at
24725the command prompt. If @code{off}, forces @value{GDBN} to operate
24726in the opposite mode, and it uses the default answers to all queries.
24727If @code{auto} (the default), @value{GDBN} tries to determine whether
24728its standard input is a terminal, and works in interactive-mode if it
24729is, non-interactively otherwise.
14fb1bac
JB
24730
24731In the vast majority of cases, the debugger should be able to guess
24732correctly which mode should be used. But this setting can be useful
24733in certain specific cases, such as running a MinGW @value{GDBN}
24734inside a cygwin window.
24735
24736@kindex show interactive-mode
24737@item show interactive-mode
24738Displays whether the debugger is operating in interactive mode or not.
24739@end table
24740
d57a3c85
TJB
24741@node Extending GDB
24742@chapter Extending @value{GDBN}
24743@cindex extending GDB
24744
71b8c845
DE
24745@value{GDBN} provides several mechanisms for extension.
24746@value{GDBN} also provides the ability to automatically load
24747extensions when it reads a file for debugging. This allows the
24748user to automatically customize @value{GDBN} for the program
24749being debugged.
d57a3c85 24750
71b8c845
DE
24751@menu
24752* Sequences:: Canned Sequences of @value{GDBN} Commands
24753* Python:: Extending @value{GDBN} using Python
ed3ef339 24754* Guile:: Extending @value{GDBN} using Guile
71b8c845 24755* Auto-loading extensions:: Automatically loading extensions
ed3ef339 24756* Multiple Extension Languages:: Working with multiple extension languages
71b8c845
DE
24757* Aliases:: Creating new spellings of existing commands
24758@end menu
24759
24760To facilitate the use of extension languages, @value{GDBN} is capable
95433b34 24761of evaluating the contents of a file. When doing so, @value{GDBN}
71b8c845 24762can recognize which extension language is being used by looking at
95433b34
JB
24763the filename extension. Files with an unrecognized filename extension
24764are always treated as a @value{GDBN} Command Files.
24765@xref{Command Files,, Command files}.
24766
24767You can control how @value{GDBN} evaluates these files with the following
24768setting:
24769
24770@table @code
24771@kindex set script-extension
24772@kindex show script-extension
24773@item set script-extension off
24774All scripts are always evaluated as @value{GDBN} Command Files.
24775
24776@item set script-extension soft
24777The debugger determines the scripting language based on filename
24778extension. If this scripting language is supported, @value{GDBN}
24779evaluates the script using that language. Otherwise, it evaluates
24780the file as a @value{GDBN} Command File.
24781
24782@item set script-extension strict
24783The debugger determines the scripting language based on filename
24784extension, and evaluates the script using that language. If the
24785language is not supported, then the evaluation fails.
24786
24787@item show script-extension
24788Display the current value of the @code{script-extension} option.
24789
24790@end table
24791
8e04817f 24792@node Sequences
d57a3c85 24793@section Canned Sequences of Commands
104c1213 24794
8e04817f 24795Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 24796Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
24797commands for execution as a unit: user-defined commands and command
24798files.
104c1213 24799
8e04817f 24800@menu
fcc73fe3
EZ
24801* Define:: How to define your own commands
24802* Hooks:: Hooks for user-defined commands
24803* Command Files:: How to write scripts of commands to be stored in a file
24804* Output:: Commands for controlled output
71b8c845 24805* Auto-loading sequences:: Controlling auto-loaded command files
8e04817f 24806@end menu
104c1213 24807
8e04817f 24808@node Define
d57a3c85 24809@subsection User-defined Commands
104c1213 24810
8e04817f 24811@cindex user-defined command
fcc73fe3 24812@cindex arguments, to user-defined commands
8e04817f
AC
24813A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
24814which you assign a new name as a command. This is done with the
df3ee9ca 24815@code{define} command. User commands may accept an unlimited number of arguments
8e04817f 24816separated by whitespace. Arguments are accessed within the user command
df3ee9ca 24817via @code{$arg0@dots{}$argN}. A trivial example:
104c1213 24818
8e04817f
AC
24819@smallexample
24820define adder
24821 print $arg0 + $arg1 + $arg2
c03c782f 24822end
8e04817f 24823@end smallexample
104c1213
JM
24824
24825@noindent
8e04817f 24826To execute the command use:
104c1213 24827
8e04817f
AC
24828@smallexample
24829adder 1 2 3
24830@end smallexample
104c1213 24831
8e04817f
AC
24832@noindent
24833This defines the command @code{adder}, which prints the sum of
24834its three arguments. Note the arguments are text substitutions, so they may
24835reference variables, use complex expressions, or even perform inferior
24836functions calls.
104c1213 24837
fcc73fe3
EZ
24838@cindex argument count in user-defined commands
24839@cindex how many arguments (user-defined commands)
c03c782f 24840In addition, @code{$argc} may be used to find out how many arguments have
df3ee9ca 24841been passed.
c03c782f
AS
24842
24843@smallexample
24844define adder
24845 if $argc == 2
24846 print $arg0 + $arg1
24847 end
24848 if $argc == 3
24849 print $arg0 + $arg1 + $arg2
24850 end
24851end
24852@end smallexample
24853
01770bbd
PA
24854Combining with the @code{eval} command (@pxref{eval}) makes it easier
24855to process a variable number of arguments:
24856
24857@smallexample
24858define adder
24859 set $i = 0
24860 set $sum = 0
24861 while $i < $argc
24862 eval "set $sum = $sum + $arg%d", $i
24863 set $i = $i + 1
24864 end
24865 print $sum
24866end
24867@end smallexample
24868
104c1213 24869@table @code
104c1213 24870
8e04817f
AC
24871@kindex define
24872@item define @var{commandname}
24873Define a command named @var{commandname}. If there is already a command
24874by that name, you are asked to confirm that you want to redefine it.
697aa1b7 24875The argument @var{commandname} may be a bare command name consisting of letters,
adb483fe
DJ
24876numbers, dashes, and underscores. It may also start with any predefined
24877prefix command. For example, @samp{define target my-target} creates
24878a user-defined @samp{target my-target} command.
104c1213 24879
8e04817f
AC
24880The definition of the command is made up of other @value{GDBN} command lines,
24881which are given following the @code{define} command. The end of these
24882commands is marked by a line containing @code{end}.
104c1213 24883
8e04817f 24884@kindex document
ca91424e 24885@kindex end@r{ (user-defined commands)}
8e04817f
AC
24886@item document @var{commandname}
24887Document the user-defined command @var{commandname}, so that it can be
24888accessed by @code{help}. The command @var{commandname} must already be
24889defined. This command reads lines of documentation just as @code{define}
24890reads the lines of the command definition, ending with @code{end}.
24891After the @code{document} command is finished, @code{help} on command
24892@var{commandname} displays the documentation you have written.
104c1213 24893
8e04817f
AC
24894You may use the @code{document} command again to change the
24895documentation of a command. Redefining the command with @code{define}
24896does not change the documentation.
104c1213 24897
c45da7e6
EZ
24898@kindex dont-repeat
24899@cindex don't repeat command
24900@item dont-repeat
24901Used inside a user-defined command, this tells @value{GDBN} that this
24902command should not be repeated when the user hits @key{RET}
24903(@pxref{Command Syntax, repeat last command}).
24904
8e04817f
AC
24905@kindex help user-defined
24906@item help user-defined
7d74f244
DE
24907List all user-defined commands and all python commands defined in class
24908COMAND_USER. The first line of the documentation or docstring is
24909included (if any).
104c1213 24910
8e04817f
AC
24911@kindex show user
24912@item show user
24913@itemx show user @var{commandname}
24914Display the @value{GDBN} commands used to define @var{commandname} (but
24915not its documentation). If no @var{commandname} is given, display the
24916definitions for all user-defined commands.
7d74f244 24917This does not work for user-defined python commands.
104c1213 24918
fcc73fe3 24919@cindex infinite recursion in user-defined commands
20f01a46
DH
24920@kindex show max-user-call-depth
24921@kindex set max-user-call-depth
24922@item show max-user-call-depth
5ca0cb28
DH
24923@itemx set max-user-call-depth
24924The value of @code{max-user-call-depth} controls how many recursion
3f94c067 24925levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 24926infinite recursion and aborts the command.
7d74f244 24927This does not apply to user-defined python commands.
104c1213
JM
24928@end table
24929
fcc73fe3
EZ
24930In addition to the above commands, user-defined commands frequently
24931use control flow commands, described in @ref{Command Files}.
24932
8e04817f
AC
24933When user-defined commands are executed, the
24934commands of the definition are not printed. An error in any command
24935stops execution of the user-defined command.
104c1213 24936
8e04817f
AC
24937If used interactively, commands that would ask for confirmation proceed
24938without asking when used inside a user-defined command. Many @value{GDBN}
24939commands that normally print messages to say what they are doing omit the
24940messages when used in a user-defined command.
104c1213 24941
8e04817f 24942@node Hooks
d57a3c85 24943@subsection User-defined Command Hooks
8e04817f
AC
24944@cindex command hooks
24945@cindex hooks, for commands
24946@cindex hooks, pre-command
104c1213 24947
8e04817f 24948@kindex hook
8e04817f
AC
24949You may define @dfn{hooks}, which are a special kind of user-defined
24950command. Whenever you run the command @samp{foo}, if the user-defined
24951command @samp{hook-foo} exists, it is executed (with no arguments)
24952before that command.
104c1213 24953
8e04817f
AC
24954@cindex hooks, post-command
24955@kindex hookpost
8e04817f
AC
24956A hook may also be defined which is run after the command you executed.
24957Whenever you run the command @samp{foo}, if the user-defined command
24958@samp{hookpost-foo} exists, it is executed (with no arguments) after
24959that command. Post-execution hooks may exist simultaneously with
24960pre-execution hooks, for the same command.
104c1213 24961
8e04817f 24962It is valid for a hook to call the command which it hooks. If this
9f1c6395 24963occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 24964
8e04817f
AC
24965@c It would be nice if hookpost could be passed a parameter indicating
24966@c if the command it hooks executed properly or not. FIXME!
104c1213 24967
8e04817f
AC
24968@kindex stop@r{, a pseudo-command}
24969In addition, a pseudo-command, @samp{stop} exists. Defining
24970(@samp{hook-stop}) makes the associated commands execute every time
24971execution stops in your program: before breakpoint commands are run,
24972displays are printed, or the stack frame is printed.
104c1213 24973
8e04817f
AC
24974For example, to ignore @code{SIGALRM} signals while
24975single-stepping, but treat them normally during normal execution,
24976you could define:
104c1213 24977
474c8240 24978@smallexample
8e04817f
AC
24979define hook-stop
24980handle SIGALRM nopass
24981end
104c1213 24982
8e04817f
AC
24983define hook-run
24984handle SIGALRM pass
24985end
104c1213 24986
8e04817f 24987define hook-continue
d3e8051b 24988handle SIGALRM pass
8e04817f 24989end
474c8240 24990@end smallexample
104c1213 24991
d3e8051b 24992As a further example, to hook at the beginning and end of the @code{echo}
b383017d 24993command, and to add extra text to the beginning and end of the message,
8e04817f 24994you could define:
104c1213 24995
474c8240 24996@smallexample
8e04817f
AC
24997define hook-echo
24998echo <<<---
24999end
104c1213 25000
8e04817f
AC
25001define hookpost-echo
25002echo --->>>\n
25003end
104c1213 25004
8e04817f
AC
25005(@value{GDBP}) echo Hello World
25006<<<---Hello World--->>>
25007(@value{GDBP})
104c1213 25008
474c8240 25009@end smallexample
104c1213 25010
8e04817f
AC
25011You can define a hook for any single-word command in @value{GDBN}, but
25012not for command aliases; you should define a hook for the basic command
c1468174 25013name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
25014@c FIXME! So how does Joe User discover whether a command is an alias
25015@c or not?
adb483fe
DJ
25016You can hook a multi-word command by adding @code{hook-} or
25017@code{hookpost-} to the last word of the command, e.g.@:
25018@samp{define target hook-remote} to add a hook to @samp{target remote}.
25019
8e04817f
AC
25020If an error occurs during the execution of your hook, execution of
25021@value{GDBN} commands stops and @value{GDBN} issues a prompt
25022(before the command that you actually typed had a chance to run).
104c1213 25023
8e04817f
AC
25024If you try to define a hook which does not match any known command, you
25025get a warning from the @code{define} command.
c906108c 25026
8e04817f 25027@node Command Files
d57a3c85 25028@subsection Command Files
c906108c 25029
8e04817f 25030@cindex command files
fcc73fe3 25031@cindex scripting commands
6fc08d32
EZ
25032A command file for @value{GDBN} is a text file made of lines that are
25033@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
25034also be included. An empty line in a command file does nothing; it
25035does not mean to repeat the last command, as it would from the
25036terminal.
c906108c 25037
6fc08d32 25038You can request the execution of a command file with the @code{source}
95433b34
JB
25039command. Note that the @code{source} command is also used to evaluate
25040scripts that are not Command Files. The exact behavior can be configured
25041using the @code{script-extension} setting.
25042@xref{Extending GDB,, Extending GDB}.
c906108c 25043
8e04817f
AC
25044@table @code
25045@kindex source
ca91424e 25046@cindex execute commands from a file
3f7b2faa 25047@item source [-s] [-v] @var{filename}
8e04817f 25048Execute the command file @var{filename}.
c906108c
SS
25049@end table
25050
fcc73fe3
EZ
25051The lines in a command file are generally executed sequentially,
25052unless the order of execution is changed by one of the
25053@emph{flow-control commands} described below. The commands are not
a71ec265
DH
25054printed as they are executed. An error in any command terminates
25055execution of the command file and control is returned to the console.
c906108c 25056
08001717
DE
25057@value{GDBN} first searches for @var{filename} in the current directory.
25058If the file is not found there, and @var{filename} does not specify a
25059directory, then @value{GDBN} also looks for the file on the source search path
25060(specified with the @samp{directory} command);
25061except that @file{$cdir} is not searched because the compilation directory
25062is not relevant to scripts.
4b505b12 25063
3f7b2faa
DE
25064If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
25065on the search path even if @var{filename} specifies a directory.
25066The search is done by appending @var{filename} to each element of the
25067search path. So, for example, if @var{filename} is @file{mylib/myscript}
25068and the search path contains @file{/home/user} then @value{GDBN} will
25069look for the script @file{/home/user/mylib/myscript}.
25070The search is also done if @var{filename} is an absolute path.
25071For example, if @var{filename} is @file{/tmp/myscript} and
25072the search path contains @file{/home/user} then @value{GDBN} will
25073look for the script @file{/home/user/tmp/myscript}.
25074For DOS-like systems, if @var{filename} contains a drive specification,
25075it is stripped before concatenation. For example, if @var{filename} is
25076@file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
25077will look for the script @file{c:/tmp/myscript}.
25078
16026cd7
AS
25079If @code{-v}, for verbose mode, is given then @value{GDBN} displays
25080each command as it is executed. The option must be given before
25081@var{filename}, and is interpreted as part of the filename anywhere else.
25082
8e04817f
AC
25083Commands that would ask for confirmation if used interactively proceed
25084without asking when used in a command file. Many @value{GDBN} commands that
25085normally print messages to say what they are doing omit the messages
25086when called from command files.
c906108c 25087
8e04817f
AC
25088@value{GDBN} also accepts command input from standard input. In this
25089mode, normal output goes to standard output and error output goes to
25090standard error. Errors in a command file supplied on standard input do
6fc08d32 25091not terminate execution of the command file---execution continues with
8e04817f 25092the next command.
c906108c 25093
474c8240 25094@smallexample
8e04817f 25095gdb < cmds > log 2>&1
474c8240 25096@end smallexample
c906108c 25097
8e04817f
AC
25098(The syntax above will vary depending on the shell used.) This example
25099will execute commands from the file @file{cmds}. All output and errors
25100would be directed to @file{log}.
c906108c 25101
fcc73fe3
EZ
25102Since commands stored on command files tend to be more general than
25103commands typed interactively, they frequently need to deal with
25104complicated situations, such as different or unexpected values of
25105variables and symbols, changes in how the program being debugged is
25106built, etc. @value{GDBN} provides a set of flow-control commands to
25107deal with these complexities. Using these commands, you can write
25108complex scripts that loop over data structures, execute commands
25109conditionally, etc.
25110
25111@table @code
25112@kindex if
25113@kindex else
25114@item if
25115@itemx else
25116This command allows to include in your script conditionally executed
25117commands. The @code{if} command takes a single argument, which is an
25118expression to evaluate. It is followed by a series of commands that
25119are executed only if the expression is true (its value is nonzero).
25120There can then optionally be an @code{else} line, followed by a series
25121of commands that are only executed if the expression was false. The
25122end of the list is marked by a line containing @code{end}.
25123
25124@kindex while
25125@item while
25126This command allows to write loops. Its syntax is similar to
25127@code{if}: the command takes a single argument, which is an expression
25128to evaluate, and must be followed by the commands to execute, one per
25129line, terminated by an @code{end}. These commands are called the
25130@dfn{body} of the loop. The commands in the body of @code{while} are
25131executed repeatedly as long as the expression evaluates to true.
25132
25133@kindex loop_break
25134@item loop_break
25135This command exits the @code{while} loop in whose body it is included.
25136Execution of the script continues after that @code{while}s @code{end}
25137line.
25138
25139@kindex loop_continue
25140@item loop_continue
25141This command skips the execution of the rest of the body of commands
25142in the @code{while} loop in whose body it is included. Execution
25143branches to the beginning of the @code{while} loop, where it evaluates
25144the controlling expression.
ca91424e
EZ
25145
25146@kindex end@r{ (if/else/while commands)}
25147@item end
25148Terminate the block of commands that are the body of @code{if},
25149@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
25150@end table
25151
25152
8e04817f 25153@node Output
d57a3c85 25154@subsection Commands for Controlled Output
c906108c 25155
8e04817f
AC
25156During the execution of a command file or a user-defined command, normal
25157@value{GDBN} output is suppressed; the only output that appears is what is
25158explicitly printed by the commands in the definition. This section
25159describes three commands useful for generating exactly the output you
25160want.
c906108c
SS
25161
25162@table @code
8e04817f
AC
25163@kindex echo
25164@item echo @var{text}
25165@c I do not consider backslash-space a standard C escape sequence
25166@c because it is not in ANSI.
25167Print @var{text}. Nonprinting characters can be included in
25168@var{text} using C escape sequences, such as @samp{\n} to print a
25169newline. @strong{No newline is printed unless you specify one.}
25170In addition to the standard C escape sequences, a backslash followed
25171by a space stands for a space. This is useful for displaying a
25172string with spaces at the beginning or the end, since leading and
25173trailing spaces are otherwise trimmed from all arguments.
25174To print @samp{@w{ }and foo =@w{ }}, use the command
25175@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 25176
8e04817f
AC
25177A backslash at the end of @var{text} can be used, as in C, to continue
25178the command onto subsequent lines. For example,
c906108c 25179
474c8240 25180@smallexample
8e04817f
AC
25181echo This is some text\n\
25182which is continued\n\
25183onto several lines.\n
474c8240 25184@end smallexample
c906108c 25185
8e04817f 25186produces the same output as
c906108c 25187
474c8240 25188@smallexample
8e04817f
AC
25189echo This is some text\n
25190echo which is continued\n
25191echo onto several lines.\n
474c8240 25192@end smallexample
c906108c 25193
8e04817f
AC
25194@kindex output
25195@item output @var{expression}
25196Print the value of @var{expression} and nothing but that value: no
25197newlines, no @samp{$@var{nn} = }. The value is not entered in the
25198value history either. @xref{Expressions, ,Expressions}, for more information
25199on expressions.
c906108c 25200
8e04817f
AC
25201@item output/@var{fmt} @var{expression}
25202Print the value of @var{expression} in format @var{fmt}. You can use
25203the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 25204Formats}, for more information.
c906108c 25205
8e04817f 25206@kindex printf
82160952
EZ
25207@item printf @var{template}, @var{expressions}@dots{}
25208Print the values of one or more @var{expressions} under the control of
25209the string @var{template}. To print several values, make
25210@var{expressions} be a comma-separated list of individual expressions,
25211which may be either numbers or pointers. Their values are printed as
25212specified by @var{template}, exactly as a C program would do by
25213executing the code below:
c906108c 25214
474c8240 25215@smallexample
82160952 25216printf (@var{template}, @var{expressions}@dots{});
474c8240 25217@end smallexample
c906108c 25218
82160952
EZ
25219As in @code{C} @code{printf}, ordinary characters in @var{template}
25220are printed verbatim, while @dfn{conversion specification} introduced
25221by the @samp{%} character cause subsequent @var{expressions} to be
25222evaluated, their values converted and formatted according to type and
25223style information encoded in the conversion specifications, and then
25224printed.
25225
8e04817f 25226For example, you can print two values in hex like this:
c906108c 25227
8e04817f
AC
25228@smallexample
25229printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
25230@end smallexample
c906108c 25231
82160952
EZ
25232@code{printf} supports all the standard @code{C} conversion
25233specifications, including the flags and modifiers between the @samp{%}
25234character and the conversion letter, with the following exceptions:
25235
25236@itemize @bullet
25237@item
25238The argument-ordering modifiers, such as @samp{2$}, are not supported.
25239
25240@item
25241The modifier @samp{*} is not supported for specifying precision or
25242width.
25243
25244@item
25245The @samp{'} flag (for separation of digits into groups according to
25246@code{LC_NUMERIC'}) is not supported.
25247
25248@item
25249The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
25250supported.
25251
25252@item
25253The conversion letter @samp{n} (as in @samp{%n}) is not supported.
25254
25255@item
25256The conversion letters @samp{a} and @samp{A} are not supported.
25257@end itemize
25258
25259@noindent
25260Note that the @samp{ll} type modifier is supported only if the
25261underlying @code{C} implementation used to build @value{GDBN} supports
25262the @code{long long int} type, and the @samp{L} type modifier is
25263supported only if @code{long double} type is available.
25264
25265As in @code{C}, @code{printf} supports simple backslash-escape
25266sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
25267@samp{\a}, and @samp{\f}, that consist of backslash followed by a
25268single character. Octal and hexadecimal escape sequences are not
25269supported.
1a619819
LM
25270
25271Additionally, @code{printf} supports conversion specifications for DFP
0aea4bf3
LM
25272(@dfn{Decimal Floating Point}) types using the following length modifiers
25273together with a floating point specifier.
1a619819
LM
25274letters:
25275
25276@itemize @bullet
25277@item
25278@samp{H} for printing @code{Decimal32} types.
25279
25280@item
25281@samp{D} for printing @code{Decimal64} types.
25282
25283@item
25284@samp{DD} for printing @code{Decimal128} types.
25285@end itemize
25286
25287If the underlying @code{C} implementation used to build @value{GDBN} has
0aea4bf3 25288support for the three length modifiers for DFP types, other modifiers
3b784c4f 25289such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
25290
25291In case there is no such @code{C} support, no additional modifiers will be
25292available and the value will be printed in the standard way.
25293
25294Here's an example of printing DFP types using the above conversion letters:
25295@smallexample
0aea4bf3 25296printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
1a619819
LM
25297@end smallexample
25298
01770bbd 25299@anchor{eval}
f1421989
HZ
25300@kindex eval
25301@item eval @var{template}, @var{expressions}@dots{}
25302Convert the values of one or more @var{expressions} under the control of
25303the string @var{template} to a command line, and call it.
25304
c906108c
SS
25305@end table
25306
71b8c845
DE
25307@node Auto-loading sequences
25308@subsection Controlling auto-loading native @value{GDBN} scripts
25309@cindex native script auto-loading
25310
25311When a new object file is read (for example, due to the @code{file}
25312command, or because the inferior has loaded a shared library),
25313@value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
25314@xref{Auto-loading extensions}.
25315
25316Auto-loading can be enabled or disabled,
25317and the list of auto-loaded scripts can be printed.
25318
25319@table @code
25320@anchor{set auto-load gdb-scripts}
25321@kindex set auto-load gdb-scripts
25322@item set auto-load gdb-scripts [on|off]
25323Enable or disable the auto-loading of canned sequences of commands scripts.
25324
25325@anchor{show auto-load gdb-scripts}
25326@kindex show auto-load gdb-scripts
25327@item show auto-load gdb-scripts
25328Show whether auto-loading of canned sequences of commands scripts is enabled or
25329disabled.
25330
25331@anchor{info auto-load gdb-scripts}
25332@kindex info auto-load gdb-scripts
25333@cindex print list of auto-loaded canned sequences of commands scripts
25334@item info auto-load gdb-scripts [@var{regexp}]
25335Print the list of all canned sequences of commands scripts that @value{GDBN}
25336auto-loaded.
25337@end table
25338
25339If @var{regexp} is supplied only canned sequences of commands scripts with
25340matching names are printed.
25341
329baa95
DE
25342@c Python docs live in a separate file.
25343@include python.texi
0e3509db 25344
ed3ef339
DE
25345@c Guile docs live in a separate file.
25346@include guile.texi
25347
71b8c845
DE
25348@node Auto-loading extensions
25349@section Auto-loading extensions
25350@cindex auto-loading extensions
25351
25352@value{GDBN} provides two mechanisms for automatically loading extensions
25353when a new object file is read (for example, due to the @code{file}
25354command, or because the inferior has loaded a shared library):
25355@file{@var{objfile}-gdb.@var{ext}} and the @code{.debug_gdb_scripts}
25356section of modern file formats like ELF.
25357
25358@menu
25359* objfile-gdb.ext file: objfile-gdbdotext file. The @file{@var{objfile}-gdb.@var{ext}} file
25360* .debug_gdb_scripts section: dotdebug_gdb_scripts section. The @code{.debug_gdb_scripts} section
25361* Which flavor to choose?::
25362@end menu
25363
25364The auto-loading feature is useful for supplying application-specific
25365debugging commands and features.
25366
25367Auto-loading can be enabled or disabled,
25368and the list of auto-loaded scripts can be printed.
25369See the @samp{auto-loading} section of each extension language
25370for more information.
25371For @value{GDBN} command files see @ref{Auto-loading sequences}.
25372For Python files see @ref{Python Auto-loading}.
25373
25374Note that loading of this script file also requires accordingly configured
25375@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
25376
25377@node objfile-gdbdotext file
25378@subsection The @file{@var{objfile}-gdb.@var{ext}} file
25379@cindex @file{@var{objfile}-gdb.gdb}
25380@cindex @file{@var{objfile}-gdb.py}
25381@cindex @file{@var{objfile}-gdb.scm}
25382
25383When a new object file is read, @value{GDBN} looks for a file named
25384@file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
25385where @var{objfile} is the object file's name and
25386where @var{ext} is the file extension for the extension language:
25387
25388@table @code
25389@item @file{@var{objfile}-gdb.gdb}
25390GDB's own command language
25391@item @file{@var{objfile}-gdb.py}
25392Python
ed3ef339
DE
25393@item @file{@var{objfile}-gdb.scm}
25394Guile
71b8c845
DE
25395@end table
25396
25397@var{script-name} is formed by ensuring that the file name of @var{objfile}
25398is absolute, following all symlinks, and resolving @code{.} and @code{..}
25399components, and appending the @file{-gdb.@var{ext}} suffix.
25400If this file exists and is readable, @value{GDBN} will evaluate it as a
25401script in the specified extension language.
25402
25403If this file does not exist, then @value{GDBN} will look for
25404@var{script-name} file in all of the directories as specified below.
25405
25406Note that loading of these files requires an accordingly configured
25407@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
25408
25409For object files using @file{.exe} suffix @value{GDBN} tries to load first the
25410scripts normally according to its @file{.exe} filename. But if no scripts are
25411found @value{GDBN} also tries script filenames matching the object file without
25412its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
25413is attempted on any platform. This makes the script filenames compatible
25414between Unix and MS-Windows hosts.
25415
25416@table @code
25417@anchor{set auto-load scripts-directory}
25418@kindex set auto-load scripts-directory
25419@item set auto-load scripts-directory @r{[}@var{directories}@r{]}
25420Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
25421may be delimited by the host platform path separator in use
25422(@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
25423
25424Each entry here needs to be covered also by the security setting
25425@code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
25426
25427@anchor{with-auto-load-dir}
25428This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
25429@code{set auto-load safe-path} value can be also overriden by @value{GDBN}
25430configuration option @option{--with-auto-load-dir}.
25431
25432Any reference to @file{$debugdir} will get replaced by
25433@var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
25434reference to @file{$datadir} will get replaced by @var{data-directory} which is
25435determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
25436@file{$datadir} must be placed as a directory component --- either alone or
25437delimited by @file{/} or @file{\} directory separators, depending on the host
25438platform.
25439
25440The list of directories uses path separator (@samp{:} on GNU and Unix
25441systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
25442to the @env{PATH} environment variable.
25443
25444@anchor{show auto-load scripts-directory}
25445@kindex show auto-load scripts-directory
25446@item show auto-load scripts-directory
25447Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
25448
25449@anchor{add-auto-load-scripts-directory}
25450@kindex add-auto-load-scripts-directory
25451@item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
25452Add an entry (or list of entries) to the list of auto-loaded scripts locations.
25453Multiple entries may be delimited by the host platform path separator in use.
71b8c845
DE
25454@end table
25455
25456@value{GDBN} does not track which files it has already auto-loaded this way.
25457@value{GDBN} will load the associated script every time the corresponding
25458@var{objfile} is opened.
25459So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
25460is evaluated more than once.
25461
25462@node dotdebug_gdb_scripts section
25463@subsection The @code{.debug_gdb_scripts} section
25464@cindex @code{.debug_gdb_scripts} section
25465
25466For systems using file formats like ELF and COFF,
25467when @value{GDBN} loads a new object file
25468it will look for a special section named @code{.debug_gdb_scripts}.
9f050062
DE
25469If this section exists, its contents is a list of null-terminated entries
25470specifying scripts to load. Each entry begins with a non-null prefix byte that
25471specifies the kind of entry, typically the extension language and whether the
25472script is in a file or inlined in @code{.debug_gdb_scripts}.
71b8c845 25473
9f050062
DE
25474The following entries are supported:
25475
25476@table @code
25477@item SECTION_SCRIPT_ID_PYTHON_FILE = 1
25478@item SECTION_SCRIPT_ID_SCHEME_FILE = 3
25479@item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
25480@item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
25481@end table
25482
25483@subsubsection Script File Entries
25484
25485If the entry specifies a file, @value{GDBN} will look for the file first
25486in the current directory and then along the source search path
71b8c845
DE
25487(@pxref{Source Path, ,Specifying Source Directories}),
25488except that @file{$cdir} is not searched, since the compilation
25489directory is not relevant to scripts.
25490
9f050062 25491File entries can be placed in section @code{.debug_gdb_scripts} with,
71b8c845
DE
25492for example, this GCC macro for Python scripts.
25493
25494@example
25495/* Note: The "MS" section flags are to remove duplicates. */
25496#define DEFINE_GDB_PY_SCRIPT(script_name) \
25497 asm("\
25498.pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
25499.byte 1 /* Python */\n\
25500.asciz \"" script_name "\"\n\
25501.popsection \n\
25502");
25503@end example
25504
25505@noindent
ed3ef339 25506For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
71b8c845
DE
25507Then one can reference the macro in a header or source file like this:
25508
25509@example
25510DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
25511@end example
25512
25513The script name may include directories if desired.
25514
25515Note that loading of this script file also requires accordingly configured
25516@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
25517
25518If the macro invocation is put in a header, any application or library
25519using this header will get a reference to the specified script,
25520and with the use of @code{"MS"} attributes on the section, the linker
25521will remove duplicates.
25522
9f050062
DE
25523@subsubsection Script Text Entries
25524
25525Script text entries allow to put the executable script in the entry
25526itself instead of loading it from a file.
25527The first line of the entry, everything after the prefix byte and up to
25528the first newline (@code{0xa}) character, is the script name, and must not
25529contain any kind of space character, e.g., spaces or tabs.
25530The rest of the entry, up to the trailing null byte, is the script to
25531execute in the specified language. The name needs to be unique among
25532all script names, as @value{GDBN} executes each script only once based
25533on its name.
25534
25535Here is an example from file @file{py-section-script.c} in the @value{GDBN}
25536testsuite.
25537
25538@example
25539#include "symcat.h"
25540#include "gdb/section-scripts.h"
25541asm(
25542".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
25543".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
25544".ascii \"gdb.inlined-script\\n\"\n"
25545".ascii \"class test_cmd (gdb.Command):\\n\"\n"
25546".ascii \" def __init__ (self):\\n\"\n"
25547".ascii \" super (test_cmd, self).__init__ ("
25548 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
25549".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
25550".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
25551".ascii \"test_cmd ()\\n\"\n"
25552".byte 0\n"
25553".popsection\n"
25554);
25555@end example
25556
25557Loading of inlined scripts requires a properly configured
25558@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
25559The path to specify in @code{auto-load safe-path} is the path of the file
25560containing the @code{.debug_gdb_scripts} section.
25561
71b8c845
DE
25562@node Which flavor to choose?
25563@subsection Which flavor to choose?
25564
25565Given the multiple ways of auto-loading extensions, it might not always
25566be clear which one to choose. This section provides some guidance.
25567
25568@noindent
25569Benefits of the @file{-gdb.@var{ext}} way:
25570
25571@itemize @bullet
25572@item
25573Can be used with file formats that don't support multiple sections.
25574
25575@item
25576Ease of finding scripts for public libraries.
25577
25578Scripts specified in the @code{.debug_gdb_scripts} section are searched for
25579in the source search path.
25580For publicly installed libraries, e.g., @file{libstdc++}, there typically
25581isn't a source directory in which to find the script.
25582
25583@item
25584Doesn't require source code additions.
25585@end itemize
25586
25587@noindent
25588Benefits of the @code{.debug_gdb_scripts} way:
25589
25590@itemize @bullet
25591@item
25592Works with static linking.
25593
25594Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
25595trigger their loading. When an application is statically linked the only
25596objfile available is the executable, and it is cumbersome to attach all the
25597scripts from all the input libraries to the executable's
25598@file{-gdb.@var{ext}} script.
25599
25600@item
25601Works with classes that are entirely inlined.
25602
25603Some classes can be entirely inlined, and thus there may not be an associated
25604shared library to attach a @file{-gdb.@var{ext}} script to.
25605
25606@item
25607Scripts needn't be copied out of the source tree.
25608
25609In some circumstances, apps can be built out of large collections of internal
25610libraries, and the build infrastructure necessary to install the
25611@file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
25612cumbersome. It may be easier to specify the scripts in the
25613@code{.debug_gdb_scripts} section as relative paths, and add a path to the
25614top of the source tree to the source search path.
25615@end itemize
25616
ed3ef339
DE
25617@node Multiple Extension Languages
25618@section Multiple Extension Languages
25619
25620The Guile and Python extension languages do not share any state,
25621and generally do not interfere with each other.
25622There are some things to be aware of, however.
25623
25624@subsection Python comes first
25625
25626Python was @value{GDBN}'s first extension language, and to avoid breaking
25627existing behaviour Python comes first. This is generally solved by the
25628``first one wins'' principle. @value{GDBN} maintains a list of enabled
25629extension languages, and when it makes a call to an extension language,
25630(say to pretty-print a value), it tries each in turn until an extension
25631language indicates it has performed the request (e.g., has returned the
25632pretty-printed form of a value).
25633This extends to errors while performing such requests: If an error happens
25634while, for example, trying to pretty-print an object then the error is
25635reported and any following extension languages are not tried.
25636
5a56e9c5
DE
25637@node Aliases
25638@section Creating new spellings of existing commands
25639@cindex aliases for commands
25640
25641It is often useful to define alternate spellings of existing commands.
25642For example, if a new @value{GDBN} command defined in Python has
25643a long name to type, it is handy to have an abbreviated version of it
25644that involves less typing.
25645
25646@value{GDBN} itself uses aliases. For example @samp{s} is an alias
25647of the @samp{step} command even though it is otherwise an ambiguous
25648abbreviation of other commands like @samp{set} and @samp{show}.
25649
25650Aliases are also used to provide shortened or more common versions
25651of multi-word commands. For example, @value{GDBN} provides the
25652@samp{tty} alias of the @samp{set inferior-tty} command.
25653
25654You can define a new alias with the @samp{alias} command.
25655
25656@table @code
25657
25658@kindex alias
25659@item alias [-a] [--] @var{ALIAS} = @var{COMMAND}
25660
25661@end table
25662
25663@var{ALIAS} specifies the name of the new alias.
25664Each word of @var{ALIAS} must consist of letters, numbers, dashes and
25665underscores.
25666
25667@var{COMMAND} specifies the name of an existing command
25668that is being aliased.
25669
25670The @samp{-a} option specifies that the new alias is an abbreviation
25671of the command. Abbreviations are not shown in command
25672lists displayed by the @samp{help} command.
25673
25674The @samp{--} option specifies the end of options,
25675and is useful when @var{ALIAS} begins with a dash.
25676
25677Here is a simple example showing how to make an abbreviation
25678of a command so that there is less to type.
25679Suppose you were tired of typing @samp{disas}, the current
25680shortest unambiguous abbreviation of the @samp{disassemble} command
25681and you wanted an even shorter version named @samp{di}.
25682The following will accomplish this.
25683
25684@smallexample
25685(gdb) alias -a di = disas
25686@end smallexample
25687
25688Note that aliases are different from user-defined commands.
25689With a user-defined command, you also need to write documentation
25690for it with the @samp{document} command.
25691An alias automatically picks up the documentation of the existing command.
25692
25693Here is an example where we make @samp{elms} an abbreviation of
25694@samp{elements} in the @samp{set print elements} command.
25695This is to show that you can make an abbreviation of any part
25696of a command.
25697
25698@smallexample
25699(gdb) alias -a set print elms = set print elements
25700(gdb) alias -a show print elms = show print elements
25701(gdb) set p elms 20
25702(gdb) show p elms
25703Limit on string chars or array elements to print is 200.
25704@end smallexample
25705
25706Note that if you are defining an alias of a @samp{set} command,
25707and you want to have an alias for the corresponding @samp{show}
25708command, then you need to define the latter separately.
25709
25710Unambiguously abbreviated commands are allowed in @var{COMMAND} and
25711@var{ALIAS}, just as they are normally.
25712
25713@smallexample
25714(gdb) alias -a set pr elms = set p ele
25715@end smallexample
25716
25717Finally, here is an example showing the creation of a one word
25718alias for a more complex command.
25719This creates alias @samp{spe} of the command @samp{set print elements}.
25720
25721@smallexample
25722(gdb) alias spe = set print elements
25723(gdb) spe 20
25724@end smallexample
25725
21c294e6
AC
25726@node Interpreters
25727@chapter Command Interpreters
25728@cindex command interpreters
25729
25730@value{GDBN} supports multiple command interpreters, and some command
25731infrastructure to allow users or user interface writers to switch
25732between interpreters or run commands in other interpreters.
25733
25734@value{GDBN} currently supports two command interpreters, the console
25735interpreter (sometimes called the command-line interpreter or @sc{cli})
25736and the machine interface interpreter (or @sc{gdb/mi}). This manual
25737describes both of these interfaces in great detail.
25738
25739By default, @value{GDBN} will start with the console interpreter.
25740However, the user may choose to start @value{GDBN} with another
25741interpreter by specifying the @option{-i} or @option{--interpreter}
25742startup options. Defined interpreters include:
25743
25744@table @code
25745@item console
25746@cindex console interpreter
25747The traditional console or command-line interpreter. This is the most often
25748used interpreter with @value{GDBN}. With no interpreter specified at runtime,
25749@value{GDBN} will use this interpreter.
25750
25751@item mi
25752@cindex mi interpreter
25753The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
25754by programs wishing to use @value{GDBN} as a backend for a debugger GUI
25755or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
25756Interface}.
25757
25758@item mi2
25759@cindex mi2 interpreter
25760The current @sc{gdb/mi} interface.
25761
25762@item mi1
25763@cindex mi1 interpreter
25764The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
25765
25766@end table
25767
25768@cindex invoke another interpreter
21c294e6
AC
25769
25770@kindex interpreter-exec
86f78169
PA
25771You may execute commands in any interpreter from the current
25772interpreter using the appropriate command. If you are running the
25773console interpreter, simply use the @code{interpreter-exec} command:
21c294e6
AC
25774
25775@smallexample
25776interpreter-exec mi "-data-list-register-names"
25777@end smallexample
25778
25779@sc{gdb/mi} has a similar command, although it is only available in versions of
25780@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
25781
86f78169
PA
25782Note that @code{interpreter-exec} only changes the interpreter for the
25783duration of the specified command. It does not change the interpreter
25784permanently.
25785
25786@cindex start a new independent interpreter
25787
25788Although you may only choose a single interpreter at startup, it is
25789possible to run an independent interpreter on a specified input/output
25790device (usually a tty).
25791
25792For example, consider a debugger GUI or IDE that wants to provide a
25793@value{GDBN} console view. It may do so by embedding a terminal
25794emulator widget in its GUI, starting @value{GDBN} in the traditional
25795command-line mode with stdin/stdout/stderr redirected to that
25796terminal, and then creating an MI interpreter running on a specified
25797input/output device. The console interpreter created by @value{GDBN}
25798at startup handles commands the user types in the terminal widget,
25799while the GUI controls and synchronizes state with @value{GDBN} using
25800the separate MI interpreter.
25801
25802To start a new secondary @dfn{user interface} running MI, use the
25803@code{new-ui} command:
25804
25805@kindex new-ui
25806@cindex new user interface
25807@smallexample
25808new-ui @var{interpreter} @var{tty}
25809@end smallexample
25810
25811The @var{interpreter} parameter specifies the interpreter to run.
25812This accepts the same values as the @code{interpreter-exec} command.
25813For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
25814@var{tty} parameter specifies the name of the bidirectional file the
25815interpreter uses for input/output, usually the name of a
25816pseudoterminal slave on Unix systems. For example:
25817
25818@smallexample
25819(@value{GDBP}) new-ui mi /dev/pts/9
25820@end smallexample
25821
25822@noindent
25823runs an MI interpreter on @file{/dev/pts/9}.
25824
8e04817f
AC
25825@node TUI
25826@chapter @value{GDBN} Text User Interface
25827@cindex TUI
d0d5df6f 25828@cindex Text User Interface
c906108c 25829
8e04817f
AC
25830@menu
25831* TUI Overview:: TUI overview
25832* TUI Keys:: TUI key bindings
7cf36c78 25833* TUI Single Key Mode:: TUI single key mode
db2e3e2e 25834* TUI Commands:: TUI-specific commands
8e04817f
AC
25835* TUI Configuration:: TUI configuration variables
25836@end menu
c906108c 25837
46ba6afa 25838The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
25839interface which uses the @code{curses} library to show the source
25840file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
25841commands in separate text windows. The TUI mode is supported only
25842on platforms where a suitable version of the @code{curses} library
25843is available.
d0d5df6f 25844
46ba6afa 25845The TUI mode is enabled by default when you invoke @value{GDBN} as
217bff3e 25846@samp{@value{GDBP} -tui}.
46ba6afa 25847You can also switch in and out of TUI mode while @value{GDBN} runs by
a4ea0946 25848using various TUI commands and key bindings, such as @command{tui
bcd8537c 25849enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
a4ea0946 25850@ref{TUI Keys, ,TUI Key Bindings}.
c906108c 25851
8e04817f 25852@node TUI Overview
79a6e687 25853@section TUI Overview
c906108c 25854
46ba6afa 25855In TUI mode, @value{GDBN} can display several text windows:
c906108c 25856
8e04817f
AC
25857@table @emph
25858@item command
25859This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
25860prompt and the @value{GDBN} output. The @value{GDBN} input is still
25861managed using readline.
c906108c 25862
8e04817f
AC
25863@item source
25864The source window shows the source file of the program. The current
46ba6afa 25865line and active breakpoints are displayed in this window.
c906108c 25866
8e04817f
AC
25867@item assembly
25868The assembly window shows the disassembly output of the program.
c906108c 25869
8e04817f 25870@item register
46ba6afa
BW
25871This window shows the processor registers. Registers are highlighted
25872when their values change.
c906108c
SS
25873@end table
25874
269c21fe 25875The source and assembly windows show the current program position
46ba6afa
BW
25876by highlighting the current line and marking it with a @samp{>} marker.
25877Breakpoints are indicated with two markers. The first marker
269c21fe
SC
25878indicates the breakpoint type:
25879
25880@table @code
25881@item B
25882Breakpoint which was hit at least once.
25883
25884@item b
25885Breakpoint which was never hit.
25886
25887@item H
25888Hardware breakpoint which was hit at least once.
25889
25890@item h
25891Hardware breakpoint which was never hit.
269c21fe
SC
25892@end table
25893
25894The second marker indicates whether the breakpoint is enabled or not:
25895
25896@table @code
25897@item +
25898Breakpoint is enabled.
25899
25900@item -
25901Breakpoint is disabled.
269c21fe
SC
25902@end table
25903
46ba6afa
BW
25904The source, assembly and register windows are updated when the current
25905thread changes, when the frame changes, or when the program counter
25906changes.
25907
25908These windows are not all visible at the same time. The command
25909window is always visible. The others can be arranged in several
25910layouts:
c906108c 25911
8e04817f
AC
25912@itemize @bullet
25913@item
46ba6afa 25914source only,
2df3850c 25915
8e04817f 25916@item
46ba6afa 25917assembly only,
8e04817f
AC
25918
25919@item
46ba6afa 25920source and assembly,
8e04817f
AC
25921
25922@item
46ba6afa 25923source and registers, or
c906108c 25924
8e04817f 25925@item
46ba6afa 25926assembly and registers.
8e04817f 25927@end itemize
c906108c 25928
46ba6afa 25929A status line above the command window shows the following information:
b7bb15bc
SC
25930
25931@table @emph
25932@item target
46ba6afa 25933Indicates the current @value{GDBN} target.
b7bb15bc
SC
25934(@pxref{Targets, ,Specifying a Debugging Target}).
25935
25936@item process
46ba6afa 25937Gives the current process or thread number.
b7bb15bc
SC
25938When no process is being debugged, this field is set to @code{No process}.
25939
25940@item function
25941Gives the current function name for the selected frame.
25942The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 25943When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
25944the string @code{??} is displayed.
25945
25946@item line
25947Indicates the current line number for the selected frame.
46ba6afa 25948When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
25949
25950@item pc
25951Indicates the current program counter address.
b7bb15bc
SC
25952@end table
25953
8e04817f
AC
25954@node TUI Keys
25955@section TUI Key Bindings
25956@cindex TUI key bindings
c906108c 25957
8e04817f 25958The TUI installs several key bindings in the readline keymaps
39037522
TT
25959@ifset SYSTEM_READLINE
25960(@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
25961@end ifset
25962@ifclear SYSTEM_READLINE
25963(@pxref{Command Line Editing}).
25964@end ifclear
25965The following key bindings are installed for both TUI mode and the
25966@value{GDBN} standard mode.
c906108c 25967
8e04817f
AC
25968@table @kbd
25969@kindex C-x C-a
25970@item C-x C-a
25971@kindex C-x a
25972@itemx C-x a
25973@kindex C-x A
25974@itemx C-x A
46ba6afa
BW
25975Enter or leave the TUI mode. When leaving the TUI mode,
25976the curses window management stops and @value{GDBN} operates using
25977its standard mode, writing on the terminal directly. When reentering
25978the TUI mode, control is given back to the curses windows.
8e04817f 25979The screen is then refreshed.
c906108c 25980
8e04817f
AC
25981@kindex C-x 1
25982@item C-x 1
25983Use a TUI layout with only one window. The layout will
25984either be @samp{source} or @samp{assembly}. When the TUI mode
25985is not active, it will switch to the TUI mode.
2df3850c 25986
8e04817f 25987Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 25988
8e04817f
AC
25989@kindex C-x 2
25990@item C-x 2
25991Use a TUI layout with at least two windows. When the current
46ba6afa 25992layout already has two windows, the next layout with two windows is used.
8e04817f
AC
25993When a new layout is chosen, one window will always be common to the
25994previous layout and the new one.
c906108c 25995
8e04817f 25996Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 25997
72ffddc9
SC
25998@kindex C-x o
25999@item C-x o
26000Change the active window. The TUI associates several key bindings
46ba6afa 26001(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
26002gives the focus to the next TUI window.
26003
26004Think of it as the Emacs @kbd{C-x o} binding.
26005
7cf36c78
SC
26006@kindex C-x s
26007@item C-x s
46ba6afa
BW
26008Switch in and out of the TUI SingleKey mode that binds single
26009keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c906108c
SS
26010@end table
26011
46ba6afa 26012The following key bindings only work in the TUI mode:
5d161b24 26013
46ba6afa 26014@table @asis
8e04817f 26015@kindex PgUp
46ba6afa 26016@item @key{PgUp}
8e04817f 26017Scroll the active window one page up.
c906108c 26018
8e04817f 26019@kindex PgDn
46ba6afa 26020@item @key{PgDn}
8e04817f 26021Scroll the active window one page down.
c906108c 26022
8e04817f 26023@kindex Up
46ba6afa 26024@item @key{Up}
8e04817f 26025Scroll the active window one line up.
c906108c 26026
8e04817f 26027@kindex Down
46ba6afa 26028@item @key{Down}
8e04817f 26029Scroll the active window one line down.
c906108c 26030
8e04817f 26031@kindex Left
46ba6afa 26032@item @key{Left}
8e04817f 26033Scroll the active window one column left.
c906108c 26034
8e04817f 26035@kindex Right
46ba6afa 26036@item @key{Right}
8e04817f 26037Scroll the active window one column right.
c906108c 26038
8e04817f 26039@kindex C-L
46ba6afa 26040@item @kbd{C-L}
8e04817f 26041Refresh the screen.
8e04817f 26042@end table
c906108c 26043
46ba6afa
BW
26044Because the arrow keys scroll the active window in the TUI mode, they
26045are not available for their normal use by readline unless the command
26046window has the focus. When another window is active, you must use
26047other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
26048and @kbd{C-f} to control the command window.
8e04817f 26049
7cf36c78
SC
26050@node TUI Single Key Mode
26051@section TUI Single Key Mode
26052@cindex TUI single key mode
26053
46ba6afa
BW
26054The TUI also provides a @dfn{SingleKey} mode, which binds several
26055frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
26056switch into this mode, where the following key bindings are used:
7cf36c78
SC
26057
26058@table @kbd
26059@kindex c @r{(SingleKey TUI key)}
26060@item c
26061continue
26062
26063@kindex d @r{(SingleKey TUI key)}
26064@item d
26065down
26066
26067@kindex f @r{(SingleKey TUI key)}
26068@item f
26069finish
26070
26071@kindex n @r{(SingleKey TUI key)}
26072@item n
26073next
26074
a5afdb16
RK
26075@kindex o @r{(SingleKey TUI key)}
26076@item o
26077nexti. The shortcut letter @samp{o} stands for ``step Over''.
26078
7cf36c78
SC
26079@kindex q @r{(SingleKey TUI key)}
26080@item q
46ba6afa 26081exit the SingleKey mode.
7cf36c78
SC
26082
26083@kindex r @r{(SingleKey TUI key)}
26084@item r
26085run
26086
26087@kindex s @r{(SingleKey TUI key)}
26088@item s
26089step
26090
a5afdb16
RK
26091@kindex i @r{(SingleKey TUI key)}
26092@item i
26093stepi. The shortcut letter @samp{i} stands for ``step Into''.
26094
7cf36c78
SC
26095@kindex u @r{(SingleKey TUI key)}
26096@item u
26097up
26098
26099@kindex v @r{(SingleKey TUI key)}
26100@item v
26101info locals
26102
26103@kindex w @r{(SingleKey TUI key)}
26104@item w
26105where
7cf36c78
SC
26106@end table
26107
26108Other keys temporarily switch to the @value{GDBN} command prompt.
26109The key that was pressed is inserted in the editing buffer so that
26110it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
26111with the TUI SingleKey mode. Once the command is entered the TUI
26112SingleKey mode is restored. The only way to permanently leave
7f9087cb 26113this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78
SC
26114
26115
8e04817f 26116@node TUI Commands
db2e3e2e 26117@section TUI-specific Commands
8e04817f
AC
26118@cindex TUI commands
26119
26120The TUI has specific commands to control the text windows.
46ba6afa
BW
26121These commands are always available, even when @value{GDBN} is not in
26122the TUI mode. When @value{GDBN} is in the standard mode, most
26123of these commands will automatically switch to the TUI mode.
c906108c 26124
ff12863f
PA
26125Note that if @value{GDBN}'s @code{stdout} is not connected to a
26126terminal, or @value{GDBN} has been started with the machine interface
26127interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
26128these commands will fail with an error, because it would not be
26129possible or desirable to enable curses window management.
26130
c906108c 26131@table @code
a4ea0946
AB
26132@item tui enable
26133@kindex tui enable
26134Activate TUI mode. The last active TUI window layout will be used if
26135TUI mode has prevsiouly been used in the current debugging session,
26136otherwise a default layout is used.
26137
26138@item tui disable
26139@kindex tui disable
26140Disable TUI mode, returning to the console interpreter.
26141
3d757584
SC
26142@item info win
26143@kindex info win
26144List and give the size of all displayed windows.
26145
6008fc5f 26146@item layout @var{name}
4644b6e3 26147@kindex layout
6008fc5f
AB
26148Changes which TUI windows are displayed. In each layout the command
26149window is always displayed, the @var{name} parameter controls which
26150additional windows are displayed, and can be any of the following:
26151
26152@table @code
26153@item next
8e04817f 26154Display the next layout.
2df3850c 26155
6008fc5f 26156@item prev
8e04817f 26157Display the previous layout.
c906108c 26158
6008fc5f
AB
26159@item src
26160Display the source and command windows.
c906108c 26161
6008fc5f
AB
26162@item asm
26163Display the assembly and command windows.
c906108c 26164
6008fc5f
AB
26165@item split
26166Display the source, assembly, and command windows.
c906108c 26167
6008fc5f
AB
26168@item regs
26169When in @code{src} layout display the register, source, and command
26170windows. When in @code{asm} or @code{split} layout display the
26171register, assembler, and command windows.
26172@end table
8e04817f 26173
6008fc5f 26174@item focus @var{name}
8e04817f 26175@kindex focus
6008fc5f
AB
26176Changes which TUI window is currently active for scrolling. The
26177@var{name} parameter can be any of the following:
26178
26179@table @code
26180@item next
46ba6afa
BW
26181Make the next window active for scrolling.
26182
6008fc5f 26183@item prev
46ba6afa
BW
26184Make the previous window active for scrolling.
26185
6008fc5f 26186@item src
46ba6afa
BW
26187Make the source window active for scrolling.
26188
6008fc5f 26189@item asm
46ba6afa
BW
26190Make the assembly window active for scrolling.
26191
6008fc5f 26192@item regs
46ba6afa
BW
26193Make the register window active for scrolling.
26194
6008fc5f 26195@item cmd
46ba6afa 26196Make the command window active for scrolling.
6008fc5f 26197@end table
c906108c 26198
8e04817f
AC
26199@item refresh
26200@kindex refresh
7f9087cb 26201Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 26202
51f0e40d 26203@item tui reg @var{group}
6a1b180d 26204@kindex tui reg
51f0e40d
AB
26205Changes the register group displayed in the tui register window to
26206@var{group}. If the register window is not currently displayed this
26207command will cause the register window to be displayed. The list of
26208register groups, as well as their order is target specific. The
26209following groups are available on most targets:
26210@table @code
26211@item next
26212Repeatedly selecting this group will cause the display to cycle
26213through all of the available register groups.
26214
26215@item prev
26216Repeatedly selecting this group will cause the display to cycle
26217through all of the available register groups in the reverse order to
26218@var{next}.
26219
26220@item general
26221Display the general registers.
26222@item float
26223Display the floating point registers.
26224@item system
26225Display the system registers.
26226@item vector
26227Display the vector registers.
26228@item all
26229Display all registers.
26230@end table
6a1b180d 26231
8e04817f
AC
26232@item update
26233@kindex update
26234Update the source window and the current execution point.
c906108c 26235
8e04817f
AC
26236@item winheight @var{name} +@var{count}
26237@itemx winheight @var{name} -@var{count}
26238@kindex winheight
26239Change the height of the window @var{name} by @var{count}
26240lines. Positive counts increase the height, while negative counts
bf555842
EZ
26241decrease it. The @var{name} parameter can be one of @code{src} (the
26242source window), @code{cmd} (the command window), @code{asm} (the
26243disassembly window), or @code{regs} (the register display window).
2df3850c 26244
46ba6afa
BW
26245@item tabset @var{nchars}
26246@kindex tabset
bf555842
EZ
26247Set the width of tab stops to be @var{nchars} characters. This
26248setting affects the display of TAB characters in the source and
26249assembly windows.
c906108c
SS
26250@end table
26251
8e04817f 26252@node TUI Configuration
79a6e687 26253@section TUI Configuration Variables
8e04817f 26254@cindex TUI configuration variables
c906108c 26255
46ba6afa 26256Several configuration variables control the appearance of TUI windows.
c906108c 26257
8e04817f
AC
26258@table @code
26259@item set tui border-kind @var{kind}
26260@kindex set tui border-kind
26261Select the border appearance for the source, assembly and register windows.
26262The possible values are the following:
26263@table @code
26264@item space
26265Use a space character to draw the border.
c906108c 26266
8e04817f 26267@item ascii
46ba6afa 26268Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 26269
8e04817f
AC
26270@item acs
26271Use the Alternate Character Set to draw the border. The border is
26272drawn using character line graphics if the terminal supports them.
8e04817f 26273@end table
c78b4128 26274
8e04817f
AC
26275@item set tui border-mode @var{mode}
26276@kindex set tui border-mode
46ba6afa
BW
26277@itemx set tui active-border-mode @var{mode}
26278@kindex set tui active-border-mode
26279Select the display attributes for the borders of the inactive windows
26280or the active window. The @var{mode} can be one of the following:
8e04817f
AC
26281@table @code
26282@item normal
26283Use normal attributes to display the border.
c906108c 26284
8e04817f
AC
26285@item standout
26286Use standout mode.
c906108c 26287
8e04817f
AC
26288@item reverse
26289Use reverse video mode.
c906108c 26290
8e04817f
AC
26291@item half
26292Use half bright mode.
c906108c 26293
8e04817f
AC
26294@item half-standout
26295Use half bright and standout mode.
c906108c 26296
8e04817f
AC
26297@item bold
26298Use extra bright or bold mode.
c78b4128 26299
8e04817f
AC
26300@item bold-standout
26301Use extra bright or bold and standout mode.
8e04817f 26302@end table
8e04817f 26303@end table
c78b4128 26304
8e04817f
AC
26305@node Emacs
26306@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 26307
8e04817f
AC
26308@cindex Emacs
26309@cindex @sc{gnu} Emacs
26310A special interface allows you to use @sc{gnu} Emacs to view (and
26311edit) the source files for the program you are debugging with
26312@value{GDBN}.
c906108c 26313
8e04817f
AC
26314To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
26315executable file you want to debug as an argument. This command starts
26316@value{GDBN} as a subprocess of Emacs, with input and output through a newly
26317created Emacs buffer.
26318@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 26319
5e252a2e 26320Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 26321things:
c906108c 26322
8e04817f
AC
26323@itemize @bullet
26324@item
5e252a2e
NR
26325All ``terminal'' input and output goes through an Emacs buffer, called
26326the GUD buffer.
c906108c 26327
8e04817f
AC
26328This applies both to @value{GDBN} commands and their output, and to the input
26329and output done by the program you are debugging.
bf0184be 26330
8e04817f
AC
26331This is useful because it means that you can copy the text of previous
26332commands and input them again; you can even use parts of the output
26333in this way.
bf0184be 26334
8e04817f
AC
26335All the facilities of Emacs' Shell mode are available for interacting
26336with your program. In particular, you can send signals the usual
26337way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
26338stop.
bf0184be
ND
26339
26340@item
8e04817f 26341@value{GDBN} displays source code through Emacs.
bf0184be 26342
8e04817f
AC
26343Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
26344source file for that frame and puts an arrow (@samp{=>}) at the
26345left margin of the current line. Emacs uses a separate buffer for
26346source display, and splits the screen to show both your @value{GDBN} session
26347and the source.
bf0184be 26348
8e04817f
AC
26349Explicit @value{GDBN} @code{list} or search commands still produce output as
26350usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
26351@end itemize
26352
26353We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
26354a graphical mode, enabled by default, which provides further buffers
26355that can control the execution and describe the state of your program.
26356@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 26357
64fabec2
AC
26358If you specify an absolute file name when prompted for the @kbd{M-x
26359gdb} argument, then Emacs sets your current working directory to where
26360your program resides. If you only specify the file name, then Emacs
7a9dd1b2 26361sets your current working directory to the directory associated
64fabec2
AC
26362with the previous buffer. In this case, @value{GDBN} may find your
26363program by searching your environment's @code{PATH} variable, but on
26364some operating systems it might not find the source. So, although the
26365@value{GDBN} input and output session proceeds normally, the auxiliary
26366buffer does not display the current source and line of execution.
26367
26368The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
26369line of the GUD buffer and this serves as a default for the commands
26370that specify files for @value{GDBN} to operate on. @xref{Files,
26371,Commands to Specify Files}.
64fabec2
AC
26372
26373By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
26374need to call @value{GDBN} by a different name (for example, if you
26375keep several configurations around, with different names) you can
26376customize the Emacs variable @code{gud-gdb-command-name} to run the
26377one you want.
8e04817f 26378
5e252a2e 26379In the GUD buffer, you can use these special Emacs commands in
8e04817f 26380addition to the standard Shell mode commands:
c906108c 26381
8e04817f
AC
26382@table @kbd
26383@item C-h m
5e252a2e 26384Describe the features of Emacs' GUD Mode.
c906108c 26385
64fabec2 26386@item C-c C-s
8e04817f
AC
26387Execute to another source line, like the @value{GDBN} @code{step} command; also
26388update the display window to show the current file and location.
c906108c 26389
64fabec2 26390@item C-c C-n
8e04817f
AC
26391Execute to next source line in this function, skipping all function
26392calls, like the @value{GDBN} @code{next} command. Then update the display window
26393to show the current file and location.
c906108c 26394
64fabec2 26395@item C-c C-i
8e04817f
AC
26396Execute one instruction, like the @value{GDBN} @code{stepi} command; update
26397display window accordingly.
c906108c 26398
8e04817f
AC
26399@item C-c C-f
26400Execute until exit from the selected stack frame, like the @value{GDBN}
26401@code{finish} command.
c906108c 26402
64fabec2 26403@item C-c C-r
8e04817f
AC
26404Continue execution of your program, like the @value{GDBN} @code{continue}
26405command.
b433d00b 26406
64fabec2 26407@item C-c <
8e04817f
AC
26408Go up the number of frames indicated by the numeric argument
26409(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
26410like the @value{GDBN} @code{up} command.
b433d00b 26411
64fabec2 26412@item C-c >
8e04817f
AC
26413Go down the number of frames indicated by the numeric argument, like the
26414@value{GDBN} @code{down} command.
8e04817f 26415@end table
c906108c 26416
7f9087cb 26417In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 26418tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 26419
5e252a2e
NR
26420In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
26421separate frame which shows a backtrace when the GUD buffer is current.
26422Move point to any frame in the stack and type @key{RET} to make it
26423become the current frame and display the associated source in the
26424source buffer. Alternatively, click @kbd{Mouse-2} to make the
26425selected frame become the current one. In graphical mode, the
26426speedbar displays watch expressions.
64fabec2 26427
8e04817f
AC
26428If you accidentally delete the source-display buffer, an easy way to get
26429it back is to type the command @code{f} in the @value{GDBN} buffer, to
26430request a frame display; when you run under Emacs, this recreates
26431the source buffer if necessary to show you the context of the current
26432frame.
c906108c 26433
8e04817f
AC
26434The source files displayed in Emacs are in ordinary Emacs buffers
26435which are visiting the source files in the usual way. You can edit
26436the files with these buffers if you wish; but keep in mind that @value{GDBN}
26437communicates with Emacs in terms of line numbers. If you add or
26438delete lines from the text, the line numbers that @value{GDBN} knows cease
26439to correspond properly with the code.
b383017d 26440
5e252a2e
NR
26441A more detailed description of Emacs' interaction with @value{GDBN} is
26442given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
26443Emacs Manual}).
c906108c 26444
922fbb7b
AC
26445@node GDB/MI
26446@chapter The @sc{gdb/mi} Interface
26447
26448@unnumberedsec Function and Purpose
26449
26450@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
26451@sc{gdb/mi} is a line based machine oriented text interface to
26452@value{GDBN} and is activated by specifying using the
26453@option{--interpreter} command line option (@pxref{Mode Options}). It
26454is specifically intended to support the development of systems which
26455use the debugger as just one small component of a larger system.
922fbb7b
AC
26456
26457This chapter is a specification of the @sc{gdb/mi} interface. It is written
26458in the form of a reference manual.
26459
26460Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
26461features described below are incomplete and subject to change
26462(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
26463
26464@unnumberedsec Notation and Terminology
26465
26466@cindex notational conventions, for @sc{gdb/mi}
26467This chapter uses the following notation:
26468
26469@itemize @bullet
26470@item
26471@code{|} separates two alternatives.
26472
26473@item
26474@code{[ @var{something} ]} indicates that @var{something} is optional:
26475it may or may not be given.
26476
26477@item
26478@code{( @var{group} )*} means that @var{group} inside the parentheses
26479may repeat zero or more times.
26480
26481@item
26482@code{( @var{group} )+} means that @var{group} inside the parentheses
26483may repeat one or more times.
26484
26485@item
26486@code{"@var{string}"} means a literal @var{string}.
26487@end itemize
26488
26489@ignore
26490@heading Dependencies
26491@end ignore
26492
922fbb7b 26493@menu
c3b108f7 26494* GDB/MI General Design::
922fbb7b
AC
26495* GDB/MI Command Syntax::
26496* GDB/MI Compatibility with CLI::
af6eff6f 26497* GDB/MI Development and Front Ends::
922fbb7b 26498* GDB/MI Output Records::
ef21caaf 26499* GDB/MI Simple Examples::
922fbb7b 26500* GDB/MI Command Description Format::
ef21caaf 26501* GDB/MI Breakpoint Commands::
3fa7bf06 26502* GDB/MI Catchpoint Commands::
a2c02241
NR
26503* GDB/MI Program Context::
26504* GDB/MI Thread Commands::
5d77fe44 26505* GDB/MI Ada Tasking Commands::
a2c02241
NR
26506* GDB/MI Program Execution::
26507* GDB/MI Stack Manipulation::
26508* GDB/MI Variable Objects::
922fbb7b 26509* GDB/MI Data Manipulation::
a2c02241
NR
26510* GDB/MI Tracepoint Commands::
26511* GDB/MI Symbol Query::
351ff01a 26512* GDB/MI File Commands::
922fbb7b
AC
26513@ignore
26514* GDB/MI Kod Commands::
26515* GDB/MI Memory Overlay Commands::
26516* GDB/MI Signal Handling Commands::
26517@end ignore
922fbb7b 26518* GDB/MI Target Manipulation::
a6b151f1 26519* GDB/MI File Transfer Commands::
58d06528 26520* GDB/MI Ada Exceptions Commands::
d192b373 26521* GDB/MI Support Commands::
ef21caaf 26522* GDB/MI Miscellaneous Commands::
922fbb7b
AC
26523@end menu
26524
c3b108f7
VP
26525@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26526@node GDB/MI General Design
26527@section @sc{gdb/mi} General Design
26528@cindex GDB/MI General Design
26529
26530Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
26531parts---commands sent to @value{GDBN}, responses to those commands
26532and notifications. Each command results in exactly one response,
26533indicating either successful completion of the command, or an error.
26534For the commands that do not resume the target, the response contains the
26535requested information. For the commands that resume the target, the
26536response only indicates whether the target was successfully resumed.
26537Notifications is the mechanism for reporting changes in the state of the
26538target, or in @value{GDBN} state, that cannot conveniently be associated with
26539a command and reported as part of that command response.
26540
26541The important examples of notifications are:
26542@itemize @bullet
26543
26544@item
26545Exec notifications. These are used to report changes in
26546target state---when a target is resumed, or stopped. It would not
26547be feasible to include this information in response of resuming
26548commands, because one resume commands can result in multiple events in
26549different threads. Also, quite some time may pass before any event
26550happens in the target, while a frontend needs to know whether the resuming
26551command itself was successfully executed.
26552
26553@item
26554Console output, and status notifications. Console output
26555notifications are used to report output of CLI commands, as well as
26556diagnostics for other commands. Status notifications are used to
26557report the progress of a long-running operation. Naturally, including
26558this information in command response would mean no output is produced
26559until the command is finished, which is undesirable.
26560
26561@item
26562General notifications. Commands may have various side effects on
26563the @value{GDBN} or target state beyond their official purpose. For example,
26564a command may change the selected thread. Although such changes can
26565be included in command response, using notification allows for more
26566orthogonal frontend design.
26567
26568@end itemize
26569
26570There's no guarantee that whenever an MI command reports an error,
26571@value{GDBN} or the target are in any specific state, and especially,
26572the state is not reverted to the state before the MI command was
26573processed. Therefore, whenever an MI command results in an error,
26574we recommend that the frontend refreshes all the information shown in
26575the user interface.
26576
508094de
NR
26577
26578@menu
26579* Context management::
26580* Asynchronous and non-stop modes::
26581* Thread groups::
26582@end menu
26583
26584@node Context management
c3b108f7
VP
26585@subsection Context management
26586
403cb6b1
JB
26587@subsubsection Threads and Frames
26588
c3b108f7
VP
26589In most cases when @value{GDBN} accesses the target, this access is
26590done in context of a specific thread and frame (@pxref{Frames}).
26591Often, even when accessing global data, the target requires that a thread
26592be specified. The CLI interface maintains the selected thread and frame,
26593and supplies them to target on each command. This is convenient,
26594because a command line user would not want to specify that information
26595explicitly on each command, and because user interacts with
26596@value{GDBN} via a single terminal, so no confusion is possible as
26597to what thread and frame are the current ones.
26598
26599In the case of MI, the concept of selected thread and frame is less
26600useful. First, a frontend can easily remember this information
26601itself. Second, a graphical frontend can have more than one window,
26602each one used for debugging a different thread, and the frontend might
26603want to access additional threads for internal purposes. This
26604increases the risk that by relying on implicitly selected thread, the
26605frontend may be operating on a wrong one. Therefore, each MI command
26606should explicitly specify which thread and frame to operate on. To
26607make it possible, each MI command accepts the @samp{--thread} and
5d5658a1
PA
26608@samp{--frame} options, the value to each is @value{GDBN} global
26609identifier for thread and frame to operate on.
c3b108f7
VP
26610
26611Usually, each top-level window in a frontend allows the user to select
26612a thread and a frame, and remembers the user selection for further
26613operations. However, in some cases @value{GDBN} may suggest that the
4034d0ff
AT
26614current thread or frame be changed. For example, when stopping on a
26615breakpoint it is reasonable to switch to the thread where breakpoint is
26616hit. For another example, if the user issues the CLI @samp{thread} or
26617@samp{frame} commands via the frontend, it is desirable to change the
26618frontend's selection to the one specified by user. @value{GDBN}
26619communicates the suggestion to change current thread and frame using the
26620@samp{=thread-selected} notification.
c3b108f7
VP
26621
26622Note that historically, MI shares the selected thread with CLI, so
26623frontends used the @code{-thread-select} to execute commands in the
26624right context. However, getting this to work right is cumbersome. The
26625simplest way is for frontend to emit @code{-thread-select} command
26626before every command. This doubles the number of commands that need
26627to be sent. The alternative approach is to suppress @code{-thread-select}
26628if the selected thread in @value{GDBN} is supposed to be identical to the
26629thread the frontend wants to operate on. However, getting this
26630optimization right can be tricky. In particular, if the frontend
26631sends several commands to @value{GDBN}, and one of the commands changes the
26632selected thread, then the behaviour of subsequent commands will
26633change. So, a frontend should either wait for response from such
26634problematic commands, or explicitly add @code{-thread-select} for
26635all subsequent commands. No frontend is known to do this exactly
26636right, so it is suggested to just always pass the @samp{--thread} and
26637@samp{--frame} options.
26638
403cb6b1
JB
26639@subsubsection Language
26640
26641The execution of several commands depends on which language is selected.
26642By default, the current language (@pxref{show language}) is used.
26643But for commands known to be language-sensitive, it is recommended
26644to use the @samp{--language} option. This option takes one argument,
26645which is the name of the language to use while executing the command.
26646For instance:
26647
26648@smallexample
26649-data-evaluate-expression --language c "sizeof (void*)"
26650^done,value="4"
26651(gdb)
26652@end smallexample
26653
26654The valid language names are the same names accepted by the
26655@samp{set language} command (@pxref{Manually}), excluding @samp{auto},
26656@samp{local} or @samp{unknown}.
26657
508094de 26658@node Asynchronous and non-stop modes
c3b108f7
VP
26659@subsection Asynchronous command execution and non-stop mode
26660
26661On some targets, @value{GDBN} is capable of processing MI commands
26662even while the target is running. This is called @dfn{asynchronous
26663command execution} (@pxref{Background Execution}). The frontend may
26664specify a preferrence for asynchronous execution using the
329ea579 26665@code{-gdb-set mi-async 1} command, which should be emitted before
c3b108f7
VP
26666either running the executable or attaching to the target. After the
26667frontend has started the executable or attached to the target, it can
26668find if asynchronous execution is enabled using the
26669@code{-list-target-features} command.
26670
329ea579
PA
26671@table @code
26672@item -gdb-set mi-async on
26673@item -gdb-set mi-async off
26674Set whether MI is in asynchronous mode.
26675
26676When @code{off}, which is the default, MI execution commands (e.g.,
26677@code{-exec-continue}) are foreground commands, and @value{GDBN} waits
26678for the program to stop before processing further commands.
26679
26680When @code{on}, MI execution commands are background execution
26681commands (e.g., @code{-exec-continue} becomes the equivalent of the
26682@code{c&} CLI command), and so @value{GDBN} is capable of processing
26683MI commands even while the target is running.
26684
26685@item -gdb-show mi-async
26686Show whether MI asynchronous mode is enabled.
26687@end table
26688
26689Note: In @value{GDBN} version 7.7 and earlier, this option was called
26690@code{target-async} instead of @code{mi-async}, and it had the effect
26691of both putting MI in asynchronous mode and making CLI background
26692commands possible. CLI background commands are now always possible
26693``out of the box'' if the target supports them. The old spelling is
26694kept as a deprecated alias for backwards compatibility.
26695
c3b108f7
VP
26696Even if @value{GDBN} can accept a command while target is running,
26697many commands that access the target do not work when the target is
26698running. Therefore, asynchronous command execution is most useful
26699when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
26700it is possible to examine the state of one thread, while other threads
26701are running.
26702
26703When a given thread is running, MI commands that try to access the
26704target in the context of that thread may not work, or may work only on
26705some targets. In particular, commands that try to operate on thread's
26706stack will not work, on any target. Commands that read memory, or
26707modify breakpoints, may work or not work, depending on the target. Note
26708that even commands that operate on global state, such as @code{print},
26709@code{set}, and breakpoint commands, still access the target in the
26710context of a specific thread, so frontend should try to find a
26711stopped thread and perform the operation on that thread (using the
26712@samp{--thread} option).
26713
26714Which commands will work in the context of a running thread is
26715highly target dependent. However, the two commands
26716@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
26717to find the state of a thread, will always work.
26718
508094de 26719@node Thread groups
c3b108f7
VP
26720@subsection Thread groups
26721@value{GDBN} may be used to debug several processes at the same time.
26722On some platfroms, @value{GDBN} may support debugging of several
26723hardware systems, each one having several cores with several different
26724processes running on each core. This section describes the MI
26725mechanism to support such debugging scenarios.
26726
26727The key observation is that regardless of the structure of the
26728target, MI can have a global list of threads, because most commands that
26729accept the @samp{--thread} option do not need to know what process that
26730thread belongs to. Therefore, it is not necessary to introduce
26731neither additional @samp{--process} option, nor an notion of the
26732current process in the MI interface. The only strictly new feature
26733that is required is the ability to find how the threads are grouped
26734into processes.
26735
26736To allow the user to discover such grouping, and to support arbitrary
26737hierarchy of machines/cores/processes, MI introduces the concept of a
26738@dfn{thread group}. Thread group is a collection of threads and other
26739thread groups. A thread group always has a string identifier, a type,
26740and may have additional attributes specific to the type. A new
26741command, @code{-list-thread-groups}, returns the list of top-level
26742thread groups, which correspond to processes that @value{GDBN} is
26743debugging at the moment. By passing an identifier of a thread group
26744to the @code{-list-thread-groups} command, it is possible to obtain
26745the members of specific thread group.
26746
26747To allow the user to easily discover processes, and other objects, he
26748wishes to debug, a concept of @dfn{available thread group} is
26749introduced. Available thread group is an thread group that
26750@value{GDBN} is not debugging, but that can be attached to, using the
26751@code{-target-attach} command. The list of available top-level thread
26752groups can be obtained using @samp{-list-thread-groups --available}.
26753In general, the content of a thread group may be only retrieved only
26754after attaching to that thread group.
26755
a79b8f6e
VP
26756Thread groups are related to inferiors (@pxref{Inferiors and
26757Programs}). Each inferior corresponds to a thread group of a special
26758type @samp{process}, and some additional operations are permitted on
26759such thread groups.
26760
922fbb7b
AC
26761@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26762@node GDB/MI Command Syntax
26763@section @sc{gdb/mi} Command Syntax
26764
26765@menu
26766* GDB/MI Input Syntax::
26767* GDB/MI Output Syntax::
922fbb7b
AC
26768@end menu
26769
26770@node GDB/MI Input Syntax
26771@subsection @sc{gdb/mi} Input Syntax
26772
26773@cindex input syntax for @sc{gdb/mi}
26774@cindex @sc{gdb/mi}, input syntax
26775@table @code
26776@item @var{command} @expansion{}
26777@code{@var{cli-command} | @var{mi-command}}
26778
26779@item @var{cli-command} @expansion{}
26780@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
26781@var{cli-command} is any existing @value{GDBN} CLI command.
26782
26783@item @var{mi-command} @expansion{}
26784@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
26785@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
26786
26787@item @var{token} @expansion{}
26788"any sequence of digits"
26789
26790@item @var{option} @expansion{}
26791@code{"-" @var{parameter} [ " " @var{parameter} ]}
26792
26793@item @var{parameter} @expansion{}
26794@code{@var{non-blank-sequence} | @var{c-string}}
26795
26796@item @var{operation} @expansion{}
26797@emph{any of the operations described in this chapter}
26798
26799@item @var{non-blank-sequence} @expansion{}
26800@emph{anything, provided it doesn't contain special characters such as
26801"-", @var{nl}, """ and of course " "}
26802
26803@item @var{c-string} @expansion{}
26804@code{""" @var{seven-bit-iso-c-string-content} """}
26805
26806@item @var{nl} @expansion{}
26807@code{CR | CR-LF}
26808@end table
26809
26810@noindent
26811Notes:
26812
26813@itemize @bullet
26814@item
26815The CLI commands are still handled by the @sc{mi} interpreter; their
26816output is described below.
26817
26818@item
26819The @code{@var{token}}, when present, is passed back when the command
26820finishes.
26821
26822@item
26823Some @sc{mi} commands accept optional arguments as part of the parameter
26824list. Each option is identified by a leading @samp{-} (dash) and may be
26825followed by an optional argument parameter. Options occur first in the
26826parameter list and can be delimited from normal parameters using
26827@samp{--} (this is useful when some parameters begin with a dash).
26828@end itemize
26829
26830Pragmatics:
26831
26832@itemize @bullet
26833@item
26834We want easy access to the existing CLI syntax (for debugging).
26835
26836@item
26837We want it to be easy to spot a @sc{mi} operation.
26838@end itemize
26839
26840@node GDB/MI Output Syntax
26841@subsection @sc{gdb/mi} Output Syntax
26842
26843@cindex output syntax of @sc{gdb/mi}
26844@cindex @sc{gdb/mi}, output syntax
26845The output from @sc{gdb/mi} consists of zero or more out-of-band records
26846followed, optionally, by a single result record. This result record
26847is for the most recent command. The sequence of output records is
594fe323 26848terminated by @samp{(gdb)}.
922fbb7b
AC
26849
26850If an input command was prefixed with a @code{@var{token}} then the
26851corresponding output for that command will also be prefixed by that same
26852@var{token}.
26853
26854@table @code
26855@item @var{output} @expansion{}
594fe323 26856@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
26857
26858@item @var{result-record} @expansion{}
26859@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
26860
26861@item @var{out-of-band-record} @expansion{}
26862@code{@var{async-record} | @var{stream-record}}
26863
26864@item @var{async-record} @expansion{}
26865@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
26866
26867@item @var{exec-async-output} @expansion{}
dcf106f3 26868@code{[ @var{token} ] "*" @var{async-output nl}}
922fbb7b
AC
26869
26870@item @var{status-async-output} @expansion{}
dcf106f3 26871@code{[ @var{token} ] "+" @var{async-output nl}}
922fbb7b
AC
26872
26873@item @var{notify-async-output} @expansion{}
dcf106f3 26874@code{[ @var{token} ] "=" @var{async-output nl}}
922fbb7b
AC
26875
26876@item @var{async-output} @expansion{}
dcf106f3 26877@code{@var{async-class} ( "," @var{result} )*}
922fbb7b
AC
26878
26879@item @var{result-class} @expansion{}
26880@code{"done" | "running" | "connected" | "error" | "exit"}
26881
26882@item @var{async-class} @expansion{}
26883@code{"stopped" | @var{others}} (where @var{others} will be added
26884depending on the needs---this is still in development).
26885
26886@item @var{result} @expansion{}
26887@code{ @var{variable} "=" @var{value}}
26888
26889@item @var{variable} @expansion{}
26890@code{ @var{string} }
26891
26892@item @var{value} @expansion{}
26893@code{ @var{const} | @var{tuple} | @var{list} }
26894
26895@item @var{const} @expansion{}
26896@code{@var{c-string}}
26897
26898@item @var{tuple} @expansion{}
26899@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
26900
26901@item @var{list} @expansion{}
26902@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
26903@var{result} ( "," @var{result} )* "]" }
26904
26905@item @var{stream-record} @expansion{}
26906@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
26907
26908@item @var{console-stream-output} @expansion{}
dcf106f3 26909@code{"~" @var{c-string nl}}
922fbb7b
AC
26910
26911@item @var{target-stream-output} @expansion{}
dcf106f3 26912@code{"@@" @var{c-string nl}}
922fbb7b
AC
26913
26914@item @var{log-stream-output} @expansion{}
dcf106f3 26915@code{"&" @var{c-string nl}}
922fbb7b
AC
26916
26917@item @var{nl} @expansion{}
26918@code{CR | CR-LF}
26919
26920@item @var{token} @expansion{}
26921@emph{any sequence of digits}.
26922@end table
26923
26924@noindent
26925Notes:
26926
26927@itemize @bullet
26928@item
26929All output sequences end in a single line containing a period.
26930
26931@item
721c02de
VP
26932The @code{@var{token}} is from the corresponding request. Note that
26933for all async output, while the token is allowed by the grammar and
26934may be output by future versions of @value{GDBN} for select async
26935output messages, it is generally omitted. Frontends should treat
26936all async output as reporting general changes in the state of the
26937target and there should be no need to associate async output to any
26938prior command.
922fbb7b
AC
26939
26940@item
26941@cindex status output in @sc{gdb/mi}
26942@var{status-async-output} contains on-going status information about the
26943progress of a slow operation. It can be discarded. All status output is
26944prefixed by @samp{+}.
26945
26946@item
26947@cindex async output in @sc{gdb/mi}
26948@var{exec-async-output} contains asynchronous state change on the target
26949(stopped, started, disappeared). All async output is prefixed by
26950@samp{*}.
26951
26952@item
26953@cindex notify output in @sc{gdb/mi}
26954@var{notify-async-output} contains supplementary information that the
26955client should handle (e.g., a new breakpoint information). All notify
26956output is prefixed by @samp{=}.
26957
26958@item
26959@cindex console output in @sc{gdb/mi}
26960@var{console-stream-output} is output that should be displayed as is in the
26961console. It is the textual response to a CLI command. All the console
26962output is prefixed by @samp{~}.
26963
26964@item
26965@cindex target output in @sc{gdb/mi}
26966@var{target-stream-output} is the output produced by the target program.
26967All the target output is prefixed by @samp{@@}.
26968
26969@item
26970@cindex log output in @sc{gdb/mi}
26971@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
26972instance messages that should be displayed as part of an error log. All
26973the log output is prefixed by @samp{&}.
26974
26975@item
26976@cindex list output in @sc{gdb/mi}
26977New @sc{gdb/mi} commands should only output @var{lists} containing
26978@var{values}.
26979
26980
26981@end itemize
26982
26983@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
26984details about the various output records.
26985
922fbb7b
AC
26986@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26987@node GDB/MI Compatibility with CLI
26988@section @sc{gdb/mi} Compatibility with CLI
26989
26990@cindex compatibility, @sc{gdb/mi} and CLI
26991@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 26992
a2c02241
NR
26993For the developers convenience CLI commands can be entered directly,
26994but there may be some unexpected behaviour. For example, commands
26995that query the user will behave as if the user replied yes, breakpoint
26996command lists are not executed and some CLI commands, such as
26997@code{if}, @code{when} and @code{define}, prompt for further input with
26998@samp{>}, which is not valid MI output.
ef21caaf
NR
26999
27000This feature may be removed at some stage in the future and it is
a2c02241
NR
27001recommended that front ends use the @code{-interpreter-exec} command
27002(@pxref{-interpreter-exec}).
922fbb7b 27003
af6eff6f
NR
27004@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27005@node GDB/MI Development and Front Ends
27006@section @sc{gdb/mi} Development and Front Ends
27007@cindex @sc{gdb/mi} development
27008
27009The application which takes the MI output and presents the state of the
27010program being debugged to the user is called a @dfn{front end}.
27011
27012Although @sc{gdb/mi} is still incomplete, it is currently being used
27013by a variety of front ends to @value{GDBN}. This makes it difficult
27014to introduce new functionality without breaking existing usage. This
27015section tries to minimize the problems by describing how the protocol
27016might change.
27017
27018Some changes in MI need not break a carefully designed front end, and
27019for these the MI version will remain unchanged. The following is a
27020list of changes that may occur within one level, so front ends should
27021parse MI output in a way that can handle them:
27022
27023@itemize @bullet
27024@item
27025New MI commands may be added.
27026
27027@item
27028New fields may be added to the output of any MI command.
27029
36ece8b3
NR
27030@item
27031The range of values for fields with specified values, e.g.,
9f708cb2 27032@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 27033
af6eff6f
NR
27034@c The format of field's content e.g type prefix, may change so parse it
27035@c at your own risk. Yes, in general?
27036
27037@c The order of fields may change? Shouldn't really matter but it might
27038@c resolve inconsistencies.
27039@end itemize
27040
27041If the changes are likely to break front ends, the MI version level
27042will be increased by one. This will allow the front end to parse the
27043output according to the MI version. Apart from mi0, new versions of
27044@value{GDBN} will not support old versions of MI and it will be the
27045responsibility of the front end to work with the new one.
27046
27047@c Starting with mi3, add a new command -mi-version that prints the MI
27048@c version?
27049
27050The best way to avoid unexpected changes in MI that might break your front
27051end is to make your project known to @value{GDBN} developers and
7a9a6b69 27052follow development on @email{gdb@@sourceware.org} and
fa0f268d 27053@email{gdb-patches@@sourceware.org}.
af6eff6f
NR
27054@cindex mailing lists
27055
922fbb7b
AC
27056@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27057@node GDB/MI Output Records
27058@section @sc{gdb/mi} Output Records
27059
27060@menu
27061* GDB/MI Result Records::
27062* GDB/MI Stream Records::
82f68b1c 27063* GDB/MI Async Records::
54516a0b 27064* GDB/MI Breakpoint Information::
c3b108f7 27065* GDB/MI Frame Information::
dc146f7c 27066* GDB/MI Thread Information::
4368ebeb 27067* GDB/MI Ada Exception Information::
922fbb7b
AC
27068@end menu
27069
27070@node GDB/MI Result Records
27071@subsection @sc{gdb/mi} Result Records
27072
27073@cindex result records in @sc{gdb/mi}
27074@cindex @sc{gdb/mi}, result records
27075In addition to a number of out-of-band notifications, the response to a
27076@sc{gdb/mi} command includes one of the following result indications:
27077
27078@table @code
27079@findex ^done
27080@item "^done" [ "," @var{results} ]
27081The synchronous operation was successful, @code{@var{results}} are the return
27082values.
27083
27084@item "^running"
27085@findex ^running
8e9c5e02
VP
27086This result record is equivalent to @samp{^done}. Historically, it
27087was output instead of @samp{^done} if the command has resumed the
27088target. This behaviour is maintained for backward compatibility, but
27089all frontends should treat @samp{^done} and @samp{^running}
27090identically and rely on the @samp{*running} output record to determine
27091which threads are resumed.
922fbb7b 27092
ef21caaf
NR
27093@item "^connected"
27094@findex ^connected
3f94c067 27095@value{GDBN} has connected to a remote target.
ef21caaf 27096
2ea126fa 27097@item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
922fbb7b 27098@findex ^error
2ea126fa
JB
27099The operation failed. The @code{msg=@var{c-string}} variable contains
27100the corresponding error message.
27101
27102If present, the @code{code=@var{c-string}} variable provides an error
27103code on which consumers can rely on to detect the corresponding
27104error condition. At present, only one error code is defined:
27105
27106@table @samp
27107@item "undefined-command"
27108Indicates that the command causing the error does not exist.
27109@end table
ef21caaf
NR
27110
27111@item "^exit"
27112@findex ^exit
3f94c067 27113@value{GDBN} has terminated.
ef21caaf 27114
922fbb7b
AC
27115@end table
27116
27117@node GDB/MI Stream Records
27118@subsection @sc{gdb/mi} Stream Records
27119
27120@cindex @sc{gdb/mi}, stream records
27121@cindex stream records in @sc{gdb/mi}
27122@value{GDBN} internally maintains a number of output streams: the console, the
27123target, and the log. The output intended for each of these streams is
27124funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
27125
27126Each stream record begins with a unique @dfn{prefix character} which
27127identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
27128Syntax}). In addition to the prefix, each stream record contains a
27129@code{@var{string-output}}. This is either raw text (with an implicit new
27130line) or a quoted C string (which does not contain an implicit newline).
27131
27132@table @code
27133@item "~" @var{string-output}
27134The console output stream contains text that should be displayed in the
27135CLI console window. It contains the textual responses to CLI commands.
27136
27137@item "@@" @var{string-output}
27138The target output stream contains any textual output from the running
ef21caaf
NR
27139target. This is only present when GDB's event loop is truly
27140asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
27141
27142@item "&" @var{string-output}
27143The log stream contains debugging messages being produced by @value{GDBN}'s
27144internals.
27145@end table
27146
82f68b1c
VP
27147@node GDB/MI Async Records
27148@subsection @sc{gdb/mi} Async Records
922fbb7b 27149
82f68b1c
VP
27150@cindex async records in @sc{gdb/mi}
27151@cindex @sc{gdb/mi}, async records
27152@dfn{Async} records are used to notify the @sc{gdb/mi} client of
922fbb7b 27153additional changes that have occurred. Those changes can either be a
82f68b1c 27154consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
922fbb7b
AC
27155target activity (e.g., target stopped).
27156
8eb41542 27157The following is the list of possible async records:
922fbb7b
AC
27158
27159@table @code
034dad6f 27160
e1ac3328 27161@item *running,thread-id="@var{thread}"
5d5658a1
PA
27162The target is now running. The @var{thread} field can be the global
27163thread ID of the the thread that is now running, and it can be
27164@samp{all} if all threads are running. The frontend should assume
27165that no interaction with a running thread is possible after this
27166notification is produced. The frontend should not assume that this
27167notification is output only once for any command. @value{GDBN} may
27168emit this notification several times, either for different threads,
27169because it cannot resume all threads together, or even for a single
27170thread, if the thread must be stepped though some code before letting
27171it run freely.
e1ac3328 27172
dc146f7c 27173@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
82f68b1c
VP
27174The target has stopped. The @var{reason} field can have one of the
27175following values:
034dad6f
BR
27176
27177@table @code
27178@item breakpoint-hit
27179A breakpoint was reached.
27180@item watchpoint-trigger
27181A watchpoint was triggered.
27182@item read-watchpoint-trigger
27183A read watchpoint was triggered.
27184@item access-watchpoint-trigger
27185An access watchpoint was triggered.
27186@item function-finished
27187An -exec-finish or similar CLI command was accomplished.
27188@item location-reached
27189An -exec-until or similar CLI command was accomplished.
27190@item watchpoint-scope
27191A watchpoint has gone out of scope.
27192@item end-stepping-range
27193An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
27194similar CLI command was accomplished.
27195@item exited-signalled
27196The inferior exited because of a signal.
27197@item exited
27198The inferior exited.
27199@item exited-normally
27200The inferior exited normally.
27201@item signal-received
27202A signal was received by the inferior.
36dfb11c
TT
27203@item solib-event
27204The inferior has stopped due to a library being loaded or unloaded.
edcc5120
TT
27205This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
27206set or when a @code{catch load} or @code{catch unload} catchpoint is
27207in use (@pxref{Set Catchpoints}).
36dfb11c
TT
27208@item fork
27209The inferior has forked. This is reported when @code{catch fork}
27210(@pxref{Set Catchpoints}) has been used.
27211@item vfork
27212The inferior has vforked. This is reported in when @code{catch vfork}
27213(@pxref{Set Catchpoints}) has been used.
27214@item syscall-entry
27215The inferior entered a system call. This is reported when @code{catch
27216syscall} (@pxref{Set Catchpoints}) has been used.
a64c9f7b 27217@item syscall-return
36dfb11c
TT
27218The inferior returned from a system call. This is reported when
27219@code{catch syscall} (@pxref{Set Catchpoints}) has been used.
27220@item exec
27221The inferior called @code{exec}. This is reported when @code{catch exec}
27222(@pxref{Set Catchpoints}) has been used.
922fbb7b
AC
27223@end table
27224
5d5658a1
PA
27225The @var{id} field identifies the global thread ID of the thread
27226that directly caused the stop -- for example by hitting a breakpoint.
27227Depending on whether all-stop
c3b108f7
VP
27228mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
27229stop all threads, or only the thread that directly triggered the stop.
27230If all threads are stopped, the @var{stopped} field will have the
27231value of @code{"all"}. Otherwise, the value of the @var{stopped}
27232field will be a list of thread identifiers. Presently, this list will
27233always include a single thread, but frontend should be prepared to see
dc146f7c
VP
27234several threads in the list. The @var{core} field reports the
27235processor core on which the stop event has happened. This field may be absent
27236if such information is not available.
c3b108f7 27237
a79b8f6e
VP
27238@item =thread-group-added,id="@var{id}"
27239@itemx =thread-group-removed,id="@var{id}"
27240A thread group was either added or removed. The @var{id} field
27241contains the @value{GDBN} identifier of the thread group. When a thread
27242group is added, it generally might not be associated with a running
27243process. When a thread group is removed, its id becomes invalid and
27244cannot be used in any way.
27245
27246@item =thread-group-started,id="@var{id}",pid="@var{pid}"
27247A thread group became associated with a running program,
27248either because the program was just started or the thread group
27249was attached to a program. The @var{id} field contains the
27250@value{GDBN} identifier of the thread group. The @var{pid} field
27251contains process identifier, specific to the operating system.
27252
8cf64490 27253@item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
a79b8f6e
VP
27254A thread group is no longer associated with a running program,
27255either because the program has exited, or because it was detached
c3b108f7 27256from. The @var{id} field contains the @value{GDBN} identifier of the
697aa1b7 27257thread group. The @var{code} field is the exit code of the inferior; it exists
8cf64490 27258only when the inferior exited with some code.
c3b108f7
VP
27259
27260@item =thread-created,id="@var{id}",group-id="@var{gid}"
27261@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
82f68b1c 27262A thread either was created, or has exited. The @var{id} field
5d5658a1 27263contains the global @value{GDBN} identifier of the thread. The @var{gid}
c3b108f7 27264field identifies the thread group this thread belongs to.
66bb093b 27265
4034d0ff
AT
27266@item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
27267Informs that the selected thread or frame were changed. This notification
27268is not emitted as result of the @code{-thread-select} or
27269@code{-stack-select-frame} commands, but is emitted whenever an MI command
27270that is not documented to change the selected thread and frame actually
27271changes them. In particular, invoking, directly or indirectly
27272(via user-defined command), the CLI @code{thread} or @code{frame} commands,
27273will generate this notification. Changing the thread or frame from another
27274user interface (see @ref{Interpreters}) will also generate this notification.
27275
27276The @var{frame} field is only present if the newly selected thread is
27277stopped. See @ref{GDB/MI Frame Information} for the format of its value.
66bb093b
VP
27278
27279We suggest that in response to this notification, front ends
27280highlight the selected thread and cause subsequent commands to apply to
27281that thread.
27282
c86cf029
VP
27283@item =library-loaded,...
27284Reports that a new library file was loaded by the program. This
51457a05
MAL
27285notification has 5 fields---@var{id}, @var{target-name},
27286@var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
c86cf029
VP
27287opaque identifier of the library. For remote debugging case,
27288@var{target-name} and @var{host-name} fields give the name of the
134eb42c
VP
27289library file on the target, and on the host respectively. For native
27290debugging, both those fields have the same value. The
f1cbe1d3
TT
27291@var{symbols-loaded} field is emitted only for backward compatibility
27292and should not be relied on to convey any useful information. The
27293@var{thread-group} field, if present, specifies the id of the thread
27294group in whose context the library was loaded. If the field is
27295absent, it means the library was loaded in the context of all present
51457a05
MAL
27296thread groups. The @var{ranges} field specifies the ranges of addresses belonging
27297to this library.
c86cf029
VP
27298
27299@item =library-unloaded,...
134eb42c 27300Reports that a library was unloaded by the program. This notification
c86cf029 27301has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
a79b8f6e
VP
27302the same meaning as for the @code{=library-loaded} notification.
27303The @var{thread-group} field, if present, specifies the id of the
27304thread group in whose context the library was unloaded. If the field is
27305absent, it means the library was unloaded in the context of all present
27306thread groups.
c86cf029 27307
201b4506
YQ
27308@item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
27309@itemx =traceframe-changed,end
27310Reports that the trace frame was changed and its new number is
27311@var{tfnum}. The number of the tracepoint associated with this trace
27312frame is @var{tpnum}.
27313
134a2066 27314@item =tsv-created,name=@var{name},initial=@var{initial}
bb25a15c 27315Reports that the new trace state variable @var{name} is created with
134a2066 27316initial value @var{initial}.
bb25a15c
YQ
27317
27318@item =tsv-deleted,name=@var{name}
27319@itemx =tsv-deleted
27320Reports that the trace state variable @var{name} is deleted or all
27321trace state variables are deleted.
27322
134a2066
YQ
27323@item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
27324Reports that the trace state variable @var{name} is modified with
27325the initial value @var{initial}. The current value @var{current} of
27326trace state variable is optional and is reported if the current
27327value of trace state variable is known.
27328
8d3788bd
VP
27329@item =breakpoint-created,bkpt=@{...@}
27330@itemx =breakpoint-modified,bkpt=@{...@}
d9f08f52 27331@itemx =breakpoint-deleted,id=@var{number}
8d3788bd
VP
27332Reports that a breakpoint was created, modified, or deleted,
27333respectively. Only user-visible breakpoints are reported to the MI
27334user.
27335
27336The @var{bkpt} argument is of the same form as returned by the various
d9f08f52
YQ
27337breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
27338@var{number} is the ordinal number of the breakpoint.
8d3788bd
VP
27339
27340Note that if a breakpoint is emitted in the result record of a
27341command, then it will not also be emitted in an async record.
27342
38b022b4 27343@item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
82a90ccf
YQ
27344@itemx =record-stopped,thread-group="@var{id}"
27345Execution log recording was either started or stopped on an
27346inferior. The @var{id} is the @value{GDBN} identifier of the thread
27347group corresponding to the affected inferior.
27348
38b022b4
SM
27349The @var{method} field indicates the method used to record execution. If the
27350method in use supports multiple recording formats, @var{format} will be present
8504e097 27351and contain the currently used format. @xref{Process Record and Replay},
38b022b4
SM
27352for existing method and format values.
27353
5b9afe8a
YQ
27354@item =cmd-param-changed,param=@var{param},value=@var{value}
27355Reports that a parameter of the command @code{set @var{param}} is
27356changed to @var{value}. In the multi-word @code{set} command,
27357the @var{param} is the whole parameter list to @code{set} command.
27358For example, In command @code{set check type on}, @var{param}
27359is @code{check type} and @var{value} is @code{on}.
8de0566d
YQ
27360
27361@item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
27362Reports that bytes from @var{addr} to @var{data} + @var{len} were
27363written in an inferior. The @var{id} is the identifier of the
27364thread group corresponding to the affected inferior. The optional
27365@code{type="code"} part is reported if the memory written to holds
27366executable code.
82f68b1c
VP
27367@end table
27368
54516a0b
TT
27369@node GDB/MI Breakpoint Information
27370@subsection @sc{gdb/mi} Breakpoint Information
27371
27372When @value{GDBN} reports information about a breakpoint, a
27373tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
27374following fields:
27375
27376@table @code
27377@item number
27378The breakpoint number. For a breakpoint that represents one location
27379of a multi-location breakpoint, this will be a dotted pair, like
27380@samp{1.2}.
27381
27382@item type
27383The type of the breakpoint. For ordinary breakpoints this will be
27384@samp{breakpoint}, but many values are possible.
27385
8ac3646f
TT
27386@item catch-type
27387If the type of the breakpoint is @samp{catchpoint}, then this
27388indicates the exact type of catchpoint.
27389
54516a0b
TT
27390@item disp
27391This is the breakpoint disposition---either @samp{del}, meaning that
27392the breakpoint will be deleted at the next stop, or @samp{keep},
27393meaning that the breakpoint will not be deleted.
27394
27395@item enabled
27396This indicates whether the breakpoint is enabled, in which case the
27397value is @samp{y}, or disabled, in which case the value is @samp{n}.
27398Note that this is not the same as the field @code{enable}.
27399
27400@item addr
27401The address of the breakpoint. This may be a hexidecimal number,
27402giving the address; or the string @samp{<PENDING>}, for a pending
27403breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
27404multiple locations. This field will not be present if no address can
27405be determined. For example, a watchpoint does not have an address.
27406
27407@item func
27408If known, the function in which the breakpoint appears.
27409If not known, this field is not present.
27410
27411@item filename
27412The name of the source file which contains this function, if known.
27413If not known, this field is not present.
27414
27415@item fullname
27416The full file name of the source file which contains this function, if
27417known. If not known, this field is not present.
27418
27419@item line
27420The line number at which this breakpoint appears, if known.
27421If not known, this field is not present.
27422
27423@item at
27424If the source file is not known, this field may be provided. If
27425provided, this holds the address of the breakpoint, possibly followed
27426by a symbol name.
27427
27428@item pending
27429If this breakpoint is pending, this field is present and holds the
27430text used to set the breakpoint, as entered by the user.
27431
27432@item evaluated-by
27433Where this breakpoint's condition is evaluated, either @samp{host} or
27434@samp{target}.
27435
27436@item thread
27437If this is a thread-specific breakpoint, then this identifies the
27438thread in which the breakpoint can trigger.
27439
27440@item task
27441If this breakpoint is restricted to a particular Ada task, then this
27442field will hold the task identifier.
27443
27444@item cond
27445If the breakpoint is conditional, this is the condition expression.
27446
27447@item ignore
27448The ignore count of the breakpoint.
27449
27450@item enable
27451The enable count of the breakpoint.
27452
27453@item traceframe-usage
27454FIXME.
27455
27456@item static-tracepoint-marker-string-id
27457For a static tracepoint, the name of the static tracepoint marker.
27458
27459@item mask
27460For a masked watchpoint, this is the mask.
27461
27462@item pass
27463A tracepoint's pass count.
27464
27465@item original-location
27466The location of the breakpoint as originally specified by the user.
27467This field is optional.
27468
27469@item times
27470The number of times the breakpoint has been hit.
27471
27472@item installed
27473This field is only given for tracepoints. This is either @samp{y},
27474meaning that the tracepoint is installed, or @samp{n}, meaning that it
27475is not.
27476
27477@item what
27478Some extra data, the exact contents of which are type-dependent.
27479
27480@end table
27481
27482For example, here is what the output of @code{-break-insert}
27483(@pxref{GDB/MI Breakpoint Commands}) might be:
27484
27485@smallexample
27486-> -break-insert main
27487<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
27488 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
27489 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
27490 times="0"@}
54516a0b
TT
27491<- (gdb)
27492@end smallexample
27493
c3b108f7
VP
27494@node GDB/MI Frame Information
27495@subsection @sc{gdb/mi} Frame Information
27496
27497Response from many MI commands includes an information about stack
27498frame. This information is a tuple that may have the following
27499fields:
27500
27501@table @code
27502@item level
27503The level of the stack frame. The innermost frame has the level of
27504zero. This field is always present.
27505
27506@item func
27507The name of the function corresponding to the frame. This field may
27508be absent if @value{GDBN} is unable to determine the function name.
27509
27510@item addr
27511The code address for the frame. This field is always present.
27512
27513@item file
27514The name of the source files that correspond to the frame's code
27515address. This field may be absent.
27516
27517@item line
27518The source line corresponding to the frames' code address. This field
27519may be absent.
27520
27521@item from
27522The name of the binary file (either executable or shared library) the
27523corresponds to the frame's code address. This field may be absent.
27524
27525@end table
82f68b1c 27526
dc146f7c
VP
27527@node GDB/MI Thread Information
27528@subsection @sc{gdb/mi} Thread Information
27529
27530Whenever @value{GDBN} has to report an information about a thread, it
ebe553db
SM
27531uses a tuple with the following fields. The fields are always present unless
27532stated otherwise.
dc146f7c
VP
27533
27534@table @code
27535@item id
ebe553db 27536The global numeric id assigned to the thread by @value{GDBN}.
dc146f7c
VP
27537
27538@item target-id
ebe553db 27539The target-specific string identifying the thread.
dc146f7c
VP
27540
27541@item details
27542Additional information about the thread provided by the target.
27543It is supposed to be human-readable and not interpreted by the
27544frontend. This field is optional.
27545
ebe553db
SM
27546@item name
27547The name of the thread. If the user specified a name using the
27548@code{thread name} command, then this name is given. Otherwise, if
27549@value{GDBN} can extract the thread name from the target, then that
27550name is given. If @value{GDBN} cannot find the thread name, then this
27551field is omitted.
27552
dc146f7c 27553@item state
ebe553db
SM
27554The execution state of the thread, either @samp{stopped} or @samp{running},
27555depending on whether the thread is presently running.
27556
27557@item frame
27558The stack frame currently executing in the thread. This field is only present
27559if the thread is stopped. Its format is documented in
27560@ref{GDB/MI Frame Information}.
dc146f7c
VP
27561
27562@item core
27563The value of this field is an integer number of the processor core the
27564thread was last seen on. This field is optional.
27565@end table
27566
956a9fb9
JB
27567@node GDB/MI Ada Exception Information
27568@subsection @sc{gdb/mi} Ada Exception Information
27569
27570Whenever a @code{*stopped} record is emitted because the program
27571stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
27572@value{GDBN} provides the name of the exception that was raised via
e547c119
JB
27573the @code{exception-name} field. Also, for exceptions that were raised
27574with an exception message, @value{GDBN} provides that message via
27575the @code{exception-message} field.
922fbb7b 27576
ef21caaf
NR
27577@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27578@node GDB/MI Simple Examples
27579@section Simple Examples of @sc{gdb/mi} Interaction
27580@cindex @sc{gdb/mi}, simple examples
27581
27582This subsection presents several simple examples of interaction using
27583the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
27584following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
27585the output received from @sc{gdb/mi}.
27586
d3e8051b 27587Note the line breaks shown in the examples are here only for
ef21caaf
NR
27588readability, they don't appear in the real output.
27589
79a6e687 27590@subheading Setting a Breakpoint
ef21caaf
NR
27591
27592Setting a breakpoint generates synchronous output which contains detailed
27593information of the breakpoint.
27594
27595@smallexample
27596-> -break-insert main
27597<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
27598 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
27599 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
27600 times="0"@}
ef21caaf
NR
27601<- (gdb)
27602@end smallexample
27603
27604@subheading Program Execution
27605
27606Program execution generates asynchronous records and MI gives the
27607reason that execution stopped.
27608
27609@smallexample
27610-> -exec-run
27611<- ^running
27612<- (gdb)
a47ec5fe 27613<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
ef21caaf
NR
27614 frame=@{addr="0x08048564",func="main",
27615 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
27616 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
27617<- (gdb)
27618-> -exec-continue
27619<- ^running
27620<- (gdb)
27621<- *stopped,reason="exited-normally"
27622<- (gdb)
27623@end smallexample
27624
3f94c067 27625@subheading Quitting @value{GDBN}
ef21caaf 27626
3f94c067 27627Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
27628
27629@smallexample
27630-> (gdb)
27631<- -gdb-exit
27632<- ^exit
27633@end smallexample
27634
a6b29f87
VP
27635Please note that @samp{^exit} is printed immediately, but it might
27636take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
27637performs necessary cleanups, including killing programs being debugged
27638or disconnecting from debug hardware, so the frontend should wait till
27639@value{GDBN} exits and should only forcibly kill @value{GDBN} if it
27640fails to exit in reasonable time.
27641
a2c02241 27642@subheading A Bad Command
ef21caaf
NR
27643
27644Here's what happens if you pass a non-existent command:
27645
27646@smallexample
27647-> -rubbish
27648<- ^error,msg="Undefined MI command: rubbish"
594fe323 27649<- (gdb)
ef21caaf
NR
27650@end smallexample
27651
27652
922fbb7b
AC
27653@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27654@node GDB/MI Command Description Format
27655@section @sc{gdb/mi} Command Description Format
27656
27657The remaining sections describe blocks of commands. Each block of
27658commands is laid out in a fashion similar to this section.
27659
922fbb7b
AC
27660@subheading Motivation
27661
27662The motivation for this collection of commands.
27663
27664@subheading Introduction
27665
27666A brief introduction to this collection of commands as a whole.
27667
27668@subheading Commands
27669
27670For each command in the block, the following is described:
27671
27672@subsubheading Synopsis
27673
27674@smallexample
27675 -command @var{args}@dots{}
27676@end smallexample
27677
922fbb7b
AC
27678@subsubheading Result
27679
265eeb58 27680@subsubheading @value{GDBN} Command
922fbb7b 27681
265eeb58 27682The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
27683
27684@subsubheading Example
27685
ef21caaf
NR
27686Example(s) formatted for readability. Some of the described commands have
27687not been implemented yet and these are labeled N.A.@: (not available).
27688
27689
922fbb7b 27690@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
27691@node GDB/MI Breakpoint Commands
27692@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
27693
27694@cindex breakpoint commands for @sc{gdb/mi}
27695@cindex @sc{gdb/mi}, breakpoint commands
27696This section documents @sc{gdb/mi} commands for manipulating
27697breakpoints.
27698
27699@subheading The @code{-break-after} Command
27700@findex -break-after
27701
27702@subsubheading Synopsis
27703
27704@smallexample
27705 -break-after @var{number} @var{count}
27706@end smallexample
27707
27708The breakpoint number @var{number} is not in effect until it has been
27709hit @var{count} times. To see how this is reflected in the output of
27710the @samp{-break-list} command, see the description of the
27711@samp{-break-list} command below.
27712
27713@subsubheading @value{GDBN} Command
27714
27715The corresponding @value{GDBN} command is @samp{ignore}.
27716
27717@subsubheading Example
27718
27719@smallexample
594fe323 27720(gdb)
922fbb7b 27721-break-insert main
a47ec5fe
AR
27722^done,bkpt=@{number="1",type="breakpoint",disp="keep",
27723enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
27724fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
27725times="0"@}
594fe323 27726(gdb)
922fbb7b
AC
27727-break-after 1 3
27728~
27729^done
594fe323 27730(gdb)
922fbb7b
AC
27731-break-list
27732^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
27733hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
27734@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
27735@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
27736@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
27737@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
27738@{width="40",alignment="2",col_name="what",colhdr="What"@}],
27739body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 27740addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 27741line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 27742(gdb)
922fbb7b
AC
27743@end smallexample
27744
27745@ignore
27746@subheading The @code{-break-catch} Command
27747@findex -break-catch
48cb2d85 27748@end ignore
922fbb7b
AC
27749
27750@subheading The @code{-break-commands} Command
27751@findex -break-commands
922fbb7b 27752
48cb2d85
VP
27753@subsubheading Synopsis
27754
27755@smallexample
27756 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
27757@end smallexample
27758
27759Specifies the CLI commands that should be executed when breakpoint
27760@var{number} is hit. The parameters @var{command1} to @var{commandN}
27761are the commands. If no command is specified, any previously-set
27762commands are cleared. @xref{Break Commands}. Typical use of this
27763functionality is tracing a program, that is, printing of values of
27764some variables whenever breakpoint is hit and then continuing.
27765
27766@subsubheading @value{GDBN} Command
27767
27768The corresponding @value{GDBN} command is @samp{commands}.
27769
27770@subsubheading Example
27771
27772@smallexample
27773(gdb)
27774-break-insert main
27775^done,bkpt=@{number="1",type="breakpoint",disp="keep",
27776enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
27777fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
27778times="0"@}
48cb2d85
VP
27779(gdb)
27780-break-commands 1 "print v" "continue"
27781^done
27782(gdb)
27783@end smallexample
922fbb7b
AC
27784
27785@subheading The @code{-break-condition} Command
27786@findex -break-condition
27787
27788@subsubheading Synopsis
27789
27790@smallexample
27791 -break-condition @var{number} @var{expr}
27792@end smallexample
27793
27794Breakpoint @var{number} will stop the program only if the condition in
27795@var{expr} is true. The condition becomes part of the
27796@samp{-break-list} output (see the description of the @samp{-break-list}
27797command below).
27798
27799@subsubheading @value{GDBN} Command
27800
27801The corresponding @value{GDBN} command is @samp{condition}.
27802
27803@subsubheading Example
27804
27805@smallexample
594fe323 27806(gdb)
922fbb7b
AC
27807-break-condition 1 1
27808^done
594fe323 27809(gdb)
922fbb7b
AC
27810-break-list
27811^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
27812hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
27813@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
27814@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
27815@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
27816@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
27817@{width="40",alignment="2",col_name="what",colhdr="What"@}],
27818body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 27819addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 27820line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 27821(gdb)
922fbb7b
AC
27822@end smallexample
27823
27824@subheading The @code{-break-delete} Command
27825@findex -break-delete
27826
27827@subsubheading Synopsis
27828
27829@smallexample
27830 -break-delete ( @var{breakpoint} )+
27831@end smallexample
27832
27833Delete the breakpoint(s) whose number(s) are specified in the argument
27834list. This is obviously reflected in the breakpoint list.
27835
79a6e687 27836@subsubheading @value{GDBN} Command
922fbb7b
AC
27837
27838The corresponding @value{GDBN} command is @samp{delete}.
27839
27840@subsubheading Example
27841
27842@smallexample
594fe323 27843(gdb)
922fbb7b
AC
27844-break-delete 1
27845^done
594fe323 27846(gdb)
922fbb7b
AC
27847-break-list
27848^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
27849hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
27850@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
27851@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
27852@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
27853@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
27854@{width="40",alignment="2",col_name="what",colhdr="What"@}],
27855body=[]@}
594fe323 27856(gdb)
922fbb7b
AC
27857@end smallexample
27858
27859@subheading The @code{-break-disable} Command
27860@findex -break-disable
27861
27862@subsubheading Synopsis
27863
27864@smallexample
27865 -break-disable ( @var{breakpoint} )+
27866@end smallexample
27867
27868Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
27869break list is now set to @samp{n} for the named @var{breakpoint}(s).
27870
27871@subsubheading @value{GDBN} Command
27872
27873The corresponding @value{GDBN} command is @samp{disable}.
27874
27875@subsubheading Example
27876
27877@smallexample
594fe323 27878(gdb)
922fbb7b
AC
27879-break-disable 2
27880^done
594fe323 27881(gdb)
922fbb7b
AC
27882-break-list
27883^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
27884hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
27885@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
27886@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
27887@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
27888@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
27889@{width="40",alignment="2",col_name="what",colhdr="What"@}],
27890body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102 27891addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 27892line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 27893(gdb)
922fbb7b
AC
27894@end smallexample
27895
27896@subheading The @code{-break-enable} Command
27897@findex -break-enable
27898
27899@subsubheading Synopsis
27900
27901@smallexample
27902 -break-enable ( @var{breakpoint} )+
27903@end smallexample
27904
27905Enable (previously disabled) @var{breakpoint}(s).
27906
27907@subsubheading @value{GDBN} Command
27908
27909The corresponding @value{GDBN} command is @samp{enable}.
27910
27911@subsubheading Example
27912
27913@smallexample
594fe323 27914(gdb)
922fbb7b
AC
27915-break-enable 2
27916^done
594fe323 27917(gdb)
922fbb7b
AC
27918-break-list
27919^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
27920hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
27921@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
27922@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
27923@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
27924@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
27925@{width="40",alignment="2",col_name="what",colhdr="What"@}],
27926body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 27927addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 27928line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 27929(gdb)
922fbb7b
AC
27930@end smallexample
27931
27932@subheading The @code{-break-info} Command
27933@findex -break-info
27934
27935@subsubheading Synopsis
27936
27937@smallexample
27938 -break-info @var{breakpoint}
27939@end smallexample
27940
27941@c REDUNDANT???
27942Get information about a single breakpoint.
27943
54516a0b
TT
27944The result is a table of breakpoints. @xref{GDB/MI Breakpoint
27945Information}, for details on the format of each breakpoint in the
27946table.
27947
79a6e687 27948@subsubheading @value{GDBN} Command
922fbb7b
AC
27949
27950The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
27951
27952@subsubheading Example
27953N.A.
27954
27955@subheading The @code{-break-insert} Command
27956@findex -break-insert
629500fa 27957@anchor{-break-insert}
922fbb7b
AC
27958
27959@subsubheading Synopsis
27960
27961@smallexample
18148017 27962 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
922fbb7b 27963 [ -c @var{condition} ] [ -i @var{ignore-count} ]
472a2379 27964 [ -p @var{thread-id} ] [ @var{location} ]
922fbb7b
AC
27965@end smallexample
27966
27967@noindent
afe8ab22 27968If specified, @var{location}, can be one of:
922fbb7b 27969
629500fa
KS
27970@table @var
27971@item linespec location
27972A linespec location. @xref{Linespec Locations}.
27973
27974@item explicit location
27975An explicit location. @sc{gdb/mi} explicit locations are
27976analogous to the CLI's explicit locations using the option names
27977listed below. @xref{Explicit Locations}.
27978
27979@table @samp
27980@item --source @var{filename}
27981The source file name of the location. This option requires the use
27982of either @samp{--function} or @samp{--line}.
27983
27984@item --function @var{function}
27985The name of a function or method.
922fbb7b 27986
629500fa
KS
27987@item --label @var{label}
27988The name of a label.
27989
27990@item --line @var{lineoffset}
27991An absolute or relative line offset from the start of the location.
27992@end table
27993
27994@item address location
27995An address location, *@var{address}. @xref{Address Locations}.
27996@end table
27997
27998@noindent
922fbb7b
AC
27999The possible optional parameters of this command are:
28000
28001@table @samp
28002@item -t
948d5102 28003Insert a temporary breakpoint.
922fbb7b
AC
28004@item -h
28005Insert a hardware breakpoint.
afe8ab22
VP
28006@item -f
28007If @var{location} cannot be parsed (for example if it
28008refers to unknown files or functions), create a pending
28009breakpoint. Without this flag, @value{GDBN} will report
28010an error, and won't create a breakpoint, if @var{location}
28011cannot be parsed.
41447f92
VP
28012@item -d
28013Create a disabled breakpoint.
18148017
VP
28014@item -a
28015Create a tracepoint. @xref{Tracepoints}. When this parameter
28016is used together with @samp{-h}, a fast tracepoint is created.
472a2379
KS
28017@item -c @var{condition}
28018Make the breakpoint conditional on @var{condition}.
28019@item -i @var{ignore-count}
28020Initialize the @var{ignore-count}.
28021@item -p @var{thread-id}
5d5658a1
PA
28022Restrict the breakpoint to the thread with the specified global
28023@var{thread-id}.
922fbb7b
AC
28024@end table
28025
28026@subsubheading Result
28027
54516a0b
TT
28028@xref{GDB/MI Breakpoint Information}, for details on the format of the
28029resulting breakpoint.
922fbb7b
AC
28030
28031Note: this format is open to change.
28032@c An out-of-band breakpoint instead of part of the result?
28033
28034@subsubheading @value{GDBN} Command
28035
28036The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
496ee73e 28037@samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
922fbb7b
AC
28038
28039@subsubheading Example
28040
28041@smallexample
594fe323 28042(gdb)
922fbb7b 28043-break-insert main
948d5102 28044^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
998580f1
MK
28045fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
28046times="0"@}
594fe323 28047(gdb)
922fbb7b 28048-break-insert -t foo
948d5102 28049^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
998580f1
MK
28050fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
28051times="0"@}
594fe323 28052(gdb)
922fbb7b
AC
28053-break-list
28054^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
28055hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28056@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28057@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28058@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28059@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28060@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28061body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 28062addr="0x0001072c", func="main",file="recursive2.c",
998580f1
MK
28063fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
28064times="0"@},
922fbb7b 28065bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102 28066addr="0x00010774",func="foo",file="recursive2.c",
998580f1
MK
28067fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
28068times="0"@}]@}
594fe323 28069(gdb)
496ee73e
KS
28070@c -break-insert -r foo.*
28071@c ~int foo(int, int);
28072@c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
998580f1
MK
28073@c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
28074@c times="0"@}
496ee73e 28075@c (gdb)
922fbb7b
AC
28076@end smallexample
28077
c5867ab6
HZ
28078@subheading The @code{-dprintf-insert} Command
28079@findex -dprintf-insert
28080
28081@subsubheading Synopsis
28082
28083@smallexample
28084 -dprintf-insert [ -t ] [ -f ] [ -d ]
28085 [ -c @var{condition} ] [ -i @var{ignore-count} ]
28086 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
28087 [ @var{argument} ]
28088@end smallexample
28089
28090@noindent
629500fa
KS
28091If supplied, @var{location} may be specified the same way as for
28092the @code{-break-insert} command. @xref{-break-insert}.
c5867ab6
HZ
28093
28094The possible optional parameters of this command are:
28095
28096@table @samp
28097@item -t
28098Insert a temporary breakpoint.
28099@item -f
28100If @var{location} cannot be parsed (for example, if it
28101refers to unknown files or functions), create a pending
28102breakpoint. Without this flag, @value{GDBN} will report
28103an error, and won't create a breakpoint, if @var{location}
28104cannot be parsed.
28105@item -d
28106Create a disabled breakpoint.
28107@item -c @var{condition}
28108Make the breakpoint conditional on @var{condition}.
28109@item -i @var{ignore-count}
28110Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
28111to @var{ignore-count}.
28112@item -p @var{thread-id}
5d5658a1
PA
28113Restrict the breakpoint to the thread with the specified global
28114@var{thread-id}.
c5867ab6
HZ
28115@end table
28116
28117@subsubheading Result
28118
28119@xref{GDB/MI Breakpoint Information}, for details on the format of the
28120resulting breakpoint.
28121
28122@c An out-of-band breakpoint instead of part of the result?
28123
28124@subsubheading @value{GDBN} Command
28125
28126The corresponding @value{GDBN} command is @samp{dprintf}.
28127
28128@subsubheading Example
28129
28130@smallexample
28131(gdb)
281324-dprintf-insert foo "At foo entry\n"
281334^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
28134addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
28135fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
28136times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
28137original-location="foo"@}
28138(gdb)
281395-dprintf-insert 26 "arg=%d, g=%d\n" arg g
281405^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
28141addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
28142fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
28143times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
28144original-location="mi-dprintf.c:26"@}
28145(gdb)
28146@end smallexample
28147
922fbb7b
AC
28148@subheading The @code{-break-list} Command
28149@findex -break-list
28150
28151@subsubheading Synopsis
28152
28153@smallexample
28154 -break-list
28155@end smallexample
28156
28157Displays the list of inserted breakpoints, showing the following fields:
28158
28159@table @samp
28160@item Number
28161number of the breakpoint
28162@item Type
28163type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
28164@item Disposition
28165should the breakpoint be deleted or disabled when it is hit: @samp{keep}
28166or @samp{nokeep}
28167@item Enabled
28168is the breakpoint enabled or no: @samp{y} or @samp{n}
28169@item Address
28170memory location at which the breakpoint is set
28171@item What
28172logical location of the breakpoint, expressed by function name, file
28173name, line number
998580f1
MK
28174@item Thread-groups
28175list of thread groups to which this breakpoint applies
922fbb7b
AC
28176@item Times
28177number of times the breakpoint has been hit
28178@end table
28179
28180If there are no breakpoints or watchpoints, the @code{BreakpointTable}
28181@code{body} field is an empty list.
28182
28183@subsubheading @value{GDBN} Command
28184
28185The corresponding @value{GDBN} command is @samp{info break}.
28186
28187@subsubheading Example
28188
28189@smallexample
594fe323 28190(gdb)
922fbb7b
AC
28191-break-list
28192^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
28193hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28194@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28195@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28196@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28197@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28198@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28199body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
998580f1
MK
28200addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
28201times="0"@},
922fbb7b 28202bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 28203addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
998580f1 28204line="13",thread-groups=["i1"],times="0"@}]@}
594fe323 28205(gdb)
922fbb7b
AC
28206@end smallexample
28207
28208Here's an example of the result when there are no breakpoints:
28209
28210@smallexample
594fe323 28211(gdb)
922fbb7b
AC
28212-break-list
28213^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
28214hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28215@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28216@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28217@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28218@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28219@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28220body=[]@}
594fe323 28221(gdb)
922fbb7b
AC
28222@end smallexample
28223
18148017
VP
28224@subheading The @code{-break-passcount} Command
28225@findex -break-passcount
28226
28227@subsubheading Synopsis
28228
28229@smallexample
28230 -break-passcount @var{tracepoint-number} @var{passcount}
28231@end smallexample
28232
28233Set the passcount for tracepoint @var{tracepoint-number} to
28234@var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
28235is not a tracepoint, error is emitted. This corresponds to CLI
28236command @samp{passcount}.
28237
922fbb7b
AC
28238@subheading The @code{-break-watch} Command
28239@findex -break-watch
28240
28241@subsubheading Synopsis
28242
28243@smallexample
28244 -break-watch [ -a | -r ]
28245@end smallexample
28246
28247Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 28248@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 28249read from or on a write to the memory location. With the @samp{-r}
d3e8051b 28250option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
28251trigger only when the memory location is accessed for reading. Without
28252either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 28253i.e., it will trigger when the memory location is accessed for writing.
79a6e687 28254@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
28255
28256Note that @samp{-break-list} will report a single list of watchpoints and
28257breakpoints inserted.
28258
28259@subsubheading @value{GDBN} Command
28260
28261The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
28262@samp{rwatch}.
28263
28264@subsubheading Example
28265
28266Setting a watchpoint on a variable in the @code{main} function:
28267
28268@smallexample
594fe323 28269(gdb)
922fbb7b
AC
28270-break-watch x
28271^done,wpt=@{number="2",exp="x"@}
594fe323 28272(gdb)
922fbb7b
AC
28273-exec-continue
28274^running
0869d01b
NR
28275(gdb)
28276*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 28277value=@{old="-268439212",new="55"@},
76ff342d 28278frame=@{func="main",args=[],file="recursive2.c",
948d5102 28279fullname="/home/foo/bar/recursive2.c",line="5"@}
594fe323 28280(gdb)
922fbb7b
AC
28281@end smallexample
28282
28283Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
28284the program execution twice: first for the variable changing value, then
28285for the watchpoint going out of scope.
28286
28287@smallexample
594fe323 28288(gdb)
922fbb7b
AC
28289-break-watch C
28290^done,wpt=@{number="5",exp="C"@}
594fe323 28291(gdb)
922fbb7b
AC
28292-exec-continue
28293^running
0869d01b
NR
28294(gdb)
28295*stopped,reason="watchpoint-trigger",
922fbb7b
AC
28296wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
28297frame=@{func="callee4",args=[],
76ff342d
DJ
28298file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28299fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 28300(gdb)
922fbb7b
AC
28301-exec-continue
28302^running
0869d01b
NR
28303(gdb)
28304*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
28305frame=@{func="callee3",args=[@{name="strarg",
28306value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
28307file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28308fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 28309(gdb)
922fbb7b
AC
28310@end smallexample
28311
28312Listing breakpoints and watchpoints, at different points in the program
28313execution. Note that once the watchpoint goes out of scope, it is
28314deleted.
28315
28316@smallexample
594fe323 28317(gdb)
922fbb7b
AC
28318-break-watch C
28319^done,wpt=@{number="2",exp="C"@}
594fe323 28320(gdb)
922fbb7b
AC
28321-break-list
28322^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
28323hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28324@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28325@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28326@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28327@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28328@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28329body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
28330addr="0x00010734",func="callee4",
948d5102 28331file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
28332fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
28333times="1"@},
922fbb7b 28334bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 28335enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
594fe323 28336(gdb)
922fbb7b
AC
28337-exec-continue
28338^running
0869d01b
NR
28339(gdb)
28340*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
28341value=@{old="-276895068",new="3"@},
28342frame=@{func="callee4",args=[],
76ff342d
DJ
28343file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28344fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 28345(gdb)
922fbb7b
AC
28346-break-list
28347^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
28348hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28349@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28350@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28351@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28352@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28353@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28354body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
28355addr="0x00010734",func="callee4",
948d5102 28356file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
28357fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
28358times="1"@},
922fbb7b 28359bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 28360enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
594fe323 28361(gdb)
922fbb7b
AC
28362-exec-continue
28363^running
28364^done,reason="watchpoint-scope",wpnum="2",
28365frame=@{func="callee3",args=[@{name="strarg",
28366value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
28367file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28368fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 28369(gdb)
922fbb7b
AC
28370-break-list
28371^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28372hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28373@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28374@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28375@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28376@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28377@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28378body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
28379addr="0x00010734",func="callee4",
948d5102
NR
28380file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28381fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
998580f1 28382thread-groups=["i1"],times="1"@}]@}
594fe323 28383(gdb)
922fbb7b
AC
28384@end smallexample
28385
3fa7bf06
MG
28386
28387@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28388@node GDB/MI Catchpoint Commands
28389@section @sc{gdb/mi} Catchpoint Commands
28390
28391This section documents @sc{gdb/mi} commands for manipulating
28392catchpoints.
28393
40555925
JB
28394@menu
28395* Shared Library GDB/MI Catchpoint Commands::
28396* Ada Exception GDB/MI Catchpoint Commands::
28397@end menu
28398
28399@node Shared Library GDB/MI Catchpoint Commands
28400@subsection Shared Library @sc{gdb/mi} Catchpoints
28401
3fa7bf06
MG
28402@subheading The @code{-catch-load} Command
28403@findex -catch-load
28404
28405@subsubheading Synopsis
28406
28407@smallexample
28408 -catch-load [ -t ] [ -d ] @var{regexp}
28409@end smallexample
28410
28411Add a catchpoint for library load events. If the @samp{-t} option is used,
28412the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
28413Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
28414in a disabled state. The @samp{regexp} argument is a regular
28415expression used to match the name of the loaded library.
28416
28417
28418@subsubheading @value{GDBN} Command
28419
28420The corresponding @value{GDBN} command is @samp{catch load}.
28421
28422@subsubheading Example
28423
28424@smallexample
28425-catch-load -t foo.so
28426^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
8ac3646f 28427what="load of library matching foo.so",catch-type="load",times="0"@}
3fa7bf06
MG
28428(gdb)
28429@end smallexample
28430
28431
28432@subheading The @code{-catch-unload} Command
28433@findex -catch-unload
28434
28435@subsubheading Synopsis
28436
28437@smallexample
28438 -catch-unload [ -t ] [ -d ] @var{regexp}
28439@end smallexample
28440
28441Add a catchpoint for library unload events. If the @samp{-t} option is
28442used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
28443Breakpoints}). If the @samp{-d} option is used, the catchpoint is
28444created in a disabled state. The @samp{regexp} argument is a regular
28445expression used to match the name of the unloaded library.
28446
28447@subsubheading @value{GDBN} Command
28448
28449The corresponding @value{GDBN} command is @samp{catch unload}.
28450
28451@subsubheading Example
28452
28453@smallexample
28454-catch-unload -d bar.so
28455^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
8ac3646f 28456what="load of library matching bar.so",catch-type="unload",times="0"@}
3fa7bf06
MG
28457(gdb)
28458@end smallexample
28459
40555925
JB
28460@node Ada Exception GDB/MI Catchpoint Commands
28461@subsection Ada Exception @sc{gdb/mi} Catchpoints
28462
28463The following @sc{gdb/mi} commands can be used to create catchpoints
28464that stop the execution when Ada exceptions are being raised.
28465
28466@subheading The @code{-catch-assert} Command
28467@findex -catch-assert
28468
28469@subsubheading Synopsis
28470
28471@smallexample
28472 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
28473@end smallexample
28474
28475Add a catchpoint for failed Ada assertions.
28476
28477The possible optional parameters for this command are:
28478
28479@table @samp
28480@item -c @var{condition}
28481Make the catchpoint conditional on @var{condition}.
28482@item -d
28483Create a disabled catchpoint.
28484@item -t
28485Create a temporary catchpoint.
28486@end table
28487
28488@subsubheading @value{GDBN} Command
28489
28490The corresponding @value{GDBN} command is @samp{catch assert}.
28491
28492@subsubheading Example
28493
28494@smallexample
28495-catch-assert
28496^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
28497enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
28498thread-groups=["i1"],times="0",
28499original-location="__gnat_debug_raise_assert_failure"@}
28500(gdb)
28501@end smallexample
28502
28503@subheading The @code{-catch-exception} Command
28504@findex -catch-exception
28505
28506@subsubheading Synopsis
28507
28508@smallexample
28509 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
28510 [ -t ] [ -u ]
28511@end smallexample
28512
28513Add a catchpoint stopping when Ada exceptions are raised.
28514By default, the command stops the program when any Ada exception
28515gets raised. But it is also possible, by using some of the
28516optional parameters described below, to create more selective
28517catchpoints.
28518
28519The possible optional parameters for this command are:
28520
28521@table @samp
28522@item -c @var{condition}
28523Make the catchpoint conditional on @var{condition}.
28524@item -d
28525Create a disabled catchpoint.
28526@item -e @var{exception-name}
28527Only stop when @var{exception-name} is raised. This option cannot
28528be used combined with @samp{-u}.
28529@item -t
28530Create a temporary catchpoint.
28531@item -u
28532Stop only when an unhandled exception gets raised. This option
28533cannot be used combined with @samp{-e}.
28534@end table
28535
28536@subsubheading @value{GDBN} Command
28537
28538The corresponding @value{GDBN} commands are @samp{catch exception}
28539and @samp{catch exception unhandled}.
28540
28541@subsubheading Example
28542
28543@smallexample
28544-catch-exception -e Program_Error
28545^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
28546enabled="y",addr="0x0000000000404874",
28547what="`Program_Error' Ada exception", thread-groups=["i1"],
28548times="0",original-location="__gnat_debug_raise_exception"@}
28549(gdb)
28550@end smallexample
3fa7bf06 28551
bea298f9
XR
28552@subheading The @code{-catch-handlers} Command
28553@findex -catch-handlers
28554
28555@subsubheading Synopsis
28556
28557@smallexample
28558 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
28559 [ -t ]
28560@end smallexample
28561
28562Add a catchpoint stopping when Ada exceptions are handled.
28563By default, the command stops the program when any Ada exception
28564gets handled. But it is also possible, by using some of the
28565optional parameters described below, to create more selective
28566catchpoints.
28567
28568The possible optional parameters for this command are:
28569
28570@table @samp
28571@item -c @var{condition}
28572Make the catchpoint conditional on @var{condition}.
28573@item -d
28574Create a disabled catchpoint.
28575@item -e @var{exception-name}
28576Only stop when @var{exception-name} is handled.
28577@item -t
28578Create a temporary catchpoint.
28579@end table
28580
28581@subsubheading @value{GDBN} Command
28582
28583The corresponding @value{GDBN} command is @samp{catch handlers}.
28584
28585@subsubheading Example
28586
28587@smallexample
28588-catch-handlers -e Constraint_Error
28589^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
28590enabled="y",addr="0x0000000000402f68",
28591what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
28592times="0",original-location="__gnat_begin_handler"@}
28593(gdb)
28594@end smallexample
28595
922fbb7b 28596@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
28597@node GDB/MI Program Context
28598@section @sc{gdb/mi} Program Context
922fbb7b 28599
a2c02241
NR
28600@subheading The @code{-exec-arguments} Command
28601@findex -exec-arguments
922fbb7b 28602
922fbb7b
AC
28603
28604@subsubheading Synopsis
28605
28606@smallexample
a2c02241 28607 -exec-arguments @var{args}
922fbb7b
AC
28608@end smallexample
28609
a2c02241
NR
28610Set the inferior program arguments, to be used in the next
28611@samp{-exec-run}.
922fbb7b 28612
a2c02241 28613@subsubheading @value{GDBN} Command
922fbb7b 28614
a2c02241 28615The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 28616
a2c02241 28617@subsubheading Example
922fbb7b 28618
fbc5282e
MK
28619@smallexample
28620(gdb)
28621-exec-arguments -v word
28622^done
28623(gdb)
28624@end smallexample
922fbb7b 28625
a2c02241 28626
9901a55b 28627@ignore
a2c02241
NR
28628@subheading The @code{-exec-show-arguments} Command
28629@findex -exec-show-arguments
28630
28631@subsubheading Synopsis
28632
28633@smallexample
28634 -exec-show-arguments
28635@end smallexample
28636
28637Print the arguments of the program.
922fbb7b
AC
28638
28639@subsubheading @value{GDBN} Command
28640
a2c02241 28641The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
28642
28643@subsubheading Example
a2c02241 28644N.A.
9901a55b 28645@end ignore
922fbb7b 28646
922fbb7b 28647
a2c02241
NR
28648@subheading The @code{-environment-cd} Command
28649@findex -environment-cd
922fbb7b 28650
a2c02241 28651@subsubheading Synopsis
922fbb7b
AC
28652
28653@smallexample
a2c02241 28654 -environment-cd @var{pathdir}
922fbb7b
AC
28655@end smallexample
28656
a2c02241 28657Set @value{GDBN}'s working directory.
922fbb7b 28658
a2c02241 28659@subsubheading @value{GDBN} Command
922fbb7b 28660
a2c02241
NR
28661The corresponding @value{GDBN} command is @samp{cd}.
28662
28663@subsubheading Example
922fbb7b
AC
28664
28665@smallexample
594fe323 28666(gdb)
a2c02241
NR
28667-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
28668^done
594fe323 28669(gdb)
922fbb7b
AC
28670@end smallexample
28671
28672
a2c02241
NR
28673@subheading The @code{-environment-directory} Command
28674@findex -environment-directory
922fbb7b
AC
28675
28676@subsubheading Synopsis
28677
28678@smallexample
a2c02241 28679 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
28680@end smallexample
28681
a2c02241
NR
28682Add directories @var{pathdir} to beginning of search path for source files.
28683If the @samp{-r} option is used, the search path is reset to the default
28684search path. If directories @var{pathdir} are supplied in addition to the
28685@samp{-r} option, the search path is first reset and then addition
28686occurs as normal.
28687Multiple directories may be specified, separated by blanks. Specifying
28688multiple directories in a single command
28689results in the directories added to the beginning of the
28690search path in the same order they were presented in the command.
28691If blanks are needed as
28692part of a directory name, double-quotes should be used around
28693the name. In the command output, the path will show up separated
d3e8051b 28694by the system directory-separator character. The directory-separator
a2c02241
NR
28695character must not be used
28696in any directory name.
28697If no directories are specified, the current search path is displayed.
922fbb7b
AC
28698
28699@subsubheading @value{GDBN} Command
28700
a2c02241 28701The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
28702
28703@subsubheading Example
28704
922fbb7b 28705@smallexample
594fe323 28706(gdb)
a2c02241
NR
28707-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
28708^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 28709(gdb)
a2c02241
NR
28710-environment-directory ""
28711^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 28712(gdb)
a2c02241
NR
28713-environment-directory -r /home/jjohnstn/src/gdb /usr/src
28714^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 28715(gdb)
a2c02241
NR
28716-environment-directory -r
28717^done,source-path="$cdir:$cwd"
594fe323 28718(gdb)
922fbb7b
AC
28719@end smallexample
28720
28721
a2c02241
NR
28722@subheading The @code{-environment-path} Command
28723@findex -environment-path
922fbb7b
AC
28724
28725@subsubheading Synopsis
28726
28727@smallexample
a2c02241 28728 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
28729@end smallexample
28730
a2c02241
NR
28731Add directories @var{pathdir} to beginning of search path for object files.
28732If the @samp{-r} option is used, the search path is reset to the original
28733search path that existed at gdb start-up. If directories @var{pathdir} are
28734supplied in addition to the
28735@samp{-r} option, the search path is first reset and then addition
28736occurs as normal.
28737Multiple directories may be specified, separated by blanks. Specifying
28738multiple directories in a single command
28739results in the directories added to the beginning of the
28740search path in the same order they were presented in the command.
28741If blanks are needed as
28742part of a directory name, double-quotes should be used around
28743the name. In the command output, the path will show up separated
d3e8051b 28744by the system directory-separator character. The directory-separator
a2c02241
NR
28745character must not be used
28746in any directory name.
28747If no directories are specified, the current path is displayed.
28748
922fbb7b
AC
28749
28750@subsubheading @value{GDBN} Command
28751
a2c02241 28752The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
28753
28754@subsubheading Example
28755
922fbb7b 28756@smallexample
594fe323 28757(gdb)
a2c02241
NR
28758-environment-path
28759^done,path="/usr/bin"
594fe323 28760(gdb)
a2c02241
NR
28761-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
28762^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 28763(gdb)
a2c02241
NR
28764-environment-path -r /usr/local/bin
28765^done,path="/usr/local/bin:/usr/bin"
594fe323 28766(gdb)
922fbb7b
AC
28767@end smallexample
28768
28769
a2c02241
NR
28770@subheading The @code{-environment-pwd} Command
28771@findex -environment-pwd
922fbb7b
AC
28772
28773@subsubheading Synopsis
28774
28775@smallexample
a2c02241 28776 -environment-pwd
922fbb7b
AC
28777@end smallexample
28778
a2c02241 28779Show the current working directory.
922fbb7b 28780
79a6e687 28781@subsubheading @value{GDBN} Command
922fbb7b 28782
a2c02241 28783The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
28784
28785@subsubheading Example
28786
922fbb7b 28787@smallexample
594fe323 28788(gdb)
a2c02241
NR
28789-environment-pwd
28790^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 28791(gdb)
922fbb7b
AC
28792@end smallexample
28793
a2c02241
NR
28794@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28795@node GDB/MI Thread Commands
28796@section @sc{gdb/mi} Thread Commands
28797
28798
28799@subheading The @code{-thread-info} Command
28800@findex -thread-info
922fbb7b
AC
28801
28802@subsubheading Synopsis
28803
28804@smallexample
8e8901c5 28805 -thread-info [ @var{thread-id} ]
922fbb7b
AC
28806@end smallexample
28807
5d5658a1
PA
28808Reports information about either a specific thread, if the
28809@var{thread-id} parameter is present, or about all threads.
28810@var{thread-id} is the thread's global thread ID. When printing
28811information about all threads, also reports the global ID of the
28812current thread.
8e8901c5 28813
79a6e687 28814@subsubheading @value{GDBN} Command
922fbb7b 28815
8e8901c5
VP
28816The @samp{info thread} command prints the same information
28817about all threads.
922fbb7b 28818
4694da01 28819@subsubheading Result
922fbb7b 28820
ebe553db 28821The result contains the following attributes:
4694da01
TT
28822
28823@table @samp
ebe553db
SM
28824@item threads
28825A list of threads. The format of the elements of the list is described in
28826@ref{GDB/MI Thread Information}.
28827
28828@item current-thread-id
28829The global id of the currently selected thread. This field is omitted if there
28830is no selected thread (for example, when the selected inferior is not running,
28831and therefore has no threads) or if a @var{thread-id} argument was passed to
28832the command.
4694da01
TT
28833
28834@end table
28835
28836@subsubheading Example
28837
28838@smallexample
28839-thread-info
28840^done,threads=[
28841@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
28842 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
28843 args=[]@},state="running"@},
28844@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
28845 frame=@{level="0",addr="0x0804891f",func="foo",
28846 args=[@{name="i",value="10"@}],
28847 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},
28848 state="running"@}],
28849current-thread-id="1"
28850(gdb)
28851@end smallexample
28852
a2c02241
NR
28853@subheading The @code{-thread-list-ids} Command
28854@findex -thread-list-ids
922fbb7b 28855
a2c02241 28856@subsubheading Synopsis
922fbb7b 28857
a2c02241
NR
28858@smallexample
28859 -thread-list-ids
28860@end smallexample
922fbb7b 28861
5d5658a1
PA
28862Produces a list of the currently known global @value{GDBN} thread ids.
28863At the end of the list it also prints the total number of such
28864threads.
922fbb7b 28865
c3b108f7
VP
28866This command is retained for historical reasons, the
28867@code{-thread-info} command should be used instead.
28868
922fbb7b
AC
28869@subsubheading @value{GDBN} Command
28870
a2c02241 28871Part of @samp{info threads} supplies the same information.
922fbb7b
AC
28872
28873@subsubheading Example
28874
922fbb7b 28875@smallexample
594fe323 28876(gdb)
a2c02241
NR
28877-thread-list-ids
28878^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
592375cd 28879current-thread-id="1",number-of-threads="3"
594fe323 28880(gdb)
922fbb7b
AC
28881@end smallexample
28882
a2c02241
NR
28883
28884@subheading The @code{-thread-select} Command
28885@findex -thread-select
922fbb7b
AC
28886
28887@subsubheading Synopsis
28888
28889@smallexample
5d5658a1 28890 -thread-select @var{thread-id}
922fbb7b
AC
28891@end smallexample
28892
5d5658a1
PA
28893Make thread with global thread number @var{thread-id} the current
28894thread. It prints the number of the new current thread, and the
28895topmost frame for that thread.
922fbb7b 28896
c3b108f7
VP
28897This command is deprecated in favor of explicitly using the
28898@samp{--thread} option to each command.
28899
922fbb7b
AC
28900@subsubheading @value{GDBN} Command
28901
a2c02241 28902The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
28903
28904@subsubheading Example
922fbb7b
AC
28905
28906@smallexample
594fe323 28907(gdb)
a2c02241
NR
28908-exec-next
28909^running
594fe323 28910(gdb)
a2c02241
NR
28911*stopped,reason="end-stepping-range",thread-id="2",line="187",
28912file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 28913(gdb)
a2c02241
NR
28914-thread-list-ids
28915^done,
28916thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
28917number-of-threads="3"
594fe323 28918(gdb)
a2c02241
NR
28919-thread-select 3
28920^done,new-thread-id="3",
28921frame=@{level="0",func="vprintf",
28922args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
28923@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
594fe323 28924(gdb)
922fbb7b
AC
28925@end smallexample
28926
5d77fe44
JB
28927@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28928@node GDB/MI Ada Tasking Commands
28929@section @sc{gdb/mi} Ada Tasking Commands
28930
28931@subheading The @code{-ada-task-info} Command
28932@findex -ada-task-info
28933
28934@subsubheading Synopsis
28935
28936@smallexample
28937 -ada-task-info [ @var{task-id} ]
28938@end smallexample
28939
28940Reports information about either a specific Ada task, if the
28941@var{task-id} parameter is present, or about all Ada tasks.
28942
28943@subsubheading @value{GDBN} Command
28944
28945The @samp{info tasks} command prints the same information
28946about all Ada tasks (@pxref{Ada Tasks}).
28947
28948@subsubheading Result
28949
28950The result is a table of Ada tasks. The following columns are
28951defined for each Ada task:
28952
28953@table @samp
28954@item current
28955This field exists only for the current thread. It has the value @samp{*}.
28956
28957@item id
28958The identifier that @value{GDBN} uses to refer to the Ada task.
28959
28960@item task-id
28961The identifier that the target uses to refer to the Ada task.
28962
28963@item thread-id
5d5658a1
PA
28964The global thread identifier of the thread corresponding to the Ada
28965task.
5d77fe44
JB
28966
28967This field should always exist, as Ada tasks are always implemented
28968on top of a thread. But if @value{GDBN} cannot find this corresponding
28969thread for any reason, the field is omitted.
28970
28971@item parent-id
28972This field exists only when the task was created by another task.
28973In this case, it provides the ID of the parent task.
28974
28975@item priority
28976The base priority of the task.
28977
28978@item state
28979The current state of the task. For a detailed description of the
28980possible states, see @ref{Ada Tasks}.
28981
28982@item name
28983The name of the task.
28984
28985@end table
28986
28987@subsubheading Example
28988
28989@smallexample
28990-ada-task-info
28991^done,tasks=@{nr_rows="3",nr_cols="8",
28992hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
28993@{width="3",alignment="1",col_name="id",colhdr="ID"@},
28994@{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
28995@{width="4",alignment="1",col_name="thread-id",colhdr=""@},
28996@{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
28997@{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
28998@{width="22",alignment="-1",col_name="state",colhdr="State"@},
28999@{width="1",alignment="2",col_name="name",colhdr="Name"@}],
29000body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
29001state="Child Termination Wait",name="main_task"@}]@}
29002(gdb)
29003@end smallexample
29004
a2c02241
NR
29005@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29006@node GDB/MI Program Execution
29007@section @sc{gdb/mi} Program Execution
922fbb7b 29008
ef21caaf 29009These are the asynchronous commands which generate the out-of-band
3f94c067 29010record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
29011asynchronously with remote targets and this interaction is mimicked in
29012other cases.
922fbb7b 29013
922fbb7b
AC
29014@subheading The @code{-exec-continue} Command
29015@findex -exec-continue
29016
29017@subsubheading Synopsis
29018
29019@smallexample
540aa8e7 29020 -exec-continue [--reverse] [--all|--thread-group N]
922fbb7b
AC
29021@end smallexample
29022
540aa8e7
MS
29023Resumes the execution of the inferior program, which will continue
29024to execute until it reaches a debugger stop event. If the
29025@samp{--reverse} option is specified, execution resumes in reverse until
29026it reaches a stop event. Stop events may include
29027@itemize @bullet
29028@item
29029breakpoints or watchpoints
29030@item
29031signals or exceptions
29032@item
29033the end of the process (or its beginning under @samp{--reverse})
29034@item
29035the end or beginning of a replay log if one is being used.
29036@end itemize
29037In all-stop mode (@pxref{All-Stop
29038Mode}), may resume only one thread, or all threads, depending on the
29039value of the @samp{scheduler-locking} variable. If @samp{--all} is
a79b8f6e 29040specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
540aa8e7
MS
29041ignored in all-stop mode. If the @samp{--thread-group} options is
29042specified, then all threads in that thread group are resumed.
922fbb7b
AC
29043
29044@subsubheading @value{GDBN} Command
29045
29046The corresponding @value{GDBN} corresponding is @samp{continue}.
29047
29048@subsubheading Example
29049
29050@smallexample
29051-exec-continue
29052^running
594fe323 29053(gdb)
922fbb7b 29054@@Hello world
a47ec5fe
AR
29055*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
29056func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
29057line="13"@}
594fe323 29058(gdb)
922fbb7b
AC
29059@end smallexample
29060
29061
29062@subheading The @code{-exec-finish} Command
29063@findex -exec-finish
29064
29065@subsubheading Synopsis
29066
29067@smallexample
540aa8e7 29068 -exec-finish [--reverse]
922fbb7b
AC
29069@end smallexample
29070
ef21caaf
NR
29071Resumes the execution of the inferior program until the current
29072function is exited. Displays the results returned by the function.
540aa8e7
MS
29073If the @samp{--reverse} option is specified, resumes the reverse
29074execution of the inferior program until the point where current
29075function was called.
922fbb7b
AC
29076
29077@subsubheading @value{GDBN} Command
29078
29079The corresponding @value{GDBN} command is @samp{finish}.
29080
29081@subsubheading Example
29082
29083Function returning @code{void}.
29084
29085@smallexample
29086-exec-finish
29087^running
594fe323 29088(gdb)
922fbb7b
AC
29089@@hello from foo
29090*stopped,reason="function-finished",frame=@{func="main",args=[],
948d5102 29091file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
594fe323 29092(gdb)
922fbb7b
AC
29093@end smallexample
29094
29095Function returning other than @code{void}. The name of the internal
29096@value{GDBN} variable storing the result is printed, together with the
29097value itself.
29098
29099@smallexample
29100-exec-finish
29101^running
594fe323 29102(gdb)
922fbb7b
AC
29103*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
29104args=[@{name="a",value="1"],@{name="b",value="9"@}@},
948d5102 29105file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
922fbb7b 29106gdb-result-var="$1",return-value="0"
594fe323 29107(gdb)
922fbb7b
AC
29108@end smallexample
29109
29110
29111@subheading The @code{-exec-interrupt} Command
29112@findex -exec-interrupt
29113
29114@subsubheading Synopsis
29115
29116@smallexample
c3b108f7 29117 -exec-interrupt [--all|--thread-group N]
922fbb7b
AC
29118@end smallexample
29119
ef21caaf
NR
29120Interrupts the background execution of the target. Note how the token
29121associated with the stop message is the one for the execution command
29122that has been interrupted. The token for the interrupt itself only
29123appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
29124interrupt a non-running program, an error message will be printed.
29125
c3b108f7
VP
29126Note that when asynchronous execution is enabled, this command is
29127asynchronous just like other execution commands. That is, first the
29128@samp{^done} response will be printed, and the target stop will be
29129reported after that using the @samp{*stopped} notification.
29130
29131In non-stop mode, only the context thread is interrupted by default.
a79b8f6e
VP
29132All threads (in all inferiors) will be interrupted if the
29133@samp{--all} option is specified. If the @samp{--thread-group}
29134option is specified, all threads in that group will be interrupted.
c3b108f7 29135
922fbb7b
AC
29136@subsubheading @value{GDBN} Command
29137
29138The corresponding @value{GDBN} command is @samp{interrupt}.
29139
29140@subsubheading Example
29141
29142@smallexample
594fe323 29143(gdb)
922fbb7b
AC
29144111-exec-continue
29145111^running
29146
594fe323 29147(gdb)
922fbb7b
AC
29148222-exec-interrupt
29149222^done
594fe323 29150(gdb)
922fbb7b 29151111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 29152frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
948d5102 29153fullname="/home/foo/bar/try.c",line="13"@}
594fe323 29154(gdb)
922fbb7b 29155
594fe323 29156(gdb)
922fbb7b
AC
29157-exec-interrupt
29158^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 29159(gdb)
922fbb7b
AC
29160@end smallexample
29161
83eba9b7
VP
29162@subheading The @code{-exec-jump} Command
29163@findex -exec-jump
29164
29165@subsubheading Synopsis
29166
29167@smallexample
29168 -exec-jump @var{location}
29169@end smallexample
29170
29171Resumes execution of the inferior program at the location specified by
29172parameter. @xref{Specify Location}, for a description of the
29173different forms of @var{location}.
29174
29175@subsubheading @value{GDBN} Command
29176
29177The corresponding @value{GDBN} command is @samp{jump}.
29178
29179@subsubheading Example
29180
29181@smallexample
29182-exec-jump foo.c:10
29183*running,thread-id="all"
29184^running
29185@end smallexample
29186
922fbb7b
AC
29187
29188@subheading The @code{-exec-next} Command
29189@findex -exec-next
29190
29191@subsubheading Synopsis
29192
29193@smallexample
540aa8e7 29194 -exec-next [--reverse]
922fbb7b
AC
29195@end smallexample
29196
ef21caaf
NR
29197Resumes execution of the inferior program, stopping when the beginning
29198of the next source line is reached.
922fbb7b 29199
540aa8e7
MS
29200If the @samp{--reverse} option is specified, resumes reverse execution
29201of the inferior program, stopping at the beginning of the previous
29202source line. If you issue this command on the first line of a
29203function, it will take you back to the caller of that function, to the
29204source line where the function was called.
29205
29206
922fbb7b
AC
29207@subsubheading @value{GDBN} Command
29208
29209The corresponding @value{GDBN} command is @samp{next}.
29210
29211@subsubheading Example
29212
29213@smallexample
29214-exec-next
29215^running
594fe323 29216(gdb)
922fbb7b 29217*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 29218(gdb)
922fbb7b
AC
29219@end smallexample
29220
29221
29222@subheading The @code{-exec-next-instruction} Command
29223@findex -exec-next-instruction
29224
29225@subsubheading Synopsis
29226
29227@smallexample
540aa8e7 29228 -exec-next-instruction [--reverse]
922fbb7b
AC
29229@end smallexample
29230
ef21caaf
NR
29231Executes one machine instruction. If the instruction is a function
29232call, continues until the function returns. If the program stops at an
29233instruction in the middle of a source line, the address will be
29234printed as well.
922fbb7b 29235
540aa8e7
MS
29236If the @samp{--reverse} option is specified, resumes reverse execution
29237of the inferior program, stopping at the previous instruction. If the
29238previously executed instruction was a return from another function,
29239it will continue to execute in reverse until the call to that function
29240(from the current stack frame) is reached.
29241
922fbb7b
AC
29242@subsubheading @value{GDBN} Command
29243
29244The corresponding @value{GDBN} command is @samp{nexti}.
29245
29246@subsubheading Example
29247
29248@smallexample
594fe323 29249(gdb)
922fbb7b
AC
29250-exec-next-instruction
29251^running
29252
594fe323 29253(gdb)
922fbb7b
AC
29254*stopped,reason="end-stepping-range",
29255addr="0x000100d4",line="5",file="hello.c"
594fe323 29256(gdb)
922fbb7b
AC
29257@end smallexample
29258
29259
29260@subheading The @code{-exec-return} Command
29261@findex -exec-return
29262
29263@subsubheading Synopsis
29264
29265@smallexample
29266 -exec-return
29267@end smallexample
29268
29269Makes current function return immediately. Doesn't execute the inferior.
29270Displays the new current frame.
29271
29272@subsubheading @value{GDBN} Command
29273
29274The corresponding @value{GDBN} command is @samp{return}.
29275
29276@subsubheading Example
29277
29278@smallexample
594fe323 29279(gdb)
922fbb7b
AC
29280200-break-insert callee4
29281200^done,bkpt=@{number="1",addr="0x00010734",
29282file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 29283(gdb)
922fbb7b
AC
29284000-exec-run
29285000^running
594fe323 29286(gdb)
a47ec5fe 29287000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
922fbb7b 29288frame=@{func="callee4",args=[],
76ff342d
DJ
29289file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29290fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 29291(gdb)
922fbb7b
AC
29292205-break-delete
29293205^done
594fe323 29294(gdb)
922fbb7b
AC
29295111-exec-return
29296111^done,frame=@{level="0",func="callee3",
29297args=[@{name="strarg",
29298value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
29299file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29300fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 29301(gdb)
922fbb7b
AC
29302@end smallexample
29303
29304
29305@subheading The @code{-exec-run} Command
29306@findex -exec-run
29307
29308@subsubheading Synopsis
29309
29310@smallexample
5713b9b5 29311 -exec-run [ --all | --thread-group N ] [ --start ]
922fbb7b
AC
29312@end smallexample
29313
ef21caaf
NR
29314Starts execution of the inferior from the beginning. The inferior
29315executes until either a breakpoint is encountered or the program
29316exits. In the latter case the output will include an exit code, if
29317the program has exited exceptionally.
922fbb7b 29318
5713b9b5
JB
29319When neither the @samp{--all} nor the @samp{--thread-group} option
29320is specified, the current inferior is started. If the
a79b8f6e
VP
29321@samp{--thread-group} option is specified, it should refer to a thread
29322group of type @samp{process}, and that thread group will be started.
29323If the @samp{--all} option is specified, then all inferiors will be started.
29324
5713b9b5
JB
29325Using the @samp{--start} option instructs the debugger to stop
29326the execution at the start of the inferior's main subprogram,
29327following the same behavior as the @code{start} command
29328(@pxref{Starting}).
29329
922fbb7b
AC
29330@subsubheading @value{GDBN} Command
29331
29332The corresponding @value{GDBN} command is @samp{run}.
29333
ef21caaf 29334@subsubheading Examples
922fbb7b
AC
29335
29336@smallexample
594fe323 29337(gdb)
922fbb7b
AC
29338-break-insert main
29339^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 29340(gdb)
922fbb7b
AC
29341-exec-run
29342^running
594fe323 29343(gdb)
a47ec5fe 29344*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
76ff342d 29345frame=@{func="main",args=[],file="recursive2.c",
948d5102 29346fullname="/home/foo/bar/recursive2.c",line="4"@}
594fe323 29347(gdb)
922fbb7b
AC
29348@end smallexample
29349
ef21caaf
NR
29350@noindent
29351Program exited normally:
29352
29353@smallexample
594fe323 29354(gdb)
ef21caaf
NR
29355-exec-run
29356^running
594fe323 29357(gdb)
ef21caaf
NR
29358x = 55
29359*stopped,reason="exited-normally"
594fe323 29360(gdb)
ef21caaf
NR
29361@end smallexample
29362
29363@noindent
29364Program exited exceptionally:
29365
29366@smallexample
594fe323 29367(gdb)
ef21caaf
NR
29368-exec-run
29369^running
594fe323 29370(gdb)
ef21caaf
NR
29371x = 55
29372*stopped,reason="exited",exit-code="01"
594fe323 29373(gdb)
ef21caaf
NR
29374@end smallexample
29375
29376Another way the program can terminate is if it receives a signal such as
29377@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
29378
29379@smallexample
594fe323 29380(gdb)
ef21caaf
NR
29381*stopped,reason="exited-signalled",signal-name="SIGINT",
29382signal-meaning="Interrupt"
29383@end smallexample
29384
922fbb7b 29385
a2c02241
NR
29386@c @subheading -exec-signal
29387
29388
29389@subheading The @code{-exec-step} Command
29390@findex -exec-step
922fbb7b
AC
29391
29392@subsubheading Synopsis
29393
29394@smallexample
540aa8e7 29395 -exec-step [--reverse]
922fbb7b
AC
29396@end smallexample
29397
a2c02241
NR
29398Resumes execution of the inferior program, stopping when the beginning
29399of the next source line is reached, if the next source line is not a
29400function call. If it is, stop at the first instruction of the called
540aa8e7
MS
29401function. If the @samp{--reverse} option is specified, resumes reverse
29402execution of the inferior program, stopping at the beginning of the
29403previously executed source line.
922fbb7b
AC
29404
29405@subsubheading @value{GDBN} Command
29406
a2c02241 29407The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
29408
29409@subsubheading Example
29410
29411Stepping into a function:
29412
29413@smallexample
29414-exec-step
29415^running
594fe323 29416(gdb)
922fbb7b
AC
29417*stopped,reason="end-stepping-range",
29418frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 29419@{name="b",value="0"@}],file="recursive2.c",
948d5102 29420fullname="/home/foo/bar/recursive2.c",line="11"@}
594fe323 29421(gdb)
922fbb7b
AC
29422@end smallexample
29423
29424Regular stepping:
29425
29426@smallexample
29427-exec-step
29428^running
594fe323 29429(gdb)
922fbb7b 29430*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 29431(gdb)
922fbb7b
AC
29432@end smallexample
29433
29434
29435@subheading The @code{-exec-step-instruction} Command
29436@findex -exec-step-instruction
29437
29438@subsubheading Synopsis
29439
29440@smallexample
540aa8e7 29441 -exec-step-instruction [--reverse]
922fbb7b
AC
29442@end smallexample
29443
540aa8e7
MS
29444Resumes the inferior which executes one machine instruction. If the
29445@samp{--reverse} option is specified, resumes reverse execution of the
29446inferior program, stopping at the previously executed instruction.
29447The output, once @value{GDBN} has stopped, will vary depending on
29448whether we have stopped in the middle of a source line or not. In the
29449former case, the address at which the program stopped will be printed
29450as well.
922fbb7b
AC
29451
29452@subsubheading @value{GDBN} Command
29453
29454The corresponding @value{GDBN} command is @samp{stepi}.
29455
29456@subsubheading Example
29457
29458@smallexample
594fe323 29459(gdb)
922fbb7b
AC
29460-exec-step-instruction
29461^running
29462
594fe323 29463(gdb)
922fbb7b 29464*stopped,reason="end-stepping-range",
76ff342d 29465frame=@{func="foo",args=[],file="try.c",
948d5102 29466fullname="/home/foo/bar/try.c",line="10"@}
594fe323 29467(gdb)
922fbb7b
AC
29468-exec-step-instruction
29469^running
29470
594fe323 29471(gdb)
922fbb7b 29472*stopped,reason="end-stepping-range",
76ff342d 29473frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
948d5102 29474fullname="/home/foo/bar/try.c",line="10"@}
594fe323 29475(gdb)
922fbb7b
AC
29476@end smallexample
29477
29478
29479@subheading The @code{-exec-until} Command
29480@findex -exec-until
29481
29482@subsubheading Synopsis
29483
29484@smallexample
29485 -exec-until [ @var{location} ]
29486@end smallexample
29487
ef21caaf
NR
29488Executes the inferior until the @var{location} specified in the
29489argument is reached. If there is no argument, the inferior executes
29490until a source line greater than the current one is reached. The
29491reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
29492
29493@subsubheading @value{GDBN} Command
29494
29495The corresponding @value{GDBN} command is @samp{until}.
29496
29497@subsubheading Example
29498
29499@smallexample
594fe323 29500(gdb)
922fbb7b
AC
29501-exec-until recursive2.c:6
29502^running
594fe323 29503(gdb)
922fbb7b
AC
29504x = 55
29505*stopped,reason="location-reached",frame=@{func="main",args=[],
948d5102 29506file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
594fe323 29507(gdb)
922fbb7b
AC
29508@end smallexample
29509
29510@ignore
29511@subheading -file-clear
29512Is this going away????
29513@end ignore
29514
351ff01a 29515@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
29516@node GDB/MI Stack Manipulation
29517@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 29518
1e611234
PM
29519@subheading The @code{-enable-frame-filters} Command
29520@findex -enable-frame-filters
29521
29522@smallexample
29523-enable-frame-filters
29524@end smallexample
29525
29526@value{GDBN} allows Python-based frame filters to affect the output of
29527the MI commands relating to stack traces. As there is no way to
29528implement this in a fully backward-compatible way, a front end must
29529request that this functionality be enabled.
29530
29531Once enabled, this feature cannot be disabled.
29532
29533Note that if Python support has not been compiled into @value{GDBN},
29534this command will still succeed (and do nothing).
922fbb7b 29535
a2c02241
NR
29536@subheading The @code{-stack-info-frame} Command
29537@findex -stack-info-frame
922fbb7b
AC
29538
29539@subsubheading Synopsis
29540
29541@smallexample
a2c02241 29542 -stack-info-frame
922fbb7b
AC
29543@end smallexample
29544
a2c02241 29545Get info on the selected frame.
922fbb7b
AC
29546
29547@subsubheading @value{GDBN} Command
29548
a2c02241
NR
29549The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
29550(without arguments).
922fbb7b
AC
29551
29552@subsubheading Example
29553
29554@smallexample
594fe323 29555(gdb)
a2c02241
NR
29556-stack-info-frame
29557^done,frame=@{level="1",addr="0x0001076c",func="callee3",
29558file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29559fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
594fe323 29560(gdb)
922fbb7b
AC
29561@end smallexample
29562
a2c02241
NR
29563@subheading The @code{-stack-info-depth} Command
29564@findex -stack-info-depth
922fbb7b
AC
29565
29566@subsubheading Synopsis
29567
29568@smallexample
a2c02241 29569 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
29570@end smallexample
29571
a2c02241
NR
29572Return the depth of the stack. If the integer argument @var{max-depth}
29573is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
29574
29575@subsubheading @value{GDBN} Command
29576
a2c02241 29577There's no equivalent @value{GDBN} command.
922fbb7b
AC
29578
29579@subsubheading Example
29580
a2c02241
NR
29581For a stack with frame levels 0 through 11:
29582
922fbb7b 29583@smallexample
594fe323 29584(gdb)
a2c02241
NR
29585-stack-info-depth
29586^done,depth="12"
594fe323 29587(gdb)
a2c02241
NR
29588-stack-info-depth 4
29589^done,depth="4"
594fe323 29590(gdb)
a2c02241
NR
29591-stack-info-depth 12
29592^done,depth="12"
594fe323 29593(gdb)
a2c02241
NR
29594-stack-info-depth 11
29595^done,depth="11"
594fe323 29596(gdb)
a2c02241
NR
29597-stack-info-depth 13
29598^done,depth="12"
594fe323 29599(gdb)
922fbb7b
AC
29600@end smallexample
29601
1e611234 29602@anchor{-stack-list-arguments}
a2c02241
NR
29603@subheading The @code{-stack-list-arguments} Command
29604@findex -stack-list-arguments
922fbb7b
AC
29605
29606@subsubheading Synopsis
29607
29608@smallexample
6211c335 29609 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
a2c02241 29610 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
29611@end smallexample
29612
a2c02241
NR
29613Display a list of the arguments for the frames between @var{low-frame}
29614and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
29615@var{high-frame} are not provided, list the arguments for the whole
29616call stack. If the two arguments are equal, show the single frame
29617at the corresponding level. It is an error if @var{low-frame} is
29618larger than the actual number of frames. On the other hand,
29619@var{high-frame} may be larger than the actual number of frames, in
29620which case only existing frames will be returned.
a2c02241 29621
3afae151
VP
29622If @var{print-values} is 0 or @code{--no-values}, print only the names of
29623the variables; if it is 1 or @code{--all-values}, print also their
29624values; and if it is 2 or @code{--simple-values}, print the name,
29625type and value for simple data types, and the name and type for arrays,
1e611234
PM
29626structures and unions. If the option @code{--no-frame-filters} is
29627supplied, then Python frame filters will not be executed.
29628
6211c335
YQ
29629If the @code{--skip-unavailable} option is specified, arguments that
29630are not available are not listed. Partially available arguments
29631are still displayed, however.
922fbb7b 29632
b3372f91
VP
29633Use of this command to obtain arguments in a single frame is
29634deprecated in favor of the @samp{-stack-list-variables} command.
29635
922fbb7b
AC
29636@subsubheading @value{GDBN} Command
29637
a2c02241
NR
29638@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
29639@samp{gdb_get_args} command which partially overlaps with the
29640functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
29641
29642@subsubheading Example
922fbb7b 29643
a2c02241 29644@smallexample
594fe323 29645(gdb)
a2c02241
NR
29646-stack-list-frames
29647^done,
29648stack=[
29649frame=@{level="0",addr="0x00010734",func="callee4",
29650file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29651fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
29652frame=@{level="1",addr="0x0001076c",func="callee3",
29653file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29654fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
29655frame=@{level="2",addr="0x0001078c",func="callee2",
29656file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29657fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
29658frame=@{level="3",addr="0x000107b4",func="callee1",
29659file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29660fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
29661frame=@{level="4",addr="0x000107e0",func="main",
29662file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29663fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
594fe323 29664(gdb)
a2c02241
NR
29665-stack-list-arguments 0
29666^done,
29667stack-args=[
29668frame=@{level="0",args=[]@},
29669frame=@{level="1",args=[name="strarg"]@},
29670frame=@{level="2",args=[name="intarg",name="strarg"]@},
29671frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
29672frame=@{level="4",args=[]@}]
594fe323 29673(gdb)
a2c02241
NR
29674-stack-list-arguments 1
29675^done,
29676stack-args=[
29677frame=@{level="0",args=[]@},
29678frame=@{level="1",
29679 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
29680frame=@{level="2",args=[
29681@{name="intarg",value="2"@},
29682@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
29683@{frame=@{level="3",args=[
29684@{name="intarg",value="2"@},
29685@{name="strarg",value="0x11940 \"A string argument.\""@},
29686@{name="fltarg",value="3.5"@}]@},
29687frame=@{level="4",args=[]@}]
594fe323 29688(gdb)
a2c02241
NR
29689-stack-list-arguments 0 2 2
29690^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 29691(gdb)
a2c02241
NR
29692-stack-list-arguments 1 2 2
29693^done,stack-args=[frame=@{level="2",
29694args=[@{name="intarg",value="2"@},
29695@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 29696(gdb)
a2c02241
NR
29697@end smallexample
29698
29699@c @subheading -stack-list-exception-handlers
922fbb7b 29700
a2c02241 29701
1e611234 29702@anchor{-stack-list-frames}
a2c02241
NR
29703@subheading The @code{-stack-list-frames} Command
29704@findex -stack-list-frames
1abaf70c
BR
29705
29706@subsubheading Synopsis
29707
29708@smallexample
1e611234 29709 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
1abaf70c
BR
29710@end smallexample
29711
a2c02241
NR
29712List the frames currently on the stack. For each frame it displays the
29713following info:
29714
29715@table @samp
29716@item @var{level}
d3e8051b 29717The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
29718@item @var{addr}
29719The @code{$pc} value for that frame.
29720@item @var{func}
29721Function name.
29722@item @var{file}
29723File name of the source file where the function lives.
7d288aaa
TT
29724@item @var{fullname}
29725The full file name of the source file where the function lives.
a2c02241
NR
29726@item @var{line}
29727Line number corresponding to the @code{$pc}.
7d288aaa
TT
29728@item @var{from}
29729The shared library where this function is defined. This is only given
29730if the frame's function is not known.
a2c02241
NR
29731@end table
29732
29733If invoked without arguments, this command prints a backtrace for the
29734whole stack. If given two integer arguments, it shows the frames whose
29735levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
29736are equal, it shows the single frame at the corresponding level. It is
29737an error if @var{low-frame} is larger than the actual number of
a5451f4e 29738frames. On the other hand, @var{high-frame} may be larger than the
1e611234
PM
29739actual number of frames, in which case only existing frames will be
29740returned. If the option @code{--no-frame-filters} is supplied, then
29741Python frame filters will not be executed.
1abaf70c
BR
29742
29743@subsubheading @value{GDBN} Command
29744
a2c02241 29745The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
29746
29747@subsubheading Example
29748
a2c02241
NR
29749Full stack backtrace:
29750
1abaf70c 29751@smallexample
594fe323 29752(gdb)
a2c02241
NR
29753-stack-list-frames
29754^done,stack=
29755[frame=@{level="0",addr="0x0001076c",func="foo",
29756 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
29757frame=@{level="1",addr="0x000107a4",func="foo",
29758 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29759frame=@{level="2",addr="0x000107a4",func="foo",
29760 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29761frame=@{level="3",addr="0x000107a4",func="foo",
29762 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29763frame=@{level="4",addr="0x000107a4",func="foo",
29764 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29765frame=@{level="5",addr="0x000107a4",func="foo",
29766 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29767frame=@{level="6",addr="0x000107a4",func="foo",
29768 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29769frame=@{level="7",addr="0x000107a4",func="foo",
29770 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29771frame=@{level="8",addr="0x000107a4",func="foo",
29772 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29773frame=@{level="9",addr="0x000107a4",func="foo",
29774 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29775frame=@{level="10",addr="0x000107a4",func="foo",
29776 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29777frame=@{level="11",addr="0x00010738",func="main",
29778 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
594fe323 29779(gdb)
1abaf70c
BR
29780@end smallexample
29781
a2c02241 29782Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 29783
a2c02241 29784@smallexample
594fe323 29785(gdb)
a2c02241
NR
29786-stack-list-frames 3 5
29787^done,stack=
29788[frame=@{level="3",addr="0x000107a4",func="foo",
29789 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29790frame=@{level="4",addr="0x000107a4",func="foo",
29791 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29792frame=@{level="5",addr="0x000107a4",func="foo",
29793 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 29794(gdb)
a2c02241 29795@end smallexample
922fbb7b 29796
a2c02241 29797Show a single frame:
922fbb7b
AC
29798
29799@smallexample
594fe323 29800(gdb)
a2c02241
NR
29801-stack-list-frames 3 3
29802^done,stack=
29803[frame=@{level="3",addr="0x000107a4",func="foo",
29804 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 29805(gdb)
922fbb7b
AC
29806@end smallexample
29807
922fbb7b 29808
a2c02241
NR
29809@subheading The @code{-stack-list-locals} Command
29810@findex -stack-list-locals
1e611234 29811@anchor{-stack-list-locals}
57c22c6c 29812
a2c02241 29813@subsubheading Synopsis
922fbb7b
AC
29814
29815@smallexample
6211c335 29816 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
922fbb7b
AC
29817@end smallexample
29818
a2c02241
NR
29819Display the local variable names for the selected frame. If
29820@var{print-values} is 0 or @code{--no-values}, print only the names of
29821the variables; if it is 1 or @code{--all-values}, print also their
29822values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 29823type and value for simple data types, and the name and type for arrays,
a2c02241
NR
29824structures and unions. In this last case, a frontend can immediately
29825display the value of simple data types and create variable objects for
d3e8051b 29826other data types when the user wishes to explore their values in
1e611234
PM
29827more detail. If the option @code{--no-frame-filters} is supplied, then
29828Python frame filters will not be executed.
922fbb7b 29829
6211c335
YQ
29830If the @code{--skip-unavailable} option is specified, local variables
29831that are not available are not listed. Partially available local
29832variables are still displayed, however.
29833
b3372f91
VP
29834This command is deprecated in favor of the
29835@samp{-stack-list-variables} command.
29836
922fbb7b
AC
29837@subsubheading @value{GDBN} Command
29838
a2c02241 29839@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
29840
29841@subsubheading Example
922fbb7b
AC
29842
29843@smallexample
594fe323 29844(gdb)
a2c02241
NR
29845-stack-list-locals 0
29846^done,locals=[name="A",name="B",name="C"]
594fe323 29847(gdb)
a2c02241
NR
29848-stack-list-locals --all-values
29849^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
29850 @{name="C",value="@{1, 2, 3@}"@}]
29851-stack-list-locals --simple-values
29852^done,locals=[@{name="A",type="int",value="1"@},
29853 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 29854(gdb)
922fbb7b
AC
29855@end smallexample
29856
1e611234 29857@anchor{-stack-list-variables}
b3372f91
VP
29858@subheading The @code{-stack-list-variables} Command
29859@findex -stack-list-variables
29860
29861@subsubheading Synopsis
29862
29863@smallexample
6211c335 29864 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
b3372f91
VP
29865@end smallexample
29866
29867Display the names of local variables and function arguments for the selected frame. If
29868@var{print-values} is 0 or @code{--no-values}, print only the names of
29869the variables; if it is 1 or @code{--all-values}, print also their
29870values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 29871type and value for simple data types, and the name and type for arrays,
1e611234
PM
29872structures and unions. If the option @code{--no-frame-filters} is
29873supplied, then Python frame filters will not be executed.
b3372f91 29874
6211c335
YQ
29875If the @code{--skip-unavailable} option is specified, local variables
29876and arguments that are not available are not listed. Partially
29877available arguments and local variables are still displayed, however.
29878
b3372f91
VP
29879@subsubheading Example
29880
29881@smallexample
29882(gdb)
29883-stack-list-variables --thread 1 --frame 0 --all-values
4f412fd0 29884^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
b3372f91
VP
29885(gdb)
29886@end smallexample
29887
922fbb7b 29888
a2c02241
NR
29889@subheading The @code{-stack-select-frame} Command
29890@findex -stack-select-frame
922fbb7b
AC
29891
29892@subsubheading Synopsis
29893
29894@smallexample
a2c02241 29895 -stack-select-frame @var{framenum}
922fbb7b
AC
29896@end smallexample
29897
a2c02241
NR
29898Change the selected frame. Select a different frame @var{framenum} on
29899the stack.
922fbb7b 29900
c3b108f7
VP
29901This command in deprecated in favor of passing the @samp{--frame}
29902option to every command.
29903
922fbb7b
AC
29904@subsubheading @value{GDBN} Command
29905
a2c02241
NR
29906The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
29907@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
29908
29909@subsubheading Example
29910
29911@smallexample
594fe323 29912(gdb)
a2c02241 29913-stack-select-frame 2
922fbb7b 29914^done
594fe323 29915(gdb)
922fbb7b
AC
29916@end smallexample
29917
29918@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
29919@node GDB/MI Variable Objects
29920@section @sc{gdb/mi} Variable Objects
922fbb7b 29921
a1b5960f 29922@ignore
922fbb7b 29923
a2c02241 29924@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 29925
a2c02241
NR
29926For the implementation of a variable debugger window (locals, watched
29927expressions, etc.), we are proposing the adaptation of the existing code
29928used by @code{Insight}.
922fbb7b 29929
a2c02241 29930The two main reasons for that are:
922fbb7b 29931
a2c02241
NR
29932@enumerate 1
29933@item
29934It has been proven in practice (it is already on its second generation).
922fbb7b 29935
a2c02241
NR
29936@item
29937It will shorten development time (needless to say how important it is
29938now).
29939@end enumerate
922fbb7b 29940
a2c02241
NR
29941The original interface was designed to be used by Tcl code, so it was
29942slightly changed so it could be used through @sc{gdb/mi}. This section
29943describes the @sc{gdb/mi} operations that will be available and gives some
29944hints about their use.
922fbb7b 29945
a2c02241
NR
29946@emph{Note}: In addition to the set of operations described here, we
29947expect the @sc{gui} implementation of a variable window to require, at
29948least, the following operations:
922fbb7b 29949
a2c02241
NR
29950@itemize @bullet
29951@item @code{-gdb-show} @code{output-radix}
29952@item @code{-stack-list-arguments}
29953@item @code{-stack-list-locals}
29954@item @code{-stack-select-frame}
29955@end itemize
922fbb7b 29956
a1b5960f
VP
29957@end ignore
29958
c8b2f53c 29959@subheading Introduction to Variable Objects
922fbb7b 29960
a2c02241 29961@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
29962
29963Variable objects are "object-oriented" MI interface for examining and
29964changing values of expressions. Unlike some other MI interfaces that
29965work with expressions, variable objects are specifically designed for
29966simple and efficient presentation in the frontend. A variable object
29967is identified by string name. When a variable object is created, the
29968frontend specifies the expression for that variable object. The
29969expression can be a simple variable, or it can be an arbitrary complex
29970expression, and can even involve CPU registers. After creating a
29971variable object, the frontend can invoke other variable object
29972operations---for example to obtain or change the value of a variable
29973object, or to change display format.
29974
29975Variable objects have hierarchical tree structure. Any variable object
29976that corresponds to a composite type, such as structure in C, has
29977a number of child variable objects, for example corresponding to each
29978element of a structure. A child variable object can itself have
29979children, recursively. Recursion ends when we reach
25d5ea92
VP
29980leaf variable objects, which always have built-in types. Child variable
29981objects are created only by explicit request, so if a frontend
29982is not interested in the children of a particular variable object, no
29983child will be created.
c8b2f53c
VP
29984
29985For a leaf variable object it is possible to obtain its value as a
29986string, or set the value from a string. String value can be also
29987obtained for a non-leaf variable object, but it's generally a string
29988that only indicates the type of the object, and does not list its
29989contents. Assignment to a non-leaf variable object is not allowed.
29990
29991A frontend does not need to read the values of all variable objects each time
29992the program stops. Instead, MI provides an update command that lists all
29993variable objects whose values has changed since the last update
29994operation. This considerably reduces the amount of data that must
25d5ea92
VP
29995be transferred to the frontend. As noted above, children variable
29996objects are created on demand, and only leaf variable objects have a
29997real value. As result, gdb will read target memory only for leaf
29998variables that frontend has created.
29999
30000The automatic update is not always desirable. For example, a frontend
30001might want to keep a value of some expression for future reference,
30002and never update it. For another example, fetching memory is
30003relatively slow for embedded targets, so a frontend might want
30004to disable automatic update for the variables that are either not
30005visible on the screen, or ``closed''. This is possible using so
30006called ``frozen variable objects''. Such variable objects are never
30007implicitly updated.
922fbb7b 30008
c3b108f7
VP
30009Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
30010fixed variable object, the expression is parsed when the variable
30011object is created, including associating identifiers to specific
30012variables. The meaning of expression never changes. For a floating
30013variable object the values of variables whose names appear in the
30014expressions are re-evaluated every time in the context of the current
30015frame. Consider this example:
30016
30017@smallexample
30018void do_work(...)
30019@{
30020 struct work_state state;
30021
30022 if (...)
30023 do_work(...);
30024@}
30025@end smallexample
30026
30027If a fixed variable object for the @code{state} variable is created in
7a9dd1b2 30028this function, and we enter the recursive call, the variable
c3b108f7
VP
30029object will report the value of @code{state} in the top-level
30030@code{do_work} invocation. On the other hand, a floating variable
30031object will report the value of @code{state} in the current frame.
30032
30033If an expression specified when creating a fixed variable object
30034refers to a local variable, the variable object becomes bound to the
30035thread and frame in which the variable object is created. When such
30036variable object is updated, @value{GDBN} makes sure that the
30037thread/frame combination the variable object is bound to still exists,
30038and re-evaluates the variable object in context of that thread/frame.
30039
a2c02241
NR
30040The following is the complete set of @sc{gdb/mi} operations defined to
30041access this functionality:
922fbb7b 30042
a2c02241
NR
30043@multitable @columnfractions .4 .6
30044@item @strong{Operation}
30045@tab @strong{Description}
922fbb7b 30046
0cc7d26f
TT
30047@item @code{-enable-pretty-printing}
30048@tab enable Python-based pretty-printing
a2c02241
NR
30049@item @code{-var-create}
30050@tab create a variable object
30051@item @code{-var-delete}
22d8a470 30052@tab delete the variable object and/or its children
a2c02241
NR
30053@item @code{-var-set-format}
30054@tab set the display format of this variable
30055@item @code{-var-show-format}
30056@tab show the display format of this variable
30057@item @code{-var-info-num-children}
30058@tab tells how many children this object has
30059@item @code{-var-list-children}
30060@tab return a list of the object's children
30061@item @code{-var-info-type}
30062@tab show the type of this variable object
30063@item @code{-var-info-expression}
02142340
VP
30064@tab print parent-relative expression that this variable object represents
30065@item @code{-var-info-path-expression}
30066@tab print full expression that this variable object represents
a2c02241
NR
30067@item @code{-var-show-attributes}
30068@tab is this variable editable? does it exist here?
30069@item @code{-var-evaluate-expression}
30070@tab get the value of this variable
30071@item @code{-var-assign}
30072@tab set the value of this variable
30073@item @code{-var-update}
30074@tab update the variable and its children
25d5ea92
VP
30075@item @code{-var-set-frozen}
30076@tab set frozeness attribute
0cc7d26f
TT
30077@item @code{-var-set-update-range}
30078@tab set range of children to display on update
a2c02241 30079@end multitable
922fbb7b 30080
a2c02241
NR
30081In the next subsection we describe each operation in detail and suggest
30082how it can be used.
922fbb7b 30083
a2c02241 30084@subheading Description And Use of Operations on Variable Objects
922fbb7b 30085
0cc7d26f
TT
30086@subheading The @code{-enable-pretty-printing} Command
30087@findex -enable-pretty-printing
30088
30089@smallexample
30090-enable-pretty-printing
30091@end smallexample
30092
30093@value{GDBN} allows Python-based visualizers to affect the output of the
30094MI variable object commands. However, because there was no way to
30095implement this in a fully backward-compatible way, a front end must
30096request that this functionality be enabled.
30097
30098Once enabled, this feature cannot be disabled.
30099
30100Note that if Python support has not been compiled into @value{GDBN},
30101this command will still succeed (and do nothing).
30102
f43030c4
TT
30103This feature is currently (as of @value{GDBN} 7.0) experimental, and
30104may work differently in future versions of @value{GDBN}.
30105
a2c02241
NR
30106@subheading The @code{-var-create} Command
30107@findex -var-create
ef21caaf 30108
a2c02241 30109@subsubheading Synopsis
ef21caaf 30110
a2c02241
NR
30111@smallexample
30112 -var-create @{@var{name} | "-"@}
c3b108f7 30113 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
a2c02241
NR
30114@end smallexample
30115
30116This operation creates a variable object, which allows the monitoring of
30117a variable, the result of an expression, a memory cell or a CPU
30118register.
ef21caaf 30119
a2c02241
NR
30120The @var{name} parameter is the string by which the object can be
30121referenced. It must be unique. If @samp{-} is specified, the varobj
30122system will generate a string ``varNNNNNN'' automatically. It will be
c3b108f7 30123unique provided that one does not specify @var{name} of that format.
a2c02241 30124The command fails if a duplicate name is found.
ef21caaf 30125
a2c02241
NR
30126The frame under which the expression should be evaluated can be
30127specified by @var{frame-addr}. A @samp{*} indicates that the current
c3b108f7
VP
30128frame should be used. A @samp{@@} indicates that a floating variable
30129object must be created.
922fbb7b 30130
a2c02241
NR
30131@var{expression} is any expression valid on the current language set (must not
30132begin with a @samp{*}), or one of the following:
922fbb7b 30133
a2c02241
NR
30134@itemize @bullet
30135@item
30136@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 30137
a2c02241
NR
30138@item
30139@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 30140
a2c02241
NR
30141@item
30142@samp{$@var{regname}} --- a CPU register name
30143@end itemize
922fbb7b 30144
0cc7d26f
TT
30145@cindex dynamic varobj
30146A varobj's contents may be provided by a Python-based pretty-printer. In this
30147case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
30148have slightly different semantics in some cases. If the
30149@code{-enable-pretty-printing} command is not sent, then @value{GDBN}
30150will never create a dynamic varobj. This ensures backward
30151compatibility for existing clients.
30152
a2c02241 30153@subsubheading Result
922fbb7b 30154
0cc7d26f
TT
30155This operation returns attributes of the newly-created varobj. These
30156are:
30157
30158@table @samp
30159@item name
30160The name of the varobj.
30161
30162@item numchild
30163The number of children of the varobj. This number is not necessarily
30164reliable for a dynamic varobj. Instead, you must examine the
30165@samp{has_more} attribute.
30166
30167@item value
30168The varobj's scalar value. For a varobj whose type is some sort of
30169aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
30170will not be interesting.
30171
30172@item type
30173The varobj's type. This is a string representation of the type, as
8264ba82
AG
30174would be printed by the @value{GDBN} CLI. If @samp{print object}
30175(@pxref{Print Settings, set print object}) is set to @code{on}, the
30176@emph{actual} (derived) type of the object is shown rather than the
30177@emph{declared} one.
0cc7d26f
TT
30178
30179@item thread-id
30180If a variable object is bound to a specific thread, then this is the
5d5658a1 30181thread's global identifier.
0cc7d26f
TT
30182
30183@item has_more
30184For a dynamic varobj, this indicates whether there appear to be any
30185children available. For a non-dynamic varobj, this will be 0.
30186
30187@item dynamic
30188This attribute will be present and have the value @samp{1} if the
30189varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
30190then this attribute will not be present.
30191
30192@item displayhint
30193A dynamic varobj can supply a display hint to the front end. The
30194value comes directly from the Python pretty-printer object's
4c374409 30195@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
30196@end table
30197
30198Typical output will look like this:
922fbb7b
AC
30199
30200@smallexample
0cc7d26f
TT
30201 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
30202 has_more="@var{has_more}"
dcaaae04
NR
30203@end smallexample
30204
a2c02241
NR
30205
30206@subheading The @code{-var-delete} Command
30207@findex -var-delete
922fbb7b
AC
30208
30209@subsubheading Synopsis
30210
30211@smallexample
22d8a470 30212 -var-delete [ -c ] @var{name}
922fbb7b
AC
30213@end smallexample
30214
a2c02241 30215Deletes a previously created variable object and all of its children.
22d8a470 30216With the @samp{-c} option, just deletes the children.
922fbb7b 30217
a2c02241 30218Returns an error if the object @var{name} is not found.
922fbb7b 30219
922fbb7b 30220
a2c02241
NR
30221@subheading The @code{-var-set-format} Command
30222@findex -var-set-format
922fbb7b 30223
a2c02241 30224@subsubheading Synopsis
922fbb7b
AC
30225
30226@smallexample
a2c02241 30227 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
30228@end smallexample
30229
a2c02241
NR
30230Sets the output format for the value of the object @var{name} to be
30231@var{format-spec}.
30232
de051565 30233@anchor{-var-set-format}
a2c02241
NR
30234The syntax for the @var{format-spec} is as follows:
30235
30236@smallexample
30237 @var{format-spec} @expansion{}
1c35a88f 30238 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
a2c02241
NR
30239@end smallexample
30240
c8b2f53c
VP
30241The natural format is the default format choosen automatically
30242based on the variable type (like decimal for an @code{int}, hex
30243for pointers, etc.).
30244
1c35a88f
LM
30245The zero-hexadecimal format has a representation similar to hexadecimal
30246but with padding zeroes to the left of the value. For example, a 32-bit
30247hexadecimal value of 0x1234 would be represented as 0x00001234 in the
30248zero-hexadecimal format.
30249
c8b2f53c
VP
30250For a variable with children, the format is set only on the
30251variable itself, and the children are not affected.
a2c02241
NR
30252
30253@subheading The @code{-var-show-format} Command
30254@findex -var-show-format
922fbb7b
AC
30255
30256@subsubheading Synopsis
30257
30258@smallexample
a2c02241 30259 -var-show-format @var{name}
922fbb7b
AC
30260@end smallexample
30261
a2c02241 30262Returns the format used to display the value of the object @var{name}.
922fbb7b 30263
a2c02241
NR
30264@smallexample
30265 @var{format} @expansion{}
30266 @var{format-spec}
30267@end smallexample
922fbb7b 30268
922fbb7b 30269
a2c02241
NR
30270@subheading The @code{-var-info-num-children} Command
30271@findex -var-info-num-children
30272
30273@subsubheading Synopsis
30274
30275@smallexample
30276 -var-info-num-children @var{name}
30277@end smallexample
30278
30279Returns the number of children of a variable object @var{name}:
30280
30281@smallexample
30282 numchild=@var{n}
30283@end smallexample
30284
0cc7d26f
TT
30285Note that this number is not completely reliable for a dynamic varobj.
30286It will return the current number of children, but more children may
30287be available.
30288
a2c02241
NR
30289
30290@subheading The @code{-var-list-children} Command
30291@findex -var-list-children
30292
30293@subsubheading Synopsis
30294
30295@smallexample
0cc7d26f 30296 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
a2c02241 30297@end smallexample
b569d230 30298@anchor{-var-list-children}
a2c02241
NR
30299
30300Return a list of the children of the specified variable object and
30301create variable objects for them, if they do not already exist. With
f5011d11 30302a single argument or if @var{print-values} has a value of 0 or
a2c02241
NR
30303@code{--no-values}, print only the names of the variables; if
30304@var{print-values} is 1 or @code{--all-values}, also print their
30305values; and if it is 2 or @code{--simple-values} print the name and
30306value for simple data types and just the name for arrays, structures
30307and unions.
922fbb7b 30308
0cc7d26f
TT
30309@var{from} and @var{to}, if specified, indicate the range of children
30310to report. If @var{from} or @var{to} is less than zero, the range is
30311reset and all children will be reported. Otherwise, children starting
30312at @var{from} (zero-based) and up to and excluding @var{to} will be
30313reported.
30314
30315If a child range is requested, it will only affect the current call to
30316@code{-var-list-children}, but not future calls to @code{-var-update}.
30317For this, you must instead use @code{-var-set-update-range}. The
30318intent of this approach is to enable a front end to implement any
30319update approach it likes; for example, scrolling a view may cause the
30320front end to request more children with @code{-var-list-children}, and
30321then the front end could call @code{-var-set-update-range} with a
30322different range to ensure that future updates are restricted to just
30323the visible items.
30324
b569d230
EZ
30325For each child the following results are returned:
30326
30327@table @var
30328
30329@item name
30330Name of the variable object created for this child.
30331
30332@item exp
30333The expression to be shown to the user by the front end to designate this child.
30334For example this may be the name of a structure member.
30335
0cc7d26f
TT
30336For a dynamic varobj, this value cannot be used to form an
30337expression. There is no way to do this at all with a dynamic varobj.
30338
b569d230
EZ
30339For C/C@t{++} structures there are several pseudo children returned to
30340designate access qualifiers. For these pseudo children @var{exp} is
30341@samp{public}, @samp{private}, or @samp{protected}. In this case the
30342type and value are not present.
30343
0cc7d26f
TT
30344A dynamic varobj will not report the access qualifying
30345pseudo-children, regardless of the language. This information is not
30346available at all with a dynamic varobj.
30347
b569d230 30348@item numchild
0cc7d26f
TT
30349Number of children this child has. For a dynamic varobj, this will be
303500.
b569d230
EZ
30351
30352@item type
8264ba82
AG
30353The type of the child. If @samp{print object}
30354(@pxref{Print Settings, set print object}) is set to @code{on}, the
30355@emph{actual} (derived) type of the object is shown rather than the
30356@emph{declared} one.
b569d230
EZ
30357
30358@item value
30359If values were requested, this is the value.
30360
30361@item thread-id
5d5658a1
PA
30362If this variable object is associated with a thread, this is the
30363thread's global thread id. Otherwise this result is not present.
b569d230
EZ
30364
30365@item frozen
30366If the variable object is frozen, this variable will be present with a value of 1.
c78feb39 30367
9df9dbe0
YQ
30368@item displayhint
30369A dynamic varobj can supply a display hint to the front end. The
30370value comes directly from the Python pretty-printer object's
30371@code{display_hint} method. @xref{Pretty Printing API}.
30372
c78feb39
YQ
30373@item dynamic
30374This attribute will be present and have the value @samp{1} if the
30375varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
30376then this attribute will not be present.
30377
b569d230
EZ
30378@end table
30379
0cc7d26f
TT
30380The result may have its own attributes:
30381
30382@table @samp
30383@item displayhint
30384A dynamic varobj can supply a display hint to the front end. The
30385value comes directly from the Python pretty-printer object's
4c374409 30386@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
30387
30388@item has_more
30389This is an integer attribute which is nonzero if there are children
30390remaining after the end of the selected range.
30391@end table
30392
922fbb7b
AC
30393@subsubheading Example
30394
30395@smallexample
594fe323 30396(gdb)
a2c02241 30397 -var-list-children n
b569d230 30398 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 30399 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 30400(gdb)
a2c02241 30401 -var-list-children --all-values n
b569d230 30402 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 30403 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
30404@end smallexample
30405
922fbb7b 30406
a2c02241
NR
30407@subheading The @code{-var-info-type} Command
30408@findex -var-info-type
922fbb7b 30409
a2c02241
NR
30410@subsubheading Synopsis
30411
30412@smallexample
30413 -var-info-type @var{name}
30414@end smallexample
30415
30416Returns the type of the specified variable @var{name}. The type is
30417returned as a string in the same format as it is output by the
30418@value{GDBN} CLI:
30419
30420@smallexample
30421 type=@var{typename}
30422@end smallexample
30423
30424
30425@subheading The @code{-var-info-expression} Command
30426@findex -var-info-expression
922fbb7b
AC
30427
30428@subsubheading Synopsis
30429
30430@smallexample
a2c02241 30431 -var-info-expression @var{name}
922fbb7b
AC
30432@end smallexample
30433
02142340
VP
30434Returns a string that is suitable for presenting this
30435variable object in user interface. The string is generally
30436not valid expression in the current language, and cannot be evaluated.
30437
30438For example, if @code{a} is an array, and variable object
30439@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 30440
a2c02241 30441@smallexample
02142340
VP
30442(gdb) -var-info-expression A.1
30443^done,lang="C",exp="1"
a2c02241 30444@end smallexample
922fbb7b 30445
a2c02241 30446@noindent
fa4d0c40
YQ
30447Here, the value of @code{lang} is the language name, which can be
30448found in @ref{Supported Languages}.
02142340
VP
30449
30450Note that the output of the @code{-var-list-children} command also
30451includes those expressions, so the @code{-var-info-expression} command
30452is of limited use.
30453
30454@subheading The @code{-var-info-path-expression} Command
30455@findex -var-info-path-expression
30456
30457@subsubheading Synopsis
30458
30459@smallexample
30460 -var-info-path-expression @var{name}
30461@end smallexample
30462
30463Returns an expression that can be evaluated in the current
30464context and will yield the same value that a variable object has.
30465Compare this with the @code{-var-info-expression} command, which
30466result can be used only for UI presentation. Typical use of
30467the @code{-var-info-path-expression} command is creating a
30468watchpoint from a variable object.
30469
0cc7d26f
TT
30470This command is currently not valid for children of a dynamic varobj,
30471and will give an error when invoked on one.
30472
02142340
VP
30473For example, suppose @code{C} is a C@t{++} class, derived from class
30474@code{Base}, and that the @code{Base} class has a member called
30475@code{m_size}. Assume a variable @code{c} is has the type of
30476@code{C} and a variable object @code{C} was created for variable
30477@code{c}. Then, we'll get this output:
30478@smallexample
30479(gdb) -var-info-path-expression C.Base.public.m_size
30480^done,path_expr=((Base)c).m_size)
30481@end smallexample
922fbb7b 30482
a2c02241
NR
30483@subheading The @code{-var-show-attributes} Command
30484@findex -var-show-attributes
922fbb7b 30485
a2c02241 30486@subsubheading Synopsis
922fbb7b 30487
a2c02241
NR
30488@smallexample
30489 -var-show-attributes @var{name}
30490@end smallexample
922fbb7b 30491
a2c02241 30492List attributes of the specified variable object @var{name}:
922fbb7b
AC
30493
30494@smallexample
a2c02241 30495 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
30496@end smallexample
30497
a2c02241
NR
30498@noindent
30499where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
30500
30501@subheading The @code{-var-evaluate-expression} Command
30502@findex -var-evaluate-expression
30503
30504@subsubheading Synopsis
30505
30506@smallexample
de051565 30507 -var-evaluate-expression [-f @var{format-spec}] @var{name}
a2c02241
NR
30508@end smallexample
30509
30510Evaluates the expression that is represented by the specified variable
de051565
MK
30511object and returns its value as a string. The format of the string
30512can be specified with the @samp{-f} option. The possible values of
30513this option are the same as for @code{-var-set-format}
30514(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
30515the current display format will be used. The current display format
30516can be changed using the @code{-var-set-format} command.
a2c02241
NR
30517
30518@smallexample
30519 value=@var{value}
30520@end smallexample
30521
30522Note that one must invoke @code{-var-list-children} for a variable
30523before the value of a child variable can be evaluated.
30524
30525@subheading The @code{-var-assign} Command
30526@findex -var-assign
30527
30528@subsubheading Synopsis
30529
30530@smallexample
30531 -var-assign @var{name} @var{expression}
30532@end smallexample
30533
30534Assigns the value of @var{expression} to the variable object specified
30535by @var{name}. The object must be @samp{editable}. If the variable's
30536value is altered by the assign, the variable will show up in any
30537subsequent @code{-var-update} list.
30538
30539@subsubheading Example
922fbb7b
AC
30540
30541@smallexample
594fe323 30542(gdb)
a2c02241
NR
30543-var-assign var1 3
30544^done,value="3"
594fe323 30545(gdb)
a2c02241
NR
30546-var-update *
30547^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 30548(gdb)
922fbb7b
AC
30549@end smallexample
30550
a2c02241
NR
30551@subheading The @code{-var-update} Command
30552@findex -var-update
30553
30554@subsubheading Synopsis
30555
30556@smallexample
30557 -var-update [@var{print-values}] @{@var{name} | "*"@}
30558@end smallexample
30559
c8b2f53c
VP
30560Reevaluate the expressions corresponding to the variable object
30561@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
30562list of variable objects whose values have changed; @var{name} must
30563be a root variable object. Here, ``changed'' means that the result of
30564@code{-var-evaluate-expression} before and after the
30565@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
30566object names, all existing variable objects are updated, except
30567for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3 30568@var{print-values} determines whether both names and values, or just
de051565 30569names are printed. The possible values of this option are the same
36ece8b3
NR
30570as for @code{-var-list-children} (@pxref{-var-list-children}). It is
30571recommended to use the @samp{--all-values} option, to reduce the
30572number of MI commands needed on each program stop.
c8b2f53c 30573
c3b108f7
VP
30574With the @samp{*} parameter, if a variable object is bound to a
30575currently running thread, it will not be updated, without any
30576diagnostic.
a2c02241 30577
0cc7d26f
TT
30578If @code{-var-set-update-range} was previously used on a varobj, then
30579only the selected range of children will be reported.
922fbb7b 30580
0cc7d26f
TT
30581@code{-var-update} reports all the changed varobjs in a tuple named
30582@samp{changelist}.
30583
30584Each item in the change list is itself a tuple holding:
30585
30586@table @samp
30587@item name
30588The name of the varobj.
30589
30590@item value
30591If values were requested for this update, then this field will be
30592present and will hold the value of the varobj.
922fbb7b 30593
0cc7d26f 30594@item in_scope
9f708cb2 30595@anchor{-var-update}
0cc7d26f 30596This field is a string which may take one of three values:
36ece8b3
NR
30597
30598@table @code
30599@item "true"
30600The variable object's current value is valid.
30601
30602@item "false"
30603The variable object does not currently hold a valid value but it may
30604hold one in the future if its associated expression comes back into
30605scope.
30606
30607@item "invalid"
30608The variable object no longer holds a valid value.
30609This can occur when the executable file being debugged has changed,
30610either through recompilation or by using the @value{GDBN} @code{file}
30611command. The front end should normally choose to delete these variable
30612objects.
30613@end table
30614
30615In the future new values may be added to this list so the front should
30616be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
30617
0cc7d26f
TT
30618@item type_changed
30619This is only present if the varobj is still valid. If the type
30620changed, then this will be the string @samp{true}; otherwise it will
30621be @samp{false}.
30622
7191c139
JB
30623When a varobj's type changes, its children are also likely to have
30624become incorrect. Therefore, the varobj's children are automatically
30625deleted when this attribute is @samp{true}. Also, the varobj's update
30626range, when set using the @code{-var-set-update-range} command, is
30627unset.
30628
0cc7d26f
TT
30629@item new_type
30630If the varobj's type changed, then this field will be present and will
30631hold the new type.
30632
30633@item new_num_children
30634For a dynamic varobj, if the number of children changed, or if the
30635type changed, this will be the new number of children.
30636
30637The @samp{numchild} field in other varobj responses is generally not
30638valid for a dynamic varobj -- it will show the number of children that
30639@value{GDBN} knows about, but because dynamic varobjs lazily
30640instantiate their children, this will not reflect the number of
30641children which may be available.
30642
30643The @samp{new_num_children} attribute only reports changes to the
30644number of children known by @value{GDBN}. This is the only way to
30645detect whether an update has removed children (which necessarily can
30646only happen at the end of the update range).
30647
30648@item displayhint
30649The display hint, if any.
30650
30651@item has_more
30652This is an integer value, which will be 1 if there are more children
30653available outside the varobj's update range.
30654
30655@item dynamic
30656This attribute will be present and have the value @samp{1} if the
30657varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
30658then this attribute will not be present.
30659
30660@item new_children
30661If new children were added to a dynamic varobj within the selected
30662update range (as set by @code{-var-set-update-range}), then they will
30663be listed in this attribute.
30664@end table
30665
30666@subsubheading Example
30667
30668@smallexample
30669(gdb)
30670-var-assign var1 3
30671^done,value="3"
30672(gdb)
30673-var-update --all-values var1
30674^done,changelist=[@{name="var1",value="3",in_scope="true",
30675type_changed="false"@}]
30676(gdb)
30677@end smallexample
30678
25d5ea92
VP
30679@subheading The @code{-var-set-frozen} Command
30680@findex -var-set-frozen
9f708cb2 30681@anchor{-var-set-frozen}
25d5ea92
VP
30682
30683@subsubheading Synopsis
30684
30685@smallexample
9f708cb2 30686 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
30687@end smallexample
30688
9f708cb2 30689Set the frozenness flag on the variable object @var{name}. The
25d5ea92 30690@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 30691frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 30692frozen, then neither itself, nor any of its children, are
9f708cb2 30693implicitly updated by @code{-var-update} of
25d5ea92
VP
30694a parent variable or by @code{-var-update *}. Only
30695@code{-var-update} of the variable itself will update its value and
30696values of its children. After a variable object is unfrozen, it is
30697implicitly updated by all subsequent @code{-var-update} operations.
30698Unfreezing a variable does not update it, only subsequent
30699@code{-var-update} does.
30700
30701@subsubheading Example
30702
30703@smallexample
30704(gdb)
30705-var-set-frozen V 1
30706^done
30707(gdb)
30708@end smallexample
30709
0cc7d26f
TT
30710@subheading The @code{-var-set-update-range} command
30711@findex -var-set-update-range
30712@anchor{-var-set-update-range}
30713
30714@subsubheading Synopsis
30715
30716@smallexample
30717 -var-set-update-range @var{name} @var{from} @var{to}
30718@end smallexample
30719
30720Set the range of children to be returned by future invocations of
30721@code{-var-update}.
30722
30723@var{from} and @var{to} indicate the range of children to report. If
30724@var{from} or @var{to} is less than zero, the range is reset and all
30725children will be reported. Otherwise, children starting at @var{from}
30726(zero-based) and up to and excluding @var{to} will be reported.
30727
30728@subsubheading Example
30729
30730@smallexample
30731(gdb)
30732-var-set-update-range V 1 2
30733^done
30734@end smallexample
30735
b6313243
TT
30736@subheading The @code{-var-set-visualizer} command
30737@findex -var-set-visualizer
30738@anchor{-var-set-visualizer}
30739
30740@subsubheading Synopsis
30741
30742@smallexample
30743 -var-set-visualizer @var{name} @var{visualizer}
30744@end smallexample
30745
30746Set a visualizer for the variable object @var{name}.
30747
30748@var{visualizer} is the visualizer to use. The special value
30749@samp{None} means to disable any visualizer in use.
30750
30751If not @samp{None}, @var{visualizer} must be a Python expression.
30752This expression must evaluate to a callable object which accepts a
30753single argument. @value{GDBN} will call this object with the value of
30754the varobj @var{name} as an argument (this is done so that the same
30755Python pretty-printing code can be used for both the CLI and MI).
30756When called, this object must return an object which conforms to the
4c374409 30757pretty-printing interface (@pxref{Pretty Printing API}).
b6313243
TT
30758
30759The pre-defined function @code{gdb.default_visualizer} may be used to
30760select a visualizer by following the built-in process
30761(@pxref{Selecting Pretty-Printers}). This is done automatically when
30762a varobj is created, and so ordinarily is not needed.
30763
30764This feature is only available if Python support is enabled. The MI
d192b373 30765command @code{-list-features} (@pxref{GDB/MI Support Commands})
b6313243
TT
30766can be used to check this.
30767
30768@subsubheading Example
30769
30770Resetting the visualizer:
30771
30772@smallexample
30773(gdb)
30774-var-set-visualizer V None
30775^done
30776@end smallexample
30777
30778Reselecting the default (type-based) visualizer:
30779
30780@smallexample
30781(gdb)
30782-var-set-visualizer V gdb.default_visualizer
30783^done
30784@end smallexample
30785
30786Suppose @code{SomeClass} is a visualizer class. A lambda expression
30787can be used to instantiate this class for a varobj:
30788
30789@smallexample
30790(gdb)
30791-var-set-visualizer V "lambda val: SomeClass()"
30792^done
30793@end smallexample
25d5ea92 30794
a2c02241
NR
30795@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30796@node GDB/MI Data Manipulation
30797@section @sc{gdb/mi} Data Manipulation
922fbb7b 30798
a2c02241
NR
30799@cindex data manipulation, in @sc{gdb/mi}
30800@cindex @sc{gdb/mi}, data manipulation
30801This section describes the @sc{gdb/mi} commands that manipulate data:
30802examine memory and registers, evaluate expressions, etc.
30803
a86c90e6
SM
30804For details about what an addressable memory unit is,
30805@pxref{addressable memory unit}.
30806
a2c02241
NR
30807@c REMOVED FROM THE INTERFACE.
30808@c @subheading -data-assign
30809@c Change the value of a program variable. Plenty of side effects.
79a6e687 30810@c @subsubheading GDB Command
a2c02241
NR
30811@c set variable
30812@c @subsubheading Example
30813@c N.A.
30814
30815@subheading The @code{-data-disassemble} Command
30816@findex -data-disassemble
922fbb7b
AC
30817
30818@subsubheading Synopsis
30819
30820@smallexample
a2c02241
NR
30821 -data-disassemble
30822 [ -s @var{start-addr} -e @var{end-addr} ]
30823 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
30824 -- @var{mode}
922fbb7b
AC
30825@end smallexample
30826
a2c02241
NR
30827@noindent
30828Where:
30829
30830@table @samp
30831@item @var{start-addr}
30832is the beginning address (or @code{$pc})
30833@item @var{end-addr}
30834is the end address
30835@item @var{filename}
30836is the name of the file to disassemble
30837@item @var{linenum}
30838is the line number to disassemble around
30839@item @var{lines}
d3e8051b 30840is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
30841the whole function will be disassembled, in case no @var{end-addr} is
30842specified. If @var{end-addr} is specified as a non-zero value, and
30843@var{lines} is lower than the number of disassembly lines between
30844@var{start-addr} and @var{end-addr}, only @var{lines} lines are
30845displayed; if @var{lines} is higher than the number of lines between
30846@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
30847are displayed.
30848@item @var{mode}
6ff0ba5f
DE
30849is one of:
30850@itemize @bullet
30851@item 0 disassembly only
30852@item 1 mixed source and disassembly (deprecated)
30853@item 2 disassembly with raw opcodes
30854@item 3 mixed source and disassembly with raw opcodes (deprecated)
30855@item 4 mixed source and disassembly
30856@item 5 mixed source and disassembly with raw opcodes
30857@end itemize
30858
30859Modes 1 and 3 are deprecated. The output is ``source centric''
30860which hasn't proved useful in practice.
30861@xref{Machine Code}, for a discussion of the difference between
30862@code{/m} and @code{/s} output of the @code{disassemble} command.
a2c02241
NR
30863@end table
30864
30865@subsubheading Result
30866
ed8a1c2d
AB
30867The result of the @code{-data-disassemble} command will be a list named
30868@samp{asm_insns}, the contents of this list depend on the @var{mode}
30869used with the @code{-data-disassemble} command.
a2c02241 30870
ed8a1c2d
AB
30871For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
30872following fields:
30873
30874@table @code
30875@item address
30876The address at which this instruction was disassembled.
30877
30878@item func-name
30879The name of the function this instruction is within.
30880
30881@item offset
30882The decimal offset in bytes from the start of @samp{func-name}.
30883
30884@item inst
30885The text disassembly for this @samp{address}.
30886
30887@item opcodes
6ff0ba5f 30888This field is only present for modes 2, 3 and 5. This contains the raw opcode
ed8a1c2d
AB
30889bytes for the @samp{inst} field.
30890
30891@end table
30892
6ff0ba5f 30893For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
ed8a1c2d 30894@samp{src_and_asm_line}, each of which has the following fields:
a2c02241 30895
ed8a1c2d
AB
30896@table @code
30897@item line
30898The line number within @samp{file}.
30899
30900@item file
30901The file name from the compilation unit. This might be an absolute
30902file name or a relative file name depending on the compile command
30903used.
30904
30905@item fullname
f35a17b5
JK
30906Absolute file name of @samp{file}. It is converted to a canonical form
30907using the source file search path
30908(@pxref{Source Path, ,Specifying Source Directories})
30909and after resolving all the symbolic links.
30910
30911If the source file is not found this field will contain the path as
30912present in the debug information.
ed8a1c2d
AB
30913
30914@item line_asm_insn
30915This is a list of tuples containing the disassembly for @samp{line} in
30916@samp{file}. The fields of each tuple are the same as for
30917@code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
30918@samp{func-name}, @samp{offset}, @samp{inst}, and optionally
30919@samp{opcodes}.
30920
30921@end table
30922
30923Note that whatever included in the @samp{inst} field, is not
30924manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
30925adjust its format.
922fbb7b
AC
30926
30927@subsubheading @value{GDBN} Command
30928
ed8a1c2d 30929The corresponding @value{GDBN} command is @samp{disassemble}.
922fbb7b
AC
30930
30931@subsubheading Example
30932
a2c02241
NR
30933Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
30934
922fbb7b 30935@smallexample
594fe323 30936(gdb)
a2c02241
NR
30937-data-disassemble -s $pc -e "$pc + 20" -- 0
30938^done,
30939asm_insns=[
30940@{address="0x000107c0",func-name="main",offset="4",
30941inst="mov 2, %o0"@},
30942@{address="0x000107c4",func-name="main",offset="8",
30943inst="sethi %hi(0x11800), %o2"@},
30944@{address="0x000107c8",func-name="main",offset="12",
30945inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
30946@{address="0x000107cc",func-name="main",offset="16",
30947inst="sethi %hi(0x11800), %o2"@},
30948@{address="0x000107d0",func-name="main",offset="20",
30949inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 30950(gdb)
a2c02241
NR
30951@end smallexample
30952
30953Disassemble the whole @code{main} function. Line 32 is part of
30954@code{main}.
30955
30956@smallexample
30957-data-disassemble -f basics.c -l 32 -- 0
30958^done,asm_insns=[
30959@{address="0x000107bc",func-name="main",offset="0",
30960inst="save %sp, -112, %sp"@},
30961@{address="0x000107c0",func-name="main",offset="4",
30962inst="mov 2, %o0"@},
30963@{address="0x000107c4",func-name="main",offset="8",
30964inst="sethi %hi(0x11800), %o2"@},
30965[@dots{}]
30966@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
30967@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 30968(gdb)
922fbb7b
AC
30969@end smallexample
30970
a2c02241 30971Disassemble 3 instructions from the start of @code{main}:
922fbb7b 30972
a2c02241 30973@smallexample
594fe323 30974(gdb)
a2c02241
NR
30975-data-disassemble -f basics.c -l 32 -n 3 -- 0
30976^done,asm_insns=[
30977@{address="0x000107bc",func-name="main",offset="0",
30978inst="save %sp, -112, %sp"@},
30979@{address="0x000107c0",func-name="main",offset="4",
30980inst="mov 2, %o0"@},
30981@{address="0x000107c4",func-name="main",offset="8",
30982inst="sethi %hi(0x11800), %o2"@}]
594fe323 30983(gdb)
a2c02241
NR
30984@end smallexample
30985
30986Disassemble 3 instructions from the start of @code{main} in mixed mode:
30987
30988@smallexample
594fe323 30989(gdb)
a2c02241
NR
30990-data-disassemble -f basics.c -l 32 -n 3 -- 1
30991^done,asm_insns=[
30992src_and_asm_line=@{line="31",
ed8a1c2d
AB
30993file="../../../src/gdb/testsuite/gdb.mi/basics.c",
30994fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
30995line_asm_insn=[@{address="0x000107bc",
30996func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
a2c02241 30997src_and_asm_line=@{line="32",
ed8a1c2d
AB
30998file="../../../src/gdb/testsuite/gdb.mi/basics.c",
30999fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
31000line_asm_insn=[@{address="0x000107c0",
31001func-name="main",offset="4",inst="mov 2, %o0"@},
a2c02241
NR
31002@{address="0x000107c4",func-name="main",offset="8",
31003inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 31004(gdb)
a2c02241
NR
31005@end smallexample
31006
31007
31008@subheading The @code{-data-evaluate-expression} Command
31009@findex -data-evaluate-expression
922fbb7b
AC
31010
31011@subsubheading Synopsis
31012
31013@smallexample
a2c02241 31014 -data-evaluate-expression @var{expr}
922fbb7b
AC
31015@end smallexample
31016
a2c02241
NR
31017Evaluate @var{expr} as an expression. The expression could contain an
31018inferior function call. The function call will execute synchronously.
31019If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
31020
31021@subsubheading @value{GDBN} Command
31022
a2c02241
NR
31023The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
31024@samp{call}. In @code{gdbtk} only, there's a corresponding
31025@samp{gdb_eval} command.
922fbb7b
AC
31026
31027@subsubheading Example
31028
a2c02241
NR
31029In the following example, the numbers that precede the commands are the
31030@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
31031Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
31032output.
31033
922fbb7b 31034@smallexample
a2c02241
NR
31035211-data-evaluate-expression A
31036211^done,value="1"
594fe323 31037(gdb)
a2c02241
NR
31038311-data-evaluate-expression &A
31039311^done,value="0xefffeb7c"
594fe323 31040(gdb)
a2c02241
NR
31041411-data-evaluate-expression A+3
31042411^done,value="4"
594fe323 31043(gdb)
a2c02241
NR
31044511-data-evaluate-expression "A + 3"
31045511^done,value="4"
594fe323 31046(gdb)
a2c02241 31047@end smallexample
922fbb7b
AC
31048
31049
a2c02241
NR
31050@subheading The @code{-data-list-changed-registers} Command
31051@findex -data-list-changed-registers
922fbb7b
AC
31052
31053@subsubheading Synopsis
31054
31055@smallexample
a2c02241 31056 -data-list-changed-registers
922fbb7b
AC
31057@end smallexample
31058
a2c02241 31059Display a list of the registers that have changed.
922fbb7b
AC
31060
31061@subsubheading @value{GDBN} Command
31062
a2c02241
NR
31063@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
31064has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
31065
31066@subsubheading Example
922fbb7b 31067
a2c02241 31068On a PPC MBX board:
922fbb7b
AC
31069
31070@smallexample
594fe323 31071(gdb)
a2c02241
NR
31072-exec-continue
31073^running
922fbb7b 31074
594fe323 31075(gdb)
a47ec5fe
AR
31076*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
31077func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
31078line="5"@}
594fe323 31079(gdb)
a2c02241
NR
31080-data-list-changed-registers
31081^done,changed-registers=["0","1","2","4","5","6","7","8","9",
31082"10","11","13","14","15","16","17","18","19","20","21","22","23",
31083"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 31084(gdb)
a2c02241 31085@end smallexample
922fbb7b
AC
31086
31087
a2c02241
NR
31088@subheading The @code{-data-list-register-names} Command
31089@findex -data-list-register-names
922fbb7b
AC
31090
31091@subsubheading Synopsis
31092
31093@smallexample
a2c02241 31094 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
31095@end smallexample
31096
a2c02241
NR
31097Show a list of register names for the current target. If no arguments
31098are given, it shows a list of the names of all the registers. If
31099integer numbers are given as arguments, it will print a list of the
31100names of the registers corresponding to the arguments. To ensure
31101consistency between a register name and its number, the output list may
31102include empty register names.
922fbb7b
AC
31103
31104@subsubheading @value{GDBN} Command
31105
a2c02241
NR
31106@value{GDBN} does not have a command which corresponds to
31107@samp{-data-list-register-names}. In @code{gdbtk} there is a
31108corresponding command @samp{gdb_regnames}.
922fbb7b
AC
31109
31110@subsubheading Example
922fbb7b 31111
a2c02241
NR
31112For the PPC MBX board:
31113@smallexample
594fe323 31114(gdb)
a2c02241
NR
31115-data-list-register-names
31116^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
31117"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
31118"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
31119"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
31120"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
31121"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
31122"", "pc","ps","cr","lr","ctr","xer"]
594fe323 31123(gdb)
a2c02241
NR
31124-data-list-register-names 1 2 3
31125^done,register-names=["r1","r2","r3"]
594fe323 31126(gdb)
a2c02241 31127@end smallexample
922fbb7b 31128
a2c02241
NR
31129@subheading The @code{-data-list-register-values} Command
31130@findex -data-list-register-values
922fbb7b
AC
31131
31132@subsubheading Synopsis
31133
31134@smallexample
c898adb7
YQ
31135 -data-list-register-values
31136 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
31137@end smallexample
31138
697aa1b7
EZ
31139Display the registers' contents. The format according to which the
31140registers' contents are to be returned is given by @var{fmt}, followed
31141by an optional list of numbers specifying the registers to display. A
31142missing list of numbers indicates that the contents of all the
31143registers must be returned. The @code{--skip-unavailable} option
31144indicates that only the available registers are to be returned.
a2c02241
NR
31145
31146Allowed formats for @var{fmt} are:
31147
31148@table @code
31149@item x
31150Hexadecimal
31151@item o
31152Octal
31153@item t
31154Binary
31155@item d
31156Decimal
31157@item r
31158Raw
31159@item N
31160Natural
31161@end table
922fbb7b
AC
31162
31163@subsubheading @value{GDBN} Command
31164
a2c02241
NR
31165The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
31166all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
31167
31168@subsubheading Example
922fbb7b 31169
a2c02241
NR
31170For a PPC MBX board (note: line breaks are for readability only, they
31171don't appear in the actual output):
31172
31173@smallexample
594fe323 31174(gdb)
a2c02241
NR
31175-data-list-register-values r 64 65
31176^done,register-values=[@{number="64",value="0xfe00a300"@},
31177@{number="65",value="0x00029002"@}]
594fe323 31178(gdb)
a2c02241
NR
31179-data-list-register-values x
31180^done,register-values=[@{number="0",value="0xfe0043c8"@},
31181@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
31182@{number="3",value="0x0"@},@{number="4",value="0xa"@},
31183@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
31184@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
31185@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
31186@{number="11",value="0x1"@},@{number="12",value="0x0"@},
31187@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
31188@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
31189@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
31190@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
31191@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
31192@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
31193@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
31194@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
31195@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
31196@{number="31",value="0x0"@},@{number="32",value="0x0"@},
31197@{number="33",value="0x0"@},@{number="34",value="0x0"@},
31198@{number="35",value="0x0"@},@{number="36",value="0x0"@},
31199@{number="37",value="0x0"@},@{number="38",value="0x0"@},
31200@{number="39",value="0x0"@},@{number="40",value="0x0"@},
31201@{number="41",value="0x0"@},@{number="42",value="0x0"@},
31202@{number="43",value="0x0"@},@{number="44",value="0x0"@},
31203@{number="45",value="0x0"@},@{number="46",value="0x0"@},
31204@{number="47",value="0x0"@},@{number="48",value="0x0"@},
31205@{number="49",value="0x0"@},@{number="50",value="0x0"@},
31206@{number="51",value="0x0"@},@{number="52",value="0x0"@},
31207@{number="53",value="0x0"@},@{number="54",value="0x0"@},
31208@{number="55",value="0x0"@},@{number="56",value="0x0"@},
31209@{number="57",value="0x0"@},@{number="58",value="0x0"@},
31210@{number="59",value="0x0"@},@{number="60",value="0x0"@},
31211@{number="61",value="0x0"@},@{number="62",value="0x0"@},
31212@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
31213@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
31214@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
31215@{number="69",value="0x20002b03"@}]
594fe323 31216(gdb)
a2c02241 31217@end smallexample
922fbb7b 31218
a2c02241
NR
31219
31220@subheading The @code{-data-read-memory} Command
31221@findex -data-read-memory
922fbb7b 31222
8dedea02
VP
31223This command is deprecated, use @code{-data-read-memory-bytes} instead.
31224
922fbb7b
AC
31225@subsubheading Synopsis
31226
31227@smallexample
a2c02241
NR
31228 -data-read-memory [ -o @var{byte-offset} ]
31229 @var{address} @var{word-format} @var{word-size}
31230 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
31231@end smallexample
31232
a2c02241
NR
31233@noindent
31234where:
922fbb7b 31235
a2c02241
NR
31236@table @samp
31237@item @var{address}
31238An expression specifying the address of the first memory word to be
31239read. Complex expressions containing embedded white space should be
31240quoted using the C convention.
922fbb7b 31241
a2c02241
NR
31242@item @var{word-format}
31243The format to be used to print the memory words. The notation is the
31244same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 31245,Output Formats}).
922fbb7b 31246
a2c02241
NR
31247@item @var{word-size}
31248The size of each memory word in bytes.
922fbb7b 31249
a2c02241
NR
31250@item @var{nr-rows}
31251The number of rows in the output table.
922fbb7b 31252
a2c02241
NR
31253@item @var{nr-cols}
31254The number of columns in the output table.
922fbb7b 31255
a2c02241
NR
31256@item @var{aschar}
31257If present, indicates that each row should include an @sc{ascii} dump. The
31258value of @var{aschar} is used as a padding character when a byte is not a
31259member of the printable @sc{ascii} character set (printable @sc{ascii}
31260characters are those whose code is between 32 and 126, inclusively).
922fbb7b 31261
a2c02241
NR
31262@item @var{byte-offset}
31263An offset to add to the @var{address} before fetching memory.
31264@end table
922fbb7b 31265
a2c02241
NR
31266This command displays memory contents as a table of @var{nr-rows} by
31267@var{nr-cols} words, each word being @var{word-size} bytes. In total,
31268@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
31269(returned as @samp{total-bytes}). Should less than the requested number
31270of bytes be returned by the target, the missing words are identified
31271using @samp{N/A}. The number of bytes read from the target is returned
31272in @samp{nr-bytes} and the starting address used to read memory in
31273@samp{addr}.
31274
31275The address of the next/previous row or page is available in
31276@samp{next-row} and @samp{prev-row}, @samp{next-page} and
31277@samp{prev-page}.
922fbb7b
AC
31278
31279@subsubheading @value{GDBN} Command
31280
a2c02241
NR
31281The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
31282@samp{gdb_get_mem} memory read command.
922fbb7b
AC
31283
31284@subsubheading Example
32e7087d 31285
a2c02241
NR
31286Read six bytes of memory starting at @code{bytes+6} but then offset by
31287@code{-6} bytes. Format as three rows of two columns. One byte per
31288word. Display each word in hex.
32e7087d
JB
31289
31290@smallexample
594fe323 31291(gdb)
a2c02241
NR
312929-data-read-memory -o -6 -- bytes+6 x 1 3 2
312939^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
31294next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
31295prev-page="0x0000138a",memory=[
31296@{addr="0x00001390",data=["0x00","0x01"]@},
31297@{addr="0x00001392",data=["0x02","0x03"]@},
31298@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 31299(gdb)
32e7087d
JB
31300@end smallexample
31301
a2c02241
NR
31302Read two bytes of memory starting at address @code{shorts + 64} and
31303display as a single word formatted in decimal.
32e7087d 31304
32e7087d 31305@smallexample
594fe323 31306(gdb)
a2c02241
NR
313075-data-read-memory shorts+64 d 2 1 1
313085^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
31309next-row="0x00001512",prev-row="0x0000150e",
31310next-page="0x00001512",prev-page="0x0000150e",memory=[
31311@{addr="0x00001510",data=["128"]@}]
594fe323 31312(gdb)
32e7087d
JB
31313@end smallexample
31314
a2c02241
NR
31315Read thirty two bytes of memory starting at @code{bytes+16} and format
31316as eight rows of four columns. Include a string encoding with @samp{x}
31317used as the non-printable character.
922fbb7b
AC
31318
31319@smallexample
594fe323 31320(gdb)
a2c02241
NR
313214-data-read-memory bytes+16 x 1 8 4 x
313224^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
31323next-row="0x000013c0",prev-row="0x0000139c",
31324next-page="0x000013c0",prev-page="0x00001380",memory=[
31325@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
31326@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
31327@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
31328@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
31329@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
31330@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
31331@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
31332@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 31333(gdb)
922fbb7b
AC
31334@end smallexample
31335
8dedea02
VP
31336@subheading The @code{-data-read-memory-bytes} Command
31337@findex -data-read-memory-bytes
31338
31339@subsubheading Synopsis
31340
31341@smallexample
a86c90e6 31342 -data-read-memory-bytes [ -o @var{offset} ]
8dedea02
VP
31343 @var{address} @var{count}
31344@end smallexample
31345
31346@noindent
31347where:
31348
31349@table @samp
31350@item @var{address}
a86c90e6
SM
31351An expression specifying the address of the first addressable memory unit
31352to be read. Complex expressions containing embedded white space should be
8dedea02
VP
31353quoted using the C convention.
31354
31355@item @var{count}
a86c90e6
SM
31356The number of addressable memory units to read. This should be an integer
31357literal.
8dedea02 31358
a86c90e6
SM
31359@item @var{offset}
31360The offset relative to @var{address} at which to start reading. This
31361should be an integer literal. This option is provided so that a frontend
31362is not required to first evaluate address and then perform address
31363arithmetics itself.
8dedea02
VP
31364
31365@end table
31366
31367This command attempts to read all accessible memory regions in the
31368specified range. First, all regions marked as unreadable in the memory
31369map (if one is defined) will be skipped. @xref{Memory Region
31370Attributes}. Second, @value{GDBN} will attempt to read the remaining
31371regions. For each one, if reading full region results in an errors,
31372@value{GDBN} will try to read a subset of the region.
31373
a86c90e6
SM
31374In general, every single memory unit in the region may be readable or not,
31375and the only way to read every readable unit is to try a read at
8dedea02 31376every address, which is not practical. Therefore, @value{GDBN} will
a86c90e6 31377attempt to read all accessible memory units at either beginning or the end
8dedea02
VP
31378of the region, using a binary division scheme. This heuristic works
31379well for reading accross a memory map boundary. Note that if a region
31380has a readable range that is neither at the beginning or the end,
31381@value{GDBN} will not read it.
31382
31383The result record (@pxref{GDB/MI Result Records}) that is output of
31384the command includes a field named @samp{memory} whose content is a
31385list of tuples. Each tuple represent a successfully read memory block
31386and has the following fields:
31387
31388@table @code
31389@item begin
31390The start address of the memory block, as hexadecimal literal.
31391
31392@item end
31393The end address of the memory block, as hexadecimal literal.
31394
31395@item offset
31396The offset of the memory block, as hexadecimal literal, relative to
31397the start address passed to @code{-data-read-memory-bytes}.
31398
31399@item contents
31400The contents of the memory block, in hex.
31401
31402@end table
31403
31404
31405
31406@subsubheading @value{GDBN} Command
31407
31408The corresponding @value{GDBN} command is @samp{x}.
31409
31410@subsubheading Example
31411
31412@smallexample
31413(gdb)
31414-data-read-memory-bytes &a 10
31415^done,memory=[@{begin="0xbffff154",offset="0x00000000",
31416 end="0xbffff15e",
31417 contents="01000000020000000300"@}]
31418(gdb)
31419@end smallexample
31420
31421
31422@subheading The @code{-data-write-memory-bytes} Command
31423@findex -data-write-memory-bytes
31424
31425@subsubheading Synopsis
31426
31427@smallexample
31428 -data-write-memory-bytes @var{address} @var{contents}
62747a60 31429 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
8dedea02
VP
31430@end smallexample
31431
31432@noindent
31433where:
31434
31435@table @samp
31436@item @var{address}
a86c90e6
SM
31437An expression specifying the address of the first addressable memory unit
31438to be written. Complex expressions containing embedded white space should
31439be quoted using the C convention.
8dedea02
VP
31440
31441@item @var{contents}
a86c90e6
SM
31442The hex-encoded data to write. It is an error if @var{contents} does
31443not represent an integral number of addressable memory units.
8dedea02 31444
62747a60 31445@item @var{count}
a86c90e6
SM
31446Optional argument indicating the number of addressable memory units to be
31447written. If @var{count} is greater than @var{contents}' length,
31448@value{GDBN} will repeatedly write @var{contents} until it fills
31449@var{count} memory units.
62747a60 31450
8dedea02
VP
31451@end table
31452
31453@subsubheading @value{GDBN} Command
31454
31455There's no corresponding @value{GDBN} command.
31456
31457@subsubheading Example
31458
31459@smallexample
31460(gdb)
31461-data-write-memory-bytes &a "aabbccdd"
31462^done
31463(gdb)
31464@end smallexample
31465
62747a60
TT
31466@smallexample
31467(gdb)
31468-data-write-memory-bytes &a "aabbccdd" 16e
31469^done
31470(gdb)
31471@end smallexample
8dedea02 31472
a2c02241
NR
31473@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31474@node GDB/MI Tracepoint Commands
31475@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 31476
18148017
VP
31477The commands defined in this section implement MI support for
31478tracepoints. For detailed introduction, see @ref{Tracepoints}.
31479
31480@subheading The @code{-trace-find} Command
31481@findex -trace-find
31482
31483@subsubheading Synopsis
31484
31485@smallexample
31486 -trace-find @var{mode} [@var{parameters}@dots{}]
31487@end smallexample
31488
31489Find a trace frame using criteria defined by @var{mode} and
31490@var{parameters}. The following table lists permissible
31491modes and their parameters. For details of operation, see @ref{tfind}.
31492
31493@table @samp
31494
31495@item none
31496No parameters are required. Stops examining trace frames.
31497
31498@item frame-number
31499An integer is required as parameter. Selects tracepoint frame with
31500that index.
31501
31502@item tracepoint-number
31503An integer is required as parameter. Finds next
31504trace frame that corresponds to tracepoint with the specified number.
31505
31506@item pc
31507An address is required as parameter. Finds
31508next trace frame that corresponds to any tracepoint at the specified
31509address.
31510
31511@item pc-inside-range
31512Two addresses are required as parameters. Finds next trace
31513frame that corresponds to a tracepoint at an address inside the
31514specified range. Both bounds are considered to be inside the range.
31515
31516@item pc-outside-range
31517Two addresses are required as parameters. Finds
31518next trace frame that corresponds to a tracepoint at an address outside
31519the specified range. Both bounds are considered to be inside the range.
31520
31521@item line
31522Line specification is required as parameter. @xref{Specify Location}.
31523Finds next trace frame that corresponds to a tracepoint at
31524the specified location.
31525
31526@end table
31527
31528If @samp{none} was passed as @var{mode}, the response does not
31529have fields. Otherwise, the response may have the following fields:
31530
31531@table @samp
31532@item found
31533This field has either @samp{0} or @samp{1} as the value, depending
31534on whether a matching tracepoint was found.
31535
31536@item traceframe
31537The index of the found traceframe. This field is present iff
31538the @samp{found} field has value of @samp{1}.
31539
31540@item tracepoint
31541The index of the found tracepoint. This field is present iff
31542the @samp{found} field has value of @samp{1}.
31543
31544@item frame
31545The information about the frame corresponding to the found trace
31546frame. This field is present only if a trace frame was found.
cd64ee31 31547@xref{GDB/MI Frame Information}, for description of this field.
18148017
VP
31548
31549@end table
31550
7d13fe92
SS
31551@subsubheading @value{GDBN} Command
31552
31553The corresponding @value{GDBN} command is @samp{tfind}.
31554
18148017
VP
31555@subheading -trace-define-variable
31556@findex -trace-define-variable
31557
31558@subsubheading Synopsis
31559
31560@smallexample
31561 -trace-define-variable @var{name} [ @var{value} ]
31562@end smallexample
31563
31564Create trace variable @var{name} if it does not exist. If
31565@var{value} is specified, sets the initial value of the specified
31566trace variable to that value. Note that the @var{name} should start
31567with the @samp{$} character.
31568
7d13fe92
SS
31569@subsubheading @value{GDBN} Command
31570
31571The corresponding @value{GDBN} command is @samp{tvariable}.
31572
dc673c81
YQ
31573@subheading The @code{-trace-frame-collected} Command
31574@findex -trace-frame-collected
31575
31576@subsubheading Synopsis
31577
31578@smallexample
31579 -trace-frame-collected
31580 [--var-print-values @var{var_pval}]
31581 [--comp-print-values @var{comp_pval}]
31582 [--registers-format @var{regformat}]
31583 [--memory-contents]
31584@end smallexample
31585
31586This command returns the set of collected objects, register names,
31587trace state variable names, memory ranges and computed expressions
31588that have been collected at a particular trace frame. The optional
31589parameters to the command affect the output format in different ways.
31590See the output description table below for more details.
31591
31592The reported names can be used in the normal manner to create
31593varobjs and inspect the objects themselves. The items returned by
31594this command are categorized so that it is clear which is a variable,
31595which is a register, which is a trace state variable, which is a
31596memory range and which is a computed expression.
31597
31598For instance, if the actions were
31599@smallexample
31600collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
31601collect *(int*)0xaf02bef0@@40
31602@end smallexample
31603
31604@noindent
31605the object collected in its entirety would be @code{myVar}. The
31606object @code{myArray} would be partially collected, because only the
31607element at index @code{myIndex} would be collected. The remaining
31608objects would be computed expressions.
31609
31610An example output would be:
31611
31612@smallexample
31613(gdb)
31614-trace-frame-collected
31615^done,
31616 explicit-variables=[@{name="myVar",value="1"@}],
31617 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
31618 @{name="myObj.field",value="0"@},
31619 @{name="myPtr->field",value="1"@},
31620 @{name="myCount + 2",value="3"@},
31621 @{name="$tvar1 + 1",value="43970027"@}],
31622 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
31623 @{number="1",value="0x0"@},
31624 @{number="2",value="0x4"@},
31625 ...
31626 @{number="125",value="0x0"@}],
31627 tvars=[@{name="$tvar1",current="43970026"@}],
31628 memory=[@{address="0x0000000000602264",length="4"@},
31629 @{address="0x0000000000615bc0",length="4"@}]
31630(gdb)
31631@end smallexample
31632
31633Where:
31634
31635@table @code
31636@item explicit-variables
31637The set of objects that have been collected in their entirety (as
31638opposed to collecting just a few elements of an array or a few struct
31639members). For each object, its name and value are printed.
31640The @code{--var-print-values} option affects how or whether the value
31641field is output. If @var{var_pval} is 0, then print only the names;
31642if it is 1, print also their values; and if it is 2, print the name,
31643type and value for simple data types, and the name and type for
31644arrays, structures and unions.
31645
31646@item computed-expressions
31647The set of computed expressions that have been collected at the
31648current trace frame. The @code{--comp-print-values} option affects
31649this set like the @code{--var-print-values} option affects the
31650@code{explicit-variables} set. See above.
31651
31652@item registers
31653The registers that have been collected at the current trace frame.
31654For each register collected, the name and current value are returned.
31655The value is formatted according to the @code{--registers-format}
31656option. See the @command{-data-list-register-values} command for a
31657list of the allowed formats. The default is @samp{x}.
31658
31659@item tvars
31660The trace state variables that have been collected at the current
31661trace frame. For each trace state variable collected, the name and
31662current value are returned.
31663
31664@item memory
31665The set of memory ranges that have been collected at the current trace
31666frame. Its content is a list of tuples. Each tuple represents a
31667collected memory range and has the following fields:
31668
31669@table @code
31670@item address
31671The start address of the memory range, as hexadecimal literal.
31672
31673@item length
31674The length of the memory range, as decimal literal.
31675
31676@item contents
31677The contents of the memory block, in hex. This field is only present
31678if the @code{--memory-contents} option is specified.
31679
31680@end table
31681
31682@end table
31683
31684@subsubheading @value{GDBN} Command
31685
31686There is no corresponding @value{GDBN} command.
31687
31688@subsubheading Example
31689
18148017
VP
31690@subheading -trace-list-variables
31691@findex -trace-list-variables
922fbb7b 31692
18148017 31693@subsubheading Synopsis
922fbb7b 31694
18148017
VP
31695@smallexample
31696 -trace-list-variables
31697@end smallexample
922fbb7b 31698
18148017
VP
31699Return a table of all defined trace variables. Each element of the
31700table has the following fields:
922fbb7b 31701
18148017
VP
31702@table @samp
31703@item name
31704The name of the trace variable. This field is always present.
922fbb7b 31705
18148017
VP
31706@item initial
31707The initial value. This is a 64-bit signed integer. This
31708field is always present.
922fbb7b 31709
18148017
VP
31710@item current
31711The value the trace variable has at the moment. This is a 64-bit
31712signed integer. This field is absent iff current value is
31713not defined, for example if the trace was never run, or is
31714presently running.
922fbb7b 31715
18148017 31716@end table
922fbb7b 31717
7d13fe92
SS
31718@subsubheading @value{GDBN} Command
31719
31720The corresponding @value{GDBN} command is @samp{tvariables}.
31721
18148017 31722@subsubheading Example
922fbb7b 31723
18148017
VP
31724@smallexample
31725(gdb)
31726-trace-list-variables
31727^done,trace-variables=@{nr_rows="1",nr_cols="3",
31728hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
31729 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
31730 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
31731body=[variable=@{name="$trace_timestamp",initial="0"@}
31732 variable=@{name="$foo",initial="10",current="15"@}]@}
31733(gdb)
31734@end smallexample
922fbb7b 31735
18148017
VP
31736@subheading -trace-save
31737@findex -trace-save
922fbb7b 31738
18148017
VP
31739@subsubheading Synopsis
31740
31741@smallexample
99e61eda 31742 -trace-save [ -r ] [ -ctf ] @var{filename}
18148017
VP
31743@end smallexample
31744
31745Saves the collected trace data to @var{filename}. Without the
31746@samp{-r} option, the data is downloaded from the target and saved
31747in a local file. With the @samp{-r} option the target is asked
31748to perform the save.
31749
99e61eda
SM
31750By default, this command will save the trace in the tfile format. You can
31751supply the optional @samp{-ctf} argument to save it the CTF format. See
31752@ref{Trace Files} for more information about CTF.
31753
7d13fe92
SS
31754@subsubheading @value{GDBN} Command
31755
31756The corresponding @value{GDBN} command is @samp{tsave}.
31757
18148017
VP
31758
31759@subheading -trace-start
31760@findex -trace-start
31761
31762@subsubheading Synopsis
31763
31764@smallexample
31765 -trace-start
31766@end smallexample
922fbb7b 31767
be06ba8c 31768Starts a tracing experiment. The result of this command does not
18148017 31769have any fields.
922fbb7b 31770
7d13fe92
SS
31771@subsubheading @value{GDBN} Command
31772
31773The corresponding @value{GDBN} command is @samp{tstart}.
31774
18148017
VP
31775@subheading -trace-status
31776@findex -trace-status
922fbb7b 31777
18148017
VP
31778@subsubheading Synopsis
31779
31780@smallexample
31781 -trace-status
31782@end smallexample
31783
a97153c7 31784Obtains the status of a tracing experiment. The result may include
18148017
VP
31785the following fields:
31786
31787@table @samp
31788
31789@item supported
31790May have a value of either @samp{0}, when no tracing operations are
31791supported, @samp{1}, when all tracing operations are supported, or
31792@samp{file} when examining trace file. In the latter case, examining
31793of trace frame is possible but new tracing experiement cannot be
31794started. This field is always present.
31795
31796@item running
31797May have a value of either @samp{0} or @samp{1} depending on whether
31798tracing experiement is in progress on target. This field is present
31799if @samp{supported} field is not @samp{0}.
31800
31801@item stop-reason
31802Report the reason why the tracing was stopped last time. This field
31803may be absent iff tracing was never stopped on target yet. The
31804value of @samp{request} means the tracing was stopped as result of
31805the @code{-trace-stop} command. The value of @samp{overflow} means
31806the tracing buffer is full. The value of @samp{disconnection} means
31807tracing was automatically stopped when @value{GDBN} has disconnected.
31808The value of @samp{passcount} means tracing was stopped when a
31809tracepoint was passed a maximal number of times for that tracepoint.
31810This field is present if @samp{supported} field is not @samp{0}.
31811
31812@item stopping-tracepoint
31813The number of tracepoint whose passcount as exceeded. This field is
31814present iff the @samp{stop-reason} field has the value of
31815@samp{passcount}.
31816
31817@item frames
87290684
SS
31818@itemx frames-created
31819The @samp{frames} field is a count of the total number of trace frames
31820in the trace buffer, while @samp{frames-created} is the total created
31821during the run, including ones that were discarded, such as when a
31822circular trace buffer filled up. Both fields are optional.
18148017
VP
31823
31824@item buffer-size
31825@itemx buffer-free
31826These fields tell the current size of the tracing buffer and the
87290684 31827remaining space. These fields are optional.
18148017 31828
a97153c7
PA
31829@item circular
31830The value of the circular trace buffer flag. @code{1} means that the
31831trace buffer is circular and old trace frames will be discarded if
31832necessary to make room, @code{0} means that the trace buffer is linear
31833and may fill up.
31834
31835@item disconnected
31836The value of the disconnected tracing flag. @code{1} means that
31837tracing will continue after @value{GDBN} disconnects, @code{0} means
31838that the trace run will stop.
31839
f5911ea1
HAQ
31840@item trace-file
31841The filename of the trace file being examined. This field is
31842optional, and only present when examining a trace file.
31843
18148017
VP
31844@end table
31845
7d13fe92
SS
31846@subsubheading @value{GDBN} Command
31847
31848The corresponding @value{GDBN} command is @samp{tstatus}.
31849
18148017
VP
31850@subheading -trace-stop
31851@findex -trace-stop
31852
31853@subsubheading Synopsis
31854
31855@smallexample
31856 -trace-stop
31857@end smallexample
922fbb7b 31858
18148017
VP
31859Stops a tracing experiment. The result of this command has the same
31860fields as @code{-trace-status}, except that the @samp{supported} and
31861@samp{running} fields are not output.
922fbb7b 31862
7d13fe92
SS
31863@subsubheading @value{GDBN} Command
31864
31865The corresponding @value{GDBN} command is @samp{tstop}.
31866
922fbb7b 31867
a2c02241
NR
31868@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31869@node GDB/MI Symbol Query
31870@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
31871
31872
9901a55b 31873@ignore
a2c02241
NR
31874@subheading The @code{-symbol-info-address} Command
31875@findex -symbol-info-address
922fbb7b
AC
31876
31877@subsubheading Synopsis
31878
31879@smallexample
a2c02241 31880 -symbol-info-address @var{symbol}
922fbb7b
AC
31881@end smallexample
31882
a2c02241 31883Describe where @var{symbol} is stored.
922fbb7b
AC
31884
31885@subsubheading @value{GDBN} Command
31886
a2c02241 31887The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
31888
31889@subsubheading Example
31890N.A.
31891
31892
a2c02241
NR
31893@subheading The @code{-symbol-info-file} Command
31894@findex -symbol-info-file
922fbb7b
AC
31895
31896@subsubheading Synopsis
31897
31898@smallexample
a2c02241 31899 -symbol-info-file
922fbb7b
AC
31900@end smallexample
31901
a2c02241 31902Show the file for the symbol.
922fbb7b 31903
a2c02241 31904@subsubheading @value{GDBN} Command
922fbb7b 31905
a2c02241
NR
31906There's no equivalent @value{GDBN} command. @code{gdbtk} has
31907@samp{gdb_find_file}.
922fbb7b
AC
31908
31909@subsubheading Example
31910N.A.
31911
31912
a2c02241
NR
31913@subheading The @code{-symbol-info-function} Command
31914@findex -symbol-info-function
922fbb7b
AC
31915
31916@subsubheading Synopsis
31917
31918@smallexample
a2c02241 31919 -symbol-info-function
922fbb7b
AC
31920@end smallexample
31921
a2c02241 31922Show which function the symbol lives in.
922fbb7b
AC
31923
31924@subsubheading @value{GDBN} Command
31925
a2c02241 31926@samp{gdb_get_function} in @code{gdbtk}.
922fbb7b
AC
31927
31928@subsubheading Example
31929N.A.
31930
31931
a2c02241
NR
31932@subheading The @code{-symbol-info-line} Command
31933@findex -symbol-info-line
922fbb7b
AC
31934
31935@subsubheading Synopsis
31936
31937@smallexample
a2c02241 31938 -symbol-info-line
922fbb7b
AC
31939@end smallexample
31940
a2c02241 31941Show the core addresses of the code for a source line.
922fbb7b 31942
a2c02241 31943@subsubheading @value{GDBN} Command
922fbb7b 31944
a2c02241
NR
31945The corresponding @value{GDBN} command is @samp{info line}.
31946@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
31947
31948@subsubheading Example
a2c02241 31949N.A.
922fbb7b
AC
31950
31951
a2c02241
NR
31952@subheading The @code{-symbol-info-symbol} Command
31953@findex -symbol-info-symbol
07f31aa6
DJ
31954
31955@subsubheading Synopsis
31956
a2c02241
NR
31957@smallexample
31958 -symbol-info-symbol @var{addr}
31959@end smallexample
07f31aa6 31960
a2c02241 31961Describe what symbol is at location @var{addr}.
07f31aa6 31962
a2c02241 31963@subsubheading @value{GDBN} Command
07f31aa6 31964
a2c02241 31965The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
31966
31967@subsubheading Example
a2c02241 31968N.A.
07f31aa6
DJ
31969
31970
a2c02241
NR
31971@subheading The @code{-symbol-list-functions} Command
31972@findex -symbol-list-functions
922fbb7b
AC
31973
31974@subsubheading Synopsis
31975
31976@smallexample
a2c02241 31977 -symbol-list-functions
922fbb7b
AC
31978@end smallexample
31979
a2c02241 31980List the functions in the executable.
922fbb7b
AC
31981
31982@subsubheading @value{GDBN} Command
31983
a2c02241
NR
31984@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
31985@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
31986
31987@subsubheading Example
a2c02241 31988N.A.
9901a55b 31989@end ignore
922fbb7b
AC
31990
31991
a2c02241
NR
31992@subheading The @code{-symbol-list-lines} Command
31993@findex -symbol-list-lines
922fbb7b
AC
31994
31995@subsubheading Synopsis
31996
31997@smallexample
a2c02241 31998 -symbol-list-lines @var{filename}
922fbb7b
AC
31999@end smallexample
32000
a2c02241
NR
32001Print the list of lines that contain code and their associated program
32002addresses for the given source filename. The entries are sorted in
32003ascending PC order.
922fbb7b
AC
32004
32005@subsubheading @value{GDBN} Command
32006
a2c02241 32007There is no corresponding @value{GDBN} command.
922fbb7b
AC
32008
32009@subsubheading Example
a2c02241 32010@smallexample
594fe323 32011(gdb)
a2c02241
NR
32012-symbol-list-lines basics.c
32013^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 32014(gdb)
a2c02241 32015@end smallexample
922fbb7b
AC
32016
32017
9901a55b 32018@ignore
a2c02241
NR
32019@subheading The @code{-symbol-list-types} Command
32020@findex -symbol-list-types
922fbb7b
AC
32021
32022@subsubheading Synopsis
32023
32024@smallexample
a2c02241 32025 -symbol-list-types
922fbb7b
AC
32026@end smallexample
32027
a2c02241 32028List all the type names.
922fbb7b
AC
32029
32030@subsubheading @value{GDBN} Command
32031
a2c02241
NR
32032The corresponding commands are @samp{info types} in @value{GDBN},
32033@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
32034
32035@subsubheading Example
32036N.A.
32037
32038
a2c02241
NR
32039@subheading The @code{-symbol-list-variables} Command
32040@findex -symbol-list-variables
922fbb7b
AC
32041
32042@subsubheading Synopsis
32043
32044@smallexample
a2c02241 32045 -symbol-list-variables
922fbb7b
AC
32046@end smallexample
32047
a2c02241 32048List all the global and static variable names.
922fbb7b
AC
32049
32050@subsubheading @value{GDBN} Command
32051
a2c02241 32052@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
32053
32054@subsubheading Example
32055N.A.
32056
32057
a2c02241
NR
32058@subheading The @code{-symbol-locate} Command
32059@findex -symbol-locate
922fbb7b
AC
32060
32061@subsubheading Synopsis
32062
32063@smallexample
a2c02241 32064 -symbol-locate
922fbb7b
AC
32065@end smallexample
32066
922fbb7b
AC
32067@subsubheading @value{GDBN} Command
32068
a2c02241 32069@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
32070
32071@subsubheading Example
32072N.A.
32073
32074
a2c02241
NR
32075@subheading The @code{-symbol-type} Command
32076@findex -symbol-type
922fbb7b
AC
32077
32078@subsubheading Synopsis
32079
32080@smallexample
a2c02241 32081 -symbol-type @var{variable}
922fbb7b
AC
32082@end smallexample
32083
a2c02241 32084Show type of @var{variable}.
922fbb7b 32085
a2c02241 32086@subsubheading @value{GDBN} Command
922fbb7b 32087
a2c02241
NR
32088The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
32089@samp{gdb_obj_variable}.
32090
32091@subsubheading Example
32092N.A.
9901a55b 32093@end ignore
a2c02241
NR
32094
32095
32096@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32097@node GDB/MI File Commands
32098@section @sc{gdb/mi} File Commands
32099
32100This section describes the GDB/MI commands to specify executable file names
32101and to read in and obtain symbol table information.
32102
32103@subheading The @code{-file-exec-and-symbols} Command
32104@findex -file-exec-and-symbols
32105
32106@subsubheading Synopsis
922fbb7b
AC
32107
32108@smallexample
a2c02241 32109 -file-exec-and-symbols @var{file}
922fbb7b
AC
32110@end smallexample
32111
a2c02241
NR
32112Specify the executable file to be debugged. This file is the one from
32113which the symbol table is also read. If no file is specified, the
32114command clears the executable and symbol information. If breakpoints
32115are set when using this command with no arguments, @value{GDBN} will produce
32116error messages. Otherwise, no output is produced, except a completion
32117notification.
32118
922fbb7b
AC
32119@subsubheading @value{GDBN} Command
32120
a2c02241 32121The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
32122
32123@subsubheading Example
32124
32125@smallexample
594fe323 32126(gdb)
a2c02241
NR
32127-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
32128^done
594fe323 32129(gdb)
922fbb7b
AC
32130@end smallexample
32131
922fbb7b 32132
a2c02241
NR
32133@subheading The @code{-file-exec-file} Command
32134@findex -file-exec-file
922fbb7b
AC
32135
32136@subsubheading Synopsis
32137
32138@smallexample
a2c02241 32139 -file-exec-file @var{file}
922fbb7b
AC
32140@end smallexample
32141
a2c02241
NR
32142Specify the executable file to be debugged. Unlike
32143@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
32144from this file. If used without argument, @value{GDBN} clears the information
32145about the executable file. No output is produced, except a completion
32146notification.
922fbb7b 32147
a2c02241
NR
32148@subsubheading @value{GDBN} Command
32149
32150The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
32151
32152@subsubheading Example
a2c02241
NR
32153
32154@smallexample
594fe323 32155(gdb)
a2c02241
NR
32156-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
32157^done
594fe323 32158(gdb)
a2c02241 32159@end smallexample
922fbb7b
AC
32160
32161
9901a55b 32162@ignore
a2c02241
NR
32163@subheading The @code{-file-list-exec-sections} Command
32164@findex -file-list-exec-sections
922fbb7b
AC
32165
32166@subsubheading Synopsis
32167
32168@smallexample
a2c02241 32169 -file-list-exec-sections
922fbb7b
AC
32170@end smallexample
32171
a2c02241
NR
32172List the sections of the current executable file.
32173
922fbb7b
AC
32174@subsubheading @value{GDBN} Command
32175
a2c02241
NR
32176The @value{GDBN} command @samp{info file} shows, among the rest, the same
32177information as this command. @code{gdbtk} has a corresponding command
32178@samp{gdb_load_info}.
922fbb7b
AC
32179
32180@subsubheading Example
32181N.A.
9901a55b 32182@end ignore
922fbb7b
AC
32183
32184
a2c02241
NR
32185@subheading The @code{-file-list-exec-source-file} Command
32186@findex -file-list-exec-source-file
922fbb7b
AC
32187
32188@subsubheading Synopsis
32189
32190@smallexample
a2c02241 32191 -file-list-exec-source-file
922fbb7b
AC
32192@end smallexample
32193
a2c02241 32194List the line number, the current source file, and the absolute path
44288b44
NR
32195to the current source file for the current executable. The macro
32196information field has a value of @samp{1} or @samp{0} depending on
32197whether or not the file includes preprocessor macro information.
922fbb7b
AC
32198
32199@subsubheading @value{GDBN} Command
32200
a2c02241 32201The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
32202
32203@subsubheading Example
32204
922fbb7b 32205@smallexample
594fe323 32206(gdb)
a2c02241 32207123-file-list-exec-source-file
44288b44 32208123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
594fe323 32209(gdb)
922fbb7b
AC
32210@end smallexample
32211
32212
a2c02241
NR
32213@subheading The @code{-file-list-exec-source-files} Command
32214@findex -file-list-exec-source-files
922fbb7b
AC
32215
32216@subsubheading Synopsis
32217
32218@smallexample
a2c02241 32219 -file-list-exec-source-files
922fbb7b
AC
32220@end smallexample
32221
a2c02241
NR
32222List the source files for the current executable.
32223
f35a17b5
JK
32224It will always output both the filename and fullname (absolute file
32225name) of a source file.
922fbb7b
AC
32226
32227@subsubheading @value{GDBN} Command
32228
a2c02241
NR
32229The @value{GDBN} equivalent is @samp{info sources}.
32230@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
32231
32232@subsubheading Example
922fbb7b 32233@smallexample
594fe323 32234(gdb)
a2c02241
NR
32235-file-list-exec-source-files
32236^done,files=[
32237@{file=foo.c,fullname=/home/foo.c@},
32238@{file=/home/bar.c,fullname=/home/bar.c@},
32239@{file=gdb_could_not_find_fullpath.c@}]
594fe323 32240(gdb)
922fbb7b
AC
32241@end smallexample
32242
a2c02241
NR
32243@subheading The @code{-file-list-shared-libraries} Command
32244@findex -file-list-shared-libraries
922fbb7b 32245
a2c02241 32246@subsubheading Synopsis
922fbb7b 32247
a2c02241 32248@smallexample
51457a05 32249 -file-list-shared-libraries [ @var{regexp} ]
a2c02241 32250@end smallexample
922fbb7b 32251
a2c02241 32252List the shared libraries in the program.
51457a05
MAL
32253With a regular expression @var{regexp}, only those libraries whose
32254names match @var{regexp} are listed.
922fbb7b 32255
a2c02241 32256@subsubheading @value{GDBN} Command
922fbb7b 32257
51457a05
MAL
32258The corresponding @value{GDBN} command is @samp{info shared}. The fields
32259have a similar meaning to the @code{=library-loaded} notification.
32260The @code{ranges} field specifies the multiple segments belonging to this
32261library. Each range has the following fields:
32262
32263@table @samp
32264@item from
32265The address defining the inclusive lower bound of the segment.
32266@item to
32267The address defining the exclusive upper bound of the segment.
32268@end table
922fbb7b 32269
a2c02241 32270@subsubheading Example
51457a05
MAL
32271@smallexample
32272(gdb)
32273-file-list-exec-source-files
32274^done,shared-libraries=[
32275@{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"@}]@},
32276@{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"@}]@}]
32277(gdb)
32278@end smallexample
922fbb7b
AC
32279
32280
51457a05 32281@ignore
a2c02241
NR
32282@subheading The @code{-file-list-symbol-files} Command
32283@findex -file-list-symbol-files
922fbb7b 32284
a2c02241 32285@subsubheading Synopsis
922fbb7b 32286
a2c02241
NR
32287@smallexample
32288 -file-list-symbol-files
32289@end smallexample
922fbb7b 32290
a2c02241 32291List symbol files.
922fbb7b 32292
a2c02241 32293@subsubheading @value{GDBN} Command
922fbb7b 32294
a2c02241 32295The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 32296
a2c02241
NR
32297@subsubheading Example
32298N.A.
9901a55b 32299@end ignore
922fbb7b 32300
922fbb7b 32301
a2c02241
NR
32302@subheading The @code{-file-symbol-file} Command
32303@findex -file-symbol-file
922fbb7b 32304
a2c02241 32305@subsubheading Synopsis
922fbb7b 32306
a2c02241
NR
32307@smallexample
32308 -file-symbol-file @var{file}
32309@end smallexample
922fbb7b 32310
a2c02241
NR
32311Read symbol table info from the specified @var{file} argument. When
32312used without arguments, clears @value{GDBN}'s symbol table info. No output is
32313produced, except for a completion notification.
922fbb7b 32314
a2c02241 32315@subsubheading @value{GDBN} Command
922fbb7b 32316
a2c02241 32317The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 32318
a2c02241 32319@subsubheading Example
922fbb7b 32320
a2c02241 32321@smallexample
594fe323 32322(gdb)
a2c02241
NR
32323-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
32324^done
594fe323 32325(gdb)
a2c02241 32326@end smallexample
922fbb7b 32327
a2c02241 32328@ignore
a2c02241
NR
32329@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32330@node GDB/MI Memory Overlay Commands
32331@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 32332
a2c02241 32333The memory overlay commands are not implemented.
922fbb7b 32334
a2c02241 32335@c @subheading -overlay-auto
922fbb7b 32336
a2c02241 32337@c @subheading -overlay-list-mapping-state
922fbb7b 32338
a2c02241 32339@c @subheading -overlay-list-overlays
922fbb7b 32340
a2c02241 32341@c @subheading -overlay-map
922fbb7b 32342
a2c02241 32343@c @subheading -overlay-off
922fbb7b 32344
a2c02241 32345@c @subheading -overlay-on
922fbb7b 32346
a2c02241 32347@c @subheading -overlay-unmap
922fbb7b 32348
a2c02241
NR
32349@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32350@node GDB/MI Signal Handling Commands
32351@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 32352
a2c02241 32353Signal handling commands are not implemented.
922fbb7b 32354
a2c02241 32355@c @subheading -signal-handle
922fbb7b 32356
a2c02241 32357@c @subheading -signal-list-handle-actions
922fbb7b 32358
a2c02241
NR
32359@c @subheading -signal-list-signal-types
32360@end ignore
922fbb7b 32361
922fbb7b 32362
a2c02241
NR
32363@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32364@node GDB/MI Target Manipulation
32365@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
32366
32367
a2c02241
NR
32368@subheading The @code{-target-attach} Command
32369@findex -target-attach
922fbb7b
AC
32370
32371@subsubheading Synopsis
32372
32373@smallexample
c3b108f7 32374 -target-attach @var{pid} | @var{gid} | @var{file}
922fbb7b
AC
32375@end smallexample
32376
c3b108f7
VP
32377Attach to a process @var{pid} or a file @var{file} outside of
32378@value{GDBN}, or a thread group @var{gid}. If attaching to a thread
32379group, the id previously returned by
32380@samp{-list-thread-groups --available} must be used.
922fbb7b 32381
79a6e687 32382@subsubheading @value{GDBN} Command
922fbb7b 32383
a2c02241 32384The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 32385
a2c02241 32386@subsubheading Example
b56e7235
VP
32387@smallexample
32388(gdb)
32389-target-attach 34
32390=thread-created,id="1"
5ae4183a 32391*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
b56e7235
VP
32392^done
32393(gdb)
32394@end smallexample
a2c02241 32395
9901a55b 32396@ignore
a2c02241
NR
32397@subheading The @code{-target-compare-sections} Command
32398@findex -target-compare-sections
922fbb7b
AC
32399
32400@subsubheading Synopsis
32401
32402@smallexample
a2c02241 32403 -target-compare-sections [ @var{section} ]
922fbb7b
AC
32404@end smallexample
32405
a2c02241
NR
32406Compare data of section @var{section} on target to the exec file.
32407Without the argument, all sections are compared.
922fbb7b 32408
a2c02241 32409@subsubheading @value{GDBN} Command
922fbb7b 32410
a2c02241 32411The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 32412
a2c02241
NR
32413@subsubheading Example
32414N.A.
9901a55b 32415@end ignore
a2c02241
NR
32416
32417
32418@subheading The @code{-target-detach} Command
32419@findex -target-detach
922fbb7b
AC
32420
32421@subsubheading Synopsis
32422
32423@smallexample
c3b108f7 32424 -target-detach [ @var{pid} | @var{gid} ]
922fbb7b
AC
32425@end smallexample
32426
a2c02241 32427Detach from the remote target which normally resumes its execution.
c3b108f7
VP
32428If either @var{pid} or @var{gid} is specified, detaches from either
32429the specified process, or specified thread group. There's no output.
a2c02241 32430
79a6e687 32431@subsubheading @value{GDBN} Command
a2c02241
NR
32432
32433The corresponding @value{GDBN} command is @samp{detach}.
32434
32435@subsubheading Example
922fbb7b
AC
32436
32437@smallexample
594fe323 32438(gdb)
a2c02241
NR
32439-target-detach
32440^done
594fe323 32441(gdb)
922fbb7b
AC
32442@end smallexample
32443
32444
a2c02241
NR
32445@subheading The @code{-target-disconnect} Command
32446@findex -target-disconnect
922fbb7b
AC
32447
32448@subsubheading Synopsis
32449
123dc839 32450@smallexample
a2c02241 32451 -target-disconnect
123dc839 32452@end smallexample
922fbb7b 32453
a2c02241
NR
32454Disconnect from the remote target. There's no output and the target is
32455generally not resumed.
32456
79a6e687 32457@subsubheading @value{GDBN} Command
a2c02241
NR
32458
32459The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
32460
32461@subsubheading Example
922fbb7b
AC
32462
32463@smallexample
594fe323 32464(gdb)
a2c02241
NR
32465-target-disconnect
32466^done
594fe323 32467(gdb)
922fbb7b
AC
32468@end smallexample
32469
32470
a2c02241
NR
32471@subheading The @code{-target-download} Command
32472@findex -target-download
922fbb7b
AC
32473
32474@subsubheading Synopsis
32475
32476@smallexample
a2c02241 32477 -target-download
922fbb7b
AC
32478@end smallexample
32479
a2c02241
NR
32480Loads the executable onto the remote target.
32481It prints out an update message every half second, which includes the fields:
32482
32483@table @samp
32484@item section
32485The name of the section.
32486@item section-sent
32487The size of what has been sent so far for that section.
32488@item section-size
32489The size of the section.
32490@item total-sent
32491The total size of what was sent so far (the current and the previous sections).
32492@item total-size
32493The size of the overall executable to download.
32494@end table
32495
32496@noindent
32497Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
32498@sc{gdb/mi} Output Syntax}).
32499
32500In addition, it prints the name and size of the sections, as they are
32501downloaded. These messages include the following fields:
32502
32503@table @samp
32504@item section
32505The name of the section.
32506@item section-size
32507The size of the section.
32508@item total-size
32509The size of the overall executable to download.
32510@end table
32511
32512@noindent
32513At the end, a summary is printed.
32514
32515@subsubheading @value{GDBN} Command
32516
32517The corresponding @value{GDBN} command is @samp{load}.
32518
32519@subsubheading Example
32520
32521Note: each status message appears on a single line. Here the messages
32522have been broken down so that they can fit onto a page.
922fbb7b
AC
32523
32524@smallexample
594fe323 32525(gdb)
a2c02241
NR
32526-target-download
32527+download,@{section=".text",section-size="6668",total-size="9880"@}
32528+download,@{section=".text",section-sent="512",section-size="6668",
32529total-sent="512",total-size="9880"@}
32530+download,@{section=".text",section-sent="1024",section-size="6668",
32531total-sent="1024",total-size="9880"@}
32532+download,@{section=".text",section-sent="1536",section-size="6668",
32533total-sent="1536",total-size="9880"@}
32534+download,@{section=".text",section-sent="2048",section-size="6668",
32535total-sent="2048",total-size="9880"@}
32536+download,@{section=".text",section-sent="2560",section-size="6668",
32537total-sent="2560",total-size="9880"@}
32538+download,@{section=".text",section-sent="3072",section-size="6668",
32539total-sent="3072",total-size="9880"@}
32540+download,@{section=".text",section-sent="3584",section-size="6668",
32541total-sent="3584",total-size="9880"@}
32542+download,@{section=".text",section-sent="4096",section-size="6668",
32543total-sent="4096",total-size="9880"@}
32544+download,@{section=".text",section-sent="4608",section-size="6668",
32545total-sent="4608",total-size="9880"@}
32546+download,@{section=".text",section-sent="5120",section-size="6668",
32547total-sent="5120",total-size="9880"@}
32548+download,@{section=".text",section-sent="5632",section-size="6668",
32549total-sent="5632",total-size="9880"@}
32550+download,@{section=".text",section-sent="6144",section-size="6668",
32551total-sent="6144",total-size="9880"@}
32552+download,@{section=".text",section-sent="6656",section-size="6668",
32553total-sent="6656",total-size="9880"@}
32554+download,@{section=".init",section-size="28",total-size="9880"@}
32555+download,@{section=".fini",section-size="28",total-size="9880"@}
32556+download,@{section=".data",section-size="3156",total-size="9880"@}
32557+download,@{section=".data",section-sent="512",section-size="3156",
32558total-sent="7236",total-size="9880"@}
32559+download,@{section=".data",section-sent="1024",section-size="3156",
32560total-sent="7748",total-size="9880"@}
32561+download,@{section=".data",section-sent="1536",section-size="3156",
32562total-sent="8260",total-size="9880"@}
32563+download,@{section=".data",section-sent="2048",section-size="3156",
32564total-sent="8772",total-size="9880"@}
32565+download,@{section=".data",section-sent="2560",section-size="3156",
32566total-sent="9284",total-size="9880"@}
32567+download,@{section=".data",section-sent="3072",section-size="3156",
32568total-sent="9796",total-size="9880"@}
32569^done,address="0x10004",load-size="9880",transfer-rate="6586",
32570write-rate="429"
594fe323 32571(gdb)
922fbb7b
AC
32572@end smallexample
32573
32574
9901a55b 32575@ignore
a2c02241
NR
32576@subheading The @code{-target-exec-status} Command
32577@findex -target-exec-status
922fbb7b
AC
32578
32579@subsubheading Synopsis
32580
32581@smallexample
a2c02241 32582 -target-exec-status
922fbb7b
AC
32583@end smallexample
32584
a2c02241
NR
32585Provide information on the state of the target (whether it is running or
32586not, for instance).
922fbb7b 32587
a2c02241 32588@subsubheading @value{GDBN} Command
922fbb7b 32589
a2c02241
NR
32590There's no equivalent @value{GDBN} command.
32591
32592@subsubheading Example
32593N.A.
922fbb7b 32594
a2c02241
NR
32595
32596@subheading The @code{-target-list-available-targets} Command
32597@findex -target-list-available-targets
922fbb7b
AC
32598
32599@subsubheading Synopsis
32600
32601@smallexample
a2c02241 32602 -target-list-available-targets
922fbb7b
AC
32603@end smallexample
32604
a2c02241 32605List the possible targets to connect to.
922fbb7b 32606
a2c02241 32607@subsubheading @value{GDBN} Command
922fbb7b 32608
a2c02241 32609The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 32610
a2c02241
NR
32611@subsubheading Example
32612N.A.
32613
32614
32615@subheading The @code{-target-list-current-targets} Command
32616@findex -target-list-current-targets
922fbb7b
AC
32617
32618@subsubheading Synopsis
32619
32620@smallexample
a2c02241 32621 -target-list-current-targets
922fbb7b
AC
32622@end smallexample
32623
a2c02241 32624Describe the current target.
922fbb7b 32625
a2c02241 32626@subsubheading @value{GDBN} Command
922fbb7b 32627
a2c02241
NR
32628The corresponding information is printed by @samp{info file} (among
32629other things).
922fbb7b 32630
a2c02241
NR
32631@subsubheading Example
32632N.A.
32633
32634
32635@subheading The @code{-target-list-parameters} Command
32636@findex -target-list-parameters
922fbb7b
AC
32637
32638@subsubheading Synopsis
32639
32640@smallexample
a2c02241 32641 -target-list-parameters
922fbb7b
AC
32642@end smallexample
32643
a2c02241 32644@c ????
9901a55b 32645@end ignore
a2c02241
NR
32646
32647@subsubheading @value{GDBN} Command
32648
32649No equivalent.
922fbb7b
AC
32650
32651@subsubheading Example
a2c02241
NR
32652N.A.
32653
78cbbba8
LM
32654@subheading The @code{-target-flash-erase} Command
32655@findex -target-flash-erase
32656
32657@subsubheading Synopsis
32658
32659@smallexample
32660 -target-flash-erase
32661@end smallexample
32662
32663Erases all known flash memory regions on the target.
32664
32665The corresponding @value{GDBN} command is @samp{flash-erase}.
32666
32667The output is a list of flash regions that have been erased, with starting
32668addresses and memory region sizes.
32669
32670@smallexample
32671(gdb)
32672-target-flash-erase
32673^done,erased-regions=@{address="0x0",size="0x40000"@}
32674(gdb)
32675@end smallexample
a2c02241
NR
32676
32677@subheading The @code{-target-select} Command
32678@findex -target-select
32679
32680@subsubheading Synopsis
922fbb7b
AC
32681
32682@smallexample
a2c02241 32683 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
32684@end smallexample
32685
a2c02241 32686Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 32687
a2c02241
NR
32688@table @samp
32689@item @var{type}
75c99385 32690The type of target, for instance @samp{remote}, etc.
a2c02241
NR
32691@item @var{parameters}
32692Device names, host names and the like. @xref{Target Commands, ,
79a6e687 32693Commands for Managing Targets}, for more details.
a2c02241
NR
32694@end table
32695
32696The output is a connection notification, followed by the address at
32697which the target program is, in the following form:
922fbb7b
AC
32698
32699@smallexample
a2c02241
NR
32700^connected,addr="@var{address}",func="@var{function name}",
32701 args=[@var{arg list}]
922fbb7b
AC
32702@end smallexample
32703
a2c02241
NR
32704@subsubheading @value{GDBN} Command
32705
32706The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
32707
32708@subsubheading Example
922fbb7b 32709
265eeb58 32710@smallexample
594fe323 32711(gdb)
75c99385 32712-target-select remote /dev/ttya
a2c02241 32713^connected,addr="0xfe00a300",func="??",args=[]
594fe323 32714(gdb)
265eeb58 32715@end smallexample
ef21caaf 32716
a6b151f1
DJ
32717@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32718@node GDB/MI File Transfer Commands
32719@section @sc{gdb/mi} File Transfer Commands
32720
32721
32722@subheading The @code{-target-file-put} Command
32723@findex -target-file-put
32724
32725@subsubheading Synopsis
32726
32727@smallexample
32728 -target-file-put @var{hostfile} @var{targetfile}
32729@end smallexample
32730
32731Copy file @var{hostfile} from the host system (the machine running
32732@value{GDBN}) to @var{targetfile} on the target system.
32733
32734@subsubheading @value{GDBN} Command
32735
32736The corresponding @value{GDBN} command is @samp{remote put}.
32737
32738@subsubheading Example
32739
32740@smallexample
32741(gdb)
32742-target-file-put localfile remotefile
32743^done
32744(gdb)
32745@end smallexample
32746
32747
1763a388 32748@subheading The @code{-target-file-get} Command
a6b151f1
DJ
32749@findex -target-file-get
32750
32751@subsubheading Synopsis
32752
32753@smallexample
32754 -target-file-get @var{targetfile} @var{hostfile}
32755@end smallexample
32756
32757Copy file @var{targetfile} from the target system to @var{hostfile}
32758on the host system.
32759
32760@subsubheading @value{GDBN} Command
32761
32762The corresponding @value{GDBN} command is @samp{remote get}.
32763
32764@subsubheading Example
32765
32766@smallexample
32767(gdb)
32768-target-file-get remotefile localfile
32769^done
32770(gdb)
32771@end smallexample
32772
32773
32774@subheading The @code{-target-file-delete} Command
32775@findex -target-file-delete
32776
32777@subsubheading Synopsis
32778
32779@smallexample
32780 -target-file-delete @var{targetfile}
32781@end smallexample
32782
32783Delete @var{targetfile} from the target system.
32784
32785@subsubheading @value{GDBN} Command
32786
32787The corresponding @value{GDBN} command is @samp{remote delete}.
32788
32789@subsubheading Example
32790
32791@smallexample
32792(gdb)
32793-target-file-delete remotefile
32794^done
32795(gdb)
32796@end smallexample
32797
32798
58d06528
JB
32799@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32800@node GDB/MI Ada Exceptions Commands
32801@section Ada Exceptions @sc{gdb/mi} Commands
32802
32803@subheading The @code{-info-ada-exceptions} Command
32804@findex -info-ada-exceptions
32805
32806@subsubheading Synopsis
32807
32808@smallexample
32809 -info-ada-exceptions [ @var{regexp}]
32810@end smallexample
32811
32812List all Ada exceptions defined within the program being debugged.
32813With a regular expression @var{regexp}, only those exceptions whose
32814names match @var{regexp} are listed.
32815
32816@subsubheading @value{GDBN} Command
32817
32818The corresponding @value{GDBN} command is @samp{info exceptions}.
32819
32820@subsubheading Result
32821
32822The result is a table of Ada exceptions. The following columns are
32823defined for each exception:
32824
32825@table @samp
32826@item name
32827The name of the exception.
32828
32829@item address
32830The address of the exception.
32831
32832@end table
32833
32834@subsubheading Example
32835
32836@smallexample
32837-info-ada-exceptions aint
32838^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
32839hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
32840@{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
32841body=[@{name="constraint_error",address="0x0000000000613da0"@},
32842@{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
32843@end smallexample
32844
32845@subheading Catching Ada Exceptions
32846
32847The commands describing how to ask @value{GDBN} to stop when a program
32848raises an exception are described at @ref{Ada Exception GDB/MI
32849Catchpoint Commands}.
32850
32851
ef21caaf 32852@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d192b373
JB
32853@node GDB/MI Support Commands
32854@section @sc{gdb/mi} Support Commands
ef21caaf 32855
d192b373
JB
32856Since new commands and features get regularly added to @sc{gdb/mi},
32857some commands are available to help front-ends query the debugger
32858about support for these capabilities. Similarly, it is also possible
32859to query @value{GDBN} about target support of certain features.
ef21caaf 32860
6b7cbff1
JB
32861@subheading The @code{-info-gdb-mi-command} Command
32862@cindex @code{-info-gdb-mi-command}
32863@findex -info-gdb-mi-command
32864
32865@subsubheading Synopsis
32866
32867@smallexample
32868 -info-gdb-mi-command @var{cmd_name}
32869@end smallexample
32870
32871Query support for the @sc{gdb/mi} command named @var{cmd_name}.
32872
32873Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
32874is technically not part of the command name (@pxref{GDB/MI Input
32875Syntax}), and thus should be omitted in @var{cmd_name}. However,
32876for ease of use, this command also accepts the form with the leading
32877dash.
32878
32879@subsubheading @value{GDBN} Command
32880
32881There is no corresponding @value{GDBN} command.
32882
32883@subsubheading Result
32884
32885The result is a tuple. There is currently only one field:
32886
32887@table @samp
32888@item exists
32889This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
32890@code{"false"} otherwise.
32891
32892@end table
32893
32894@subsubheading Example
32895
32896Here is an example where the @sc{gdb/mi} command does not exist:
32897
32898@smallexample
32899-info-gdb-mi-command unsupported-command
32900^done,command=@{exists="false"@}
32901@end smallexample
32902
32903@noindent
32904And here is an example where the @sc{gdb/mi} command is known
32905to the debugger:
32906
32907@smallexample
32908-info-gdb-mi-command symbol-list-lines
32909^done,command=@{exists="true"@}
32910@end smallexample
32911
084344da
VP
32912@subheading The @code{-list-features} Command
32913@findex -list-features
9b26f0fb 32914@cindex supported @sc{gdb/mi} features, list
084344da
VP
32915
32916Returns a list of particular features of the MI protocol that
32917this version of gdb implements. A feature can be a command,
32918or a new field in an output of some command, or even an
32919important bugfix. While a frontend can sometimes detect presence
32920of a feature at runtime, it is easier to perform detection at debugger
d192b373 32921startup.
084344da
VP
32922
32923The command returns a list of strings, with each string naming an
32924available feature. Each returned string is just a name, it does not
d192b373 32925have any internal structure. The list of possible feature names
084344da
VP
32926is given below.
32927
32928Example output:
32929
32930@smallexample
32931(gdb) -list-features
32932^done,result=["feature1","feature2"]
32933@end smallexample
32934
32935The current list of features is:
32936
edef6000 32937@ftable @samp
30e026bb 32938@item frozen-varobjs
a05336a1
JB
32939Indicates support for the @code{-var-set-frozen} command, as well
32940as possible presense of the @code{frozen} field in the output
30e026bb
VP
32941of @code{-varobj-create}.
32942@item pending-breakpoints
a05336a1
JB
32943Indicates support for the @option{-f} option to the @code{-break-insert}
32944command.
b6313243 32945@item python
a05336a1 32946Indicates Python scripting support, Python-based
b6313243
TT
32947pretty-printing commands, and possible presence of the
32948@samp{display_hint} field in the output of @code{-var-list-children}
30e026bb 32949@item thread-info
a05336a1 32950Indicates support for the @code{-thread-info} command.
8dedea02 32951@item data-read-memory-bytes
a05336a1 32952Indicates support for the @code{-data-read-memory-bytes} and the
8dedea02 32953@code{-data-write-memory-bytes} commands.
39c4d40a
TT
32954@item breakpoint-notifications
32955Indicates that changes to breakpoints and breakpoints created via the
32956CLI will be announced via async records.
5d77fe44 32957@item ada-task-info
6adcee18 32958Indicates support for the @code{-ada-task-info} command.
422ad5c2
JB
32959@item language-option
32960Indicates that all @sc{gdb/mi} commands accept the @option{--language}
32961option (@pxref{Context management}).
6b7cbff1
JB
32962@item info-gdb-mi-command
32963Indicates support for the @code{-info-gdb-mi-command} command.
2ea126fa
JB
32964@item undefined-command-error-code
32965Indicates support for the "undefined-command" error code in error result
32966records, produced when trying to execute an undefined @sc{gdb/mi} command
32967(@pxref{GDB/MI Result Records}).
72bfa06c
JB
32968@item exec-run-start-option
32969Indicates that the @code{-exec-run} command supports the @option{--start}
32970option (@pxref{GDB/MI Program Execution}).
edef6000 32971@end ftable
084344da 32972
c6ebd6cf
VP
32973@subheading The @code{-list-target-features} Command
32974@findex -list-target-features
32975
32976Returns a list of particular features that are supported by the
32977target. Those features affect the permitted MI commands, but
32978unlike the features reported by the @code{-list-features} command, the
32979features depend on which target GDB is using at the moment. Whenever
32980a target can change, due to commands such as @code{-target-select},
32981@code{-target-attach} or @code{-exec-run}, the list of target features
32982may change, and the frontend should obtain it again.
32983Example output:
32984
32985@smallexample
b3d3b4bd 32986(gdb) -list-target-features
c6ebd6cf
VP
32987^done,result=["async"]
32988@end smallexample
32989
32990The current list of features is:
32991
32992@table @samp
32993@item async
32994Indicates that the target is capable of asynchronous command
32995execution, which means that @value{GDBN} will accept further commands
32996while the target is running.
32997
f75d858b
MK
32998@item reverse
32999Indicates that the target is capable of reverse execution.
33000@xref{Reverse Execution}, for more information.
33001
c6ebd6cf
VP
33002@end table
33003
d192b373
JB
33004@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33005@node GDB/MI Miscellaneous Commands
33006@section Miscellaneous @sc{gdb/mi} Commands
33007
33008@c @subheading -gdb-complete
33009
33010@subheading The @code{-gdb-exit} Command
33011@findex -gdb-exit
33012
33013@subsubheading Synopsis
33014
33015@smallexample
33016 -gdb-exit
33017@end smallexample
33018
33019Exit @value{GDBN} immediately.
33020
33021@subsubheading @value{GDBN} Command
33022
33023Approximately corresponds to @samp{quit}.
33024
33025@subsubheading Example
33026
33027@smallexample
33028(gdb)
33029-gdb-exit
33030^exit
33031@end smallexample
33032
33033
33034@ignore
33035@subheading The @code{-exec-abort} Command
33036@findex -exec-abort
33037
33038@subsubheading Synopsis
33039
33040@smallexample
33041 -exec-abort
33042@end smallexample
33043
33044Kill the inferior running program.
33045
33046@subsubheading @value{GDBN} Command
33047
33048The corresponding @value{GDBN} command is @samp{kill}.
33049
33050@subsubheading Example
33051N.A.
33052@end ignore
33053
33054
33055@subheading The @code{-gdb-set} Command
33056@findex -gdb-set
33057
33058@subsubheading Synopsis
33059
33060@smallexample
33061 -gdb-set
33062@end smallexample
33063
33064Set an internal @value{GDBN} variable.
33065@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
33066
33067@subsubheading @value{GDBN} Command
33068
33069The corresponding @value{GDBN} command is @samp{set}.
33070
33071@subsubheading Example
33072
33073@smallexample
33074(gdb)
33075-gdb-set $foo=3
33076^done
33077(gdb)
33078@end smallexample
33079
33080
33081@subheading The @code{-gdb-show} Command
33082@findex -gdb-show
33083
33084@subsubheading Synopsis
33085
33086@smallexample
33087 -gdb-show
33088@end smallexample
33089
33090Show the current value of a @value{GDBN} variable.
33091
33092@subsubheading @value{GDBN} Command
33093
33094The corresponding @value{GDBN} command is @samp{show}.
33095
33096@subsubheading Example
33097
33098@smallexample
33099(gdb)
33100-gdb-show annotate
33101^done,value="0"
33102(gdb)
33103@end smallexample
33104
33105@c @subheading -gdb-source
33106
33107
33108@subheading The @code{-gdb-version} Command
33109@findex -gdb-version
33110
33111@subsubheading Synopsis
33112
33113@smallexample
33114 -gdb-version
33115@end smallexample
33116
33117Show version information for @value{GDBN}. Used mostly in testing.
33118
33119@subsubheading @value{GDBN} Command
33120
33121The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
33122default shows this information when you start an interactive session.
33123
33124@subsubheading Example
33125
33126@c This example modifies the actual output from GDB to avoid overfull
33127@c box in TeX.
33128@smallexample
33129(gdb)
33130-gdb-version
33131~GNU gdb 5.2.1
33132~Copyright 2000 Free Software Foundation, Inc.
33133~GDB is free software, covered by the GNU General Public License, and
33134~you are welcome to change it and/or distribute copies of it under
33135~ certain conditions.
33136~Type "show copying" to see the conditions.
33137~There is absolutely no warranty for GDB. Type "show warranty" for
33138~ details.
33139~This GDB was configured as
33140 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
33141^done
33142(gdb)
33143@end smallexample
33144
c3b108f7
VP
33145@subheading The @code{-list-thread-groups} Command
33146@findex -list-thread-groups
33147
33148@subheading Synopsis
33149
33150@smallexample
dc146f7c 33151-list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
c3b108f7
VP
33152@end smallexample
33153
dc146f7c
VP
33154Lists thread groups (@pxref{Thread groups}). When a single thread
33155group is passed as the argument, lists the children of that group.
33156When several thread group are passed, lists information about those
33157thread groups. Without any parameters, lists information about all
33158top-level thread groups.
33159
33160Normally, thread groups that are being debugged are reported.
33161With the @samp{--available} option, @value{GDBN} reports thread groups
33162available on the target.
33163
33164The output of this command may have either a @samp{threads} result or
33165a @samp{groups} result. The @samp{thread} result has a list of tuples
33166as value, with each tuple describing a thread (@pxref{GDB/MI Thread
33167Information}). The @samp{groups} result has a list of tuples as value,
33168each tuple describing a thread group. If top-level groups are
33169requested (that is, no parameter is passed), or when several groups
33170are passed, the output always has a @samp{groups} result. The format
33171of the @samp{group} result is described below.
33172
33173To reduce the number of roundtrips it's possible to list thread groups
33174together with their children, by passing the @samp{--recurse} option
33175and the recursion depth. Presently, only recursion depth of 1 is
33176permitted. If this option is present, then every reported thread group
33177will also include its children, either as @samp{group} or
33178@samp{threads} field.
33179
33180In general, any combination of option and parameters is permitted, with
33181the following caveats:
33182
33183@itemize @bullet
33184@item
33185When a single thread group is passed, the output will typically
33186be the @samp{threads} result. Because threads may not contain
33187anything, the @samp{recurse} option will be ignored.
33188
33189@item
33190When the @samp{--available} option is passed, limited information may
33191be available. In particular, the list of threads of a process might
33192be inaccessible. Further, specifying specific thread groups might
33193not give any performance advantage over listing all thread groups.
33194The frontend should assume that @samp{-list-thread-groups --available}
33195is always an expensive operation and cache the results.
33196
33197@end itemize
33198
33199The @samp{groups} result is a list of tuples, where each tuple may
33200have the following fields:
33201
33202@table @code
33203@item id
33204Identifier of the thread group. This field is always present.
a79b8f6e
VP
33205The identifier is an opaque string; frontends should not try to
33206convert it to an integer, even though it might look like one.
dc146f7c
VP
33207
33208@item type
33209The type of the thread group. At present, only @samp{process} is a
33210valid type.
33211
33212@item pid
33213The target-specific process identifier. This field is only present
a79b8f6e 33214for thread groups of type @samp{process} and only if the process exists.
c3b108f7 33215
2ddf4301
SM
33216@item exit-code
33217The exit code of this group's last exited thread, formatted in octal.
33218This field is only present for thread groups of type @samp{process} and
33219only if the process is not running.
33220
dc146f7c
VP
33221@item num_children
33222The number of children this thread group has. This field may be
33223absent for an available thread group.
33224
33225@item threads
33226This field has a list of tuples as value, each tuple describing a
33227thread. It may be present if the @samp{--recurse} option is
33228specified, and it's actually possible to obtain the threads.
33229
33230@item cores
33231This field is a list of integers, each identifying a core that one
33232thread of the group is running on. This field may be absent if
33233such information is not available.
33234
a79b8f6e
VP
33235@item executable
33236The name of the executable file that corresponds to this thread group.
33237The field is only present for thread groups of type @samp{process},
33238and only if there is a corresponding executable file.
33239
dc146f7c 33240@end table
c3b108f7
VP
33241
33242@subheading Example
33243
33244@smallexample
33245@value{GDBP}
33246-list-thread-groups
33247^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
33248-list-thread-groups 17
33249^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
33250 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
33251@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
33252 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
33253 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}]]
dc146f7c
VP
33254-list-thread-groups --available
33255^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
33256-list-thread-groups --available --recurse 1
33257 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
33258 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
33259 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
33260-list-thread-groups --available --recurse 1 17 18
33261^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
33262 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
33263 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
c3b108f7 33264@end smallexample
c6ebd6cf 33265
f3e0e960
SS
33266@subheading The @code{-info-os} Command
33267@findex -info-os
33268
33269@subsubheading Synopsis
33270
33271@smallexample
33272-info-os [ @var{type} ]
33273@end smallexample
33274
33275If no argument is supplied, the command returns a table of available
33276operating-system-specific information types. If one of these types is
33277supplied as an argument @var{type}, then the command returns a table
33278of data of that type.
33279
33280The types of information available depend on the target operating
33281system.
33282
33283@subsubheading @value{GDBN} Command
33284
33285The corresponding @value{GDBN} command is @samp{info os}.
33286
33287@subsubheading Example
33288
33289When run on a @sc{gnu}/Linux system, the output will look something
33290like this:
33291
33292@smallexample
33293@value{GDBP}
33294-info-os
d33279b3 33295^done,OSDataTable=@{nr_rows="10",nr_cols="3",
f3e0e960 33296hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
71caed83
SS
33297 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
33298 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
d33279b3
AT
33299body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
33300 col2="CPUs"@},
33301 item=@{col0="files",col1="Listing of all file descriptors",
33302 col2="File descriptors"@},
33303 item=@{col0="modules",col1="Listing of all loaded kernel modules",
33304 col2="Kernel modules"@},
33305 item=@{col0="msg",col1="Listing of all message queues",
33306 col2="Message queues"@},
33307 item=@{col0="processes",col1="Listing of all processes",
71caed83
SS
33308 col2="Processes"@},
33309 item=@{col0="procgroups",col1="Listing of all process groups",
33310 col2="Process groups"@},
71caed83
SS
33311 item=@{col0="semaphores",col1="Listing of all semaphores",
33312 col2="Semaphores"@},
d33279b3
AT
33313 item=@{col0="shm",col1="Listing of all shared-memory regions",
33314 col2="Shared-memory regions"@},
33315 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
33316 col2="Sockets"@},
33317 item=@{col0="threads",col1="Listing of all threads",
33318 col2="Threads"@}]
f3e0e960
SS
33319@value{GDBP}
33320-info-os processes
33321^done,OSDataTable=@{nr_rows="190",nr_cols="4",
33322hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
33323 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
33324 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
33325 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
33326body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
33327 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
33328 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
33329 ...
33330 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
33331 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
33332(gdb)
33333@end smallexample
a79b8f6e 33334
71caed83
SS
33335(Note that the MI output here includes a @code{"Title"} column that
33336does not appear in command-line @code{info os}; this column is useful
33337for MI clients that want to enumerate the types of data, such as in a
33338popup menu, but is needless clutter on the command line, and
33339@code{info os} omits it.)
33340
a79b8f6e
VP
33341@subheading The @code{-add-inferior} Command
33342@findex -add-inferior
33343
33344@subheading Synopsis
33345
33346@smallexample
33347-add-inferior
33348@end smallexample
33349
33350Creates a new inferior (@pxref{Inferiors and Programs}). The created
33351inferior is not associated with any executable. Such association may
33352be established with the @samp{-file-exec-and-symbols} command
33353(@pxref{GDB/MI File Commands}). The command response has a single
b7742092 33354field, @samp{inferior}, whose value is the identifier of the
a79b8f6e
VP
33355thread group corresponding to the new inferior.
33356
33357@subheading Example
33358
33359@smallexample
33360@value{GDBP}
33361-add-inferior
b7742092 33362^done,inferior="i3"
a79b8f6e
VP
33363@end smallexample
33364
ef21caaf
NR
33365@subheading The @code{-interpreter-exec} Command
33366@findex -interpreter-exec
33367
33368@subheading Synopsis
33369
33370@smallexample
33371-interpreter-exec @var{interpreter} @var{command}
33372@end smallexample
a2c02241 33373@anchor{-interpreter-exec}
ef21caaf
NR
33374
33375Execute the specified @var{command} in the given @var{interpreter}.
33376
33377@subheading @value{GDBN} Command
33378
33379The corresponding @value{GDBN} command is @samp{interpreter-exec}.
33380
33381@subheading Example
33382
33383@smallexample
594fe323 33384(gdb)
ef21caaf
NR
33385-interpreter-exec console "break main"
33386&"During symbol reading, couldn't parse type; debugger out of date?.\n"
33387&"During symbol reading, bad structure-type format.\n"
33388~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
33389^done
594fe323 33390(gdb)
ef21caaf
NR
33391@end smallexample
33392
33393@subheading The @code{-inferior-tty-set} Command
33394@findex -inferior-tty-set
33395
33396@subheading Synopsis
33397
33398@smallexample
33399-inferior-tty-set /dev/pts/1
33400@end smallexample
33401
33402Set terminal for future runs of the program being debugged.
33403
33404@subheading @value{GDBN} Command
33405
33406The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
33407
33408@subheading Example
33409
33410@smallexample
594fe323 33411(gdb)
ef21caaf
NR
33412-inferior-tty-set /dev/pts/1
33413^done
594fe323 33414(gdb)
ef21caaf
NR
33415@end smallexample
33416
33417@subheading The @code{-inferior-tty-show} Command
33418@findex -inferior-tty-show
33419
33420@subheading Synopsis
33421
33422@smallexample
33423-inferior-tty-show
33424@end smallexample
33425
33426Show terminal for future runs of program being debugged.
33427
33428@subheading @value{GDBN} Command
33429
33430The corresponding @value{GDBN} command is @samp{show inferior-tty}.
33431
33432@subheading Example
33433
33434@smallexample
594fe323 33435(gdb)
ef21caaf
NR
33436-inferior-tty-set /dev/pts/1
33437^done
594fe323 33438(gdb)
ef21caaf
NR
33439-inferior-tty-show
33440^done,inferior_tty_terminal="/dev/pts/1"
594fe323 33441(gdb)
ef21caaf 33442@end smallexample
922fbb7b 33443
a4eefcd8
NR
33444@subheading The @code{-enable-timings} Command
33445@findex -enable-timings
33446
33447@subheading Synopsis
33448
33449@smallexample
33450-enable-timings [yes | no]
33451@end smallexample
33452
33453Toggle the printing of the wallclock, user and system times for an MI
33454command as a field in its output. This command is to help frontend
33455developers optimize the performance of their code. No argument is
33456equivalent to @samp{yes}.
33457
33458@subheading @value{GDBN} Command
33459
33460No equivalent.
33461
33462@subheading Example
33463
33464@smallexample
33465(gdb)
33466-enable-timings
33467^done
33468(gdb)
33469-break-insert main
33470^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
33471addr="0x080484ed",func="main",file="myprog.c",
998580f1
MK
33472fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
33473times="0"@},
a4eefcd8
NR
33474time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
33475(gdb)
33476-enable-timings no
33477^done
33478(gdb)
33479-exec-run
33480^running
33481(gdb)
a47ec5fe 33482*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
a4eefcd8
NR
33483frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
33484@{name="argv",value="0xbfb60364"@}],file="myprog.c",
33485fullname="/home/nickrob/myprog.c",line="73"@}
33486(gdb)
33487@end smallexample
33488
922fbb7b
AC
33489@node Annotations
33490@chapter @value{GDBN} Annotations
33491
086432e2
AC
33492This chapter describes annotations in @value{GDBN}. Annotations were
33493designed to interface @value{GDBN} to graphical user interfaces or other
33494similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
33495relatively high level.
33496
d3e8051b 33497The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
33498(@pxref{GDB/MI}).
33499
922fbb7b
AC
33500@ignore
33501This is Edition @value{EDITION}, @value{DATE}.
33502@end ignore
33503
33504@menu
33505* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 33506* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
33507* Prompting:: Annotations marking @value{GDBN}'s need for input.
33508* Errors:: Annotations for error messages.
922fbb7b
AC
33509* Invalidation:: Some annotations describe things now invalid.
33510* Annotations for Running::
33511 Whether the program is running, how it stopped, etc.
33512* Source Annotations:: Annotations describing source code.
922fbb7b
AC
33513@end menu
33514
33515@node Annotations Overview
33516@section What is an Annotation?
33517@cindex annotations
33518
922fbb7b
AC
33519Annotations start with a newline character, two @samp{control-z}
33520characters, and the name of the annotation. If there is no additional
33521information associated with this annotation, the name of the annotation
33522is followed immediately by a newline. If there is additional
33523information, the name of the annotation is followed by a space, the
33524additional information, and a newline. The additional information
33525cannot contain newline characters.
33526
33527Any output not beginning with a newline and two @samp{control-z}
33528characters denotes literal output from @value{GDBN}. Currently there is
33529no need for @value{GDBN} to output a newline followed by two
33530@samp{control-z} characters, but if there was such a need, the
33531annotations could be extended with an @samp{escape} annotation which
33532means those three characters as output.
33533
086432e2
AC
33534The annotation @var{level}, which is specified using the
33535@option{--annotate} command line option (@pxref{Mode Options}), controls
33536how much information @value{GDBN} prints together with its prompt,
33537values of expressions, source lines, and other types of output. Level 0
d3e8051b 33538is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
33539subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
33540for programs that control @value{GDBN}, and level 2 annotations have
33541been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
33542Interface, annotate, GDB's Obsolete Annotations}).
33543
33544@table @code
33545@kindex set annotate
33546@item set annotate @var{level}
e09f16f9 33547The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 33548annotations to the specified @var{level}.
9c16f35a
EZ
33549
33550@item show annotate
33551@kindex show annotate
33552Show the current annotation level.
09d4efe1
EZ
33553@end table
33554
33555This chapter describes level 3 annotations.
086432e2 33556
922fbb7b
AC
33557A simple example of starting up @value{GDBN} with annotations is:
33558
33559@smallexample
086432e2
AC
33560$ @kbd{gdb --annotate=3}
33561GNU gdb 6.0
33562Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
33563GDB is free software, covered by the GNU General Public License,
33564and you are welcome to change it and/or distribute copies of it
33565under certain conditions.
33566Type "show copying" to see the conditions.
33567There is absolutely no warranty for GDB. Type "show warranty"
33568for details.
086432e2 33569This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
33570
33571^Z^Zpre-prompt
f7dc1244 33572(@value{GDBP})
922fbb7b 33573^Z^Zprompt
086432e2 33574@kbd{quit}
922fbb7b
AC
33575
33576^Z^Zpost-prompt
b383017d 33577$
922fbb7b
AC
33578@end smallexample
33579
33580Here @samp{quit} is input to @value{GDBN}; the rest is output from
33581@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
33582denotes a @samp{control-z} character) are annotations; the rest is
33583output from @value{GDBN}.
33584
9e6c4bd5
NR
33585@node Server Prefix
33586@section The Server Prefix
33587@cindex server prefix
33588
33589If you prefix a command with @samp{server } then it will not affect
33590the command history, nor will it affect @value{GDBN}'s notion of which
33591command to repeat if @key{RET} is pressed on a line by itself. This
33592means that commands can be run behind a user's back by a front-end in
33593a transparent manner.
33594
d837706a
NR
33595The @code{server } prefix does not affect the recording of values into
33596the value history; to print a value without recording it into the
33597value history, use the @code{output} command instead of the
33598@code{print} command.
33599
33600Using this prefix also disables confirmation requests
33601(@pxref{confirmation requests}).
9e6c4bd5 33602
922fbb7b
AC
33603@node Prompting
33604@section Annotation for @value{GDBN} Input
33605
33606@cindex annotations for prompts
33607When @value{GDBN} prompts for input, it annotates this fact so it is possible
33608to know when to send output, when the output from a given command is
33609over, etc.
33610
33611Different kinds of input each have a different @dfn{input type}. Each
33612input type has three annotations: a @code{pre-} annotation, which
33613denotes the beginning of any prompt which is being output, a plain
33614annotation, which denotes the end of the prompt, and then a @code{post-}
33615annotation which denotes the end of any echo which may (or may not) be
33616associated with the input. For example, the @code{prompt} input type
33617features the following annotations:
33618
33619@smallexample
33620^Z^Zpre-prompt
33621^Z^Zprompt
33622^Z^Zpost-prompt
33623@end smallexample
33624
33625The input types are
33626
33627@table @code
e5ac9b53
EZ
33628@findex pre-prompt annotation
33629@findex prompt annotation
33630@findex post-prompt annotation
922fbb7b
AC
33631@item prompt
33632When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
33633
e5ac9b53
EZ
33634@findex pre-commands annotation
33635@findex commands annotation
33636@findex post-commands annotation
922fbb7b
AC
33637@item commands
33638When @value{GDBN} prompts for a set of commands, like in the @code{commands}
33639command. The annotations are repeated for each command which is input.
33640
e5ac9b53
EZ
33641@findex pre-overload-choice annotation
33642@findex overload-choice annotation
33643@findex post-overload-choice annotation
922fbb7b
AC
33644@item overload-choice
33645When @value{GDBN} wants the user to select between various overloaded functions.
33646
e5ac9b53
EZ
33647@findex pre-query annotation
33648@findex query annotation
33649@findex post-query annotation
922fbb7b
AC
33650@item query
33651When @value{GDBN} wants the user to confirm a potentially dangerous operation.
33652
e5ac9b53
EZ
33653@findex pre-prompt-for-continue annotation
33654@findex prompt-for-continue annotation
33655@findex post-prompt-for-continue annotation
922fbb7b
AC
33656@item prompt-for-continue
33657When @value{GDBN} is asking the user to press return to continue. Note: Don't
33658expect this to work well; instead use @code{set height 0} to disable
33659prompting. This is because the counting of lines is buggy in the
33660presence of annotations.
33661@end table
33662
33663@node Errors
33664@section Errors
33665@cindex annotations for errors, warnings and interrupts
33666
e5ac9b53 33667@findex quit annotation
922fbb7b
AC
33668@smallexample
33669^Z^Zquit
33670@end smallexample
33671
33672This annotation occurs right before @value{GDBN} responds to an interrupt.
33673
e5ac9b53 33674@findex error annotation
922fbb7b
AC
33675@smallexample
33676^Z^Zerror
33677@end smallexample
33678
33679This annotation occurs right before @value{GDBN} responds to an error.
33680
33681Quit and error annotations indicate that any annotations which @value{GDBN} was
33682in the middle of may end abruptly. For example, if a
33683@code{value-history-begin} annotation is followed by a @code{error}, one
33684cannot expect to receive the matching @code{value-history-end}. One
33685cannot expect not to receive it either, however; an error annotation
33686does not necessarily mean that @value{GDBN} is immediately returning all the way
33687to the top level.
33688
e5ac9b53 33689@findex error-begin annotation
922fbb7b
AC
33690A quit or error annotation may be preceded by
33691
33692@smallexample
33693^Z^Zerror-begin
33694@end smallexample
33695
33696Any output between that and the quit or error annotation is the error
33697message.
33698
33699Warning messages are not yet annotated.
33700@c If we want to change that, need to fix warning(), type_error(),
33701@c range_error(), and possibly other places.
33702
922fbb7b
AC
33703@node Invalidation
33704@section Invalidation Notices
33705
33706@cindex annotations for invalidation messages
33707The following annotations say that certain pieces of state may have
33708changed.
33709
33710@table @code
e5ac9b53 33711@findex frames-invalid annotation
922fbb7b
AC
33712@item ^Z^Zframes-invalid
33713
33714The frames (for example, output from the @code{backtrace} command) may
33715have changed.
33716
e5ac9b53 33717@findex breakpoints-invalid annotation
922fbb7b
AC
33718@item ^Z^Zbreakpoints-invalid
33719
33720The breakpoints may have changed. For example, the user just added or
33721deleted a breakpoint.
33722@end table
33723
33724@node Annotations for Running
33725@section Running the Program
33726@cindex annotations for running programs
33727
e5ac9b53
EZ
33728@findex starting annotation
33729@findex stopping annotation
922fbb7b 33730When the program starts executing due to a @value{GDBN} command such as
b383017d 33731@code{step} or @code{continue},
922fbb7b
AC
33732
33733@smallexample
33734^Z^Zstarting
33735@end smallexample
33736
b383017d 33737is output. When the program stops,
922fbb7b
AC
33738
33739@smallexample
33740^Z^Zstopped
33741@end smallexample
33742
33743is output. Before the @code{stopped} annotation, a variety of
33744annotations describe how the program stopped.
33745
33746@table @code
e5ac9b53 33747@findex exited annotation
922fbb7b
AC
33748@item ^Z^Zexited @var{exit-status}
33749The program exited, and @var{exit-status} is the exit status (zero for
33750successful exit, otherwise nonzero).
33751
e5ac9b53
EZ
33752@findex signalled annotation
33753@findex signal-name annotation
33754@findex signal-name-end annotation
33755@findex signal-string annotation
33756@findex signal-string-end annotation
922fbb7b
AC
33757@item ^Z^Zsignalled
33758The program exited with a signal. After the @code{^Z^Zsignalled}, the
33759annotation continues:
33760
33761@smallexample
33762@var{intro-text}
33763^Z^Zsignal-name
33764@var{name}
33765^Z^Zsignal-name-end
33766@var{middle-text}
33767^Z^Zsignal-string
33768@var{string}
33769^Z^Zsignal-string-end
33770@var{end-text}
33771@end smallexample
33772
33773@noindent
33774where @var{name} is the name of the signal, such as @code{SIGILL} or
33775@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
697aa1b7 33776as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
922fbb7b
AC
33777@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
33778user's benefit and have no particular format.
33779
e5ac9b53 33780@findex signal annotation
922fbb7b
AC
33781@item ^Z^Zsignal
33782The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
33783just saying that the program received the signal, not that it was
33784terminated with it.
33785
e5ac9b53 33786@findex breakpoint annotation
922fbb7b
AC
33787@item ^Z^Zbreakpoint @var{number}
33788The program hit breakpoint number @var{number}.
33789
e5ac9b53 33790@findex watchpoint annotation
922fbb7b
AC
33791@item ^Z^Zwatchpoint @var{number}
33792The program hit watchpoint number @var{number}.
33793@end table
33794
33795@node Source Annotations
33796@section Displaying Source
33797@cindex annotations for source display
33798
e5ac9b53 33799@findex source annotation
922fbb7b
AC
33800The following annotation is used instead of displaying source code:
33801
33802@smallexample
33803^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
33804@end smallexample
33805
33806where @var{filename} is an absolute file name indicating which source
33807file, @var{line} is the line number within that file (where 1 is the
33808first line in the file), @var{character} is the character position
33809within the file (where 0 is the first character in the file) (for most
33810debug formats this will necessarily point to the beginning of a line),
33811@var{middle} is @samp{middle} if @var{addr} is in the middle of the
33812line, or @samp{beg} if @var{addr} is at the beginning of the line, and
33813@var{addr} is the address in the target program associated with the
697aa1b7 33814source which is being displayed. The @var{addr} is in the form @samp{0x}
922fbb7b
AC
33815followed by one or more lowercase hex digits (note that this does not
33816depend on the language).
33817
4efc6507
DE
33818@node JIT Interface
33819@chapter JIT Compilation Interface
33820@cindex just-in-time compilation
33821@cindex JIT compilation interface
33822
33823This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
33824interface. A JIT compiler is a program or library that generates native
33825executable code at runtime and executes it, usually in order to achieve good
33826performance while maintaining platform independence.
33827
33828Programs that use JIT compilation are normally difficult to debug because
33829portions of their code are generated at runtime, instead of being loaded from
33830object files, which is where @value{GDBN} normally finds the program's symbols
33831and debug information. In order to debug programs that use JIT compilation,
33832@value{GDBN} has an interface that allows the program to register in-memory
33833symbol files with @value{GDBN} at runtime.
33834
33835If you are using @value{GDBN} to debug a program that uses this interface, then
33836it should work transparently so long as you have not stripped the binary. If
33837you are developing a JIT compiler, then the interface is documented in the rest
33838of this chapter. At this time, the only known client of this interface is the
33839LLVM JIT.
33840
33841Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
33842JIT compiler communicates with @value{GDBN} by writing data into a global
33843variable and calling a fuction at a well-known symbol. When @value{GDBN}
33844attaches, it reads a linked list of symbol files from the global variable to
33845find existing code, and puts a breakpoint in the function so that it can find
33846out about additional code.
33847
33848@menu
33849* Declarations:: Relevant C struct declarations
33850* Registering Code:: Steps to register code
33851* Unregistering Code:: Steps to unregister code
f85b53f8 33852* Custom Debug Info:: Emit debug information in a custom format
4efc6507
DE
33853@end menu
33854
33855@node Declarations
33856@section JIT Declarations
33857
33858These are the relevant struct declarations that a C program should include to
33859implement the interface:
33860
33861@smallexample
33862typedef enum
33863@{
33864 JIT_NOACTION = 0,
33865 JIT_REGISTER_FN,
33866 JIT_UNREGISTER_FN
33867@} jit_actions_t;
33868
33869struct jit_code_entry
33870@{
33871 struct jit_code_entry *next_entry;
33872 struct jit_code_entry *prev_entry;
33873 const char *symfile_addr;
33874 uint64_t symfile_size;
33875@};
33876
33877struct jit_descriptor
33878@{
33879 uint32_t version;
33880 /* This type should be jit_actions_t, but we use uint32_t
33881 to be explicit about the bitwidth. */
33882 uint32_t action_flag;
33883 struct jit_code_entry *relevant_entry;
33884 struct jit_code_entry *first_entry;
33885@};
33886
33887/* GDB puts a breakpoint in this function. */
33888void __attribute__((noinline)) __jit_debug_register_code() @{ @};
33889
33890/* Make sure to specify the version statically, because the
33891 debugger may check the version before we can set it. */
33892struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
33893@end smallexample
33894
33895If the JIT is multi-threaded, then it is important that the JIT synchronize any
33896modifications to this global data properly, which can easily be done by putting
33897a global mutex around modifications to these structures.
33898
33899@node Registering Code
33900@section Registering Code
33901
33902To register code with @value{GDBN}, the JIT should follow this protocol:
33903
33904@itemize @bullet
33905@item
33906Generate an object file in memory with symbols and other desired debug
33907information. The file must include the virtual addresses of the sections.
33908
33909@item
33910Create a code entry for the file, which gives the start and size of the symbol
33911file.
33912
33913@item
33914Add it to the linked list in the JIT descriptor.
33915
33916@item
33917Point the relevant_entry field of the descriptor at the entry.
33918
33919@item
33920Set @code{action_flag} to @code{JIT_REGISTER} and call
33921@code{__jit_debug_register_code}.
33922@end itemize
33923
33924When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
33925@code{relevant_entry} pointer so it doesn't have to walk the list looking for
33926new code. However, the linked list must still be maintained in order to allow
33927@value{GDBN} to attach to a running process and still find the symbol files.
33928
33929@node Unregistering Code
33930@section Unregistering Code
33931
33932If code is freed, then the JIT should use the following protocol:
33933
33934@itemize @bullet
33935@item
33936Remove the code entry corresponding to the code from the linked list.
33937
33938@item
33939Point the @code{relevant_entry} field of the descriptor at the code entry.
33940
33941@item
33942Set @code{action_flag} to @code{JIT_UNREGISTER} and call
33943@code{__jit_debug_register_code}.
33944@end itemize
33945
33946If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
33947and the JIT will leak the memory used for the associated symbol files.
33948
f85b53f8
SD
33949@node Custom Debug Info
33950@section Custom Debug Info
33951@cindex custom JIT debug info
33952@cindex JIT debug info reader
33953
33954Generating debug information in platform-native file formats (like ELF
33955or COFF) may be an overkill for JIT compilers; especially if all the
33956debug info is used for is displaying a meaningful backtrace. The
33957issue can be resolved by having the JIT writers decide on a debug info
33958format and also provide a reader that parses the debug info generated
33959by the JIT compiler. This section gives a brief overview on writing
33960such a parser. More specific details can be found in the source file
33961@file{gdb/jit-reader.in}, which is also installed as a header at
33962@file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
33963
33964The reader is implemented as a shared object (so this functionality is
33965not available on platforms which don't allow loading shared objects at
33966runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
33967@code{jit-reader-unload} are provided, to be used to load and unload
33968the readers from a preconfigured directory. Once loaded, the shared
33969object is used the parse the debug information emitted by the JIT
33970compiler.
33971
33972@menu
33973* Using JIT Debug Info Readers:: How to use supplied readers correctly
33974* Writing JIT Debug Info Readers:: Creating a debug-info reader
33975@end menu
33976
33977@node Using JIT Debug Info Readers
33978@subsection Using JIT Debug Info Readers
33979@kindex jit-reader-load
33980@kindex jit-reader-unload
33981
33982Readers can be loaded and unloaded using the @code{jit-reader-load}
33983and @code{jit-reader-unload} commands.
33984
33985@table @code
c9fb1240 33986@item jit-reader-load @var{reader}
697aa1b7 33987Load the JIT reader named @var{reader}, which is a shared
c9fb1240
SD
33988object specified as either an absolute or a relative file name. In
33989the latter case, @value{GDBN} will try to load the reader from a
33990pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
33991system (here @var{libdir} is the system library directory, often
33992@file{/usr/local/lib}).
33993
33994Only one reader can be active at a time; trying to load a second
33995reader when one is already loaded will result in @value{GDBN}
33996reporting an error. A new JIT reader can be loaded by first unloading
33997the current one using @code{jit-reader-unload} and then invoking
33998@code{jit-reader-load}.
f85b53f8
SD
33999
34000@item jit-reader-unload
34001Unload the currently loaded JIT reader.
34002
34003@end table
34004
34005@node Writing JIT Debug Info Readers
34006@subsection Writing JIT Debug Info Readers
34007@cindex writing JIT debug info readers
34008
34009As mentioned, a reader is essentially a shared object conforming to a
34010certain ABI. This ABI is described in @file{jit-reader.h}.
34011
34012@file{jit-reader.h} defines the structures, macros and functions
34013required to write a reader. It is installed (along with
34014@value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
34015the system include directory.
34016
34017Readers need to be released under a GPL compatible license. A reader
34018can be declared as released under such a license by placing the macro
34019@code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
34020
34021The entry point for readers is the symbol @code{gdb_init_reader},
34022which is expected to be a function with the prototype
34023
34024@findex gdb_init_reader
34025@smallexample
34026extern struct gdb_reader_funcs *gdb_init_reader (void);
34027@end smallexample
34028
34029@cindex @code{struct gdb_reader_funcs}
34030
34031@code{struct gdb_reader_funcs} contains a set of pointers to callback
34032functions. These functions are executed to read the debug info
34033generated by the JIT compiler (@code{read}), to unwind stack frames
34034(@code{unwind}) and to create canonical frame IDs
34035(@code{get_Frame_id}). It also has a callback that is called when the
34036reader is being unloaded (@code{destroy}). The struct looks like this
34037
34038@smallexample
34039struct gdb_reader_funcs
34040@{
34041 /* Must be set to GDB_READER_INTERFACE_VERSION. */
34042 int reader_version;
34043
34044 /* For use by the reader. */
34045 void *priv_data;
34046
34047 gdb_read_debug_info *read;
34048 gdb_unwind_frame *unwind;
34049 gdb_get_frame_id *get_frame_id;
34050 gdb_destroy_reader *destroy;
34051@};
34052@end smallexample
34053
34054@cindex @code{struct gdb_symbol_callbacks}
34055@cindex @code{struct gdb_unwind_callbacks}
34056
34057The callbacks are provided with another set of callbacks by
34058@value{GDBN} to do their job. For @code{read}, these callbacks are
34059passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
34060and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
34061@code{struct gdb_symbol_callbacks} has callbacks to create new object
34062files and new symbol tables inside those object files. @code{struct
34063gdb_unwind_callbacks} has callbacks to read registers off the current
34064frame and to write out the values of the registers in the previous
34065frame. Both have a callback (@code{target_read}) to read bytes off the
34066target's address space.
34067
d1feda86
YQ
34068@node In-Process Agent
34069@chapter In-Process Agent
34070@cindex debugging agent
34071The traditional debugging model is conceptually low-speed, but works fine,
34072because most bugs can be reproduced in debugging-mode execution. However,
34073as multi-core or many-core processors are becoming mainstream, and
34074multi-threaded programs become more and more popular, there should be more
34075and more bugs that only manifest themselves at normal-mode execution, for
34076example, thread races, because debugger's interference with the program's
34077timing may conceal the bugs. On the other hand, in some applications,
34078it is not feasible for the debugger to interrupt the program's execution
34079long enough for the developer to learn anything helpful about its behavior.
34080If the program's correctness depends on its real-time behavior, delays
34081introduced by a debugger might cause the program to fail, even when the
34082code itself is correct. It is useful to be able to observe the program's
34083behavior without interrupting it.
34084
34085Therefore, traditional debugging model is too intrusive to reproduce
34086some bugs. In order to reduce the interference with the program, we can
34087reduce the number of operations performed by debugger. The
34088@dfn{In-Process Agent}, a shared library, is running within the same
34089process with inferior, and is able to perform some debugging operations
34090itself. As a result, debugger is only involved when necessary, and
34091performance of debugging can be improved accordingly. Note that
34092interference with program can be reduced but can't be removed completely,
34093because the in-process agent will still stop or slow down the program.
34094
34095The in-process agent can interpret and execute Agent Expressions
34096(@pxref{Agent Expressions}) during performing debugging operations. The
34097agent expressions can be used for different purposes, such as collecting
34098data in tracepoints, and condition evaluation in breakpoints.
34099
34100@anchor{Control Agent}
34101You can control whether the in-process agent is used as an aid for
34102debugging with the following commands:
34103
34104@table @code
34105@kindex set agent on
34106@item set agent on
34107Causes the in-process agent to perform some operations on behalf of the
34108debugger. Just which operations requested by the user will be done
34109by the in-process agent depends on the its capabilities. For example,
34110if you request to evaluate breakpoint conditions in the in-process agent,
34111and the in-process agent has such capability as well, then breakpoint
34112conditions will be evaluated in the in-process agent.
34113
34114@kindex set agent off
34115@item set agent off
34116Disables execution of debugging operations by the in-process agent. All
34117of the operations will be performed by @value{GDBN}.
34118
34119@kindex show agent
34120@item show agent
34121Display the current setting of execution of debugging operations by
34122the in-process agent.
34123@end table
34124
16bdd41f
YQ
34125@menu
34126* In-Process Agent Protocol::
34127@end menu
34128
34129@node In-Process Agent Protocol
34130@section In-Process Agent Protocol
34131@cindex in-process agent protocol
34132
34133The in-process agent is able to communicate with both @value{GDBN} and
34134GDBserver (@pxref{In-Process Agent}). This section documents the protocol
34135used for communications between @value{GDBN} or GDBserver and the IPA.
34136In general, @value{GDBN} or GDBserver sends commands
34137(@pxref{IPA Protocol Commands}) and data to in-process agent, and then
34138in-process agent replies back with the return result of the command, or
34139some other information. The data sent to in-process agent is composed
34140of primitive data types, such as 4-byte or 8-byte type, and composite
34141types, which are called objects (@pxref{IPA Protocol Objects}).
34142
34143@menu
34144* IPA Protocol Objects::
34145* IPA Protocol Commands::
34146@end menu
34147
34148@node IPA Protocol Objects
34149@subsection IPA Protocol Objects
34150@cindex ipa protocol objects
34151
34152The commands sent to and results received from agent may contain some
34153complex data types called @dfn{objects}.
34154
34155The in-process agent is running on the same machine with @value{GDBN}
34156or GDBserver, so it doesn't have to handle as much differences between
34157two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
34158However, there are still some differences of two ends in two processes:
34159
34160@enumerate
34161@item
34162word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
34163compiled as a 64-bit executable, while in-process agent is a 32-bit one.
34164@item
34165ABI. Some machines may have multiple types of ABI, @value{GDBN} or
34166GDBserver is compiled with one, and in-process agent is compiled with
34167the other one.
34168@end enumerate
34169
34170Here are the IPA Protocol Objects:
34171
34172@enumerate
34173@item
34174agent expression object. It represents an agent expression
34175(@pxref{Agent Expressions}).
34176@anchor{agent expression object}
34177@item
34178tracepoint action object. It represents a tracepoint action
34179(@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
34180memory, static trace data and to evaluate expression.
34181@anchor{tracepoint action object}
34182@item
34183tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
34184@anchor{tracepoint object}
34185
34186@end enumerate
34187
34188The following table describes important attributes of each IPA protocol
34189object:
34190
34191@multitable @columnfractions .30 .20 .50
34192@headitem Name @tab Size @tab Description
34193@item @emph{agent expression object} @tab @tab
34194@item length @tab 4 @tab length of bytes code
34195@item byte code @tab @var{length} @tab contents of byte code
34196@item @emph{tracepoint action for collecting memory} @tab @tab
34197@item 'M' @tab 1 @tab type of tracepoint action
34198@item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
34199address of the lowest byte to collect, otherwise @var{addr} is the offset
34200of @var{basereg} for memory collecting.
34201@item len @tab 8 @tab length of memory for collecting
34202@item basereg @tab 4 @tab the register number containing the starting
34203memory address for collecting.
34204@item @emph{tracepoint action for collecting registers} @tab @tab
34205@item 'R' @tab 1 @tab type of tracepoint action
34206@item @emph{tracepoint action for collecting static trace data} @tab @tab
34207@item 'L' @tab 1 @tab type of tracepoint action
34208@item @emph{tracepoint action for expression evaluation} @tab @tab
34209@item 'X' @tab 1 @tab type of tracepoint action
34210@item agent expression @tab length of @tab @ref{agent expression object}
34211@item @emph{tracepoint object} @tab @tab
34212@item number @tab 4 @tab number of tracepoint
34213@item address @tab 8 @tab address of tracepoint inserted on
34214@item type @tab 4 @tab type of tracepoint
34215@item enabled @tab 1 @tab enable or disable of tracepoint
34216@item step_count @tab 8 @tab step
34217@item pass_count @tab 8 @tab pass
34218@item numactions @tab 4 @tab number of tracepoint actions
34219@item hit count @tab 8 @tab hit count
34220@item trace frame usage @tab 8 @tab trace frame usage
34221@item compiled_cond @tab 8 @tab compiled condition
34222@item orig_size @tab 8 @tab orig size
34223@item condition @tab 4 if condition is NULL otherwise length of
34224@ref{agent expression object}
34225@tab zero if condition is NULL, otherwise is
34226@ref{agent expression object}
34227@item actions @tab variable
34228@tab numactions number of @ref{tracepoint action object}
34229@end multitable
34230
34231@node IPA Protocol Commands
34232@subsection IPA Protocol Commands
34233@cindex ipa protocol commands
34234
34235The spaces in each command are delimiters to ease reading this commands
34236specification. They don't exist in real commands.
34237
34238@table @samp
34239
34240@item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
34241Installs a new fast tracepoint described by @var{tracepoint_object}
697aa1b7 34242(@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
16bdd41f
YQ
34243head of @dfn{jumppad}, which is used to jump to data collection routine
34244in IPA finally.
34245
34246Replies:
34247@table @samp
34248@item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
34249@var{target_address} is address of tracepoint in the inferior.
697aa1b7 34250The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
16bdd41f 34251@var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
697aa1b7
EZ
34252The @var{fjump} contains a sequence of instructions jump to jumppad entry.
34253The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
16bdd41f
YQ
34254@item E @var{NN}
34255for an error
34256
34257@end table
34258
7255706c
YQ
34259@item close
34260Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
34261is about to kill inferiors.
34262
16bdd41f
YQ
34263@item qTfSTM
34264@xref{qTfSTM}.
34265@item qTsSTM
34266@xref{qTsSTM}.
34267@item qTSTMat
34268@xref{qTSTMat}.
34269@item probe_marker_at:@var{address}
34270Asks in-process agent to probe the marker at @var{address}.
34271
34272Replies:
34273@table @samp
34274@item E @var{NN}
34275for an error
34276@end table
34277@item unprobe_marker_at:@var{address}
34278Asks in-process agent to unprobe the marker at @var{address}.
34279@end table
34280
8e04817f
AC
34281@node GDB Bugs
34282@chapter Reporting Bugs in @value{GDBN}
34283@cindex bugs in @value{GDBN}
34284@cindex reporting bugs in @value{GDBN}
c906108c 34285
8e04817f 34286Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 34287
8e04817f
AC
34288Reporting a bug may help you by bringing a solution to your problem, or it
34289may not. But in any case the principal function of a bug report is to help
34290the entire community by making the next version of @value{GDBN} work better. Bug
34291reports are your contribution to the maintenance of @value{GDBN}.
c906108c 34292
8e04817f
AC
34293In order for a bug report to serve its purpose, you must include the
34294information that enables us to fix the bug.
c4555f82
SC
34295
34296@menu
8e04817f
AC
34297* Bug Criteria:: Have you found a bug?
34298* Bug Reporting:: How to report bugs
c4555f82
SC
34299@end menu
34300
8e04817f 34301@node Bug Criteria
79a6e687 34302@section Have You Found a Bug?
8e04817f 34303@cindex bug criteria
c4555f82 34304
8e04817f 34305If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
34306
34307@itemize @bullet
8e04817f
AC
34308@cindex fatal signal
34309@cindex debugger crash
34310@cindex crash of debugger
c4555f82 34311@item
8e04817f
AC
34312If the debugger gets a fatal signal, for any input whatever, that is a
34313@value{GDBN} bug. Reliable debuggers never crash.
34314
34315@cindex error on valid input
34316@item
34317If @value{GDBN} produces an error message for valid input, that is a
34318bug. (Note that if you're cross debugging, the problem may also be
34319somewhere in the connection to the target.)
c4555f82 34320
8e04817f 34321@cindex invalid input
c4555f82 34322@item
8e04817f
AC
34323If @value{GDBN} does not produce an error message for invalid input,
34324that is a bug. However, you should note that your idea of
34325``invalid input'' might be our idea of ``an extension'' or ``support
34326for traditional practice''.
34327
34328@item
34329If you are an experienced user of debugging tools, your suggestions
34330for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
34331@end itemize
34332
8e04817f 34333@node Bug Reporting
79a6e687 34334@section How to Report Bugs
8e04817f
AC
34335@cindex bug reports
34336@cindex @value{GDBN} bugs, reporting
34337
34338A number of companies and individuals offer support for @sc{gnu} products.
34339If you obtained @value{GDBN} from a support organization, we recommend you
34340contact that organization first.
34341
34342You can find contact information for many support companies and
34343individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
34344distribution.
34345@c should add a web page ref...
34346
c16158bc
JM
34347@ifset BUGURL
34348@ifset BUGURL_DEFAULT
129188f6 34349In any event, we also recommend that you submit bug reports for
d3e8051b 34350@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
34351@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
34352page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
34353be used.
8e04817f
AC
34354
34355@strong{Do not send bug reports to @samp{info-gdb}, or to
34356@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
34357not want to receive bug reports. Those that do have arranged to receive
34358@samp{bug-gdb}.
34359
34360The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
34361serves as a repeater. The mailing list and the newsgroup carry exactly
34362the same messages. Often people think of posting bug reports to the
34363newsgroup instead of mailing them. This appears to work, but it has one
34364problem which can be crucial: a newsgroup posting often lacks a mail
34365path back to the sender. Thus, if we need to ask for more information,
34366we may be unable to reach you. For this reason, it is better to send
34367bug reports to the mailing list.
c16158bc
JM
34368@end ifset
34369@ifclear BUGURL_DEFAULT
34370In any event, we also recommend that you submit bug reports for
34371@value{GDBN} to @value{BUGURL}.
34372@end ifclear
34373@end ifset
c4555f82 34374
8e04817f
AC
34375The fundamental principle of reporting bugs usefully is this:
34376@strong{report all the facts}. If you are not sure whether to state a
34377fact or leave it out, state it!
c4555f82 34378
8e04817f
AC
34379Often people omit facts because they think they know what causes the
34380problem and assume that some details do not matter. Thus, you might
34381assume that the name of the variable you use in an example does not matter.
34382Well, probably it does not, but one cannot be sure. Perhaps the bug is a
34383stray memory reference which happens to fetch from the location where that
34384name is stored in memory; perhaps, if the name were different, the contents
34385of that location would fool the debugger into doing the right thing despite
34386the bug. Play it safe and give a specific, complete example. That is the
34387easiest thing for you to do, and the most helpful.
c4555f82 34388
8e04817f
AC
34389Keep in mind that the purpose of a bug report is to enable us to fix the
34390bug. It may be that the bug has been reported previously, but neither
34391you nor we can know that unless your bug report is complete and
34392self-contained.
c4555f82 34393
8e04817f
AC
34394Sometimes people give a few sketchy facts and ask, ``Does this ring a
34395bell?'' Those bug reports are useless, and we urge everyone to
34396@emph{refuse to respond to them} except to chide the sender to report
34397bugs properly.
34398
34399To enable us to fix the bug, you should include all these things:
c4555f82
SC
34400
34401@itemize @bullet
34402@item
8e04817f
AC
34403The version of @value{GDBN}. @value{GDBN} announces it if you start
34404with no arguments; you can also print it at any time using @code{show
34405version}.
c4555f82 34406
8e04817f
AC
34407Without this, we will not know whether there is any point in looking for
34408the bug in the current version of @value{GDBN}.
c4555f82
SC
34409
34410@item
8e04817f
AC
34411The type of machine you are using, and the operating system name and
34412version number.
c4555f82 34413
6eaaf48b
EZ
34414@item
34415The details of the @value{GDBN} build-time configuration.
34416@value{GDBN} shows these details if you invoke it with the
34417@option{--configuration} command-line option, or if you type
34418@code{show configuration} at @value{GDBN}'s prompt.
34419
c4555f82 34420@item
c1468174 34421What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 34422``@value{GCC}--2.8.1''.
c4555f82
SC
34423
34424@item
8e04817f 34425What compiler (and its version) was used to compile the program you are
c1468174 34426debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
34427C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
34428to get this information; for other compilers, see the documentation for
34429those compilers.
c4555f82 34430
8e04817f
AC
34431@item
34432The command arguments you gave the compiler to compile your example and
34433observe the bug. For example, did you use @samp{-O}? To guarantee
34434you will not omit something important, list them all. A copy of the
34435Makefile (or the output from make) is sufficient.
c4555f82 34436
8e04817f
AC
34437If we were to try to guess the arguments, we would probably guess wrong
34438and then we might not encounter the bug.
c4555f82 34439
8e04817f
AC
34440@item
34441A complete input script, and all necessary source files, that will
34442reproduce the bug.
c4555f82 34443
8e04817f
AC
34444@item
34445A description of what behavior you observe that you believe is
34446incorrect. For example, ``It gets a fatal signal.''
c4555f82 34447
8e04817f
AC
34448Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
34449will certainly notice it. But if the bug is incorrect output, we might
34450not notice unless it is glaringly wrong. You might as well not give us
34451a chance to make a mistake.
c4555f82 34452
8e04817f
AC
34453Even if the problem you experience is a fatal signal, you should still
34454say so explicitly. Suppose something strange is going on, such as, your
34455copy of @value{GDBN} is out of synch, or you have encountered a bug in
34456the C library on your system. (This has happened!) Your copy might
34457crash and ours would not. If you told us to expect a crash, then when
34458ours fails to crash, we would know that the bug was not happening for
34459us. If you had not told us to expect a crash, then we would not be able
34460to draw any conclusion from our observations.
c4555f82 34461
e0c07bf0
MC
34462@pindex script
34463@cindex recording a session script
34464To collect all this information, you can use a session recording program
34465such as @command{script}, which is available on many Unix systems.
34466Just run your @value{GDBN} session inside @command{script} and then
34467include the @file{typescript} file with your bug report.
34468
34469Another way to record a @value{GDBN} session is to run @value{GDBN}
34470inside Emacs and then save the entire buffer to a file.
34471
8e04817f
AC
34472@item
34473If you wish to suggest changes to the @value{GDBN} source, send us context
34474diffs. If you even discuss something in the @value{GDBN} source, refer to
34475it by context, not by line number.
c4555f82 34476
8e04817f
AC
34477The line numbers in our development sources will not match those in your
34478sources. Your line numbers would convey no useful information to us.
c4555f82 34479
8e04817f 34480@end itemize
c4555f82 34481
8e04817f 34482Here are some things that are not necessary:
c4555f82 34483
8e04817f
AC
34484@itemize @bullet
34485@item
34486A description of the envelope of the bug.
c4555f82 34487
8e04817f
AC
34488Often people who encounter a bug spend a lot of time investigating
34489which changes to the input file will make the bug go away and which
34490changes will not affect it.
c4555f82 34491
8e04817f
AC
34492This is often time consuming and not very useful, because the way we
34493will find the bug is by running a single example under the debugger
34494with breakpoints, not by pure deduction from a series of examples.
34495We recommend that you save your time for something else.
c4555f82 34496
8e04817f
AC
34497Of course, if you can find a simpler example to report @emph{instead}
34498of the original one, that is a convenience for us. Errors in the
34499output will be easier to spot, running under the debugger will take
34500less time, and so on.
c4555f82 34501
8e04817f
AC
34502However, simplification is not vital; if you do not want to do this,
34503report the bug anyway and send us the entire test case you used.
c4555f82 34504
8e04817f
AC
34505@item
34506A patch for the bug.
c4555f82 34507
8e04817f
AC
34508A patch for the bug does help us if it is a good one. But do not omit
34509the necessary information, such as the test case, on the assumption that
34510a patch is all we need. We might see problems with your patch and decide
34511to fix the problem another way, or we might not understand it at all.
c4555f82 34512
8e04817f
AC
34513Sometimes with a program as complicated as @value{GDBN} it is very hard to
34514construct an example that will make the program follow a certain path
34515through the code. If you do not send us the example, we will not be able
34516to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 34517
8e04817f
AC
34518And if we cannot understand what bug you are trying to fix, or why your
34519patch should be an improvement, we will not install it. A test case will
34520help us to understand.
c4555f82 34521
8e04817f
AC
34522@item
34523A guess about what the bug is or what it depends on.
c4555f82 34524
8e04817f
AC
34525Such guesses are usually wrong. Even we cannot guess right about such
34526things without first using the debugger to find the facts.
34527@end itemize
c4555f82 34528
8e04817f
AC
34529@c The readline documentation is distributed with the readline code
34530@c and consists of the two following files:
cc88a640
JK
34531@c rluser.texi
34532@c hsuser.texi
8e04817f
AC
34533@c Use -I with makeinfo to point to the appropriate directory,
34534@c environment var TEXINPUTS with TeX.
39037522 34535@ifclear SYSTEM_READLINE
5bdf8622 34536@include rluser.texi
cc88a640 34537@include hsuser.texi
39037522 34538@end ifclear
c4555f82 34539
4ceed123
JB
34540@node In Memoriam
34541@appendix In Memoriam
34542
9ed350ad
JB
34543The @value{GDBN} project mourns the loss of the following long-time
34544contributors:
4ceed123
JB
34545
34546@table @code
34547@item Fred Fish
9ed350ad
JB
34548Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
34549to Free Software in general. Outside of @value{GDBN}, he was known in
34550the Amiga world for his series of Fish Disks, and the GeekGadget project.
4ceed123
JB
34551
34552@item Michael Snyder
9ed350ad
JB
34553Michael was one of the Global Maintainers of the @value{GDBN} project,
34554with contributions recorded as early as 1996, until 2011. In addition
34555to his day to day participation, he was a large driving force behind
34556adding Reverse Debugging to @value{GDBN}.
4ceed123
JB
34557@end table
34558
34559Beyond their technical contributions to the project, they were also
34560enjoyable members of the Free Software Community. We will miss them.
c4555f82 34561
8e04817f
AC
34562@node Formatting Documentation
34563@appendix Formatting Documentation
c4555f82 34564
8e04817f
AC
34565@cindex @value{GDBN} reference card
34566@cindex reference card
34567The @value{GDBN} 4 release includes an already-formatted reference card, ready
34568for printing with PostScript or Ghostscript, in the @file{gdb}
34569subdirectory of the main source directory@footnote{In
34570@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
34571release.}. If you can use PostScript or Ghostscript with your printer,
34572you can print the reference card immediately with @file{refcard.ps}.
c4555f82 34573
8e04817f
AC
34574The release also includes the source for the reference card. You
34575can format it, using @TeX{}, by typing:
c4555f82 34576
474c8240 34577@smallexample
8e04817f 34578make refcard.dvi
474c8240 34579@end smallexample
c4555f82 34580
8e04817f
AC
34581The @value{GDBN} reference card is designed to print in @dfn{landscape}
34582mode on US ``letter'' size paper;
34583that is, on a sheet 11 inches wide by 8.5 inches
34584high. You will need to specify this form of printing as an option to
34585your @sc{dvi} output program.
c4555f82 34586
8e04817f 34587@cindex documentation
c4555f82 34588
8e04817f
AC
34589All the documentation for @value{GDBN} comes as part of the machine-readable
34590distribution. The documentation is written in Texinfo format, which is
34591a documentation system that uses a single source file to produce both
34592on-line information and a printed manual. You can use one of the Info
34593formatting commands to create the on-line version of the documentation
34594and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 34595
8e04817f
AC
34596@value{GDBN} includes an already formatted copy of the on-line Info
34597version of this manual in the @file{gdb} subdirectory. The main Info
34598file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
34599subordinate files matching @samp{gdb.info*} in the same directory. If
34600necessary, you can print out these files, or read them with any editor;
34601but they are easier to read using the @code{info} subsystem in @sc{gnu}
34602Emacs or the standalone @code{info} program, available as part of the
34603@sc{gnu} Texinfo distribution.
c4555f82 34604
8e04817f
AC
34605If you want to format these Info files yourself, you need one of the
34606Info formatting programs, such as @code{texinfo-format-buffer} or
34607@code{makeinfo}.
c4555f82 34608
8e04817f
AC
34609If you have @code{makeinfo} installed, and are in the top level
34610@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
34611version @value{GDBVN}), you can make the Info file by typing:
c4555f82 34612
474c8240 34613@smallexample
8e04817f
AC
34614cd gdb
34615make gdb.info
474c8240 34616@end smallexample
c4555f82 34617
8e04817f
AC
34618If you want to typeset and print copies of this manual, you need @TeX{},
34619a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
34620Texinfo definitions file.
c4555f82 34621
8e04817f
AC
34622@TeX{} is a typesetting program; it does not print files directly, but
34623produces output files called @sc{dvi} files. To print a typeset
34624document, you need a program to print @sc{dvi} files. If your system
34625has @TeX{} installed, chances are it has such a program. The precise
34626command to use depends on your system; @kbd{lpr -d} is common; another
34627(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
34628require a file name without any extension or a @samp{.dvi} extension.
c4555f82 34629
8e04817f
AC
34630@TeX{} also requires a macro definitions file called
34631@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
34632written in Texinfo format. On its own, @TeX{} cannot either read or
34633typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
34634and is located in the @file{gdb-@var{version-number}/texinfo}
34635directory.
c4555f82 34636
8e04817f 34637If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 34638typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
34639subdirectory of the main source directory (for example, to
34640@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 34641
474c8240 34642@smallexample
8e04817f 34643make gdb.dvi
474c8240 34644@end smallexample
c4555f82 34645
8e04817f 34646Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 34647
8e04817f
AC
34648@node Installing GDB
34649@appendix Installing @value{GDBN}
8e04817f 34650@cindex installation
c4555f82 34651
7fa2210b
DJ
34652@menu
34653* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 34654* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
34655* Separate Objdir:: Compiling @value{GDBN} in another directory
34656* Config Names:: Specifying names for hosts and targets
34657* Configure Options:: Summary of options for configure
098b41a6 34658* System-wide configuration:: Having a system-wide init file
7fa2210b
DJ
34659@end menu
34660
34661@node Requirements
79a6e687 34662@section Requirements for Building @value{GDBN}
7fa2210b
DJ
34663@cindex building @value{GDBN}, requirements for
34664
34665Building @value{GDBN} requires various tools and packages to be available.
34666Other packages will be used only if they are found.
34667
79a6e687 34668@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b
DJ
34669@table @asis
34670@item ISO C90 compiler
34671@value{GDBN} is written in ISO C90. It should be buildable with any
34672working C90 compiler, e.g.@: GCC.
34673
34674@end table
34675
79a6e687 34676@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
34677@table @asis
34678@item Expat
123dc839 34679@anchor{Expat}
7fa2210b
DJ
34680@value{GDBN} can use the Expat XML parsing library. This library may be
34681included with your operating system distribution; if it is not, you
34682can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 34683The @file{configure} script will search for this library in several
7fa2210b
DJ
34684standard locations; if it is installed in an unusual path, you can
34685use the @option{--with-libexpat-prefix} option to specify its location.
34686
9cceb671
DJ
34687Expat is used for:
34688
34689@itemize @bullet
34690@item
34691Remote protocol memory maps (@pxref{Memory Map Format})
34692@item
34693Target descriptions (@pxref{Target Descriptions})
34694@item
2268b414
JK
34695Remote shared library lists (@xref{Library List Format},
34696or alternatively @pxref{Library List Format for SVR4 Targets})
9cceb671
DJ
34697@item
34698MS-Windows shared libraries (@pxref{Shared Libraries})
b3b9301e
PA
34699@item
34700Traceframe info (@pxref{Traceframe Info Format})
2ae8c8e7 34701@item
f4abbc16
MM
34702Branch trace (@pxref{Branch Trace Format},
34703@pxref{Branch Trace Configuration Format})
9cceb671 34704@end itemize
7fa2210b 34705
2400729e
UW
34706@item MPFR
34707@anchor{MPFR}
34708@value{GDBN} can use the GNU MPFR multiple-precision floating-point
34709library. This library may be included with your operating system
34710distribution; if it is not, you can get the latest version from
34711@url{http://www.mpfr.org}. The @file{configure} script will search
34712for this library in several standard locations; if it is installed
34713in an unusual path, you can use the @option{--with-libmpfr-prefix}
34714option to specify its location.
34715
34716GNU MPFR is used to emulate target floating-point arithmetic during
34717expression evaluation when the target uses different floating-point
34718formats than the host. If GNU MPFR it is not available, @value{GDBN}
34719will fall back to using host floating-point arithmetic.
34720
31fffb02
CS
34721@item zlib
34722@cindex compressed debug sections
34723@value{GDBN} will use the @samp{zlib} library, if available, to read
34724compressed debug sections. Some linkers, such as GNU gold, are capable
34725of producing binaries with compressed debug sections. If @value{GDBN}
34726is compiled with @samp{zlib}, it will be able to read the debug
34727information in such binaries.
34728
34729The @samp{zlib} library is likely included with your operating system
34730distribution; if it is not, you can get the latest version from
34731@url{http://zlib.net}.
34732
6c7a06a3
TT
34733@item iconv
34734@value{GDBN}'s features related to character sets (@pxref{Character
34735Sets}) require a functioning @code{iconv} implementation. If you are
34736on a GNU system, then this is provided by the GNU C Library. Some
34737other systems also provide a working @code{iconv}.
34738
478aac75
DE
34739If @value{GDBN} is using the @code{iconv} program which is installed
34740in a non-standard place, you will need to tell @value{GDBN} where to find it.
34741This is done with @option{--with-iconv-bin} which specifies the
34742directory that contains the @code{iconv} program.
34743
34744On systems without @code{iconv}, you can install GNU Libiconv. If you
6c7a06a3
TT
34745have previously installed Libiconv, you can use the
34746@option{--with-libiconv-prefix} option to configure.
34747
34748@value{GDBN}'s top-level @file{configure} and @file{Makefile} will
34749arrange to build Libiconv if a directory named @file{libiconv} appears
34750in the top-most source directory. If Libiconv is built this way, and
34751if the operating system does not provide a suitable @code{iconv}
34752implementation, then the just-built library will automatically be used
34753by @value{GDBN}. One easy way to set this up is to download GNU
34754Libiconv, unpack it, and then rename the directory holding the
34755Libiconv source code to @samp{libiconv}.
7fa2210b
DJ
34756@end table
34757
34758@node Running Configure
db2e3e2e 34759@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 34760@cindex configuring @value{GDBN}
db2e3e2e 34761@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
34762of preparing @value{GDBN} for installation; you can then use @code{make} to
34763build the @code{gdb} program.
34764@iftex
34765@c irrelevant in info file; it's as current as the code it lives with.
34766@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
34767look at the @file{README} file in the sources; we may have improved the
34768installation procedures since publishing this manual.}
34769@end iftex
c4555f82 34770
8e04817f
AC
34771The @value{GDBN} distribution includes all the source code you need for
34772@value{GDBN} in a single directory, whose name is usually composed by
34773appending the version number to @samp{gdb}.
c4555f82 34774
8e04817f
AC
34775For example, the @value{GDBN} version @value{GDBVN} distribution is in the
34776@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 34777
8e04817f
AC
34778@table @code
34779@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
34780script for configuring @value{GDBN} and all its supporting libraries
c4555f82 34781
8e04817f
AC
34782@item gdb-@value{GDBVN}/gdb
34783the source specific to @value{GDBN} itself
c4555f82 34784
8e04817f
AC
34785@item gdb-@value{GDBVN}/bfd
34786source for the Binary File Descriptor library
c906108c 34787
8e04817f
AC
34788@item gdb-@value{GDBVN}/include
34789@sc{gnu} include files
c906108c 34790
8e04817f
AC
34791@item gdb-@value{GDBVN}/libiberty
34792source for the @samp{-liberty} free software library
c906108c 34793
8e04817f
AC
34794@item gdb-@value{GDBVN}/opcodes
34795source for the library of opcode tables and disassemblers
c906108c 34796
8e04817f
AC
34797@item gdb-@value{GDBVN}/readline
34798source for the @sc{gnu} command-line interface
c906108c 34799
8e04817f
AC
34800@item gdb-@value{GDBVN}/glob
34801source for the @sc{gnu} filename pattern-matching subroutine
c906108c 34802
8e04817f
AC
34803@item gdb-@value{GDBVN}/mmalloc
34804source for the @sc{gnu} memory-mapped malloc package
34805@end table
c906108c 34806
db2e3e2e 34807The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
34808from the @file{gdb-@var{version-number}} source directory, which in
34809this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 34810
8e04817f 34811First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 34812if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
34813identifier for the platform on which @value{GDBN} will run as an
34814argument.
c906108c 34815
8e04817f 34816For example:
c906108c 34817
474c8240 34818@smallexample
8e04817f
AC
34819cd gdb-@value{GDBVN}
34820./configure @var{host}
34821make
474c8240 34822@end smallexample
c906108c 34823
8e04817f
AC
34824@noindent
34825where @var{host} is an identifier such as @samp{sun4} or
34826@samp{decstation}, that identifies the platform where @value{GDBN} will run.
db2e3e2e 34827(You can often leave off @var{host}; @file{configure} tries to guess the
8e04817f 34828correct value by examining your system.)
c906108c 34829
8e04817f
AC
34830Running @samp{configure @var{host}} and then running @code{make} builds the
34831@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
34832libraries, then @code{gdb} itself. The configured source files, and the
34833binaries, are left in the corresponding source directories.
c906108c 34834
8e04817f 34835@need 750
db2e3e2e 34836@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
34837system does not recognize this automatically when you run a different
34838shell, you may need to run @code{sh} on it explicitly:
c906108c 34839
474c8240 34840@smallexample
8e04817f 34841sh configure @var{host}
474c8240 34842@end smallexample
c906108c 34843
db2e3e2e 34844If you run @file{configure} from a directory that contains source
8e04817f 34845directories for multiple libraries or programs, such as the
db2e3e2e
BW
34846@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
34847@file{configure}
8e04817f
AC
34848creates configuration files for every directory level underneath (unless
34849you tell it not to, with the @samp{--norecursion} option).
34850
db2e3e2e 34851You should run the @file{configure} script from the top directory in the
94e91d6d 34852source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 34853@file{configure} from one of the subdirectories, you will configure only
94e91d6d 34854that subdirectory. That is usually not what you want. In particular,
db2e3e2e 34855if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
34856of the @file{gdb-@var{version-number}} directory, you will omit the
34857configuration of @file{bfd}, @file{readline}, and other sibling
34858directories of the @file{gdb} subdirectory. This leads to build errors
34859about missing include files such as @file{bfd/bfd.h}.
c906108c 34860
8e04817f
AC
34861You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
34862However, you should make sure that the shell on your path (named by
34863the @samp{SHELL} environment variable) is publicly readable. Remember
34864that @value{GDBN} uses the shell to start your program---some systems refuse to
34865let @value{GDBN} debug child processes whose programs are not readable.
c906108c 34866
8e04817f 34867@node Separate Objdir
79a6e687 34868@section Compiling @value{GDBN} in Another Directory
c906108c 34869
8e04817f
AC
34870If you want to run @value{GDBN} versions for several host or target machines,
34871you need a different @code{gdb} compiled for each combination of
db2e3e2e 34872host and target. @file{configure} is designed to make this easy by
8e04817f
AC
34873allowing you to generate each configuration in a separate subdirectory,
34874rather than in the source directory. If your @code{make} program
34875handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
34876@code{make} in each of these directories builds the @code{gdb}
34877program specified there.
c906108c 34878
db2e3e2e 34879To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 34880with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
34881(You also need to specify a path to find @file{configure}
34882itself from your working directory. If the path to @file{configure}
8e04817f
AC
34883would be the same as the argument to @samp{--srcdir}, you can leave out
34884the @samp{--srcdir} option; it is assumed.)
c906108c 34885
8e04817f
AC
34886For example, with version @value{GDBVN}, you can build @value{GDBN} in a
34887separate directory for a Sun 4 like this:
c906108c 34888
474c8240 34889@smallexample
8e04817f
AC
34890@group
34891cd gdb-@value{GDBVN}
34892mkdir ../gdb-sun4
34893cd ../gdb-sun4
34894../gdb-@value{GDBVN}/configure sun4
34895make
34896@end group
474c8240 34897@end smallexample
c906108c 34898
db2e3e2e 34899When @file{configure} builds a configuration using a remote source
8e04817f
AC
34900directory, it creates a tree for the binaries with the same structure
34901(and using the same names) as the tree under the source directory. In
34902the example, you'd find the Sun 4 library @file{libiberty.a} in the
34903directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
34904@file{gdb-sun4/gdb}.
c906108c 34905
94e91d6d
MC
34906Make sure that your path to the @file{configure} script has just one
34907instance of @file{gdb} in it. If your path to @file{configure} looks
34908like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
34909one subdirectory of @value{GDBN}, not the whole package. This leads to
34910build errors about missing include files such as @file{bfd/bfd.h}.
34911
8e04817f
AC
34912One popular reason to build several @value{GDBN} configurations in separate
34913directories is to configure @value{GDBN} for cross-compiling (where
34914@value{GDBN} runs on one machine---the @dfn{host}---while debugging
34915programs that run on another machine---the @dfn{target}).
34916You specify a cross-debugging target by
db2e3e2e 34917giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 34918
8e04817f
AC
34919When you run @code{make} to build a program or library, you must run
34920it in a configured directory---whatever directory you were in when you
db2e3e2e 34921called @file{configure} (or one of its subdirectories).
c906108c 34922
db2e3e2e 34923The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
34924directory also runs recursively. If you type @code{make} in a source
34925directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
34926directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
34927will build all the required libraries, and then build GDB.
c906108c 34928
8e04817f
AC
34929When you have multiple hosts or targets configured in separate
34930directories, you can run @code{make} on them in parallel (for example,
34931if they are NFS-mounted on each of the hosts); they will not interfere
34932with each other.
c906108c 34933
8e04817f 34934@node Config Names
79a6e687 34935@section Specifying Names for Hosts and Targets
c906108c 34936
db2e3e2e 34937The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
34938script are based on a three-part naming scheme, but some short predefined
34939aliases are also supported. The full naming scheme encodes three pieces
34940of information in the following pattern:
c906108c 34941
474c8240 34942@smallexample
8e04817f 34943@var{architecture}-@var{vendor}-@var{os}
474c8240 34944@end smallexample
c906108c 34945
8e04817f
AC
34946For example, you can use the alias @code{sun4} as a @var{host} argument,
34947or as the value for @var{target} in a @code{--target=@var{target}}
34948option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 34949
db2e3e2e 34950The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 34951any query facility to list all supported host and target names or
db2e3e2e 34952aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
34953@code{config.sub} to map abbreviations to full names; you can read the
34954script, if you wish, or you can use it to test your guesses on
34955abbreviations---for example:
c906108c 34956
8e04817f
AC
34957@smallexample
34958% sh config.sub i386-linux
34959i386-pc-linux-gnu
34960% sh config.sub alpha-linux
34961alpha-unknown-linux-gnu
34962% sh config.sub hp9k700
34963hppa1.1-hp-hpux
34964% sh config.sub sun4
34965sparc-sun-sunos4.1.1
34966% sh config.sub sun3
34967m68k-sun-sunos4.1.1
34968% sh config.sub i986v
34969Invalid configuration `i986v': machine `i986v' not recognized
34970@end smallexample
c906108c 34971
8e04817f
AC
34972@noindent
34973@code{config.sub} is also distributed in the @value{GDBN} source
34974directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 34975
8e04817f 34976@node Configure Options
db2e3e2e 34977@section @file{configure} Options
c906108c 34978
db2e3e2e
BW
34979Here is a summary of the @file{configure} options and arguments that
34980are most often useful for building @value{GDBN}. @file{configure} also has
8e04817f 34981several other options not listed here. @inforef{What Configure
db2e3e2e 34982Does,,configure.info}, for a full explanation of @file{configure}.
c906108c 34983
474c8240 34984@smallexample
8e04817f
AC
34985configure @r{[}--help@r{]}
34986 @r{[}--prefix=@var{dir}@r{]}
34987 @r{[}--exec-prefix=@var{dir}@r{]}
34988 @r{[}--srcdir=@var{dirname}@r{]}
34989 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
34990 @r{[}--target=@var{target}@r{]}
34991 @var{host}
474c8240 34992@end smallexample
c906108c 34993
8e04817f
AC
34994@noindent
34995You may introduce options with a single @samp{-} rather than
34996@samp{--} if you prefer; but you may abbreviate option names if you use
34997@samp{--}.
c906108c 34998
8e04817f
AC
34999@table @code
35000@item --help
db2e3e2e 35001Display a quick summary of how to invoke @file{configure}.
c906108c 35002
8e04817f
AC
35003@item --prefix=@var{dir}
35004Configure the source to install programs and files under directory
35005@file{@var{dir}}.
c906108c 35006
8e04817f
AC
35007@item --exec-prefix=@var{dir}
35008Configure the source to install programs under directory
35009@file{@var{dir}}.
c906108c 35010
8e04817f
AC
35011@c avoid splitting the warning from the explanation:
35012@need 2000
35013@item --srcdir=@var{dirname}
35014@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
35015@code{make} that implements the @code{VPATH} feature.}@*
35016Use this option to make configurations in directories separate from the
35017@value{GDBN} source directories. Among other things, you can use this to
35018build (or maintain) several configurations simultaneously, in separate
db2e3e2e 35019directories. @file{configure} writes configuration-specific files in
8e04817f 35020the current directory, but arranges for them to use the source in the
db2e3e2e 35021directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
35022the working directory in parallel to the source directories below
35023@var{dirname}.
c906108c 35024
8e04817f 35025@item --norecursion
db2e3e2e 35026Configure only the directory level where @file{configure} is executed; do not
8e04817f 35027propagate configuration to subdirectories.
c906108c 35028
8e04817f
AC
35029@item --target=@var{target}
35030Configure @value{GDBN} for cross-debugging programs running on the specified
35031@var{target}. Without this option, @value{GDBN} is configured to debug
35032programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 35033
8e04817f 35034There is no convenient way to generate a list of all available targets.
c906108c 35035
8e04817f
AC
35036@item @var{host} @dots{}
35037Configure @value{GDBN} to run on the specified @var{host}.
c906108c 35038
8e04817f
AC
35039There is no convenient way to generate a list of all available hosts.
35040@end table
c906108c 35041
8e04817f
AC
35042There are many other options available as well, but they are generally
35043needed for special purposes only.
c906108c 35044
098b41a6
JG
35045@node System-wide configuration
35046@section System-wide configuration and settings
35047@cindex system-wide init file
35048
35049@value{GDBN} can be configured to have a system-wide init file;
35050this file will be read and executed at startup (@pxref{Startup, , What
35051@value{GDBN} does during startup}).
35052
35053Here is the corresponding configure option:
35054
35055@table @code
35056@item --with-system-gdbinit=@var{file}
35057Specify that the default location of the system-wide init file is
35058@var{file}.
35059@end table
35060
35061If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
35062it may be subject to relocation. Two possible cases:
35063
35064@itemize @bullet
35065@item
35066If the default location of this init file contains @file{$prefix},
35067it will be subject to relocation. Suppose that the configure options
35068are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
35069if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
35070init file is looked for as @file{$install/etc/gdbinit} instead of
35071@file{$prefix/etc/gdbinit}.
35072
35073@item
35074By contrast, if the default location does not contain the prefix,
35075it will not be relocated. E.g.@: if @value{GDBN} has been configured with
35076@option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
35077then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
35078wherever @value{GDBN} is installed.
35079@end itemize
35080
e64e0392
DE
35081If the configured location of the system-wide init file (as given by the
35082@option{--with-system-gdbinit} option at configure time) is in the
35083data-directory (as specified by @option{--with-gdb-datadir} at configure
35084time) or in one of its subdirectories, then @value{GDBN} will look for the
35085system-wide init file in the directory specified by the
35086@option{--data-directory} command-line option.
35087Note that the system-wide init file is only read once, during @value{GDBN}
35088initialization. If the data-directory is changed after @value{GDBN} has
35089started with the @code{set data-directory} command, the file will not be
35090reread.
35091
5901af59
JB
35092@menu
35093* System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
35094@end menu
35095
35096@node System-wide Configuration Scripts
0201faac
JB
35097@subsection Installed System-wide Configuration Scripts
35098@cindex system-wide configuration scripts
35099
35100The @file{system-gdbinit} directory, located inside the data-directory
35101(as specified by @option{--with-gdb-datadir} at configure time) contains
35102a number of scripts which can be used as system-wide init files. To
35103automatically source those scripts at startup, @value{GDBN} should be
35104configured with @option{--with-system-gdbinit}. Otherwise, any user
35105should be able to source them by hand as needed.
35106
35107The following scripts are currently available:
35108@itemize @bullet
35109
35110@item @file{elinos.py}
35111@pindex elinos.py
35112@cindex ELinOS system-wide configuration script
35113This script is useful when debugging a program on an ELinOS target.
35114It takes advantage of the environment variables defined in a standard
35115ELinOS environment in order to determine the location of the system
35116shared libraries, and then sets the @samp{solib-absolute-prefix}
35117and @samp{solib-search-path} variables appropriately.
35118
35119@item @file{wrs-linux.py}
35120@pindex wrs-linux.py
35121@cindex Wind River Linux system-wide configuration script
35122This script is useful when debugging a program on a target running
35123Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
35124the host-side sysroot used by the target system.
35125
35126@end itemize
35127
8e04817f
AC
35128@node Maintenance Commands
35129@appendix Maintenance Commands
35130@cindex maintenance commands
35131@cindex internal commands
c906108c 35132
8e04817f 35133In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
35134includes a number of commands intended for @value{GDBN} developers,
35135that are not documented elsewhere in this manual. These commands are
da316a69
EZ
35136provided here for reference. (For commands that turn on debugging
35137messages, see @ref{Debugging Output}.)
c906108c 35138
8e04817f 35139@table @code
09d4efe1 35140@kindex maint agent
782b2b07 35141@kindex maint agent-eval
f77cc5f0
HZ
35142@item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
35143@itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
09d4efe1
EZ
35144Translate the given @var{expression} into remote agent bytecodes.
35145This command is useful for debugging the Agent Expression mechanism
782b2b07
SS
35146(@pxref{Agent Expressions}). The @samp{agent} version produces an
35147expression useful for data collection, such as by tracepoints, while
35148@samp{maint agent-eval} produces an expression that evaluates directly
35149to a result. For instance, a collection expression for @code{globa +
35150globb} will include bytecodes to record four bytes of memory at each
35151of the addresses of @code{globa} and @code{globb}, while discarding
35152the result of the addition, while an evaluation expression will do the
35153addition and return the sum.
f77cc5f0
HZ
35154If @code{-at} is given, generate remote agent bytecode for @var{location}.
35155If not, generate remote agent bytecode for current frame PC address.
09d4efe1 35156
d3ce09f5
SS
35157@kindex maint agent-printf
35158@item maint agent-printf @var{format},@var{expr},...
35159Translate the given format string and list of argument expressions
35160into remote agent bytecodes and display them as a disassembled list.
35161This command is useful for debugging the agent version of dynamic
6dd24dfa 35162printf (@pxref{Dynamic Printf}).
d3ce09f5 35163
8e04817f
AC
35164@kindex maint info breakpoints
35165@item @anchor{maint info breakpoints}maint info breakpoints
35166Using the same format as @samp{info breakpoints}, display both the
35167breakpoints you've set explicitly, and those @value{GDBN} is using for
35168internal purposes. Internal breakpoints are shown with negative
35169breakpoint numbers. The type column identifies what kind of breakpoint
35170is shown:
c906108c 35171
8e04817f
AC
35172@table @code
35173@item breakpoint
35174Normal, explicitly set breakpoint.
c906108c 35175
8e04817f
AC
35176@item watchpoint
35177Normal, explicitly set watchpoint.
c906108c 35178
8e04817f
AC
35179@item longjmp
35180Internal breakpoint, used to handle correctly stepping through
35181@code{longjmp} calls.
c906108c 35182
8e04817f
AC
35183@item longjmp resume
35184Internal breakpoint at the target of a @code{longjmp}.
c906108c 35185
8e04817f
AC
35186@item until
35187Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 35188
8e04817f
AC
35189@item finish
35190Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 35191
8e04817f
AC
35192@item shlib events
35193Shared library events.
c906108c 35194
8e04817f 35195@end table
c906108c 35196
b0627500
MM
35197@kindex maint info btrace
35198@item maint info btrace
35199Pint information about raw branch tracing data.
35200
35201@kindex maint btrace packet-history
35202@item maint btrace packet-history
35203Print the raw branch trace packets that are used to compute the
35204execution history for the @samp{record btrace} command. Both the
35205information and the format in which it is printed depend on the btrace
35206recording format.
35207
35208@table @code
35209@item bts
35210For the BTS recording format, print a list of blocks of sequential
35211code. For each block, the following information is printed:
35212
35213@table @asis
35214@item Block number
35215Newer blocks have higher numbers. The oldest block has number zero.
35216@item Lowest @samp{PC}
35217@item Highest @samp{PC}
35218@end table
35219
35220@item pt
bc504a31
PA
35221For the Intel Processor Trace recording format, print a list of
35222Intel Processor Trace packets. For each packet, the following
b0627500
MM
35223information is printed:
35224
35225@table @asis
35226@item Packet number
35227Newer packets have higher numbers. The oldest packet has number zero.
35228@item Trace offset
35229The packet's offset in the trace stream.
35230@item Packet opcode and payload
35231@end table
35232@end table
35233
35234@kindex maint btrace clear-packet-history
35235@item maint btrace clear-packet-history
35236Discards the cached packet history printed by the @samp{maint btrace
35237packet-history} command. The history will be computed again when
35238needed.
35239
35240@kindex maint btrace clear
35241@item maint btrace clear
35242Discard the branch trace data. The data will be fetched anew and the
35243branch trace will be recomputed when needed.
35244
35245This implicitly truncates the branch trace to a single branch trace
35246buffer. When updating branch trace incrementally, the branch trace
35247available to @value{GDBN} may be bigger than a single branch trace
35248buffer.
35249
35250@kindex maint set btrace pt skip-pad
35251@item maint set btrace pt skip-pad
35252@kindex maint show btrace pt skip-pad
35253@item maint show btrace pt skip-pad
35254Control whether @value{GDBN} will skip PAD packets when computing the
35255packet history.
35256
fff08868
HZ
35257@kindex set displaced-stepping
35258@kindex show displaced-stepping
237fc4c9
PA
35259@cindex displaced stepping support
35260@cindex out-of-line single-stepping
fff08868
HZ
35261@item set displaced-stepping
35262@itemx show displaced-stepping
237fc4c9 35263Control whether or not @value{GDBN} will do @dfn{displaced stepping}
fff08868
HZ
35264if the target supports it. Displaced stepping is a way to single-step
35265over breakpoints without removing them from the inferior, by executing
35266an out-of-line copy of the instruction that was originally at the
35267breakpoint location. It is also known as out-of-line single-stepping.
35268
35269@table @code
35270@item set displaced-stepping on
35271If the target architecture supports it, @value{GDBN} will use
35272displaced stepping to step over breakpoints.
35273
35274@item set displaced-stepping off
35275@value{GDBN} will not use displaced stepping to step over breakpoints,
35276even if such is supported by the target architecture.
35277
35278@cindex non-stop mode, and @samp{set displaced-stepping}
35279@item set displaced-stepping auto
35280This is the default mode. @value{GDBN} will use displaced stepping
35281only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
35282architecture supports displaced stepping.
35283@end table
237fc4c9 35284
7d0c9981
DE
35285@kindex maint check-psymtabs
35286@item maint check-psymtabs
35287Check the consistency of currently expanded psymtabs versus symtabs.
35288Use this to check, for example, whether a symbol is in one but not the other.
35289
09d4efe1
EZ
35290@kindex maint check-symtabs
35291@item maint check-symtabs
7d0c9981
DE
35292Check the consistency of currently expanded symtabs.
35293
35294@kindex maint expand-symtabs
35295@item maint expand-symtabs [@var{regexp}]
35296Expand symbol tables.
35297If @var{regexp} is specified, only expand symbol tables for file
35298names matching @var{regexp}.
09d4efe1 35299
992c7d70
GB
35300@kindex maint set catch-demangler-crashes
35301@kindex maint show catch-demangler-crashes
35302@cindex demangler crashes
35303@item maint set catch-demangler-crashes [on|off]
35304@itemx maint show catch-demangler-crashes
35305Control whether @value{GDBN} should attempt to catch crashes in the
35306symbol name demangler. The default is to attempt to catch crashes.
35307If enabled, the first time a crash is caught, a core file is created,
35308the offending symbol is displayed and the user is presented with the
35309option to terminate the current session.
35310
09d4efe1
EZ
35311@kindex maint cplus first_component
35312@item maint cplus first_component @var{name}
35313Print the first C@t{++} class/namespace component of @var{name}.
35314
35315@kindex maint cplus namespace
35316@item maint cplus namespace
35317Print the list of possible C@t{++} namespaces.
35318
09d4efe1
EZ
35319@kindex maint deprecate
35320@kindex maint undeprecate
35321@cindex deprecated commands
35322@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
35323@itemx maint undeprecate @var{command}
35324Deprecate or undeprecate the named @var{command}. Deprecated commands
35325cause @value{GDBN} to issue a warning when you use them. The optional
35326argument @var{replacement} says which newer command should be used in
35327favor of the deprecated one; if it is given, @value{GDBN} will mention
35328the replacement as part of the warning.
35329
35330@kindex maint dump-me
35331@item maint dump-me
721c2651 35332@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 35333Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
35334This is supported only on systems which support aborting a program
35335with the @code{SIGQUIT} signal.
09d4efe1 35336
8d30a00d
AC
35337@kindex maint internal-error
35338@kindex maint internal-warning
57fcfb1b
GB
35339@kindex maint demangler-warning
35340@cindex demangler crashes
09d4efe1
EZ
35341@item maint internal-error @r{[}@var{message-text}@r{]}
35342@itemx maint internal-warning @r{[}@var{message-text}@r{]}
57fcfb1b
GB
35343@itemx maint demangler-warning @r{[}@var{message-text}@r{]}
35344
35345Cause @value{GDBN} to call the internal function @code{internal_error},
35346@code{internal_warning} or @code{demangler_warning} and hence behave
7ee67ee4 35347as though an internal problem has been detected. In addition to
57fcfb1b
GB
35348reporting the internal problem, these functions give the user the
35349opportunity to either quit @value{GDBN} or (for @code{internal_error}
35350and @code{internal_warning}) create a core file of the current
8d30a00d
AC
35351@value{GDBN} session.
35352
09d4efe1
EZ
35353These commands take an optional parameter @var{message-text} that is
35354used as the text of the error or warning message.
35355
d3e8051b 35356Here's an example of using @code{internal-error}:
09d4efe1 35357
8d30a00d 35358@smallexample
f7dc1244 35359(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
35360@dots{}/maint.c:121: internal-error: testing, 1, 2
35361A problem internal to GDB has been detected. Further
35362debugging may prove unreliable.
35363Quit this debugging session? (y or n) @kbd{n}
35364Create a core file? (y or n) @kbd{n}
f7dc1244 35365(@value{GDBP})
8d30a00d
AC
35366@end smallexample
35367
3c16cced
PA
35368@cindex @value{GDBN} internal error
35369@cindex internal errors, control of @value{GDBN} behavior
57fcfb1b 35370@cindex demangler crashes
3c16cced
PA
35371
35372@kindex maint set internal-error
35373@kindex maint show internal-error
35374@kindex maint set internal-warning
35375@kindex maint show internal-warning
57fcfb1b
GB
35376@kindex maint set demangler-warning
35377@kindex maint show demangler-warning
3c16cced
PA
35378@item maint set internal-error @var{action} [ask|yes|no]
35379@itemx maint show internal-error @var{action}
35380@itemx maint set internal-warning @var{action} [ask|yes|no]
35381@itemx maint show internal-warning @var{action}
57fcfb1b
GB
35382@itemx maint set demangler-warning @var{action} [ask|yes|no]
35383@itemx maint show demangler-warning @var{action}
3c16cced
PA
35384When @value{GDBN} reports an internal problem (error or warning) it
35385gives the user the opportunity to both quit @value{GDBN} and create a
35386core file of the current @value{GDBN} session. These commands let you
35387override the default behaviour for each particular @var{action},
35388described in the table below.
35389
35390@table @samp
35391@item quit
35392You can specify that @value{GDBN} should always (yes) or never (no)
35393quit. The default is to ask the user what to do.
35394
35395@item corefile
35396You can specify that @value{GDBN} should always (yes) or never (no)
57fcfb1b
GB
35397create a core file. The default is to ask the user what to do. Note
35398that there is no @code{corefile} option for @code{demangler-warning}:
35399demangler warnings always create a core file and this cannot be
35400disabled.
3c16cced
PA
35401@end table
35402
09d4efe1
EZ
35403@kindex maint packet
35404@item maint packet @var{text}
35405If @value{GDBN} is talking to an inferior via the serial protocol,
35406then this command sends the string @var{text} to the inferior, and
35407displays the response packet. @value{GDBN} supplies the initial
35408@samp{$} character, the terminating @samp{#} character, and the
35409checksum.
35410
35411@kindex maint print architecture
35412@item maint print architecture @r{[}@var{file}@r{]}
35413Print the entire architecture configuration. The optional argument
35414@var{file} names the file where the output goes.
8d30a00d 35415
8e2141c6 35416@kindex maint print c-tdesc @r{[}@var{file}@r{]}
81adfced 35417@item maint print c-tdesc
8e2141c6
YQ
35418Print the target description (@pxref{Target Descriptions}) as
35419a C source file. By default, the target description is for the current
35420target, but if the optional argument @var{file} is provided, that file
35421is used to produce the description. The @var{file} should be an XML
35422document, of the form described in @ref{Target Description Format}.
35423The created source file is built into @value{GDBN} when @value{GDBN} is
35424built again. This command is used by developers after they add or
35425modify XML target descriptions.
81adfced 35426
27d41eac
YQ
35427@kindex maint check xml-descriptions
35428@item maint check xml-descriptions @var{dir}
35429Check that the target descriptions dynamically created by @value{GDBN}
35430equal the descriptions created from XML files found in @var{dir}.
35431
00905d52
AC
35432@kindex maint print dummy-frames
35433@item maint print dummy-frames
00905d52
AC
35434Prints the contents of @value{GDBN}'s internal dummy-frame stack.
35435
35436@smallexample
f7dc1244 35437(@value{GDBP}) @kbd{b add}
00905d52 35438@dots{}
f7dc1244 35439(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
35440Breakpoint 2, add (a=2, b=3) at @dots{}
3544158 return (a + b);
35442The program being debugged stopped while in a function called from GDB.
35443@dots{}
f7dc1244 35444(@value{GDBP}) @kbd{maint print dummy-frames}
b67a2c6f 354450xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
f7dc1244 35446(@value{GDBP})
00905d52
AC
35447@end smallexample
35448
35449Takes an optional file parameter.
35450
0680b120
AC
35451@kindex maint print registers
35452@kindex maint print raw-registers
35453@kindex maint print cooked-registers
617073a9 35454@kindex maint print register-groups
c21236dc 35455@kindex maint print remote-registers
09d4efe1
EZ
35456@item maint print registers @r{[}@var{file}@r{]}
35457@itemx maint print raw-registers @r{[}@var{file}@r{]}
35458@itemx maint print cooked-registers @r{[}@var{file}@r{]}
35459@itemx maint print register-groups @r{[}@var{file}@r{]}
c21236dc 35460@itemx maint print remote-registers @r{[}@var{file}@r{]}
0680b120
AC
35461Print @value{GDBN}'s internal register data structures.
35462
617073a9 35463The command @code{maint print raw-registers} includes the contents of
c21236dc
PA
35464the raw register cache; the command @code{maint print
35465cooked-registers} includes the (cooked) value of all registers,
35466including registers which aren't available on the target nor visible
35467to user; the command @code{maint print register-groups} includes the
35468groups that each register is a member of; and the command @code{maint
35469print remote-registers} includes the remote target's register numbers
0a7cfe2c 35470and offsets in the `G' packets.
0680b120 35471
09d4efe1
EZ
35472These commands take an optional parameter, a file name to which to
35473write the information.
0680b120 35474
617073a9 35475@kindex maint print reggroups
09d4efe1
EZ
35476@item maint print reggroups @r{[}@var{file}@r{]}
35477Print @value{GDBN}'s internal register group data structures. The
35478optional argument @var{file} tells to what file to write the
35479information.
617073a9 35480
09d4efe1 35481The register groups info looks like this:
617073a9
AC
35482
35483@smallexample
f7dc1244 35484(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
35485 Group Type
35486 general user
35487 float user
35488 all user
35489 vector user
35490 system user
35491 save internal
35492 restore internal
617073a9
AC
35493@end smallexample
35494
09d4efe1
EZ
35495@kindex flushregs
35496@item flushregs
35497This command forces @value{GDBN} to flush its internal register cache.
35498
35499@kindex maint print objfiles
35500@cindex info for known object files
52e260a3
DE
35501@item maint print objfiles @r{[}@var{regexp}@r{]}
35502Print a dump of all known object files.
35503If @var{regexp} is specified, only print object files whose names
35504match @var{regexp}. For each object file, this command prints its name,
35505address in memory, and all of its psymtabs and symtabs.
09d4efe1 35506
f5b95c01
AA
35507@kindex maint print user-registers
35508@cindex user registers
35509@item maint print user-registers
35510List all currently available @dfn{user registers}. User registers
35511typically provide alternate names for actual hardware registers. They
35512include the four ``standard'' registers @code{$fp}, @code{$pc},
35513@code{$sp}, and @code{$ps}. @xref{standard registers}. User
35514registers can be used in expressions in the same way as the canonical
35515register names, but only the latter are listed by the @code{info
35516registers} and @code{maint print registers} commands.
35517
8a1ea21f
DE
35518@kindex maint print section-scripts
35519@cindex info for known .debug_gdb_scripts-loaded scripts
35520@item maint print section-scripts [@var{regexp}]
35521Print a dump of scripts specified in the @code{.debug_gdb_section} section.
35522If @var{regexp} is specified, only print scripts loaded by object files
35523matching @var{regexp}.
35524For each script, this command prints its name as specified in the objfile,
35525and the full path if known.
8e0583c8 35526@xref{dotdebug_gdb_scripts section}.
8a1ea21f 35527
09d4efe1
EZ
35528@kindex maint print statistics
35529@cindex bcache statistics
35530@item maint print statistics
35531This command prints, for each object file in the program, various data
35532about that object file followed by the byte cache (@dfn{bcache})
35533statistics for the object file. The objfile data includes the number
d3e8051b 35534of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
35535defined by the objfile, the number of as yet unexpanded psym tables,
35536the number of line tables and string tables, and the amount of memory
35537used by the various tables. The bcache statistics include the counts,
35538sizes, and counts of duplicates of all and unique objects, max,
35539average, and median entry size, total memory used and its overhead and
35540savings, and various measures of the hash table size and chain
35541lengths.
35542
c7ba131e
JB
35543@kindex maint print target-stack
35544@cindex target stack description
35545@item maint print target-stack
35546A @dfn{target} is an interface between the debugger and a particular
35547kind of file or process. Targets can be stacked in @dfn{strata},
35548so that more than one target can potentially respond to a request.
35549In particular, memory accesses will walk down the stack of targets
35550until they find a target that is interested in handling that particular
35551address.
35552
35553This command prints a short description of each layer that was pushed on
35554the @dfn{target stack}, starting from the top layer down to the bottom one.
35555
09d4efe1
EZ
35556@kindex maint print type
35557@cindex type chain of a data type
35558@item maint print type @var{expr}
35559Print the type chain for a type specified by @var{expr}. The argument
35560can be either a type name or a symbol. If it is a symbol, the type of
35561that symbol is described. The type chain produced by this command is
35562a recursive definition of the data type as stored in @value{GDBN}'s
35563data structures, including its flags and contained types.
35564
dcd1f979
TT
35565@kindex maint selftest
35566@cindex self tests
1526853e 35567@item maint selftest @r{[}@var{filter}@r{]}
dcd1f979
TT
35568Run any self tests that were compiled in to @value{GDBN}. This will
35569print a message showing how many tests were run, and how many failed.
1526853e
SM
35570If a @var{filter} is passed, only the tests with @var{filter} in their
35571name will by ran.
35572
35573@kindex "maint info selftests"
35574@cindex self tests
35575@item maint info selftests
35576List the selftests compiled in to @value{GDBN}.
dcd1f979 35577
b4f54984
DE
35578@kindex maint set dwarf always-disassemble
35579@kindex maint show dwarf always-disassemble
35580@item maint set dwarf always-disassemble
35581@item maint show dwarf always-disassemble
9eae7c52
TT
35582Control the behavior of @code{info address} when using DWARF debugging
35583information.
35584
35585The default is @code{off}, which means that @value{GDBN} should try to
35586describe a variable's location in an easily readable format. When
35587@code{on}, @value{GDBN} will instead display the DWARF location
35588expression in an assembly-like format. Note that some locations are
35589too complex for @value{GDBN} to describe simply; in this case you will
35590always see the disassembly form.
35591
35592Here is an example of the resulting disassembly:
35593
35594@smallexample
35595(gdb) info addr argc
35596Symbol "argc" is a complex DWARF expression:
35597 1: DW_OP_fbreg 0
35598@end smallexample
35599
35600For more information on these expressions, see
35601@uref{http://www.dwarfstd.org/, the DWARF standard}.
35602
b4f54984
DE
35603@kindex maint set dwarf max-cache-age
35604@kindex maint show dwarf max-cache-age
35605@item maint set dwarf max-cache-age
35606@itemx maint show dwarf max-cache-age
35607Control the DWARF compilation unit cache.
09d4efe1 35608
b4f54984 35609@cindex DWARF compilation units cache
09d4efe1 35610In object files with inter-compilation-unit references, such as those
b4f54984 35611produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
09d4efe1
EZ
35612reader needs to frequently refer to previously read compilation units.
35613This setting controls how long a compilation unit will remain in the
35614cache if it is not referenced. A higher limit means that cached
35615compilation units will be stored in memory longer, and more total
35616memory will be used. Setting it to zero disables caching, which will
35617slow down @value{GDBN} startup, but reduce memory consumption.
35618
e7ba9c65
DJ
35619@kindex maint set profile
35620@kindex maint show profile
35621@cindex profiling GDB
35622@item maint set profile
35623@itemx maint show profile
35624Control profiling of @value{GDBN}.
35625
35626Profiling will be disabled until you use the @samp{maint set profile}
35627command to enable it. When you enable profiling, the system will begin
35628collecting timing and execution count data; when you disable profiling or
35629exit @value{GDBN}, the results will be written to a log file. Remember that
35630if you use profiling, @value{GDBN} will overwrite the profiling log file
35631(often called @file{gmon.out}). If you have a record of important profiling
35632data in a @file{gmon.out} file, be sure to move it to a safe location.
35633
35634Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 35635compiled with the @samp{-pg} compiler option.
e7ba9c65 35636
cbe54154
PA
35637@kindex maint set show-debug-regs
35638@kindex maint show show-debug-regs
eac35c4e 35639@cindex hardware debug registers
cbe54154
PA
35640@item maint set show-debug-regs
35641@itemx maint show show-debug-regs
eac35c4e 35642Control whether to show variables that mirror the hardware debug
6dd315ba 35643registers. Use @code{on} to enable, @code{off} to disable. If
3f94c067 35644enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
35645removes a hardware breakpoint or watchpoint, and when the inferior
35646triggers a hardware-assisted breakpoint or watchpoint.
35647
711e434b
PM
35648@kindex maint set show-all-tib
35649@kindex maint show show-all-tib
35650@item maint set show-all-tib
35651@itemx maint show show-all-tib
35652Control whether to show all non zero areas within a 1k block starting
35653at thread local base, when using the @samp{info w32 thread-information-block}
35654command.
35655
329ea579
PA
35656@kindex maint set target-async
35657@kindex maint show target-async
35658@item maint set target-async
35659@itemx maint show target-async
35660This controls whether @value{GDBN} targets operate in synchronous or
35661asynchronous mode (@pxref{Background Execution}). Normally the
35662default is asynchronous, if it is available; but this can be changed
35663to more easily debug problems occurring only in synchronous mode.
35664
fbea99ea
PA
35665@kindex maint set target-non-stop @var{mode} [on|off|auto]
35666@kindex maint show target-non-stop
35667@item maint set target-non-stop
35668@itemx maint show target-non-stop
35669
35670This controls whether @value{GDBN} targets always operate in non-stop
35671mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
35672Mode}). The default is @code{auto}, meaning non-stop mode is enabled
35673if supported by the target.
35674
35675@table @code
35676@item maint set target-non-stop auto
35677This is the default mode. @value{GDBN} controls the target in
35678non-stop mode if the target supports it.
35679
35680@item maint set target-non-stop on
35681@value{GDBN} controls the target in non-stop mode even if the target
35682does not indicate support.
35683
35684@item maint set target-non-stop off
35685@value{GDBN} does not control the target in non-stop mode even if the
35686target supports it.
35687@end table
35688
bd712aed
DE
35689@kindex maint set per-command
35690@kindex maint show per-command
35691@item maint set per-command
35692@itemx maint show per-command
35693@cindex resources used by commands
09d4efe1 35694
bd712aed
DE
35695@value{GDBN} can display the resources used by each command.
35696This is useful in debugging performance problems.
35697
35698@table @code
35699@item maint set per-command space [on|off]
35700@itemx maint show per-command space
35701Enable or disable the printing of the memory used by GDB for each command.
35702If enabled, @value{GDBN} will display how much memory each command
35703took, following the command's own output.
35704This can also be requested by invoking @value{GDBN} with the
35705@option{--statistics} command-line switch (@pxref{Mode Options}).
35706
35707@item maint set per-command time [on|off]
35708@itemx maint show per-command time
35709Enable or disable the printing of the execution time of @value{GDBN}
35710for each command.
35711If enabled, @value{GDBN} will display how much time it
09d4efe1 35712took to execute each command, following the command's own output.
0a1c4d10
DE
35713Both CPU time and wallclock time are printed.
35714Printing both is useful when trying to determine whether the cost is
bd712aed 35715CPU or, e.g., disk/network latency.
0a1c4d10
DE
35716Note that the CPU time printed is for @value{GDBN} only, it does not include
35717the execution time of the inferior because there's no mechanism currently
35718to compute how much time was spent by @value{GDBN} and how much time was
35719spent by the program been debugged.
09d4efe1
EZ
35720This can also be requested by invoking @value{GDBN} with the
35721@option{--statistics} command-line switch (@pxref{Mode Options}).
35722
bd712aed
DE
35723@item maint set per-command symtab [on|off]
35724@itemx maint show per-command symtab
35725Enable or disable the printing of basic symbol table statistics
35726for each command.
35727If enabled, @value{GDBN} will display the following information:
35728
215b9f98
EZ
35729@enumerate a
35730@item
35731number of symbol tables
35732@item
35733number of primary symbol tables
35734@item
35735number of blocks in the blockvector
35736@end enumerate
bd712aed
DE
35737@end table
35738
35739@kindex maint space
35740@cindex memory used by commands
35741@item maint space @var{value}
35742An alias for @code{maint set per-command space}.
35743A non-zero value enables it, zero disables it.
35744
35745@kindex maint time
35746@cindex time of command execution
35747@item maint time @var{value}
35748An alias for @code{maint set per-command time}.
35749A non-zero value enables it, zero disables it.
35750
09d4efe1
EZ
35751@kindex maint translate-address
35752@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
35753Find the symbol stored at the location specified by the address
35754@var{addr} and an optional section name @var{section}. If found,
35755@value{GDBN} prints the name of the closest symbol and an offset from
35756the symbol's location to the specified address. This is similar to
35757the @code{info address} command (@pxref{Symbols}), except that this
35758command also allows to find symbols in other sections.
ae038cb0 35759
c14c28ba
PP
35760If section was not specified, the section in which the symbol was found
35761is also printed. For dynamically linked executables, the name of
35762executable or shared library containing the symbol is printed as well.
35763
8e04817f 35764@end table
c906108c 35765
9c16f35a
EZ
35766The following command is useful for non-interactive invocations of
35767@value{GDBN}, such as in the test suite.
35768
35769@table @code
35770@item set watchdog @var{nsec}
35771@kindex set watchdog
35772@cindex watchdog timer
35773@cindex timeout for commands
35774Set the maximum number of seconds @value{GDBN} will wait for the
35775target operation to finish. If this time expires, @value{GDBN}
35776reports and error and the command is aborted.
35777
35778@item show watchdog
35779Show the current setting of the target wait timeout.
35780@end table
c906108c 35781
e0ce93ac 35782@node Remote Protocol
8e04817f 35783@appendix @value{GDBN} Remote Serial Protocol
c906108c 35784
ee2d5c50
AC
35785@menu
35786* Overview::
35787* Packets::
35788* Stop Reply Packets::
35789* General Query Packets::
a1dcb23a 35790* Architecture-Specific Protocol Details::
9d29849a 35791* Tracepoint Packets::
a6b151f1 35792* Host I/O Packets::
9a6253be 35793* Interrupts::
8b23ecc4
SL
35794* Notification Packets::
35795* Remote Non-Stop::
a6f3e723 35796* Packet Acknowledgment::
ee2d5c50 35797* Examples::
79a6e687 35798* File-I/O Remote Protocol Extension::
cfa9d6d9 35799* Library List Format::
2268b414 35800* Library List Format for SVR4 Targets::
79a6e687 35801* Memory Map Format::
dc146f7c 35802* Thread List Format::
b3b9301e 35803* Traceframe Info Format::
2ae8c8e7 35804* Branch Trace Format::
f4abbc16 35805* Branch Trace Configuration Format::
ee2d5c50
AC
35806@end menu
35807
35808@node Overview
35809@section Overview
35810
8e04817f
AC
35811There may be occasions when you need to know something about the
35812protocol---for example, if there is only one serial port to your target
35813machine, you might want your program to do something special if it
35814recognizes a packet meant for @value{GDBN}.
c906108c 35815
d2c6833e 35816In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 35817transmitted and received data, respectively.
c906108c 35818
8e04817f
AC
35819@cindex protocol, @value{GDBN} remote serial
35820@cindex serial protocol, @value{GDBN} remote
35821@cindex remote serial protocol
8b23ecc4
SL
35822All @value{GDBN} commands and responses (other than acknowledgments
35823and notifications, see @ref{Notification Packets}) are sent as a
35824@var{packet}. A @var{packet} is introduced with the character
8e04817f
AC
35825@samp{$}, the actual @var{packet-data}, and the terminating character
35826@samp{#} followed by a two-digit @var{checksum}:
c906108c 35827
474c8240 35828@smallexample
8e04817f 35829@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 35830@end smallexample
8e04817f 35831@noindent
c906108c 35832
8e04817f
AC
35833@cindex checksum, for @value{GDBN} remote
35834@noindent
35835The two-digit @var{checksum} is computed as the modulo 256 sum of all
35836characters between the leading @samp{$} and the trailing @samp{#} (an
35837eight bit unsigned checksum).
c906108c 35838
8e04817f
AC
35839Implementors should note that prior to @value{GDBN} 5.0 the protocol
35840specification also included an optional two-digit @var{sequence-id}:
c906108c 35841
474c8240 35842@smallexample
8e04817f 35843@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 35844@end smallexample
c906108c 35845
8e04817f
AC
35846@cindex sequence-id, for @value{GDBN} remote
35847@noindent
35848That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
35849has never output @var{sequence-id}s. Stubs that handle packets added
35850since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 35851
8e04817f
AC
35852When either the host or the target machine receives a packet, the first
35853response expected is an acknowledgment: either @samp{+} (to indicate
35854the package was received correctly) or @samp{-} (to request
35855retransmission):
c906108c 35856
474c8240 35857@smallexample
d2c6833e
AC
35858-> @code{$}@var{packet-data}@code{#}@var{checksum}
35859<- @code{+}
474c8240 35860@end smallexample
8e04817f 35861@noindent
53a5351d 35862
a6f3e723
SL
35863The @samp{+}/@samp{-} acknowledgments can be disabled
35864once a connection is established.
35865@xref{Packet Acknowledgment}, for details.
35866
8e04817f
AC
35867The host (@value{GDBN}) sends @var{command}s, and the target (the
35868debugging stub incorporated in your program) sends a @var{response}. In
35869the case of step and continue @var{command}s, the response is only sent
8b23ecc4
SL
35870when the operation has completed, and the target has again stopped all
35871threads in all attached processes. This is the default all-stop mode
35872behavior, but the remote protocol also supports @value{GDBN}'s non-stop
35873execution mode; see @ref{Remote Non-Stop}, for details.
c906108c 35874
8e04817f
AC
35875@var{packet-data} consists of a sequence of characters with the
35876exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
35877exceptions).
c906108c 35878
ee2d5c50 35879@cindex remote protocol, field separator
0876f84a 35880Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 35881@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 35882@sc{hex} with leading zeros suppressed.
c906108c 35883
8e04817f
AC
35884Implementors should note that prior to @value{GDBN} 5.0, the character
35885@samp{:} could not appear as the third character in a packet (as it
35886would potentially conflict with the @var{sequence-id}).
c906108c 35887
0876f84a
DJ
35888@cindex remote protocol, binary data
35889@anchor{Binary Data}
35890Binary data in most packets is encoded either as two hexadecimal
35891digits per byte of binary data. This allowed the traditional remote
35892protocol to work over connections which were only seven-bit clean.
35893Some packets designed more recently assume an eight-bit clean
35894connection, and use a more efficient encoding to send and receive
35895binary data.
35896
35897The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
35898as an escape character. Any escaped byte is transmitted as the escape
35899character followed by the original character XORed with @code{0x20}.
35900For example, the byte @code{0x7d} would be transmitted as the two
35901bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
35902@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
35903@samp{@}}) must always be escaped. Responses sent by the stub
35904must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
35905is not interpreted as the start of a run-length encoded sequence
35906(described next).
35907
1d3811f6
DJ
35908Response @var{data} can be run-length encoded to save space.
35909Run-length encoding replaces runs of identical characters with one
35910instance of the repeated character, followed by a @samp{*} and a
35911repeat count. The repeat count is itself sent encoded, to avoid
35912binary characters in @var{data}: a value of @var{n} is sent as
35913@code{@var{n}+29}. For a repeat count greater or equal to 3, this
35914produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
35915code 32) for a repeat count of 3. (This is because run-length
35916encoding starts to win for counts 3 or more.) Thus, for example,
35917@samp{0* } is a run-length encoding of ``0000'': the space character
35918after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
359193}} more times.
35920
35921The printable characters @samp{#} and @samp{$} or with a numeric value
35922greater than 126 must not be used. Runs of six repeats (@samp{#}) or
35923seven repeats (@samp{$}) can be expanded using a repeat count of only
35924five (@samp{"}). For example, @samp{00000000} can be encoded as
35925@samp{0*"00}.
c906108c 35926
8e04817f
AC
35927The error response returned for some packets includes a two character
35928error number. That number is not well defined.
c906108c 35929
f8da2bff 35930@cindex empty response, for unsupported packets
8e04817f
AC
35931For any @var{command} not supported by the stub, an empty response
35932(@samp{$#00}) should be returned. That way it is possible to extend the
35933protocol. A newer @value{GDBN} can tell if a packet is supported based
35934on that response.
c906108c 35935
393eab54
PA
35936At a minimum, a stub is required to support the @samp{g} and @samp{G}
35937commands for register access, and the @samp{m} and @samp{M} commands
35938for memory access. Stubs that only control single-threaded targets
35939can implement run control with the @samp{c} (continue), and @samp{s}
35940(step) commands. Stubs that support multi-threading targets should
35941support the @samp{vCont} command. All other commands are optional.
c906108c 35942
ee2d5c50
AC
35943@node Packets
35944@section Packets
35945
35946The following table provides a complete list of all currently defined
35947@var{command}s and their corresponding response @var{data}.
79a6e687 35948@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 35949I/O extension of the remote protocol.
ee2d5c50 35950
b8ff78ce
JB
35951Each packet's description has a template showing the packet's overall
35952syntax, followed by an explanation of the packet's meaning. We
35953include spaces in some of the templates for clarity; these are not
35954part of the packet's syntax. No @value{GDBN} packet uses spaces to
35955separate its components. For example, a template like @samp{foo
35956@var{bar} @var{baz}} describes a packet beginning with the three ASCII
35957bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 35958@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
35959@samp{foo} and the @var{bar}, or between the @var{bar} and the
35960@var{baz}.
35961
b90a069a
SL
35962@cindex @var{thread-id}, in remote protocol
35963@anchor{thread-id syntax}
35964Several packets and replies include a @var{thread-id} field to identify
35965a thread. Normally these are positive numbers with a target-specific
35966interpretation, formatted as big-endian hex strings. A @var{thread-id}
35967can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
35968pick any thread.
35969
35970In addition, the remote protocol supports a multiprocess feature in
35971which the @var{thread-id} syntax is extended to optionally include both
35972process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
35973The @var{pid} (process) and @var{tid} (thread) components each have the
35974format described above: a positive number with target-specific
35975interpretation formatted as a big-endian hex string, literal @samp{-1}
35976to indicate all processes or threads (respectively), or @samp{0} to
35977indicate an arbitrary process or thread. Specifying just a process, as
35978@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
35979error to specify all processes but a specific thread, such as
35980@samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
35981for those packets and replies explicitly documented to include a process
35982ID, rather than a @var{thread-id}.
35983
35984The multiprocess @var{thread-id} syntax extensions are only used if both
35985@value{GDBN} and the stub report support for the @samp{multiprocess}
35986feature using @samp{qSupported}. @xref{multiprocess extensions}, for
35987more information.
35988
8ffe2530
JB
35989Note that all packet forms beginning with an upper- or lower-case
35990letter, other than those described here, are reserved for future use.
35991
b8ff78ce 35992Here are the packet descriptions.
ee2d5c50 35993
b8ff78ce 35994@table @samp
ee2d5c50 35995
b8ff78ce
JB
35996@item !
35997@cindex @samp{!} packet
2d717e4f 35998@anchor{extended mode}
8e04817f
AC
35999Enable extended mode. In extended mode, the remote server is made
36000persistent. The @samp{R} packet is used to restart the program being
36001debugged.
ee2d5c50
AC
36002
36003Reply:
36004@table @samp
36005@item OK
8e04817f 36006The remote target both supports and has enabled extended mode.
ee2d5c50 36007@end table
c906108c 36008
b8ff78ce
JB
36009@item ?
36010@cindex @samp{?} packet
36cb1214 36011@anchor{? packet}
ee2d5c50 36012Indicate the reason the target halted. The reply is the same as for
8b23ecc4
SL
36013step and continue. This packet has a special interpretation when the
36014target is in non-stop mode; see @ref{Remote Non-Stop}.
c906108c 36015
ee2d5c50
AC
36016Reply:
36017@xref{Stop Reply Packets}, for the reply specifications.
36018
b8ff78ce
JB
36019@item A @var{arglen},@var{argnum},@var{arg},@dots{}
36020@cindex @samp{A} packet
36021Initialized @code{argv[]} array passed into program. @var{arglen}
36022specifies the number of bytes in the hex encoded byte stream
36023@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
36024
36025Reply:
36026@table @samp
36027@item OK
b8ff78ce
JB
36028The arguments were set.
36029@item E @var{NN}
36030An error occurred.
ee2d5c50
AC
36031@end table
36032
b8ff78ce
JB
36033@item b @var{baud}
36034@cindex @samp{b} packet
36035(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
36036Change the serial line speed to @var{baud}.
36037
36038JTC: @emph{When does the transport layer state change? When it's
36039received, or after the ACK is transmitted. In either case, there are
36040problems if the command or the acknowledgment packet is dropped.}
36041
36042Stan: @emph{If people really wanted to add something like this, and get
36043it working for the first time, they ought to modify ser-unix.c to send
36044some kind of out-of-band message to a specially-setup stub and have the
36045switch happen "in between" packets, so that from remote protocol's point
36046of view, nothing actually happened.}
36047
b8ff78ce
JB
36048@item B @var{addr},@var{mode}
36049@cindex @samp{B} packet
8e04817f 36050Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
36051breakpoint at @var{addr}.
36052
b8ff78ce 36053Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 36054(@pxref{insert breakpoint or watchpoint packet}).
c906108c 36055
bacec72f 36056@cindex @samp{bc} packet
0d772ac9
MS
36057@anchor{bc}
36058@item bc
bacec72f
MS
36059Backward continue. Execute the target system in reverse. No parameter.
36060@xref{Reverse Execution}, for more information.
36061
36062Reply:
36063@xref{Stop Reply Packets}, for the reply specifications.
36064
bacec72f 36065@cindex @samp{bs} packet
0d772ac9
MS
36066@anchor{bs}
36067@item bs
bacec72f
MS
36068Backward single step. Execute one instruction in reverse. No parameter.
36069@xref{Reverse Execution}, for more information.
36070
36071Reply:
36072@xref{Stop Reply Packets}, for the reply specifications.
36073
4f553f88 36074@item c @r{[}@var{addr}@r{]}
b8ff78ce 36075@cindex @samp{c} packet
697aa1b7
EZ
36076Continue at @var{addr}, which is the address to resume. If @var{addr}
36077is omitted, resume at current address.
c906108c 36078
393eab54
PA
36079This packet is deprecated for multi-threading support. @xref{vCont
36080packet}.
36081
ee2d5c50
AC
36082Reply:
36083@xref{Stop Reply Packets}, for the reply specifications.
36084
4f553f88 36085@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 36086@cindex @samp{C} packet
8e04817f 36087Continue with signal @var{sig} (hex signal number). If
b8ff78ce 36088@samp{;@var{addr}} is omitted, resume at same address.
c906108c 36089
393eab54
PA
36090This packet is deprecated for multi-threading support. @xref{vCont
36091packet}.
36092
ee2d5c50
AC
36093Reply:
36094@xref{Stop Reply Packets}, for the reply specifications.
c906108c 36095
b8ff78ce
JB
36096@item d
36097@cindex @samp{d} packet
ee2d5c50
AC
36098Toggle debug flag.
36099
b8ff78ce
JB
36100Don't use this packet; instead, define a general set packet
36101(@pxref{General Query Packets}).
ee2d5c50 36102
b8ff78ce 36103@item D
b90a069a 36104@itemx D;@var{pid}
b8ff78ce 36105@cindex @samp{D} packet
b90a069a
SL
36106The first form of the packet is used to detach @value{GDBN} from the
36107remote system. It is sent to the remote target
07f31aa6 36108before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50 36109
b90a069a
SL
36110The second form, including a process ID, is used when multiprocess
36111protocol extensions are enabled (@pxref{multiprocess extensions}), to
36112detach only a specific process. The @var{pid} is specified as a
36113big-endian hex string.
36114
ee2d5c50
AC
36115Reply:
36116@table @samp
10fac096
NW
36117@item OK
36118for success
b8ff78ce 36119@item E @var{NN}
10fac096 36120for an error
ee2d5c50 36121@end table
c906108c 36122
b8ff78ce
JB
36123@item F @var{RC},@var{EE},@var{CF};@var{XX}
36124@cindex @samp{F} packet
36125A reply from @value{GDBN} to an @samp{F} packet sent by the target.
36126This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 36127Remote Protocol Extension}, for the specification.
ee2d5c50 36128
b8ff78ce 36129@item g
ee2d5c50 36130@anchor{read registers packet}
b8ff78ce 36131@cindex @samp{g} packet
ee2d5c50
AC
36132Read general registers.
36133
36134Reply:
36135@table @samp
36136@item @var{XX@dots{}}
8e04817f
AC
36137Each byte of register data is described by two hex digits. The bytes
36138with the register are transmitted in target byte order. The size of
b8ff78ce 36139each register and their position within the @samp{g} packet are
4a9bb1df 36140determined by the @value{GDBN} internal gdbarch functions
4435e1cc 36141@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
ad196637
PA
36142
36143When reading registers from a trace frame (@pxref{Analyze Collected
36144Data,,Using the Collected Data}), the stub may also return a string of
36145literal @samp{x}'s in place of the register data digits, to indicate
36146that the corresponding register has not been collected, thus its value
36147is unavailable. For example, for an architecture with 4 registers of
361484 bytes each, the following reply indicates to @value{GDBN} that
36149registers 0 and 2 have not been collected, while registers 1 and 3
36150have been collected, and both have zero value:
36151
36152@smallexample
36153-> @code{g}
36154<- @code{xxxxxxxx00000000xxxxxxxx00000000}
36155@end smallexample
36156
b8ff78ce 36157@item E @var{NN}
ee2d5c50
AC
36158for an error.
36159@end table
c906108c 36160
b8ff78ce
JB
36161@item G @var{XX@dots{}}
36162@cindex @samp{G} packet
36163Write general registers. @xref{read registers packet}, for a
36164description of the @var{XX@dots{}} data.
ee2d5c50
AC
36165
36166Reply:
36167@table @samp
36168@item OK
36169for success
b8ff78ce 36170@item E @var{NN}
ee2d5c50
AC
36171for an error
36172@end table
36173
393eab54 36174@item H @var{op} @var{thread-id}
b8ff78ce 36175@cindex @samp{H} packet
8e04817f 36176Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
697aa1b7
EZ
36177@samp{G}, et.al.). Depending on the operation to be performed, @var{op}
36178should be @samp{c} for step and continue operations (note that this
393eab54 36179is deprecated, supporting the @samp{vCont} command is a better
697aa1b7 36180option), and @samp{g} for other operations. The thread designator
393eab54
PA
36181@var{thread-id} has the format and interpretation described in
36182@ref{thread-id syntax}.
ee2d5c50
AC
36183
36184Reply:
36185@table @samp
36186@item OK
36187for success
b8ff78ce 36188@item E @var{NN}
ee2d5c50
AC
36189for an error
36190@end table
c906108c 36191
8e04817f
AC
36192@c FIXME: JTC:
36193@c 'H': How restrictive (or permissive) is the thread model. If a
36194@c thread is selected and stopped, are other threads allowed
36195@c to continue to execute? As I mentioned above, I think the
36196@c semantics of each command when a thread is selected must be
36197@c described. For example:
36198@c
36199@c 'g': If the stub supports threads and a specific thread is
36200@c selected, returns the register block from that thread;
36201@c otherwise returns current registers.
36202@c
36203@c 'G' If the stub supports threads and a specific thread is
36204@c selected, sets the registers of the register block of
36205@c that thread; otherwise sets current registers.
c906108c 36206
b8ff78ce 36207@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 36208@anchor{cycle step packet}
b8ff78ce
JB
36209@cindex @samp{i} packet
36210Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
36211present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
36212step starting at that address.
c906108c 36213
b8ff78ce
JB
36214@item I
36215@cindex @samp{I} packet
36216Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
36217step packet}.
ee2d5c50 36218
b8ff78ce
JB
36219@item k
36220@cindex @samp{k} packet
36221Kill request.
c906108c 36222
36cb1214
HZ
36223The exact effect of this packet is not specified.
36224
36225For a bare-metal target, it may power cycle or reset the target
36226system. For that reason, the @samp{k} packet has no reply.
36227
36228For a single-process target, it may kill that process if possible.
36229
36230A multiple-process target may choose to kill just one process, or all
36231that are under @value{GDBN}'s control. For more precise control, use
36232the vKill packet (@pxref{vKill packet}).
36233
36234If the target system immediately closes the connection in response to
36235@samp{k}, @value{GDBN} does not consider the lack of packet
36236acknowledgment to be an error, and assumes the kill was successful.
36237
36238If connected using @kbd{target extended-remote}, and the target does
36239not close the connection in response to a kill request, @value{GDBN}
36240probes the target state as if a new connection was opened
36241(@pxref{? packet}).
c906108c 36242
b8ff78ce
JB
36243@item m @var{addr},@var{length}
36244@cindex @samp{m} packet
a86c90e6
SM
36245Read @var{length} addressable memory units starting at address @var{addr}
36246(@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
36247any particular boundary.
fb031cdf
JB
36248
36249The stub need not use any particular size or alignment when gathering
36250data from memory for the response; even if @var{addr} is word-aligned
36251and @var{length} is a multiple of the word size, the stub is free to
36252use byte accesses, or not. For this reason, this packet may not be
36253suitable for accessing memory-mapped I/O devices.
c43c5473
JB
36254@cindex alignment of remote memory accesses
36255@cindex size of remote memory accesses
36256@cindex memory, alignment and size of remote accesses
c906108c 36257
ee2d5c50
AC
36258Reply:
36259@table @samp
36260@item @var{XX@dots{}}
a86c90e6
SM
36261Memory contents; each byte is transmitted as a two-digit hexadecimal number.
36262The reply may contain fewer addressable memory units than requested if the
b8ff78ce
JB
36263server was able to read only part of the region of memory.
36264@item E @var{NN}
ee2d5c50
AC
36265@var{NN} is errno
36266@end table
36267
b8ff78ce
JB
36268@item M @var{addr},@var{length}:@var{XX@dots{}}
36269@cindex @samp{M} packet
a86c90e6
SM
36270Write @var{length} addressable memory units starting at address @var{addr}
36271(@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
36272byte is transmitted as a two-digit hexadecimal number.
ee2d5c50
AC
36273
36274Reply:
36275@table @samp
36276@item OK
36277for success
b8ff78ce 36278@item E @var{NN}
8e04817f
AC
36279for an error (this includes the case where only part of the data was
36280written).
ee2d5c50 36281@end table
c906108c 36282
b8ff78ce
JB
36283@item p @var{n}
36284@cindex @samp{p} packet
36285Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
36286@xref{read registers packet}, for a description of how the returned
36287register value is encoded.
ee2d5c50
AC
36288
36289Reply:
36290@table @samp
2e868123
AC
36291@item @var{XX@dots{}}
36292the register's value
b8ff78ce 36293@item E @var{NN}
2e868123 36294for an error
d57350ea 36295@item @w{}
2e868123 36296Indicating an unrecognized @var{query}.
ee2d5c50
AC
36297@end table
36298
b8ff78ce 36299@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 36300@anchor{write register packet}
b8ff78ce
JB
36301@cindex @samp{P} packet
36302Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 36303number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 36304digits for each byte in the register (target byte order).
c906108c 36305
ee2d5c50
AC
36306Reply:
36307@table @samp
36308@item OK
36309for success
b8ff78ce 36310@item E @var{NN}
ee2d5c50
AC
36311for an error
36312@end table
36313
5f3bebba
JB
36314@item q @var{name} @var{params}@dots{}
36315@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 36316@cindex @samp{q} packet
b8ff78ce 36317@cindex @samp{Q} packet
5f3bebba
JB
36318General query (@samp{q}) and set (@samp{Q}). These packets are
36319described fully in @ref{General Query Packets}.
c906108c 36320
b8ff78ce
JB
36321@item r
36322@cindex @samp{r} packet
8e04817f 36323Reset the entire system.
c906108c 36324
b8ff78ce 36325Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 36326
b8ff78ce
JB
36327@item R @var{XX}
36328@cindex @samp{R} packet
697aa1b7 36329Restart the program being debugged. The @var{XX}, while needed, is ignored.
2d717e4f 36330This packet is only available in extended mode (@pxref{extended mode}).
ee2d5c50 36331
8e04817f 36332The @samp{R} packet has no reply.
ee2d5c50 36333
4f553f88 36334@item s @r{[}@var{addr}@r{]}
b8ff78ce 36335@cindex @samp{s} packet
697aa1b7 36336Single step, resuming at @var{addr}. If
b8ff78ce 36337@var{addr} is omitted, resume at same address.
c906108c 36338
393eab54
PA
36339This packet is deprecated for multi-threading support. @xref{vCont
36340packet}.
36341
ee2d5c50
AC
36342Reply:
36343@xref{Stop Reply Packets}, for the reply specifications.
36344
4f553f88 36345@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 36346@anchor{step with signal packet}
b8ff78ce
JB
36347@cindex @samp{S} packet
36348Step with signal. This is analogous to the @samp{C} packet, but
36349requests a single-step, rather than a normal resumption of execution.
c906108c 36350
393eab54
PA
36351This packet is deprecated for multi-threading support. @xref{vCont
36352packet}.
36353
ee2d5c50
AC
36354Reply:
36355@xref{Stop Reply Packets}, for the reply specifications.
36356
b8ff78ce
JB
36357@item t @var{addr}:@var{PP},@var{MM}
36358@cindex @samp{t} packet
8e04817f 36359Search backwards starting at address @var{addr} for a match with pattern
697aa1b7
EZ
36360@var{PP} and mask @var{MM}, both of which are are 4 byte long.
36361There must be at least 3 digits in @var{addr}.
c906108c 36362
b90a069a 36363@item T @var{thread-id}
b8ff78ce 36364@cindex @samp{T} packet
b90a069a 36365Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
c906108c 36366
ee2d5c50
AC
36367Reply:
36368@table @samp
36369@item OK
36370thread is still alive
b8ff78ce 36371@item E @var{NN}
ee2d5c50
AC
36372thread is dead
36373@end table
36374
b8ff78ce
JB
36375@item v
36376Packets starting with @samp{v} are identified by a multi-letter name,
36377up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 36378
2d717e4f
DJ
36379@item vAttach;@var{pid}
36380@cindex @samp{vAttach} packet
8b23ecc4
SL
36381Attach to a new process with the specified process ID @var{pid}.
36382The process ID is a
36383hexadecimal integer identifying the process. In all-stop mode, all
36384threads in the attached process are stopped; in non-stop mode, it may be
36385attached without being stopped if that is supported by the target.
36386
36387@c In non-stop mode, on a successful vAttach, the stub should set the
36388@c current thread to a thread of the newly-attached process. After
36389@c attaching, GDB queries for the attached process's thread ID with qC.
36390@c Also note that, from a user perspective, whether or not the
36391@c target is stopped on attach in non-stop mode depends on whether you
36392@c use the foreground or background version of the attach command, not
36393@c on what vAttach does; GDB does the right thing with respect to either
36394@c stopping or restarting threads.
2d717e4f
DJ
36395
36396This packet is only available in extended mode (@pxref{extended mode}).
36397
36398Reply:
36399@table @samp
36400@item E @var{nn}
36401for an error
36402@item @r{Any stop packet}
8b23ecc4
SL
36403for success in all-stop mode (@pxref{Stop Reply Packets})
36404@item OK
36405for success in non-stop mode (@pxref{Remote Non-Stop})
2d717e4f
DJ
36406@end table
36407
b90a069a 36408@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
b8ff78ce 36409@cindex @samp{vCont} packet
393eab54 36410@anchor{vCont packet}
b8ff78ce 36411Resume the inferior, specifying different actions for each thread.
ca6eff59
PA
36412
36413For each inferior thread, the leftmost action with a matching
36414@var{thread-id} is applied. Threads that don't match any action
36415remain in their current state. Thread IDs are specified using the
36416syntax described in @ref{thread-id syntax}. If multiprocess
36417extensions (@pxref{multiprocess extensions}) are supported, actions
36418can be specified to match all threads in a process by using the
36419@samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
39402e6c
PA
36420@var{thread-id} matches all threads. Specifying no actions is an
36421error.
b90a069a
SL
36422
36423Currently supported actions are:
86d30acc 36424
b8ff78ce 36425@table @samp
86d30acc
DJ
36426@item c
36427Continue.
b8ff78ce 36428@item C @var{sig}
8b23ecc4 36429Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
36430@item s
36431Step.
b8ff78ce 36432@item S @var{sig}
8b23ecc4
SL
36433Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
36434@item t
36435Stop.
c1e36e3e
PA
36436@item r @var{start},@var{end}
36437Step once, and then keep stepping as long as the thread stops at
36438addresses between @var{start} (inclusive) and @var{end} (exclusive).
36439The remote stub reports a stop reply when either the thread goes out
36440of the range or is stopped due to an unrelated reason, such as hitting
36441a breakpoint. @xref{range stepping}.
36442
36443If the range is empty (@var{start} == @var{end}), then the action
36444becomes equivalent to the @samp{s} action. In other words,
36445single-step once, and report the stop (even if the stepped instruction
36446jumps to @var{start}).
36447
36448(A stop reply may be sent at any point even if the PC is still within
36449the stepping range; for example, it is valid to implement this packet
36450in a degenerate way as a single instruction step operation.)
36451
86d30acc
DJ
36452@end table
36453
8b23ecc4
SL
36454The optional argument @var{addr} normally associated with the
36455@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
b8ff78ce 36456not supported in @samp{vCont}.
86d30acc 36457
08a0efd0
PA
36458The @samp{t} action is only relevant in non-stop mode
36459(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
8b23ecc4
SL
36460A stop reply should be generated for any affected thread not already stopped.
36461When a thread is stopped by means of a @samp{t} action,
36462the corresponding stop reply should indicate that the thread has stopped with
36463signal @samp{0}, regardless of whether the target uses some other signal
36464as an implementation detail.
36465
ca6eff59
PA
36466The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
36467@samp{r} actions for threads that are already running. Conversely,
36468the server must ignore @samp{t} actions for threads that are already
36469stopped.
36470
36471@emph{Note:} In non-stop mode, a thread is considered running until
36472@value{GDBN} acknowleges an asynchronous stop notification for it with
36473the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
36474
4220b2f8 36475The stub must support @samp{vCont} if it reports support for
ca6eff59 36476multiprocess extensions (@pxref{multiprocess extensions}).
4220b2f8 36477
86d30acc
DJ
36478Reply:
36479@xref{Stop Reply Packets}, for the reply specifications.
36480
b8ff78ce
JB
36481@item vCont?
36482@cindex @samp{vCont?} packet
d3e8051b 36483Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
36484
36485Reply:
36486@table @samp
b8ff78ce
JB
36487@item vCont@r{[};@var{action}@dots{}@r{]}
36488The @samp{vCont} packet is supported. Each @var{action} is a supported
36489command in the @samp{vCont} packet.
d57350ea 36490@item @w{}
b8ff78ce 36491The @samp{vCont} packet is not supported.
86d30acc 36492@end table
ee2d5c50 36493
de979965
PA
36494@anchor{vCtrlC packet}
36495@item vCtrlC
36496@cindex @samp{vCtrlC} packet
36497Interrupt remote target as if a control-C was pressed on the remote
36498terminal. This is the equivalent to reacting to the @code{^C}
36499(@samp{\003}, the control-C character) character in all-stop mode
36500while the target is running, except this works in non-stop mode.
36501@xref{interrupting remote targets}, for more info on the all-stop
36502variant.
36503
36504Reply:
36505@table @samp
36506@item E @var{nn}
36507for an error
36508@item OK
36509for success
36510@end table
36511
a6b151f1
DJ
36512@item vFile:@var{operation}:@var{parameter}@dots{}
36513@cindex @samp{vFile} packet
36514Perform a file operation on the target system. For details,
36515see @ref{Host I/O Packets}.
36516
68437a39
DJ
36517@item vFlashErase:@var{addr},@var{length}
36518@cindex @samp{vFlashErase} packet
36519Direct the stub to erase @var{length} bytes of flash starting at
36520@var{addr}. The region may enclose any number of flash blocks, but
36521its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
36522flash block size appearing in the memory map (@pxref{Memory Map
36523Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
36524together, and sends a @samp{vFlashDone} request after each group; the
36525stub is allowed to delay erase operation until the @samp{vFlashDone}
36526packet is received.
36527
36528Reply:
36529@table @samp
36530@item OK
36531for success
36532@item E @var{NN}
36533for an error
36534@end table
36535
36536@item vFlashWrite:@var{addr}:@var{XX@dots{}}
36537@cindex @samp{vFlashWrite} packet
36538Direct the stub to write data to flash address @var{addr}. The data
36539is passed in binary form using the same encoding as for the @samp{X}
36540packet (@pxref{Binary Data}). The memory ranges specified by
36541@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
36542not overlap, and must appear in order of increasing addresses
36543(although @samp{vFlashErase} packets for higher addresses may already
36544have been received; the ordering is guaranteed only between
36545@samp{vFlashWrite} packets). If a packet writes to an address that was
36546neither erased by a preceding @samp{vFlashErase} packet nor by some other
36547target-specific method, the results are unpredictable.
36548
36549
36550Reply:
36551@table @samp
36552@item OK
36553for success
36554@item E.memtype
36555for vFlashWrite addressing non-flash memory
36556@item E @var{NN}
36557for an error
36558@end table
36559
36560@item vFlashDone
36561@cindex @samp{vFlashDone} packet
36562Indicate to the stub that flash programming operation is finished.
36563The stub is permitted to delay or batch the effects of a group of
36564@samp{vFlashErase} and @samp{vFlashWrite} packets until a
36565@samp{vFlashDone} packet is received. The contents of the affected
36566regions of flash memory are unpredictable until the @samp{vFlashDone}
36567request is completed.
36568
b90a069a
SL
36569@item vKill;@var{pid}
36570@cindex @samp{vKill} packet
36cb1214 36571@anchor{vKill packet}
697aa1b7 36572Kill the process with the specified process ID @var{pid}, which is a
b90a069a
SL
36573hexadecimal integer identifying the process. This packet is used in
36574preference to @samp{k} when multiprocess protocol extensions are
36575supported; see @ref{multiprocess extensions}.
36576
36577Reply:
36578@table @samp
36579@item E @var{nn}
36580for an error
36581@item OK
36582for success
36583@end table
36584
176efed1
AB
36585@item vMustReplyEmpty
36586@cindex @samp{vMustReplyEmpty} packet
36587The correct reply to an unknown @samp{v} packet is to return the empty
36588string, however, some older versions of @command{gdbserver} would
36589incorrectly return @samp{OK} for unknown @samp{v} packets.
36590
36591The @samp{vMustReplyEmpty} is used as a feature test to check how
36592@command{gdbserver} handles unknown packets, it is important that this
36593packet be handled in the same way as other unknown @samp{v} packets.
36594If this packet is handled differently to other unknown @samp{v}
36595packets then it is possile that @value{GDBN} may run into problems in
36596other areas, specifically around use of @samp{vFile:setfs:}.
36597
2d717e4f
DJ
36598@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
36599@cindex @samp{vRun} packet
36600Run the program @var{filename}, passing it each @var{argument} on its
36601command line. The file and arguments are hex-encoded strings. If
36602@var{filename} is an empty string, the stub may use a default program
36603(e.g.@: the last program run). The program is created in the stopped
9b562ab8 36604state.
2d717e4f 36605
8b23ecc4
SL
36606@c FIXME: What about non-stop mode?
36607
2d717e4f
DJ
36608This packet is only available in extended mode (@pxref{extended mode}).
36609
36610Reply:
36611@table @samp
36612@item E @var{nn}
36613for an error
36614@item @r{Any stop packet}
36615for success (@pxref{Stop Reply Packets})
36616@end table
36617
8b23ecc4 36618@item vStopped
8b23ecc4 36619@cindex @samp{vStopped} packet
8dbe8ece 36620@xref{Notification Packets}.
8b23ecc4 36621
b8ff78ce 36622@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 36623@anchor{X packet}
b8ff78ce
JB
36624@cindex @samp{X} packet
36625Write data to memory, where the data is transmitted in binary.
a86c90e6
SM
36626Memory is specified by its address @var{addr} and number of addressable memory
36627units @var{length} (@pxref{addressable memory unit});
0876f84a 36628@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 36629
ee2d5c50
AC
36630Reply:
36631@table @samp
36632@item OK
36633for success
b8ff78ce 36634@item E @var{NN}
ee2d5c50
AC
36635for an error
36636@end table
36637
a1dcb23a
DJ
36638@item z @var{type},@var{addr},@var{kind}
36639@itemx Z @var{type},@var{addr},@var{kind}
2f870471 36640@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
36641@cindex @samp{z} packet
36642@cindex @samp{Z} packets
36643Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
a1dcb23a 36644watchpoint starting at address @var{address} of kind @var{kind}.
ee2d5c50 36645
2f870471
AC
36646Each breakpoint and watchpoint packet @var{type} is documented
36647separately.
36648
512217c7
AC
36649@emph{Implementation notes: A remote target shall return an empty string
36650for an unrecognized breakpoint or watchpoint packet @var{type}. A
36651remote target shall support either both or neither of a given
b8ff78ce 36652@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
36653avoid potential problems with duplicate packets, the operations should
36654be implemented in an idempotent way.}
36655
a1dcb23a 36656@item z0,@var{addr},@var{kind}
d3ce09f5 36657@itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
36658@cindex @samp{z0} packet
36659@cindex @samp{Z0} packet
4435e1cc 36660Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
a1dcb23a 36661@var{addr} of type @var{kind}.
2f870471 36662
4435e1cc 36663A software breakpoint is implemented by replacing the instruction at
2f870471 36664@var{addr} with a software breakpoint or trap instruction. The
4435e1cc
TT
36665@var{kind} is target-specific and typically indicates the size of the
36666breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
36667@sc{mips} can insert either a 2 or 4 byte breakpoint. Some
36668architectures have additional meanings for @var{kind}
36669(@pxref{Architecture-Specific Protocol Details}); if no
36670architecture-specific value is being used, it should be @samp{0}.
36671@var{kind} is hex-encoded. @var{cond_list} is an optional list of
36672conditional expressions in bytecode form that should be evaluated on
36673the target's side. These are the conditions that should be taken into
36674consideration when deciding if the breakpoint trigger should be
36675reported back to @value{GDBN}.
83364271 36676
f7e6eed5 36677See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
4435e1cc 36678for how to best report a software breakpoint event to @value{GDBN}.
f7e6eed5 36679
83364271
LM
36680The @var{cond_list} parameter is comprised of a series of expressions,
36681concatenated without separators. Each expression has the following form:
36682
36683@table @samp
36684
36685@item X @var{len},@var{expr}
36686@var{len} is the length of the bytecode expression and @var{expr} is the
36687actual conditional expression in bytecode form.
36688
36689@end table
36690
d3ce09f5
SS
36691The optional @var{cmd_list} parameter introduces commands that may be
36692run on the target, rather than being reported back to @value{GDBN}.
36693The parameter starts with a numeric flag @var{persist}; if the flag is
36694nonzero, then the breakpoint may remain active and the commands
36695continue to be run even when @value{GDBN} disconnects from the target.
36696Following this flag is a series of expressions concatenated with no
36697separators. Each expression has the following form:
36698
36699@table @samp
36700
36701@item X @var{len},@var{expr}
36702@var{len} is the length of the bytecode expression and @var{expr} is the
0968fbae 36703actual commands expression in bytecode form.
d3ce09f5
SS
36704
36705@end table
36706
2f870471 36707@emph{Implementation note: It is possible for a target to copy or move
4435e1cc 36708code that contains software breakpoints (e.g., when implementing
2f870471
AC
36709overlays). The behavior of this packet, in the presence of such a
36710target, is not defined.}
c906108c 36711
ee2d5c50
AC
36712Reply:
36713@table @samp
2f870471
AC
36714@item OK
36715success
d57350ea 36716@item @w{}
2f870471 36717not supported
b8ff78ce 36718@item E @var{NN}
ee2d5c50 36719for an error
2f870471
AC
36720@end table
36721
a1dcb23a 36722@item z1,@var{addr},@var{kind}
4435e1cc 36723@itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
36724@cindex @samp{z1} packet
36725@cindex @samp{Z1} packet
36726Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
a1dcb23a 36727address @var{addr}.
2f870471
AC
36728
36729A hardware breakpoint is implemented using a mechanism that is not
4435e1cc
TT
36730dependent on being able to modify the target's memory. The
36731@var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
36732same meaning as in @samp{Z0} packets.
2f870471
AC
36733
36734@emph{Implementation note: A hardware breakpoint is not affected by code
36735movement.}
36736
36737Reply:
36738@table @samp
ee2d5c50 36739@item OK
2f870471 36740success
d57350ea 36741@item @w{}
2f870471 36742not supported
b8ff78ce 36743@item E @var{NN}
2f870471
AC
36744for an error
36745@end table
36746
a1dcb23a
DJ
36747@item z2,@var{addr},@var{kind}
36748@itemx Z2,@var{addr},@var{kind}
b8ff78ce
JB
36749@cindex @samp{z2} packet
36750@cindex @samp{Z2} packet
a1dcb23a 36751Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
697aa1b7 36752The number of bytes to watch is specified by @var{kind}.
2f870471
AC
36753
36754Reply:
36755@table @samp
36756@item OK
36757success
d57350ea 36758@item @w{}
2f870471 36759not supported
b8ff78ce 36760@item E @var{NN}
2f870471
AC
36761for an error
36762@end table
36763
a1dcb23a
DJ
36764@item z3,@var{addr},@var{kind}
36765@itemx Z3,@var{addr},@var{kind}
b8ff78ce
JB
36766@cindex @samp{z3} packet
36767@cindex @samp{Z3} packet
a1dcb23a 36768Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
697aa1b7 36769The number of bytes to watch is specified by @var{kind}.
2f870471
AC
36770
36771Reply:
36772@table @samp
36773@item OK
36774success
d57350ea 36775@item @w{}
2f870471 36776not supported
b8ff78ce 36777@item E @var{NN}
2f870471
AC
36778for an error
36779@end table
36780
a1dcb23a
DJ
36781@item z4,@var{addr},@var{kind}
36782@itemx Z4,@var{addr},@var{kind}
b8ff78ce
JB
36783@cindex @samp{z4} packet
36784@cindex @samp{Z4} packet
a1dcb23a 36785Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
697aa1b7 36786The number of bytes to watch is specified by @var{kind}.
2f870471
AC
36787
36788Reply:
36789@table @samp
36790@item OK
36791success
d57350ea 36792@item @w{}
2f870471 36793not supported
b8ff78ce 36794@item E @var{NN}
2f870471 36795for an error
ee2d5c50
AC
36796@end table
36797
36798@end table
c906108c 36799
ee2d5c50
AC
36800@node Stop Reply Packets
36801@section Stop Reply Packets
36802@cindex stop reply packets
c906108c 36803
8b23ecc4
SL
36804The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
36805@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
36806receive any of the below as a reply. Except for @samp{?}
36807and @samp{vStopped}, that reply is only returned
b8ff78ce 36808when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
36809number} is defined by the header @file{include/gdb/signals.h} in the
36810@value{GDBN} source code.
c906108c 36811
4435e1cc
TT
36812In non-stop mode, the server will simply reply @samp{OK} to commands
36813such as @samp{vCont}; any stop will be the subject of a future
36814notification. @xref{Remote Non-Stop}.
36815
b8ff78ce
JB
36816As in the description of request packets, we include spaces in the
36817reply templates for clarity; these are not part of the reply packet's
36818syntax. No @value{GDBN} stop reply packet uses spaces to separate its
36819components.
c906108c 36820
b8ff78ce 36821@table @samp
ee2d5c50 36822
b8ff78ce 36823@item S @var{AA}
599b237a 36824The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
36825number). This is equivalent to a @samp{T} response with no
36826@var{n}:@var{r} pairs.
c906108c 36827
b8ff78ce
JB
36828@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
36829@cindex @samp{T} packet reply
599b237a 36830The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
36831number). This is equivalent to an @samp{S} response, except that the
36832@samp{@var{n}:@var{r}} pairs can carry values of important registers
36833and other information directly in the stop reply packet, reducing
36834round-trip latency. Single-step and breakpoint traps are reported
36835this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
36836
36837@itemize @bullet
b8ff78ce 36838@item
599b237a 36839If @var{n} is a hexadecimal number, it is a register number, and the
697aa1b7 36840corresponding @var{r} gives that register's value. The data @var{r} is a
b8ff78ce
JB
36841series of bytes in target byte order, with each byte given by a
36842two-digit hex number.
cfa9d6d9 36843
b8ff78ce 36844@item
b90a069a
SL
36845If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
36846the stopped thread, as specified in @ref{thread-id syntax}.
cfa9d6d9 36847
dc146f7c
VP
36848@item
36849If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
36850the core on which the stop event was detected.
36851
b8ff78ce 36852@item
cfa9d6d9
DJ
36853If @var{n} is a recognized @dfn{stop reason}, it describes a more
36854specific event that stopped the target. The currently defined stop
697aa1b7 36855reasons are listed below. The @var{aa} should be @samp{05}, the trap
cfa9d6d9
DJ
36856signal. At most one stop reason should be present.
36857
b8ff78ce
JB
36858@item
36859Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
36860and go on to the next; this allows us to extend the protocol in the
36861future.
cfa9d6d9
DJ
36862@end itemize
36863
36864The currently defined stop reasons are:
36865
36866@table @samp
36867@item watch
36868@itemx rwatch
36869@itemx awatch
36870The packet indicates a watchpoint hit, and @var{r} is the data address, in
36871hex.
36872
82075af2
JS
36873@item syscall_entry
36874@itemx syscall_return
36875The packet indicates a syscall entry or return, and @var{r} is the
36876syscall number, in hex.
36877
cfa9d6d9
DJ
36878@cindex shared library events, remote reply
36879@item library
36880The packet indicates that the loaded libraries have changed.
36881@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
697aa1b7 36882list of loaded libraries. The @var{r} part is ignored.
bacec72f
MS
36883
36884@cindex replay log events, remote reply
36885@item replaylog
36886The packet indicates that the target cannot continue replaying
36887logged execution events, because it has reached the end (or the
36888beginning when executing backward) of the log. The value of @var{r}
36889will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
36890for more information.
f7e6eed5
PA
36891
36892@item swbreak
36893@anchor{swbreak stop reason}
4435e1cc 36894The packet indicates a software breakpoint instruction was executed,
f7e6eed5
PA
36895irrespective of whether it was @value{GDBN} that planted the
36896breakpoint or the breakpoint is hardcoded in the program. The @var{r}
36897part must be left empty.
36898
36899On some architectures, such as x86, at the architecture level, when a
36900breakpoint instruction executes the program counter points at the
36901breakpoint address plus an offset. On such targets, the stub is
36902responsible for adjusting the PC to point back at the breakpoint
36903address.
36904
36905This packet should not be sent by default; older @value{GDBN} versions
36906did not support it. @value{GDBN} requests it, by supplying an
36907appropriate @samp{qSupported} feature (@pxref{qSupported}). The
36908remote stub must also supply the appropriate @samp{qSupported} feature
36909indicating support.
36910
36911This packet is required for correct non-stop mode operation.
36912
36913@item hwbreak
36914The packet indicates the target stopped for a hardware breakpoint.
36915The @var{r} part must be left empty.
36916
36917The same remarks about @samp{qSupported} and non-stop mode above
36918apply.
0d71eef5
DB
36919
36920@cindex fork events, remote reply
36921@item fork
36922The packet indicates that @code{fork} was called, and @var{r}
36923is the thread ID of the new child process. Refer to
36924@ref{thread-id syntax} for the format of the @var{thread-id}
36925field. This packet is only applicable to targets that support
36926fork events.
36927
36928This packet should not be sent by default; older @value{GDBN} versions
36929did not support it. @value{GDBN} requests it, by supplying an
36930appropriate @samp{qSupported} feature (@pxref{qSupported}). The
36931remote stub must also supply the appropriate @samp{qSupported} feature
36932indicating support.
36933
36934@cindex vfork events, remote reply
36935@item vfork
36936The packet indicates that @code{vfork} was called, and @var{r}
36937is the thread ID of the new child process. Refer to
36938@ref{thread-id syntax} for the format of the @var{thread-id}
36939field. This packet is only applicable to targets that support
36940vfork events.
36941
36942This packet should not be sent by default; older @value{GDBN} versions
36943did not support it. @value{GDBN} requests it, by supplying an
36944appropriate @samp{qSupported} feature (@pxref{qSupported}). The
36945remote stub must also supply the appropriate @samp{qSupported} feature
36946indicating support.
36947
36948@cindex vforkdone events, remote reply
36949@item vforkdone
e68fa6f0
PA
36950The packet indicates that a child process created by a vfork
36951has either called @code{exec} or terminated, so that the
36952address spaces of the parent and child process are no longer
36953shared. The @var{r} part is ignored. This packet is only
36954applicable to targets that support vforkdone events.
0d71eef5
DB
36955
36956This packet should not be sent by default; older @value{GDBN} versions
36957did not support it. @value{GDBN} requests it, by supplying an
36958appropriate @samp{qSupported} feature (@pxref{qSupported}). The
36959remote stub must also supply the appropriate @samp{qSupported} feature
36960indicating support.
36961
b459a59b
DB
36962@cindex exec events, remote reply
36963@item exec
36964The packet indicates that @code{execve} was called, and @var{r}
36965is the absolute pathname of the file that was executed, in hex.
36966This packet is only applicable to targets that support exec events.
36967
36968This packet should not be sent by default; older @value{GDBN} versions
36969did not support it. @value{GDBN} requests it, by supplying an
36970appropriate @samp{qSupported} feature (@pxref{qSupported}). The
36971remote stub must also supply the appropriate @samp{qSupported} feature
36972indicating support.
36973
65706a29
PA
36974@cindex thread create event, remote reply
36975@anchor{thread create event}
36976@item create
36977The packet indicates that the thread was just created. The new thread
36978is stopped until @value{GDBN} sets it running with a resumption packet
36979(@pxref{vCont packet}). This packet should not be sent by default;
36980@value{GDBN} requests it with the @ref{QThreadEvents} packet. See
4435e1cc
TT
36981also the @samp{w} (@pxref{thread exit event}) remote reply below. The
36982@var{r} part is ignored.
65706a29 36983
cfa9d6d9 36984@end table
ee2d5c50 36985
b8ff78ce 36986@item W @var{AA}
b90a069a 36987@itemx W @var{AA} ; process:@var{pid}
8e04817f 36988The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
36989applicable to certain targets.
36990
4435e1cc
TT
36991The second form of the response, including the process ID of the
36992exited process, can be used only when @value{GDBN} has reported
36993support for multiprocess protocol extensions; see @ref{multiprocess
36994extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
36995hex strings.
b90a069a 36996
b8ff78ce 36997@item X @var{AA}
b90a069a 36998@itemx X @var{AA} ; process:@var{pid}
8e04817f 36999The process terminated with signal @var{AA}.
c906108c 37000
b90a069a
SL
37001The second form of the response, including the process ID of the
37002terminated process, can be used only when @value{GDBN} has reported
37003support for multiprocess protocol extensions; see @ref{multiprocess
4435e1cc
TT
37004extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
37005hex strings.
b90a069a 37006
65706a29
PA
37007@anchor{thread exit event}
37008@cindex thread exit event, remote reply
37009@item w @var{AA} ; @var{tid}
37010
37011The thread exited, and @var{AA} is the exit status. This response
37012should not be sent by default; @value{GDBN} requests it with the
37013@ref{QThreadEvents} packet. See also @ref{thread create event} above.
4435e1cc 37014@var{AA} is formatted as a big-endian hex string.
65706a29 37015
f2faf941
PA
37016@item N
37017There are no resumed threads left in the target. In other words, even
37018though the process is alive, the last resumed thread has exited. For
37019example, say the target process has two threads: thread 1 and thread
370202. The client leaves thread 1 stopped, and resumes thread 2, which
37021subsequently exits. At this point, even though the process is still
37022alive, and thus no @samp{W} stop reply is sent, no thread is actually
37023executing either. The @samp{N} stop reply thus informs the client
37024that it can stop waiting for stop replies. This packet should not be
37025sent by default; older @value{GDBN} versions did not support it.
37026@value{GDBN} requests it, by supplying an appropriate
37027@samp{qSupported} feature (@pxref{qSupported}). The remote stub must
37028also supply the appropriate @samp{qSupported} feature indicating
37029support.
37030
b8ff78ce
JB
37031@item O @var{XX}@dots{}
37032@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
37033written as the program's console output. This can happen at any time
37034while the program is running and the debugger should continue to wait
8b23ecc4 37035for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
0ce1b118 37036
b8ff78ce 37037@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
37038@var{call-id} is the identifier which says which host system call should
37039be called. This is just the name of the function. Translation into the
37040correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 37041@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
37042system calls.
37043
b8ff78ce
JB
37044@samp{@var{parameter}@dots{}} is a list of parameters as defined for
37045this very system call.
0ce1b118 37046
b8ff78ce
JB
37047The target replies with this packet when it expects @value{GDBN} to
37048call a host system call on behalf of the target. @value{GDBN} replies
37049with an appropriate @samp{F} packet and keeps up waiting for the next
37050reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
37051or @samp{s} action is expected to be continued. @xref{File-I/O Remote
37052Protocol Extension}, for more details.
0ce1b118 37053
ee2d5c50
AC
37054@end table
37055
37056@node General Query Packets
37057@section General Query Packets
9c16f35a 37058@cindex remote query requests
c906108c 37059
5f3bebba
JB
37060Packets starting with @samp{q} are @dfn{general query packets};
37061packets starting with @samp{Q} are @dfn{general set packets}. General
37062query and set packets are a semi-unified form for retrieving and
37063sending information to and from the stub.
37064
37065The initial letter of a query or set packet is followed by a name
37066indicating what sort of thing the packet applies to. For example,
37067@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
37068definitions with the stub. These packet names follow some
37069conventions:
37070
37071@itemize @bullet
37072@item
37073The name must not contain commas, colons or semicolons.
37074@item
37075Most @value{GDBN} query and set packets have a leading upper case
37076letter.
37077@item
37078The names of custom vendor packets should use a company prefix, in
37079lower case, followed by a period. For example, packets designed at
37080the Acme Corporation might begin with @samp{qacme.foo} (for querying
37081foos) or @samp{Qacme.bar} (for setting bars).
37082@end itemize
37083
aa56d27a
JB
37084The name of a query or set packet should be separated from any
37085parameters by a @samp{:}; the parameters themselves should be
37086separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
37087full packet name, and check for a separator or the end of the packet,
37088in case two packet names share a common prefix. New packets should not begin
37089with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
37090packets predate these conventions, and have arguments without any terminator
37091for the packet name; we suspect they are in widespread use in places that
37092are difficult to upgrade. The @samp{qC} packet has no arguments, but some
37093existing stubs (e.g.@: RedBoot) are known to not check for the end of the
37094packet.}.
c906108c 37095
b8ff78ce
JB
37096Like the descriptions of the other packets, each description here
37097has a template showing the packet's overall syntax, followed by an
37098explanation of the packet's meaning. We include spaces in some of the
37099templates for clarity; these are not part of the packet's syntax. No
37100@value{GDBN} packet uses spaces to separate its components.
37101
5f3bebba
JB
37102Here are the currently defined query and set packets:
37103
b8ff78ce 37104@table @samp
c906108c 37105
d1feda86 37106@item QAgent:1
af4238e5 37107@itemx QAgent:0
d1feda86
YQ
37108Turn on or off the agent as a helper to perform some debugging operations
37109delegated from @value{GDBN} (@pxref{Control Agent}).
37110
d914c394
SS
37111@item QAllow:@var{op}:@var{val}@dots{}
37112@cindex @samp{QAllow} packet
37113Specify which operations @value{GDBN} expects to request of the
37114target, as a semicolon-separated list of operation name and value
37115pairs. Possible values for @var{op} include @samp{WriteReg},
37116@samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
37117@samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
37118indicating that @value{GDBN} will not request the operation, or 1,
37119indicating that it may. (The target can then use this to set up its
37120own internals optimally, for instance if the debugger never expects to
37121insert breakpoints, it may not need to install its own trap handler.)
37122
b8ff78ce 37123@item qC
9c16f35a 37124@cindex current thread, remote request
b8ff78ce 37125@cindex @samp{qC} packet
b90a069a 37126Return the current thread ID.
ee2d5c50
AC
37127
37128Reply:
37129@table @samp
b90a069a
SL
37130@item QC @var{thread-id}
37131Where @var{thread-id} is a thread ID as documented in
37132@ref{thread-id syntax}.
b8ff78ce 37133@item @r{(anything else)}
b90a069a 37134Any other reply implies the old thread ID.
ee2d5c50
AC
37135@end table
37136
b8ff78ce 37137@item qCRC:@var{addr},@var{length}
ff2587ec 37138@cindex CRC of memory block, remote request
b8ff78ce 37139@cindex @samp{qCRC} packet
936d2992 37140@anchor{qCRC packet}
99e008fe
EZ
37141Compute the CRC checksum of a block of memory using CRC-32 defined in
37142IEEE 802.3. The CRC is computed byte at a time, taking the most
37143significant bit of each byte first. The initial pattern code
37144@code{0xffffffff} is used to ensure leading zeros affect the CRC.
37145
37146@emph{Note:} This is the same CRC used in validating separate debug
37147files (@pxref{Separate Debug Files, , Debugging Information in Separate
37148Files}). However the algorithm is slightly different. When validating
37149separate debug files, the CRC is computed taking the @emph{least}
37150significant bit of each byte first, and the final result is inverted to
37151detect trailing zeros.
37152
ff2587ec
WZ
37153Reply:
37154@table @samp
b8ff78ce 37155@item E @var{NN}
ff2587ec 37156An error (such as memory fault)
b8ff78ce
JB
37157@item C @var{crc32}
37158The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
37159@end table
37160
03583c20
UW
37161@item QDisableRandomization:@var{value}
37162@cindex disable address space randomization, remote request
37163@cindex @samp{QDisableRandomization} packet
37164Some target operating systems will randomize the virtual address space
37165of the inferior process as a security feature, but provide a feature
37166to disable such randomization, e.g.@: to allow for a more deterministic
37167debugging experience. On such systems, this packet with a @var{value}
37168of 1 directs the target to disable address space randomization for
37169processes subsequently started via @samp{vRun} packets, while a packet
37170with a @var{value} of 0 tells the target to enable address space
37171randomization.
37172
37173This packet is only available in extended mode (@pxref{extended mode}).
37174
37175Reply:
37176@table @samp
37177@item OK
37178The request succeeded.
37179
37180@item E @var{nn}
697aa1b7 37181An error occurred. The error number @var{nn} is given as hex digits.
03583c20 37182
d57350ea 37183@item @w{}
03583c20
UW
37184An empty reply indicates that @samp{QDisableRandomization} is not supported
37185by the stub.
37186@end table
37187
37188This packet is not probed by default; the remote stub must request it,
37189by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37190This should only be done on targets that actually support disabling
37191address space randomization.
37192
aefd8b33
SDJ
37193@item QStartupWithShell:@var{value}
37194@cindex startup with shell, remote request
37195@cindex @samp{QStartupWithShell} packet
37196On UNIX-like targets, it is possible to start the inferior using a
37197shell program. This is the default behavior on both @value{GDBN} and
37198@command{gdbserver} (@pxref{set startup-with-shell}). This packet is
37199used to inform @command{gdbserver} whether it should start the
37200inferior using a shell or not.
37201
37202If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
37203to start the inferior. If @var{value} is @samp{1},
37204@command{gdbserver} will use a shell to start the inferior. All other
37205values are considered an error.
37206
37207This packet is only available in extended mode (@pxref{extended
37208mode}).
37209
37210Reply:
37211@table @samp
37212@item OK
37213The request succeeded.
37214
37215@item E @var{nn}
37216An error occurred. The error number @var{nn} is given as hex digits.
37217@end table
37218
37219This packet is not probed by default; the remote stub must request it,
37220by supplying an appropriate @samp{qSupported} response
37221(@pxref{qSupported}). This should only be done on targets that
37222actually support starting the inferior using a shell.
37223
37224Use of this packet is controlled by the @code{set startup-with-shell}
37225command; @pxref{set startup-with-shell}.
37226
0a2dde4a
SDJ
37227@item QEnvironmentHexEncoded:@var{hex-value}
37228@anchor{QEnvironmentHexEncoded}
37229@cindex set environment variable, remote request
37230@cindex @samp{QEnvironmentHexEncoded} packet
37231On UNIX-like targets, it is possible to set environment variables that
37232will be passed to the inferior during the startup process. This
37233packet is used to inform @command{gdbserver} of an environment
37234variable that has been defined by the user on @value{GDBN} (@pxref{set
37235environment}).
37236
37237The packet is composed by @var{hex-value}, an hex encoded
37238representation of the @var{name=value} format representing an
37239environment variable. The name of the environment variable is
37240represented by @var{name}, and the value to be assigned to the
37241environment variable is represented by @var{value}. If the variable
37242has no value (i.e., the value is @code{null}), then @var{value} will
37243not be present.
37244
37245This packet is only available in extended mode (@pxref{extended
37246mode}).
37247
37248Reply:
37249@table @samp
37250@item OK
37251The request succeeded.
37252@end table
37253
37254This packet is not probed by default; the remote stub must request it,
37255by supplying an appropriate @samp{qSupported} response
37256(@pxref{qSupported}). This should only be done on targets that
37257actually support passing environment variables to the starting
37258inferior.
37259
37260This packet is related to the @code{set environment} command;
37261@pxref{set environment}.
37262
37263@item QEnvironmentUnset:@var{hex-value}
37264@anchor{QEnvironmentUnset}
37265@cindex unset environment variable, remote request
37266@cindex @samp{QEnvironmentUnset} packet
37267On UNIX-like targets, it is possible to unset environment variables
37268before starting the inferior in the remote target. This packet is
37269used to inform @command{gdbserver} of an environment variable that has
37270been unset by the user on @value{GDBN} (@pxref{unset environment}).
37271
37272The packet is composed by @var{hex-value}, an hex encoded
37273representation of the name of the environment variable to be unset.
37274
37275This packet is only available in extended mode (@pxref{extended
37276mode}).
37277
37278Reply:
37279@table @samp
37280@item OK
37281The request succeeded.
37282@end table
37283
37284This packet is not probed by default; the remote stub must request it,
37285by supplying an appropriate @samp{qSupported} response
37286(@pxref{qSupported}). This should only be done on targets that
37287actually support passing environment variables to the starting
37288inferior.
37289
37290This packet is related to the @code{unset environment} command;
37291@pxref{unset environment}.
37292
37293@item QEnvironmentReset
37294@anchor{QEnvironmentReset}
37295@cindex reset environment, remote request
37296@cindex @samp{QEnvironmentReset} packet
37297On UNIX-like targets, this packet is used to reset the state of
37298environment variables in the remote target before starting the
37299inferior. In this context, reset means unsetting all environment
37300variables that were previously set by the user (i.e., were not
37301initially present in the environment). It is sent to
37302@command{gdbserver} before the @samp{QEnvironmentHexEncoded}
37303(@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
37304(@pxref{QEnvironmentUnset}) packets.
37305
37306This packet is only available in extended mode (@pxref{extended
37307mode}).
37308
37309Reply:
37310@table @samp
37311@item OK
37312The request succeeded.
37313@end table
37314
37315This packet is not probed by default; the remote stub must request it,
37316by supplying an appropriate @samp{qSupported} response
37317(@pxref{qSupported}). This should only be done on targets that
37318actually support passing environment variables to the starting
37319inferior.
37320
bc3b087d
SDJ
37321@item QSetWorkingDir:@r{[}@var{directory}@r{]}
37322@anchor{QSetWorkingDir packet}
37323@cindex set working directory, remote request
37324@cindex @samp{QSetWorkingDir} packet
37325This packet is used to inform the remote server of the intended
37326current working directory for programs that are going to be executed.
37327
37328The packet is composed by @var{directory}, an hex encoded
37329representation of the directory that the remote inferior will use as
37330its current working directory. If @var{directory} is an empty string,
37331the remote server should reset the inferior's current working
37332directory to its original, empty value.
37333
37334This packet is only available in extended mode (@pxref{extended
37335mode}).
37336
37337Reply:
37338@table @samp
37339@item OK
37340The request succeeded.
37341@end table
37342
b8ff78ce
JB
37343@item qfThreadInfo
37344@itemx qsThreadInfo
9c16f35a 37345@cindex list active threads, remote request
b8ff78ce
JB
37346@cindex @samp{qfThreadInfo} packet
37347@cindex @samp{qsThreadInfo} packet
b90a069a 37348Obtain a list of all active thread IDs from the target (OS). Since there
8e04817f
AC
37349may be too many active threads to fit into one reply packet, this query
37350works iteratively: it may require more than one query/reply sequence to
37351obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
37352be the @samp{qfThreadInfo} query; subsequent queries in the
37353sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 37354
b8ff78ce 37355NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
37356
37357Reply:
37358@table @samp
b90a069a
SL
37359@item m @var{thread-id}
37360A single thread ID
37361@item m @var{thread-id},@var{thread-id}@dots{}
37362a comma-separated list of thread IDs
b8ff78ce
JB
37363@item l
37364(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
37365@end table
37366
37367In response to each query, the target will reply with a list of one or
b90a069a 37368more thread IDs, separated by commas.
e1aac25b 37369@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce 37370ids (using the @samp{qs} form of the query), until the target responds
501994c0 37371with @samp{l} (lower-case ell, for @dfn{last}).
b90a069a
SL
37372Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
37373fields.
c906108c 37374
8dfcab11
DT
37375@emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
37376initial connection with the remote target, and the very first thread ID
37377mentioned in the reply will be stopped by @value{GDBN} in a subsequent
37378message. Therefore, the stub should ensure that the first thread ID in
37379the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
37380
b8ff78ce 37381@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 37382@cindex get thread-local storage address, remote request
b8ff78ce 37383@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
37384Fetch the address associated with thread local storage specified
37385by @var{thread-id}, @var{offset}, and @var{lm}.
37386
b90a069a
SL
37387@var{thread-id} is the thread ID associated with the
37388thread for which to fetch the TLS address. @xref{thread-id syntax}.
ff2587ec
WZ
37389
37390@var{offset} is the (big endian, hex encoded) offset associated with the
37391thread local variable. (This offset is obtained from the debug
37392information associated with the variable.)
37393
db2e3e2e 37394@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
7a9dd1b2 37395load module associated with the thread local storage. For example,
ff2587ec
WZ
37396a @sc{gnu}/Linux system will pass the link map address of the shared
37397object associated with the thread local storage under consideration.
37398Other operating environments may choose to represent the load module
37399differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
37400
37401Reply:
b8ff78ce
JB
37402@table @samp
37403@item @var{XX}@dots{}
ff2587ec
WZ
37404Hex encoded (big endian) bytes representing the address of the thread
37405local storage requested.
37406
b8ff78ce 37407@item E @var{nn}
697aa1b7 37408An error occurred. The error number @var{nn} is given as hex digits.
ff2587ec 37409
d57350ea 37410@item @w{}
b8ff78ce 37411An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
37412@end table
37413
711e434b
PM
37414@item qGetTIBAddr:@var{thread-id}
37415@cindex get thread information block address
37416@cindex @samp{qGetTIBAddr} packet
37417Fetch address of the Windows OS specific Thread Information Block.
37418
37419@var{thread-id} is the thread ID associated with the thread.
37420
37421Reply:
37422@table @samp
37423@item @var{XX}@dots{}
37424Hex encoded (big endian) bytes representing the linear address of the
37425thread information block.
37426
37427@item E @var{nn}
37428An error occured. This means that either the thread was not found, or the
37429address could not be retrieved.
37430
d57350ea 37431@item @w{}
711e434b
PM
37432An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
37433@end table
37434
b8ff78ce 37435@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
37436Obtain thread information from RTOS. Where: @var{startflag} (one hex
37437digit) is one to indicate the first query and zero to indicate a
37438subsequent query; @var{threadcount} (two hex digits) is the maximum
37439number of threads the response packet can contain; and @var{nextthread}
37440(eight hex digits), for subsequent queries (@var{startflag} is zero), is
37441returned in the response as @var{argthread}.
ee2d5c50 37442
b8ff78ce 37443Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
37444
37445Reply:
37446@table @samp
b8ff78ce 37447@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
37448Where: @var{count} (two hex digits) is the number of threads being
37449returned; @var{done} (one hex digit) is zero to indicate more threads
37450and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 37451digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
697aa1b7
EZ
37452is a sequence of thread IDs, @var{threadid} (eight hex
37453digits), from the target. See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 37454@end table
c906108c 37455
b8ff78ce 37456@item qOffsets
9c16f35a 37457@cindex section offsets, remote request
b8ff78ce 37458@cindex @samp{qOffsets} packet
31d99776
DJ
37459Get section offsets that the target used when relocating the downloaded
37460image.
c906108c 37461
ee2d5c50
AC
37462Reply:
37463@table @samp
31d99776
DJ
37464@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
37465Relocate the @code{Text} section by @var{xxx} from its original address.
37466Relocate the @code{Data} section by @var{yyy} from its original address.
37467If the object file format provides segment information (e.g.@: @sc{elf}
37468@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
37469segments by the supplied offsets.
37470
37471@emph{Note: while a @code{Bss} offset may be included in the response,
37472@value{GDBN} ignores this and instead applies the @code{Data} offset
37473to the @code{Bss} section.}
37474
37475@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
37476Relocate the first segment of the object file, which conventionally
37477contains program code, to a starting address of @var{xxx}. If
37478@samp{DataSeg} is specified, relocate the second segment, which
37479conventionally contains modifiable data, to a starting address of
37480@var{yyy}. @value{GDBN} will report an error if the object file
37481does not contain segment information, or does not contain at least
37482as many segments as mentioned in the reply. Extra segments are
37483kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
37484@end table
37485
b90a069a 37486@item qP @var{mode} @var{thread-id}
9c16f35a 37487@cindex thread information, remote request
b8ff78ce 37488@cindex @samp{qP} packet
b90a069a
SL
37489Returns information on @var{thread-id}. Where: @var{mode} is a hex
37490encoded 32 bit mode; @var{thread-id} is a thread ID
37491(@pxref{thread-id syntax}).
ee2d5c50 37492
aa56d27a
JB
37493Don't use this packet; use the @samp{qThreadExtraInfo} query instead
37494(see below).
37495
b8ff78ce 37496Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 37497
8b23ecc4 37498@item QNonStop:1
687e43a4 37499@itemx QNonStop:0
8b23ecc4
SL
37500@cindex non-stop mode, remote request
37501@cindex @samp{QNonStop} packet
37502@anchor{QNonStop}
37503Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
37504@xref{Remote Non-Stop}, for more information.
37505
37506Reply:
37507@table @samp
37508@item OK
37509The request succeeded.
37510
37511@item E @var{nn}
697aa1b7 37512An error occurred. The error number @var{nn} is given as hex digits.
8b23ecc4 37513
d57350ea 37514@item @w{}
8b23ecc4
SL
37515An empty reply indicates that @samp{QNonStop} is not supported by
37516the stub.
37517@end table
37518
37519This packet is not probed by default; the remote stub must request it,
37520by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37521Use of this packet is controlled by the @code{set non-stop} command;
37522@pxref{Non-Stop Mode}.
37523
82075af2
JS
37524@item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
37525@itemx QCatchSyscalls:0
37526@cindex catch syscalls from inferior, remote request
37527@cindex @samp{QCatchSyscalls} packet
37528@anchor{QCatchSyscalls}
37529Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
37530catching syscalls from the inferior process.
37531
37532For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
37533in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
37534is listed, every system call should be reported.
37535
37536Note that if a syscall not in the list is reported, @value{GDBN} will
37537still filter the event according to its own list from all corresponding
37538@code{catch syscall} commands. However, it is more efficient to only
37539report the requested syscalls.
37540
37541Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
37542@samp{QCatchSyscalls:1} list is completely replaced by the new list.
37543
37544If the inferior process execs, the state of @samp{QCatchSyscalls} is
37545kept for the new process too. On targets where exec may affect syscall
37546numbers, for example with exec between 32 and 64-bit processes, the
37547client should send a new packet with the new syscall list.
37548
37549Reply:
37550@table @samp
37551@item OK
37552The request succeeded.
37553
37554@item E @var{nn}
37555An error occurred. @var{nn} are hex digits.
37556
37557@item @w{}
37558An empty reply indicates that @samp{QCatchSyscalls} is not supported by
37559the stub.
37560@end table
37561
37562Use of this packet is controlled by the @code{set remote catch-syscalls}
37563command (@pxref{Remote Configuration, set remote catch-syscalls}).
37564This packet is not probed by default; the remote stub must request it,
37565by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37566
89be2091
DJ
37567@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
37568@cindex pass signals to inferior, remote request
37569@cindex @samp{QPassSignals} packet
23181151 37570@anchor{QPassSignals}
89be2091
DJ
37571Each listed @var{signal} should be passed directly to the inferior process.
37572Signals are numbered identically to continue packets and stop replies
37573(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
37574strictly greater than the previous item. These signals do not need to stop
37575the inferior, or be reported to @value{GDBN}. All other signals should be
37576reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
37577combine; any earlier @samp{QPassSignals} list is completely replaced by the
37578new list. This packet improves performance when using @samp{handle
37579@var{signal} nostop noprint pass}.
37580
37581Reply:
37582@table @samp
37583@item OK
37584The request succeeded.
37585
37586@item E @var{nn}
697aa1b7 37587An error occurred. The error number @var{nn} is given as hex digits.
89be2091 37588
d57350ea 37589@item @w{}
89be2091
DJ
37590An empty reply indicates that @samp{QPassSignals} is not supported by
37591the stub.
37592@end table
37593
37594Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 37595command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
37596This packet is not probed by default; the remote stub must request it,
37597by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37598
9b224c5e
PA
37599@item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
37600@cindex signals the inferior may see, remote request
37601@cindex @samp{QProgramSignals} packet
37602@anchor{QProgramSignals}
37603Each listed @var{signal} may be delivered to the inferior process.
37604Others should be silently discarded.
37605
37606In some cases, the remote stub may need to decide whether to deliver a
37607signal to the program or not without @value{GDBN} involvement. One
37608example of that is while detaching --- the program's threads may have
37609stopped for signals that haven't yet had a chance of being reported to
37610@value{GDBN}, and so the remote stub can use the signal list specified
37611by this packet to know whether to deliver or ignore those pending
37612signals.
37613
37614This does not influence whether to deliver a signal as requested by a
37615resumption packet (@pxref{vCont packet}).
37616
37617Signals are numbered identically to continue packets and stop replies
37618(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
37619strictly greater than the previous item. Multiple
37620@samp{QProgramSignals} packets do not combine; any earlier
37621@samp{QProgramSignals} list is completely replaced by the new list.
37622
37623Reply:
37624@table @samp
37625@item OK
37626The request succeeded.
37627
37628@item E @var{nn}
697aa1b7 37629An error occurred. The error number @var{nn} is given as hex digits.
9b224c5e 37630
d57350ea 37631@item @w{}
9b224c5e
PA
37632An empty reply indicates that @samp{QProgramSignals} is not supported
37633by the stub.
37634@end table
37635
37636Use of this packet is controlled by the @code{set remote program-signals}
37637command (@pxref{Remote Configuration, set remote program-signals}).
37638This packet is not probed by default; the remote stub must request it,
37639by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37640
65706a29
PA
37641@anchor{QThreadEvents}
37642@item QThreadEvents:1
37643@itemx QThreadEvents:0
37644@cindex thread create/exit events, remote request
37645@cindex @samp{QThreadEvents} packet
37646
37647Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
37648reporting of thread create and exit events. @xref{thread create
37649event}, for the reply specifications. For example, this is used in
37650non-stop mode when @value{GDBN} stops a set of threads and
37651synchronously waits for the their corresponding stop replies. Without
37652exit events, if one of the threads exits, @value{GDBN} would hang
37653forever not knowing that it should no longer expect a stop for that
37654same thread. @value{GDBN} does not enable this feature unless the
37655stub reports that it supports it by including @samp{QThreadEvents+} in
37656its @samp{qSupported} reply.
37657
37658Reply:
37659@table @samp
37660@item OK
37661The request succeeded.
37662
37663@item E @var{nn}
37664An error occurred. The error number @var{nn} is given as hex digits.
37665
37666@item @w{}
37667An empty reply indicates that @samp{QThreadEvents} is not supported by
37668the stub.
37669@end table
37670
37671Use of this packet is controlled by the @code{set remote thread-events}
37672command (@pxref{Remote Configuration, set remote thread-events}).
37673
b8ff78ce 37674@item qRcmd,@var{command}
ff2587ec 37675@cindex execute remote command, remote request
b8ff78ce 37676@cindex @samp{qRcmd} packet
ff2587ec 37677@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
37678execution. Invalid commands should be reported using the output
37679string. Before the final result packet, the target may also respond
37680with a number of intermediate @samp{O@var{output}} console output
37681packets. @emph{Implementors should note that providing access to a
37682stubs's interpreter may have security implications}.
fa93a9d8 37683
ff2587ec
WZ
37684Reply:
37685@table @samp
37686@item OK
37687A command response with no output.
37688@item @var{OUTPUT}
37689A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 37690@item E @var{NN}
ff2587ec 37691Indicate a badly formed request.
d57350ea 37692@item @w{}
b8ff78ce 37693An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 37694@end table
fa93a9d8 37695
aa56d27a
JB
37696(Note that the @code{qRcmd} packet's name is separated from the
37697command by a @samp{,}, not a @samp{:}, contrary to the naming
37698conventions above. Please don't use this packet as a model for new
37699packets.)
37700
08388c79
DE
37701@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
37702@cindex searching memory, in remote debugging
5c4808ca 37703@ifnotinfo
08388c79 37704@cindex @samp{qSearch:memory} packet
5c4808ca
EZ
37705@end ifnotinfo
37706@cindex @samp{qSearch memory} packet
08388c79
DE
37707@anchor{qSearch memory}
37708Search @var{length} bytes at @var{address} for @var{search-pattern}.
697aa1b7
EZ
37709Both @var{address} and @var{length} are encoded in hex;
37710@var{search-pattern} is a sequence of bytes, also hex encoded.
08388c79
DE
37711
37712Reply:
37713@table @samp
37714@item 0
37715The pattern was not found.
37716@item 1,address
37717The pattern was found at @var{address}.
37718@item E @var{NN}
37719A badly formed request or an error was encountered while searching memory.
d57350ea 37720@item @w{}
08388c79
DE
37721An empty reply indicates that @samp{qSearch:memory} is not recognized.
37722@end table
37723
a6f3e723
SL
37724@item QStartNoAckMode
37725@cindex @samp{QStartNoAckMode} packet
37726@anchor{QStartNoAckMode}
37727Request that the remote stub disable the normal @samp{+}/@samp{-}
37728protocol acknowledgments (@pxref{Packet Acknowledgment}).
37729
37730Reply:
37731@table @samp
37732@item OK
37733The stub has switched to no-acknowledgment mode.
37734@value{GDBN} acknowledges this reponse,
37735but neither the stub nor @value{GDBN} shall send or expect further
37736@samp{+}/@samp{-} acknowledgments in the current connection.
d57350ea 37737@item @w{}
a6f3e723
SL
37738An empty reply indicates that the stub does not support no-acknowledgment mode.
37739@end table
37740
be2a5f71
DJ
37741@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
37742@cindex supported packets, remote query
37743@cindex features of the remote protocol
37744@cindex @samp{qSupported} packet
0876f84a 37745@anchor{qSupported}
be2a5f71
DJ
37746Tell the remote stub about features supported by @value{GDBN}, and
37747query the stub for features it supports. This packet allows
37748@value{GDBN} and the remote stub to take advantage of each others'
37749features. @samp{qSupported} also consolidates multiple feature probes
37750at startup, to improve @value{GDBN} performance---a single larger
37751packet performs better than multiple smaller probe packets on
37752high-latency links. Some features may enable behavior which must not
37753be on by default, e.g.@: because it would confuse older clients or
37754stubs. Other features may describe packets which could be
37755automatically probed for, but are not. These features must be
37756reported before @value{GDBN} will use them. This ``default
37757unsupported'' behavior is not appropriate for all packets, but it
37758helps to keep the initial connection time under control with new
37759versions of @value{GDBN} which support increasing numbers of packets.
37760
37761Reply:
37762@table @samp
37763@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
37764The stub supports or does not support each returned @var{stubfeature},
37765depending on the form of each @var{stubfeature} (see below for the
37766possible forms).
d57350ea 37767@item @w{}
be2a5f71
DJ
37768An empty reply indicates that @samp{qSupported} is not recognized,
37769or that no features needed to be reported to @value{GDBN}.
37770@end table
37771
37772The allowed forms for each feature (either a @var{gdbfeature} in the
37773@samp{qSupported} packet, or a @var{stubfeature} in the response)
37774are:
37775
37776@table @samp
37777@item @var{name}=@var{value}
37778The remote protocol feature @var{name} is supported, and associated
37779with the specified @var{value}. The format of @var{value} depends
37780on the feature, but it must not include a semicolon.
37781@item @var{name}+
37782The remote protocol feature @var{name} is supported, and does not
37783need an associated value.
37784@item @var{name}-
37785The remote protocol feature @var{name} is not supported.
37786@item @var{name}?
37787The remote protocol feature @var{name} may be supported, and
37788@value{GDBN} should auto-detect support in some other way when it is
37789needed. This form will not be used for @var{gdbfeature} notifications,
37790but may be used for @var{stubfeature} responses.
37791@end table
37792
37793Whenever the stub receives a @samp{qSupported} request, the
37794supplied set of @value{GDBN} features should override any previous
37795request. This allows @value{GDBN} to put the stub in a known
37796state, even if the stub had previously been communicating with
37797a different version of @value{GDBN}.
37798
b90a069a
SL
37799The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
37800are defined:
37801
37802@table @samp
37803@item multiprocess
37804This feature indicates whether @value{GDBN} supports multiprocess
37805extensions to the remote protocol. @value{GDBN} does not use such
37806extensions unless the stub also reports that it supports them by
37807including @samp{multiprocess+} in its @samp{qSupported} reply.
37808@xref{multiprocess extensions}, for details.
c8d5aac9
L
37809
37810@item xmlRegisters
37811This feature indicates that @value{GDBN} supports the XML target
37812description. If the stub sees @samp{xmlRegisters=} with target
37813specific strings separated by a comma, it will report register
37814description.
dde08ee1
PA
37815
37816@item qRelocInsn
37817This feature indicates whether @value{GDBN} supports the
37818@samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
37819instruction reply packet}).
f7e6eed5
PA
37820
37821@item swbreak
37822This feature indicates whether @value{GDBN} supports the swbreak stop
37823reason in stop replies. @xref{swbreak stop reason}, for details.
37824
37825@item hwbreak
37826This feature indicates whether @value{GDBN} supports the hwbreak stop
37827reason in stop replies. @xref{swbreak stop reason}, for details.
0d71eef5
DB
37828
37829@item fork-events
37830This feature indicates whether @value{GDBN} supports fork event
37831extensions to the remote protocol. @value{GDBN} does not use such
37832extensions unless the stub also reports that it supports them by
37833including @samp{fork-events+} in its @samp{qSupported} reply.
37834
37835@item vfork-events
37836This feature indicates whether @value{GDBN} supports vfork event
37837extensions to the remote protocol. @value{GDBN} does not use such
37838extensions unless the stub also reports that it supports them by
37839including @samp{vfork-events+} in its @samp{qSupported} reply.
b459a59b
DB
37840
37841@item exec-events
37842This feature indicates whether @value{GDBN} supports exec event
37843extensions to the remote protocol. @value{GDBN} does not use such
37844extensions unless the stub also reports that it supports them by
37845including @samp{exec-events+} in its @samp{qSupported} reply.
750ce8d1
YQ
37846
37847@item vContSupported
37848This feature indicates whether @value{GDBN} wants to know the
37849supported actions in the reply to @samp{vCont?} packet.
b90a069a
SL
37850@end table
37851
37852Stubs should ignore any unknown values for
be2a5f71
DJ
37853@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
37854packet supports receiving packets of unlimited length (earlier
b90a069a 37855versions of @value{GDBN} may reject overly long responses). Additional values
be2a5f71
DJ
37856for @var{gdbfeature} may be defined in the future to let the stub take
37857advantage of new features in @value{GDBN}, e.g.@: incompatible
b90a069a
SL
37858improvements in the remote protocol---the @samp{multiprocess} feature is
37859an example of such a feature. The stub's reply should be independent
be2a5f71
DJ
37860of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
37861describes all the features it supports, and then the stub replies with
37862all the features it supports.
37863
37864Similarly, @value{GDBN} will silently ignore unrecognized stub feature
37865responses, as long as each response uses one of the standard forms.
37866
37867Some features are flags. A stub which supports a flag feature
37868should respond with a @samp{+} form response. Other features
37869require values, and the stub should respond with an @samp{=}
37870form response.
37871
37872Each feature has a default value, which @value{GDBN} will use if
37873@samp{qSupported} is not available or if the feature is not mentioned
37874in the @samp{qSupported} response. The default values are fixed; a
37875stub is free to omit any feature responses that match the defaults.
37876
37877Not all features can be probed, but for those which can, the probing
37878mechanism is useful: in some cases, a stub's internal
37879architecture may not allow the protocol layer to know some information
37880about the underlying target in advance. This is especially common in
37881stubs which may be configured for multiple targets.
37882
37883These are the currently defined stub features and their properties:
37884
cfa9d6d9 37885@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
37886@c NOTE: The first row should be @headitem, but we do not yet require
37887@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 37888@item Feature Name
be2a5f71
DJ
37889@tab Value Required
37890@tab Default
37891@tab Probe Allowed
37892
37893@item @samp{PacketSize}
37894@tab Yes
37895@tab @samp{-}
37896@tab No
37897
0876f84a
DJ
37898@item @samp{qXfer:auxv:read}
37899@tab No
37900@tab @samp{-}
37901@tab Yes
37902
2ae8c8e7
MM
37903@item @samp{qXfer:btrace:read}
37904@tab No
37905@tab @samp{-}
37906@tab Yes
37907
f4abbc16
MM
37908@item @samp{qXfer:btrace-conf:read}
37909@tab No
37910@tab @samp{-}
37911@tab Yes
37912
c78fa86a
GB
37913@item @samp{qXfer:exec-file:read}
37914@tab No
37915@tab @samp{-}
37916@tab Yes
37917
23181151
DJ
37918@item @samp{qXfer:features:read}
37919@tab No
37920@tab @samp{-}
37921@tab Yes
37922
cfa9d6d9
DJ
37923@item @samp{qXfer:libraries:read}
37924@tab No
37925@tab @samp{-}
37926@tab Yes
37927
85dc5a12
GB
37928@item @samp{qXfer:libraries-svr4:read}
37929@tab No
37930@tab @samp{-}
37931@tab Yes
37932
37933@item @samp{augmented-libraries-svr4-read}
37934@tab No
37935@tab @samp{-}
37936@tab No
37937
68437a39
DJ
37938@item @samp{qXfer:memory-map:read}
37939@tab No
37940@tab @samp{-}
37941@tab Yes
37942
0fb4aa4b
PA
37943@item @samp{qXfer:sdata:read}
37944@tab No
37945@tab @samp{-}
37946@tab Yes
37947
0e7f50da
UW
37948@item @samp{qXfer:spu:read}
37949@tab No
37950@tab @samp{-}
37951@tab Yes
37952
37953@item @samp{qXfer:spu:write}
37954@tab No
37955@tab @samp{-}
37956@tab Yes
37957
4aa995e1
PA
37958@item @samp{qXfer:siginfo:read}
37959@tab No
37960@tab @samp{-}
37961@tab Yes
37962
37963@item @samp{qXfer:siginfo:write}
37964@tab No
37965@tab @samp{-}
37966@tab Yes
37967
dc146f7c
VP
37968@item @samp{qXfer:threads:read}
37969@tab No
37970@tab @samp{-}
37971@tab Yes
37972
b3b9301e
PA
37973@item @samp{qXfer:traceframe-info:read}
37974@tab No
37975@tab @samp{-}
37976@tab Yes
37977
169081d0
TG
37978@item @samp{qXfer:uib:read}
37979@tab No
37980@tab @samp{-}
37981@tab Yes
37982
78d85199
YQ
37983@item @samp{qXfer:fdpic:read}
37984@tab No
37985@tab @samp{-}
37986@tab Yes
dc146f7c 37987
2ae8c8e7
MM
37988@item @samp{Qbtrace:off}
37989@tab Yes
37990@tab @samp{-}
37991@tab Yes
37992
37993@item @samp{Qbtrace:bts}
37994@tab Yes
37995@tab @samp{-}
37996@tab Yes
37997
b20a6524
MM
37998@item @samp{Qbtrace:pt}
37999@tab Yes
38000@tab @samp{-}
38001@tab Yes
38002
d33501a5
MM
38003@item @samp{Qbtrace-conf:bts:size}
38004@tab Yes
38005@tab @samp{-}
38006@tab Yes
38007
b20a6524
MM
38008@item @samp{Qbtrace-conf:pt:size}
38009@tab Yes
38010@tab @samp{-}
38011@tab Yes
38012
8b23ecc4
SL
38013@item @samp{QNonStop}
38014@tab No
38015@tab @samp{-}
38016@tab Yes
38017
82075af2
JS
38018@item @samp{QCatchSyscalls}
38019@tab No
38020@tab @samp{-}
38021@tab Yes
38022
89be2091
DJ
38023@item @samp{QPassSignals}
38024@tab No
38025@tab @samp{-}
38026@tab Yes
38027
a6f3e723
SL
38028@item @samp{QStartNoAckMode}
38029@tab No
38030@tab @samp{-}
38031@tab Yes
38032
b90a069a
SL
38033@item @samp{multiprocess}
38034@tab No
38035@tab @samp{-}
38036@tab No
38037
83364271
LM
38038@item @samp{ConditionalBreakpoints}
38039@tab No
38040@tab @samp{-}
38041@tab No
38042
782b2b07
SS
38043@item @samp{ConditionalTracepoints}
38044@tab No
38045@tab @samp{-}
38046@tab No
38047
0d772ac9
MS
38048@item @samp{ReverseContinue}
38049@tab No
2f8132f3 38050@tab @samp{-}
0d772ac9
MS
38051@tab No
38052
38053@item @samp{ReverseStep}
38054@tab No
2f8132f3 38055@tab @samp{-}
0d772ac9
MS
38056@tab No
38057
409873ef
SS
38058@item @samp{TracepointSource}
38059@tab No
38060@tab @samp{-}
38061@tab No
38062
d1feda86
YQ
38063@item @samp{QAgent}
38064@tab No
38065@tab @samp{-}
38066@tab No
38067
d914c394
SS
38068@item @samp{QAllow}
38069@tab No
38070@tab @samp{-}
38071@tab No
38072
03583c20
UW
38073@item @samp{QDisableRandomization}
38074@tab No
38075@tab @samp{-}
38076@tab No
38077
d248b706
KY
38078@item @samp{EnableDisableTracepoints}
38079@tab No
38080@tab @samp{-}
38081@tab No
38082
f6f899bf
HAQ
38083@item @samp{QTBuffer:size}
38084@tab No
38085@tab @samp{-}
38086@tab No
38087
3065dfb6
SS
38088@item @samp{tracenz}
38089@tab No
38090@tab @samp{-}
38091@tab No
38092
d3ce09f5
SS
38093@item @samp{BreakpointCommands}
38094@tab No
38095@tab @samp{-}
38096@tab No
38097
f7e6eed5
PA
38098@item @samp{swbreak}
38099@tab No
38100@tab @samp{-}
38101@tab No
38102
38103@item @samp{hwbreak}
38104@tab No
38105@tab @samp{-}
38106@tab No
38107
0d71eef5
DB
38108@item @samp{fork-events}
38109@tab No
38110@tab @samp{-}
38111@tab No
38112
38113@item @samp{vfork-events}
38114@tab No
38115@tab @samp{-}
38116@tab No
38117
b459a59b
DB
38118@item @samp{exec-events}
38119@tab No
38120@tab @samp{-}
38121@tab No
38122
65706a29
PA
38123@item @samp{QThreadEvents}
38124@tab No
38125@tab @samp{-}
38126@tab No
38127
f2faf941
PA
38128@item @samp{no-resumed}
38129@tab No
38130@tab @samp{-}
38131@tab No
38132
be2a5f71
DJ
38133@end multitable
38134
38135These are the currently defined stub features, in more detail:
38136
38137@table @samp
38138@cindex packet size, remote protocol
38139@item PacketSize=@var{bytes}
38140The remote stub can accept packets up to at least @var{bytes} in
38141length. @value{GDBN} will send packets up to this size for bulk
38142transfers, and will never send larger packets. This is a limit on the
38143data characters in the packet, including the frame and checksum.
38144There is no trailing NUL byte in a remote protocol packet; if the stub
38145stores packets in a NUL-terminated format, it should allow an extra
38146byte in its buffer for the NUL. If this stub feature is not supported,
38147@value{GDBN} guesses based on the size of the @samp{g} packet response.
38148
0876f84a
DJ
38149@item qXfer:auxv:read
38150The remote stub understands the @samp{qXfer:auxv:read} packet
38151(@pxref{qXfer auxiliary vector read}).
38152
2ae8c8e7
MM
38153@item qXfer:btrace:read
38154The remote stub understands the @samp{qXfer:btrace:read}
38155packet (@pxref{qXfer btrace read}).
38156
f4abbc16
MM
38157@item qXfer:btrace-conf:read
38158The remote stub understands the @samp{qXfer:btrace-conf:read}
38159packet (@pxref{qXfer btrace-conf read}).
38160
c78fa86a
GB
38161@item qXfer:exec-file:read
38162The remote stub understands the @samp{qXfer:exec-file:read} packet
38163(@pxref{qXfer executable filename read}).
38164
23181151
DJ
38165@item qXfer:features:read
38166The remote stub understands the @samp{qXfer:features:read} packet
38167(@pxref{qXfer target description read}).
38168
cfa9d6d9
DJ
38169@item qXfer:libraries:read
38170The remote stub understands the @samp{qXfer:libraries:read} packet
38171(@pxref{qXfer library list read}).
38172
2268b414
JK
38173@item qXfer:libraries-svr4:read
38174The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
38175(@pxref{qXfer svr4 library list read}).
38176
85dc5a12
GB
38177@item augmented-libraries-svr4-read
38178The remote stub understands the augmented form of the
38179@samp{qXfer:libraries-svr4:read} packet
38180(@pxref{qXfer svr4 library list read}).
38181
23181151
DJ
38182@item qXfer:memory-map:read
38183The remote stub understands the @samp{qXfer:memory-map:read} packet
38184(@pxref{qXfer memory map read}).
38185
0fb4aa4b
PA
38186@item qXfer:sdata:read
38187The remote stub understands the @samp{qXfer:sdata:read} packet
38188(@pxref{qXfer sdata read}).
38189
0e7f50da
UW
38190@item qXfer:spu:read
38191The remote stub understands the @samp{qXfer:spu:read} packet
38192(@pxref{qXfer spu read}).
38193
38194@item qXfer:spu:write
38195The remote stub understands the @samp{qXfer:spu:write} packet
38196(@pxref{qXfer spu write}).
38197
4aa995e1
PA
38198@item qXfer:siginfo:read
38199The remote stub understands the @samp{qXfer:siginfo:read} packet
38200(@pxref{qXfer siginfo read}).
38201
38202@item qXfer:siginfo:write
38203The remote stub understands the @samp{qXfer:siginfo:write} packet
38204(@pxref{qXfer siginfo write}).
38205
dc146f7c
VP
38206@item qXfer:threads:read
38207The remote stub understands the @samp{qXfer:threads:read} packet
38208(@pxref{qXfer threads read}).
38209
b3b9301e
PA
38210@item qXfer:traceframe-info:read
38211The remote stub understands the @samp{qXfer:traceframe-info:read}
38212packet (@pxref{qXfer traceframe info read}).
38213
169081d0
TG
38214@item qXfer:uib:read
38215The remote stub understands the @samp{qXfer:uib:read}
38216packet (@pxref{qXfer unwind info block}).
38217
78d85199
YQ
38218@item qXfer:fdpic:read
38219The remote stub understands the @samp{qXfer:fdpic:read}
38220packet (@pxref{qXfer fdpic loadmap read}).
38221
8b23ecc4
SL
38222@item QNonStop
38223The remote stub understands the @samp{QNonStop} packet
38224(@pxref{QNonStop}).
38225
82075af2
JS
38226@item QCatchSyscalls
38227The remote stub understands the @samp{QCatchSyscalls} packet
38228(@pxref{QCatchSyscalls}).
38229
23181151
DJ
38230@item QPassSignals
38231The remote stub understands the @samp{QPassSignals} packet
38232(@pxref{QPassSignals}).
38233
a6f3e723
SL
38234@item QStartNoAckMode
38235The remote stub understands the @samp{QStartNoAckMode} packet and
38236prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
38237
b90a069a
SL
38238@item multiprocess
38239@anchor{multiprocess extensions}
38240@cindex multiprocess extensions, in remote protocol
38241The remote stub understands the multiprocess extensions to the remote
38242protocol syntax. The multiprocess extensions affect the syntax of
38243thread IDs in both packets and replies (@pxref{thread-id syntax}), and
38244add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
38245replies. Note that reporting this feature indicates support for the
38246syntactic extensions only, not that the stub necessarily supports
38247debugging of more than one process at a time. The stub must not use
38248multiprocess extensions in packet replies unless @value{GDBN} has also
38249indicated it supports them in its @samp{qSupported} request.
38250
07e059b5
VP
38251@item qXfer:osdata:read
38252The remote stub understands the @samp{qXfer:osdata:read} packet
38253((@pxref{qXfer osdata read}).
38254
83364271
LM
38255@item ConditionalBreakpoints
38256The target accepts and implements evaluation of conditional expressions
38257defined for breakpoints. The target will only report breakpoint triggers
38258when such conditions are true (@pxref{Conditions, ,Break Conditions}).
38259
782b2b07
SS
38260@item ConditionalTracepoints
38261The remote stub accepts and implements conditional expressions defined
38262for tracepoints (@pxref{Tracepoint Conditions}).
38263
0d772ac9
MS
38264@item ReverseContinue
38265The remote stub accepts and implements the reverse continue packet
38266(@pxref{bc}).
38267
38268@item ReverseStep
38269The remote stub accepts and implements the reverse step packet
38270(@pxref{bs}).
38271
409873ef
SS
38272@item TracepointSource
38273The remote stub understands the @samp{QTDPsrc} packet that supplies
38274the source form of tracepoint definitions.
38275
d1feda86
YQ
38276@item QAgent
38277The remote stub understands the @samp{QAgent} packet.
38278
d914c394
SS
38279@item QAllow
38280The remote stub understands the @samp{QAllow} packet.
38281
03583c20
UW
38282@item QDisableRandomization
38283The remote stub understands the @samp{QDisableRandomization} packet.
38284
0fb4aa4b
PA
38285@item StaticTracepoint
38286@cindex static tracepoints, in remote protocol
38287The remote stub supports static tracepoints.
38288
1e4d1764
YQ
38289@item InstallInTrace
38290@anchor{install tracepoint in tracing}
38291The remote stub supports installing tracepoint in tracing.
38292
d248b706
KY
38293@item EnableDisableTracepoints
38294The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
38295@samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
38296to be enabled and disabled while a trace experiment is running.
38297
f6f899bf 38298@item QTBuffer:size
28abe188 38299The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
f6f899bf
HAQ
38300packet that allows to change the size of the trace buffer.
38301
3065dfb6
SS
38302@item tracenz
38303@cindex string tracing, in remote protocol
38304The remote stub supports the @samp{tracenz} bytecode for collecting strings.
38305See @ref{Bytecode Descriptions} for details about the bytecode.
38306
d3ce09f5
SS
38307@item BreakpointCommands
38308@cindex breakpoint commands, in remote protocol
38309The remote stub supports running a breakpoint's command list itself,
38310rather than reporting the hit to @value{GDBN}.
38311
2ae8c8e7
MM
38312@item Qbtrace:off
38313The remote stub understands the @samp{Qbtrace:off} packet.
38314
38315@item Qbtrace:bts
38316The remote stub understands the @samp{Qbtrace:bts} packet.
38317
b20a6524
MM
38318@item Qbtrace:pt
38319The remote stub understands the @samp{Qbtrace:pt} packet.
38320
d33501a5
MM
38321@item Qbtrace-conf:bts:size
38322The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
38323
b20a6524
MM
38324@item Qbtrace-conf:pt:size
38325The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
38326
f7e6eed5
PA
38327@item swbreak
38328The remote stub reports the @samp{swbreak} stop reason for memory
38329breakpoints.
38330
38331@item hwbreak
38332The remote stub reports the @samp{hwbreak} stop reason for hardware
38333breakpoints.
38334
0d71eef5
DB
38335@item fork-events
38336The remote stub reports the @samp{fork} stop reason for fork events.
38337
38338@item vfork-events
38339The remote stub reports the @samp{vfork} stop reason for vfork events
38340and vforkdone events.
38341
b459a59b
DB
38342@item exec-events
38343The remote stub reports the @samp{exec} stop reason for exec events.
38344
750ce8d1
YQ
38345@item vContSupported
38346The remote stub reports the supported actions in the reply to
38347@samp{vCont?} packet.
38348
65706a29
PA
38349@item QThreadEvents
38350The remote stub understands the @samp{QThreadEvents} packet.
38351
f2faf941
PA
38352@item no-resumed
38353The remote stub reports the @samp{N} stop reply.
38354
be2a5f71
DJ
38355@end table
38356
b8ff78ce 38357@item qSymbol::
ff2587ec 38358@cindex symbol lookup, remote request
b8ff78ce 38359@cindex @samp{qSymbol} packet
ff2587ec
WZ
38360Notify the target that @value{GDBN} is prepared to serve symbol lookup
38361requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
38362
38363Reply:
ff2587ec 38364@table @samp
b8ff78ce 38365@item OK
ff2587ec 38366The target does not need to look up any (more) symbols.
b8ff78ce 38367@item qSymbol:@var{sym_name}
ff2587ec
WZ
38368The target requests the value of symbol @var{sym_name} (hex encoded).
38369@value{GDBN} may provide the value by using the
b8ff78ce
JB
38370@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
38371below.
ff2587ec 38372@end table
83761cbd 38373
b8ff78ce 38374@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
38375Set the value of @var{sym_name} to @var{sym_value}.
38376
38377@var{sym_name} (hex encoded) is the name of a symbol whose value the
38378target has previously requested.
38379
38380@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
38381@value{GDBN} cannot supply a value for @var{sym_name}, then this field
38382will be empty.
38383
38384Reply:
38385@table @samp
b8ff78ce 38386@item OK
ff2587ec 38387The target does not need to look up any (more) symbols.
b8ff78ce 38388@item qSymbol:@var{sym_name}
ff2587ec
WZ
38389The target requests the value of a new symbol @var{sym_name} (hex
38390encoded). @value{GDBN} will continue to supply the values of symbols
38391(if available), until the target ceases to request them.
fa93a9d8 38392@end table
0abb7bc7 38393
00bf0b85 38394@item qTBuffer
687e43a4
TT
38395@itemx QTBuffer
38396@itemx QTDisconnected
d5551862 38397@itemx QTDP
409873ef 38398@itemx QTDPsrc
d5551862 38399@itemx QTDV
00bf0b85
SS
38400@itemx qTfP
38401@itemx qTfV
9d29849a 38402@itemx QTFrame
405f8e94
SS
38403@itemx qTMinFTPILen
38404
9d29849a
JB
38405@xref{Tracepoint Packets}.
38406
b90a069a 38407@item qThreadExtraInfo,@var{thread-id}
ff2587ec 38408@cindex thread attributes info, remote request
b8ff78ce 38409@cindex @samp{qThreadExtraInfo} packet
697aa1b7
EZ
38410Obtain from the target OS a printable string description of thread
38411attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
38412for the forms of @var{thread-id}. This
b8ff78ce
JB
38413string may contain anything that the target OS thinks is interesting
38414for @value{GDBN} to tell the user about the thread. The string is
38415displayed in @value{GDBN}'s @code{info threads} display. Some
38416examples of possible thread extra info strings are @samp{Runnable}, or
38417@samp{Blocked on Mutex}.
ff2587ec
WZ
38418
38419Reply:
38420@table @samp
b8ff78ce
JB
38421@item @var{XX}@dots{}
38422Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
38423comprising the printable string containing the extra information about
38424the thread's attributes.
ff2587ec 38425@end table
814e32d7 38426
aa56d27a
JB
38427(Note that the @code{qThreadExtraInfo} packet's name is separated from
38428the command by a @samp{,}, not a @samp{:}, contrary to the naming
38429conventions above. Please don't use this packet as a model for new
38430packets.)
38431
f196051f 38432@item QTNotes
687e43a4
TT
38433@itemx qTP
38434@itemx QTSave
38435@itemx qTsP
38436@itemx qTsV
d5551862 38437@itemx QTStart
9d29849a 38438@itemx QTStop
d248b706
KY
38439@itemx QTEnable
38440@itemx QTDisable
9d29849a
JB
38441@itemx QTinit
38442@itemx QTro
38443@itemx qTStatus
d5551862 38444@itemx qTV
0fb4aa4b
PA
38445@itemx qTfSTM
38446@itemx qTsSTM
38447@itemx qTSTMat
9d29849a
JB
38448@xref{Tracepoint Packets}.
38449
0876f84a
DJ
38450@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
38451@cindex read special object, remote request
38452@cindex @samp{qXfer} packet
68437a39 38453@anchor{qXfer read}
0876f84a
DJ
38454Read uninterpreted bytes from the target's special data area
38455identified by the keyword @var{object}. Request @var{length} bytes
38456starting at @var{offset} bytes into the data. The content and
0e7f50da 38457encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
38458additional details about what data to access.
38459
c185ba27
EZ
38460Reply:
38461@table @samp
38462@item m @var{data}
38463Data @var{data} (@pxref{Binary Data}) has been read from the
38464target. There may be more data at a higher address (although
38465it is permitted to return @samp{m} even for the last valid
38466block of data, as long as at least one byte of data was read).
38467It is possible for @var{data} to have fewer bytes than the @var{length} in the
38468request.
38469
38470@item l @var{data}
38471Data @var{data} (@pxref{Binary Data}) has been read from the target.
38472There is no more data to be read. It is possible for @var{data} to
38473have fewer bytes than the @var{length} in the request.
38474
38475@item l
38476The @var{offset} in the request is at the end of the data.
38477There is no more data to be read.
38478
38479@item E00
38480The request was malformed, or @var{annex} was invalid.
38481
38482@item E @var{nn}
38483The offset was invalid, or there was an error encountered reading the data.
38484The @var{nn} part is a hex-encoded @code{errno} value.
38485
38486@item @w{}
38487An empty reply indicates the @var{object} string was not recognized by
38488the stub, or that the object does not support reading.
38489@end table
38490
38491Here are the specific requests of this form defined so far. All the
0876f84a 38492@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
c185ba27 38493formats, listed above.
0876f84a
DJ
38494
38495@table @samp
38496@item qXfer:auxv:read::@var{offset},@var{length}
38497@anchor{qXfer auxiliary vector read}
38498Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 38499auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
38500
38501This packet is not probed by default; the remote stub must request it,
89be2091 38502by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 38503
2ae8c8e7
MM
38504@item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
38505@anchor{qXfer btrace read}
38506
38507Return a description of the current branch trace.
38508@xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
38509packet may have one of the following values:
38510
38511@table @code
38512@item all
38513Returns all available branch trace.
38514
38515@item new
38516Returns all available branch trace if the branch trace changed since
38517the last read request.
969c39fb
MM
38518
38519@item delta
38520Returns the new branch trace since the last read request. Adds a new
38521block to the end of the trace that begins at zero and ends at the source
38522location of the first branch in the trace buffer. This extra block is
38523used to stitch traces together.
38524
38525If the trace buffer overflowed, returns an error indicating the overflow.
2ae8c8e7
MM
38526@end table
38527
38528This packet is not probed by default; the remote stub must request it
38529by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38530
f4abbc16
MM
38531@item qXfer:btrace-conf:read::@var{offset},@var{length}
38532@anchor{qXfer btrace-conf read}
38533
38534Return a description of the current branch trace configuration.
38535@xref{Branch Trace Configuration Format}.
38536
38537This packet is not probed by default; the remote stub must request it
38538by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
c78fa86a
GB
38539
38540@item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
38541@anchor{qXfer executable filename read}
38542Return the full absolute name of the file that was executed to create
38543a process running on the remote system. The annex specifies the
38544numeric process ID of the process to query, encoded as a hexadecimal
835205d0
GB
38545number. If the annex part is empty the remote stub should return the
38546filename corresponding to the currently executing process.
c78fa86a
GB
38547
38548This packet is not probed by default; the remote stub must request it,
38549by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
f4abbc16 38550
23181151
DJ
38551@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
38552@anchor{qXfer target description read}
38553Access the @dfn{target description}. @xref{Target Descriptions}. The
38554annex specifies which XML document to access. The main description is
38555always loaded from the @samp{target.xml} annex.
38556
38557This packet is not probed by default; the remote stub must request it,
38558by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38559
cfa9d6d9
DJ
38560@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
38561@anchor{qXfer library list read}
38562Access the target's list of loaded libraries. @xref{Library List Format}.
38563The annex part of the generic @samp{qXfer} packet must be empty
38564(@pxref{qXfer read}).
38565
38566Targets which maintain a list of libraries in the program's memory do
38567not need to implement this packet; it is designed for platforms where
38568the operating system manages the list of loaded libraries.
38569
38570This packet is not probed by default; the remote stub must request it,
38571by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38572
2268b414
JK
38573@item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
38574@anchor{qXfer svr4 library list read}
38575Access the target's list of loaded libraries when the target is an SVR4
38576platform. @xref{Library List Format for SVR4 Targets}. The annex part
85dc5a12
GB
38577of the generic @samp{qXfer} packet must be empty unless the remote
38578stub indicated it supports the augmented form of this packet
38579by supplying an appropriate @samp{qSupported} response
38580(@pxref{qXfer read}, @ref{qSupported}).
2268b414
JK
38581
38582This packet is optional for better performance on SVR4 targets.
38583@value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
38584
38585This packet is not probed by default; the remote stub must request it,
38586by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38587
85dc5a12
GB
38588If the remote stub indicates it supports the augmented form of this
38589packet then the annex part of the generic @samp{qXfer} packet may
38590contain a semicolon-separated list of @samp{@var{name}=@var{value}}
38591arguments. The currently supported arguments are:
38592
38593@table @code
38594@item start=@var{address}
38595A hexadecimal number specifying the address of the @samp{struct
38596link_map} to start reading the library list from. If unset or zero
38597then the first @samp{struct link_map} in the library list will be
38598chosen as the starting point.
38599
38600@item prev=@var{address}
38601A hexadecimal number specifying the address of the @samp{struct
38602link_map} immediately preceding the @samp{struct link_map}
38603specified by the @samp{start} argument. If unset or zero then
38604the remote stub will expect that no @samp{struct link_map}
38605exists prior to the starting point.
38606
38607@end table
38608
38609Arguments that are not understood by the remote stub will be silently
38610ignored.
38611
68437a39
DJ
38612@item qXfer:memory-map:read::@var{offset},@var{length}
38613@anchor{qXfer memory map read}
79a6e687 38614Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
38615annex part of the generic @samp{qXfer} packet must be empty
38616(@pxref{qXfer read}).
38617
0e7f50da
UW
38618This packet is not probed by default; the remote stub must request it,
38619by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38620
0fb4aa4b
PA
38621@item qXfer:sdata:read::@var{offset},@var{length}
38622@anchor{qXfer sdata read}
38623
38624Read contents of the extra collected static tracepoint marker
38625information. The annex part of the generic @samp{qXfer} packet must
38626be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
38627Action Lists}.
38628
38629This packet is not probed by default; the remote stub must request it,
38630by supplying an appropriate @samp{qSupported} response
38631(@pxref{qSupported}).
38632
4aa995e1
PA
38633@item qXfer:siginfo:read::@var{offset},@var{length}
38634@anchor{qXfer siginfo read}
38635Read contents of the extra signal information on the target
38636system. The annex part of the generic @samp{qXfer} packet must be
38637empty (@pxref{qXfer read}).
38638
38639This packet is not probed by default; the remote stub must request it,
38640by supplying an appropriate @samp{qSupported} response
38641(@pxref{qSupported}).
38642
0e7f50da
UW
38643@item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
38644@anchor{qXfer spu read}
38645Read contents of an @code{spufs} file on the target system. The
38646annex specifies which file to read; it must be of the form
38647@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
38648in the target process, and @var{name} identifes the @code{spufs} file
38649in that context to be accessed.
38650
68437a39 38651This packet is not probed by default; the remote stub must request it,
07e059b5
VP
38652by supplying an appropriate @samp{qSupported} response
38653(@pxref{qSupported}).
38654
dc146f7c
VP
38655@item qXfer:threads:read::@var{offset},@var{length}
38656@anchor{qXfer threads read}
38657Access the list of threads on target. @xref{Thread List Format}. The
38658annex part of the generic @samp{qXfer} packet must be empty
38659(@pxref{qXfer read}).
38660
38661This packet is not probed by default; the remote stub must request it,
38662by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38663
b3b9301e
PA
38664@item qXfer:traceframe-info:read::@var{offset},@var{length}
38665@anchor{qXfer traceframe info read}
38666
38667Return a description of the current traceframe's contents.
38668@xref{Traceframe Info Format}. The annex part of the generic
38669@samp{qXfer} packet must be empty (@pxref{qXfer read}).
38670
38671This packet is not probed by default; the remote stub must request it,
38672by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38673
169081d0
TG
38674@item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
38675@anchor{qXfer unwind info block}
38676
38677Return the unwind information block for @var{pc}. This packet is used
38678on OpenVMS/ia64 to ask the kernel unwind information.
38679
38680This packet is not probed by default.
38681
78d85199
YQ
38682@item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
38683@anchor{qXfer fdpic loadmap read}
38684Read contents of @code{loadmap}s on the target system. The
38685annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
38686executable @code{loadmap} or interpreter @code{loadmap} to read.
38687
38688This packet is not probed by default; the remote stub must request it,
38689by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38690
07e059b5
VP
38691@item qXfer:osdata:read::@var{offset},@var{length}
38692@anchor{qXfer osdata read}
697aa1b7 38693Access the target's @dfn{operating system information}.
07e059b5
VP
38694@xref{Operating System Information}.
38695
68437a39
DJ
38696@end table
38697
c185ba27
EZ
38698@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
38699@cindex write data into object, remote request
38700@anchor{qXfer write}
38701Write uninterpreted bytes into the target's special data area
38702identified by the keyword @var{object}, starting at @var{offset} bytes
38703into the data. The binary-encoded data (@pxref{Binary Data}) to be
38704written is given by @var{data}@dots{}. The content and encoding of @var{annex}
38705is specific to @var{object}; it can supply additional details about what data
38706to access.
38707
0876f84a
DJ
38708Reply:
38709@table @samp
c185ba27
EZ
38710@item @var{nn}
38711@var{nn} (hex encoded) is the number of bytes written.
38712This may be fewer bytes than supplied in the request.
0876f84a
DJ
38713
38714@item E00
38715The request was malformed, or @var{annex} was invalid.
38716
38717@item E @var{nn}
c185ba27 38718The offset was invalid, or there was an error encountered writing the data.
697aa1b7 38719The @var{nn} part is a hex-encoded @code{errno} value.
0876f84a 38720
d57350ea 38721@item @w{}
c185ba27
EZ
38722An empty reply indicates the @var{object} string was not
38723recognized by the stub, or that the object does not support writing.
0876f84a
DJ
38724@end table
38725
c185ba27 38726Here are the specific requests of this form defined so far. All the
0e7f50da 38727@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
c185ba27 38728formats, listed above.
0e7f50da
UW
38729
38730@table @samp
4aa995e1
PA
38731@item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
38732@anchor{qXfer siginfo write}
38733Write @var{data} to the extra signal information on the target system.
38734The annex part of the generic @samp{qXfer} packet must be
38735empty (@pxref{qXfer write}).
38736
38737This packet is not probed by default; the remote stub must request it,
38738by supplying an appropriate @samp{qSupported} response
38739(@pxref{qSupported}).
38740
84fcdf95 38741@item qXfer:spu:write:@var{annex}:@var{offset}:@var{data}@dots{}
0e7f50da
UW
38742@anchor{qXfer spu write}
38743Write @var{data} to an @code{spufs} file on the target system. The
38744annex specifies which file to write; it must be of the form
38745@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
38746in the target process, and @var{name} identifes the @code{spufs} file
38747in that context to be accessed.
38748
38749This packet is not probed by default; the remote stub must request it,
38750by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38751@end table
0876f84a 38752
0876f84a
DJ
38753@item qXfer:@var{object}:@var{operation}:@dots{}
38754Requests of this form may be added in the future. When a stub does
38755not recognize the @var{object} keyword, or its support for
38756@var{object} does not recognize the @var{operation} keyword, the stub
38757must respond with an empty packet.
38758
0b16c5cf
PA
38759@item qAttached:@var{pid}
38760@cindex query attached, remote request
38761@cindex @samp{qAttached} packet
38762Return an indication of whether the remote server attached to an
38763existing process or created a new process. When the multiprocess
38764protocol extensions are supported (@pxref{multiprocess extensions}),
38765@var{pid} is an integer in hexadecimal format identifying the target
38766process. Otherwise, @value{GDBN} will omit the @var{pid} field and
38767the query packet will be simplified as @samp{qAttached}.
38768
38769This query is used, for example, to know whether the remote process
38770should be detached or killed when a @value{GDBN} session is ended with
38771the @code{quit} command.
38772
38773Reply:
38774@table @samp
38775@item 1
38776The remote server attached to an existing process.
38777@item 0
38778The remote server created a new process.
38779@item E @var{NN}
38780A badly formed request or an error was encountered.
38781@end table
38782
2ae8c8e7 38783@item Qbtrace:bts
b20a6524
MM
38784Enable branch tracing for the current thread using Branch Trace Store.
38785
38786Reply:
38787@table @samp
38788@item OK
38789Branch tracing has been enabled.
38790@item E.errtext
38791A badly formed request or an error was encountered.
38792@end table
38793
38794@item Qbtrace:pt
bc504a31 38795Enable branch tracing for the current thread using Intel Processor Trace.
2ae8c8e7
MM
38796
38797Reply:
38798@table @samp
38799@item OK
38800Branch tracing has been enabled.
38801@item E.errtext
38802A badly formed request or an error was encountered.
38803@end table
38804
38805@item Qbtrace:off
38806Disable branch tracing for the current thread.
38807
38808Reply:
38809@table @samp
38810@item OK
38811Branch tracing has been disabled.
38812@item E.errtext
38813A badly formed request or an error was encountered.
38814@end table
38815
d33501a5
MM
38816@item Qbtrace-conf:bts:size=@var{value}
38817Set the requested ring buffer size for new threads that use the
38818btrace recording method in bts format.
38819
38820Reply:
38821@table @samp
38822@item OK
38823The ring buffer size has been set.
38824@item E.errtext
38825A badly formed request or an error was encountered.
38826@end table
38827
b20a6524
MM
38828@item Qbtrace-conf:pt:size=@var{value}
38829Set the requested ring buffer size for new threads that use the
38830btrace recording method in pt format.
38831
38832Reply:
38833@table @samp
38834@item OK
38835The ring buffer size has been set.
38836@item E.errtext
38837A badly formed request or an error was encountered.
38838@end table
38839
ee2d5c50
AC
38840@end table
38841
a1dcb23a
DJ
38842@node Architecture-Specific Protocol Details
38843@section Architecture-Specific Protocol Details
38844
38845This section describes how the remote protocol is applied to specific
38846target architectures. Also see @ref{Standard Target Features}, for
38847details of XML target descriptions for each architecture.
38848
02b67415
MR
38849@menu
38850* ARM-Specific Protocol Details::
38851* MIPS-Specific Protocol Details::
38852@end menu
38853
38854@node ARM-Specific Protocol Details
38855@subsection @acronym{ARM}-specific Protocol Details
38856
38857@menu
38858* ARM Breakpoint Kinds::
38859@end menu
a1dcb23a 38860
02b67415
MR
38861@node ARM Breakpoint Kinds
38862@subsubsection @acronym{ARM} Breakpoint Kinds
38863@cindex breakpoint kinds, @acronym{ARM}
a1dcb23a
DJ
38864
38865These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
38866
38867@table @r
38868
38869@item 2
3887016-bit Thumb mode breakpoint.
38871
38872@item 3
3887332-bit Thumb mode (Thumb-2) breakpoint.
38874
38875@item 4
02b67415 3887632-bit @acronym{ARM} mode breakpoint.
a1dcb23a
DJ
38877
38878@end table
38879
02b67415
MR
38880@node MIPS-Specific Protocol Details
38881@subsection @acronym{MIPS}-specific Protocol Details
38882
38883@menu
38884* MIPS Register packet Format::
4cc0665f 38885* MIPS Breakpoint Kinds::
02b67415 38886@end menu
a1dcb23a 38887
02b67415
MR
38888@node MIPS Register packet Format
38889@subsubsection @acronym{MIPS} Register Packet Format
eb17f351 38890@cindex register packet format, @acronym{MIPS}
eb12ee30 38891
b8ff78ce 38892The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
38893In the below, some thirty-two bit registers are transferred as
38894sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
38895to fill the space allocated. Register bytes are transferred in target
38896byte order. The two nibbles within a register byte are transferred
02b67415 38897most-significant -- least-significant.
eb12ee30 38898
ee2d5c50 38899@table @r
eb12ee30 38900
8e04817f 38901@item MIPS32
599b237a 38902All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
3890332 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
38904registers; fsr; fir; fp.
eb12ee30 38905
8e04817f 38906@item MIPS64
599b237a 38907All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
38908thirty-two bit registers such as @code{sr}). The ordering is the same
38909as @code{MIPS32}.
eb12ee30 38910
ee2d5c50
AC
38911@end table
38912
4cc0665f
MR
38913@node MIPS Breakpoint Kinds
38914@subsubsection @acronym{MIPS} Breakpoint Kinds
38915@cindex breakpoint kinds, @acronym{MIPS}
38916
38917These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
38918
38919@table @r
38920
38921@item 2
3892216-bit @acronym{MIPS16} mode breakpoint.
38923
38924@item 3
3892516-bit @acronym{microMIPS} mode breakpoint.
38926
38927@item 4
3892832-bit standard @acronym{MIPS} mode breakpoint.
38929
38930@item 5
3893132-bit @acronym{microMIPS} mode breakpoint.
38932
38933@end table
38934
9d29849a
JB
38935@node Tracepoint Packets
38936@section Tracepoint Packets
38937@cindex tracepoint packets
38938@cindex packets, tracepoint
38939
38940Here we describe the packets @value{GDBN} uses to implement
38941tracepoints (@pxref{Tracepoints}).
38942
38943@table @samp
38944
7a697b8d 38945@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
c614397c 38946@cindex @samp{QTDP} packet
9d29849a
JB
38947Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
38948is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
697aa1b7
EZ
38949the tracepoint is disabled. The @var{step} gives the tracepoint's step
38950count, and @var{pass} gives its pass count. If an @samp{F} is present,
7a697b8d
SS
38951then the tracepoint is to be a fast tracepoint, and the @var{flen} is
38952the number of bytes that the target should copy elsewhere to make room
38953for the tracepoint. If an @samp{X} is present, it introduces a
38954tracepoint condition, which consists of a hexadecimal length, followed
38955by a comma and hex-encoded bytes, in a manner similar to action
38956encodings as described below. If the trailing @samp{-} is present,
38957further @samp{QTDP} packets will follow to specify this tracepoint's
38958actions.
9d29849a
JB
38959
38960Replies:
38961@table @samp
38962@item OK
38963The packet was understood and carried out.
dde08ee1
PA
38964@item qRelocInsn
38965@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 38966@item @w{}
9d29849a
JB
38967The packet was not recognized.
38968@end table
38969
38970@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
697aa1b7 38971Define actions to be taken when a tracepoint is hit. The @var{n} and
9d29849a
JB
38972@var{addr} must be the same as in the initial @samp{QTDP} packet for
38973this tracepoint. This packet may only be sent immediately after
38974another @samp{QTDP} packet that ended with a @samp{-}. If the
38975trailing @samp{-} is present, further @samp{QTDP} packets will follow,
38976specifying more actions for this tracepoint.
38977
38978In the series of action packets for a given tracepoint, at most one
38979can have an @samp{S} before its first @var{action}. If such a packet
38980is sent, it and the following packets define ``while-stepping''
38981actions. Any prior packets define ordinary actions --- that is, those
38982taken when the tracepoint is first hit. If no action packet has an
38983@samp{S}, then all the packets in the series specify ordinary
38984tracepoint actions.
38985
38986The @samp{@var{action}@dots{}} portion of the packet is a series of
38987actions, concatenated without separators. Each action has one of the
38988following forms:
38989
38990@table @samp
38991
38992@item R @var{mask}
697aa1b7 38993Collect the registers whose bits are set in @var{mask},
599b237a 38994a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
38995@var{i} should be collected. (The least significant bit is numbered
38996zero.) Note that @var{mask} may be any number of digits long; it may
38997not fit in a 32-bit word.
38998
38999@item M @var{basereg},@var{offset},@var{len}
39000Collect @var{len} bytes of memory starting at the address in register
39001number @var{basereg}, plus @var{offset}. If @var{basereg} is
39002@samp{-1}, then the range has a fixed address: @var{offset} is the
39003address of the lowest byte to collect. The @var{basereg},
599b237a 39004@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
39005values (the @samp{-1} value for @var{basereg} is a special case).
39006
39007@item X @var{len},@var{expr}
39008Evaluate @var{expr}, whose length is @var{len}, and collect memory as
697aa1b7 39009it directs. The agent expression @var{expr} is as described in
9d29849a
JB
39010@ref{Agent Expressions}. Each byte of the expression is encoded as a
39011two-digit hex number in the packet; @var{len} is the number of bytes
39012in the expression (and thus one-half the number of hex digits in the
39013packet).
39014
39015@end table
39016
39017Any number of actions may be packed together in a single @samp{QTDP}
39018packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
39019length (400 bytes, for many stubs). There may be only one @samp{R}
39020action per tracepoint, and it must precede any @samp{M} or @samp{X}
39021actions. Any registers referred to by @samp{M} and @samp{X} actions
39022must be collected by a preceding @samp{R} action. (The
39023``while-stepping'' actions are treated as if they were attached to a
39024separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
39025
39026Replies:
39027@table @samp
39028@item OK
39029The packet was understood and carried out.
dde08ee1
PA
39030@item qRelocInsn
39031@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 39032@item @w{}
9d29849a
JB
39033The packet was not recognized.
39034@end table
39035
409873ef
SS
39036@item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
39037@cindex @samp{QTDPsrc} packet
39038Specify a source string of tracepoint @var{n} at address @var{addr}.
39039This is useful to get accurate reproduction of the tracepoints
697aa1b7 39040originally downloaded at the beginning of the trace run. The @var{type}
409873ef
SS
39041is the name of the tracepoint part, such as @samp{cond} for the
39042tracepoint's conditional expression (see below for a list of types), while
39043@var{bytes} is the string, encoded in hexadecimal.
39044
39045@var{start} is the offset of the @var{bytes} within the overall source
39046string, while @var{slen} is the total length of the source string.
39047This is intended for handling source strings that are longer than will
39048fit in a single packet.
39049@c Add detailed example when this info is moved into a dedicated
39050@c tracepoint descriptions section.
39051
39052The available string types are @samp{at} for the location,
39053@samp{cond} for the conditional, and @samp{cmd} for an action command.
39054@value{GDBN} sends a separate packet for each command in the action
39055list, in the same order in which the commands are stored in the list.
39056
39057The target does not need to do anything with source strings except
39058report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
39059query packets.
39060
39061Although this packet is optional, and @value{GDBN} will only send it
39062if the target replies with @samp{TracepointSource} @xref{General
39063Query Packets}, it makes both disconnected tracing and trace files
39064much easier to use. Otherwise the user must be careful that the
39065tracepoints in effect while looking at trace frames are identical to
39066the ones in effect during the trace run; even a small discrepancy
39067could cause @samp{tdump} not to work, or a particular trace frame not
39068be found.
39069
fa3f8d5a 39070@item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
f61e138d
SS
39071@cindex define trace state variable, remote request
39072@cindex @samp{QTDV} packet
39073Create a new trace state variable, number @var{n}, with an initial
39074value of @var{value}, which is a 64-bit signed integer. Both @var{n}
39075and @var{value} are encoded as hexadecimal values. @value{GDBN} has
39076the option of not using this packet for initial values of zero; the
39077target should simply create the trace state variables as they are
fa3f8d5a
DT
39078mentioned in expressions. The value @var{builtin} should be 1 (one)
39079if the trace state variable is builtin and 0 (zero) if it is not builtin.
39080@value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
39081@samp{qTsV} packet had it set. The contents of @var{name} is the
39082hex-encoded name (without the leading @samp{$}) of the trace state
39083variable.
f61e138d 39084
9d29849a 39085@item QTFrame:@var{n}
c614397c 39086@cindex @samp{QTFrame} packet
9d29849a
JB
39087Select the @var{n}'th tracepoint frame from the buffer, and use the
39088register and memory contents recorded there to answer subsequent
39089request packets from @value{GDBN}.
39090
39091A successful reply from the stub indicates that the stub has found the
39092requested frame. The response is a series of parts, concatenated
39093without separators, describing the frame we selected. Each part has
39094one of the following forms:
39095
39096@table @samp
39097@item F @var{f}
39098The selected frame is number @var{n} in the trace frame buffer;
599b237a 39099@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
39100was no frame matching the criteria in the request packet.
39101
39102@item T @var{t}
39103The selected trace frame records a hit of tracepoint number @var{t};
599b237a 39104@var{t} is a hexadecimal number.
9d29849a
JB
39105
39106@end table
39107
39108@item QTFrame:pc:@var{addr}
39109Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
39110currently selected frame whose PC is @var{addr};
599b237a 39111@var{addr} is a hexadecimal number.
9d29849a
JB
39112
39113@item QTFrame:tdp:@var{t}
39114Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
39115currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 39116is a hexadecimal number.
9d29849a
JB
39117
39118@item QTFrame:range:@var{start}:@var{end}
39119Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
39120currently selected frame whose PC is between @var{start} (inclusive)
081dfbf7 39121and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
39122numbers.
39123
39124@item QTFrame:outside:@var{start}:@var{end}
39125Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
081dfbf7 39126frame @emph{outside} the given range of addresses (exclusive).
9d29849a 39127
405f8e94 39128@item qTMinFTPILen
c614397c 39129@cindex @samp{qTMinFTPILen} packet
405f8e94
SS
39130This packet requests the minimum length of instruction at which a fast
39131tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
39132the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
39133it depends on the target system being able to create trampolines in
39134the first 64K of memory, which might or might not be possible for that
39135system. So the reply to this packet will be 4 if it is able to
39136arrange for that.
39137
39138Replies:
39139
39140@table @samp
39141@item 0
39142The minimum instruction length is currently unknown.
39143@item @var{length}
697aa1b7
EZ
39144The minimum instruction length is @var{length}, where @var{length}
39145is a hexadecimal number greater or equal to 1. A reply
39146of 1 means that a fast tracepoint may be placed on any instruction
39147regardless of size.
405f8e94
SS
39148@item E
39149An error has occurred.
d57350ea 39150@item @w{}
405f8e94
SS
39151An empty reply indicates that the request is not supported by the stub.
39152@end table
39153
9d29849a 39154@item QTStart
c614397c 39155@cindex @samp{QTStart} packet
dde08ee1
PA
39156Begin the tracepoint experiment. Begin collecting data from
39157tracepoint hits in the trace frame buffer. This packet supports the
39158@samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
39159instruction reply packet}).
9d29849a
JB
39160
39161@item QTStop
c614397c 39162@cindex @samp{QTStop} packet
9d29849a
JB
39163End the tracepoint experiment. Stop collecting trace frames.
39164
d248b706
KY
39165@item QTEnable:@var{n}:@var{addr}
39166@anchor{QTEnable}
c614397c 39167@cindex @samp{QTEnable} packet
d248b706
KY
39168Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
39169experiment. If the tracepoint was previously disabled, then collection
39170of data from it will resume.
39171
39172@item QTDisable:@var{n}:@var{addr}
39173@anchor{QTDisable}
c614397c 39174@cindex @samp{QTDisable} packet
d248b706
KY
39175Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
39176experiment. No more data will be collected from the tracepoint unless
39177@samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
39178
9d29849a 39179@item QTinit
c614397c 39180@cindex @samp{QTinit} packet
9d29849a
JB
39181Clear the table of tracepoints, and empty the trace frame buffer.
39182
39183@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
c614397c 39184@cindex @samp{QTro} packet
9d29849a
JB
39185Establish the given ranges of memory as ``transparent''. The stub
39186will answer requests for these ranges from memory's current contents,
39187if they were not collected as part of the tracepoint hit.
39188
39189@value{GDBN} uses this to mark read-only regions of memory, like those
39190containing program code. Since these areas never change, they should
39191still have the same contents they did when the tracepoint was hit, so
39192there's no reason for the stub to refuse to provide their contents.
39193
d5551862 39194@item QTDisconnected:@var{value}
c614397c 39195@cindex @samp{QTDisconnected} packet
d5551862
SS
39196Set the choice to what to do with the tracing run when @value{GDBN}
39197disconnects from the target. A @var{value} of 1 directs the target to
39198continue the tracing run, while 0 tells the target to stop tracing if
39199@value{GDBN} is no longer in the picture.
39200
9d29849a 39201@item qTStatus
c614397c 39202@cindex @samp{qTStatus} packet
9d29849a
JB
39203Ask the stub if there is a trace experiment running right now.
39204
4daf5ac0
SS
39205The reply has the form:
39206
39207@table @samp
39208
39209@item T@var{running}@r{[};@var{field}@r{]}@dots{}
39210@var{running} is a single digit @code{1} if the trace is presently
39211running, or @code{0} if not. It is followed by semicolon-separated
39212optional fields that an agent may use to report additional status.
39213
39214@end table
39215
39216If the trace is not running, the agent may report any of several
39217explanations as one of the optional fields:
39218
39219@table @samp
39220
39221@item tnotrun:0
39222No trace has been run yet.
39223
f196051f
SS
39224@item tstop[:@var{text}]:0
39225The trace was stopped by a user-originated stop command. The optional
39226@var{text} field is a user-supplied string supplied as part of the
39227stop command (for instance, an explanation of why the trace was
39228stopped manually). It is hex-encoded.
4daf5ac0
SS
39229
39230@item tfull:0
39231The trace stopped because the trace buffer filled up.
39232
39233@item tdisconnected:0
39234The trace stopped because @value{GDBN} disconnected from the target.
39235
39236@item tpasscount:@var{tpnum}
39237The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
39238
6c28cbf2
SS
39239@item terror:@var{text}:@var{tpnum}
39240The trace stopped because tracepoint @var{tpnum} had an error. The
39241string @var{text} is available to describe the nature of the error
697aa1b7
EZ
39242(for instance, a divide by zero in the condition expression); it
39243is hex encoded.
6c28cbf2 39244
4daf5ac0
SS
39245@item tunknown:0
39246The trace stopped for some other reason.
39247
39248@end table
39249
33da3f1c
SS
39250Additional optional fields supply statistical and other information.
39251Although not required, they are extremely useful for users monitoring
39252the progress of a trace run. If a trace has stopped, and these
39253numbers are reported, they must reflect the state of the just-stopped
39254trace.
4daf5ac0 39255
9d29849a 39256@table @samp
4daf5ac0
SS
39257
39258@item tframes:@var{n}
39259The number of trace frames in the buffer.
39260
39261@item tcreated:@var{n}
39262The total number of trace frames created during the run. This may
39263be larger than the trace frame count, if the buffer is circular.
39264
39265@item tsize:@var{n}
39266The total size of the trace buffer, in bytes.
39267
39268@item tfree:@var{n}
39269The number of bytes still unused in the buffer.
39270
33da3f1c
SS
39271@item circular:@var{n}
39272The value of the circular trace buffer flag. @code{1} means that the
39273trace buffer is circular and old trace frames will be discarded if
39274necessary to make room, @code{0} means that the trace buffer is linear
39275and may fill up.
39276
39277@item disconn:@var{n}
39278The value of the disconnected tracing flag. @code{1} means that
39279tracing will continue after @value{GDBN} disconnects, @code{0} means
39280that the trace run will stop.
39281
9d29849a
JB
39282@end table
39283
f196051f
SS
39284@item qTP:@var{tp}:@var{addr}
39285@cindex tracepoint status, remote request
39286@cindex @samp{qTP} packet
39287Ask the stub for the current state of tracepoint number @var{tp} at
39288address @var{addr}.
39289
39290Replies:
39291@table @samp
39292@item V@var{hits}:@var{usage}
39293The tracepoint has been hit @var{hits} times so far during the trace
39294run, and accounts for @var{usage} in the trace buffer. Note that
39295@code{while-stepping} steps are not counted as separate hits, but the
39296steps' space consumption is added into the usage number.
39297
39298@end table
39299
f61e138d
SS
39300@item qTV:@var{var}
39301@cindex trace state variable value, remote request
39302@cindex @samp{qTV} packet
39303Ask the stub for the value of the trace state variable number @var{var}.
39304
39305Replies:
39306@table @samp
39307@item V@var{value}
39308The value of the variable is @var{value}. This will be the current
39309value of the variable if the user is examining a running target, or a
39310saved value if the variable was collected in the trace frame that the
39311user is looking at. Note that multiple requests may result in
39312different reply values, such as when requesting values while the
39313program is running.
39314
39315@item U
39316The value of the variable is unknown. This would occur, for example,
39317if the user is examining a trace frame in which the requested variable
39318was not collected.
9d29849a
JB
39319@end table
39320
d5551862 39321@item qTfP
c614397c 39322@cindex @samp{qTfP} packet
d5551862 39323@itemx qTsP
c614397c 39324@cindex @samp{qTsP} packet
d5551862
SS
39325These packets request data about tracepoints that are being used by
39326the target. @value{GDBN} sends @code{qTfP} to get the first piece
39327of data, and multiple @code{qTsP} to get additional pieces. Replies
39328to these packets generally take the form of the @code{QTDP} packets
39329that define tracepoints. (FIXME add detailed syntax)
39330
00bf0b85 39331@item qTfV
c614397c 39332@cindex @samp{qTfV} packet
00bf0b85 39333@itemx qTsV
c614397c 39334@cindex @samp{qTsV} packet
00bf0b85
SS
39335These packets request data about trace state variables that are on the
39336target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
39337and multiple @code{qTsV} to get additional variables. Replies to
39338these packets follow the syntax of the @code{QTDV} packets that define
39339trace state variables.
39340
0fb4aa4b
PA
39341@item qTfSTM
39342@itemx qTsSTM
16bdd41f
YQ
39343@anchor{qTfSTM}
39344@anchor{qTsSTM}
c614397c
YQ
39345@cindex @samp{qTfSTM} packet
39346@cindex @samp{qTsSTM} packet
0fb4aa4b
PA
39347These packets request data about static tracepoint markers that exist
39348in the target program. @value{GDBN} sends @code{qTfSTM} to get the
39349first piece of data, and multiple @code{qTsSTM} to get additional
39350pieces. Replies to these packets take the following form:
39351
39352Reply:
39353@table @samp
39354@item m @var{address}:@var{id}:@var{extra}
39355A single marker
39356@item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
39357a comma-separated list of markers
39358@item l
39359(lower case letter @samp{L}) denotes end of list.
39360@item E @var{nn}
697aa1b7 39361An error occurred. The error number @var{nn} is given as hex digits.
d57350ea 39362@item @w{}
0fb4aa4b
PA
39363An empty reply indicates that the request is not supported by the
39364stub.
39365@end table
39366
697aa1b7 39367The @var{address} is encoded in hex;
0fb4aa4b
PA
39368@var{id} and @var{extra} are strings encoded in hex.
39369
39370In response to each query, the target will reply with a list of one or
39371more markers, separated by commas. @value{GDBN} will respond to each
39372reply with a request for more markers (using the @samp{qs} form of the
39373query), until the target responds with @samp{l} (lower-case ell, for
39374@dfn{last}).
39375
39376@item qTSTMat:@var{address}
16bdd41f 39377@anchor{qTSTMat}
c614397c 39378@cindex @samp{qTSTMat} packet
0fb4aa4b
PA
39379This packets requests data about static tracepoint markers in the
39380target program at @var{address}. Replies to this packet follow the
39381syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
39382tracepoint markers.
39383
00bf0b85 39384@item QTSave:@var{filename}
c614397c 39385@cindex @samp{QTSave} packet
00bf0b85 39386This packet directs the target to save trace data to the file name
697aa1b7 39387@var{filename} in the target's filesystem. The @var{filename} is encoded
00bf0b85
SS
39388as a hex string; the interpretation of the file name (relative vs
39389absolute, wild cards, etc) is up to the target.
39390
39391@item qTBuffer:@var{offset},@var{len}
c614397c 39392@cindex @samp{qTBuffer} packet
00bf0b85
SS
39393Return up to @var{len} bytes of the current contents of trace buffer,
39394starting at @var{offset}. The trace buffer is treated as if it were
39395a contiguous collection of traceframes, as per the trace file format.
39396The reply consists as many hex-encoded bytes as the target can deliver
39397in a packet; it is not an error to return fewer than were asked for.
39398A reply consisting of just @code{l} indicates that no bytes are
39399available.
39400
4daf5ac0
SS
39401@item QTBuffer:circular:@var{value}
39402This packet directs the target to use a circular trace buffer if
39403@var{value} is 1, or a linear buffer if the value is 0.
39404
f6f899bf 39405@item QTBuffer:size:@var{size}
28abe188
EZ
39406@anchor{QTBuffer-size}
39407@cindex @samp{QTBuffer size} packet
f6f899bf
HAQ
39408This packet directs the target to make the trace buffer be of size
39409@var{size} if possible. A value of @code{-1} tells the target to
39410use whatever size it prefers.
39411
f196051f 39412@item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
c614397c 39413@cindex @samp{QTNotes} packet
f196051f
SS
39414This packet adds optional textual notes to the trace run. Allowable
39415types include @code{user}, @code{notes}, and @code{tstop}, the
39416@var{text} fields are arbitrary strings, hex-encoded.
39417
f61e138d 39418@end table
9d29849a 39419
dde08ee1
PA
39420@subsection Relocate instruction reply packet
39421When installing fast tracepoints in memory, the target may need to
39422relocate the instruction currently at the tracepoint address to a
39423different address in memory. For most instructions, a simple copy is
39424enough, but, for example, call instructions that implicitly push the
39425return address on the stack, and relative branches or other
39426PC-relative instructions require offset adjustment, so that the effect
39427of executing the instruction at a different address is the same as if
39428it had executed in the original location.
39429
39430In response to several of the tracepoint packets, the target may also
39431respond with a number of intermediate @samp{qRelocInsn} request
39432packets before the final result packet, to have @value{GDBN} handle
39433this relocation operation. If a packet supports this mechanism, its
39434documentation will explicitly say so. See for example the above
39435descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
39436format of the request is:
39437
39438@table @samp
39439@item qRelocInsn:@var{from};@var{to}
39440
39441This requests @value{GDBN} to copy instruction at address @var{from}
39442to address @var{to}, possibly adjusted so that executing the
39443instruction at @var{to} has the same effect as executing it at
39444@var{from}. @value{GDBN} writes the adjusted instruction to target
39445memory starting at @var{to}.
39446@end table
39447
39448Replies:
39449@table @samp
39450@item qRelocInsn:@var{adjusted_size}
697aa1b7 39451Informs the stub the relocation is complete. The @var{adjusted_size} is
dde08ee1
PA
39452the length in bytes of resulting relocated instruction sequence.
39453@item E @var{NN}
39454A badly formed request was detected, or an error was encountered while
39455relocating the instruction.
39456@end table
39457
a6b151f1
DJ
39458@node Host I/O Packets
39459@section Host I/O Packets
39460@cindex Host I/O, remote protocol
39461@cindex file transfer, remote protocol
39462
39463The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
39464operations on the far side of a remote link. For example, Host I/O is
39465used to upload and download files to a remote target with its own
39466filesystem. Host I/O uses the same constant values and data structure
39467layout as the target-initiated File-I/O protocol. However, the
39468Host I/O packets are structured differently. The target-initiated
39469protocol relies on target memory to store parameters and buffers.
39470Host I/O requests are initiated by @value{GDBN}, and the
39471target's memory is not involved. @xref{File-I/O Remote Protocol
39472Extension}, for more details on the target-initiated protocol.
39473
39474The Host I/O request packets all encode a single operation along with
39475its arguments. They have this format:
39476
39477@table @samp
39478
39479@item vFile:@var{operation}: @var{parameter}@dots{}
39480@var{operation} is the name of the particular request; the target
39481should compare the entire packet name up to the second colon when checking
39482for a supported operation. The format of @var{parameter} depends on
39483the operation. Numbers are always passed in hexadecimal. Negative
39484numbers have an explicit minus sign (i.e.@: two's complement is not
39485used). Strings (e.g.@: filenames) are encoded as a series of
39486hexadecimal bytes. The last argument to a system call may be a
39487buffer of escaped binary data (@pxref{Binary Data}).
39488
39489@end table
39490
39491The valid responses to Host I/O packets are:
39492
39493@table @samp
39494
39495@item F @var{result} [, @var{errno}] [; @var{attachment}]
39496@var{result} is the integer value returned by this operation, usually
39497non-negative for success and -1 for errors. If an error has occured,
697aa1b7 39498@var{errno} will be included in the result specifying a
a6b151f1
DJ
39499value defined by the File-I/O protocol (@pxref{Errno Values}). For
39500operations which return data, @var{attachment} supplies the data as a
39501binary buffer. Binary buffers in response packets are escaped in the
39502normal way (@pxref{Binary Data}). See the individual packet
39503documentation for the interpretation of @var{result} and
39504@var{attachment}.
39505
d57350ea 39506@item @w{}
a6b151f1
DJ
39507An empty response indicates that this operation is not recognized.
39508
39509@end table
39510
39511These are the supported Host I/O operations:
39512
39513@table @samp
697aa1b7
EZ
39514@item vFile:open: @var{filename}, @var{flags}, @var{mode}
39515Open a file at @var{filename} and return a file descriptor for it, or
39516return -1 if an error occurs. The @var{filename} is a string,
a6b151f1
DJ
39517@var{flags} is an integer indicating a mask of open flags
39518(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
39519of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 39520@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
39521
39522@item vFile:close: @var{fd}
39523Close the open file corresponding to @var{fd} and return 0, or
39524-1 if an error occurs.
39525
39526@item vFile:pread: @var{fd}, @var{count}, @var{offset}
39527Read data from the open file corresponding to @var{fd}. Up to
39528@var{count} bytes will be read from the file, starting at @var{offset}
39529relative to the start of the file. The target may read fewer bytes;
39530common reasons include packet size limits and an end-of-file
39531condition. The number of bytes read is returned. Zero should only be
39532returned for a successful read at the end of the file, or if
39533@var{count} was zero.
39534
39535The data read should be returned as a binary attachment on success.
39536If zero bytes were read, the response should include an empty binary
39537attachment (i.e.@: a trailing semicolon). The return value is the
39538number of target bytes read; the binary attachment may be longer if
39539some characters were escaped.
39540
39541@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
39542Write @var{data} (a binary buffer) to the open file corresponding
39543to @var{fd}. Start the write at @var{offset} from the start of the
39544file. Unlike many @code{write} system calls, there is no
39545separate @var{count} argument; the length of @var{data} in the
39546packet is used. @samp{vFile:write} returns the number of bytes written,
39547which may be shorter than the length of @var{data}, or -1 if an
39548error occurred.
39549
0a93529c
GB
39550@item vFile:fstat: @var{fd}
39551Get information about the open file corresponding to @var{fd}.
39552On success the information is returned as a binary attachment
39553and the return value is the size of this attachment in bytes.
39554If an error occurs the return value is -1. The format of the
39555returned binary attachment is as described in @ref{struct stat}.
39556
697aa1b7
EZ
39557@item vFile:unlink: @var{filename}
39558Delete the file at @var{filename} on the target. Return 0,
39559or -1 if an error occurs. The @var{filename} is a string.
a6b151f1 39560
b9e7b9c3
UW
39561@item vFile:readlink: @var{filename}
39562Read value of symbolic link @var{filename} on the target. Return
39563the number of bytes read, or -1 if an error occurs.
39564
39565The data read should be returned as a binary attachment on success.
39566If zero bytes were read, the response should include an empty binary
39567attachment (i.e.@: a trailing semicolon). The return value is the
39568number of target bytes read; the binary attachment may be longer if
39569some characters were escaped.
39570
15a201c8
GB
39571@item vFile:setfs: @var{pid}
39572Select the filesystem on which @code{vFile} operations with
39573@var{filename} arguments will operate. This is required for
39574@value{GDBN} to be able to access files on remote targets where
39575the remote stub does not share a common filesystem with the
39576inferior(s).
39577
39578If @var{pid} is nonzero, select the filesystem as seen by process
39579@var{pid}. If @var{pid} is zero, select the filesystem as seen by
39580the remote stub. Return 0 on success, or -1 if an error occurs.
39581If @code{vFile:setfs:} indicates success, the selected filesystem
39582remains selected until the next successful @code{vFile:setfs:}
39583operation.
39584
a6b151f1
DJ
39585@end table
39586
9a6253be
KB
39587@node Interrupts
39588@section Interrupts
39589@cindex interrupts (remote protocol)
de979965 39590@anchor{interrupting remote targets}
9a6253be 39591
de979965
PA
39592In all-stop mode, when a program on the remote target is running,
39593@value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
39594@code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
39595is specified via @value{GDBN}'s @samp{interrupt-sequence}.
9a6253be
KB
39596
39597The precise meaning of @code{BREAK} is defined by the transport
8775bb90
MS
39598mechanism and may, in fact, be undefined. @value{GDBN} does not
39599currently define a @code{BREAK} mechanism for any of the network
39600interfaces except for TCP, in which case @value{GDBN} sends the
39601@code{telnet} BREAK sequence.
9a6253be
KB
39602
39603@samp{Ctrl-C}, on the other hand, is defined and implemented for all
39604transport mechanisms. It is represented by sending the single byte
39605@code{0x03} without any of the usual packet overhead described in
39606the Overview section (@pxref{Overview}). When a @code{0x03} byte is
39607transmitted as part of a packet, it is considered to be packet data
39608and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 39609(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
39610@code{0x03} as part of its packet.
39611
9a7071a8
JB
39612@code{BREAK} followed by @code{g} is also known as Magic SysRq g.
39613When Linux kernel receives this sequence from serial port,
39614it stops execution and connects to gdb.
39615
de979965
PA
39616In non-stop mode, because packet resumptions are asynchronous
39617(@pxref{vCont packet}), @value{GDBN} is always free to send a remote
39618command to the remote stub, even when the target is running. For that
39619reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
39620packet}) with the usual packet framing instead of the single byte
39621@code{0x03}.
39622
9a6253be
KB
39623Stubs are not required to recognize these interrupt mechanisms and the
39624precise meaning associated with receipt of the interrupt is
8b23ecc4
SL
39625implementation defined. If the target supports debugging of multiple
39626threads and/or processes, it should attempt to interrupt all
39627currently-executing threads and processes.
39628If the stub is successful at interrupting the
39629running program, it should send one of the stop
39630reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
39631of successfully stopping the program in all-stop mode, and a stop reply
39632for each stopped thread in non-stop mode.
39633Interrupts received while the
cde67b27
YQ
39634program is stopped are queued and the program will be interrupted when
39635it is resumed next time.
8b23ecc4
SL
39636
39637@node Notification Packets
39638@section Notification Packets
39639@cindex notification packets
39640@cindex packets, notification
39641
39642The @value{GDBN} remote serial protocol includes @dfn{notifications},
39643packets that require no acknowledgment. Both the GDB and the stub
39644may send notifications (although the only notifications defined at
39645present are sent by the stub). Notifications carry information
39646without incurring the round-trip latency of an acknowledgment, and so
39647are useful for low-impact communications where occasional packet loss
39648is not a problem.
39649
39650A notification packet has the form @samp{% @var{data} #
39651@var{checksum}}, where @var{data} is the content of the notification,
39652and @var{checksum} is a checksum of @var{data}, computed and formatted
39653as for ordinary @value{GDBN} packets. A notification's @var{data}
39654never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
39655receiving a notification, the recipient sends no @samp{+} or @samp{-}
39656to acknowledge the notification's receipt or to report its corruption.
39657
39658Every notification's @var{data} begins with a name, which contains no
39659colon characters, followed by a colon character.
39660
39661Recipients should silently ignore corrupted notifications and
39662notifications they do not understand. Recipients should restart
39663timeout periods on receipt of a well-formed notification, whether or
39664not they understand it.
39665
39666Senders should only send the notifications described here when this
39667protocol description specifies that they are permitted. In the
39668future, we may extend the protocol to permit existing notifications in
39669new contexts; this rule helps older senders avoid confusing newer
39670recipients.
39671
39672(Older versions of @value{GDBN} ignore bytes received until they see
39673the @samp{$} byte that begins an ordinary packet, so new stubs may
39674transmit notifications without fear of confusing older clients. There
39675are no notifications defined for @value{GDBN} to send at the moment, but we
39676assume that most older stubs would ignore them, as well.)
39677
8dbe8ece 39678Each notification is comprised of three parts:
8b23ecc4 39679@table @samp
8dbe8ece
YQ
39680@item @var{name}:@var{event}
39681The notification packet is sent by the side that initiates the
39682exchange (currently, only the stub does that), with @var{event}
697aa1b7
EZ
39683carrying the specific information about the notification, and
39684@var{name} specifying the name of the notification.
8dbe8ece
YQ
39685@item @var{ack}
39686The acknowledge sent by the other side, usually @value{GDBN}, to
39687acknowledge the exchange and request the event.
39688@end table
39689
39690The purpose of an asynchronous notification mechanism is to report to
39691@value{GDBN} that something interesting happened in the remote stub.
39692
39693The remote stub may send notification @var{name}:@var{event}
39694at any time, but @value{GDBN} acknowledges the notification when
39695appropriate. The notification event is pending before @value{GDBN}
39696acknowledges. Only one notification at a time may be pending; if
39697additional events occur before @value{GDBN} has acknowledged the
39698previous notification, they must be queued by the stub for later
39699synchronous transmission in response to @var{ack} packets from
39700@value{GDBN}. Because the notification mechanism is unreliable,
39701the stub is permitted to resend a notification if it believes
39702@value{GDBN} may not have received it.
39703
39704Specifically, notifications may appear when @value{GDBN} is not
39705otherwise reading input from the stub, or when @value{GDBN} is
39706expecting to read a normal synchronous response or a
39707@samp{+}/@samp{-} acknowledgment to a packet it has sent.
39708Notification packets are distinct from any other communication from
39709the stub so there is no ambiguity.
39710
39711After receiving a notification, @value{GDBN} shall acknowledge it by
39712sending a @var{ack} packet as a regular, synchronous request to the
39713stub. Such acknowledgment is not required to happen immediately, as
39714@value{GDBN} is permitted to send other, unrelated packets to the
39715stub first, which the stub should process normally.
39716
39717Upon receiving a @var{ack} packet, if the stub has other queued
39718events to report to @value{GDBN}, it shall respond by sending a
39719normal @var{event}. @value{GDBN} shall then send another @var{ack}
39720packet to solicit further responses; again, it is permitted to send
39721other, unrelated packets as well which the stub should process
39722normally.
39723
39724If the stub receives a @var{ack} packet and there are no additional
39725@var{event} to report, the stub shall return an @samp{OK} response.
39726At this point, @value{GDBN} has finished processing a notification
39727and the stub has completed sending any queued events. @value{GDBN}
39728won't accept any new notifications until the final @samp{OK} is
39729received . If further notification events occur, the stub shall send
39730a new notification, @value{GDBN} shall accept the notification, and
39731the process shall be repeated.
39732
39733The process of asynchronous notification can be illustrated by the
39734following example:
39735@smallexample
4435e1cc 39736<- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
8dbe8ece
YQ
39737@code{...}
39738-> @code{vStopped}
39739<- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
39740-> @code{vStopped}
39741<- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
39742-> @code{vStopped}
39743<- @code{OK}
39744@end smallexample
39745
39746The following notifications are defined:
39747@multitable @columnfractions 0.12 0.12 0.38 0.38
39748
39749@item Notification
39750@tab Ack
39751@tab Event
39752@tab Description
39753
39754@item Stop
39755@tab vStopped
39756@tab @var{reply}. The @var{reply} has the form of a stop reply, as
8b23ecc4
SL
39757described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
39758for information on how these notifications are acknowledged by
39759@value{GDBN}.
8dbe8ece
YQ
39760@tab Report an asynchronous stop event in non-stop mode.
39761
39762@end multitable
8b23ecc4
SL
39763
39764@node Remote Non-Stop
39765@section Remote Protocol Support for Non-Stop Mode
39766
39767@value{GDBN}'s remote protocol supports non-stop debugging of
39768multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
39769supports non-stop mode, it should report that to @value{GDBN} by including
39770@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
39771
39772@value{GDBN} typically sends a @samp{QNonStop} packet only when
39773establishing a new connection with the stub. Entering non-stop mode
39774does not alter the state of any currently-running threads, but targets
39775must stop all threads in any already-attached processes when entering
39776all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
39777probe the target state after a mode change.
39778
39779In non-stop mode, when an attached process encounters an event that
39780would otherwise be reported with a stop reply, it uses the
39781asynchronous notification mechanism (@pxref{Notification Packets}) to
39782inform @value{GDBN}. In contrast to all-stop mode, where all threads
39783in all processes are stopped when a stop reply is sent, in non-stop
39784mode only the thread reporting the stop event is stopped. That is,
39785when reporting a @samp{S} or @samp{T} response to indicate completion
39786of a step operation, hitting a breakpoint, or a fault, only the
39787affected thread is stopped; any other still-running threads continue
39788to run. When reporting a @samp{W} or @samp{X} response, all running
39789threads belonging to other attached processes continue to run.
39790
8b23ecc4
SL
39791In non-stop mode, the target shall respond to the @samp{?} packet as
39792follows. First, any incomplete stop reply notification/@samp{vStopped}
39793sequence in progress is abandoned. The target must begin a new
39794sequence reporting stop events for all stopped threads, whether or not
39795it has previously reported those events to @value{GDBN}. The first
39796stop reply is sent as a synchronous reply to the @samp{?} packet, and
39797subsequent stop replies are sent as responses to @samp{vStopped} packets
39798using the mechanism described above. The target must not send
39799asynchronous stop reply notifications until the sequence is complete.
39800If all threads are running when the target receives the @samp{?} packet,
39801or if the target is not attached to any process, it shall respond
39802@samp{OK}.
9a6253be 39803
f7e6eed5
PA
39804If the stub supports non-stop mode, it should also support the
39805@samp{swbreak} stop reason if software breakpoints are supported, and
39806the @samp{hwbreak} stop reason if hardware breakpoints are supported
39807(@pxref{swbreak stop reason}). This is because given the asynchronous
39808nature of non-stop mode, between the time a thread hits a breakpoint
39809and the time the event is finally processed by @value{GDBN}, the
39810breakpoint may have already been removed from the target. Due to
39811this, @value{GDBN} needs to be able to tell whether a trap stop was
39812caused by a delayed breakpoint event, which should be ignored, as
39813opposed to a random trap signal, which should be reported to the user.
39814Note the @samp{swbreak} feature implies that the target is responsible
39815for adjusting the PC when a software breakpoint triggers, if
39816necessary, such as on the x86 architecture.
39817
a6f3e723
SL
39818@node Packet Acknowledgment
39819@section Packet Acknowledgment
39820
39821@cindex acknowledgment, for @value{GDBN} remote
39822@cindex packet acknowledgment, for @value{GDBN} remote
39823By default, when either the host or the target machine receives a packet,
39824the first response expected is an acknowledgment: either @samp{+} (to indicate
39825the package was received correctly) or @samp{-} (to request retransmission).
39826This mechanism allows the @value{GDBN} remote protocol to operate over
39827unreliable transport mechanisms, such as a serial line.
39828
39829In cases where the transport mechanism is itself reliable (such as a pipe or
39830TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
39831It may be desirable to disable them in that case to reduce communication
39832overhead, or for other reasons. This can be accomplished by means of the
39833@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
39834
39835When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
39836expect @samp{+}/@samp{-} protocol acknowledgments. The packet
39837and response format still includes the normal checksum, as described in
39838@ref{Overview}, but the checksum may be ignored by the receiver.
39839
39840If the stub supports @samp{QStartNoAckMode} and prefers to operate in
39841no-acknowledgment mode, it should report that to @value{GDBN}
39842by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
39843@pxref{qSupported}.
39844If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
39845disabled via the @code{set remote noack-packet off} command
39846(@pxref{Remote Configuration}),
39847@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
39848Only then may the stub actually turn off packet acknowledgments.
39849@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
39850response, which can be safely ignored by the stub.
39851
39852Note that @code{set remote noack-packet} command only affects negotiation
39853between @value{GDBN} and the stub when subsequent connections are made;
39854it does not affect the protocol acknowledgment state for any current
39855connection.
39856Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
39857new connection is established,
39858there is also no protocol request to re-enable the acknowledgments
39859for the current connection, once disabled.
39860
ee2d5c50
AC
39861@node Examples
39862@section Examples
eb12ee30 39863
8e04817f
AC
39864Example sequence of a target being re-started. Notice how the restart
39865does not get any direct output:
eb12ee30 39866
474c8240 39867@smallexample
d2c6833e
AC
39868-> @code{R00}
39869<- @code{+}
8e04817f 39870@emph{target restarts}
d2c6833e 39871-> @code{?}
8e04817f 39872<- @code{+}
d2c6833e
AC
39873<- @code{T001:1234123412341234}
39874-> @code{+}
474c8240 39875@end smallexample
eb12ee30 39876
8e04817f 39877Example sequence of a target being stepped by a single instruction:
eb12ee30 39878
474c8240 39879@smallexample
d2c6833e 39880-> @code{G1445@dots{}}
8e04817f 39881<- @code{+}
d2c6833e
AC
39882-> @code{s}
39883<- @code{+}
39884@emph{time passes}
39885<- @code{T001:1234123412341234}
8e04817f 39886-> @code{+}
d2c6833e 39887-> @code{g}
8e04817f 39888<- @code{+}
d2c6833e
AC
39889<- @code{1455@dots{}}
39890-> @code{+}
474c8240 39891@end smallexample
eb12ee30 39892
79a6e687
BW
39893@node File-I/O Remote Protocol Extension
39894@section File-I/O Remote Protocol Extension
0ce1b118
CV
39895@cindex File-I/O remote protocol extension
39896
39897@menu
39898* File-I/O Overview::
79a6e687
BW
39899* Protocol Basics::
39900* The F Request Packet::
39901* The F Reply Packet::
39902* The Ctrl-C Message::
0ce1b118 39903* Console I/O::
79a6e687 39904* List of Supported Calls::
db2e3e2e 39905* Protocol-specific Representation of Datatypes::
0ce1b118
CV
39906* Constants::
39907* File-I/O Examples::
39908@end menu
39909
39910@node File-I/O Overview
39911@subsection File-I/O Overview
39912@cindex file-i/o overview
39913
9c16f35a 39914The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 39915target to use the host's file system and console I/O to perform various
0ce1b118 39916system calls. System calls on the target system are translated into a
fc320d37
SL
39917remote protocol packet to the host system, which then performs the needed
39918actions and returns a response packet to the target system.
0ce1b118
CV
39919This simulates file system operations even on targets that lack file systems.
39920
fc320d37
SL
39921The protocol is defined to be independent of both the host and target systems.
39922It uses its own internal representation of datatypes and values. Both
0ce1b118 39923@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
39924translating the system-dependent value representations into the internal
39925protocol representations when data is transmitted.
0ce1b118 39926
fc320d37
SL
39927The communication is synchronous. A system call is possible only when
39928@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
39929or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 39930the target is stopped to allow deterministic access to the target's
fc320d37
SL
39931memory. Therefore File-I/O is not interruptible by target signals. On
39932the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 39933(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
39934
39935The target's request to perform a host system call does not finish
39936the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
39937after finishing the system call, the target returns to continuing the
39938previous activity (continue, step). No additional continue or step
39939request from @value{GDBN} is required.
39940
39941@smallexample
f7dc1244 39942(@value{GDBP}) continue
0ce1b118
CV
39943 <- target requests 'system call X'
39944 target is stopped, @value{GDBN} executes system call
3f94c067
BW
39945 -> @value{GDBN} returns result
39946 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
39947 <- target hits breakpoint and sends a Txx packet
39948@end smallexample
39949
fc320d37
SL
39950The protocol only supports I/O on the console and to regular files on
39951the host file system. Character or block special devices, pipes,
39952named pipes, sockets or any other communication method on the host
0ce1b118
CV
39953system are not supported by this protocol.
39954
8b23ecc4
SL
39955File I/O is not supported in non-stop mode.
39956
79a6e687
BW
39957@node Protocol Basics
39958@subsection Protocol Basics
0ce1b118
CV
39959@cindex protocol basics, file-i/o
39960
fc320d37
SL
39961The File-I/O protocol uses the @code{F} packet as the request as well
39962as reply packet. Since a File-I/O system call can only occur when
39963@value{GDBN} is waiting for a response from the continuing or stepping target,
39964the File-I/O request is a reply that @value{GDBN} has to expect as a result
39965of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
39966This @code{F} packet contains all information needed to allow @value{GDBN}
39967to call the appropriate host system call:
39968
39969@itemize @bullet
b383017d 39970@item
0ce1b118
CV
39971A unique identifier for the requested system call.
39972
39973@item
39974All parameters to the system call. Pointers are given as addresses
39975in the target memory address space. Pointers to strings are given as
b383017d 39976pointer/length pair. Numerical values are given as they are.
db2e3e2e 39977Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
39978
39979@end itemize
39980
fc320d37 39981At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
39982
39983@itemize @bullet
b383017d 39984@item
fc320d37
SL
39985If the parameters include pointer values to data needed as input to a
39986system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
39987standard @code{m} packet request. This additional communication has to be
39988expected by the target implementation and is handled as any other @code{m}
39989packet.
39990
39991@item
39992@value{GDBN} translates all value from protocol representation to host
39993representation as needed. Datatypes are coerced into the host types.
39994
39995@item
fc320d37 39996@value{GDBN} calls the system call.
0ce1b118
CV
39997
39998@item
39999It then coerces datatypes back to protocol representation.
40000
40001@item
fc320d37
SL
40002If the system call is expected to return data in buffer space specified
40003by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
40004target using a @code{M} or @code{X} packet. This packet has to be expected
40005by the target implementation and is handled as any other @code{M} or @code{X}
40006packet.
40007
40008@end itemize
40009
40010Eventually @value{GDBN} replies with another @code{F} packet which contains all
40011necessary information for the target to continue. This at least contains
40012
40013@itemize @bullet
40014@item
40015Return value.
40016
40017@item
40018@code{errno}, if has been changed by the system call.
40019
40020@item
40021``Ctrl-C'' flag.
40022
40023@end itemize
40024
40025After having done the needed type and value coercion, the target continues
40026the latest continue or step action.
40027
79a6e687
BW
40028@node The F Request Packet
40029@subsection The @code{F} Request Packet
0ce1b118
CV
40030@cindex file-i/o request packet
40031@cindex @code{F} request packet
40032
40033The @code{F} request packet has the following format:
40034
40035@table @samp
fc320d37 40036@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
40037
40038@var{call-id} is the identifier to indicate the host system call to be called.
40039This is just the name of the function.
40040
fc320d37
SL
40041@var{parameter@dots{}} are the parameters to the system call.
40042Parameters are hexadecimal integer values, either the actual values in case
40043of scalar datatypes, pointers to target buffer space in case of compound
40044datatypes and unspecified memory areas, or pointer/length pairs in case
40045of string parameters. These are appended to the @var{call-id} as a
40046comma-delimited list. All values are transmitted in ASCII
40047string representation, pointer/length pairs separated by a slash.
0ce1b118 40048
b383017d 40049@end table
0ce1b118 40050
fc320d37 40051
0ce1b118 40052
79a6e687
BW
40053@node The F Reply Packet
40054@subsection The @code{F} Reply Packet
0ce1b118
CV
40055@cindex file-i/o reply packet
40056@cindex @code{F} reply packet
40057
40058The @code{F} reply packet has the following format:
40059
40060@table @samp
40061
d3bdde98 40062@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
40063
40064@var{retcode} is the return code of the system call as hexadecimal value.
40065
db2e3e2e
BW
40066@var{errno} is the @code{errno} set by the call, in protocol-specific
40067representation.
0ce1b118
CV
40068This parameter can be omitted if the call was successful.
40069
fc320d37
SL
40070@var{Ctrl-C flag} is only sent if the user requested a break. In this
40071case, @var{errno} must be sent as well, even if the call was successful.
40072The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
40073
40074@smallexample
40075F0,0,C
40076@end smallexample
40077
40078@noindent
fc320d37 40079or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
40080
40081@smallexample
40082F-1,4,C
40083@end smallexample
40084
40085@noindent
db2e3e2e 40086assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
40087
40088@end table
40089
0ce1b118 40090
79a6e687
BW
40091@node The Ctrl-C Message
40092@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
40093@cindex ctrl-c message, in file-i/o protocol
40094
c8aa23ab 40095If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 40096reply packet (@pxref{The F Reply Packet}),
fc320d37 40097the target should behave as if it had
0ce1b118 40098gotten a break message. The meaning for the target is ``system call
fc320d37 40099interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 40100(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 40101packet.
fc320d37
SL
40102
40103It's important for the target to know in which
40104state the system call was interrupted. There are two possible cases:
0ce1b118
CV
40105
40106@itemize @bullet
40107@item
40108The system call hasn't been performed on the host yet.
40109
40110@item
40111The system call on the host has been finished.
40112
40113@end itemize
40114
40115These two states can be distinguished by the target by the value of the
40116returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
40117call hasn't been performed. This is equivalent to the @code{EINTR} handling
40118on POSIX systems. In any other case, the target may presume that the
fc320d37 40119system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
40120as if the break message arrived right after the system call.
40121
fc320d37 40122@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
40123yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
40124@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
40125before the user requests a break, the full action must be finished by
40126@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
40127The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
40128or the full action has been completed.
40129
40130@node Console I/O
40131@subsection Console I/O
40132@cindex console i/o as part of file-i/o
40133
d3e8051b 40134By default and if not explicitly closed by the target system, the file
0ce1b118
CV
40135descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
40136on the @value{GDBN} console is handled as any other file output operation
40137(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
40138by @value{GDBN} so that after the target read request from file descriptor
401390 all following typing is buffered until either one of the following
40140conditions is met:
40141
40142@itemize @bullet
40143@item
c8aa23ab 40144The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
40145@code{read}
40146system call is treated as finished.
40147
40148@item
7f9087cb 40149The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 40150newline.
0ce1b118
CV
40151
40152@item
c8aa23ab
EZ
40153The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
40154character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
40155
40156@end itemize
40157
fc320d37
SL
40158If the user has typed more characters than fit in the buffer given to
40159the @code{read} call, the trailing characters are buffered in @value{GDBN} until
40160either another @code{read(0, @dots{})} is requested by the target, or debugging
40161is stopped at the user's request.
0ce1b118 40162
0ce1b118 40163
79a6e687
BW
40164@node List of Supported Calls
40165@subsection List of Supported Calls
0ce1b118
CV
40166@cindex list of supported file-i/o calls
40167
40168@menu
40169* open::
40170* close::
40171* read::
40172* write::
40173* lseek::
40174* rename::
40175* unlink::
40176* stat/fstat::
40177* gettimeofday::
40178* isatty::
40179* system::
40180@end menu
40181
40182@node open
40183@unnumberedsubsubsec open
40184@cindex open, file-i/o system call
40185
fc320d37
SL
40186@table @asis
40187@item Synopsis:
0ce1b118 40188@smallexample
0ce1b118
CV
40189int open(const char *pathname, int flags);
40190int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
40191@end smallexample
40192
fc320d37
SL
40193@item Request:
40194@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
40195
0ce1b118 40196@noindent
fc320d37 40197@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
40198
40199@table @code
b383017d 40200@item O_CREAT
0ce1b118
CV
40201If the file does not exist it will be created. The host
40202rules apply as far as file ownership and time stamps
40203are concerned.
40204
b383017d 40205@item O_EXCL
fc320d37 40206When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
40207an error and open() fails.
40208
b383017d 40209@item O_TRUNC
0ce1b118 40210If the file already exists and the open mode allows
fc320d37
SL
40211writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
40212truncated to zero length.
0ce1b118 40213
b383017d 40214@item O_APPEND
0ce1b118
CV
40215The file is opened in append mode.
40216
b383017d 40217@item O_RDONLY
0ce1b118
CV
40218The file is opened for reading only.
40219
b383017d 40220@item O_WRONLY
0ce1b118
CV
40221The file is opened for writing only.
40222
b383017d 40223@item O_RDWR
0ce1b118 40224The file is opened for reading and writing.
fc320d37 40225@end table
0ce1b118
CV
40226
40227@noindent
fc320d37 40228Other bits are silently ignored.
0ce1b118 40229
0ce1b118
CV
40230
40231@noindent
fc320d37 40232@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
40233
40234@table @code
b383017d 40235@item S_IRUSR
0ce1b118
CV
40236User has read permission.
40237
b383017d 40238@item S_IWUSR
0ce1b118
CV
40239User has write permission.
40240
b383017d 40241@item S_IRGRP
0ce1b118
CV
40242Group has read permission.
40243
b383017d 40244@item S_IWGRP
0ce1b118
CV
40245Group has write permission.
40246
b383017d 40247@item S_IROTH
0ce1b118
CV
40248Others have read permission.
40249
b383017d 40250@item S_IWOTH
0ce1b118 40251Others have write permission.
fc320d37 40252@end table
0ce1b118
CV
40253
40254@noindent
fc320d37 40255Other bits are silently ignored.
0ce1b118 40256
0ce1b118 40257
fc320d37
SL
40258@item Return value:
40259@code{open} returns the new file descriptor or -1 if an error
40260occurred.
0ce1b118 40261
fc320d37 40262@item Errors:
0ce1b118
CV
40263
40264@table @code
b383017d 40265@item EEXIST
fc320d37 40266@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 40267
b383017d 40268@item EISDIR
fc320d37 40269@var{pathname} refers to a directory.
0ce1b118 40270
b383017d 40271@item EACCES
0ce1b118
CV
40272The requested access is not allowed.
40273
40274@item ENAMETOOLONG
fc320d37 40275@var{pathname} was too long.
0ce1b118 40276
b383017d 40277@item ENOENT
fc320d37 40278A directory component in @var{pathname} does not exist.
0ce1b118 40279
b383017d 40280@item ENODEV
fc320d37 40281@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 40282
b383017d 40283@item EROFS
fc320d37 40284@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
40285write access was requested.
40286
b383017d 40287@item EFAULT
fc320d37 40288@var{pathname} is an invalid pointer value.
0ce1b118 40289
b383017d 40290@item ENOSPC
0ce1b118
CV
40291No space on device to create the file.
40292
b383017d 40293@item EMFILE
0ce1b118
CV
40294The process already has the maximum number of files open.
40295
b383017d 40296@item ENFILE
0ce1b118
CV
40297The limit on the total number of files open on the system
40298has been reached.
40299
b383017d 40300@item EINTR
0ce1b118
CV
40301The call was interrupted by the user.
40302@end table
40303
fc320d37
SL
40304@end table
40305
0ce1b118
CV
40306@node close
40307@unnumberedsubsubsec close
40308@cindex close, file-i/o system call
40309
fc320d37
SL
40310@table @asis
40311@item Synopsis:
0ce1b118 40312@smallexample
0ce1b118 40313int close(int fd);
fc320d37 40314@end smallexample
0ce1b118 40315
fc320d37
SL
40316@item Request:
40317@samp{Fclose,@var{fd}}
0ce1b118 40318
fc320d37
SL
40319@item Return value:
40320@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 40321
fc320d37 40322@item Errors:
0ce1b118
CV
40323
40324@table @code
b383017d 40325@item EBADF
fc320d37 40326@var{fd} isn't a valid open file descriptor.
0ce1b118 40327
b383017d 40328@item EINTR
0ce1b118
CV
40329The call was interrupted by the user.
40330@end table
40331
fc320d37
SL
40332@end table
40333
0ce1b118
CV
40334@node read
40335@unnumberedsubsubsec read
40336@cindex read, file-i/o system call
40337
fc320d37
SL
40338@table @asis
40339@item Synopsis:
0ce1b118 40340@smallexample
0ce1b118 40341int read(int fd, void *buf, unsigned int count);
fc320d37 40342@end smallexample
0ce1b118 40343
fc320d37
SL
40344@item Request:
40345@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 40346
fc320d37 40347@item Return value:
0ce1b118
CV
40348On success, the number of bytes read is returned.
40349Zero indicates end of file. If count is zero, read
b383017d 40350returns zero as well. On error, -1 is returned.
0ce1b118 40351
fc320d37 40352@item Errors:
0ce1b118
CV
40353
40354@table @code
b383017d 40355@item EBADF
fc320d37 40356@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
40357reading.
40358
b383017d 40359@item EFAULT
fc320d37 40360@var{bufptr} is an invalid pointer value.
0ce1b118 40361
b383017d 40362@item EINTR
0ce1b118
CV
40363The call was interrupted by the user.
40364@end table
40365
fc320d37
SL
40366@end table
40367
0ce1b118
CV
40368@node write
40369@unnumberedsubsubsec write
40370@cindex write, file-i/o system call
40371
fc320d37
SL
40372@table @asis
40373@item Synopsis:
0ce1b118 40374@smallexample
0ce1b118 40375int write(int fd, const void *buf, unsigned int count);
fc320d37 40376@end smallexample
0ce1b118 40377
fc320d37
SL
40378@item Request:
40379@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 40380
fc320d37 40381@item Return value:
0ce1b118
CV
40382On success, the number of bytes written are returned.
40383Zero indicates nothing was written. On error, -1
40384is returned.
40385
fc320d37 40386@item Errors:
0ce1b118
CV
40387
40388@table @code
b383017d 40389@item EBADF
fc320d37 40390@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
40391writing.
40392
b383017d 40393@item EFAULT
fc320d37 40394@var{bufptr} is an invalid pointer value.
0ce1b118 40395
b383017d 40396@item EFBIG
0ce1b118 40397An attempt was made to write a file that exceeds the
db2e3e2e 40398host-specific maximum file size allowed.
0ce1b118 40399
b383017d 40400@item ENOSPC
0ce1b118
CV
40401No space on device to write the data.
40402
b383017d 40403@item EINTR
0ce1b118
CV
40404The call was interrupted by the user.
40405@end table
40406
fc320d37
SL
40407@end table
40408
0ce1b118
CV
40409@node lseek
40410@unnumberedsubsubsec lseek
40411@cindex lseek, file-i/o system call
40412
fc320d37
SL
40413@table @asis
40414@item Synopsis:
0ce1b118 40415@smallexample
0ce1b118 40416long lseek (int fd, long offset, int flag);
0ce1b118
CV
40417@end smallexample
40418
fc320d37
SL
40419@item Request:
40420@samp{Flseek,@var{fd},@var{offset},@var{flag}}
40421
40422@var{flag} is one of:
0ce1b118
CV
40423
40424@table @code
b383017d 40425@item SEEK_SET
fc320d37 40426The offset is set to @var{offset} bytes.
0ce1b118 40427
b383017d 40428@item SEEK_CUR
fc320d37 40429The offset is set to its current location plus @var{offset}
0ce1b118
CV
40430bytes.
40431
b383017d 40432@item SEEK_END
fc320d37 40433The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
40434bytes.
40435@end table
40436
fc320d37 40437@item Return value:
0ce1b118
CV
40438On success, the resulting unsigned offset in bytes from
40439the beginning of the file is returned. Otherwise, a
40440value of -1 is returned.
40441
fc320d37 40442@item Errors:
0ce1b118
CV
40443
40444@table @code
b383017d 40445@item EBADF
fc320d37 40446@var{fd} is not a valid open file descriptor.
0ce1b118 40447
b383017d 40448@item ESPIPE
fc320d37 40449@var{fd} is associated with the @value{GDBN} console.
0ce1b118 40450
b383017d 40451@item EINVAL
fc320d37 40452@var{flag} is not a proper value.
0ce1b118 40453
b383017d 40454@item EINTR
0ce1b118
CV
40455The call was interrupted by the user.
40456@end table
40457
fc320d37
SL
40458@end table
40459
0ce1b118
CV
40460@node rename
40461@unnumberedsubsubsec rename
40462@cindex rename, file-i/o system call
40463
fc320d37
SL
40464@table @asis
40465@item Synopsis:
0ce1b118 40466@smallexample
0ce1b118 40467int rename(const char *oldpath, const char *newpath);
fc320d37 40468@end smallexample
0ce1b118 40469
fc320d37
SL
40470@item Request:
40471@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 40472
fc320d37 40473@item Return value:
0ce1b118
CV
40474On success, zero is returned. On error, -1 is returned.
40475
fc320d37 40476@item Errors:
0ce1b118
CV
40477
40478@table @code
b383017d 40479@item EISDIR
fc320d37 40480@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
40481directory.
40482
b383017d 40483@item EEXIST
fc320d37 40484@var{newpath} is a non-empty directory.
0ce1b118 40485
b383017d 40486@item EBUSY
fc320d37 40487@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
40488process.
40489
b383017d 40490@item EINVAL
0ce1b118
CV
40491An attempt was made to make a directory a subdirectory
40492of itself.
40493
b383017d 40494@item ENOTDIR
fc320d37
SL
40495A component used as a directory in @var{oldpath} or new
40496path is not a directory. Or @var{oldpath} is a directory
40497and @var{newpath} exists but is not a directory.
0ce1b118 40498
b383017d 40499@item EFAULT
fc320d37 40500@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 40501
b383017d 40502@item EACCES
0ce1b118
CV
40503No access to the file or the path of the file.
40504
40505@item ENAMETOOLONG
b383017d 40506
fc320d37 40507@var{oldpath} or @var{newpath} was too long.
0ce1b118 40508
b383017d 40509@item ENOENT
fc320d37 40510A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 40511
b383017d 40512@item EROFS
0ce1b118
CV
40513The file is on a read-only filesystem.
40514
b383017d 40515@item ENOSPC
0ce1b118
CV
40516The device containing the file has no room for the new
40517directory entry.
40518
b383017d 40519@item EINTR
0ce1b118
CV
40520The call was interrupted by the user.
40521@end table
40522
fc320d37
SL
40523@end table
40524
0ce1b118
CV
40525@node unlink
40526@unnumberedsubsubsec unlink
40527@cindex unlink, file-i/o system call
40528
fc320d37
SL
40529@table @asis
40530@item Synopsis:
0ce1b118 40531@smallexample
0ce1b118 40532int unlink(const char *pathname);
fc320d37 40533@end smallexample
0ce1b118 40534
fc320d37
SL
40535@item Request:
40536@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 40537
fc320d37 40538@item Return value:
0ce1b118
CV
40539On success, zero is returned. On error, -1 is returned.
40540
fc320d37 40541@item Errors:
0ce1b118
CV
40542
40543@table @code
b383017d 40544@item EACCES
0ce1b118
CV
40545No access to the file or the path of the file.
40546
b383017d 40547@item EPERM
0ce1b118
CV
40548The system does not allow unlinking of directories.
40549
b383017d 40550@item EBUSY
fc320d37 40551The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
40552being used by another process.
40553
b383017d 40554@item EFAULT
fc320d37 40555@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
40556
40557@item ENAMETOOLONG
fc320d37 40558@var{pathname} was too long.
0ce1b118 40559
b383017d 40560@item ENOENT
fc320d37 40561A directory component in @var{pathname} does not exist.
0ce1b118 40562
b383017d 40563@item ENOTDIR
0ce1b118
CV
40564A component of the path is not a directory.
40565
b383017d 40566@item EROFS
0ce1b118
CV
40567The file is on a read-only filesystem.
40568
b383017d 40569@item EINTR
0ce1b118
CV
40570The call was interrupted by the user.
40571@end table
40572
fc320d37
SL
40573@end table
40574
0ce1b118
CV
40575@node stat/fstat
40576@unnumberedsubsubsec stat/fstat
40577@cindex fstat, file-i/o system call
40578@cindex stat, file-i/o system call
40579
fc320d37
SL
40580@table @asis
40581@item Synopsis:
0ce1b118 40582@smallexample
0ce1b118
CV
40583int stat(const char *pathname, struct stat *buf);
40584int fstat(int fd, struct stat *buf);
fc320d37 40585@end smallexample
0ce1b118 40586
fc320d37
SL
40587@item Request:
40588@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
40589@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 40590
fc320d37 40591@item Return value:
0ce1b118
CV
40592On success, zero is returned. On error, -1 is returned.
40593
fc320d37 40594@item Errors:
0ce1b118
CV
40595
40596@table @code
b383017d 40597@item EBADF
fc320d37 40598@var{fd} is not a valid open file.
0ce1b118 40599
b383017d 40600@item ENOENT
fc320d37 40601A directory component in @var{pathname} does not exist or the
0ce1b118
CV
40602path is an empty string.
40603
b383017d 40604@item ENOTDIR
0ce1b118
CV
40605A component of the path is not a directory.
40606
b383017d 40607@item EFAULT
fc320d37 40608@var{pathnameptr} is an invalid pointer value.
0ce1b118 40609
b383017d 40610@item EACCES
0ce1b118
CV
40611No access to the file or the path of the file.
40612
40613@item ENAMETOOLONG
fc320d37 40614@var{pathname} was too long.
0ce1b118 40615
b383017d 40616@item EINTR
0ce1b118
CV
40617The call was interrupted by the user.
40618@end table
40619
fc320d37
SL
40620@end table
40621
0ce1b118
CV
40622@node gettimeofday
40623@unnumberedsubsubsec gettimeofday
40624@cindex gettimeofday, file-i/o system call
40625
fc320d37
SL
40626@table @asis
40627@item Synopsis:
0ce1b118 40628@smallexample
0ce1b118 40629int gettimeofday(struct timeval *tv, void *tz);
fc320d37 40630@end smallexample
0ce1b118 40631
fc320d37
SL
40632@item Request:
40633@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 40634
fc320d37 40635@item Return value:
0ce1b118
CV
40636On success, 0 is returned, -1 otherwise.
40637
fc320d37 40638@item Errors:
0ce1b118
CV
40639
40640@table @code
b383017d 40641@item EINVAL
fc320d37 40642@var{tz} is a non-NULL pointer.
0ce1b118 40643
b383017d 40644@item EFAULT
fc320d37
SL
40645@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
40646@end table
40647
0ce1b118
CV
40648@end table
40649
40650@node isatty
40651@unnumberedsubsubsec isatty
40652@cindex isatty, file-i/o system call
40653
fc320d37
SL
40654@table @asis
40655@item Synopsis:
0ce1b118 40656@smallexample
0ce1b118 40657int isatty(int fd);
fc320d37 40658@end smallexample
0ce1b118 40659
fc320d37
SL
40660@item Request:
40661@samp{Fisatty,@var{fd}}
0ce1b118 40662
fc320d37
SL
40663@item Return value:
40664Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 40665
fc320d37 40666@item Errors:
0ce1b118
CV
40667
40668@table @code
b383017d 40669@item EINTR
0ce1b118
CV
40670The call was interrupted by the user.
40671@end table
40672
fc320d37
SL
40673@end table
40674
40675Note that the @code{isatty} call is treated as a special case: it returns
406761 to the target if the file descriptor is attached
40677to the @value{GDBN} console, 0 otherwise. Implementing through system calls
40678would require implementing @code{ioctl} and would be more complex than
40679needed.
40680
40681
0ce1b118
CV
40682@node system
40683@unnumberedsubsubsec system
40684@cindex system, file-i/o system call
40685
fc320d37
SL
40686@table @asis
40687@item Synopsis:
0ce1b118 40688@smallexample
0ce1b118 40689int system(const char *command);
fc320d37 40690@end smallexample
0ce1b118 40691
fc320d37
SL
40692@item Request:
40693@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 40694
fc320d37 40695@item Return value:
5600ea19
NS
40696If @var{len} is zero, the return value indicates whether a shell is
40697available. A zero return value indicates a shell is not available.
40698For non-zero @var{len}, the value returned is -1 on error and the
40699return status of the command otherwise. Only the exit status of the
40700command is returned, which is extracted from the host's @code{system}
40701return value by calling @code{WEXITSTATUS(retval)}. In case
40702@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 40703
fc320d37 40704@item Errors:
0ce1b118
CV
40705
40706@table @code
b383017d 40707@item EINTR
0ce1b118
CV
40708The call was interrupted by the user.
40709@end table
40710
fc320d37
SL
40711@end table
40712
40713@value{GDBN} takes over the full task of calling the necessary host calls
40714to perform the @code{system} call. The return value of @code{system} on
40715the host is simplified before it's returned
40716to the target. Any termination signal information from the child process
40717is discarded, and the return value consists
40718entirely of the exit status of the called command.
40719
40720Due to security concerns, the @code{system} call is by default refused
40721by @value{GDBN}. The user has to allow this call explicitly with the
40722@code{set remote system-call-allowed 1} command.
40723
40724@table @code
40725@item set remote system-call-allowed
40726@kindex set remote system-call-allowed
40727Control whether to allow the @code{system} calls in the File I/O
40728protocol for the remote target. The default is zero (disabled).
40729
40730@item show remote system-call-allowed
40731@kindex show remote system-call-allowed
40732Show whether the @code{system} calls are allowed in the File I/O
40733protocol.
40734@end table
40735
db2e3e2e
BW
40736@node Protocol-specific Representation of Datatypes
40737@subsection Protocol-specific Representation of Datatypes
40738@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
40739
40740@menu
79a6e687
BW
40741* Integral Datatypes::
40742* Pointer Values::
40743* Memory Transfer::
0ce1b118
CV
40744* struct stat::
40745* struct timeval::
40746@end menu
40747
79a6e687
BW
40748@node Integral Datatypes
40749@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
40750@cindex integral datatypes, in file-i/o protocol
40751
fc320d37
SL
40752The integral datatypes used in the system calls are @code{int},
40753@code{unsigned int}, @code{long}, @code{unsigned long},
40754@code{mode_t}, and @code{time_t}.
0ce1b118 40755
fc320d37 40756@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
40757implemented as 32 bit values in this protocol.
40758
fc320d37 40759@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 40760
0ce1b118
CV
40761@xref{Limits}, for corresponding MIN and MAX values (similar to those
40762in @file{limits.h}) to allow range checking on host and target.
40763
40764@code{time_t} datatypes are defined as seconds since the Epoch.
40765
40766All integral datatypes transferred as part of a memory read or write of a
40767structured datatype e.g.@: a @code{struct stat} have to be given in big endian
40768byte order.
40769
79a6e687
BW
40770@node Pointer Values
40771@unnumberedsubsubsec Pointer Values
0ce1b118
CV
40772@cindex pointer values, in file-i/o protocol
40773
40774Pointers to target data are transmitted as they are. An exception
40775is made for pointers to buffers for which the length isn't
40776transmitted as part of the function call, namely strings. Strings
40777are transmitted as a pointer/length pair, both as hex values, e.g.@:
40778
40779@smallexample
40780@code{1aaf/12}
40781@end smallexample
40782
40783@noindent
40784which is a pointer to data of length 18 bytes at position 0x1aaf.
40785The length is defined as the full string length in bytes, including
fc320d37
SL
40786the trailing null byte. For example, the string @code{"hello world"}
40787at address 0x123456 is transmitted as
0ce1b118
CV
40788
40789@smallexample
fc320d37 40790@code{123456/d}
0ce1b118
CV
40791@end smallexample
40792
79a6e687
BW
40793@node Memory Transfer
40794@unnumberedsubsubsec Memory Transfer
fc320d37
SL
40795@cindex memory transfer, in file-i/o protocol
40796
40797Structured data which is transferred using a memory read or write (for
db2e3e2e 40798example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
40799with all scalar multibyte datatypes being big endian. Translation to
40800this representation needs to be done both by the target before the @code{F}
40801packet is sent, and by @value{GDBN} before
40802it transfers memory to the target. Transferred pointers to structured
40803data should point to the already-coerced data at any time.
0ce1b118 40804
0ce1b118
CV
40805
40806@node struct stat
40807@unnumberedsubsubsec struct stat
40808@cindex struct stat, in file-i/o protocol
40809
fc320d37
SL
40810The buffer of type @code{struct stat} used by the target and @value{GDBN}
40811is defined as follows:
0ce1b118
CV
40812
40813@smallexample
40814struct stat @{
40815 unsigned int st_dev; /* device */
40816 unsigned int st_ino; /* inode */
40817 mode_t st_mode; /* protection */
40818 unsigned int st_nlink; /* number of hard links */
40819 unsigned int st_uid; /* user ID of owner */
40820 unsigned int st_gid; /* group ID of owner */
40821 unsigned int st_rdev; /* device type (if inode device) */
40822 unsigned long st_size; /* total size, in bytes */
40823 unsigned long st_blksize; /* blocksize for filesystem I/O */
40824 unsigned long st_blocks; /* number of blocks allocated */
40825 time_t st_atime; /* time of last access */
40826 time_t st_mtime; /* time of last modification */
40827 time_t st_ctime; /* time of last change */
40828@};
40829@end smallexample
40830
fc320d37 40831The integral datatypes conform to the definitions given in the
79a6e687 40832appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
40833structure is of size 64 bytes.
40834
40835The values of several fields have a restricted meaning and/or
40836range of values.
40837
fc320d37 40838@table @code
0ce1b118 40839
fc320d37
SL
40840@item st_dev
40841A value of 0 represents a file, 1 the console.
0ce1b118 40842
fc320d37
SL
40843@item st_ino
40844No valid meaning for the target. Transmitted unchanged.
0ce1b118 40845
fc320d37
SL
40846@item st_mode
40847Valid mode bits are described in @ref{Constants}. Any other
40848bits have currently no meaning for the target.
0ce1b118 40849
fc320d37
SL
40850@item st_uid
40851@itemx st_gid
40852@itemx st_rdev
40853No valid meaning for the target. Transmitted unchanged.
0ce1b118 40854
fc320d37
SL
40855@item st_atime
40856@itemx st_mtime
40857@itemx st_ctime
40858These values have a host and file system dependent
40859accuracy. Especially on Windows hosts, the file system may not
40860support exact timing values.
40861@end table
0ce1b118 40862
fc320d37
SL
40863The target gets a @code{struct stat} of the above representation and is
40864responsible for coercing it to the target representation before
0ce1b118
CV
40865continuing.
40866
fc320d37
SL
40867Note that due to size differences between the host, target, and protocol
40868representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
40869get truncated on the target.
40870
40871@node struct timeval
40872@unnumberedsubsubsec struct timeval
40873@cindex struct timeval, in file-i/o protocol
40874
fc320d37 40875The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
40876is defined as follows:
40877
40878@smallexample
b383017d 40879struct timeval @{
0ce1b118
CV
40880 time_t tv_sec; /* second */
40881 long tv_usec; /* microsecond */
40882@};
40883@end smallexample
40884
fc320d37 40885The integral datatypes conform to the definitions given in the
79a6e687 40886appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
40887structure is of size 8 bytes.
40888
40889@node Constants
40890@subsection Constants
40891@cindex constants, in file-i/o protocol
40892
40893The following values are used for the constants inside of the
fc320d37 40894protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
40895values before and after the call as needed.
40896
40897@menu
79a6e687
BW
40898* Open Flags::
40899* mode_t Values::
40900* Errno Values::
40901* Lseek Flags::
0ce1b118
CV
40902* Limits::
40903@end menu
40904
79a6e687
BW
40905@node Open Flags
40906@unnumberedsubsubsec Open Flags
0ce1b118
CV
40907@cindex open flags, in file-i/o protocol
40908
40909All values are given in hexadecimal representation.
40910
40911@smallexample
40912 O_RDONLY 0x0
40913 O_WRONLY 0x1
40914 O_RDWR 0x2
40915 O_APPEND 0x8
40916 O_CREAT 0x200
40917 O_TRUNC 0x400
40918 O_EXCL 0x800
40919@end smallexample
40920
79a6e687
BW
40921@node mode_t Values
40922@unnumberedsubsubsec mode_t Values
0ce1b118
CV
40923@cindex mode_t values, in file-i/o protocol
40924
40925All values are given in octal representation.
40926
40927@smallexample
40928 S_IFREG 0100000
40929 S_IFDIR 040000
40930 S_IRUSR 0400
40931 S_IWUSR 0200
40932 S_IXUSR 0100
40933 S_IRGRP 040
40934 S_IWGRP 020
40935 S_IXGRP 010
40936 S_IROTH 04
40937 S_IWOTH 02
40938 S_IXOTH 01
40939@end smallexample
40940
79a6e687
BW
40941@node Errno Values
40942@unnumberedsubsubsec Errno Values
0ce1b118
CV
40943@cindex errno values, in file-i/o protocol
40944
40945All values are given in decimal representation.
40946
40947@smallexample
40948 EPERM 1
40949 ENOENT 2
40950 EINTR 4
40951 EBADF 9
40952 EACCES 13
40953 EFAULT 14
40954 EBUSY 16
40955 EEXIST 17
40956 ENODEV 19
40957 ENOTDIR 20
40958 EISDIR 21
40959 EINVAL 22
40960 ENFILE 23
40961 EMFILE 24
40962 EFBIG 27
40963 ENOSPC 28
40964 ESPIPE 29
40965 EROFS 30
40966 ENAMETOOLONG 91
40967 EUNKNOWN 9999
40968@end smallexample
40969
fc320d37 40970 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
40971 any error value not in the list of supported error numbers.
40972
79a6e687
BW
40973@node Lseek Flags
40974@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
40975@cindex lseek flags, in file-i/o protocol
40976
40977@smallexample
40978 SEEK_SET 0
40979 SEEK_CUR 1
40980 SEEK_END 2
40981@end smallexample
40982
40983@node Limits
40984@unnumberedsubsubsec Limits
40985@cindex limits, in file-i/o protocol
40986
40987All values are given in decimal representation.
40988
40989@smallexample
40990 INT_MIN -2147483648
40991 INT_MAX 2147483647
40992 UINT_MAX 4294967295
40993 LONG_MIN -9223372036854775808
40994 LONG_MAX 9223372036854775807
40995 ULONG_MAX 18446744073709551615
40996@end smallexample
40997
40998@node File-I/O Examples
40999@subsection File-I/O Examples
41000@cindex file-i/o examples
41001
41002Example sequence of a write call, file descriptor 3, buffer is at target
41003address 0x1234, 6 bytes should be written:
41004
41005@smallexample
41006<- @code{Fwrite,3,1234,6}
41007@emph{request memory read from target}
41008-> @code{m1234,6}
41009<- XXXXXX
41010@emph{return "6 bytes written"}
41011-> @code{F6}
41012@end smallexample
41013
41014Example sequence of a read call, file descriptor 3, buffer is at target
41015address 0x1234, 6 bytes should be read:
41016
41017@smallexample
41018<- @code{Fread,3,1234,6}
41019@emph{request memory write to target}
41020-> @code{X1234,6:XXXXXX}
41021@emph{return "6 bytes read"}
41022-> @code{F6}
41023@end smallexample
41024
41025Example sequence of a read call, call fails on the host due to invalid
fc320d37 41026file descriptor (@code{EBADF}):
0ce1b118
CV
41027
41028@smallexample
41029<- @code{Fread,3,1234,6}
41030-> @code{F-1,9}
41031@end smallexample
41032
c8aa23ab 41033Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
41034host is called:
41035
41036@smallexample
41037<- @code{Fread,3,1234,6}
41038-> @code{F-1,4,C}
41039<- @code{T02}
41040@end smallexample
41041
c8aa23ab 41042Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
41043host is called:
41044
41045@smallexample
41046<- @code{Fread,3,1234,6}
41047-> @code{X1234,6:XXXXXX}
41048<- @code{T02}
41049@end smallexample
41050
cfa9d6d9
DJ
41051@node Library List Format
41052@section Library List Format
41053@cindex library list format, remote protocol
41054
41055On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
41056same process as your application to manage libraries. In this case,
41057@value{GDBN} can use the loader's symbol table and normal memory
41058operations to maintain a list of shared libraries. On other
41059platforms, the operating system manages loaded libraries.
41060@value{GDBN} can not retrieve the list of currently loaded libraries
41061through memory operations, so it uses the @samp{qXfer:libraries:read}
41062packet (@pxref{qXfer library list read}) instead. The remote stub
41063queries the target's operating system and reports which libraries
41064are loaded.
41065
41066The @samp{qXfer:libraries:read} packet returns an XML document which
41067lists loaded libraries and their offsets. Each library has an
1fddbabb
PA
41068associated name and one or more segment or section base addresses,
41069which report where the library was loaded in memory.
41070
41071For the common case of libraries that are fully linked binaries, the
41072library should have a list of segments. If the target supports
41073dynamic linking of a relocatable object file, its library XML element
41074should instead include a list of allocated sections. The segment or
41075section bases are start addresses, not relocation offsets; they do not
41076depend on the library's link-time base addresses.
cfa9d6d9 41077
9cceb671
DJ
41078@value{GDBN} must be linked with the Expat library to support XML
41079library lists. @xref{Expat}.
41080
cfa9d6d9
DJ
41081A simple memory map, with one loaded library relocated by a single
41082offset, looks like this:
41083
41084@smallexample
41085<library-list>
41086 <library name="/lib/libc.so.6">
41087 <segment address="0x10000000"/>
41088 </library>
41089</library-list>
41090@end smallexample
41091
1fddbabb
PA
41092Another simple memory map, with one loaded library with three
41093allocated sections (.text, .data, .bss), looks like this:
41094
41095@smallexample
41096<library-list>
41097 <library name="sharedlib.o">
41098 <section address="0x10000000"/>
41099 <section address="0x20000000"/>
41100 <section address="0x30000000"/>
41101 </library>
41102</library-list>
41103@end smallexample
41104
cfa9d6d9
DJ
41105The format of a library list is described by this DTD:
41106
41107@smallexample
41108<!-- library-list: Root element with versioning -->
41109<!ELEMENT library-list (library)*>
41110<!ATTLIST library-list version CDATA #FIXED "1.0">
1fddbabb 41111<!ELEMENT library (segment*, section*)>
cfa9d6d9
DJ
41112<!ATTLIST library name CDATA #REQUIRED>
41113<!ELEMENT segment EMPTY>
41114<!ATTLIST segment address CDATA #REQUIRED>
1fddbabb
PA
41115<!ELEMENT section EMPTY>
41116<!ATTLIST section address CDATA #REQUIRED>
cfa9d6d9
DJ
41117@end smallexample
41118
1fddbabb
PA
41119In addition, segments and section descriptors cannot be mixed within a
41120single library element, and you must supply at least one segment or
41121section for each library.
41122
2268b414
JK
41123@node Library List Format for SVR4 Targets
41124@section Library List Format for SVR4 Targets
41125@cindex library list format, remote protocol
41126
41127On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
41128(e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
41129shared libraries. Still a special library list provided by this packet is
41130more efficient for the @value{GDBN} remote protocol.
41131
41132The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
41133loaded libraries and their SVR4 linker parameters. For each library on SVR4
41134target, the following parameters are reported:
41135
41136@itemize @minus
41137@item
41138@code{name}, the absolute file name from the @code{l_name} field of
41139@code{struct link_map}.
41140@item
41141@code{lm} with address of @code{struct link_map} used for TLS
41142(Thread Local Storage) access.
41143@item
41144@code{l_addr}, the displacement as read from the field @code{l_addr} of
41145@code{struct link_map}. For prelinked libraries this is not an absolute
41146memory address. It is a displacement of absolute memory address against
41147address the file was prelinked to during the library load.
41148@item
41149@code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
41150@end itemize
41151
41152Additionally the single @code{main-lm} attribute specifies address of
41153@code{struct link_map} used for the main executable. This parameter is used
41154for TLS access and its presence is optional.
41155
41156@value{GDBN} must be linked with the Expat library to support XML
41157SVR4 library lists. @xref{Expat}.
41158
41159A simple memory map, with two loaded libraries (which do not use prelink),
41160looks like this:
41161
41162@smallexample
41163<library-list-svr4 version="1.0" main-lm="0xe4f8f8">
41164 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
41165 l_ld="0xe4eefc"/>
41166 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
db1ff28b 41167 l_ld="0x152350"/>
2268b414
JK
41168</library-list-svr>
41169@end smallexample
41170
41171The format of an SVR4 library list is described by this DTD:
41172
41173@smallexample
41174<!-- library-list-svr4: Root element with versioning -->
41175<!ELEMENT library-list-svr4 (library)*>
db1ff28b
JK
41176<!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
41177<!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
2268b414 41178<!ELEMENT library EMPTY>
db1ff28b
JK
41179<!ATTLIST library name CDATA #REQUIRED>
41180<!ATTLIST library lm CDATA #REQUIRED>
41181<!ATTLIST library l_addr CDATA #REQUIRED>
41182<!ATTLIST library l_ld CDATA #REQUIRED>
2268b414
JK
41183@end smallexample
41184
79a6e687
BW
41185@node Memory Map Format
41186@section Memory Map Format
68437a39
DJ
41187@cindex memory map format
41188
41189To be able to write into flash memory, @value{GDBN} needs to obtain a
41190memory map from the target. This section describes the format of the
41191memory map.
41192
41193The memory map is obtained using the @samp{qXfer:memory-map:read}
41194(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
41195lists memory regions.
41196
41197@value{GDBN} must be linked with the Expat library to support XML
41198memory maps. @xref{Expat}.
41199
41200The top-level structure of the document is shown below:
68437a39
DJ
41201
41202@smallexample
41203<?xml version="1.0"?>
41204<!DOCTYPE memory-map
41205 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
41206 "http://sourceware.org/gdb/gdb-memory-map.dtd">
41207<memory-map>
41208 region...
41209</memory-map>
41210@end smallexample
41211
41212Each region can be either:
41213
41214@itemize
41215
41216@item
41217A region of RAM starting at @var{addr} and extending for @var{length}
41218bytes from there:
41219
41220@smallexample
41221<memory type="ram" start="@var{addr}" length="@var{length}"/>
41222@end smallexample
41223
41224
41225@item
41226A region of read-only memory:
41227
41228@smallexample
41229<memory type="rom" start="@var{addr}" length="@var{length}"/>
41230@end smallexample
41231
41232
41233@item
41234A region of flash memory, with erasure blocks @var{blocksize}
41235bytes in length:
41236
41237@smallexample
41238<memory type="flash" start="@var{addr}" length="@var{length}">
41239 <property name="blocksize">@var{blocksize}</property>
41240</memory>
41241@end smallexample
41242
41243@end itemize
41244
41245Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
41246by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
41247packets to write to addresses in such ranges.
41248
41249The formal DTD for memory map format is given below:
41250
41251@smallexample
41252<!-- ................................................... -->
41253<!-- Memory Map XML DTD ................................ -->
41254<!-- File: memory-map.dtd .............................. -->
41255<!-- .................................... .............. -->
41256<!-- memory-map.dtd -->
41257<!-- memory-map: Root element with versioning -->
5f1ca24a 41258<!ELEMENT memory-map (memory)*>
68437a39 41259<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
5f1ca24a 41260<!ELEMENT memory (property)*>
68437a39
DJ
41261<!-- memory: Specifies a memory region,
41262 and its type, or device. -->
5f1ca24a 41263<!ATTLIST memory type (ram|rom|flash) #REQUIRED
68437a39 41264 start CDATA #REQUIRED
5f1ca24a 41265 length CDATA #REQUIRED>
68437a39
DJ
41266<!-- property: Generic attribute tag -->
41267<!ELEMENT property (#PCDATA | property)*>
5f1ca24a 41268<!ATTLIST property name (blocksize) #REQUIRED>
68437a39
DJ
41269@end smallexample
41270
dc146f7c
VP
41271@node Thread List Format
41272@section Thread List Format
41273@cindex thread list format
41274
41275To efficiently update the list of threads and their attributes,
41276@value{GDBN} issues the @samp{qXfer:threads:read} packet
41277(@pxref{qXfer threads read}) and obtains the XML document with
41278the following structure:
41279
41280@smallexample
41281<?xml version="1.0"?>
41282<threads>
79efa585 41283 <thread id="id" core="0" name="name">
dc146f7c
VP
41284 ... description ...
41285 </thread>
41286</threads>
41287@end smallexample
41288
41289Each @samp{thread} element must have the @samp{id} attribute that
41290identifies the thread (@pxref{thread-id syntax}). The
41291@samp{core} attribute, if present, specifies which processor core
79efa585
SM
41292the thread was last executing on. The @samp{name} attribute, if
41293present, specifies the human-readable name of the thread. The content
41294of the of @samp{thread} element is interpreted as human-readable
f2ff95c5
KB
41295auxiliary information. The @samp{handle} attribute, if present,
41296is a hex encoded representation of the thread handle.
41297
dc146f7c 41298
b3b9301e
PA
41299@node Traceframe Info Format
41300@section Traceframe Info Format
41301@cindex traceframe info format
41302
41303To be able to know which objects in the inferior can be examined when
41304inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
41305memory ranges, registers and trace state variables that have been
41306collected in a traceframe.
41307
41308This list is obtained using the @samp{qXfer:traceframe-info:read}
41309(@pxref{qXfer traceframe info read}) packet and is an XML document.
41310
41311@value{GDBN} must be linked with the Expat library to support XML
41312traceframe info discovery. @xref{Expat}.
41313
41314The top-level structure of the document is shown below:
41315
41316@smallexample
41317<?xml version="1.0"?>
41318<!DOCTYPE traceframe-info
41319 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
41320 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
41321<traceframe-info>
41322 block...
41323</traceframe-info>
41324@end smallexample
41325
41326Each traceframe block can be either:
41327
41328@itemize
41329
41330@item
41331A region of collected memory starting at @var{addr} and extending for
41332@var{length} bytes from there:
41333
41334@smallexample
41335<memory start="@var{addr}" length="@var{length}"/>
41336@end smallexample
41337
28a93511
YQ
41338@item
41339A block indicating trace state variable numbered @var{number} has been
41340collected:
41341
41342@smallexample
41343<tvar id="@var{number}"/>
41344@end smallexample
41345
b3b9301e
PA
41346@end itemize
41347
41348The formal DTD for the traceframe info format is given below:
41349
41350@smallexample
28a93511 41351<!ELEMENT traceframe-info (memory | tvar)* >
b3b9301e
PA
41352<!ATTLIST traceframe-info version CDATA #FIXED "1.0">
41353
41354<!ELEMENT memory EMPTY>
41355<!ATTLIST memory start CDATA #REQUIRED
41356 length CDATA #REQUIRED>
28a93511
YQ
41357<!ELEMENT tvar>
41358<!ATTLIST tvar id CDATA #REQUIRED>
b3b9301e
PA
41359@end smallexample
41360
2ae8c8e7
MM
41361@node Branch Trace Format
41362@section Branch Trace Format
41363@cindex branch trace format
41364
41365In order to display the branch trace of an inferior thread,
41366@value{GDBN} needs to obtain the list of branches. This list is
41367represented as list of sequential code blocks that are connected via
41368branches. The code in each block has been executed sequentially.
41369
41370This list is obtained using the @samp{qXfer:btrace:read}
41371(@pxref{qXfer btrace read}) packet and is an XML document.
41372
41373@value{GDBN} must be linked with the Expat library to support XML
41374traceframe info discovery. @xref{Expat}.
41375
41376The top-level structure of the document is shown below:
41377
41378@smallexample
41379<?xml version="1.0"?>
41380<!DOCTYPE btrace
41381 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
41382 "http://sourceware.org/gdb/gdb-btrace.dtd">
41383<btrace>
41384 block...
41385</btrace>
41386@end smallexample
41387
41388@itemize
41389
41390@item
41391A block of sequentially executed instructions starting at @var{begin}
41392and ending at @var{end}:
41393
41394@smallexample
41395<block begin="@var{begin}" end="@var{end}"/>
41396@end smallexample
41397
41398@end itemize
41399
41400The formal DTD for the branch trace format is given below:
41401
41402@smallexample
b20a6524 41403<!ELEMENT btrace (block* | pt) >
2ae8c8e7
MM
41404<!ATTLIST btrace version CDATA #FIXED "1.0">
41405
41406<!ELEMENT block EMPTY>
41407<!ATTLIST block begin CDATA #REQUIRED
41408 end CDATA #REQUIRED>
b20a6524
MM
41409
41410<!ELEMENT pt (pt-config?, raw?)>
41411
41412<!ELEMENT pt-config (cpu?)>
41413
41414<!ELEMENT cpu EMPTY>
41415<!ATTLIST cpu vendor CDATA #REQUIRED
41416 family CDATA #REQUIRED
41417 model CDATA #REQUIRED
41418 stepping CDATA #REQUIRED>
41419
41420<!ELEMENT raw (#PCDATA)>
2ae8c8e7
MM
41421@end smallexample
41422
f4abbc16
MM
41423@node Branch Trace Configuration Format
41424@section Branch Trace Configuration Format
41425@cindex branch trace configuration format
41426
41427For each inferior thread, @value{GDBN} can obtain the branch trace
41428configuration using the @samp{qXfer:btrace-conf:read}
41429(@pxref{qXfer btrace-conf read}) packet.
41430
41431The configuration describes the branch trace format and configuration
d33501a5
MM
41432settings for that format. The following information is described:
41433
41434@table @code
41435@item bts
41436This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
41437@table @code
41438@item size
41439The size of the @acronym{BTS} ring buffer in bytes.
41440@end table
b20a6524 41441@item pt
bc504a31 41442This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
b20a6524
MM
41443PT}) format.
41444@table @code
41445@item size
bc504a31 41446The size of the @acronym{Intel PT} ring buffer in bytes.
b20a6524 41447@end table
d33501a5 41448@end table
f4abbc16
MM
41449
41450@value{GDBN} must be linked with the Expat library to support XML
41451branch trace configuration discovery. @xref{Expat}.
41452
41453The formal DTD for the branch trace configuration format is given below:
41454
41455@smallexample
b20a6524 41456<!ELEMENT btrace-conf (bts?, pt?)>
f4abbc16
MM
41457<!ATTLIST btrace-conf version CDATA #FIXED "1.0">
41458
41459<!ELEMENT bts EMPTY>
d33501a5 41460<!ATTLIST bts size CDATA #IMPLIED>
b20a6524
MM
41461
41462<!ELEMENT pt EMPTY>
41463<!ATTLIST pt size CDATA #IMPLIED>
f4abbc16
MM
41464@end smallexample
41465
f418dd93
DJ
41466@include agentexpr.texi
41467
23181151
DJ
41468@node Target Descriptions
41469@appendix Target Descriptions
41470@cindex target descriptions
41471
23181151
DJ
41472One of the challenges of using @value{GDBN} to debug embedded systems
41473is that there are so many minor variants of each processor
41474architecture in use. It is common practice for vendors to start with
eb17f351 41475a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
23181151
DJ
41476and then make changes to adapt it to a particular market niche. Some
41477architectures have hundreds of variants, available from dozens of
41478vendors. This leads to a number of problems:
41479
41480@itemize @bullet
41481@item
41482With so many different customized processors, it is difficult for
41483the @value{GDBN} maintainers to keep up with the changes.
41484@item
41485Since individual variants may have short lifetimes or limited
41486audiences, it may not be worthwhile to carry information about every
41487variant in the @value{GDBN} source tree.
41488@item
41489When @value{GDBN} does support the architecture of the embedded system
41490at hand, the task of finding the correct architecture name to give the
41491@command{set architecture} command can be error-prone.
41492@end itemize
41493
41494To address these problems, the @value{GDBN} remote protocol allows a
41495target system to not only identify itself to @value{GDBN}, but to
41496actually describe its own features. This lets @value{GDBN} support
41497processor variants it has never seen before --- to the extent that the
41498descriptions are accurate, and that @value{GDBN} understands them.
41499
9cceb671
DJ
41500@value{GDBN} must be linked with the Expat library to support XML
41501target descriptions. @xref{Expat}.
123dc839 41502
23181151
DJ
41503@menu
41504* Retrieving Descriptions:: How descriptions are fetched from a target.
41505* Target Description Format:: The contents of a target description.
123dc839
DJ
41506* Predefined Target Types:: Standard types available for target
41507 descriptions.
81516450 41508* Enum Target Types:: How to define enum target types.
123dc839 41509* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
41510@end menu
41511
41512@node Retrieving Descriptions
41513@section Retrieving Descriptions
41514
41515Target descriptions can be read from the target automatically, or
41516specified by the user manually. The default behavior is to read the
41517description from the target. @value{GDBN} retrieves it via the remote
41518protocol using @samp{qXfer} requests (@pxref{General Query Packets,
41519qXfer}). The @var{annex} in the @samp{qXfer} packet will be
41520@samp{target.xml}. The contents of the @samp{target.xml} annex are an
41521XML document, of the form described in @ref{Target Description
41522Format}.
41523
41524Alternatively, you can specify a file to read for the target description.
41525If a file is set, the target will not be queried. The commands to
41526specify a file are:
41527
41528@table @code
41529@cindex set tdesc filename
41530@item set tdesc filename @var{path}
41531Read the target description from @var{path}.
41532
41533@cindex unset tdesc filename
41534@item unset tdesc filename
41535Do not read the XML target description from a file. @value{GDBN}
41536will use the description supplied by the current target.
41537
41538@cindex show tdesc filename
41539@item show tdesc filename
41540Show the filename to read for a target description, if any.
41541@end table
41542
41543
41544@node Target Description Format
41545@section Target Description Format
41546@cindex target descriptions, XML format
41547
41548A target description annex is an @uref{http://www.w3.org/XML/, XML}
41549document which complies with the Document Type Definition provided in
41550the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
41551means you can use generally available tools like @command{xmllint} to
41552check that your feature descriptions are well-formed and valid.
41553However, to help people unfamiliar with XML write descriptions for
41554their targets, we also describe the grammar here.
41555
123dc839
DJ
41556Target descriptions can identify the architecture of the remote target
41557and (for some architectures) provide information about custom register
08d16641
PA
41558sets. They can also identify the OS ABI of the remote target.
41559@value{GDBN} can use this information to autoconfigure for your
123dc839 41560target, or to warn you if you connect to an unsupported target.
23181151
DJ
41561
41562Here is a simple target description:
41563
123dc839 41564@smallexample
1780a0ed 41565<target version="1.0">
23181151
DJ
41566 <architecture>i386:x86-64</architecture>
41567</target>
123dc839 41568@end smallexample
23181151
DJ
41569
41570@noindent
41571This minimal description only says that the target uses
41572the x86-64 architecture.
41573
123dc839
DJ
41574A target description has the following overall form, with [ ] marking
41575optional elements and @dots{} marking repeatable elements. The elements
41576are explained further below.
23181151 41577
123dc839 41578@smallexample
23181151
DJ
41579<?xml version="1.0"?>
41580<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 41581<target version="1.0">
123dc839 41582 @r{[}@var{architecture}@r{]}
08d16641 41583 @r{[}@var{osabi}@r{]}
e35359c5 41584 @r{[}@var{compatible}@r{]}
123dc839 41585 @r{[}@var{feature}@dots{}@r{]}
23181151 41586</target>
123dc839 41587@end smallexample
23181151
DJ
41588
41589@noindent
41590The description is generally insensitive to whitespace and line
41591breaks, under the usual common-sense rules. The XML version
41592declaration and document type declaration can generally be omitted
41593(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
41594useful for XML validation tools. The @samp{version} attribute for
41595@samp{<target>} may also be omitted, but we recommend
41596including it; if future versions of @value{GDBN} use an incompatible
41597revision of @file{gdb-target.dtd}, they will detect and report
41598the version mismatch.
23181151 41599
108546a0
DJ
41600@subsection Inclusion
41601@cindex target descriptions, inclusion
41602@cindex XInclude
41603@ifnotinfo
41604@cindex <xi:include>
41605@end ifnotinfo
41606
41607It can sometimes be valuable to split a target description up into
41608several different annexes, either for organizational purposes, or to
41609share files between different possible target descriptions. You can
41610divide a description into multiple files by replacing any element of
41611the target description with an inclusion directive of the form:
41612
123dc839 41613@smallexample
108546a0 41614<xi:include href="@var{document}"/>
123dc839 41615@end smallexample
108546a0
DJ
41616
41617@noindent
41618When @value{GDBN} encounters an element of this form, it will retrieve
41619the named XML @var{document}, and replace the inclusion directive with
41620the contents of that document. If the current description was read
41621using @samp{qXfer}, then so will be the included document;
41622@var{document} will be interpreted as the name of an annex. If the
41623current description was read from a file, @value{GDBN} will look for
41624@var{document} as a file in the same directory where it found the
41625original description.
41626
123dc839
DJ
41627@subsection Architecture
41628@cindex <architecture>
41629
41630An @samp{<architecture>} element has this form:
41631
41632@smallexample
41633 <architecture>@var{arch}</architecture>
41634@end smallexample
41635
e35359c5
UW
41636@var{arch} is one of the architectures from the set accepted by
41637@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
123dc839 41638
08d16641
PA
41639@subsection OS ABI
41640@cindex @code{<osabi>}
41641
41642This optional field was introduced in @value{GDBN} version 7.0.
41643Previous versions of @value{GDBN} ignore it.
41644
41645An @samp{<osabi>} element has this form:
41646
41647@smallexample
41648 <osabi>@var{abi-name}</osabi>
41649@end smallexample
41650
41651@var{abi-name} is an OS ABI name from the same selection accepted by
41652@w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
41653
e35359c5
UW
41654@subsection Compatible Architecture
41655@cindex @code{<compatible>}
41656
41657This optional field was introduced in @value{GDBN} version 7.0.
41658Previous versions of @value{GDBN} ignore it.
41659
41660A @samp{<compatible>} element has this form:
41661
41662@smallexample
41663 <compatible>@var{arch}</compatible>
41664@end smallexample
41665
41666@var{arch} is one of the architectures from the set accepted by
41667@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
41668
41669A @samp{<compatible>} element is used to specify that the target
41670is able to run binaries in some other than the main target architecture
41671given by the @samp{<architecture>} element. For example, on the
41672Cell Broadband Engine, the main architecture is @code{powerpc:common}
41673or @code{powerpc:common64}, but the system is able to run binaries
41674in the @code{spu} architecture as well. The way to describe this
41675capability with @samp{<compatible>} is as follows:
41676
41677@smallexample
41678 <architecture>powerpc:common</architecture>
41679 <compatible>spu</compatible>
41680@end smallexample
41681
123dc839
DJ
41682@subsection Features
41683@cindex <feature>
41684
41685Each @samp{<feature>} describes some logical portion of the target
41686system. Features are currently used to describe available CPU
41687registers and the types of their contents. A @samp{<feature>} element
41688has this form:
41689
41690@smallexample
41691<feature name="@var{name}">
41692 @r{[}@var{type}@dots{}@r{]}
41693 @var{reg}@dots{}
41694</feature>
41695@end smallexample
41696
41697@noindent
41698Each feature's name should be unique within the description. The name
41699of a feature does not matter unless @value{GDBN} has some special
41700knowledge of the contents of that feature; if it does, the feature
41701should have its standard name. @xref{Standard Target Features}.
41702
41703@subsection Types
41704
41705Any register's value is a collection of bits which @value{GDBN} must
41706interpret. The default interpretation is a two's complement integer,
41707but other types can be requested by name in the register description.
41708Some predefined types are provided by @value{GDBN} (@pxref{Predefined
81516450
DE
41709Target Types}), and the description can define additional composite
41710and enum types.
123dc839
DJ
41711
41712Each type element must have an @samp{id} attribute, which gives
41713a unique (within the containing @samp{<feature>}) name to the type.
41714Types must be defined before they are used.
41715
41716@cindex <vector>
41717Some targets offer vector registers, which can be treated as arrays
41718of scalar elements. These types are written as @samp{<vector>} elements,
41719specifying the array element type, @var{type}, and the number of elements,
41720@var{count}:
41721
41722@smallexample
41723<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
41724@end smallexample
41725
41726@cindex <union>
41727If a register's value is usefully viewed in multiple ways, define it
41728with a union type containing the useful representations. The
41729@samp{<union>} element contains one or more @samp{<field>} elements,
41730each of which has a @var{name} and a @var{type}:
41731
41732@smallexample
41733<union id="@var{id}">
41734 <field name="@var{name}" type="@var{type}"/>
41735 @dots{}
41736</union>
41737@end smallexample
41738
f5dff777 41739@cindex <struct>
81516450 41740@cindex <flags>
f5dff777 41741If a register's value is composed from several separate values, define
81516450
DE
41742it with either a structure type or a flags type.
41743A flags type may only contain bitfields.
41744A structure type may either contain only bitfields or contain no bitfields.
41745If the value contains only bitfields, its total size in bytes must be
41746specified.
41747
41748Non-bitfield values have a @var{name} and @var{type}.
f5dff777
DJ
41749
41750@smallexample
81516450
DE
41751<struct id="@var{id}">
41752 <field name="@var{name}" type="@var{type}"/>
f5dff777
DJ
41753 @dots{}
41754</struct>
41755@end smallexample
41756
81516450
DE
41757Both @var{name} and @var{type} values are required.
41758No implicit padding is added.
41759
41760Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
f5dff777
DJ
41761
41762@smallexample
81516450
DE
41763<struct id="@var{id}" size="@var{size}">
41764 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
f5dff777
DJ
41765 @dots{}
41766</struct>
41767@end smallexample
41768
f5dff777
DJ
41769@smallexample
41770<flags id="@var{id}" size="@var{size}">
81516450 41771 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
f5dff777
DJ
41772 @dots{}
41773</flags>
41774@end smallexample
41775
81516450
DE
41776The @var{name} value is required.
41777Bitfield values may be named with the empty string, @samp{""},
41778in which case the field is ``filler'' and its value is not printed.
41779Not all bits need to be specified, so ``filler'' fields are optional.
41780
ee8da4b8
DE
41781The @var{start} and @var{end} values are required, and @var{type}
41782is optional.
81516450
DE
41783The field's @var{start} must be less than or equal to its @var{end},
41784and zero represents the least significant bit.
81516450 41785
ee8da4b8
DE
41786The default value of @var{type} is @code{bool} for single bit fields,
41787and an unsigned integer otherwise.
81516450
DE
41788
41789Which to choose? Structures or flags?
41790
41791Registers defined with @samp{flags} have these advantages over
41792defining them with @samp{struct}:
41793
41794@itemize @bullet
41795@item
41796Arithmetic may be performed on them as if they were integers.
41797@item
41798They are printed in a more readable fashion.
41799@end itemize
41800
41801Registers defined with @samp{struct} have one advantage over
41802defining them with @samp{flags}:
41803
41804@itemize @bullet
41805@item
41806One can fetch individual fields like in @samp{C}.
41807
41808@smallexample
41809(gdb) print $my_struct_reg.field3
41810$1 = 42
41811@end smallexample
41812
41813@end itemize
41814
123dc839
DJ
41815@subsection Registers
41816@cindex <reg>
41817
41818Each register is represented as an element with this form:
41819
41820@smallexample
41821<reg name="@var{name}"
41822 bitsize="@var{size}"
41823 @r{[}regnum="@var{num}"@r{]}
41824 @r{[}save-restore="@var{save-restore}"@r{]}
41825 @r{[}type="@var{type}"@r{]}
41826 @r{[}group="@var{group}"@r{]}/>
41827@end smallexample
41828
41829@noindent
41830The components are as follows:
41831
41832@table @var
41833
41834@item name
41835The register's name; it must be unique within the target description.
41836
41837@item bitsize
41838The register's size, in bits.
41839
41840@item regnum
41841The register's number. If omitted, a register's number is one greater
41842than that of the previous register (either in the current feature or in
177b42fe 41843a preceding feature); the first register in the target description
123dc839
DJ
41844defaults to zero. This register number is used to read or write
41845the register; e.g.@: it is used in the remote @code{p} and @code{P}
41846packets, and registers appear in the @code{g} and @code{G} packets
41847in order of increasing register number.
41848
41849@item save-restore
41850Whether the register should be preserved across inferior function
41851calls; this must be either @code{yes} or @code{no}. The default is
41852@code{yes}, which is appropriate for most registers except for
41853some system control registers; this is not related to the target's
41854ABI.
41855
41856@item type
697aa1b7 41857The type of the register. It may be a predefined type, a type
123dc839
DJ
41858defined in the current feature, or one of the special types @code{int}
41859and @code{float}. @code{int} is an integer type of the correct size
41860for @var{bitsize}, and @code{float} is a floating point type (in the
41861architecture's normal floating point format) of the correct size for
41862@var{bitsize}. The default is @code{int}.
41863
41864@item group
cef0f868
SH
41865The register group to which this register belongs. It can be one of the
41866standard register groups @code{general}, @code{float}, @code{vector} or an
41867arbitrary string. Group names should be limited to alphanumeric characters.
41868If a group name is made up of multiple words the words may be separated by
41869hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
41870@var{group} is specified, @value{GDBN} will not display the register in
41871@code{info registers}.
123dc839
DJ
41872
41873@end table
41874
41875@node Predefined Target Types
41876@section Predefined Target Types
41877@cindex target descriptions, predefined types
41878
41879Type definitions in the self-description can build up composite types
41880from basic building blocks, but can not define fundamental types. Instead,
41881standard identifiers are provided by @value{GDBN} for the fundamental
41882types. The currently supported types are:
41883
41884@table @code
41885
81516450
DE
41886@item bool
41887Boolean type, occupying a single bit.
41888
123dc839
DJ
41889@item int8
41890@itemx int16
41891@itemx int32
41892@itemx int64
7cc46491 41893@itemx int128
123dc839
DJ
41894Signed integer types holding the specified number of bits.
41895
41896@item uint8
41897@itemx uint16
41898@itemx uint32
41899@itemx uint64
7cc46491 41900@itemx uint128
123dc839
DJ
41901Unsigned integer types holding the specified number of bits.
41902
41903@item code_ptr
41904@itemx data_ptr
41905Pointers to unspecified code and data. The program counter and
41906any dedicated return address register may be marked as code
41907pointers; printing a code pointer converts it into a symbolic
41908address. The stack pointer and any dedicated address registers
41909may be marked as data pointers.
41910
6e3bbd1a
PB
41911@item ieee_single
41912Single precision IEEE floating point.
41913
41914@item ieee_double
41915Double precision IEEE floating point.
41916
123dc839
DJ
41917@item arm_fpa_ext
41918The 12-byte extended precision format used by ARM FPA registers.
41919
075b51b7
L
41920@item i387_ext
41921The 10-byte extended precision format used by x87 registers.
41922
41923@item i386_eflags
4192432bit @sc{eflags} register used by x86.
41925
41926@item i386_mxcsr
4192732bit @sc{mxcsr} register used by x86.
41928
123dc839
DJ
41929@end table
41930
81516450
DE
41931@node Enum Target Types
41932@section Enum Target Types
41933@cindex target descriptions, enum types
41934
41935Enum target types are useful in @samp{struct} and @samp{flags}
41936register descriptions. @xref{Target Description Format}.
41937
41938Enum types have a name, size and a list of name/value pairs.
41939
41940@smallexample
41941<enum id="@var{id}" size="@var{size}">
41942 <evalue name="@var{name}" value="@var{value}"/>
41943 @dots{}
41944</enum>
41945@end smallexample
41946
41947Enums must be defined before they are used.
41948
41949@smallexample
41950<enum id="levels_type" size="4">
41951 <evalue name="low" value="0"/>
41952 <evalue name="high" value="1"/>
41953</enum>
41954<flags id="flags_type" size="4">
41955 <field name="X" start="0"/>
41956 <field name="LEVEL" start="1" end="1" type="levels_type"/>
41957</flags>
41958<reg name="flags" bitsize="32" type="flags_type"/>
41959@end smallexample
41960
41961Given that description, a value of 3 for the @samp{flags} register
41962would be printed as:
41963
41964@smallexample
41965(gdb) info register flags
41966flags 0x3 [ X LEVEL=high ]
41967@end smallexample
41968
123dc839
DJ
41969@node Standard Target Features
41970@section Standard Target Features
41971@cindex target descriptions, standard features
41972
41973A target description must contain either no registers or all the
41974target's registers. If the description contains no registers, then
41975@value{GDBN} will assume a default register layout, selected based on
41976the architecture. If the description contains any registers, the
41977default layout will not be used; the standard registers must be
41978described in the target description, in such a way that @value{GDBN}
41979can recognize them.
41980
41981This is accomplished by giving specific names to feature elements
41982which contain standard registers. @value{GDBN} will look for features
41983with those names and verify that they contain the expected registers;
41984if any known feature is missing required registers, or if any required
41985feature is missing, @value{GDBN} will reject the target
41986description. You can add additional registers to any of the
41987standard features --- @value{GDBN} will display them just as if
41988they were added to an unrecognized feature.
41989
41990This section lists the known features and their expected contents.
41991Sample XML documents for these features are included in the
41992@value{GDBN} source tree, in the directory @file{gdb/features}.
41993
41994Names recognized by @value{GDBN} should include the name of the
41995company or organization which selected the name, and the overall
41996architecture to which the feature applies; so e.g.@: the feature
41997containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
41998
ff6f572f
DJ
41999The names of registers are not case sensitive for the purpose
42000of recognizing standard features, but @value{GDBN} will only display
42001registers using the capitalization used in the description.
42002
e9c17194 42003@menu
430ed3f0 42004* AArch64 Features::
ad0a504f 42005* ARC Features::
e9c17194 42006* ARM Features::
3bb8d5c3 42007* i386 Features::
164224e9 42008* MicroBlaze Features::
1e26b4f8 42009* MIPS Features::
e9c17194 42010* M68K Features::
a28d8e50 42011* NDS32 Features::
a1217d97 42012* Nios II Features::
a994fec4 42013* OpenRISC 1000 Features::
1e26b4f8 42014* PowerPC Features::
4ac33720 42015* S/390 and System z Features::
3f7b46f2 42016* Sparc Features::
224bbe49 42017* TIC6x Features::
e9c17194
VP
42018@end menu
42019
42020
430ed3f0
MS
42021@node AArch64 Features
42022@subsection AArch64 Features
42023@cindex target descriptions, AArch64 features
42024
42025The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
42026targets. It should contain registers @samp{x0} through @samp{x30},
42027@samp{sp}, @samp{pc}, and @samp{cpsr}.
42028
42029The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
42030it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
42031and @samp{fpcr}.
42032
ad0a504f
AK
42033@node ARC Features
42034@subsection ARC Features
42035@cindex target descriptions, ARC Features
42036
42037ARC processors are highly configurable, so even core registers and their number
42038are not completely predetermined. In addition flags and PC registers which are
42039important to @value{GDBN} are not ``core'' registers in ARC. It is required
42040that one of the core registers features is present.
42041@samp{org.gnu.gdb.arc.aux-minimal} feature is mandatory.
42042
42043The @samp{org.gnu.gdb.arc.core.v2} feature is required for ARC EM and ARC HS
42044targets with a normal register file. It should contain registers @samp{r0}
42045through @samp{r25}, @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink},
42046@samp{lp_count} and @samp{pcl}. This feature may contain register @samp{ilink}
42047and any of extension core registers @samp{r32} through @samp{r59/acch}.
42048@samp{ilink} and extension core registers are not available to read/write, when
42049debugging GNU/Linux applications, thus @samp{ilink} is made optional.
42050
42051The @samp{org.gnu.gdb.arc.core-reduced.v2} feature is required for ARC EM and
42052ARC HS targets with a reduced register file. It should contain registers
42053@samp{r0} through @samp{r3}, @samp{r10} through @samp{r15}, @samp{gp},
42054@samp{fp}, @samp{sp}, @samp{r30}, @samp{blink}, @samp{lp_count} and @samp{pcl}.
42055This feature may contain register @samp{ilink} and any of extension core
42056registers @samp{r32} through @samp{r59/acch}.
42057
42058The @samp{org.gnu.gdb.arc.core.arcompact} feature is required for ARCompact
42059targets with a normal register file. It should contain registers @samp{r0}
42060through @samp{r25}, @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink},
42061@samp{lp_count} and @samp{pcl}. This feature may contain registers
42062@samp{ilink1}, @samp{ilink2} and any of extension core registers @samp{r32}
42063through @samp{r59/acch}. @samp{ilink1} and @samp{ilink2} and extension core
42064registers are not available when debugging GNU/Linux applications. The only
42065difference with @samp{org.gnu.gdb.arc.core.v2} feature is in the names of
42066@samp{ilink1} and @samp{ilink2} registers and that @samp{r30} is mandatory in
42067ARC v2, but @samp{ilink2} is optional on ARCompact.
42068
42069The @samp{org.gnu.gdb.arc.aux-minimal} feature is required for all ARC
42070targets. It should contain registers @samp{pc} and @samp{status32}.
42071
e9c17194 42072@node ARM Features
123dc839
DJ
42073@subsection ARM Features
42074@cindex target descriptions, ARM features
42075
9779414d
DJ
42076The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
42077ARM targets.
123dc839
DJ
42078It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
42079@samp{lr}, @samp{pc}, and @samp{cpsr}.
42080
9779414d
DJ
42081For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
42082feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
42083registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
42084and @samp{xpsr}.
42085
123dc839
DJ
42086The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
42087should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
42088
ff6f572f
DJ
42089The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
42090it should contain at least registers @samp{wR0} through @samp{wR15} and
42091@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
42092@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 42093
58d6951d
DJ
42094The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
42095should contain at least registers @samp{d0} through @samp{d15}. If
42096they are present, @samp{d16} through @samp{d31} should also be included.
42097@value{GDBN} will synthesize the single-precision registers from
42098halves of the double-precision registers.
42099
42100The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
42101need to contain registers; it instructs @value{GDBN} to display the
42102VFP double-precision registers as vectors and to synthesize the
42103quad-precision registers from pairs of double-precision registers.
42104If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
42105be present and include 32 double-precision registers.
42106
3bb8d5c3
L
42107@node i386 Features
42108@subsection i386 Features
42109@cindex target descriptions, i386 features
42110
42111The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
42112targets. It should describe the following registers:
42113
42114@itemize @minus
42115@item
42116@samp{eax} through @samp{edi} plus @samp{eip} for i386
42117@item
42118@samp{rax} through @samp{r15} plus @samp{rip} for amd64
42119@item
42120@samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
42121@samp{fs}, @samp{gs}
42122@item
42123@samp{st0} through @samp{st7}
42124@item
42125@samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
42126@samp{foseg}, @samp{fooff} and @samp{fop}
42127@end itemize
42128
42129The register sets may be different, depending on the target.
42130
3a13a53b 42131The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
3bb8d5c3
L
42132describe registers:
42133
42134@itemize @minus
42135@item
42136@samp{xmm0} through @samp{xmm7} for i386
42137@item
42138@samp{xmm0} through @samp{xmm15} for amd64
42139@item
42140@samp{mxcsr}
42141@end itemize
42142
3a13a53b
L
42143The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
42144@samp{org.gnu.gdb.i386.sse} feature. It should
f68eb612
L
42145describe the upper 128 bits of @sc{ymm} registers:
42146
42147@itemize @minus
42148@item
42149@samp{ymm0h} through @samp{ymm7h} for i386
42150@item
42151@samp{ymm0h} through @samp{ymm15h} for amd64
f68eb612
L
42152@end itemize
42153
bc504a31 42154The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
ca8941bb
WT
42155Memory Protection Extension (MPX). It should describe the following registers:
42156
42157@itemize @minus
42158@item
42159@samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
42160@item
42161@samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
42162@end itemize
42163
3bb8d5c3
L
42164The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
42165describe a single register, @samp{orig_eax}.
42166
2735833d
WT
42167The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
42168describe two system registers: @samp{fs_base} and @samp{gs_base}.
42169
01f9f808
MS
42170The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
42171@samp{org.gnu.gdb.i386.avx} feature. It should
42172describe additional @sc{xmm} registers:
42173
42174@itemize @minus
42175@item
42176@samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
42177@end itemize
42178
42179It should describe the upper 128 bits of additional @sc{ymm} registers:
42180
42181@itemize @minus
42182@item
42183@samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
42184@end itemize
42185
42186It should
42187describe the upper 256 bits of @sc{zmm} registers:
42188
42189@itemize @minus
42190@item
42191@samp{zmm0h} through @samp{zmm7h} for i386.
42192@item
42193@samp{zmm0h} through @samp{zmm15h} for amd64.
42194@end itemize
42195
42196It should
42197describe the additional @sc{zmm} registers:
42198
42199@itemize @minus
42200@item
42201@samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
42202@end itemize
42203
51547df6
MS
42204The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
42205describe a single register, @samp{pkru}. It is a 32-bit register
42206valid for i386 and amd64.
42207
164224e9
ME
42208@node MicroBlaze Features
42209@subsection MicroBlaze Features
42210@cindex target descriptions, MicroBlaze features
42211
42212The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
42213targets. It should contain registers @samp{r0} through @samp{r31},
42214@samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
42215@samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
42216@samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
42217
42218The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
42219If present, it should contain registers @samp{rshr} and @samp{rslr}
42220
1e26b4f8 42221@node MIPS Features
eb17f351
EZ
42222@subsection @acronym{MIPS} Features
42223@cindex target descriptions, @acronym{MIPS} features
f8b73d13 42224
eb17f351 42225The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
f8b73d13
DJ
42226It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
42227@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
42228on the target.
42229
42230The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
42231contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
42232registers. They may be 32-bit or 64-bit depending on the target.
42233
42234The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
42235it may be optional in a future version of @value{GDBN}. It should
42236contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
42237@samp{fir}. They may be 32-bit or 64-bit depending on the target.
42238
1faeff08
MR
42239The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
42240contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
42241@samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
42242be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
42243
822b6570
DJ
42244The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
42245contain a single register, @samp{restart}, which is used by the
42246Linux kernel to control restartable syscalls.
42247
e9c17194
VP
42248@node M68K Features
42249@subsection M68K Features
42250@cindex target descriptions, M68K features
42251
42252@table @code
42253@item @samp{org.gnu.gdb.m68k.core}
42254@itemx @samp{org.gnu.gdb.coldfire.core}
42255@itemx @samp{org.gnu.gdb.fido.core}
42256One of those features must be always present.
249e1128 42257The feature that is present determines which flavor of m68k is
e9c17194
VP
42258used. The feature that is present should contain registers
42259@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
42260@samp{sp}, @samp{ps} and @samp{pc}.
42261
42262@item @samp{org.gnu.gdb.coldfire.fp}
42263This feature is optional. If present, it should contain registers
42264@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
42265@samp{fpiaddr}.
42266@end table
42267
a28d8e50
YTL
42268@node NDS32 Features
42269@subsection NDS32 Features
42270@cindex target descriptions, NDS32 features
42271
42272The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
42273targets. It should contain at least registers @samp{r0} through
42274@samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
42275and @samp{pc}.
42276
42277The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
42278it should contain 64-bit double-precision floating-point registers
42279@samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
42280@samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
42281
42282@emph{Note:} The first sixteen 64-bit double-precision floating-point
42283registers are overlapped with the thirty-two 32-bit single-precision
42284floating-point registers. The 32-bit single-precision registers, if
42285not being listed explicitly, will be synthesized from halves of the
42286overlapping 64-bit double-precision registers. Listing 32-bit
42287single-precision registers explicitly is deprecated, and the
42288support to it could be totally removed some day.
42289
a1217d97
SL
42290@node Nios II Features
42291@subsection Nios II Features
42292@cindex target descriptions, Nios II features
42293
42294The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
42295targets. It should contain the 32 core registers (@samp{zero},
42296@samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
42297@samp{pc}, and the 16 control registers (@samp{status} through
42298@samp{mpuacc}).
42299
a994fec4
FJ
42300@node OpenRISC 1000 Features
42301@subsection Openrisc 1000 Features
42302@cindex target descriptions, OpenRISC 1000 features
42303
42304The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
42305targets. It should contain the 32 general purpose registers (@samp{r0}
42306through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
42307
1e26b4f8 42308@node PowerPC Features
7cc46491
DJ
42309@subsection PowerPC Features
42310@cindex target descriptions, PowerPC features
42311
42312The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
42313targets. It should contain registers @samp{r0} through @samp{r31},
42314@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
42315@samp{xer}. They may be 32-bit or 64-bit depending on the target.
42316
42317The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
42318contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
42319
42320The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
42321contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
42322and @samp{vrsave}.
42323
677c5bb1
LM
42324The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
42325contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN}
42326will combine these registers with the floating point registers
42327(@samp{f0} through @samp{f31}) and the altivec registers (@samp{vr0}
aeac0ff9 42328through @samp{vr31}) to present the 128-bit wide registers @samp{vs0}
677c5bb1
LM
42329through @samp{vs63}, the set of vector registers for POWER7.
42330
7cc46491
DJ
42331The @samp{org.gnu.gdb.power.spe} feature is optional. It should
42332contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
42333@samp{spefscr}. SPE targets should provide 32-bit registers in
42334@samp{org.gnu.gdb.power.core} and provide the upper halves in
42335@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
42336these to present registers @samp{ev0} through @samp{ev31} to the
42337user.
42338
4ac33720
UW
42339@node S/390 and System z Features
42340@subsection S/390 and System z Features
42341@cindex target descriptions, S/390 features
42342@cindex target descriptions, System z features
42343
42344The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
42345System z targets. It should contain the PSW and the 16 general
42346registers. In particular, System z targets should provide the 64-bit
42347registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
42348S/390 targets should provide the 32-bit versions of these registers.
42349A System z target that runs in 31-bit addressing mode should provide
4235032-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
42351register's upper halves @samp{r0h} through @samp{r15h}, and their
42352lower halves @samp{r0l} through @samp{r15l}.
42353
42354The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
42355contain the 64-bit registers @samp{f0} through @samp{f15}, and
42356@samp{fpc}.
42357
42358The @samp{org.gnu.gdb.s390.acr} feature is required. It should
42359contain the 32-bit registers @samp{acr0} through @samp{acr15}.
42360
42361The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
42362contain the register @samp{orig_r2}, which is 64-bit wide on System z
42363targets and 32-bit otherwise. In addition, the feature may contain
42364the @samp{last_break} register, whose width depends on the addressing
42365mode, as well as the @samp{system_call} register, which is always
4236632-bit wide.
42367
42368The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
42369contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
42370@samp{atia}, and @samp{tr0} through @samp{tr15}.
42371
446899e4
AA
42372The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
4237364-bit wide registers @samp{v0l} through @samp{v15l}, which will be
42374combined by @value{GDBN} with the floating point registers @samp{f0}
42375through @samp{f15} to present the 128-bit wide vector registers
42376@samp{v0} through @samp{v15}. In addition, this feature should
42377contain the 128-bit wide vector registers @samp{v16} through
42378@samp{v31}.
42379
289e23aa
AA
42380The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
42381the 64-bit wide guarded-storage-control registers @samp{gsd},
42382@samp{gssm}, and @samp{gsepla}.
42383
42384The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
42385the 64-bit wide guarded-storage broadcast control registers
42386@samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
42387
3f7b46f2
IR
42388@node Sparc Features
42389@subsection Sparc Features
42390@cindex target descriptions, sparc32 features
42391@cindex target descriptions, sparc64 features
42392The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
42393targets. It should describe the following registers:
42394
42395@itemize @minus
42396@item
42397@samp{g0} through @samp{g7}
42398@item
42399@samp{o0} through @samp{o7}
42400@item
42401@samp{l0} through @samp{l7}
42402@item
42403@samp{i0} through @samp{i7}
42404@end itemize
42405
42406They may be 32-bit or 64-bit depending on the target.
42407
42408Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
42409targets. It should describe the following registers:
42410
42411@itemize @minus
42412@item
42413@samp{f0} through @samp{f31}
42414@item
42415@samp{f32} through @samp{f62} for sparc64
42416@end itemize
42417
42418The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
42419targets. It should describe the following registers:
42420
42421@itemize @minus
42422@item
42423@samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
42424@samp{fsr}, and @samp{csr} for sparc32
42425@item
42426@samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
42427for sparc64
42428@end itemize
42429
224bbe49
YQ
42430@node TIC6x Features
42431@subsection TMS320C6x Features
42432@cindex target descriptions, TIC6x features
42433@cindex target descriptions, TMS320C6x features
42434The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
42435targets. It should contain registers @samp{A0} through @samp{A15},
42436registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
42437
42438The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
42439contain registers @samp{A16} through @samp{A31} and @samp{B16}
42440through @samp{B31}.
42441
42442The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
42443contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
42444
07e059b5
VP
42445@node Operating System Information
42446@appendix Operating System Information
42447@cindex operating system information
42448
42449@menu
42450* Process list::
42451@end menu
42452
42453Users of @value{GDBN} often wish to obtain information about the state of
42454the operating system running on the target---for example the list of
42455processes, or the list of open files. This section describes the
42456mechanism that makes it possible. This mechanism is similar to the
42457target features mechanism (@pxref{Target Descriptions}), but focuses
42458on a different aspect of target.
42459
42460Operating system information is retrived from the target via the
42461remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
42462read}). The object name in the request should be @samp{osdata}, and
42463the @var{annex} identifies the data to be fetched.
42464
42465@node Process list
42466@appendixsection Process list
42467@cindex operating system information, process list
42468
42469When requesting the process list, the @var{annex} field in the
42470@samp{qXfer} request should be @samp{processes}. The returned data is
42471an XML document. The formal syntax of this document is defined in
42472@file{gdb/features/osdata.dtd}.
42473
42474An example document is:
42475
42476@smallexample
42477<?xml version="1.0"?>
42478<!DOCTYPE target SYSTEM "osdata.dtd">
42479<osdata type="processes">
42480 <item>
42481 <column name="pid">1</column>
42482 <column name="user">root</column>
42483 <column name="command">/sbin/init</column>
dc146f7c 42484 <column name="cores">1,2,3</column>
07e059b5
VP
42485 </item>
42486</osdata>
42487@end smallexample
42488
42489Each item should include a column whose name is @samp{pid}. The value
42490of that column should identify the process on the target. The
42491@samp{user} and @samp{command} columns are optional, and will be
dc146f7c
VP
42492displayed by @value{GDBN}. The @samp{cores} column, if present,
42493should contain a comma-separated list of cores that this process
42494is running on. Target may provide additional columns,
07e059b5
VP
42495which @value{GDBN} currently ignores.
42496
05c8c3f5
TT
42497@node Trace File Format
42498@appendix Trace File Format
42499@cindex trace file format
42500
42501The trace file comes in three parts: a header, a textual description
42502section, and a trace frame section with binary data.
42503
42504The header has the form @code{\x7fTRACE0\n}. The first byte is
42505@code{0x7f} so as to indicate that the file contains binary data,
42506while the @code{0} is a version number that may have different values
42507in the future.
42508
42509The description section consists of multiple lines of @sc{ascii} text
42510separated by newline characters (@code{0xa}). The lines may include a
42511variety of optional descriptive or context-setting information, such
42512as tracepoint definitions or register set size. @value{GDBN} will
42513ignore any line that it does not recognize. An empty line marks the end
42514of this section.
42515
0748bf3e
MK
42516@table @code
42517@item R @var{size}
42518Specifies the size of a register block in bytes. This is equal to the
42519size of a @code{g} packet payload in the remote protocol. @var{size}
42520is an ascii decimal number. There should be only one such line in
42521a single trace file.
42522
42523@item status @var{status}
42524Trace status. @var{status} has the same format as a @code{qTStatus}
42525remote packet reply. There should be only one such line in a single trace
42526file.
42527
42528@item tp @var{payload}
42529Tracepoint definition. The @var{payload} has the same format as
42530@code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
42531may take multiple lines of definition, corresponding to the multiple
42532reply packets.
42533
42534@item tsv @var{payload}
42535Trace state variable definition. The @var{payload} has the same format as
42536@code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
42537may take multiple lines of definition, corresponding to the multiple
42538reply packets.
42539
42540@item tdesc @var{payload}
42541Target description in XML format. The @var{payload} is a single line of
42542the XML file. All such lines should be concatenated together to get
42543the original XML file. This file is in the same format as @code{qXfer}
42544@code{features} payload, and corresponds to the main @code{target.xml}
42545file. Includes are not allowed.
42546
42547@end table
05c8c3f5
TT
42548
42549The trace frame section consists of a number of consecutive frames.
42550Each frame begins with a two-byte tracepoint number, followed by a
42551four-byte size giving the amount of data in the frame. The data in
42552the frame consists of a number of blocks, each introduced by a
42553character indicating its type (at least register, memory, and trace
42554state variable). The data in this section is raw binary, not a
42555hexadecimal or other encoding; its endianness matches the target's
42556endianness.
42557
42558@c FIXME bi-arch may require endianness/arch info in description section
42559
42560@table @code
42561@item R @var{bytes}
42562Register block. The number and ordering of bytes matches that of a
42563@code{g} packet in the remote protocol. Note that these are the
e909d859 42564actual bytes, in target order, not a hexadecimal encoding.
05c8c3f5
TT
42565
42566@item M @var{address} @var{length} @var{bytes}...
42567Memory block. This is a contiguous block of memory, at the 8-byte
42568address @var{address}, with a 2-byte length @var{length}, followed by
42569@var{length} bytes.
42570
42571@item V @var{number} @var{value}
42572Trace state variable block. This records the 8-byte signed value
42573@var{value} of trace state variable numbered @var{number}.
42574
42575@end table
42576
42577Future enhancements of the trace file format may include additional types
42578of blocks.
42579
90476074
TT
42580@node Index Section Format
42581@appendix @code{.gdb_index} section format
42582@cindex .gdb_index section format
42583@cindex index section format
42584
42585This section documents the index section that is created by @code{save
42586gdb-index} (@pxref{Index Files}). The index section is
42587DWARF-specific; some knowledge of DWARF is assumed in this
42588description.
42589
42590The mapped index file format is designed to be directly
42591@code{mmap}able on any architecture. In most cases, a datum is
42592represented using a little-endian 32-bit integer value, called an
42593@code{offset_type}. Big endian machines must byte-swap the values
42594before using them. Exceptions to this rule are noted. The data is
42595laid out such that alignment is always respected.
42596
42597A mapped index consists of several areas, laid out in order.
42598
42599@enumerate
42600@item
42601The file header. This is a sequence of values, of @code{offset_type}
42602unless otherwise noted:
42603
42604@enumerate
42605@item
796a7ff8 42606The version number, currently 8. Versions 1, 2 and 3 are obsolete.
481860b3 42607Version 4 uses a different hashing function from versions 5 and 6.
b6ba681c
TT
42608Version 6 includes symbols for inlined functions, whereas versions 4
42609and 5 do not. Version 7 adds attributes to the CU indices in the
796a7ff8
DE
42610symbol table. Version 8 specifies that symbols from DWARF type units
42611(@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
42612compilation unit (@samp{DW_TAG_comp_unit}) using the type.
42613
42614@value{GDBN} will only read version 4, 5, or 6 indices
e615022a 42615by specifying @code{set use-deprecated-index-sections on}.
796a7ff8
DE
42616GDB has a workaround for potentially broken version 7 indices so it is
42617currently not flagged as deprecated.
90476074
TT
42618
42619@item
42620The offset, from the start of the file, of the CU list.
42621
42622@item
42623The offset, from the start of the file, of the types CU list. Note
42624that this area can be empty, in which case this offset will be equal
42625to the next offset.
42626
42627@item
42628The offset, from the start of the file, of the address area.
42629
42630@item
42631The offset, from the start of the file, of the symbol table.
42632
42633@item
42634The offset, from the start of the file, of the constant pool.
42635@end enumerate
42636
42637@item
42638The CU list. This is a sequence of pairs of 64-bit little-endian
42639values, sorted by the CU offset. The first element in each pair is
42640the offset of a CU in the @code{.debug_info} section. The second
42641element in each pair is the length of that CU. References to a CU
42642elsewhere in the map are done using a CU index, which is just the
426430-based index into this table. Note that if there are type CUs, then
42644conceptually CUs and type CUs form a single list for the purposes of
42645CU indices.
42646
42647@item
42648The types CU list. This is a sequence of triplets of 64-bit
42649little-endian values. In a triplet, the first value is the CU offset,
42650the second value is the type offset in the CU, and the third value is
42651the type signature. The types CU list is not sorted.
42652
42653@item
42654The address area. The address area consists of a sequence of address
42655entries. Each address entry has three elements:
42656
42657@enumerate
42658@item
42659The low address. This is a 64-bit little-endian value.
42660
42661@item
42662The high address. This is a 64-bit little-endian value. Like
42663@code{DW_AT_high_pc}, the value is one byte beyond the end.
42664
42665@item
42666The CU index. This is an @code{offset_type} value.
42667@end enumerate
42668
42669@item
42670The symbol table. This is an open-addressed hash table. The size of
42671the hash table is always a power of 2.
42672
42673Each slot in the hash table consists of a pair of @code{offset_type}
42674values. The first value is the offset of the symbol's name in the
42675constant pool. The second value is the offset of the CU vector in the
42676constant pool.
42677
42678If both values are 0, then this slot in the hash table is empty. This
42679is ok because while 0 is a valid constant pool index, it cannot be a
42680valid index for both a string and a CU vector.
42681
42682The hash value for a table entry is computed by applying an
42683iterative hash function to the symbol's name. Starting with an
42684initial value of @code{r = 0}, each (unsigned) character @samp{c} in
559a7a62
JK
42685the string is incorporated into the hash using the formula depending on the
42686index version:
42687
42688@table @asis
42689@item Version 4
42690The formula is @code{r = r * 67 + c - 113}.
42691
156942c7 42692@item Versions 5 to 7
559a7a62
JK
42693The formula is @code{r = r * 67 + tolower (c) - 113}.
42694@end table
42695
42696The terminating @samp{\0} is not incorporated into the hash.
90476074
TT
42697
42698The step size used in the hash table is computed via
42699@code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
42700value, and @samp{size} is the size of the hash table. The step size
42701is used to find the next candidate slot when handling a hash
42702collision.
42703
42704The names of C@t{++} symbols in the hash table are canonicalized. We
42705don't currently have a simple description of the canonicalization
42706algorithm; if you intend to create new index sections, you must read
42707the code.
42708
42709@item
42710The constant pool. This is simply a bunch of bytes. It is organized
42711so that alignment is correct: CU vectors are stored first, followed by
42712strings.
42713
42714A CU vector in the constant pool is a sequence of @code{offset_type}
42715values. The first value is the number of CU indices in the vector.
156942c7
DE
42716Each subsequent value is the index and symbol attributes of a CU in
42717the CU list. This element in the hash table is used to indicate which
42718CUs define the symbol and how the symbol is used.
42719See below for the format of each CU index+attributes entry.
90476074
TT
42720
42721A string in the constant pool is zero-terminated.
42722@end enumerate
42723
156942c7
DE
42724Attributes were added to CU index values in @code{.gdb_index} version 7.
42725If a symbol has multiple uses within a CU then there is one
42726CU index+attributes value for each use.
42727
42728The format of each CU index+attributes entry is as follows
42729(bit 0 = LSB):
42730
42731@table @asis
42732
42733@item Bits 0-23
42734This is the index of the CU in the CU list.
42735@item Bits 24-27
42736These bits are reserved for future purposes and must be zero.
42737@item Bits 28-30
42738The kind of the symbol in the CU.
42739
42740@table @asis
42741@item 0
42742This value is reserved and should not be used.
42743By reserving zero the full @code{offset_type} value is backwards compatible
42744with previous versions of the index.
42745@item 1
42746The symbol is a type.
42747@item 2
42748The symbol is a variable or an enum value.
42749@item 3
42750The symbol is a function.
42751@item 4
42752Any other kind of symbol.
42753@item 5,6,7
42754These values are reserved.
42755@end table
42756
42757@item Bit 31
42758This bit is zero if the value is global and one if it is static.
42759
42760The determination of whether a symbol is global or static is complicated.
42761The authorative reference is the file @file{dwarf2read.c} in
42762@value{GDBN} sources.
42763
42764@end table
42765
42766This pseudo-code describes the computation of a symbol's kind and
42767global/static attributes in the index.
42768
42769@smallexample
42770is_external = get_attribute (die, DW_AT_external);
42771language = get_attribute (cu_die, DW_AT_language);
42772switch (die->tag)
42773 @{
42774 case DW_TAG_typedef:
42775 case DW_TAG_base_type:
42776 case DW_TAG_subrange_type:
42777 kind = TYPE;
42778 is_static = 1;
42779 break;
42780 case DW_TAG_enumerator:
42781 kind = VARIABLE;
9c37b5ae 42782 is_static = language != CPLUS;
156942c7
DE
42783 break;
42784 case DW_TAG_subprogram:
42785 kind = FUNCTION;
42786 is_static = ! (is_external || language == ADA);
42787 break;
42788 case DW_TAG_constant:
42789 kind = VARIABLE;
42790 is_static = ! is_external;
42791 break;
42792 case DW_TAG_variable:
42793 kind = VARIABLE;
42794 is_static = ! is_external;
42795 break;
42796 case DW_TAG_namespace:
42797 kind = TYPE;
42798 is_static = 0;
42799 break;
42800 case DW_TAG_class_type:
42801 case DW_TAG_interface_type:
42802 case DW_TAG_structure_type:
42803 case DW_TAG_union_type:
42804 case DW_TAG_enumeration_type:
42805 kind = TYPE;
9c37b5ae 42806 is_static = language != CPLUS;
156942c7
DE
42807 break;
42808 default:
42809 assert (0);
42810 @}
42811@end smallexample
42812
43662968
JK
42813@node Man Pages
42814@appendix Manual pages
42815@cindex Man pages
42816
42817@menu
42818* gdb man:: The GNU Debugger man page
42819* gdbserver man:: Remote Server for the GNU Debugger man page
b292c783 42820* gcore man:: Generate a core file of a running program
43662968 42821* gdbinit man:: gdbinit scripts
ba643918 42822* gdb-add-index man:: Add index files to speed up GDB
43662968
JK
42823@end menu
42824
42825@node gdb man
42826@heading gdb man
42827
42828@c man title gdb The GNU Debugger
42829
42830@c man begin SYNOPSIS gdb
42831gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
42832[@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
42833[@option{-b}@w{ }@var{bps}]
42834 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
42835[@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
906ccdf0
JK
42836[@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
42837 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
42838[@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
43662968
JK
42839@c man end
42840
42841@c man begin DESCRIPTION gdb
42842The purpose of a debugger such as @value{GDBN} is to allow you to see what is
42843going on ``inside'' another program while it executes -- or what another
42844program was doing at the moment it crashed.
42845
42846@value{GDBN} can do four main kinds of things (plus other things in support of
42847these) to help you catch bugs in the act:
42848
42849@itemize @bullet
42850@item
42851Start your program, specifying anything that might affect its behavior.
42852
42853@item
42854Make your program stop on specified conditions.
42855
42856@item
42857Examine what has happened, when your program has stopped.
42858
42859@item
42860Change things in your program, so you can experiment with correcting the
42861effects of one bug and go on to learn about another.
42862@end itemize
42863
906ccdf0
JK
42864You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
42865Modula-2.
43662968
JK
42866
42867@value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
42868commands from the terminal until you tell it to exit with the @value{GDBN}
42869command @code{quit}. You can get online help from @value{GDBN} itself
42870by using the command @code{help}.
42871
42872You can run @code{gdb} with no arguments or options; but the most
42873usual way to start @value{GDBN} is with one argument or two, specifying an
42874executable program as the argument:
42875
42876@smallexample
42877gdb program
42878@end smallexample
42879
42880You can also start with both an executable program and a core file specified:
42881
42882@smallexample
42883gdb program core
42884@end smallexample
42885
42886You can, instead, specify a process ID as a second argument, if you want
42887to debug a running process:
42888
42889@smallexample
42890gdb program 1234
906ccdf0 42891gdb -p 1234
43662968
JK
42892@end smallexample
42893
42894@noindent
42895would attach @value{GDBN} to process @code{1234} (unless you also have a file
42896named @file{1234}; @value{GDBN} does check for a core file first).
906ccdf0 42897With option @option{-p} you can omit the @var{program} filename.
43662968
JK
42898
42899Here are some of the most frequently needed @value{GDBN} commands:
42900
42901@c pod2man highlights the right hand side of the @item lines.
42902@table @env
224f10c1 42903@item break [@var{file}:]@var{function}
43662968
JK
42904Set a breakpoint at @var{function} (in @var{file}).
42905
42906@item run [@var{arglist}]
42907Start your program (with @var{arglist}, if specified).
42908
42909@item bt
42910Backtrace: display the program stack.
42911
42912@item print @var{expr}
42913Display the value of an expression.
42914
42915@item c
42916Continue running your program (after stopping, e.g. at a breakpoint).
42917
42918@item next
42919Execute next program line (after stopping); step @emph{over} any
42920function calls in the line.
42921
42922@item edit [@var{file}:]@var{function}
42923look at the program line where it is presently stopped.
42924
42925@item list [@var{file}:]@var{function}
42926type the text of the program in the vicinity of where it is presently stopped.
42927
42928@item step
42929Execute next program line (after stopping); step @emph{into} any
42930function calls in the line.
42931
42932@item help [@var{name}]
42933Show information about @value{GDBN} command @var{name}, or general information
42934about using @value{GDBN}.
42935
42936@item quit
42937Exit from @value{GDBN}.
42938@end table
42939
42940@ifset man
42941For full details on @value{GDBN},
42942see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
42943by Richard M. Stallman and Roland H. Pesch. The same text is available online
42944as the @code{gdb} entry in the @code{info} program.
42945@end ifset
42946@c man end
42947
42948@c man begin OPTIONS gdb
42949Any arguments other than options specify an executable
42950file and core file (or process ID); that is, the first argument
42951encountered with no
42952associated option flag is equivalent to a @option{-se} option, and the second,
42953if any, is equivalent to a @option{-c} option if it's the name of a file.
42954Many options have
42955both long and short forms; both are shown here. The long forms are also
42956recognized if you truncate them, so long as enough of the option is
42957present to be unambiguous. (If you prefer, you can flag option
42958arguments with @option{+} rather than @option{-}, though we illustrate the
42959more usual convention.)
42960
42961All the options and command line arguments you give are processed
42962in sequential order. The order makes a difference when the @option{-x}
42963option is used.
42964
42965@table @env
42966@item -help
42967@itemx -h
42968List all options, with brief explanations.
42969
42970@item -symbols=@var{file}
42971@itemx -s @var{file}
42972Read symbol table from file @var{file}.
42973
42974@item -write
42975Enable writing into executable and core files.
42976
42977@item -exec=@var{file}
42978@itemx -e @var{file}
42979Use file @var{file} as the executable file to execute when
42980appropriate, and for examining pure data in conjunction with a core
42981dump.
42982
42983@item -se=@var{file}
42984Read symbol table from file @var{file} and use it as the executable
42985file.
42986
42987@item -core=@var{file}
42988@itemx -c @var{file}
42989Use file @var{file} as a core dump to examine.
42990
42991@item -command=@var{file}
42992@itemx -x @var{file}
42993Execute @value{GDBN} commands from file @var{file}.
42994
42995@item -ex @var{command}
42996Execute given @value{GDBN} @var{command}.
42997
42998@item -directory=@var{directory}
42999@itemx -d @var{directory}
43000Add @var{directory} to the path to search for source files.
43001
43002@item -nh
43003Do not execute commands from @file{~/.gdbinit}.
43004
43005@item -nx
43006@itemx -n
43007Do not execute commands from any @file{.gdbinit} initialization files.
43008
43009@item -quiet
43010@itemx -q
43011``Quiet''. Do not print the introductory and copyright messages. These
43012messages are also suppressed in batch mode.
43013
43014@item -batch
43015Run in batch mode. Exit with status @code{0} after processing all the command
43016files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
43017Exit with nonzero status if an error occurs in executing the @value{GDBN}
43018commands in the command files.
43019
43020Batch mode may be useful for running @value{GDBN} as a filter, for example to
43021download and run a program on another computer; in order to make this
43022more useful, the message
43023
43024@smallexample
43025Program exited normally.
43026@end smallexample
43027
43028@noindent
43029(which is ordinarily issued whenever a program running under @value{GDBN} control
43030terminates) is not issued when running in batch mode.
43031
43032@item -cd=@var{directory}
43033Run @value{GDBN} using @var{directory} as its working directory,
43034instead of the current directory.
43035
43036@item -fullname
43037@itemx -f
43038Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
43039@value{GDBN} to output the full file name and line number in a standard,
43040recognizable fashion each time a stack frame is displayed (which
43041includes each time the program stops). This recognizable format looks
43042like two @samp{\032} characters, followed by the file name, line number
43043and character position separated by colons, and a newline. The
43044Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
43045characters as a signal to display the source code for the frame.
43046
43047@item -b @var{bps}
43048Set the line speed (baud rate or bits per second) of any serial
43049interface used by @value{GDBN} for remote debugging.
43050
43051@item -tty=@var{device}
43052Run using @var{device} for your program's standard input and output.
43053@end table
43054@c man end
43055
43056@c man begin SEEALSO gdb
43057@ifset man
43058The full documentation for @value{GDBN} is maintained as a Texinfo manual.
43059If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
43060documentation are properly installed at your site, the command
43061
43062@smallexample
43063info gdb
43064@end smallexample
43065
43066@noindent
43067should give you access to the complete manual.
43068
43069@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
43070Richard M. Stallman and Roland H. Pesch, July 1991.
43071@end ifset
43072@c man end
43073
43074@node gdbserver man
43075@heading gdbserver man
43076
43077@c man title gdbserver Remote Server for the GNU Debugger
43078@format
43079@c man begin SYNOPSIS gdbserver
5b8b6385 43080gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
43662968 43081
5b8b6385
JK
43082gdbserver --attach @var{comm} @var{pid}
43083
43084gdbserver --multi @var{comm}
43662968
JK
43085@c man end
43086@end format
43087
43088@c man begin DESCRIPTION gdbserver
43089@command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
43090than the one which is running the program being debugged.
43091
43092@ifclear man
43093@subheading Usage (server (target) side)
43094@end ifclear
43095@ifset man
43096Usage (server (target) side):
43097@end ifset
43098
43099First, you need to have a copy of the program you want to debug put onto
43100the target system. The program can be stripped to save space if needed, as
43101@command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
43102the @value{GDBN} running on the host system.
43103
43104To use the server, you log on to the target system, and run the @command{gdbserver}
43105program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
43106your program, and (c) its arguments. The general syntax is:
43107
43108@smallexample
43109target> gdbserver @var{comm} @var{program} [@var{args} ...]
43110@end smallexample
43111
43112For example, using a serial port, you might say:
43113
43114@smallexample
43115@ifset man
43116@c @file would wrap it as F</dev/com1>.
43117target> gdbserver /dev/com1 emacs foo.txt
43118@end ifset
43119@ifclear man
43120target> gdbserver @file{/dev/com1} emacs foo.txt
43121@end ifclear
43122@end smallexample
43123
43124This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
43125to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
43126waits patiently for the host @value{GDBN} to communicate with it.
43127
43128To use a TCP connection, you could say:
43129
43130@smallexample
43131target> gdbserver host:2345 emacs foo.txt
43132@end smallexample
43133
43134This says pretty much the same thing as the last example, except that we are
43135going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
43136that we are expecting to see a TCP connection from @code{host} to local TCP port
431372345. (Currently, the @code{host} part is ignored.) You can choose any number you
43138want for the port number as long as it does not conflict with any existing TCP
43139ports on the target system. This same port number must be used in the host
43140@value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
43141you chose a port number that conflicts with another service, @command{gdbserver} will
43142print an error message and exit.
43143
5b8b6385 43144@command{gdbserver} can also attach to running programs.
43662968
JK
43145This is accomplished via the @option{--attach} argument. The syntax is:
43146
43147@smallexample
5b8b6385 43148target> gdbserver --attach @var{comm} @var{pid}
43662968
JK
43149@end smallexample
43150
43151@var{pid} is the process ID of a currently running process. It isn't
43152necessary to point @command{gdbserver} at a binary for the running process.
43153
5b8b6385
JK
43154To start @code{gdbserver} without supplying an initial command to run
43155or process ID to attach, use the @option{--multi} command line option.
43156In such case you should connect using @kbd{target extended-remote} to start
43157the program you want to debug.
43158
43159@smallexample
43160target> gdbserver --multi @var{comm}
43161@end smallexample
43162
43662968
JK
43163@ifclear man
43164@subheading Usage (host side)
43165@end ifclear
43166@ifset man
43167Usage (host side):
43168@end ifset
43169
43170You need an unstripped copy of the target program on your host system, since
43171@value{GDBN} needs to examine it's symbol tables and such. Start up @value{GDBN} as you normally
43172would, with the target program as the first argument. (You may need to use the
43173@option{--baud} option if the serial line is running at anything except 9600 baud.)
43174That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
5b8b6385
JK
43175new command you need to know about is @code{target remote}
43176(or @code{target extended-remote}). Its argument is either
43662968
JK
43177a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
43178descriptor. For example:
43179
43180@smallexample
43181@ifset man
43182@c @file would wrap it as F</dev/ttyb>.
43183(gdb) target remote /dev/ttyb
43184@end ifset
43185@ifclear man
43186(gdb) target remote @file{/dev/ttyb}
43187@end ifclear
43188@end smallexample
43189
43190@noindent
43191communicates with the server via serial line @file{/dev/ttyb}, and:
43192
43193@smallexample
43194(gdb) target remote the-target:2345
43195@end smallexample
43196
43197@noindent
43198communicates via a TCP connection to port 2345 on host `the-target', where
43199you previously started up @command{gdbserver} with the same port number. Note that for
43200TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
43201command, otherwise you may get an error that looks something like
43202`Connection refused'.
5b8b6385
JK
43203
43204@command{gdbserver} can also debug multiple inferiors at once,
43205described in
43206@ifset man
43207the @value{GDBN} manual in node @code{Inferiors and Programs}
43208-- shell command @code{info -f gdb -n 'Inferiors and Programs'}.
43209@end ifset
43210@ifclear man
43211@ref{Inferiors and Programs}.
43212@end ifclear
43213In such case use the @code{extended-remote} @value{GDBN} command variant:
43214
43215@smallexample
43216(gdb) target extended-remote the-target:2345
43217@end smallexample
43218
43219The @command{gdbserver} option @option{--multi} may or may not be used in such
43220case.
43662968
JK
43221@c man end
43222
43223@c man begin OPTIONS gdbserver
5b8b6385
JK
43224There are three different modes for invoking @command{gdbserver}:
43225
43226@itemize @bullet
43227
43228@item
43229Debug a specific program specified by its program name:
43230
43231@smallexample
43232gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
43233@end smallexample
43234
43235The @var{comm} parameter specifies how should the server communicate
43236with @value{GDBN}; it is either a device name (to use a serial line),
43237a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
43238stdin/stdout of @code{gdbserver}. Specify the name of the program to
43239debug in @var{prog}. Any remaining arguments will be passed to the
43240program verbatim. When the program exits, @value{GDBN} will close the
43241connection, and @code{gdbserver} will exit.
43242
43243@item
43244Debug a specific program by specifying the process ID of a running
43245program:
43246
43247@smallexample
43248gdbserver --attach @var{comm} @var{pid}
43249@end smallexample
43250
43251The @var{comm} parameter is as described above. Supply the process ID
43252of a running program in @var{pid}; @value{GDBN} will do everything
43253else. Like with the previous mode, when the process @var{pid} exits,
43254@value{GDBN} will close the connection, and @code{gdbserver} will exit.
43255
43256@item
43257Multi-process mode -- debug more than one program/process:
43258
43259@smallexample
43260gdbserver --multi @var{comm}
43261@end smallexample
43262
43263In this mode, @value{GDBN} can instruct @command{gdbserver} which
43264command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
43265close the connection when a process being debugged exits, so you can
43266debug several processes in the same session.
43267@end itemize
43268
43269In each of the modes you may specify these options:
43270
43271@table @env
43272
43273@item --help
43274List all options, with brief explanations.
43275
43276@item --version
43277This option causes @command{gdbserver} to print its version number and exit.
43278
43279@item --attach
43280@command{gdbserver} will attach to a running program. The syntax is:
43281
43282@smallexample
43283target> gdbserver --attach @var{comm} @var{pid}
43284@end smallexample
43285
43286@var{pid} is the process ID of a currently running process. It isn't
43287necessary to point @command{gdbserver} at a binary for the running process.
43288
43289@item --multi
43290To start @code{gdbserver} without supplying an initial command to run
43291or process ID to attach, use this command line option.
43292Then you can connect using @kbd{target extended-remote} and start
43293the program you want to debug. The syntax is:
43294
43295@smallexample
43296target> gdbserver --multi @var{comm}
43297@end smallexample
43298
43299@item --debug
43300Instruct @code{gdbserver} to display extra status information about the debugging
43301process.
43302This option is intended for @code{gdbserver} development and for bug reports to
43303the developers.
43304
43305@item --remote-debug
43306Instruct @code{gdbserver} to display remote protocol debug output.
43307This option is intended for @code{gdbserver} development and for bug reports to
43308the developers.
43309
87ce2a04
DE
43310@item --debug-format=option1@r{[},option2,...@r{]}
43311Instruct @code{gdbserver} to include extra information in each line
43312of debugging output.
43313@xref{Other Command-Line Arguments for gdbserver}.
43314
5b8b6385
JK
43315@item --wrapper
43316Specify a wrapper to launch programs
43317for debugging. The option should be followed by the name of the
43318wrapper, then any command-line arguments to pass to the wrapper, then
43319@kbd{--} indicating the end of the wrapper arguments.
43320
43321@item --once
43322By default, @command{gdbserver} keeps the listening TCP port open, so that
43323additional connections are possible. However, if you start @code{gdbserver}
43324with the @option{--once} option, it will stop listening for any further
43325connection attempts after connecting to the first @value{GDBN} session.
43326
43327@c --disable-packet is not documented for users.
43328
43329@c --disable-randomization and --no-disable-randomization are superseded by
43330@c QDisableRandomization.
43331
43332@end table
43662968
JK
43333@c man end
43334
43335@c man begin SEEALSO gdbserver
43336@ifset man
43337The full documentation for @value{GDBN} is maintained as a Texinfo manual.
43338If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
43339documentation are properly installed at your site, the command
43340
43341@smallexample
43342info gdb
43343@end smallexample
43344
43345should give you access to the complete manual.
43346
43347@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
43348Richard M. Stallman and Roland H. Pesch, July 1991.
43349@end ifset
43350@c man end
43351
b292c783
JK
43352@node gcore man
43353@heading gcore
43354
43355@c man title gcore Generate a core file of a running program
43356
43357@format
43358@c man begin SYNOPSIS gcore
c179febe 43359gcore [-a] [-o @var{filename}] @var{pid}
b292c783
JK
43360@c man end
43361@end format
43362
43363@c man begin DESCRIPTION gcore
43364Generate a core dump of a running program with process ID @var{pid}.
43365Produced file is equivalent to a kernel produced core file as if the process
43366crashed (and if @kbd{ulimit -c} were used to set up an appropriate core dump
43367limit). Unlike after a crash, after @command{gcore} the program remains
43368running without any change.
43369@c man end
43370
43371@c man begin OPTIONS gcore
43372@table @env
c179febe
SL
43373@item -a
43374Dump all memory mappings. The actual effect of this option depends on
43375the Operating System. On @sc{gnu}/Linux, it will disable
43376@code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
43377enable @code{dump-excluded-mappings} (@pxref{set
43378dump-excluded-mappings}).
43379
b292c783
JK
43380@item -o @var{filename}
43381The optional argument
43382@var{filename} specifies the file name where to put the core dump.
43383If not specified, the file name defaults to @file{core.@var{pid}},
43384where @var{pid} is the running program process ID.
43385@end table
43386@c man end
43387
43388@c man begin SEEALSO gcore
43389@ifset man
43390The full documentation for @value{GDBN} is maintained as a Texinfo manual.
43391If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
43392documentation are properly installed at your site, the command
43393
43394@smallexample
43395info gdb
43396@end smallexample
43397
43398@noindent
43399should give you access to the complete manual.
43400
43401@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
43402Richard M. Stallman and Roland H. Pesch, July 1991.
43403@end ifset
43404@c man end
43405
43662968
JK
43406@node gdbinit man
43407@heading gdbinit
43408
43409@c man title gdbinit GDB initialization scripts
43410
43411@format
43412@c man begin SYNOPSIS gdbinit
43413@ifset SYSTEM_GDBINIT
43414@value{SYSTEM_GDBINIT}
43415@end ifset
43416
43417~/.gdbinit
43418
43419./.gdbinit
43420@c man end
43421@end format
43422
43423@c man begin DESCRIPTION gdbinit
43424These files contain @value{GDBN} commands to automatically execute during
43425@value{GDBN} startup. The lines of contents are canned sequences of commands,
43426described in
43427@ifset man
43428the @value{GDBN} manual in node @code{Sequences}
43429-- shell command @code{info -f gdb -n Sequences}.
43430@end ifset
43431@ifclear man
43432@ref{Sequences}.
43433@end ifclear
43434
43435Please read more in
43436@ifset man
43437the @value{GDBN} manual in node @code{Startup}
43438-- shell command @code{info -f gdb -n Startup}.
43439@end ifset
43440@ifclear man
43441@ref{Startup}.
43442@end ifclear
43443
43444@table @env
43445@ifset SYSTEM_GDBINIT
43446@item @value{SYSTEM_GDBINIT}
43447@end ifset
43448@ifclear SYSTEM_GDBINIT
43449@item (not enabled with @code{--with-system-gdbinit} during compilation)
43450@end ifclear
43451System-wide initialization file. It is executed unless user specified
43452@value{GDBN} option @code{-nx} or @code{-n}.
43453See more in
43454@ifset man
43455the @value{GDBN} manual in node @code{System-wide configuration}
43456-- shell command @code{info -f gdb -n 'System-wide configuration'}.
43457@end ifset
43458@ifclear man
43459@ref{System-wide configuration}.
43460@end ifclear
43461
43462@item ~/.gdbinit
43463User initialization file. It is executed unless user specified
43464@value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
43465
43466@item ./.gdbinit
43467Initialization file for current directory. It may need to be enabled with
43468@value{GDBN} security command @code{set auto-load local-gdbinit}.
43469See more in
43470@ifset man
43471the @value{GDBN} manual in node @code{Init File in the Current Directory}
43472-- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
43473@end ifset
43474@ifclear man
43475@ref{Init File in the Current Directory}.
43476@end ifclear
43477@end table
43478@c man end
43479
43480@c man begin SEEALSO gdbinit
43481@ifset man
43482gdb(1), @code{info -f gdb -n Startup}
43483
43484The full documentation for @value{GDBN} is maintained as a Texinfo manual.
43485If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
43486documentation are properly installed at your site, the command
ba643918
SDJ
43487
43488@smallexample
43489info gdb
43490@end smallexample
43491
43492should give you access to the complete manual.
43493
43494@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
43495Richard M. Stallman and Roland H. Pesch, July 1991.
43496@end ifset
43497@c man end
43498
43499@node gdb-add-index man
ba643918 43500@heading gdb-add-index
d726cb5d 43501@pindex gdb-add-index
dbfa4523 43502@anchor{gdb-add-index}
ba643918
SDJ
43503
43504@c man title gdb-add-index Add index files to speed up GDB
43505
43506@c man begin SYNOPSIS gdb-add-index
43507gdb-add-index @var{filename}
43508@c man end
43509
43510@c man begin DESCRIPTION gdb-add-index
43511When @value{GDBN} finds a symbol file, it scans the symbols in the
43512file in order to construct an internal symbol table. This lets most
43513@value{GDBN} operations work quickly--at the cost of a delay early on.
43514For large programs, this delay can be quite lengthy, so @value{GDBN}
43515provides a way to build an index, which speeds up startup.
43516
43517To determine whether a file contains such an index, use the command
43518@kbd{readelf -S filename}: the index is stored in a section named
43519@code{.gdb_index}. The index file can only be produced on systems
43520which use ELF binaries and DWARF debug information (i.e., sections
43521named @code{.debug_*}).
43522
43523@command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
43524in the @env{PATH} environment variable. If you want to use different
43525versions of these programs, you can specify them through the
43526@env{GDB} and @env{OBJDUMP} environment variables.
43527
43528See more in
43529@ifset man
43530the @value{GDBN} manual in node @code{Index Files}
43531-- shell command @kbd{info -f gdb -n "Index Files"}.
43532@end ifset
43533@ifclear man
43534@ref{Index Files}.
43535@end ifclear
43536@c man end
43537
43538@c man begin SEEALSO gdb-add-index
43539@ifset man
43540The full documentation for @value{GDBN} is maintained as a Texinfo manual.
43541If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
43542documentation are properly installed at your site, the command
43662968
JK
43543
43544@smallexample
43545info gdb
43546@end smallexample
43547
43548should give you access to the complete manual.
43549
43550@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
43551Richard M. Stallman and Roland H. Pesch, July 1991.
43552@end ifset
43553@c man end
43554
aab4e0ec 43555@include gpl.texi
eb12ee30 43556
e4c0cfae
SS
43557@node GNU Free Documentation License
43558@appendix GNU Free Documentation License
6826cf00
EZ
43559@include fdl.texi
43560
00595b5e
EZ
43561@node Concept Index
43562@unnumbered Concept Index
c906108c
SS
43563
43564@printindex cp
43565
00595b5e
EZ
43566@node Command and Variable Index
43567@unnumbered Command, Variable, and Function Index
43568
43569@printindex fn
43570
c906108c 43571@tex
984359d2 43572% I think something like @@colophon should be in texinfo. In the
c906108c
SS
43573% meantime:
43574\long\def\colophon{\hbox to0pt{}\vfill
43575\centerline{The body of this manual is set in}
43576\centerline{\fontname\tenrm,}
43577\centerline{with headings in {\bf\fontname\tenbf}}
43578\centerline{and examples in {\tt\fontname\tentt}.}
43579\centerline{{\it\fontname\tenit\/},}
43580\centerline{{\bf\fontname\tenbf}, and}
43581\centerline{{\sl\fontname\tensl\/}}
43582\centerline{are used for emphasis.}\vfill}
43583\page\colophon
984359d2 43584% Blame: doc@@cygnus.com, 1991.
c906108c
SS
43585@end tex
43586
c906108c 43587@bye
This page took 9.824547 seconds and 4 git commands to generate.